feat: scope the handle manifest and re-aim the ghost

Two consequences of the preview dropping from ~1535 ms to ~142 ms.

The manifest is now scoped to the object being edited. It was 844 KB on a
41-road workspace — 239 handles, 89% of the bytes being `affects` id lists at 46
ids per junction handle — shipped on every preview while the map rendered six.
A segment selection returns 12.2 KB, a 69x reduction, and the cost no longer
multiplies with each handle kind we are about to add. Omitting the selection
keeps the full manifest for the compiler and existing callers, and the tests
assert that scoping is a filter of the full manifest rather than a second
derivation.

The ghost is re-aimed from "estimated geometry" to "what you asked for". Its
guide line existed to mark the origin through a long wait that no longer happens,
so it is gone; what remains is what the preview cannot say — the numeric delta
and whether the drag has hit its clamp. The translucent outline
research/joint-solver.md asked for is deliberately not built: drawing it
accurately means recomputing the road surface in the browser, which the design
forbids, and drawing it crudely would be wrong exactly at transitions, junction
boundaries and clamps. A preview that lies is worse than none.

`degraded` finally has a consumer. EditSession has tracked it since the session
work but nothing read it; a slow solve now dims the ghost in place with a pending
label instead of clearing it and letting the geometry flicker, as design.md
requires.

Selection also fixed a latent hazard: the manifest effect reloads on every
selection change, and it used to call session.load() each time, which would have
discarded unsaved edits the moment the user clicked another road. It now adopts a
document only when the compiled document actually changed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
que01andClaude Opus 5 committed 2026-08-28 12:26:15 +08:00
1 parent d893e406d6
commit 5292c00926
13 files changed
+305 -41

No files matched your search

+41 -26
View File
@@ -21,32 +21,29 @@ import { handlePositionFor } from './projection';
import type { IntervalRangeHandle } from './selection';
import type { EditHandle, RoadIntervalAnchor } from './types';
const GUIDE = new Style({
stroke: new Stroke({ color: '#00a5cf', width: 2, lineDash: [6, 4] }),
});
/** The stretch of road an interval edit applies to. */
const BAND = new Style({
stroke: new Stroke({ color: '#29695699', width: 14 }),
});
/** Drawn at the bound so it is obvious the handle stopped rather than stuck. */
const CLAMPED = new Style({
stroke: new Stroke({ color: '#d49318', width: 2, lineDash: [6, 4] }),
});
function knob(label: string, clamped: boolean): Style {
/**
* Clamped turns the knob amber so "the road cannot go further" reads differently
* from "the drag is still following". Pending dims it while a solve is over
* budget, so a slow answer looks slow rather than broken.
*/
function knob(label: string, clamped: boolean, pending: boolean): Style {
const colour = clamped ? '#d49318' : '#00a5cf';
return new Style({
image: new CircleStyle({
radius: 8,
fill: new Fill({ color: clamped ? '#d49318' : '#00a5cf' }),
stroke: new Stroke({ color: '#fff', width: 2 }),
fill: new Fill({ color: pending ? `${colour}66` : colour }),
stroke: new Stroke({ color: pending ? '#ffffff88' : '#fff', width: 2 }),
}),
text: new Text({
text: label,
text: pending ? `${label} 求解中…` : label,
offsetY: -18,
font: '600 12px system-ui, sans-serif',
fill: new Fill({ color: '#1b2426' }),
fill: new Fill({ color: pending ? '#59696c' : '#1b2426' }),
stroke: new Stroke({ color: '#ffffffcc', width: 3 }),
}),
});
@@ -55,6 +52,7 @@ function knob(label: string, clamped: boolean): Style {
export class EditGhostLayer {
readonly layer: VectorLayer<VectorSource>;
private readonly source = new VectorSource();
private pending = false;
constructor() {
this.layer = new VectorLayer({
@@ -63,32 +61,49 @@ export class EditGhostLayer {
zIndex: 110,
style: (feature) => {
if (feature.get('band')) return BAND;
const label = feature.get('label');
if (typeof label === 'string') return knob(label, Boolean(feature.get('clamped')));
return feature.get('clamped') ? CLAMPED : GUIDE;
return knob(String(feature.get('label') ?? ''), Boolean(feature.get('clamped')), this.pending);
},
});
}
/**
* Shows the handle at the position implied by `value`, plus a guide line back to
* where it started. `value` is already clamped by `projectHandleValue`, so a
* ghost pinned at the bound is the correct picture: the road cannot go further.
* Shows the handle at the position implied by `value`. `value` is already
* clamped by `projectHandleValue()`, so a ghost pinned at the bound is the
* correct picture: the road cannot go further.
*
* There is deliberately no translucent outline of the resulting road, which
* `research/joint-solver.md` originally asked for. Drawing it accurately means
* recomputing the road surface in the browser — the second geometry algorithm
* the design forbids — and drawing it crudely would be wrong exactly where the
* solver does something non-trivial: transitions, junction boundaries, clamps.
* A preview that lies is worse than none. Since the solve dropped to ~142 ms the
* authoritative geometry arrives fast enough to show the shape itself, so the
* ghost only says what the preview cannot: how far you asked to move, and
* whether you have hit the limit.
*/
show(handle: EditHandle, value: number): void {
const origin = fromLonLat(handle.position);
const moved = fromLonLat(handlePositionFor(handle, value));
const clamped = value >= handle.value.max - 1e-6 || value <= handle.value.min + 1e-6;
const delta = value - handle.value.current;
this.pending = false;
this.source.clear();
this.source.addFeatures([
new Feature({ geometry: new LineString([origin, moved]), clamped }),
this.source.addFeature(
new Feature({
geometry: new Point(moved),
geometry: new Point(fromLonLat(handlePositionFor(handle, value))),
label: `${delta >= 0 ? '+' : ''}${delta.toFixed(2)} 米`,
clamped,
}),
]);
);
}
/**
* Holds the ghost while a solve is over budget. design.md requires the client to
* keep the ghost and a pending state rather than let the geometry flicker, so a
* degraded response dims the knob in place instead of clearing it.
*/
markPending(): void {
if (this.source.getFeatures().length === 0) return;
this.pending = true;
this.layer.changed();
}
/**