Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c247a337a9 | ||
|
|
9f5ff8eb42 | ||
|
|
2131340c01 | ||
|
|
9a21e111d0 | ||
|
|
46175efe1b | ||
|
|
128c5c6f4e | ||
|
|
1a9c7b56ff | ||
|
|
cf3e64e836 | ||
|
|
fc5f2fee41 | ||
|
|
f0b952e3a2 | ||
|
|
cc20c0cc25 | ||
|
|
5f31542cb6 | ||
|
|
77f63a6f80 | ||
|
|
0c5c1040cd | ||
|
|
35211c69a4 | ||
|
|
b8d894f243 | ||
|
|
e69f2db44c | ||
|
|
dc9c2773de | ||
|
|
5a4e116475 | ||
|
|
d029e480d0 | ||
|
|
85dc9a1ac2 | ||
|
|
0d53bdaf9a | ||
|
|
cd007ba431 | ||
|
|
47fabe6180 | ||
|
|
8b6c9593e1 |
No files matched your search
@@ -33,12 +33,21 @@ jobs:
|
|||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
||||||
|
- name: React path quality stubs
|
||||||
|
run: npm run frontend:react:check
|
||||||
|
|
||||||
- name: Install Playwright browsers
|
- name: Install Playwright browsers
|
||||||
run: npx playwright install chromium
|
run: npx playwright install chromium
|
||||||
|
|
||||||
- name: Run browser regression
|
- name: Run browser regression
|
||||||
run: npm run test:ui
|
run: npm run test:ui
|
||||||
|
|
||||||
|
- name: UI metrics report (always)
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
echo "UI metrics report:"
|
||||||
|
cat output/playwright/ui-metrics-report.json || true
|
||||||
|
|
||||||
- name: Browser artifacts listing (always)
|
- name: Browser artifacts listing (always)
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -18,6 +18,17 @@ This version includes:
|
|||||||
npm run start
|
npm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Frontend migration command paths:
|
||||||
|
- Legacy: `npm run frontend:legacy:dev` or `npm run frontend:legacy:start`
|
||||||
|
- React (`frontend-react/`): `npm run frontend:react:dev`
|
||||||
|
- React checks: `npm run frontend:react:check`
|
||||||
|
|
||||||
|
React app bootstrap:
|
||||||
|
```bash
|
||||||
|
npm --prefix frontend-react install
|
||||||
|
npm run frontend:react:dev
|
||||||
|
```
|
||||||
|
|
||||||
Open:
|
Open:
|
||||||
- Workspace: `http://localhost:8787/`
|
- Workspace: `http://localhost:8787/`
|
||||||
- Health: `http://localhost:8787/health`
|
- Health: `http://localhost:8787/health`
|
||||||
@@ -40,6 +51,9 @@ Docs:
|
|||||||
- `docs/operations-runbook.md`
|
- `docs/operations-runbook.md`
|
||||||
- `docs/quality-gates.md`
|
- `docs/quality-gates.md`
|
||||||
- `docs/phase4-execution-plan.md`
|
- `docs/phase4-execution-plan.md`
|
||||||
|
- `docs/phase5-execution-plan.md`
|
||||||
|
- `docs/phase8-dual-run-kickoff.md`
|
||||||
|
- `docs/fixtures.md`
|
||||||
- `docs/api-mcp-contracts.md`
|
- `docs/api-mcp-contracts.md`
|
||||||
|
|
||||||
CI:
|
CI:
|
||||||
@@ -186,6 +200,9 @@ npx playwright install chromium
|
|||||||
npm run test:ui
|
npm run test:ui
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Metrics report artifact:
|
||||||
|
- `output/playwright/ui-metrics-report.json`
|
||||||
|
|
||||||
Refresh visual baselines intentionally:
|
Refresh visual baselines intentionally:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Fixture Pack
|
||||||
|
|
||||||
|
Schemeta uses deterministic fixture circuits for compile/layout/readability QA.
|
||||||
|
|
||||||
|
## Core fixtures
|
||||||
|
|
||||||
|
1. `examples/esp32-audio.json`
|
||||||
|
- Baseline audio pipeline (MCU -> DAC -> amp).
|
||||||
|
2. `examples/dense-analog.json`
|
||||||
|
- High-density analog topology used for overlap/crossing stress.
|
||||||
|
3. `examples/i2c-sensor-hub.json`
|
||||||
|
- Shared bus topology with pull-ups and interrupt branches.
|
||||||
|
4. `examples/power-tree.json`
|
||||||
|
- Multi-domain power-distribution with digital branch nets.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Manual import in UI:
|
||||||
|
- `Import JSON` then select fixture file.
|
||||||
|
2. API:
|
||||||
|
- `POST /compile` or `POST /analyze` with fixture payload.
|
||||||
|
3. Automated regression:
|
||||||
|
- `npm run test:ui` uses `dense-analog` for layout budget checks.
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
1. Fixtures should stay deterministic (stable ordering and explicit naming).
|
||||||
|
2. Avoid avoidable warnings in default/demo fixtures.
|
||||||
|
3. Add a fixture whenever a routing/layout bug is fixed to prevent regressions.
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Phase 5 Execution Plan
|
||||||
|
|
||||||
|
Milestone: `Phase 5 - Layout Robustness and JSON Import UX Hardening`
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
|
||||||
|
1. Make drag/re-layout behavior measurable and regression-resistant.
|
||||||
|
2. Improve JSON import/apply reliability with validation-first messaging.
|
||||||
|
3. Ship richer fixture coverage and enforce readability budgets in CI.
|
||||||
|
|
||||||
|
## Workstreams
|
||||||
|
|
||||||
|
1. QA harness and metrics artifact
|
||||||
|
- Extend `tests/ui-regression-runner.js` to capture:
|
||||||
|
- initial compile metrics
|
||||||
|
- post-drag metrics
|
||||||
|
- post-drag auto-tidy metrics
|
||||||
|
- dense fixture metrics
|
||||||
|
- Emit machine-readable artifact:
|
||||||
|
- `output/playwright/ui-metrics-report.json`
|
||||||
|
|
||||||
|
2. Layout/readability quality budgets
|
||||||
|
- Enforce thresholds in UI regression runner with env overrides:
|
||||||
|
- `UI_SAMPLE_MAX_*`
|
||||||
|
- `UI_DRAG_MAX_*`
|
||||||
|
- `UI_TIDY_MAX_*`
|
||||||
|
- `UI_DENSE_MAX_*`
|
||||||
|
- Keep defaults tuned to current deterministic behavior.
|
||||||
|
|
||||||
|
3. JSON import UX hardening
|
||||||
|
- Validate with `/analyze` before applying/importing JSON.
|
||||||
|
- Block apply/import when validation has errors.
|
||||||
|
- Surface first warning/error and path for faster correction.
|
||||||
|
- Keep deterministic change summary after successful apply.
|
||||||
|
|
||||||
|
4. Fixture pack expansion
|
||||||
|
- Add representative fixtures beyond the baseline audio example:
|
||||||
|
- `examples/dense-analog.json`
|
||||||
|
- `examples/i2c-sensor-hub.json`
|
||||||
|
- `examples/power-tree.json`
|
||||||
|
- Maintain warning-clean default sample (`frontend/sample.schemeta.json`).
|
||||||
|
|
||||||
|
## Done Definition
|
||||||
|
|
||||||
|
1. `npm test` passes.
|
||||||
|
2. `npm run test:ui` passes with quality budgets.
|
||||||
|
3. `output/playwright/ui-metrics-report.json` is generated on every UI run.
|
||||||
|
4. Import/apply validation behavior is deterministic and user-visible.
|
||||||
|
5. Phase 5 issues `#24-#29` are closed and milestone is closed.
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Phase 8 Kickoff: Dual-Run Frontend (Legacy + React)
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
Define how to run the current legacy frontend and the incoming React frontend side-by-side during migration kickoff.
|
||||||
|
|
||||||
|
## Frontend Paths
|
||||||
|
- Legacy frontend: served by `src/server.js` at `http://localhost:8787/`
|
||||||
|
- React frontend (target): expected in `frontend-react/` (Vite default expected at `http://localhost:5173/`)
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
- Legacy dev server: `npm run frontend:legacy:dev`
|
||||||
|
- Legacy start (non-watch): `npm run frontend:legacy:start`
|
||||||
|
- React dev (stub-aware): `npm run frontend:react:dev`
|
||||||
|
- React quality stubs:
|
||||||
|
- `npm run frontend:react:lint`
|
||||||
|
- `npm run frontend:react:test`
|
||||||
|
- `npm run frontend:react:build`
|
||||||
|
- `npm run frontend:react:check`
|
||||||
|
|
||||||
|
If `frontend-react/package.json` does not exist, lacks the requested script, or `frontend-react/node_modules` is missing, React commands exit successfully with a deterministic skip message.
|
||||||
|
|
||||||
|
## Side-by-Side Local Run
|
||||||
|
1. Terminal A: `npm run frontend:legacy:dev`
|
||||||
|
2. Terminal B: `npm run frontend:react:dev`
|
||||||
|
3. Verify legacy UI responds on `http://localhost:8787/`
|
||||||
|
4. Verify React command behavior:
|
||||||
|
- pre-scaffold: skip message (expected)
|
||||||
|
- post-scaffold: starts actual React dev server
|
||||||
|
|
||||||
|
## Milestone Kickoff Checklist (`#37`, `#38`)
|
||||||
|
- [x] `#37` React migration kickoff commands are exposed in root `package.json`.
|
||||||
|
- [x] `#37` Dual-run operational doc exists for legacy + React side-by-side local execution.
|
||||||
|
- [x] `#37` CI includes a React-path quality command (`frontend:react:check`) that is safe before scaffold and active after scaffold.
|
||||||
|
- [x] `#38` Deterministic command wiring established for React quality gates (`lint/test/build`) via a single stub-aware runner.
|
||||||
|
- [x] `#38` Legacy and React paths are explicitly separated in command names to reduce migration ambiguity.
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
# Phase 8 Execution Plan: React + ELK Core Refactor
|
||||||
|
|
||||||
|
## Objective
|
||||||
|
Deliver the largest Schemeta refactor to date: migrate the frontend to a robust React architecture, replace fragile placement behavior with ELK-driven layout, harden routing/labeling readability, and establish production-grade quality gates.
|
||||||
|
|
||||||
|
This phase is OSS-only and budget-neutral.
|
||||||
|
|
||||||
|
## Non-Goals
|
||||||
|
- No paid/proprietary graph SDKs.
|
||||||
|
- No API contract break for `/compile`, `/analyze`, `/layout/auto`, `/layout/tidy`.
|
||||||
|
- No regression of current JSON schema compatibility.
|
||||||
|
|
||||||
|
## Architecture Target
|
||||||
|
- Frontend: React + TypeScript + Vite.
|
||||||
|
- Interaction layer: React Flow primitives for node/selection/viewport interactions.
|
||||||
|
- Layout: `elkjs` as primary placement engine.
|
||||||
|
- Routing: Schemeta incremental router with deterministic tie-net fallback.
|
||||||
|
- State: deterministic centralized action pipeline (undo/redo transaction model).
|
||||||
|
|
||||||
|
## Work Breakdown (Milestone #7)
|
||||||
|
- #37 P8-01 Frontend architecture migration to React + TS + Vite
|
||||||
|
- #38 P8-02 State model refactor with deterministic action pipeline
|
||||||
|
- #39 P8-03 Canvas subsystem rewrite with React Flow contracts
|
||||||
|
- #40 P8-04 ELK integration and constraints mapping
|
||||||
|
- #41 P8-05 Routing engine revamp (incremental reroute)
|
||||||
|
- #42 P8-06 Deterministic label placement and collision avoidance
|
||||||
|
- #43 P8-07 Symbol readability and pin-density standards
|
||||||
|
- #44 P8-08 JSON editor power-tool upgrade (schema-aware + diff apply)
|
||||||
|
- #45 P8-09 QA hardening (visual/readability gates)
|
||||||
|
- #46 P8-10 Cutover, migration, rollback
|
||||||
|
|
||||||
|
## Delivery Sequence (Critical Path)
|
||||||
|
1. Foundation
|
||||||
|
- Complete #37 (React app shell) and #38 (state architecture).
|
||||||
|
- Exit criteria: feature-parity shell + deterministic action store.
|
||||||
|
2. Interaction rewrite
|
||||||
|
- Complete #39 on top of #37/#38.
|
||||||
|
- Exit criteria: drag/multi-select/pan/zoom/edit stable and undoable.
|
||||||
|
3. Layout core
|
||||||
|
- Complete #40 with adapter boundaries for constraints.
|
||||||
|
- Exit criteria: ELK-based autolayout deterministic on fixtures.
|
||||||
|
4. Routing core
|
||||||
|
- Complete #41 with local reroute and deterministic fallback behavior.
|
||||||
|
- Exit criteria: moved components reroute only affected nets.
|
||||||
|
5. Readability system
|
||||||
|
- Complete #42 + #43 for labels/pin-density constraints.
|
||||||
|
- Exit criteria: baseline fixtures have no label/pin overlap failures.
|
||||||
|
6. Power-user JSON workflow
|
||||||
|
- Complete #44 for schema-aware editing and safe apply previews.
|
||||||
|
7. Quality gates + ship safety
|
||||||
|
- Complete #45 + #46; run cutover checklist.
|
||||||
|
|
||||||
|
## Technical Design Rules
|
||||||
|
- Determinism first: all ordered traversals sort by stable keys.
|
||||||
|
- Incremental operations default: no full relayout on drag/edit unless explicit.
|
||||||
|
- Readability constraints are hard constraints, not best-effort hints.
|
||||||
|
- Feature flags for risky changes during dual-run period.
|
||||||
|
|
||||||
|
## Quality Gates (Phase 8 Additions)
|
||||||
|
In addition to existing crossings/overlaps/detour metrics:
|
||||||
|
- Label collisions must be 0 in baseline fixtures.
|
||||||
|
- Pin text collisions must be 0 in baseline fixtures.
|
||||||
|
- Component overlap must remain 0.
|
||||||
|
- Drag action must not move untouched components.
|
||||||
|
- Snapshot test matrix across viewport sizes and render modes.
|
||||||
|
|
||||||
|
## Risks and Mitigation
|
||||||
|
- Risk: React migration stalls on parity gaps.
|
||||||
|
- Mitigation: keep legacy UI in dual-run until parity checklist passes.
|
||||||
|
- Risk: ELK mapping mismatch with custom constraints.
|
||||||
|
- Mitigation: fallback mapping with explicit unsupported-constraint diagnostics.
|
||||||
|
- Risk: routing regressions after layout changes.
|
||||||
|
- Mitigation: incremental router tests and stress fixtures in CI.
|
||||||
|
- Risk: test flakiness due to persisted state.
|
||||||
|
- Mitigation: force deterministic test bootstrapping and storage resets.
|
||||||
|
|
||||||
|
## Performance Budgets
|
||||||
|
- Compile latency p95 (sample): <= 180ms local.
|
||||||
|
- Drag-to-reroute p95 (affected nets only): <= 120ms local.
|
||||||
|
- Auto layout p95 (medium fixture): <= 600ms local.
|
||||||
|
|
||||||
|
## Release Readiness Checklist
|
||||||
|
- All milestone issues closed.
|
||||||
|
- CI green for unit + UI + readability metrics.
|
||||||
|
- Dual-run comparison report attached.
|
||||||
|
- Rollback validated with documented steps.
|
||||||
|
- Release notes include migration caveats and known limitations.
|
||||||
|
|
||||||
|
## Definition of Done
|
||||||
|
Phase 8 is done only when:
|
||||||
|
- React UI is default and legacy path can be disabled safely.
|
||||||
|
- ELK placement is primary in production path.
|
||||||
|
- Readability gates are enforced in CI.
|
||||||
|
- Drag/edit interactions are deterministic and locally incremental.
|
||||||
|
- JSON/AI workflows are schema-aware and operator-safe.
|
||||||
@@ -14,10 +14,13 @@ This document defines measurable release gates for Schemeta.
|
|||||||
- `npm run test:ui` passes.
|
- `npm run test:ui` passes.
|
||||||
2. Visual regression
|
2. Visual regression
|
||||||
- No unexpected screenshot diffs in `tests/baselines/ui`.
|
- No unexpected screenshot diffs in `tests/baselines/ui`.
|
||||||
- Dense analog fixture remains under threshold:
|
- UI budget thresholds (defaults in `tests/ui-regression-runner.js`) are met:
|
||||||
- crossings = `0`
|
- sample: crossings <= `1`, overlaps <= `1`, detour <= `3.6`
|
||||||
- overlaps = `0`
|
- drag: crossings <= `3`, overlaps <= `3`, detour <= `3.5`
|
||||||
- detour <= `2.5`
|
- drag+tidy: crossings <= `2`, overlaps <= `2`, detour <= `4.5`
|
||||||
|
- dense fixture: crossings <= `2`, overlaps <= `2`, detour <= `4.2`
|
||||||
|
- Machine-readable report generated:
|
||||||
|
- `output/playwright/ui-metrics-report.json`
|
||||||
3. Interaction reliability
|
3. Interaction reliability
|
||||||
- Selection/deselection/isolate/reset flow verified.
|
- Selection/deselection/isolate/reset flow verified.
|
||||||
- Undo/redo parity verified for component, pin, net, and symbol edits.
|
- Undo/redo parity verified for component, pin, net, and symbol edits.
|
||||||
@@ -48,6 +51,7 @@ This document defines measurable release gates for Schemeta.
|
|||||||
- syntax checks
|
- syntax checks
|
||||||
- `npm test`
|
- `npm test`
|
||||||
- `npm run test:ui`
|
- `npm run test:ui`
|
||||||
|
- verify `output/playwright/ui-metrics-report.json` was produced
|
||||||
- Release candidate required:
|
- Release candidate required:
|
||||||
- checklist completion in `docs/release-checklist.md`
|
- checklist completion in `docs/release-checklist.md`
|
||||||
- intentional baseline updates reviewed and approved
|
- intentional baseline updates reviewed and approved
|
||||||
@@ -4,6 +4,7 @@ Use this checklist before cutting a release tag.
|
|||||||
Reference docs:
|
Reference docs:
|
||||||
- `docs/quality-gates.md`
|
- `docs/quality-gates.md`
|
||||||
- `docs/phase4-execution-plan.md`
|
- `docs/phase4-execution-plan.md`
|
||||||
|
- `docs/phase5-execution-plan.md`
|
||||||
|
|
||||||
## Pre-merge
|
## Pre-merge
|
||||||
|
|
||||||
@@ -15,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
|
||||||
@@ -30,7 +32,8 @@ Reference docs:
|
|||||||
- [ ] Visual baselines updated intentionally (`tests/baselines/ui`) and screenshot diff checks pass.
|
- [ ] Visual baselines updated intentionally (`tests/baselines/ui`) and screenshot diff checks pass.
|
||||||
- [ ] Labels remain legible at common zoom levels.
|
- [ ] Labels remain legible at common zoom levels.
|
||||||
- [ ] No major overlap/crossing regressions vs previous release baseline.
|
- [ ] No major overlap/crossing regressions vs previous release baseline.
|
||||||
- [ ] Dense analog fixture meets gate thresholds (`crossings=0`, `overlaps=0`, detour target).
|
- [ ] UI metrics report generated (`output/playwright/ui-metrics-report.json`).
|
||||||
|
- [ ] Sample/drag/tidy/dense fixture all meet the thresholds in `docs/quality-gates.md`.
|
||||||
|
|
||||||
## Security / Operations
|
## Security / Operations
|
||||||
|
|
||||||
@@ -51,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.
|
||||||
@@ -80,10 +80,15 @@
|
|||||||
"constraints": {
|
"constraints": {
|
||||||
"groups": [
|
"groups": [
|
||||||
{ "name": "power_stage", "members": ["U4"], "layout": "cluster" },
|
{ "name": "power_stage", "members": ["U4"], "layout": "cluster" },
|
||||||
{ "name": "compute", "members": ["U1", "U2"], "layout": "cluster" }
|
{ "name": "compute", "members": ["U1"], "layout": "cluster" },
|
||||||
|
{ "name": "audio_out", "members": ["U2", "U3"], "layout": "cluster" }
|
||||||
],
|
],
|
||||||
"alignment": [{ "left_of": "U1", "right_of": "U2" }],
|
"alignment": [
|
||||||
"near": [{ "component": "U2", "target_pin": { "ref": "U1", "pin": "GPIO5" } }]
|
{ "left_of": "U4", "right_of": "U1" },
|
||||||
|
{ "left_of": "U1", "right_of": "U2" },
|
||||||
|
{ "left_of": "U2", "right_of": "U3" }
|
||||||
|
],
|
||||||
|
"near": []
|
||||||
},
|
},
|
||||||
"annotations": [
|
"annotations": [
|
||||||
{ "text": "I2S audio chain" }
|
{ "text": "I2S audio chain" }
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"title": "I2C Sensor Hub",
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"symbols": {
|
||||||
|
"mcu": {
|
||||||
|
"symbol_id": "mcu",
|
||||||
|
"category": "microcontroller",
|
||||||
|
"body": { "width": 180, "height": 220 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 24, "type": "power_in" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 56, "type": "ground" },
|
||||||
|
{ "name": "SCL", "number": "3", "side": "right", "offset": 48, "type": "bidirectional" },
|
||||||
|
{ "name": "SDA", "number": "4", "side": "right", "offset": 78, "type": "bidirectional" },
|
||||||
|
{ "name": "INT1", "number": "5", "side": "right", "offset": 122, "type": "input" },
|
||||||
|
{ "name": "INT2", "number": "6", "side": "right", "offset": 152, "type": "input" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"i2c_sensor": {
|
||||||
|
"symbol_id": "i2c_sensor",
|
||||||
|
"category": "sensor",
|
||||||
|
"body": { "width": 140, "height": 120 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 18, "type": "power_in" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 44, "type": "ground" },
|
||||||
|
{ "name": "SCL", "number": "3", "side": "left", "offset": 70, "type": "bidirectional" },
|
||||||
|
{ "name": "SDA", "number": "4", "side": "left", "offset": 96, "type": "bidirectional" },
|
||||||
|
{ "name": "INT", "number": "5", "side": "right", "offset": 58, "type": "output" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"power_source": {
|
||||||
|
"symbol_id": "power_source",
|
||||||
|
"category": "power",
|
||||||
|
"body": { "width": 130, "height": 90 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "right", "offset": 26, "type": "power_out" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "right", "offset": 56, "type": "ground" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"instances": [
|
||||||
|
{ "ref": "U1", "symbol": "mcu", "properties": { "value": "ESP32-S3" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U2", "symbol": "i2c_sensor", "properties": { "value": "IMU" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U3", "symbol": "i2c_sensor", "properties": { "value": "BME280" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U4", "symbol": "i2c_sensor", "properties": { "value": "Mag" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "R1", "part": "resistor", "properties": { "value": "4.7k" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "R2", "part": "resistor", "properties": { "value": "4.7k" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "V1", "symbol": "power_source", "properties": { "value": "3V3/GND source" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } }
|
||||||
|
],
|
||||||
|
"nets": [
|
||||||
|
{ "name": "3V3", "class": "power", "nodes": [
|
||||||
|
{ "ref": "V1", "pin": "3V3" }, { "ref": "U1", "pin": "3V3" }, { "ref": "U2", "pin": "3V3" },
|
||||||
|
{ "ref": "U3", "pin": "3V3" }, { "ref": "U4", "pin": "3V3" }, { "ref": "R1", "pin": "1" }, { "ref": "R2", "pin": "1" }
|
||||||
|
] },
|
||||||
|
{ "name": "GND", "class": "ground", "nodes": [
|
||||||
|
{ "ref": "V1", "pin": "GND" }, { "ref": "U1", "pin": "GND" }, { "ref": "U2", "pin": "GND" },
|
||||||
|
{ "ref": "U3", "pin": "GND" }, { "ref": "U4", "pin": "GND" }
|
||||||
|
] },
|
||||||
|
{ "name": "I2C_SCL", "class": "clock", "nodes": [
|
||||||
|
{ "ref": "U1", "pin": "SCL" }, { "ref": "U2", "pin": "SCL" }, { "ref": "U3", "pin": "SCL" },
|
||||||
|
{ "ref": "U4", "pin": "SCL" }, { "ref": "R1", "pin": "2" }
|
||||||
|
] },
|
||||||
|
{ "name": "I2C_SDA", "class": "signal", "nodes": [
|
||||||
|
{ "ref": "U1", "pin": "SDA" }, { "ref": "U2", "pin": "SDA" }, { "ref": "U3", "pin": "SDA" },
|
||||||
|
{ "ref": "U4", "pin": "SDA" }, { "ref": "R2", "pin": "2" }
|
||||||
|
] },
|
||||||
|
{ "name": "INT1", "class": "signal", "nodes": [ { "ref": "U2", "pin": "INT" }, { "ref": "U1", "pin": "INT1" } ] },
|
||||||
|
{ "name": "INT2", "class": "signal", "nodes": [ { "ref": "U3", "pin": "INT" }, { "ref": "U1", "pin": "INT2" } ] }
|
||||||
|
],
|
||||||
|
"constraints": {
|
||||||
|
"groups": [
|
||||||
|
{ "name": "controller", "members": ["U1"], "layout": "cluster" },
|
||||||
|
{ "name": "sensors", "members": ["U2", "U3", "U4"], "layout": "cluster" },
|
||||||
|
{ "name": "pullups", "members": ["R1", "R2"], "layout": "cluster" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"annotations": [
|
||||||
|
{ "text": "Shared I2C bus with pull-ups and interrupt lines.", "x": 24, "y": 24 }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"title": "Dual-Rail Power Tree",
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"symbols": {},
|
||||||
|
"instances": [
|
||||||
|
{ "ref": "J1", "part": "connector", "properties": { "value": "VIN/GND" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U1", "part": "generic", "properties": { "value": "Buck 12V->5V" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U2", "part": "generic", "properties": { "value": "LDO 5V->3V3" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U3", "part": "generic", "properties": { "value": "MCU" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U4", "part": "generic", "properties": { "value": "RF Module" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C1", "part": "capacitor", "properties": { "value": "22uF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C2", "part": "capacitor", "properties": { "value": "10uF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C3", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C4", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } }
|
||||||
|
],
|
||||||
|
"nets": [
|
||||||
|
{ "name": "VIN", "class": "power", "nodes": [ { "ref": "J1", "pin": "1" }, { "ref": "U1", "pin": "VIN" } ] },
|
||||||
|
{ "name": "5V", "class": "power", "nodes": [ { "ref": "U1", "pin": "VOUT" }, { "ref": "U2", "pin": "VIN" }, { "ref": "C1", "pin": "1" }, { "ref": "C2", "pin": "1" } ] },
|
||||||
|
{ "name": "3V3", "class": "power", "nodes": [ { "ref": "U2", "pin": "VOUT" }, { "ref": "U3", "pin": "VCC" }, { "ref": "U4", "pin": "VCC" }, { "ref": "C3", "pin": "1" }, { "ref": "C4", "pin": "1" } ] },
|
||||||
|
{ "name": "GND", "class": "ground", "nodes": [ { "ref": "J1", "pin": "2" }, { "ref": "U1", "pin": "GND" }, { "ref": "U2", "pin": "GND" }, { "ref": "U3", "pin": "GND" }, { "ref": "U4", "pin": "GND" }, { "ref": "C1", "pin": "2" }, { "ref": "C2", "pin": "2" }, { "ref": "C3", "pin": "2" }, { "ref": "C4", "pin": "2" } ] },
|
||||||
|
{ "name": "SPI_CLK", "class": "clock", "nodes": [ { "ref": "U3", "pin": "SCLK" }, { "ref": "U4", "pin": "SCLK" } ] },
|
||||||
|
{ "name": "SPI_MOSI", "class": "signal", "nodes": [ { "ref": "U3", "pin": "MOSI" }, { "ref": "U4", "pin": "MOSI" } ] },
|
||||||
|
{ "name": "SPI_MISO", "class": "signal", "nodes": [ { "ref": "U3", "pin": "MISO" }, { "ref": "U4", "pin": "MISO" } ] }
|
||||||
|
],
|
||||||
|
"constraints": {
|
||||||
|
"groups": [
|
||||||
|
{ "name": "source", "members": ["J1", "U1", "C1"], "layout": "cluster" },
|
||||||
|
{ "name": "regulation", "members": ["U2", "C2"], "layout": "cluster" },
|
||||||
|
{ "name": "load", "members": ["U3", "U4", "C3", "C4"], "layout": "cluster" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"annotations": [
|
||||||
|
{ "text": "Power-chain fixture with SPI branch used for readability QA.", "x": 24, "y": 24 }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
*.tsbuildinfo
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Schemeta React Frontend (Track A)
|
||||||
|
|
||||||
|
Bootstrap React + TypeScript + Vite shell for Schemeta.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
- `npm run dev` - start Vite dev server
|
||||||
|
- `npm run build` - type-check and build production bundle
|
||||||
|
- `npm run preview` - preview built bundle
|
||||||
|
- `npm run lint` - TypeScript no-emit check
|
||||||
|
- `npm run test` - placeholder test command
|
||||||
|
|
||||||
|
## API endpoints wired
|
||||||
|
|
||||||
|
The app client posts to the existing backend routes without contract changes:
|
||||||
|
|
||||||
|
- `POST /compile`
|
||||||
|
- `POST /analyze`
|
||||||
|
- `POST /layout/auto`
|
||||||
|
- `POST /layout/tidy`
|
||||||
|
|
||||||
|
Vite dev server proxies these routes to `http://localhost:8787`.
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Schemeta React</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "schemeta-frontend-react",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"lint": "tsc --noEmit -p tsconfig.app.json",
|
||||||
|
"test": "node -e \"console.log('frontend-react: no tests yet')\""
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^18.3.1",
|
||||||
|
"react-dom": "^18.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.3.12",
|
||||||
|
"@types/react-dom": "^18.3.1",
|
||||||
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
|
"typescript": "^5.5.4",
|
||||||
|
"vite": "^5.4.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,297 @@
|
|||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { analyze, autoLayout, compile, tidyLayout } from "./api/client";
|
||||||
|
import { CanvasArea } from "./components/CanvasArea";
|
||||||
|
import { LeftPanel } from "./components/LeftPanel";
|
||||||
|
import { RightInspector } from "./components/RightInspector";
|
||||||
|
import { TopBar } from "./components/TopBar";
|
||||||
|
import type { TopBarStatusTone } from "./components/TopBar";
|
||||||
|
import sampleFixture from "./fixtures/sample.schemeta.json";
|
||||||
|
import { useSchemetaActions, useSchemetaSelector } from "./hooks";
|
||||||
|
import { createSchemetaStore } from "./state";
|
||||||
|
import type { SchemetaModel } from "./state";
|
||||||
|
|
||||||
|
type EndpointActionId = "compile" | "analyze" | "layout-auto" | "layout-tidy";
|
||||||
|
type LocalActionId = "load-sample" | "reset-sample";
|
||||||
|
type WorkflowActionId = EndpointActionId | LocalActionId;
|
||||||
|
|
||||||
|
type WorkflowAction = {
|
||||||
|
id: WorkflowActionId;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SAMPLE_PAYLOAD = sampleFixture as SchemetaModel;
|
||||||
|
|
||||||
|
function getPayloadOrThrow(payload: unknown): SchemetaModel {
|
||||||
|
if (typeof payload !== "object" || payload === null) {
|
||||||
|
throw new Error("No model loaded. Run 'Load Sample JSON' first.");
|
||||||
|
}
|
||||||
|
return payload as SchemetaModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toCompileFromAnalyze(result: Awaited<ReturnType<typeof analyze>>): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
api_version: result.api_version,
|
||||||
|
schema_version: result.schema_version,
|
||||||
|
request_id: result.request_id,
|
||||||
|
ok: result.ok ?? true,
|
||||||
|
errors: Array.isArray(result.errors) ? result.errors : [],
|
||||||
|
warnings: Array.isArray(result.warnings) ? result.warnings : [],
|
||||||
|
topology: result.topology ?? {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
const store = useMemo(() => createSchemetaStore({ model: SAMPLE_PAYLOAD }), []);
|
||||||
|
const actionsApi = useSchemetaActions(store);
|
||||||
|
const model = useSchemetaSelector(store, (state) => state.model);
|
||||||
|
const selection = useSchemetaSelector(store, (state) => state.selection);
|
||||||
|
const compileResult = useSchemetaSelector(store, (state) => state.compileResult);
|
||||||
|
const lifecycle = useSchemetaSelector(store, (state) => state.lifecycle);
|
||||||
|
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 apiVersion = state.compileResult && typeof state.compileResult.api_version === "string" ? state.compileResult.api_version : null;
|
||||||
|
return apiVersion ?? "-";
|
||||||
|
});
|
||||||
|
|
||||||
|
const actions = useMemo<WorkflowAction[]>(
|
||||||
|
() => [
|
||||||
|
{ id: "load-sample", label: "Load Sample JSON" },
|
||||||
|
{ id: "compile", label: "Compile" },
|
||||||
|
{ id: "analyze", label: "Analyze" },
|
||||||
|
{ id: "layout-auto", label: "Auto Layout" },
|
||||||
|
{ id: "layout-tidy", label: "Auto Tidy" },
|
||||||
|
{ id: "reset-sample", label: "Reset Sample" }
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const status = jsonError
|
||||||
|
? `JSON parse failed: ${jsonError}`
|
||||||
|
: lifecycle.isCompiling
|
||||||
|
? `${lifecycle.lastAction ?? "Working"}...`
|
||||||
|
: lifecycle.lastError
|
||||||
|
? `${lifecycle.lastAction ?? "Action"} failed: ${lifecycle.lastError}`
|
||||||
|
: lifecycle.lastAction
|
||||||
|
? `${lifecycle.lastAction} complete`
|
||||||
|
: "Idle";
|
||||||
|
const statusTone: TopBarStatusTone = jsonError
|
||||||
|
? "error"
|
||||||
|
: lifecycle.isCompiling
|
||||||
|
? "busy"
|
||||||
|
: lifecycle.lastError
|
||||||
|
? "error"
|
||||||
|
: lifecycle.lastAction
|
||||||
|
? "success"
|
||||||
|
: "idle";
|
||||||
|
|
||||||
|
async function runAction(actionId: WorkflowActionId) {
|
||||||
|
const action = actions.find((item) => item.id === actionId);
|
||||||
|
if (!action) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsApi.beginCompile(action.label);
|
||||||
|
try {
|
||||||
|
if (action.id === "load-sample" || action.id === "reset-sample") {
|
||||||
|
const parsed = actionsApi.applyJsonText(JSON.stringify(SAMPLE_PAYLOAD));
|
||||||
|
if (!parsed.ok) {
|
||||||
|
throw new Error(parsed.error);
|
||||||
|
}
|
||||||
|
actionsApi.setCompileResult(null);
|
||||||
|
actionsApi.setSelection({ selectedRefs: [], selectedNet: null, selectedPin: null });
|
||||||
|
actionsApi.setViewport({ scale: 1, panX: 40, panY: 40 });
|
||||||
|
actionsApi.completeCompile(action.label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = getPayloadOrThrow(store.getState().model);
|
||||||
|
|
||||||
|
switch (action.id) {
|
||||||
|
case "compile":
|
||||||
|
{
|
||||||
|
const result = await compile(payload, { preserve_placement: true });
|
||||||
|
actionsApi.setCompileResult(result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "analyze":
|
||||||
|
{
|
||||||
|
const result = await analyze(payload);
|
||||||
|
actionsApi.setCompileResult(toCompileFromAnalyze(result));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "layout-auto":
|
||||||
|
{
|
||||||
|
const result = await autoLayout(payload);
|
||||||
|
if (result.model) {
|
||||||
|
actionsApi.setModel(result.model);
|
||||||
|
}
|
||||||
|
if (result.compile) {
|
||||||
|
actionsApi.setCompileResult(result.compile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "layout-tidy":
|
||||||
|
{
|
||||||
|
const result = await tidyLayout(payload);
|
||||||
|
if (result.model) {
|
||||||
|
actionsApi.setModel(result.model);
|
||||||
|
}
|
||||||
|
if (result.compile) {
|
||||||
|
actionsApi.setCompileResult(result.compile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsApi.completeCompile(action.label);
|
||||||
|
} catch (err) {
|
||||||
|
actionsApi.failCompile(action.label, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<div className="app-shell">
|
||||||
|
<TopBar
|
||||||
|
title="React Frontend Skeleton"
|
||||||
|
actions={actions.map((action) => ({
|
||||||
|
id: action.id,
|
||||||
|
label: action.label,
|
||||||
|
onClick: () => {
|
||||||
|
void runAction(action.id);
|
||||||
|
},
|
||||||
|
disabled: lifecycle.isCompiling
|
||||||
|
}))}
|
||||||
|
statusMessage={status}
|
||||||
|
statusTone={statusTone}
|
||||||
|
apiVersion={lastApiVersion}
|
||||||
|
/>
|
||||||
|
<div className="workspace-grid">
|
||||||
|
<LeftPanel
|
||||||
|
model={model}
|
||||||
|
selection={selection}
|
||||||
|
onSelectInstance={(ref) =>
|
||||||
|
actionsApi.setSelection({
|
||||||
|
selectedRefs: selection.selectedRefs.includes(ref) ? [] : [ref],
|
||||||
|
selectedNet: null,
|
||||||
|
selectedPin: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onSelectNet={(name) =>
|
||||||
|
actionsApi.setSelection({
|
||||||
|
selectedRefs: [],
|
||||||
|
selectedNet: selection.selectedNet === name ? null : name,
|
||||||
|
selectedPin: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<CanvasArea store={store} />
|
||||||
|
<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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import type {
|
||||||
|
AnalyzeResponse,
|
||||||
|
CompileResponse,
|
||||||
|
LayoutActionResponse,
|
||||||
|
SchemetaRequest
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
async function postJson<TResponse>(path: string, body: unknown): Promise<TResponse> {
|
||||||
|
const response = await fetch(path, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = (await response.json()) as TResponse & {
|
||||||
|
error?: { message?: string };
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const message = data?.error?.message ?? data?.message ?? `Request failed with status ${response.status}`;
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compile(payload: unknown, options: Record<string, unknown> = {}): Promise<CompileResponse> {
|
||||||
|
const body: SchemetaRequest = { payload, options };
|
||||||
|
return postJson<CompileResponse>("/compile", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function analyze(payload: unknown, options: Record<string, unknown> = {}): Promise<AnalyzeResponse> {
|
||||||
|
const body: SchemetaRequest = { payload, options };
|
||||||
|
return postJson<AnalyzeResponse>("/analyze", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function autoLayout(payload: unknown, options: Record<string, unknown> = {}): Promise<LayoutActionResponse> {
|
||||||
|
const body: SchemetaRequest = { payload, options };
|
||||||
|
return postJson<LayoutActionResponse>("/layout/auto", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tidyLayout(payload: unknown, options: Record<string, unknown> = {}): Promise<LayoutActionResponse> {
|
||||||
|
const body: SchemetaRequest = { payload, options };
|
||||||
|
return postJson<LayoutActionResponse>("/layout/tidy", body);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
export type SchemetaRequest<TPayload = unknown, TOptions = Record<string, unknown>> = {
|
||||||
|
payload: TPayload;
|
||||||
|
options?: TOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemetaEnvelope = {
|
||||||
|
api_version?: string;
|
||||||
|
schema_version?: string;
|
||||||
|
request_id?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CompileResponse = SchemetaEnvelope & {
|
||||||
|
ok?: boolean;
|
||||||
|
errors?: unknown[];
|
||||||
|
warnings?: unknown[];
|
||||||
|
svg?: string;
|
||||||
|
layout?: {
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
placed?: Array<Record<string, unknown>>;
|
||||||
|
};
|
||||||
|
layout_metrics?: Record<string, number>;
|
||||||
|
topology?: Record<string, unknown>;
|
||||||
|
focus_map?: Record<string, unknown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AnalyzeResponse = SchemetaEnvelope & {
|
||||||
|
ok?: boolean;
|
||||||
|
errors?: unknown[];
|
||||||
|
warnings?: unknown[];
|
||||||
|
topology?: Record<string, unknown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LayoutActionResponse = SchemetaEnvelope & {
|
||||||
|
ok?: boolean;
|
||||||
|
model?: Record<string, unknown>;
|
||||||
|
compile?: CompileResponse;
|
||||||
|
};
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import type { SchemetaModel, SelectionSlice } from "../state";
|
||||||
|
|
||||||
|
type LeftPanelProps = {
|
||||||
|
model: SchemetaModel | null;
|
||||||
|
selection: SelectionSlice;
|
||||||
|
onSelectInstance: (ref: string) => void;
|
||||||
|
onSelectNet: (name: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NetRow = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function asNetLabel(net: Record<string, unknown>, index: number): NetRow {
|
||||||
|
const name = typeof net.name === "string" && net.name.length > 0 ? net.name : null;
|
||||||
|
const id = name ?? `net-${index + 1}`;
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
label: name ?? `Net ${index + 1}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LeftPanel({ model, selection, onSelectInstance, onSelectNet }: LeftPanelProps) {
|
||||||
|
const [filterText, setFilterText] = useState("");
|
||||||
|
|
||||||
|
const filter = filterText.trim().toLowerCase();
|
||||||
|
const instances = model?.instances ?? [];
|
||||||
|
const netsRaw = (model?.nets ?? []).filter((item): item is Record<string, unknown> => typeof item === "object" && item !== null);
|
||||||
|
const nets = netsRaw.map(asNetLabel);
|
||||||
|
|
||||||
|
const filteredInstances = useMemo(
|
||||||
|
() =>
|
||||||
|
instances.filter((instance) => {
|
||||||
|
if (!filter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const symbol = typeof instance.symbol === "string" ? instance.symbol : "";
|
||||||
|
const part = typeof instance.part === "string" ? instance.part : "";
|
||||||
|
return `${instance.ref} ${symbol} ${part}`.toLowerCase().includes(filter);
|
||||||
|
}),
|
||||||
|
[filter, instances]
|
||||||
|
);
|
||||||
|
|
||||||
|
const filteredNets = useMemo(
|
||||||
|
() =>
|
||||||
|
nets.filter((net) => {
|
||||||
|
if (!filter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return net.label.toLowerCase().includes(filter) || net.id.toLowerCase().includes(filter);
|
||||||
|
}),
|
||||||
|
[filter, nets]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside className="panel panel--left" aria-label="Left panel">
|
||||||
|
<h2 className="panel__title">Model Browser</h2>
|
||||||
|
<input
|
||||||
|
aria-label="Filter instances and nets"
|
||||||
|
type="search"
|
||||||
|
value={filterText}
|
||||||
|
onChange={(event) => setFilterText(event.target.value)}
|
||||||
|
placeholder="Filter refs, parts, nets..."
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h3>Instances ({filteredInstances.length})</h3>
|
||||||
|
<ul>
|
||||||
|
{filteredInstances.map((instance) => {
|
||||||
|
const isSelected = selection.selectedRefs.includes(instance.ref);
|
||||||
|
const descriptor = instance.symbol ?? instance.part ?? "component";
|
||||||
|
return (
|
||||||
|
<li key={instance.ref}>
|
||||||
|
<button type="button" onClick={() => onSelectInstance(instance.ref)}>
|
||||||
|
{isSelected ? "[x]" : "[ ]"} {instance.ref} - {descriptor}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Nets ({filteredNets.length})</h3>
|
||||||
|
<ul>
|
||||||
|
{filteredNets.map((net) => {
|
||||||
|
const isSelected = selection.selectedNet === net.id;
|
||||||
|
return (
|
||||||
|
<li key={net.id}>
|
||||||
|
<button type="button" onClick={() => onSelectNet(net.id)}>
|
||||||
|
{isSelected ? "[x]" : "[ ]"} {net.label}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</aside>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import type { SchemetaModel, SelectionSlice } from "../state";
|
||||||
|
|
||||||
|
type RightInspectorProps = {
|
||||||
|
model: SchemetaModel | null;
|
||||||
|
selection: SelectionSlice;
|
||||||
|
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 {
|
||||||
|
if (typeof value !== "object" || value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return value as Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asList(value: unknown): unknown[] {
|
||||||
|
return Array.isArray(value) ? value : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function toSnippet(value: unknown, fallback: string): string {
|
||||||
|
if (value == null) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "string") {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JSON.stringify(value, null, 2);
|
||||||
|
} catch {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RightInspector({
|
||||||
|
model,
|
||||||
|
selection,
|
||||||
|
compileResult,
|
||||||
|
jsonText,
|
||||||
|
jsonError,
|
||||||
|
onJsonTextChange,
|
||||||
|
onApplyJson,
|
||||||
|
onValidateJson,
|
||||||
|
onFormatJson,
|
||||||
|
onSortJson,
|
||||||
|
onCopyRepro
|
||||||
|
}: RightInspectorProps) {
|
||||||
|
const selectedRef = selection.selectedRefs[0] ?? null;
|
||||||
|
const selectedInstance = selectedRef ? (model?.instances ?? []).find((instance) => instance.ref === selectedRef) : null;
|
||||||
|
|
||||||
|
const compile = asRecord(compileResult);
|
||||||
|
const errors = asList(compile?.errors);
|
||||||
|
const warnings = asList(compile?.warnings);
|
||||||
|
const topology = compile?.topology;
|
||||||
|
const layoutMetrics = compile?.layout_metrics;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside className="panel panel--right" aria-label="Right inspector">
|
||||||
|
<h2 className="panel__title">Selection Summary</h2>
|
||||||
|
<p className="panel__body">Refs: {selection.selectedRefs.length > 0 ? selection.selectedRefs.join(", ") : "None"}</p>
|
||||||
|
<p className="panel__body">Net: {selection.selectedNet ?? "None"}</p>
|
||||||
|
<p className="panel__body">
|
||||||
|
Pin: {selection.selectedPin ? `${selection.selectedPin.ref}.${selection.selectedPin.pin}` : "None"}
|
||||||
|
</p>
|
||||||
|
<p className="panel__body">
|
||||||
|
Focused Component: {selectedInstance ? `${selectedInstance.ref} (${selectedInstance.symbol ?? selectedInstance.part ?? "component"})` : "None"}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2 className="panel__title">Diagnostics</h2>
|
||||||
|
<p className="panel__body">Errors: {errors.length}</p>
|
||||||
|
<p className="panel__body">Warnings: {warnings.length}</p>
|
||||||
|
<pre>{toSnippet(errors[0], "No error diagnostics yet.")}</pre>
|
||||||
|
<pre>{toSnippet(warnings[0], "No warning diagnostics yet.")}</pre>
|
||||||
|
|
||||||
|
<h2 className="panel__title">Topology Snippet</h2>
|
||||||
|
<pre>{toSnippet(topology, "No topology available yet.")}</pre>
|
||||||
|
|
||||||
|
<h2 className="panel__title">Layout Metrics</h2>
|
||||||
|
<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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
export type TopBarAction = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
onClick: () => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TopBarStatusTone = "idle" | "busy" | "success" | "error";
|
||||||
|
|
||||||
|
type TopBarProps = {
|
||||||
|
title: string;
|
||||||
|
actions: TopBarAction[];
|
||||||
|
statusMessage: string;
|
||||||
|
statusTone: TopBarStatusTone;
|
||||||
|
apiVersion: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function TopBar({ title, actions, statusMessage, statusTone, apiVersion }: TopBarProps) {
|
||||||
|
return (
|
||||||
|
<header className="topbar" role="banner">
|
||||||
|
<div className="topbar__brand">Schemeta</div>
|
||||||
|
<div className="topbar__title">{title}</div>
|
||||||
|
<div className="topbar__actions" role="toolbar" aria-label="Workflow actions">
|
||||||
|
{actions.map((action) => (
|
||||||
|
<button key={action.id} type="button" onClick={action.onClick} disabled={action.disabled === true}>
|
||||||
|
{action.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="topbar__meta">
|
||||||
|
<span>Status: {statusMessage}</span>
|
||||||
|
<span>Level: {statusTone}</span>
|
||||||
|
<span>API: {apiVersion}</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"title": "Dual-Rail Power Tree",
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"symbols": {},
|
||||||
|
"instances": [
|
||||||
|
{ "ref": "J1", "part": "connector", "properties": { "value": "VIN/GND" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U1", "part": "generic", "properties": { "value": "Buck 12V->5V" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U2", "part": "generic", "properties": { "value": "LDO 5V->3V3" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U3", "part": "generic", "properties": { "value": "MCU" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U4", "part": "generic", "properties": { "value": "RF Module" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C1", "part": "capacitor", "properties": { "value": "22uF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C2", "part": "capacitor", "properties": { "value": "10uF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C3", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C4", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } }
|
||||||
|
],
|
||||||
|
"nets": [
|
||||||
|
{ "name": "VIN", "class": "power", "nodes": [ { "ref": "J1", "pin": "1" }, { "ref": "U1", "pin": "VIN" } ] },
|
||||||
|
{ "name": "5V", "class": "power", "nodes": [ { "ref": "U1", "pin": "VOUT" }, { "ref": "U2", "pin": "VIN" }, { "ref": "C1", "pin": "1" }, { "ref": "C2", "pin": "1" } ] },
|
||||||
|
{ "name": "3V3", "class": "power", "nodes": [ { "ref": "U2", "pin": "VOUT" }, { "ref": "U3", "pin": "VCC" }, { "ref": "U4", "pin": "VCC" }, { "ref": "C3", "pin": "1" }, { "ref": "C4", "pin": "1" } ] },
|
||||||
|
{ "name": "GND", "class": "ground", "nodes": [ { "ref": "J1", "pin": "2" }, { "ref": "U1", "pin": "GND" }, { "ref": "U2", "pin": "GND" }, { "ref": "U3", "pin": "GND" }, { "ref": "U4", "pin": "GND" }, { "ref": "C1", "pin": "2" }, { "ref": "C2", "pin": "2" }, { "ref": "C3", "pin": "2" }, { "ref": "C4", "pin": "2" } ] },
|
||||||
|
{ "name": "SPI_CLK", "class": "clock", "nodes": [ { "ref": "U3", "pin": "SCLK" }, { "ref": "U4", "pin": "SCLK" } ] },
|
||||||
|
{ "name": "SPI_MOSI", "class": "signal", "nodes": [ { "ref": "U3", "pin": "MOSI" }, { "ref": "U4", "pin": "MOSI" } ] },
|
||||||
|
{ "name": "SPI_MISO", "class": "signal", "nodes": [ { "ref": "U3", "pin": "MISO" }, { "ref": "U4", "pin": "MISO" } ] }
|
||||||
|
],
|
||||||
|
"constraints": {
|
||||||
|
"groups": [
|
||||||
|
{ "name": "source", "members": ["J1", "U1", "C1"], "layout": "cluster" },
|
||||||
|
{ "name": "regulation", "members": ["U2", "C2"], "layout": "cluster" },
|
||||||
|
{ "name": "load", "members": ["U3", "U4", "C3", "C4"], "layout": "cluster" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"annotations": [
|
||||||
|
{ "text": "Power-chain fixture with SPI branch used for readability QA.", "x": 24, "y": 24 }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { useSchemetaActions, useSchemetaSelector, useSchemetaStoreState } from "./useSchemetaStore";
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { useMemo, useSyncExternalStore } from "react";
|
||||||
|
import type { SchemetaStore, StoreState } from "../state";
|
||||||
|
|
||||||
|
type Selector<TSelected> = (state: StoreState) => TSelected;
|
||||||
|
|
||||||
|
export function useSchemetaStoreState(store: SchemetaStore): StoreState {
|
||||||
|
return useSyncExternalStore(store.subscribe, store.getState, store.getState);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSchemetaSelector<TSelected>(store: SchemetaStore, selector: Selector<TSelected>): TSelected {
|
||||||
|
const state = useSchemetaStoreState(store);
|
||||||
|
return useMemo(() => selector(state), [selector, state]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSchemetaActions(store: SchemetaStore): SchemetaStore["actions"] {
|
||||||
|
return store.actions;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import React from "react";
|
||||||
|
import ReactDOM from "react-dom/client";
|
||||||
|
import { App } from "./App";
|
||||||
|
import "./styles.css";
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./store.js";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { createInitialState, createSchemetaStore } from "./store.js";
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
export type SchemetaPlacement = {
|
||||||
|
x: number | null;
|
||||||
|
y: number | null;
|
||||||
|
rotation?: number;
|
||||||
|
locked?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemetaInstance = {
|
||||||
|
ref: string;
|
||||||
|
symbol?: string;
|
||||||
|
part?: string;
|
||||||
|
properties?: Record<string, unknown>;
|
||||||
|
placement: SchemetaPlacement;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemetaModel = {
|
||||||
|
meta?: Record<string, unknown>;
|
||||||
|
symbols?: Record<string, unknown>;
|
||||||
|
instances: SchemetaInstance[];
|
||||||
|
nets?: Array<Record<string, unknown>>;
|
||||||
|
constraints?: Record<string, unknown>;
|
||||||
|
annotations?: Array<Record<string, unknown>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CompileResult = {
|
||||||
|
api_version?: string;
|
||||||
|
schema_version?: string;
|
||||||
|
request_id?: string;
|
||||||
|
ok: boolean;
|
||||||
|
errors: Array<Record<string, unknown>>;
|
||||||
|
warnings: Array<Record<string, unknown>>;
|
||||||
|
layout?: Record<string, unknown>;
|
||||||
|
layout_metrics?: Record<string, unknown>;
|
||||||
|
render_mode_used?: string;
|
||||||
|
svg?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SelectionSlice = {
|
||||||
|
selectedRefs: string[];
|
||||||
|
selectedNet: string | null;
|
||||||
|
selectedPin: { ref: string; pin: string } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ViewportSlice = {
|
||||||
|
scale: number;
|
||||||
|
panX: number;
|
||||||
|
panY: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UiFlagsSlice = {
|
||||||
|
showLabels: boolean;
|
||||||
|
isolateNet: boolean;
|
||||||
|
isolateComponent: boolean;
|
||||||
|
renderMode: string;
|
||||||
|
jsonError: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LifecycleSlice = {
|
||||||
|
isCompiling: boolean;
|
||||||
|
lastError: string | null;
|
||||||
|
lastAction: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type StateSnapshot = {
|
||||||
|
model: SchemetaModel | null;
|
||||||
|
compileResult: CompileResult | null;
|
||||||
|
selection: SelectionSlice;
|
||||||
|
viewport: ViewportSlice;
|
||||||
|
uiFlags: UiFlagsSlice;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type StoreState = {
|
||||||
|
model: SchemetaModel | null;
|
||||||
|
compileResult: CompileResult | null;
|
||||||
|
selection: SelectionSlice;
|
||||||
|
viewport: ViewportSlice;
|
||||||
|
uiFlags: UiFlagsSlice;
|
||||||
|
lifecycle: LifecycleSlice;
|
||||||
|
history: {
|
||||||
|
past: Array<{ label: string; snapshot: StateSnapshot }>;
|
||||||
|
future: Array<{ label: string; snapshot: StateSnapshot }>;
|
||||||
|
limit: number;
|
||||||
|
};
|
||||||
|
transaction: {
|
||||||
|
active: boolean;
|
||||||
|
label: string | null;
|
||||||
|
before: StateSnapshot | null;
|
||||||
|
dirty: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemetaStore = {
|
||||||
|
getState(): StoreState;
|
||||||
|
subscribe(listener: (next: StoreState, prev: StoreState, action: string) => void): () => void;
|
||||||
|
actions: {
|
||||||
|
setModel(model: unknown): void;
|
||||||
|
setCompileResult(compileResult: unknown): void;
|
||||||
|
setSelection(selection: Partial<SelectionSlice>): void;
|
||||||
|
moveComponent(ref: string, placement: Partial<SchemetaPlacement>): void;
|
||||||
|
setViewport(viewport: Partial<ViewportSlice>): void;
|
||||||
|
setUiFlags(uiFlags: Partial<UiFlagsSlice>): void;
|
||||||
|
setLifecycle(lifecycle: Partial<LifecycleSlice>): void;
|
||||||
|
beginCompile(action: string): void;
|
||||||
|
completeCompile(action: string): void;
|
||||||
|
failCompile(action: string, error: unknown): void;
|
||||||
|
applyJsonText(jsonText: string): { ok: true } | { ok: false; error: string };
|
||||||
|
beginTransaction(label?: string): boolean;
|
||||||
|
commitTransaction(): boolean;
|
||||||
|
rollbackTransaction(): boolean;
|
||||||
|
undo(): void;
|
||||||
|
redo(): void;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createInitialState(overrides?: Partial<StoreState>): StoreState;
|
||||||
|
export function createSchemetaStore(initialState?: Partial<StoreState>): SchemetaStore;
|
||||||
@@ -0,0 +1,718 @@
|
|||||||
|
const DEFAULT_HISTORY_LIMIT = 80;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SchemetaPlacement
|
||||||
|
* @property {number | null} x
|
||||||
|
* @property {number | null} y
|
||||||
|
* @property {number} [rotation]
|
||||||
|
* @property {boolean} [locked]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SchemetaInstance
|
||||||
|
* @property {string} ref
|
||||||
|
* @property {string} [symbol]
|
||||||
|
* @property {string} [part]
|
||||||
|
* @property {Record<string, unknown>} [properties]
|
||||||
|
* @property {SchemetaPlacement} placement
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SchemetaModel
|
||||||
|
* @property {Record<string, unknown>} [meta]
|
||||||
|
* @property {Record<string, unknown>} [symbols]
|
||||||
|
* @property {SchemetaInstance[]} instances
|
||||||
|
* @property {Array<Record<string, unknown>>} [nets]
|
||||||
|
* @property {Record<string, unknown>} [constraints]
|
||||||
|
* @property {Array<Record<string, unknown>>} [annotations]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} CompileResult
|
||||||
|
* @property {string} [api_version]
|
||||||
|
* @property {string} [schema_version]
|
||||||
|
* @property {string} [request_id]
|
||||||
|
* @property {boolean} ok
|
||||||
|
* @property {Array<Record<string, unknown>>} errors
|
||||||
|
* @property {Array<Record<string, unknown>>} warnings
|
||||||
|
* @property {Record<string, unknown>} [layout]
|
||||||
|
* @property {Record<string, unknown>} [layout_metrics]
|
||||||
|
* @property {string} [render_mode_used]
|
||||||
|
* @property {string} [svg]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{ ref: string, pin: string } | null} SelectedPin
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SelectionSlice
|
||||||
|
* @property {string[]} selectedRefs
|
||||||
|
* @property {string | null} selectedNet
|
||||||
|
* @property {SelectedPin} selectedPin
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} ViewportSlice
|
||||||
|
* @property {number} scale
|
||||||
|
* @property {number} panX
|
||||||
|
* @property {number} panY
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} UiFlagsSlice
|
||||||
|
* @property {boolean} showLabels
|
||||||
|
* @property {boolean} isolateNet
|
||||||
|
* @property {boolean} isolateComponent
|
||||||
|
* @property {string} renderMode
|
||||||
|
* @property {string | null} jsonError
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} LifecycleSlice
|
||||||
|
* @property {boolean} isCompiling
|
||||||
|
* @property {string | null} lastError
|
||||||
|
* @property {string | null} lastAction
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} StateSnapshot
|
||||||
|
* @property {SchemetaModel | null} model
|
||||||
|
* @property {CompileResult | null} compileResult
|
||||||
|
* @property {SelectionSlice} selection
|
||||||
|
* @property {ViewportSlice} viewport
|
||||||
|
* @property {UiFlagsSlice} uiFlags
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} HistoryEntry
|
||||||
|
* @property {string} label
|
||||||
|
* @property {StateSnapshot} snapshot
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} StoreState
|
||||||
|
* @property {SchemetaModel | null} model
|
||||||
|
* @property {CompileResult | null} compileResult
|
||||||
|
* @property {SelectionSlice} selection
|
||||||
|
* @property {ViewportSlice} viewport
|
||||||
|
* @property {UiFlagsSlice} uiFlags
|
||||||
|
* @property {LifecycleSlice} lifecycle
|
||||||
|
* @property {{ past: HistoryEntry[], future: HistoryEntry[], limit: number }} history
|
||||||
|
* @property {{ active: boolean, label: string | null, before: StateSnapshot | null, dirty: boolean }} transaction
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {unknown} value
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
function deepClone(value) {
|
||||||
|
if (typeof structuredClone === "function") {
|
||||||
|
return structuredClone(value);
|
||||||
|
}
|
||||||
|
return JSON.parse(JSON.stringify(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {SelectionSlice | Partial<SelectionSlice>} selection
|
||||||
|
* @returns {SelectionSlice}
|
||||||
|
*/
|
||||||
|
function normalizeSelection(selection) {
|
||||||
|
const selectedRefs = [...new Set((selection.selectedRefs ?? []).filter(Boolean))].sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
|
const selectedNet = typeof selection.selectedNet === "string" && selection.selectedNet.length > 0 ? selection.selectedNet : null;
|
||||||
|
const selectedPin =
|
||||||
|
selection.selectedPin && typeof selection.selectedPin.ref === "string" && typeof selection.selectedPin.pin === "string"
|
||||||
|
? { ref: selection.selectedPin.ref, pin: selection.selectedPin.pin }
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
selectedRefs,
|
||||||
|
selectedNet,
|
||||||
|
selectedPin
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Partial<ViewportSlice>} viewport
|
||||||
|
* @param {ViewportSlice} prev
|
||||||
|
* @returns {ViewportSlice}
|
||||||
|
*/
|
||||||
|
function normalizeViewport(viewport, prev) {
|
||||||
|
const nextScale = Number.isFinite(viewport.scale) ? Number(viewport.scale) : prev.scale;
|
||||||
|
const nextPanX = Number.isFinite(viewport.panX) ? Number(viewport.panX) : prev.panX;
|
||||||
|
const nextPanY = Number.isFinite(viewport.panY) ? Number(viewport.panY) : prev.panY;
|
||||||
|
|
||||||
|
return {
|
||||||
|
scale: nextScale,
|
||||||
|
panX: nextPanX,
|
||||||
|
panY: nextPanY
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Partial<UiFlagsSlice>} uiFlags
|
||||||
|
* @param {UiFlagsSlice} prev
|
||||||
|
* @returns {UiFlagsSlice}
|
||||||
|
*/
|
||||||
|
function normalizeUiFlags(uiFlags, prev) {
|
||||||
|
return {
|
||||||
|
showLabels: typeof uiFlags.showLabels === "boolean" ? uiFlags.showLabels : prev.showLabels,
|
||||||
|
isolateNet: typeof uiFlags.isolateNet === "boolean" ? uiFlags.isolateNet : prev.isolateNet,
|
||||||
|
isolateComponent: typeof uiFlags.isolateComponent === "boolean" ? uiFlags.isolateComponent : prev.isolateComponent,
|
||||||
|
renderMode: typeof uiFlags.renderMode === "string" && uiFlags.renderMode.length > 0 ? uiFlags.renderMode : prev.renderMode,
|
||||||
|
jsonError:
|
||||||
|
uiFlags.jsonError === null || (typeof uiFlags.jsonError === "string" && uiFlags.jsonError.length > 0)
|
||||||
|
? uiFlags.jsonError
|
||||||
|
: prev.jsonError
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Partial<LifecycleSlice>} lifecycle
|
||||||
|
* @param {LifecycleSlice} prev
|
||||||
|
* @returns {LifecycleSlice}
|
||||||
|
*/
|
||||||
|
function normalizeLifecycle(lifecycle, prev) {
|
||||||
|
return {
|
||||||
|
isCompiling: typeof lifecycle.isCompiling === "boolean" ? lifecycle.isCompiling : prev.isCompiling,
|
||||||
|
lastError:
|
||||||
|
lifecycle.lastError === null || (typeof lifecycle.lastError === "string" && lifecycle.lastError.length > 0)
|
||||||
|
? lifecycle.lastError
|
||||||
|
: prev.lastError,
|
||||||
|
lastAction:
|
||||||
|
lifecycle.lastAction === null || (typeof lifecycle.lastAction === "string" && lifecycle.lastAction.length > 0)
|
||||||
|
? lifecycle.lastAction
|
||||||
|
: prev.lastAction
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @returns {StateSnapshot}
|
||||||
|
*/
|
||||||
|
function snapshotState(state) {
|
||||||
|
return {
|
||||||
|
model: deepClone(state.model),
|
||||||
|
compileResult: deepClone(state.compileResult),
|
||||||
|
selection: deepClone(state.selection),
|
||||||
|
viewport: deepClone(state.viewport),
|
||||||
|
uiFlags: deepClone(state.uiFlags)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {StateSnapshot} snapshot
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function restoreSnapshot(state, snapshot) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
model: deepClone(snapshot.model),
|
||||||
|
compileResult: deepClone(snapshot.compileResult),
|
||||||
|
selection: deepClone(snapshot.selection),
|
||||||
|
viewport: deepClone(snapshot.viewport),
|
||||||
|
uiFlags: deepClone(snapshot.uiFlags)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {string} label
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function pushHistoryEntry(state, label) {
|
||||||
|
const nextPast = [...state.history.past, { label, snapshot: snapshotState(state) }];
|
||||||
|
const overflow = Math.max(0, nextPast.length - state.history.limit);
|
||||||
|
const past = overflow > 0 ? nextPast.slice(overflow) : nextPast;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
history: {
|
||||||
|
...state.history,
|
||||||
|
past,
|
||||||
|
future: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} current
|
||||||
|
* @param {StoreState} candidate
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function hasCoreChange(current, candidate) {
|
||||||
|
return (
|
||||||
|
current.model !== candidate.model ||
|
||||||
|
current.compileResult !== candidate.compileResult ||
|
||||||
|
current.selection !== candidate.selection ||
|
||||||
|
current.viewport !== candidate.viewport ||
|
||||||
|
current.uiFlags !== candidate.uiFlags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function undoState(state) {
|
||||||
|
if (state.transaction.active || state.history.past.length === 0) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prev = state.history.past[state.history.past.length - 1];
|
||||||
|
const currentSnapshot = snapshotState(state);
|
||||||
|
const restored = restoreSnapshot(state, prev.snapshot);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...restored,
|
||||||
|
history: {
|
||||||
|
...state.history,
|
||||||
|
past: state.history.past.slice(0, -1),
|
||||||
|
future: [...state.history.future, { label: prev.label, snapshot: currentSnapshot }]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function redoState(state) {
|
||||||
|
if (state.transaction.active || state.history.future.length === 0) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = state.history.future[state.history.future.length - 1];
|
||||||
|
const currentSnapshot = snapshotState(state);
|
||||||
|
const restored = restoreSnapshot(state, next.snapshot);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...restored,
|
||||||
|
history: {
|
||||||
|
...state.history,
|
||||||
|
past: [...state.history.past, { label: next.label, snapshot: currentSnapshot }],
|
||||||
|
future: state.history.future.slice(0, -1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {string} label
|
||||||
|
* @param {(state: StoreState) => StoreState} recipe
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function applyMutation(state, label, recipe) {
|
||||||
|
const candidate = recipe(state);
|
||||||
|
if (!hasCoreChange(state, candidate)) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.transaction.active) {
|
||||||
|
return {
|
||||||
|
...candidate,
|
||||||
|
transaction: {
|
||||||
|
...state.transaction,
|
||||||
|
dirty: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const withHistory = pushHistoryEntry(state, label);
|
||||||
|
return {
|
||||||
|
...candidate,
|
||||||
|
history: withHistory.history,
|
||||||
|
transaction: state.transaction
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {unknown} model
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function setModelState(state, model) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
model: model == null ? null : deepClone(model)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {unknown} compileResult
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function setCompileResultState(state, compileResult) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
compileResult: compileResult == null ? null : deepClone(compileResult)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {Partial<SelectionSlice>} selection
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function setSelectionState(state, selection) {
|
||||||
|
const nextSelection = normalizeSelection({
|
||||||
|
selectedRefs: selection.selectedRefs ?? state.selection.selectedRefs,
|
||||||
|
selectedNet: selection.selectedNet ?? state.selection.selectedNet,
|
||||||
|
selectedPin: selection.selectedPin ?? state.selection.selectedPin
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
selection: nextSelection
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {string} ref
|
||||||
|
* @param {Partial<SchemetaPlacement>} placement
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function moveComponentState(state, ref, placement) {
|
||||||
|
if (!state.model || !Array.isArray(state.model.instances)) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
let touched = false;
|
||||||
|
const instances = state.model.instances.map((instance) => {
|
||||||
|
if (instance.ref !== ref) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPlacement = instance.placement ?? { x: null, y: null, rotation: 0, locked: false };
|
||||||
|
const nextPlacement = {
|
||||||
|
...currentPlacement,
|
||||||
|
x: Number.isFinite(placement.x) ? Math.round(Number(placement.x)) : currentPlacement.x,
|
||||||
|
y: Number.isFinite(placement.y) ? Math.round(Number(placement.y)) : currentPlacement.y,
|
||||||
|
rotation: Number.isFinite(placement.rotation) ? Number(placement.rotation) : currentPlacement.rotation,
|
||||||
|
locked: typeof placement.locked === "boolean" ? placement.locked : currentPlacement.locked
|
||||||
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
nextPlacement.x === currentPlacement.x &&
|
||||||
|
nextPlacement.y === currentPlacement.y &&
|
||||||
|
nextPlacement.rotation === currentPlacement.rotation &&
|
||||||
|
nextPlacement.locked === currentPlacement.locked
|
||||||
|
) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
touched = true;
|
||||||
|
return {
|
||||||
|
...instance,
|
||||||
|
placement: nextPlacement
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!touched) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
model: {
|
||||||
|
...state.model,
|
||||||
|
instances
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {string} text
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function applyJsonTextFailureState(state, text) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
uiFlags: normalizeUiFlags(
|
||||||
|
{
|
||||||
|
...state.uiFlags,
|
||||||
|
jsonError: text
|
||||||
|
},
|
||||||
|
state.uiFlags
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} state
|
||||||
|
* @param {Partial<LifecycleSlice>} lifecycle
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
function setLifecycleState(state, lifecycle) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
lifecycle: normalizeLifecycle(lifecycle, state.lifecycle)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Partial<StoreState>} [overrides]
|
||||||
|
* @returns {StoreState}
|
||||||
|
*/
|
||||||
|
export function createInitialState(overrides = {}) {
|
||||||
|
const historyLimit = Number.isInteger(overrides.history?.limit) ? overrides.history.limit : DEFAULT_HISTORY_LIMIT;
|
||||||
|
|
||||||
|
return {
|
||||||
|
model: overrides.model ? deepClone(overrides.model) : null,
|
||||||
|
compileResult: overrides.compileResult ? deepClone(overrides.compileResult) : null,
|
||||||
|
selection: normalizeSelection(overrides.selection ?? {}),
|
||||||
|
viewport: normalizeViewport(overrides.viewport ?? {}, { scale: 1, panX: 40, panY: 40 }),
|
||||||
|
uiFlags: normalizeUiFlags(overrides.uiFlags ?? {}, {
|
||||||
|
showLabels: true,
|
||||||
|
isolateNet: false,
|
||||||
|
isolateComponent: false,
|
||||||
|
renderMode: "schematic_stub",
|
||||||
|
jsonError: null
|
||||||
|
}),
|
||||||
|
lifecycle: normalizeLifecycle(overrides.lifecycle ?? {}, {
|
||||||
|
isCompiling: false,
|
||||||
|
lastError: null,
|
||||||
|
lastAction: null
|
||||||
|
}),
|
||||||
|
history: {
|
||||||
|
past: [],
|
||||||
|
future: [],
|
||||||
|
limit: historyLimit
|
||||||
|
},
|
||||||
|
transaction: {
|
||||||
|
active: false,
|
||||||
|
label: null,
|
||||||
|
before: null,
|
||||||
|
dirty: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Partial<StoreState>} [initialState]
|
||||||
|
*/
|
||||||
|
export function createSchemetaStore(initialState = {}) {
|
||||||
|
/** @type {StoreState} */
|
||||||
|
let state = createInitialState(initialState);
|
||||||
|
const listeners = new Set();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StoreState} nextState
|
||||||
|
* @param {string} action
|
||||||
|
*/
|
||||||
|
function publish(nextState, action) {
|
||||||
|
const prevState = state;
|
||||||
|
if (nextState === prevState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
state = nextState;
|
||||||
|
listeners.forEach((listener) => listener(state, prevState, action));
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
/** @param {unknown} model */
|
||||||
|
setModel(model) {
|
||||||
|
publish(applyMutation(state, "setModel", (s) => setModelState(s, model)), "setModel");
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {unknown} compileResult */
|
||||||
|
setCompileResult(compileResult) {
|
||||||
|
publish(
|
||||||
|
applyMutation(state, "setCompileResult", (s) => setCompileResultState(s, compileResult)),
|
||||||
|
"setCompileResult"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {Partial<SelectionSlice>} selection */
|
||||||
|
setSelection(selection) {
|
||||||
|
publish(applyMutation(state, "setSelection", (s) => setSelectionState(s, selection)), "setSelection");
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} ref @param {Partial<SchemetaPlacement>} placement */
|
||||||
|
moveComponent(ref, placement) {
|
||||||
|
publish(applyMutation(state, `moveComponent:${ref}`, (s) => moveComponentState(s, ref, placement ?? {})), "moveComponent");
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {Partial<ViewportSlice>} viewport */
|
||||||
|
setViewport(viewport) {
|
||||||
|
publish(
|
||||||
|
applyMutation(state, "setViewport", (s) => ({ ...s, viewport: normalizeViewport(viewport ?? {}, s.viewport) })),
|
||||||
|
"setViewport"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {Partial<UiFlagsSlice>} uiFlags */
|
||||||
|
setUiFlags(uiFlags) {
|
||||||
|
publish(
|
||||||
|
applyMutation(state, "setUiFlags", (s) => ({ ...s, uiFlags: normalizeUiFlags(uiFlags ?? {}, s.uiFlags) })),
|
||||||
|
"setUiFlags"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {Partial<LifecycleSlice>} lifecycle */
|
||||||
|
setLifecycle(lifecycle) {
|
||||||
|
publish(setLifecycleState(state, lifecycle ?? {}), "setLifecycle");
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} action */
|
||||||
|
beginCompile(action) {
|
||||||
|
publish(
|
||||||
|
setLifecycleState(state, {
|
||||||
|
isCompiling: true,
|
||||||
|
lastAction: action || "compile",
|
||||||
|
lastError: null
|
||||||
|
}),
|
||||||
|
"beginCompile"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} action */
|
||||||
|
completeCompile(action) {
|
||||||
|
publish(
|
||||||
|
setLifecycleState(state, {
|
||||||
|
isCompiling: false,
|
||||||
|
lastAction: action || state.lifecycle.lastAction,
|
||||||
|
lastError: null
|
||||||
|
}),
|
||||||
|
"completeCompile"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} action @param {unknown} error */
|
||||||
|
failCompile(action, error) {
|
||||||
|
const message = error instanceof Error ? error.message : typeof error === "string" ? error : "Unknown error";
|
||||||
|
publish(
|
||||||
|
setLifecycleState(state, {
|
||||||
|
isCompiling: false,
|
||||||
|
lastAction: action || state.lifecycle.lastAction,
|
||||||
|
lastError: message
|
||||||
|
}),
|
||||||
|
"failCompile"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} jsonText */
|
||||||
|
applyJsonText(jsonText) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(jsonText);
|
||||||
|
const next = applyMutation(state, "applyJsonText", (s) => {
|
||||||
|
const withModel = setModelState(s, parsed);
|
||||||
|
return {
|
||||||
|
...withModel,
|
||||||
|
uiFlags: normalizeUiFlags({ ...withModel.uiFlags, jsonError: null }, withModel.uiFlags)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
publish(next, "applyJsonText");
|
||||||
|
return { ok: true };
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Invalid JSON";
|
||||||
|
publish(applyJsonTextFailureState(state, message), "applyJsonTextError");
|
||||||
|
return { ok: false, error: message };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {string} [label] */
|
||||||
|
beginTransaction(label = "transaction") {
|
||||||
|
if (state.transaction.active) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
publish(
|
||||||
|
{
|
||||||
|
...state,
|
||||||
|
transaction: {
|
||||||
|
active: true,
|
||||||
|
label,
|
||||||
|
before: snapshotState(state),
|
||||||
|
dirty: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"beginTransaction"
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
commitTransaction() {
|
||||||
|
if (!state.transaction.active) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tx = state.transaction;
|
||||||
|
let nextState = {
|
||||||
|
...state,
|
||||||
|
transaction: {
|
||||||
|
active: false,
|
||||||
|
label: null,
|
||||||
|
before: null,
|
||||||
|
dirty: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tx.dirty && tx.before) {
|
||||||
|
const nextPast = [...state.history.past, { label: tx.label ?? "transaction", snapshot: tx.before }];
|
||||||
|
const overflow = Math.max(0, nextPast.length - state.history.limit);
|
||||||
|
nextState = {
|
||||||
|
...nextState,
|
||||||
|
history: {
|
||||||
|
...state.history,
|
||||||
|
past: overflow > 0 ? nextPast.slice(overflow) : nextPast,
|
||||||
|
future: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
publish(nextState, "commitTransaction");
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
rollbackTransaction() {
|
||||||
|
if (!state.transaction.active) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tx = state.transaction;
|
||||||
|
const rolledBack = tx.before ? restoreSnapshot(state, tx.before) : state;
|
||||||
|
publish(
|
||||||
|
{
|
||||||
|
...rolledBack,
|
||||||
|
transaction: {
|
||||||
|
active: false,
|
||||||
|
label: null,
|
||||||
|
before: null,
|
||||||
|
dirty: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rollbackTransaction"
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
publish(undoState(state), "undo");
|
||||||
|
},
|
||||||
|
|
||||||
|
redo() {
|
||||||
|
publish(redoState(state), "redo");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getState() {
|
||||||
|
return state;
|
||||||
|
},
|
||||||
|
|
||||||
|
subscribe(listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
return () => {
|
||||||
|
listeners.delete(listener);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
actions
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,485 @@
|
|||||||
|
:root {
|
||||||
|
font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
|
||||||
|
color: #1a1a1a;
|
||||||
|
background: #f3f6f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#root {
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: auto auto 1fr;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
color: #f4f8ff;
|
||||||
|
background: linear-gradient(90deg, #0b2a42 0%, #164863 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__brand {
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__title {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.45rem;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__actions button {
|
||||||
|
padding: 0.35rem 0.6rem;
|
||||||
|
border: 1px solid rgba(232, 242, 250, 0.65);
|
||||||
|
border-radius: 6px;
|
||||||
|
background: rgba(8, 24, 38, 0.24);
|
||||||
|
color: #f2f8ff;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__actions button:hover:not(:disabled) {
|
||||||
|
background: rgba(8, 24, 38, 0.38);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__actions button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__meta {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 0.1rem;
|
||||||
|
font-size: 0.84rem;
|
||||||
|
color: #d7e6f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border-bottom: 1px solid #d7dde3;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar button {
|
||||||
|
padding: 0.45rem 0.7rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid #164863;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #164863;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar button:hover {
|
||||||
|
background: #eaf2f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar__meta {
|
||||||
|
margin-left: auto;
|
||||||
|
color: #4a5b66;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 280px 1fr 320px;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.75rem;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel,
|
||||||
|
.canvas {
|
||||||
|
border: 1px solid #d7dde3;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #ffffff;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
padding: 0.9rem;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__title {
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__body {
|
||||||
|
margin: 0;
|
||||||
|
color: #52626e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel input[type="search"] {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 0.7rem;
|
||||||
|
padding: 0.4rem 0.5rem;
|
||||||
|
border: 1px solid #9bb0c0;
|
||||||
|
border-radius: 6px;
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel h3 {
|
||||||
|
margin: 0.7rem 0 0.4rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #264258;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel ul {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
display: grid;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel li button {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
border: 1px solid #d2dee8;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fafcff;
|
||||||
|
padding: 0.32rem 0.45rem;
|
||||||
|
color: #173247;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel li button:hover {
|
||||||
|
background: #eef6fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel pre {
|
||||||
|
margin: 0.35rem 0 0.55rem;
|
||||||
|
border: 1px solid #dbe5ee;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f7fbff;
|
||||||
|
color: #274054;
|
||||||
|
padding: 0.45rem 0.55rem;
|
||||||
|
max-height: 8rem;
|
||||||
|
overflow: auto;
|
||||||
|
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 {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: auto 1fr;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #f7fbff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-bottom: 1px solid #dbe5ec;
|
||||||
|
background: linear-gradient(180deg, #ffffff 0%, #f3f8fc 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__toolbar button {
|
||||||
|
padding: 0.35rem 0.6rem;
|
||||||
|
border: 1px solid #8ca1b3;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #173247;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__toolbar button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__zoom-readout {
|
||||||
|
min-width: 6rem;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #21435a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__placeholder-control {
|
||||||
|
border-style: dashed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__surface {
|
||||||
|
position: relative;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: #f7fbff;
|
||||||
|
background-image:
|
||||||
|
linear-gradient(to right, #e6edf3 1px, transparent 1px),
|
||||||
|
linear-gradient(to bottom, #e6edf3 1px, transparent 1px);
|
||||||
|
background-size: 28px 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__surface:focus-visible {
|
||||||
|
outline: 2px solid #0a79c2;
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__selection-box {
|
||||||
|
position: absolute;
|
||||||
|
border: 1px solid #0a79c2;
|
||||||
|
background: rgba(10, 121, 194, 0.14);
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas__viewport {
|
||||||
|
position: relative;
|
||||||
|
width: 2200px;
|
||||||
|
height: 1500px;
|
||||||
|
transform-origin: 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wires {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-segment {
|
||||||
|
stroke: #5a6e7f;
|
||||||
|
stroke-width: 2.2px;
|
||||||
|
stroke-linecap: round;
|
||||||
|
opacity: 0.9;
|
||||||
|
pointer-events: stroke;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-segment.is-highlight {
|
||||||
|
stroke: #0b78bf;
|
||||||
|
stroke-width: 3px;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-segment.is-dimmed {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-label {
|
||||||
|
position: absolute;
|
||||||
|
transform: translate(-50%, calc(-100% - 6px));
|
||||||
|
padding: 0.1rem 0.3rem;
|
||||||
|
border: 1px solid rgba(144, 158, 171, 0.8);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
color: #243f53;
|
||||||
|
font-size: 0.66rem;
|
||||||
|
line-height: 1.1;
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
white-space: nowrap;
|
||||||
|
pointer-events: auto;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.canvas-wire-label {
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-label.is-highlight {
|
||||||
|
border-color: #0b78bf;
|
||||||
|
color: #0d4f7b;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wire-label.is-dimmed {
|
||||||
|
opacity: 0.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node {
|
||||||
|
position: absolute;
|
||||||
|
user-select: none;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__chrome {
|
||||||
|
width: 100%;
|
||||||
|
min-height: inherit;
|
||||||
|
border: 1px solid #406078;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: linear-gradient(180deg, #ffffff 0%, #f6fbff 100%);
|
||||||
|
box-shadow: 0 3px 10px rgba(38, 64, 89, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__content {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0.45rem 0.55rem 0.5rem;
|
||||||
|
transform-origin: 50% 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__ref {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
color: #113148;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__value {
|
||||||
|
margin-top: 0.15rem;
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
font-size: 0.74rem;
|
||||||
|
color: #405260;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pins {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin-col {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.14rem;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin-col--right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto 1fr;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 0.3rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin-col--right .canvas-node__pin {
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin-number {
|
||||||
|
font-size: 0.66rem;
|
||||||
|
color: #6c8090;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__pin-name {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
color: #2d475a;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node__lock {
|
||||||
|
margin-top: 0.35rem;
|
||||||
|
font-size: 0.64rem;
|
||||||
|
color: #925d00;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node.is-selected .canvas-node__chrome {
|
||||||
|
border-color: #0a79c2;
|
||||||
|
box-shadow: 0 0 0 2px rgba(10, 121, 194, 0.25), 0 4px 14px rgba(18, 53, 78, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-node.is-dragging .canvas-node__chrome {
|
||||||
|
cursor: grabbing;
|
||||||
|
box-shadow: 0 0 0 2px rgba(10, 121, 194, 0.3), 0 8px 18px rgba(12, 42, 66, 0.26);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1100px) {
|
||||||
|
.topbar {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar__meta {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: auto minmax(260px, 1fr) auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar__meta {
|
||||||
|
width: 100%;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowImportingTsExtensions": false,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
server: {
|
||||||
|
port: 5173,
|
||||||
|
proxy: {
|
||||||
|
"/compile": "http://localhost:8787",
|
||||||
|
"/analyze": "http://localhost:8787",
|
||||||
|
"/layout": "http://localhost:8787",
|
||||||
|
"/health": "http://localhost:8787"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preview: {
|
||||||
|
port: 4173
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -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)`;
|
||||||
@@ -364,11 +390,14 @@ function defaultProject() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileOptions() {
|
function compileOptions(extra = {}) {
|
||||||
return {
|
return {
|
||||||
render_mode: state.renderMode,
|
render_mode: state.renderMode,
|
||||||
show_labels: state.showLabels,
|
show_labels: state.showLabels,
|
||||||
generic_symbols: true
|
show_annotations: false,
|
||||||
|
show_legend: false,
|
||||||
|
generic_symbols: true,
|
||||||
|
...extra
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,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;
|
||||||
@@ -450,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) {
|
||||||
@@ -745,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" : "";
|
||||||
@@ -972,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>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1266,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1278,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1287,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1319,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1328,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) {
|
||||||
@@ -1675,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;
|
||||||
@@ -1692,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);
|
||||||
@@ -1771,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1783,6 +1887,7 @@ function renderCanvas() {
|
|||||||
applyLabelDensityByZoom(svg);
|
applyLabelDensityByZoom(svg);
|
||||||
resolveLabelCollisions(svg);
|
resolveLabelCollisions(svg);
|
||||||
}
|
}
|
||||||
|
updateSelectedNoteHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAll() {
|
function renderAll() {
|
||||||
@@ -1807,12 +1912,24 @@ async function compileModel(model, opts = {}) {
|
|||||||
const source = opts.source ?? "manual";
|
const source = opts.source ?? "manual";
|
||||||
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 compileLayoutOpts = preservePlacement
|
||||||
|
? {
|
||||||
|
preserve_placement: true,
|
||||||
|
auto_rotate: false,
|
||||||
|
respect_locks: true
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
preserve_placement: false,
|
||||||
|
auto_rotate: true,
|
||||||
|
respect_locks: false
|
||||||
|
};
|
||||||
|
|
||||||
setStatus(source === "drag" ? "Compiling after drag..." : "Compiling...");
|
setStatus(source === "drag" ? "Compiling after drag..." : "Compiling...");
|
||||||
try {
|
try {
|
||||||
const result = await apiPost("/compile", {
|
const result = await apiPost("/compile", {
|
||||||
payload: model,
|
payload: model,
|
||||||
options: compileOptions()
|
options: compileOptions(compileLayoutOpts)
|
||||||
});
|
});
|
||||||
|
|
||||||
state.model = applyCompileLayoutToModel(model, result);
|
state.model = applyCompileLayoutToModel(model, result);
|
||||||
@@ -1858,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2341,13 +2458,9 @@ async function validateJsonEditor() {
|
|||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(text);
|
const parsed = JSON.parse(text);
|
||||||
const out = await apiPost("/analyze", { payload: parsed });
|
const out = await apiPost("/analyze", { payload: parsed });
|
||||||
el.jsonFeedback.textContent = `Validation: ${out.errors.length} errors, ${out.warnings.length} warnings.`;
|
|
||||||
if (!out.errors.length && !out.warnings.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const first = out.errors[0] ?? out.warnings[0];
|
const first = out.errors[0] ?? out.warnings[0];
|
||||||
el.jsonFeedback.textContent += ` First issue: ${first.message}`;
|
const firstPath = first?.path ? ` (${first.path})` : "";
|
||||||
|
el.jsonFeedback.textContent = `Validation: ${out.errors.length} errors, ${out.warnings.length} warnings.${first ? ` First issue: ${first.message}${firstPath}` : ""}`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const p = parseJsonPositionError(text, err);
|
const p = parseJsonPositionError(text, err);
|
||||||
if (p.line != null) {
|
if (p.line != null) {
|
||||||
@@ -2365,6 +2478,28 @@ async function validateJsonEditor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function analyzeModelForImport(parsed, sourceName = "JSON") {
|
||||||
|
const out = await apiPost("/analyze", { payload: parsed });
|
||||||
|
if (out.errors.length) {
|
||||||
|
const first = out.errors[0];
|
||||||
|
const path = first.path ? ` (${first.path})` : "";
|
||||||
|
const msg = `${sourceName} blocked by validation: ${out.errors.length} error(s), ${out.warnings.length} warning(s). First error: ${first.message}${path}`;
|
||||||
|
return { ok: false, out, message: msg };
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstWarn = out.warnings[0];
|
||||||
|
if (firstWarn) {
|
||||||
|
const path = firstWarn.path ? ` (${firstWarn.path})` : "";
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
out,
|
||||||
|
message: `${sourceName} validated: ${out.errors.length} errors, ${out.warnings.length} warnings. First warning: ${firstWarn.message}${path}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ok: true, out, message: `${sourceName} validated: 0 errors, 0 warnings.` };
|
||||||
|
}
|
||||||
|
|
||||||
async function runLayoutAction(path) {
|
async function runLayoutAction(path) {
|
||||||
if (!state.model) {
|
if (!state.model) {
|
||||||
return;
|
return;
|
||||||
@@ -2375,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);
|
||||||
@@ -2411,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 = "";
|
||||||
@@ -2614,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
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2647,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");
|
||||||
@@ -3128,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 });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3295,10 +3432,9 @@ 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 });
|
await compileModel(state.model, { source: "drag", keepView: true, preservePlacement: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3344,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;
|
||||||
}
|
}
|
||||||
@@ -3570,6 +3705,11 @@ function setupEvents() {
|
|||||||
el.applyJsonBtn.addEventListener("click", async () => {
|
el.applyJsonBtn.addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(el.jsonEditor.value);
|
const parsed = JSON.parse(el.jsonEditor.value);
|
||||||
|
const analyzed = await analyzeModelForImport(parsed, "Apply JSON");
|
||||||
|
el.jsonFeedback.textContent = analyzed.message;
|
||||||
|
if (!analyzed.ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const before = state.model ? clone(state.model) : null;
|
const before = state.model ? clone(state.model) : null;
|
||||||
if (state.model) {
|
if (state.model) {
|
||||||
pushHistory("apply-json");
|
pushHistory("apply-json");
|
||||||
@@ -3579,7 +3719,7 @@ function setupEvents() {
|
|||||||
state.selectedNet = null;
|
state.selectedNet = null;
|
||||||
state.selectedPin = null;
|
state.selectedPin = null;
|
||||||
await compileModel(parsed, { fit: true });
|
await compileModel(parsed, { fit: true });
|
||||||
el.jsonFeedback.textContent = summarizeModelDelta(before, state.model);
|
el.jsonFeedback.textContent = `${summarizeModelDelta(before, state.model)} ${analyzed.out.warnings.length ? `Validation warnings: ${analyzed.out.warnings.length}.` : "Validation clean."}`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const p = parseJsonPositionError(el.jsonEditor.value, err);
|
const p = parseJsonPositionError(el.jsonEditor.value, err);
|
||||||
el.jsonFeedback.textContent = `Apply failed: ${p.message}`;
|
el.jsonFeedback.textContent = `Apply failed: ${p.message}`;
|
||||||
@@ -3613,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();
|
||||||
});
|
});
|
||||||
@@ -3634,6 +3798,12 @@ function setupEvents() {
|
|||||||
try {
|
try {
|
||||||
const content = await file.text();
|
const content = await file.text();
|
||||||
const parsed = JSON.parse(content);
|
const parsed = JSON.parse(content);
|
||||||
|
const analyzed = await analyzeModelForImport(parsed, "Import JSON");
|
||||||
|
if (!analyzed.ok) {
|
||||||
|
el.jsonFeedback.textContent = analyzed.message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const before = state.model ? clone(state.model) : null;
|
||||||
if (state.model) {
|
if (state.model) {
|
||||||
pushHistory("import-json");
|
pushHistory("import-json");
|
||||||
}
|
}
|
||||||
@@ -3641,6 +3811,7 @@ function setupEvents() {
|
|||||||
state.selectedNet = null;
|
state.selectedNet = null;
|
||||||
state.selectedPin = null;
|
state.selectedPin = null;
|
||||||
await compileModel(parsed, { fit: true });
|
await compileModel(parsed, { fit: true });
|
||||||
|
el.jsonFeedback.textContent = `${summarizeModelDelta(before, state.model)} Imported from file (${analyzed.out.warnings.length} warnings).`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setStatus(`Import failed: ${err.message}`, false);
|
setStatus(`Import failed: ${err.message}`, false);
|
||||||
}
|
}
|
||||||
@@ -3665,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 />
|
||||||
|
|||||||
@@ -1,91 +1,162 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"title": "ESP32 Audio Path"
|
"title": "ESP32 Smart Audio + Sensing Node"
|
||||||
},
|
},
|
||||||
"symbols": {
|
"symbols": {
|
||||||
"esp32_s3_supermini": {
|
"esp32_s3_supermini": {
|
||||||
"symbol_id": "esp32_s3_supermini",
|
"symbol_id": "esp32_s3_supermini",
|
||||||
"category": "microcontroller",
|
"category": "microcontroller",
|
||||||
"body": { "width": 160, "height": 240 },
|
"body": { "width": 180, "height": 280 },
|
||||||
"pins": [
|
"pins": [
|
||||||
{ "name": "3V3", "number": "1", "side": "left", "offset": 30, "type": "power_in" },
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 24, "type": "power_in" },
|
||||||
{ "name": "GND", "number": "2", "side": "left", "offset": 60, "type": "ground" },
|
{ "name": "GND", "number": "2", "side": "left", "offset": 56, "type": "ground" },
|
||||||
{ "name": "GPIO5", "number": "10", "side": "right", "offset": 40, "type": "output" },
|
{ "name": "GPIO5", "number": "10", "side": "right", "offset": 36, "type": "output" },
|
||||||
{ "name": "GPIO6", "number": "11", "side": "right", "offset": 70, "type": "output" },
|
{ "name": "GPIO6", "number": "11", "side": "right", "offset": 66, "type": "output" },
|
||||||
{ "name": "GPIO7", "number": "12", "side": "right", "offset": 100, "type": "output" }
|
{ "name": "GPIO7", "number": "12", "side": "right", "offset": 96, "type": "output" },
|
||||||
|
{ "name": "GPIO8", "number": "13", "side": "right", "offset": 126, "type": "input" },
|
||||||
|
{ "name": "GPIO9", "number": "14", "side": "right", "offset": 156, "type": "bidirectional" },
|
||||||
|
{ "name": "GPIO10", "number": "15", "side": "right", "offset": 186, "type": "bidirectional" },
|
||||||
|
{ "name": "GPIO11", "number": "16", "side": "right", "offset": 216, "type": "output" },
|
||||||
|
{ "name": "GPIO12", "number": "17", "side": "right", "offset": 246, "type": "output" }
|
||||||
],
|
],
|
||||||
"graphics": {
|
"graphics": {
|
||||||
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 160, "h": 240 }]
|
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 180, "h": 280 }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dac_i2s": {
|
"dac_i2s": {
|
||||||
"symbol_id": "dac_i2s",
|
"symbol_id": "dac_i2s",
|
||||||
"category": "audio",
|
"category": "audio",
|
||||||
"body": { "width": 140, "height": 180 },
|
"body": { "width": 160, "height": 200 },
|
||||||
"pins": [
|
"pins": [
|
||||||
{ "name": "3V3", "number": "1", "side": "left", "offset": 20, "type": "power_in" },
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 24, "type": "power_in" },
|
||||||
{ "name": "GND", "number": "2", "side": "left", "offset": 50, "type": "ground" },
|
{ "name": "GND", "number": "2", "side": "left", "offset": 54, "type": "ground" },
|
||||||
{ "name": "BCLK", "number": "3", "side": "left", "offset": 80, "type": "input" },
|
{ "name": "BCLK", "number": "3", "side": "left", "offset": 86, "type": "input" },
|
||||||
{ "name": "LRCLK", "number": "4", "side": "left", "offset": 110, "type": "input" },
|
{ "name": "LRCLK", "number": "4", "side": "left", "offset": 116, "type": "input" },
|
||||||
{ "name": "DIN", "number": "5", "side": "left", "offset": 140, "type": "input" },
|
{ "name": "DIN", "number": "5", "side": "left", "offset": 146, "type": "input" },
|
||||||
{ "name": "AOUT", "number": "6", "side": "right", "offset": 90, "type": "analog" }
|
{ "name": "AOUT", "number": "6", "side": "right", "offset": 96, "type": "analog" }
|
||||||
],
|
],
|
||||||
"graphics": {
|
"graphics": {
|
||||||
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 140, "h": 180 }]
|
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 160, "h": 200 }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"amp": {
|
"amp": {
|
||||||
"symbol_id": "amp",
|
"symbol_id": "amp",
|
||||||
"category": "output",
|
"category": "output",
|
||||||
"body": { "width": 120, "height": 120 },
|
"body": { "width": 130, "height": 130 },
|
||||||
"pins": [
|
"pins": [
|
||||||
{ "name": "5V", "number": "1", "side": "left", "offset": 20, "type": "power_in" },
|
{ "name": "5V", "number": "1", "side": "left", "offset": 22, "type": "power_in" },
|
||||||
{ "name": "GND", "number": "2", "side": "left", "offset": 50, "type": "ground" },
|
{ "name": "GND", "number": "2", "side": "left", "offset": 52, "type": "ground" },
|
||||||
{ "name": "IN", "number": "3", "side": "left", "offset": 80, "type": "input" },
|
{ "name": "IN", "number": "3", "side": "left", "offset": 84, "type": "input" },
|
||||||
{ "name": "SPK", "number": "4", "side": "right", "offset": 70, "type": "output" }
|
{ "name": "SPK", "number": "4", "side": "right", "offset": 74, "type": "output" }
|
||||||
],
|
],
|
||||||
"graphics": {
|
"graphics": {
|
||||||
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 120, "h": 120 }]
|
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 130, "h": 130 }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"psu": {
|
"psu": {
|
||||||
"symbol_id": "psu",
|
"symbol_id": "psu",
|
||||||
"category": "power",
|
"category": "power",
|
||||||
"body": { "width": 120, "height": 120 },
|
"body": { "width": 140, "height": 140 },
|
||||||
"pins": [
|
"pins": [
|
||||||
{ "name": "5V_OUT", "number": "1", "side": "right", "offset": 30, "type": "power_out" },
|
{ "name": "5V_OUT", "number": "1", "side": "right", "offset": 34, "type": "power_out" },
|
||||||
{ "name": "3V3_OUT", "number": "2", "side": "right", "offset": 60, "type": "power_out" },
|
{ "name": "3V3_OUT", "number": "2", "side": "right", "offset": 70, "type": "power_out" },
|
||||||
{ "name": "GND", "number": "3", "side": "right", "offset": 90, "type": "ground" }
|
{ "name": "GND", "number": "3", "side": "right", "offset": 104, "type": "ground" }
|
||||||
],
|
],
|
||||||
"graphics": {
|
"graphics": {
|
||||||
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 120, "h": 120 }]
|
"primitives": [{ "type": "rect", "x": 0, "y": 0, "w": 140, "h": 140 }]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"imu_i2c": {
|
||||||
|
"symbol_id": "imu_i2c",
|
||||||
|
"category": "sensor",
|
||||||
|
"body": { "width": 140, "height": 120 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 18, "type": "power_in" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 44, "type": "ground" },
|
||||||
|
{ "name": "SCL", "number": "3", "side": "left", "offset": 70, "type": "bidirectional" },
|
||||||
|
{ "name": "SDA", "number": "4", "side": "left", "offset": 96, "type": "bidirectional" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"oled_i2c": {
|
||||||
|
"symbol_id": "oled_i2c",
|
||||||
|
"category": "display",
|
||||||
|
"body": { "width": 140, "height": 120 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 18, "type": "power_in" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 44, "type": "ground" },
|
||||||
|
{ "name": "SCL", "number": "3", "side": "left", "offset": 70, "type": "bidirectional" },
|
||||||
|
{ "name": "SDA", "number": "4", "side": "left", "offset": 96, "type": "bidirectional" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mic_pre": {
|
||||||
|
"symbol_id": "mic_pre",
|
||||||
|
"category": "analog",
|
||||||
|
"body": { "width": 150, "height": 120 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "3V3", "number": "1", "side": "left", "offset": 20, "type": "power_in" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 48, "type": "ground" },
|
||||||
|
{ "name": "OUT", "number": "3", "side": "right", "offset": 62, "type": "analog" },
|
||||||
|
{ "name": "EN", "number": "4", "side": "left", "offset": 90, "type": "input" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"debug_header": {
|
||||||
|
"symbol_id": "debug_header",
|
||||||
|
"category": "connector",
|
||||||
|
"body": { "width": 130, "height": 80 },
|
||||||
|
"pins": [
|
||||||
|
{ "name": "1", "number": "1", "side": "right", "offset": 24, "type": "bidirectional" },
|
||||||
|
{ "name": "GND", "number": "2", "side": "left", "offset": 24, "type": "ground" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"instances": [
|
"instances": [
|
||||||
{ "ref": "U1", "symbol": "esp32_s3_supermini", "properties": { "value": "ESP32-S3" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
{ "ref": "U1", "symbol": "esp32_s3_supermini", "properties": { "value": "ESP32-S3" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
{ "ref": "U2", "symbol": "dac_i2s", "properties": { "value": "DAC" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
{ "ref": "U2", "symbol": "dac_i2s", "properties": { "value": "DAC" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
{ "ref": "U3", "symbol": "amp", "properties": { "value": "Amp" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
{ "ref": "U3", "symbol": "amp", "properties": { "value": "Class-D Amp" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
{ "ref": "U4", "symbol": "psu", "properties": { "value": "Power" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } }
|
{ "ref": "U4", "symbol": "psu", "properties": { "value": "5V/3V3 Power" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U5", "symbol": "imu_i2c", "properties": { "value": "IMU" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U6", "symbol": "oled_i2c", "properties": { "value": "OLED" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "U7", "symbol": "mic_pre", "properties": { "value": "Mic Preamp" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "J1", "symbol": "debug_header", "properties": { "value": "Debug Header" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "R1", "part": "resistor", "properties": { "value": "10k" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "R2", "part": "resistor", "properties": { "value": "10k" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C1", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C2", "part": "capacitor", "properties": { "value": "100nF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } },
|
||||||
|
{ "ref": "C3", "part": "capacitor", "properties": { "value": "1uF" }, "placement": { "x": null, "y": null, "rotation": 0, "locked": false } }
|
||||||
],
|
],
|
||||||
"nets": [
|
"nets": [
|
||||||
{ "name": "3V3", "class": "power", "nodes": [{ "ref": "U4", "pin": "3V3_OUT" }, { "ref": "U1", "pin": "3V3" }, { "ref": "U2", "pin": "3V3" }] },
|
{ "name": "3V3", "class": "power", "nodes": [{ "ref": "U4", "pin": "3V3_OUT" }, { "ref": "U1", "pin": "3V3" }, { "ref": "U2", "pin": "3V3" }, { "ref": "U5", "pin": "3V3" }, { "ref": "U6", "pin": "3V3" }, { "ref": "U7", "pin": "3V3" }, { "ref": "R1", "pin": "1" }, { "ref": "R2", "pin": "1" }, { "ref": "C1", "pin": "1" }, { "ref": "C2", "pin": "1" }] },
|
||||||
{ "name": "5V", "class": "power", "nodes": [{ "ref": "U4", "pin": "5V_OUT" }, { "ref": "U3", "pin": "5V" }] },
|
{ "name": "5V", "class": "power", "nodes": [{ "ref": "U4", "pin": "5V_OUT" }, { "ref": "U3", "pin": "5V" }] },
|
||||||
{ "name": "GND", "class": "ground", "nodes": [{ "ref": "U4", "pin": "GND" }, { "ref": "U1", "pin": "GND" }, { "ref": "U2", "pin": "GND" }, { "ref": "U3", "pin": "GND" }] },
|
{ "name": "GND", "class": "ground", "nodes": [{ "ref": "U4", "pin": "GND" }, { "ref": "U1", "pin": "GND" }, { "ref": "U2", "pin": "GND" }, { "ref": "U3", "pin": "GND" }, { "ref": "U5", "pin": "GND" }, { "ref": "U6", "pin": "GND" }, { "ref": "U7", "pin": "GND" }, { "ref": "J1", "pin": "GND" }, { "ref": "C1", "pin": "2" }, { "ref": "C2", "pin": "2" }, { "ref": "C3", "pin": "2" }] },
|
||||||
{ "name": "I2S_BCLK", "class": "clock", "nodes": [{ "ref": "U1", "pin": "GPIO5" }, { "ref": "U2", "pin": "BCLK" }] },
|
{ "name": "I2S_BCLK", "class": "clock", "nodes": [{ "ref": "U1", "pin": "GPIO5" }, { "ref": "U2", "pin": "BCLK" }] },
|
||||||
{ "name": "I2S_LRCLK", "class": "clock", "nodes": [{ "ref": "U1", "pin": "GPIO6" }, { "ref": "U2", "pin": "LRCLK" }] },
|
{ "name": "I2S_LRCLK", "class": "clock", "nodes": [{ "ref": "U1", "pin": "GPIO6" }, { "ref": "U2", "pin": "LRCLK" }] },
|
||||||
{ "name": "I2S_DOUT", "class": "signal", "nodes": [{ "ref": "U1", "pin": "GPIO7" }, { "ref": "U2", "pin": "DIN" }] },
|
{ "name": "I2S_DOUT", "class": "signal", "nodes": [{ "ref": "U1", "pin": "GPIO7" }, { "ref": "U2", "pin": "DIN" }] },
|
||||||
{ "name": "AUDIO_ANALOG", "class": "analog", "nodes": [{ "ref": "U2", "pin": "AOUT" }, { "ref": "U3", "pin": "IN" }] }
|
{ "name": "AUDIO_ANALOG", "class": "analog", "nodes": [{ "ref": "U2", "pin": "AOUT" }, { "ref": "U3", "pin": "IN" }] },
|
||||||
|
{ "name": "I2C_SCL", "class": "clock", "nodes": [{ "ref": "U1", "pin": "GPIO9" }, { "ref": "U5", "pin": "SCL" }, { "ref": "U6", "pin": "SCL" }, { "ref": "R1", "pin": "2" }] },
|
||||||
|
{ "name": "I2C_SDA", "class": "signal", "nodes": [{ "ref": "U1", "pin": "GPIO10" }, { "ref": "U5", "pin": "SDA" }, { "ref": "U6", "pin": "SDA" }, { "ref": "R2", "pin": "2" }] },
|
||||||
|
{ "name": "MIC_ADC", "class": "analog", "nodes": [{ "ref": "U7", "pin": "OUT" }, { "ref": "U1", "pin": "GPIO8" }, { "ref": "C3", "pin": "1" }] },
|
||||||
|
{ "name": "MIC_EN", "class": "signal", "nodes": [{ "ref": "U1", "pin": "GPIO11" }, { "ref": "U7", "pin": "EN" }] },
|
||||||
|
{ "name": "DEBUG_TX", "class": "signal", "nodes": [{ "ref": "U1", "pin": "GPIO12" }, { "ref": "J1", "pin": "1" }] }
|
||||||
],
|
],
|
||||||
"constraints": {
|
"constraints": {
|
||||||
"groups": [
|
"groups": [
|
||||||
{ "name": "power_stage", "members": ["U4"], "layout": "cluster" },
|
{ "name": "power_stage", "members": ["U4"], "layout": "cluster" },
|
||||||
{ "name": "compute", "members": ["U1", "U2"], "layout": "cluster" }
|
{ "name": "compute_audio", "members": ["U1", "U2", "U3", "U7"], "layout": "cluster" },
|
||||||
|
{ "name": "i2c_peripherals", "members": ["U5", "U6", "R1", "R2"], "layout": "cluster" },
|
||||||
|
{ "name": "support", "members": ["C1", "C2", "C3", "J1"], "layout": "cluster" }
|
||||||
],
|
],
|
||||||
"alignment": [{ "left_of": "U1", "right_of": "U2" }],
|
"alignment": [
|
||||||
"near": [{ "component": "U2", "target_pin": { "ref": "U1", "pin": "GPIO5" } }]
|
{ "left_of": "U4", "right_of": "U1" },
|
||||||
|
{ "left_of": "U1", "right_of": "U2" },
|
||||||
|
{ "left_of": "U2", "right_of": "U3" }
|
||||||
|
],
|
||||||
|
"near": [
|
||||||
|
{ "component": "C1", "target_pin": { "ref": "U1", "pin": "3V3" } },
|
||||||
|
{ "component": "C2", "target_pin": { "ref": "U2", "pin": "3V3" } },
|
||||||
|
{ "component": "C3", "target_pin": { "ref": "U1", "pin": "GPIO8" } }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"annotations": [
|
"annotations": [
|
||||||
{ "text": "I2S audio chain" }
|
{ "text": "Smart audio + sensing node with I2S DAC, class-D amp, I2C peripherals, and mic ADC front-end." }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,22 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/server.js",
|
"start": "node src/server.js",
|
||||||
|
"start:legacy": "node src/server.js",
|
||||||
"dev": "node --watch src/server.js",
|
"dev": "node --watch src/server.js",
|
||||||
|
"dev:legacy": "node --watch src/server.js",
|
||||||
|
"frontend:legacy:start": "npm run start:legacy",
|
||||||
|
"frontend:legacy:dev": "npm run dev:legacy",
|
||||||
"test": "node --test",
|
"test": "node --test",
|
||||||
|
"test:legacy": "node --test",
|
||||||
"test:ui": "node tests/ui-regression-runner.js",
|
"test:ui": "node tests/ui-regression-runner.js",
|
||||||
"test:ui:update-baselines": "UPDATE_SNAPSHOTS=1 node tests/ui-regression-runner.js",
|
"test:ui:update-baselines": "UPDATE_SNAPSHOTS=1 node tests/ui-regression-runner.js",
|
||||||
|
"frontend:react:dev": "node scripts/react-path.mjs dev",
|
||||||
|
"frontend:react:install": "npm --prefix frontend-react install",
|
||||||
|
"frontend:react:lint": "node scripts/react-path.mjs lint",
|
||||||
|
"frontend:react:test": "node scripts/react-path.mjs test",
|
||||||
|
"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",
|
||||||
|
"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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { existsSync, readFileSync } from 'node:fs';
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
const command = process.argv[2];
|
||||||
|
if (!command) {
|
||||||
|
console.error('[react-path] Missing command argument (e.g. lint/test/build/dev).');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactDir = path.resolve(process.cwd(), 'frontend-react');
|
||||||
|
const reactPkgPath = path.join(reactDir, 'package.json');
|
||||||
|
const reactNodeModulesPath = path.join(reactDir, 'node_modules');
|
||||||
|
|
||||||
|
if (!existsSync(reactPkgPath)) {
|
||||||
|
console.log(`[react-path] Stub: frontend-react is not scaffolded yet. Skipping "${command}".`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactPkg = JSON.parse(readFileSync(reactPkgPath, 'utf8'));
|
||||||
|
if (!reactPkg.scripts || !reactPkg.scripts[command]) {
|
||||||
|
console.log(`[react-path] Stub: frontend-react/package.json has no "${command}" script. Skipping.`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existsSync(reactNodeModulesPath)) {
|
||||||
|
console.log('[react-path] Stub: frontend-react dependencies are not installed. Skipping.');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = spawnSync('npm', ['--prefix', reactDir, 'run', command], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof result.status === 'number') {
|
||||||
|
process.exit(result.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { analyzeModel } from "./analyze.js";
|
import { analyzeModel } from "./analyze.js";
|
||||||
import { layoutAndRoute } from "./layout.js";
|
import { DEFAULT_LAYOUT_ENGINE, layoutAndRoute, requestedLayoutEngine } from "./layout.js";
|
||||||
import { renderSvgFromLayout } from "./render.js";
|
import { renderSvgFromLayout } from "./render.js";
|
||||||
import { validateModel } from "./validate.js";
|
import { validateModel } from "./validate.js";
|
||||||
|
|
||||||
@@ -239,6 +239,7 @@ function annotateIssues(issues, prefix) {
|
|||||||
|
|
||||||
export function compile(payload, options = {}) {
|
export function compile(payload, options = {}) {
|
||||||
const validated = validateModel(payload, options);
|
const validated = validateModel(payload, options);
|
||||||
|
const layoutEngineRequested = requestedLayoutEngine(options);
|
||||||
|
|
||||||
if (!validated.model) {
|
if (!validated.model) {
|
||||||
const errors = annotateIssues(validated.issues.filter((x) => x.severity === "error"), "E");
|
const errors = annotateIssues(validated.issues.filter((x) => x.severity === "error"), "E");
|
||||||
@@ -266,6 +267,9 @@ export function compile(payload, options = {}) {
|
|||||||
bus_groups: [],
|
bus_groups: [],
|
||||||
focus_map: {},
|
focus_map: {},
|
||||||
render_mode_used: options.render_mode ?? "schematic_stub",
|
render_mode_used: options.render_mode ?? "schematic_stub",
|
||||||
|
layout_engine_requested: layoutEngineRequested,
|
||||||
|
layout_engine_used: DEFAULT_LAYOUT_ENGINE,
|
||||||
|
layout_warnings: [],
|
||||||
svg: ""
|
svg: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -300,6 +304,9 @@ export function compile(payload, options = {}) {
|
|||||||
layout_metrics: layout.metrics,
|
layout_metrics: layout.metrics,
|
||||||
bus_groups: layout.bus_groups,
|
bus_groups: layout.bus_groups,
|
||||||
render_mode_used: layout.render_mode_used,
|
render_mode_used: layout.render_mode_used,
|
||||||
|
layout_engine_requested: layout.layout_engine_requested ?? layoutEngineRequested,
|
||||||
|
layout_engine_used: layout.layout_engine_used ?? DEFAULT_LAYOUT_ENGINE,
|
||||||
|
layout_warnings: Array.isArray(layout.layout_warnings) ? layout.layout_warnings : [],
|
||||||
svg
|
svg
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { createRequire } from "node:module";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const DEFAULT_ELK_MODULE = "elkjs/lib/elk.bundled.js";
|
||||||
|
const runtimeCache = new Map();
|
||||||
|
|
||||||
|
function normalizeElkExport(mod) {
|
||||||
|
if (!mod) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (typeof mod === "function") {
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
if (typeof mod.default === "function") {
|
||||||
|
return mod.default;
|
||||||
|
}
|
||||||
|
if (typeof mod.ELK === "function") {
|
||||||
|
return mod.ELK;
|
||||||
|
}
|
||||||
|
if (mod.default && typeof mod.default.ELK === "function") {
|
||||||
|
return mod.default.ELK;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveElkRuntime(moduleId = DEFAULT_ELK_MODULE) {
|
||||||
|
const key = String(moduleId || DEFAULT_ELK_MODULE);
|
||||||
|
if (runtimeCache.has(key)) {
|
||||||
|
return runtimeCache.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
let state;
|
||||||
|
try {
|
||||||
|
const loaded = require(key);
|
||||||
|
const ElkCtor = normalizeElkExport(loaded);
|
||||||
|
if (!ElkCtor) {
|
||||||
|
state = {
|
||||||
|
ok: false,
|
||||||
|
module: key,
|
||||||
|
reason: "invalid_export",
|
||||||
|
message: `ELK module "${key}" loaded but did not expose a usable constructor.`
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
state = {
|
||||||
|
ok: true,
|
||||||
|
module: key,
|
||||||
|
ElkCtor
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const message = err instanceof Error ? err.message : String(err);
|
||||||
|
state = {
|
||||||
|
ok: false,
|
||||||
|
module: key,
|
||||||
|
reason: "module_load_failed",
|
||||||
|
message: `ELK module "${key}" unavailable: ${message}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
runtimeCache.set(key, state);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -191,7 +216,39 @@ function distance(a, b) {
|
|||||||
return Math.hypot(a.x - b.x, a.y - b.y);
|
return Math.hypot(a.x - b.x, a.y - b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickLabelPoints(points, maxCount, used, minSpacing, avoidPoints = []) {
|
function rectFromLabelPoint(point, width = 78, height = 14) {
|
||||||
|
return {
|
||||||
|
x: point.x - 2,
|
||||||
|
y: point.y - height + 2,
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function rectsOverlap(a, b) {
|
||||||
|
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pointInRect(point, rect) {
|
||||||
|
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withCandidateOffsets(point) {
|
||||||
|
const offsets = [
|
||||||
|
[0, 0],
|
||||||
|
[0, -10],
|
||||||
|
[0, 10],
|
||||||
|
[10, 0],
|
||||||
|
[-10, 0],
|
||||||
|
[14, -10],
|
||||||
|
[-14, -10],
|
||||||
|
[14, 10],
|
||||||
|
[-14, 10]
|
||||||
|
];
|
||||||
|
return offsets.map(([dx, dy]) => ({ x: point.x + dx, y: point.y + dy }));
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickLabelPoints(points, maxCount, used, usedRects, minSpacing, avoidPoints = [], blockedRects = []) {
|
||||||
const accepted = [];
|
const accepted = [];
|
||||||
|
|
||||||
for (const p of points) {
|
for (const p of points) {
|
||||||
@@ -199,9 +256,11 @@ function pickLabelPoints(points, maxCount, used, minSpacing, avoidPoints = []) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const candidates = withCandidateOffsets(p);
|
||||||
|
for (const candidate of candidates) {
|
||||||
let blocked = false;
|
let blocked = false;
|
||||||
for (const prev of used) {
|
for (const prev of used) {
|
||||||
if (distance(p, prev) < minSpacing) {
|
if (distance(candidate, prev) < minSpacing) {
|
||||||
blocked = true;
|
blocked = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -211,7 +270,7 @@ function pickLabelPoints(points, maxCount, used, minSpacing, avoidPoints = []) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const pin of avoidPoints) {
|
for (const pin of avoidPoints) {
|
||||||
if (distance(p, pin) < minSpacing * 0.9) {
|
if (distance(candidate, pin) < minSpacing * 0.9) {
|
||||||
blocked = true;
|
blocked = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -220,13 +279,58 @@ function pickLabelPoints(points, maxCount, used, minSpacing, avoidPoints = []) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
accepted.push(p);
|
const labelRect = rectFromLabelPoint(candidate);
|
||||||
used.push(p);
|
for (const usedRect of usedRects) {
|
||||||
|
if (rectsOverlap(labelRect, usedRect)) {
|
||||||
|
blocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blocked) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const blockedRect of blockedRects) {
|
||||||
|
if (rectsOverlap(labelRect, blockedRect) || pointInRect(candidate, blockedRect)) {
|
||||||
|
blocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blocked) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
accepted.push(candidate);
|
||||||
|
used.push(candidate);
|
||||||
|
usedRects.push(labelRect);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -281,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"],
|
||||||
@@ -298,17 +402,50 @@ 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 = [];
|
||||||
|
const componentRects = [];
|
||||||
|
|
||||||
const components = layout.placed
|
const components = layout.placed
|
||||||
.map((inst) => {
|
.map((inst) => {
|
||||||
@@ -318,6 +455,12 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
const rotation = normalizeRotation(inst.placement.rotation ?? 0);
|
const rotation = normalizeRotation(inst.placement.rotation ?? 0);
|
||||||
const cx = x + sym.body.width / 2;
|
const cx = x + sym.body.width / 2;
|
||||||
const cy = y + sym.body.height / 2;
|
const cy = y + sym.body.height / 2;
|
||||||
|
componentRects.push({
|
||||||
|
x: x - 6,
|
||||||
|
y: y - 6,
|
||||||
|
width: sym.body.width + 12,
|
||||||
|
height: sym.body.height + 12
|
||||||
|
});
|
||||||
const templateKind = symbolTemplateKind(sym);
|
const templateKind = symbolTemplateKind(sym);
|
||||||
const compactLabel = templateKind || sym.body.width <= 140 || sym.body.height <= 90;
|
const compactLabel = templateKind || sym.body.width <= 140 || sym.body.height <= 90;
|
||||||
const legacyShowInstanceNetLabels = Boolean(inst.properties?.show_net_labels);
|
const legacyShowInstanceNetLabels = Boolean(inst.properties?.show_net_labels);
|
||||||
@@ -329,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;
|
||||||
@@ -375,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(
|
||||||
@@ -413,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>`
|
||||||
);
|
);
|
||||||
@@ -471,8 +624,21 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
|
|
||||||
const routedByName = new Map(layout.routed.map((r) => [r.net.name, r]));
|
const routedByName = new Map(layout.routed.map((r) => [r.net.name, r]));
|
||||||
const usedLabelPoints = [];
|
const usedLabelPoints = [];
|
||||||
|
const usedLabelRects = [];
|
||||||
const labels = [];
|
const labels = [];
|
||||||
const tieLabels = [];
|
const tieLabels = [];
|
||||||
|
const annotationLines = showAnnotations
|
||||||
|
? (model.annotations ?? []).map((a) => truncate(String(a.text ?? ""), 140)).filter(Boolean).slice(0, 6)
|
||||||
|
: [];
|
||||||
|
const annotationPanel = renderAnnotationPanel(annotationLines, (layout.width ?? 1200) * 0.36);
|
||||||
|
const legendY = annotationPanel.height > 0 ? annotationPanel.y + annotationPanel.height + 8 : 14;
|
||||||
|
const blockedLabelRects = [
|
||||||
|
...(annotationPanel.height > 0
|
||||||
|
? [{ x: annotationPanel.x - 2, y: annotationPanel.y - 2, width: annotationPanel.width + 4, height: annotationPanel.height + 4 }]
|
||||||
|
: []),
|
||||||
|
...(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)) {
|
||||||
@@ -489,7 +655,15 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
|
|
||||||
if (routeInfo?.mode === "label_tie") {
|
if (routeInfo?.mode === "label_tie") {
|
||||||
candidates.push(...(routeInfo?.labelPoints ?? []));
|
candidates.push(...(routeInfo?.labelPoints ?? []));
|
||||||
const selected = pickLabelPoints(candidates, 1, usedLabelPoints, GRID * 2.4, allPinPoints);
|
const selected = pickLabelPoints(
|
||||||
|
candidates,
|
||||||
|
1,
|
||||||
|
usedLabelPoints,
|
||||||
|
usedLabelRects,
|
||||||
|
GRID * 2.4,
|
||||||
|
allPinPoints,
|
||||||
|
blockedLabelRects
|
||||||
|
);
|
||||||
for (const p of selected) {
|
for (const p of selected) {
|
||||||
labels.push(renderNetLabel(p.x, p.y, net.name, net.class, true));
|
labels.push(renderNetLabel(p.x, p.y, net.name, net.class, true));
|
||||||
}
|
}
|
||||||
@@ -499,11 +673,23 @@ 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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const selected = pickLabelPoints(candidates, 1, usedLabelPoints, GRID * 2.4, allPinPoints);
|
const selected = pickLabelPoints(
|
||||||
|
candidates,
|
||||||
|
1,
|
||||||
|
usedLabelPoints,
|
||||||
|
usedLabelRects,
|
||||||
|
GRID * 2.4,
|
||||||
|
allPinPoints,
|
||||||
|
blockedLabelRects
|
||||||
|
);
|
||||||
for (const p of selected) {
|
for (const p of selected) {
|
||||||
labels.push(renderNetLabel(p.x, p.y, net.name, net.class));
|
labels.push(renderNetLabel(p.x, p.y, net.name, net.class));
|
||||||
}
|
}
|
||||||
@@ -511,6 +697,7 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
|
|
||||||
if (showLabels) {
|
if (showLabels) {
|
||||||
const usedTieLabels = [];
|
const usedTieLabels = [];
|
||||||
|
const usedTieRects = [];
|
||||||
for (const rn of layout.routed) {
|
for (const rn of layout.routed) {
|
||||||
if (rn.mode !== "label_tie" || isGroundLikeNet(rn.net)) {
|
if (rn.mode !== "label_tie" || isGroundLikeNet(rn.net)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -522,7 +709,15 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const maxPerNet = rn.net.class === "power" ? Math.min(6, candidates.length) : Math.min(2, candidates.length);
|
const maxPerNet = rn.net.class === "power" ? Math.min(6, candidates.length) : Math.min(2, candidates.length);
|
||||||
const selected = pickLabelPoints(candidates, maxPerNet, usedTieLabels, GRID * 1.5, allPinPoints);
|
const selected = pickLabelPoints(
|
||||||
|
candidates,
|
||||||
|
maxPerNet,
|
||||||
|
usedTieLabels,
|
||||||
|
usedTieRects,
|
||||||
|
GRID * 1.5,
|
||||||
|
allPinPoints,
|
||||||
|
blockedLabelRects
|
||||||
|
);
|
||||||
for (const p of selected) {
|
for (const p of selected) {
|
||||||
tieLabels.push(renderNetLabel(p.x, p.y, rn.net.name, rn.net.class, true));
|
tieLabels.push(renderNetLabel(p.x, p.y, rn.net.name, rn.net.class, true));
|
||||||
}
|
}
|
||||||
@@ -553,14 +748,6 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
})
|
})
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
const annotations = (model.annotations ?? [])
|
|
||||||
.map((a, idx) => {
|
|
||||||
const x = a.x ?? 16;
|
|
||||||
const y = a.y ?? 24 + idx * 16;
|
|
||||||
return `<text x="${x}" y="${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"?>
|
||||||
@@ -574,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);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ test("REST compile contract shape is stable with version metadata", () => {
|
|||||||
assert.ok(Array.isArray(body.warnings));
|
assert.ok(Array.isArray(body.warnings));
|
||||||
assert.ok(Array.isArray(body.bus_groups));
|
assert.ok(Array.isArray(body.bus_groups));
|
||||||
assert.equal(typeof body.render_mode_used, "string");
|
assert.equal(typeof body.render_mode_used, "string");
|
||||||
|
assert.equal(typeof body.layout_engine_requested, "string");
|
||||||
|
assert.equal(typeof body.layout_engine_used, "string");
|
||||||
|
assert.ok(Array.isArray(body.layout_warnings));
|
||||||
assert.equal(typeof body.svg, "string");
|
assert.equal(typeof body.svg, "string");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 268 KiB |
|
Before Width: | Height: | Size: 175 KiB After Width: | Height: | Size: 201 KiB |
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 269 KiB After Width: | Height: | Size: 163 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 202 KiB |
|
Before Width: | Height: | Size: 165 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" };
|
||||||
|
|
||||||
@@ -36,6 +37,48 @@ test("compile accepts render mode options", () => {
|
|||||||
assert.equal(result.render_mode_used, "explicit");
|
assert.equal(result.render_mode_used, "explicit");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("compile default layout engine path remains stable", () => {
|
||||||
|
const baseline = compile(fixture);
|
||||||
|
const explicitDefault = compile(fixture, { use_elk_layout: false });
|
||||||
|
|
||||||
|
assert.equal(baseline.ok, true);
|
||||||
|
assert.deepEqual(explicitDefault.layout, baseline.layout);
|
||||||
|
assert.deepEqual(explicitDefault.layout_metrics, baseline.layout_metrics);
|
||||||
|
assert.equal(baseline.layout_engine_requested, "schemeta-v2");
|
||||||
|
assert.equal(baseline.layout_engine_used, "schemeta-v2");
|
||||||
|
assert.deepEqual(baseline.layout_warnings, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("compile accepts ELK layout flag option", () => {
|
||||||
|
const result = compile(fixture, {
|
||||||
|
use_elk_layout: true,
|
||||||
|
elk_runtime_module: path.resolve(process.cwd(), "tests/fixtures/mock-elk-runtime.cjs")
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(result.ok, true);
|
||||||
|
assert.equal(result.layout_engine_requested, "elk");
|
||||||
|
assert.equal(result.layout_engine_used, "elk");
|
||||||
|
assert.deepEqual(result.layout_warnings, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("compile ELK fallback is deterministic when runtime is unavailable", () => {
|
||||||
|
const options = {
|
||||||
|
use_elk_layout: true,
|
||||||
|
elk_runtime_module: "__missing_elk_runtime_for_test__"
|
||||||
|
};
|
||||||
|
const runA = compile(fixture, options);
|
||||||
|
const runB = compile(fixture, options);
|
||||||
|
|
||||||
|
assert.equal(runA.ok, true);
|
||||||
|
assert.deepEqual(runB.layout, runA.layout);
|
||||||
|
assert.deepEqual(runB.layout_metrics, runA.layout_metrics);
|
||||||
|
assert.equal(runA.layout_engine_requested, "elk");
|
||||||
|
assert.equal(runA.layout_engine_used, "schemeta-v2");
|
||||||
|
assert.equal(runA.layout_warnings.length, 1);
|
||||||
|
assert.equal(runA.layout_warnings[0].code, "elk_layout_unavailable_fallback");
|
||||||
|
assert.deepEqual(runB.layout_warnings, runA.layout_warnings);
|
||||||
|
});
|
||||||
|
|
||||||
test("compile auto-creates generic symbols for unknown instances", () => {
|
test("compile auto-creates generic symbols for unknown instances", () => {
|
||||||
const model = {
|
const model = {
|
||||||
meta: { title: "Generic Demo" },
|
meta: { title: "Generic Demo" },
|
||||||
@@ -283,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), "c7a3cd161b6129b53e335d689e13b5425ccca6692f263245e3bf2d7b37aab06a");
|
assert.equal(svgHash(outA.svg), "fe431f62be90da91fbd707e1d2dae9286a04d61442893fa54fbebb048c748841");
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import test from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import fixture from "../frontend/sample.schemeta.json" with { type: "json" };
|
||||||
|
import { createSchemetaStore } from "../frontend-react/src/state/store.js";
|
||||||
|
|
||||||
|
function baseModel() {
|
||||||
|
return {
|
||||||
|
...fixture,
|
||||||
|
instances: fixture.instances.map((instance) => ({
|
||||||
|
...instance,
|
||||||
|
placement: {
|
||||||
|
...instance.placement
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test("setSelection normalizes and sorts refs deterministically", () => {
|
||||||
|
const store = createSchemetaStore();
|
||||||
|
|
||||||
|
store.actions.setSelection({
|
||||||
|
selectedRefs: ["U7", "U1", "U2", "U1", "U3"],
|
||||||
|
selectedNet: "I2C_SCL",
|
||||||
|
selectedPin: { ref: "U1", pin: "GPIO9" }
|
||||||
|
});
|
||||||
|
|
||||||
|
const { selection } = store.getState();
|
||||||
|
assert.deepEqual(selection.selectedRefs, ["U1", "U2", "U3", "U7"]);
|
||||||
|
assert.equal(selection.selectedNet, "I2C_SCL");
|
||||||
|
assert.deepEqual(selection.selectedPin, { ref: "U1", pin: "GPIO9" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("moveComponent only updates targeted instance and is deterministic", () => {
|
||||||
|
const model = baseModel();
|
||||||
|
|
||||||
|
const storeA = createSchemetaStore();
|
||||||
|
const storeB = createSchemetaStore();
|
||||||
|
|
||||||
|
storeA.actions.setModel(model);
|
||||||
|
storeA.actions.moveComponent("U1", { x: 121.7, y: 333.2 });
|
||||||
|
|
||||||
|
storeB.actions.setModel(model);
|
||||||
|
storeB.actions.moveComponent("U1", { x: 121.7, y: 333.2 });
|
||||||
|
|
||||||
|
const stateA = storeA.getState();
|
||||||
|
const stateB = storeB.getState();
|
||||||
|
|
||||||
|
assert.deepEqual(stateA.model, stateB.model);
|
||||||
|
|
||||||
|
const moved = stateA.model.instances.find((x) => x.ref === "U1");
|
||||||
|
assert.equal(moved.placement.x, 122);
|
||||||
|
assert.equal(moved.placement.y, 333);
|
||||||
|
|
||||||
|
const untouched = stateA.model.instances.find((x) => x.ref === "U2");
|
||||||
|
assert.equal(untouched.placement.x, null);
|
||||||
|
assert.equal(untouched.placement.y, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("applyJsonText updates model on valid JSON and clears jsonError", () => {
|
||||||
|
const store = createSchemetaStore({
|
||||||
|
uiFlags: { jsonError: "Old error" }
|
||||||
|
});
|
||||||
|
|
||||||
|
const payload = JSON.stringify(baseModel());
|
||||||
|
const result = store.actions.applyJsonText(payload);
|
||||||
|
|
||||||
|
assert.equal(result.ok, true);
|
||||||
|
assert.equal(store.getState().uiFlags.jsonError, null);
|
||||||
|
assert.equal(store.getState().model.instances.length > 0, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("applyJsonText reports parse errors without mutating model", () => {
|
||||||
|
const store = createSchemetaStore();
|
||||||
|
store.actions.setModel(baseModel());
|
||||||
|
|
||||||
|
const before = store.getState().model;
|
||||||
|
const result = store.actions.applyJsonText("{ bad json }");
|
||||||
|
|
||||||
|
assert.equal(result.ok, false);
|
||||||
|
assert.equal(typeof result.error, "string");
|
||||||
|
assert.equal(store.getState().uiFlags.jsonError.length > 0, true);
|
||||||
|
assert.deepEqual(store.getState().model, before);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("undo/redo restores deterministic snapshots", () => {
|
||||||
|
const store = createSchemetaStore();
|
||||||
|
store.actions.setModel(baseModel());
|
||||||
|
store.actions.setSelection({ selectedRefs: ["U3", "U1"] });
|
||||||
|
|
||||||
|
const beforeMove = store.getState().model;
|
||||||
|
store.actions.moveComponent("U1", { x: 80, y: 60 });
|
||||||
|
|
||||||
|
assert.equal(store.getState().history.past.length >= 3, true);
|
||||||
|
|
||||||
|
store.actions.undo();
|
||||||
|
assert.deepEqual(store.getState().model, beforeMove);
|
||||||
|
|
||||||
|
store.actions.redo();
|
||||||
|
const moved = store.getState().model.instances.find((x) => x.ref === "U1");
|
||||||
|
assert.equal(moved.placement.x, 80);
|
||||||
|
assert.equal(moved.placement.y, 60);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("transaction scaffold groups multiple actions into one undo step", () => {
|
||||||
|
const store = createSchemetaStore();
|
||||||
|
store.actions.setModel(baseModel());
|
||||||
|
|
||||||
|
const pastBefore = store.getState().history.past.length;
|
||||||
|
store.actions.beginTransaction("drag-and-select");
|
||||||
|
store.actions.moveComponent("U1", { x: 240, y: 140 });
|
||||||
|
store.actions.setSelection({ selectedRefs: ["U2", "U1"] });
|
||||||
|
store.actions.commitTransaction();
|
||||||
|
|
||||||
|
assert.equal(store.getState().history.past.length, pastBefore + 1);
|
||||||
|
assert.deepEqual(store.getState().selection.selectedRefs, ["U1", "U2"]);
|
||||||
|
|
||||||
|
store.actions.undo();
|
||||||
|
assert.deepEqual(store.getState().selection.selectedRefs, []);
|
||||||
|
const u1 = store.getState().model.instances.find((x) => x.ref === "U1");
|
||||||
|
assert.equal(u1.placement.x, null);
|
||||||
|
assert.equal(u1.placement.y, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("compile lifecycle state transitions are deterministic", () => {
|
||||||
|
const storeA = createSchemetaStore();
|
||||||
|
const storeB = createSchemetaStore();
|
||||||
|
|
||||||
|
storeA.actions.beginCompile("Compile");
|
||||||
|
storeA.actions.failCompile("Compile", "Bad payload");
|
||||||
|
storeA.actions.beginCompile("Analyze");
|
||||||
|
storeA.actions.completeCompile("Analyze");
|
||||||
|
|
||||||
|
storeB.actions.beginCompile("Compile");
|
||||||
|
storeB.actions.failCompile("Compile", "Bad payload");
|
||||||
|
storeB.actions.beginCompile("Analyze");
|
||||||
|
storeB.actions.completeCompile("Analyze");
|
||||||
|
|
||||||
|
assert.deepEqual(storeA.getState().lifecycle, storeB.getState().lifecycle);
|
||||||
|
assert.equal(storeA.getState().lifecycle.isCompiling, false);
|
||||||
|
assert.equal(storeA.getState().lifecycle.lastError, null);
|
||||||
|
assert.equal(storeA.getState().lifecycle.lastAction, "Analyze");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("compile lifecycle updates do not alter undo/redo history", () => {
|
||||||
|
const store = createSchemetaStore();
|
||||||
|
store.actions.setModel(baseModel());
|
||||||
|
store.actions.moveComponent("U1", { x: 90, y: 70 });
|
||||||
|
|
||||||
|
const beforeUndo = store.getState();
|
||||||
|
const pastBeforeLifecycle = beforeUndo.history.past.length;
|
||||||
|
|
||||||
|
store.actions.beginCompile("Compile");
|
||||||
|
store.actions.failCompile("Compile", "Synthetic error");
|
||||||
|
store.actions.beginCompile("Compile");
|
||||||
|
store.actions.completeCompile("Compile");
|
||||||
|
|
||||||
|
assert.equal(store.getState().history.past.length, pastBeforeLifecycle);
|
||||||
|
assert.equal(store.getState().lifecycle.lastAction, "Compile");
|
||||||
|
assert.equal(store.getState().lifecycle.lastError, null);
|
||||||
|
|
||||||
|
store.actions.undo();
|
||||||
|
const u1 = store.getState().model.instances.find((x) => x.ref === "U1");
|
||||||
|
assert.equal(u1.placement.x, null);
|
||||||
|
assert.equal(u1.placement.y, null);
|
||||||
|
});
|
||||||
@@ -10,11 +10,24 @@ import { chromium } from "playwright";
|
|||||||
|
|
||||||
const UPDATE_SNAPSHOTS = process.env.UPDATE_SNAPSHOTS === "1";
|
const UPDATE_SNAPSHOTS = process.env.UPDATE_SNAPSHOTS === "1";
|
||||||
const MAX_DIFF_PIXELS = Number(process.env.UI_MAX_DIFF_PIXELS ?? 220);
|
const MAX_DIFF_PIXELS = Number(process.env.UI_MAX_DIFF_PIXELS ?? 220);
|
||||||
|
const SAMPLE_MAX_CROSSINGS = Number(process.env.UI_SAMPLE_MAX_CROSSINGS ?? 1);
|
||||||
|
const SAMPLE_MAX_OVERLAPS = Number(process.env.UI_SAMPLE_MAX_OVERLAPS ?? 1);
|
||||||
|
const SAMPLE_MAX_DETOUR = Number(process.env.UI_SAMPLE_MAX_DETOUR ?? 3.6);
|
||||||
|
const DRAG_MAX_CROSSINGS = Number(process.env.UI_DRAG_MAX_CROSSINGS ?? 3);
|
||||||
|
const DRAG_MAX_OVERLAPS = Number(process.env.UI_DRAG_MAX_OVERLAPS ?? 3);
|
||||||
|
const DRAG_MAX_DETOUR = Number(process.env.UI_DRAG_MAX_DETOUR ?? 3.5);
|
||||||
|
const TIDY_MAX_CROSSINGS = Number(process.env.UI_TIDY_MAX_CROSSINGS ?? 2);
|
||||||
|
const TIDY_MAX_OVERLAPS = Number(process.env.UI_TIDY_MAX_OVERLAPS ?? 2);
|
||||||
|
const TIDY_MAX_DETOUR = Number(process.env.UI_TIDY_MAX_DETOUR ?? 4.5);
|
||||||
|
const DENSE_MAX_CROSSINGS = Number(process.env.UI_DENSE_MAX_CROSSINGS ?? 2);
|
||||||
|
const DENSE_MAX_OVERLAPS = Number(process.env.UI_DENSE_MAX_OVERLAPS ?? 2);
|
||||||
|
const DENSE_MAX_DETOUR = Number(process.env.UI_DENSE_MAX_DETOUR ?? 4.2);
|
||||||
const BASELINE_DIR = join(process.cwd(), "tests", "baselines", "ui");
|
const BASELINE_DIR = join(process.cwd(), "tests", "baselines", "ui");
|
||||||
const OUTPUT_DIR = join(process.cwd(), "output", "playwright");
|
const OUTPUT_DIR = join(process.cwd(), "output", "playwright");
|
||||||
const CURRENT_DIR = join(OUTPUT_DIR, "current");
|
const CURRENT_DIR = join(OUTPUT_DIR, "current");
|
||||||
const DIFF_DIR = join(OUTPUT_DIR, "diff");
|
const DIFF_DIR = join(OUTPUT_DIR, "diff");
|
||||||
const DENSE_ANALOG_PATH = join(process.cwd(), "examples", "dense-analog.json");
|
const DENSE_ANALOG_PATH = join(process.cwd(), "examples", "dense-analog.json");
|
||||||
|
const REPORT_PATH = join(OUTPUT_DIR, "ui-metrics-report.json");
|
||||||
|
|
||||||
async function getFreePort() {
|
async function getFreePort() {
|
||||||
const probe = createNetServer();
|
const probe = createNetServer();
|
||||||
@@ -41,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(),
|
||||||
@@ -138,13 +173,38 @@ async function run() {
|
|||||||
const srv = await startServer(port);
|
const srv = await startServer(port);
|
||||||
const browser = await chromium.launch({ headless: true });
|
const browser = await chromium.launch({ headless: true });
|
||||||
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
|
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
|
||||||
|
await page.addInitScript(() => {
|
||||||
|
try {
|
||||||
|
window.localStorage?.clear();
|
||||||
|
window.sessionStorage?.clear();
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
const report = {
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
thresholds: {
|
||||||
|
sample: { crossings: SAMPLE_MAX_CROSSINGS, overlaps: SAMPLE_MAX_OVERLAPS, detour: SAMPLE_MAX_DETOUR },
|
||||||
|
drag: { crossings: DRAG_MAX_CROSSINGS, overlaps: DRAG_MAX_OVERLAPS, detour: DRAG_MAX_DETOUR },
|
||||||
|
tidy: { crossings: TIDY_MAX_CROSSINGS, overlaps: TIDY_MAX_OVERLAPS, detour: TIDY_MAX_DETOUR },
|
||||||
|
dense: { crossings: DENSE_MAX_CROSSINGS, overlaps: DENSE_MAX_OVERLAPS, detour: DENSE_MAX_DETOUR }
|
||||||
|
},
|
||||||
|
snapshots: {},
|
||||||
|
status: {}
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await page.goto(`${srv.baseUrl}/`);
|
await page.goto(`${srv.baseUrl}/`);
|
||||||
await page.waitForSelector("#compileStatus");
|
await page.waitForSelector("#compileStatus");
|
||||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||||
|
const initialStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
const initialMetrics = parseStatusMetrics(initialStatus);
|
||||||
|
report.status.initial = { text: initialStatus, metrics: initialMetrics };
|
||||||
|
assert.ok(initialMetrics, `Unable to parse initial compile metrics from: ${initialStatus}`);
|
||||||
|
assert.ok(initialMetrics.crossings <= SAMPLE_MAX_CROSSINGS, `sample crossings too high: ${initialMetrics.crossings}`);
|
||||||
|
assert.ok(initialMetrics.overlaps <= SAMPLE_MAX_OVERLAPS, `sample overlaps too high: ${initialMetrics.overlaps}`);
|
||||||
|
assert.ok(initialMetrics.detour <= SAMPLE_MAX_DETOUR, `sample detour too high: ${initialMetrics.detour}`);
|
||||||
|
|
||||||
await compareScene(page, "initial");
|
await compareScene(page, "initial");
|
||||||
|
report.snapshots.initial = "tests/baselines/ui/initial.png";
|
||||||
await page.keyboard.press("Control+k");
|
await page.keyboard.press("Control+k");
|
||||||
await page.getByRole("dialog", { name: "Command Palette" }).waitFor();
|
await page.getByRole("dialog", { name: "Command Palette" }).waitFor();
|
||||||
await page.locator("#commandInput").fill("fit");
|
await page.locator("#commandInput").fill("fit");
|
||||||
@@ -161,6 +221,32 @@ async function run() {
|
|||||||
await page.getByRole("button", { name: "Reset view" }).click();
|
await page.getByRole("button", { name: "Reset view" }).click();
|
||||||
await compareScene(page, "selected-u2");
|
await compareScene(page, "selected-u2");
|
||||||
|
|
||||||
|
const target = page.locator('[data-ref="U2"]');
|
||||||
|
const box = await target.boundingBox();
|
||||||
|
assert.ok(box, "selected U2 should be draggable");
|
||||||
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(box.x + box.width / 2 - 320, box.y + box.height / 2 + 220, { steps: 12 });
|
||||||
|
await page.mouse.up();
|
||||||
|
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||||
|
const dragStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
const dragMetrics = parseStatusMetrics(dragStatus);
|
||||||
|
report.status.after_drag = { text: dragStatus, metrics: dragMetrics };
|
||||||
|
assert.ok(dragMetrics, `Unable to parse drag compile metrics from: ${dragStatus}`);
|
||||||
|
assert.ok(dragMetrics.crossings <= DRAG_MAX_CROSSINGS, `dragged layout crossings too high: ${dragMetrics.crossings}`);
|
||||||
|
assert.ok(dragMetrics.overlaps <= DRAG_MAX_OVERLAPS, `dragged layout overlaps too high: ${dragMetrics.overlaps}`);
|
||||||
|
assert.ok(dragMetrics.detour <= DRAG_MAX_DETOUR, `dragged layout detour too high: ${dragMetrics.detour}`);
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Run automatic tidy layout" }).click();
|
||||||
|
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||||
|
const tidyStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
const tidyMetrics = parseStatusMetrics(tidyStatus);
|
||||||
|
report.status.after_drag_tidy = { text: tidyStatus, metrics: tidyMetrics };
|
||||||
|
assert.ok(tidyMetrics, `Unable to parse tidy compile metrics from: ${tidyStatus}`);
|
||||||
|
assert.ok(tidyMetrics.crossings <= TIDY_MAX_CROSSINGS, `drag+tidy crossings too high: ${tidyMetrics.crossings}`);
|
||||||
|
assert.ok(tidyMetrics.overlaps <= TIDY_MAX_OVERLAPS, `drag+tidy overlaps too high: ${tidyMetrics.overlaps}`);
|
||||||
|
assert.ok(tidyMetrics.detour <= TIDY_MAX_DETOUR, `drag+tidy detour too high: ${tidyMetrics.detour}`);
|
||||||
|
|
||||||
await page.locator("#canvasViewport").click({ position: { x: 40, y: 40 } });
|
await page.locator("#canvasViewport").click({ position: { x: 40, y: 40 } });
|
||||||
await expectText(page, "#selectedSummary", /Click a component, net, or pin/);
|
await expectText(page, "#selectedSummary", /Click a component, net, or pin/);
|
||||||
|
|
||||||
@@ -193,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");
|
||||||
|
|
||||||
@@ -210,29 +295,47 @@ async function run() {
|
|||||||
await page.getByRole("button", { name: "Add Component" }).click();
|
await page.getByRole("button", { name: "Add Component" }).click();
|
||||||
await waitFor(async () => (await page.locator("[data-ref-item]").count()) >= beforeInstanceCount + 1);
|
await waitFor(async () => (await page.locator("[data-ref-item]").count()) >= beforeInstanceCount + 1);
|
||||||
|
|
||||||
await page.locator("#newQuickNetClassSelect").selectOption("signal");
|
|
||||||
await page.locator("#newQuickNetNameInput").fill("UI_TEST_NET");
|
|
||||||
await page.getByRole("button", { name: "Add Net" }).click();
|
|
||||||
await expectText(page, "#netList", /UI_TEST_NET/);
|
|
||||||
|
|
||||||
const dense = await readFile(DENSE_ANALOG_PATH, "utf8");
|
const dense = await readFile(DENSE_ANALOG_PATH, "utf8");
|
||||||
await page.locator("#jsonEditor").fill(dense);
|
await page.locator("#jsonEditor").fill(dense);
|
||||||
await page.getByRole("button", { name: "Apply JSON" }).click();
|
await page.getByRole("button", { name: "Apply JSON" }).click();
|
||||||
|
await expectText(page, "#jsonFeedback", /Applied JSON|blocked by validation/);
|
||||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||||
const denseStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
const denseStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
const denseFeedback = String((await page.locator("#jsonFeedback").textContent()) ?? "");
|
||||||
|
assert.ok(!/blocked by validation/i.test(denseFeedback), `dense fixture apply unexpectedly blocked: ${denseFeedback}`);
|
||||||
const metrics = parseStatusMetrics(denseStatus);
|
const metrics = parseStatusMetrics(denseStatus);
|
||||||
|
report.status.dense = { text: denseStatus, metrics, feedback: denseFeedback };
|
||||||
assert.ok(metrics, `Unable to parse compile status metrics from: ${denseStatus}`);
|
assert.ok(metrics, `Unable to parse compile status metrics from: ${denseStatus}`);
|
||||||
assert.equal(metrics.errors, 0, "dense analog scene should compile with no errors");
|
assert.equal(metrics.errors, 0, `dense analog scene should compile with no errors (feedback: ${denseFeedback})`);
|
||||||
assert.ok(metrics.crossings <= 2, `dense analog crossings too high: ${metrics.crossings}`);
|
assert.ok(metrics.crossings <= DENSE_MAX_CROSSINGS, `dense analog crossings too high: ${metrics.crossings}`);
|
||||||
assert.ok(metrics.overlaps <= 2, `dense analog overlaps too high: ${metrics.overlaps}`);
|
assert.ok(metrics.overlaps <= DENSE_MAX_OVERLAPS, `dense analog overlaps too high: ${metrics.overlaps}`);
|
||||||
|
assert.ok(metrics.detour <= DENSE_MAX_DETOUR, `dense analog detour too high: ${metrics.detour}`);
|
||||||
await compareScene(page, "dense-analog");
|
await compareScene(page, "dense-analog");
|
||||||
|
report.snapshots.dense = "tests/baselines/ui/dense-analog.png";
|
||||||
|
|
||||||
await page.setViewportSize({ width: 1280, height: 720 });
|
await page.setViewportSize({ width: 1280, height: 720 });
|
||||||
await page.getByRole("button", { name: "Fit schematic to viewport" }).click();
|
await page.getByRole("button", { name: "Fit schematic to viewport" }).click();
|
||||||
await expectText(page, "#compileStatus", /Compiled/);
|
await expectText(page, "#compileStatus", /Compiled/);
|
||||||
assert.ok(await page.locator("#applyJsonBtn").isVisible(), "Apply JSON button should remain visible at laptop viewport");
|
assert.ok(await page.locator("#applyJsonBtn").isVisible(), "Apply JSON button should remain visible at laptop viewport");
|
||||||
await compareScene(page, "laptop-viewport");
|
await compareScene(page, "laptop-viewport");
|
||||||
|
report.snapshots.laptop = "tests/baselines/ui/laptop-viewport.png";
|
||||||
|
|
||||||
|
const compileBeforeInvalidApply = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
await page.locator("#jsonEditor").fill("{\"meta\":{\"title\":\"invalid\"},\"instances\":[],\"nets\":[]}");
|
||||||
|
await page.getByRole("button", { name: "Apply JSON" }).click();
|
||||||
|
await expectText(page, "#jsonFeedback", /blocked by validation/i);
|
||||||
|
const compileAfterInvalidApply = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||||
|
assert.equal(
|
||||||
|
compileAfterInvalidApply,
|
||||||
|
compileBeforeInvalidApply,
|
||||||
|
"invalid JSON apply should not mutate compiled workspace state"
|
||||||
|
);
|
||||||
|
report.result = "pass";
|
||||||
} finally {
|
} finally {
|
||||||
|
if (!report.result) {
|
||||||
|
report.result = "fail";
|
||||||
|
}
|
||||||
|
await writeFile(REPORT_PATH, `${JSON.stringify(report, null, 2)}\n`);
|
||||||
await page.close().catch(() => {});
|
await page.close().catch(() => {});
|
||||||
await browser.close().catch(() => {});
|
await browser.close().catch(() => {});
|
||||||
await srv.stop().catch(() => {});
|
await srv.stop().catch(() => {});
|
||||||
|
|||||||
@@ -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"));
|
||||||
|
});
|
||||||