Web target, plan 5b: events and widgets
The second of slice 5's three plans. Frame code in the page gets engine.emit and handlers that run, the desktop's input events with their payloads, a frame event with engine.elapsed, a wall clock read through time.time(), random.Random bit for bit, and the five widgets a phone app needs: Button, Slider, Toggle, Image and a new Joystick, which lands on the desktop first. A page that frames the export talks to it through events. It ends with examples/web_crowd.py carrying a panel of all five widgets and a handler per event, replayed with no mismatch in Node and in Chromium, where Playwright drives each widget with a real pointer.
examples/web_crowd.py with a second panel: a Button throws a wave, a Slider sets gravity, a Toggle turns the spin on and off, a Joystick blows a wind over the boxes, an Image shows an SVG. Handlers on frame, the seven input events, every widget event and an app event (fell) keep counts in engine.state. The Python, Node and Chromium replays deliver the same events in the same order, frame by frame.
architectureOne event queue per side, in the desktop's order (Engine._draw_frame, src/manifoldx/engine.py:1238-1247): the frame event, then what was emitted during the previous frame, then the events that came in since. The replay frame gains events, the input events and outside emits the page saw, in order, and clock. A pointer event over a widget carries the widget and the pointer's place inside it, because the page's DOM is its hit test; the desktop's GUI bridge gets a seam so the Python replay reads that target instead of hit-testing its own layout. Widget events then come out of the desktop's own widget code in Python, and out of a port of it in manifoldx.js, one frame after the pointer event, as on the desktop.
techPython 3.13 and numpy 2; plain ES modules; Node 20+ for node --test and the replay; three.js 0.186.1 as vendored; Playwright with Chromium in the existing browser CI job on lavapipe, with a touch context and the DevTools protocol for two pointers at once.
spec.knowledge/analysis/2026-11-07-web-target-slice5-design.html (approved; sections 02, 06, 07, 10, 12 and 13, Q1, Q4 and Q5 of section 16)
builds onplan 5a (merged as #166), and plans 1 to 3 before it. This plan's branch is feat/web-target-5b from main at db6ef90; its PR targets main. Plan 5c (skinned entities and the second consumer) follows it.
code it changesdesktop: src/manifoldx/input.py, src/manifoldx/gui/bridge.py, slider.py, painter.py, __init__.py, new joystick.py. web: src/manifoldx/web/ gui.py, snapshot.py, reach.py, types.py, transpile.py, replay.py, and in js/: pyrt.js, manifoldx.js, input.js, gui.js, browser.js, replay.mjs. examples/web_crowd.py.
Done when
The spec's criterion for 5b, as tests
examples/web_crowd.py has a panel with a Button, a Slider, a Toggle, an Image and a Joystick, and a handler for each event the app can receive: frame, key_down, key_up, pointer_down, pointer_up, pointer_move, wheel, resize, gui:button:wave:click, gui:slider:gravity:change and :commit, gui:toggle:spin:change, gui:joystick:wind:change and the app's own fell.
Replay, Python against Node: compare(replay_python(...), replay_node(...)) is None in tests/web/test_web_crowd.py on a 600-frame script whose frames carry key, pointer, wheel and resize events and pointer events routed to each widget. The trace's new events key (the names delivered each frame, in order) is part of the comparison.
Chromium: tests/web/browser/test_web_crowd_page.py drives each widget through Playwright's mouse (click the Button, drag the Slider, click the Toggle, drag the Joystick, press an arrow key after clicking the Slider) and a two-pointer touch (the Joystick held while the Button is tapped); compare(replay_python(page_frames), page_trace) is None, and the frame checks pass: the frame of each press holds its pointer_down with that widget's index, the next frame's trace delivers its gui: event, the clock never runs backwards.
Breaking tests, each shown to make compare fail (task 10, and task 11 for the last): emits delivered in the frame that made them; a widget's value changed after its event is queued instead of before; the random state not loaded from the export; one pointer capture for all pointers instead of one per pointer. 5a's four breaking tests still fail as they did. CI's test and browser jobs are green.
Global constraints
- Functional parity (spec section 02): every runtime feature the page gains behaves as the desktop's. Where the desktop lacks a form the page needs (the Joystick, a capture per pointer, arrow keys on a Slider), it lands on the desktop first, in tasks 1 and 2, with desktop tests.
- One event queue, the desktop's order: frame event, then the emits of the previous frame (handlers' and systems', widget events included), then the input and outside events since then (
src/manifoldx/engine.py:1238-1247,src/manifoldx/events.py:133-137). An emit during delivery waits for the next frame. - A widget's value changes before its event is queued, as in
src/manifoldx/gui/slider.py:56-66andtoggle.py:35-37. - No app JavaScript. The host page of Q1 talks to the export only through events (spec section 06).
manifoldx.jsandpyrt.jsimport neither three.js nor a DOM name, so the Node replay keeps working. The DOM work is ininput.js,gui.jsandbrowser.js.- Every float both sides compute from a pointer goes through
+ - * /andsqrtonly (neverhypot, whose last bit differs between libms), so replays compare exactly. - An export error names the Python file and line, and what to write instead where one form exists, as the subset's errors do today.
- Node and Playwright are test dependencies only; tests skip with
node not found,playwright not installedorchromium not installed, and the browser job fails on any skip. - Shared host: each task's verify runs only the tests covering it.
make testand the browser job run in CI. - manifoldx is public: no consumer's repository, people, places, domains or machines in code, tests, commits or PR text. Say "the second consumer", "a third consumer".
- Commits are conventional and end with the co-author line; stage files by name; scratch goes under pytest's
tmp_pathor the system temp dir, never in the repo.
Review focus
- A drag that leaves its widget. A pointer goes down on the Slider, leaves the panel and comes up over the 3D view: the Slider keeps the capture, its moves and its commit use the pointer's place relative to the Slider (fractions below 0 or past 1, clamped),
pointer_over_guiis True in those frames, and the up also releases the mouse button in the frame. tests in tasks 1, 7 and 8 - An emit from a handler while the queue drains. The Button's click handler emits
throw: it is delivered the frame after the click event, which is itself the frame after the pointer went down. Two frames, on all three sides. tests in tasks 4 and 10 - Two pointers at once. A thumb holds the Joystick while another finger taps the Button: the Joystick keeps its capture and its value, the Button clicks once, and the Joystick goes back to (0, 0) only when its own pointer lifts. tests in tasks 1, 7 and 11
- Frame code writes a widget the user is dragging. A system sets
GRAVITY_SLIDER.value = 6.0while the pointer drags it: the page draws 6.0 this frame, the next move sets the value from the pointer again, and the write queues no event, as on the desktop. test in task 7 - An outside emit before the first frame or while the tab is frozen. A host page posts a message while the page loads, or while
run --webholds the tab frozen: it waits in the frame builder and enters the next frame taken; a message from a window other than the parent is ignored. test in task 9
File structure
| file | responsibility |
|---|---|
| src/manifoldx/input.py | PointerEvent.pointer_id: int = 0 (task 1) |
| src/manifoldx/gui/bridge.py | a capture per pointer, the _locate seam, focus and arrow keys (task 1) |
| src/manifoldx/gui/slider.py | Slider._on_step(sign, engine) (task 1) |
| src/manifoldx/gui/joystick.py, painter.py, __init__.py | the Joystick widget, painted like the Slider, exported from manifoldx.gui (task 2) |
| src/manifoldx/web/js/pyrt.js | Random, MT19937 as CPython's; $rt.setClock, $rt.time_time |
| src/manifoldx/web/js/manifoldx.js | EventBus, advance(app, frame, dt), the input event objects, GuiBridge and the widget hooks, the widgets' runtime objects |
| src/manifoldx/web/js/input.js | FrameBuilder records events (with widget targets) and clock; emit(name, payload) for outside events |
| src/manifoldx/web/js/gui.js | Button, Slider, Toggle, Joystick and Image drawn from the resolved style, ARIA, targetOf(domEvent) |
| src/manifoldx/web/js/browser.js, replay.mjs | both call advance; the host-page bridge; agent emits into the frame |
| src/manifoldx/web/gui.py | gui_spec for the five widgets; widget_list(engine) in the snapshot's walk order |
| src/manifoldx/web/snapshot.py | the {"__random": ...} value form; the random module's state |
| src/manifoldx/web/types.py, reach.py, transpile.py | the surface of emit, elapsed, the event classes, the widgets, random and time.time; a handler's payload type |
| src/manifoldx/web/replay.py | frames delivered through the engine's own bus; event_of; the routed GUI bridge; the clock; events in the trace |
| examples/web_crowd.py | the controls panel and a handler per event |
| tests/gui/test_bridge.py, test_slider.py, test_joystick.py, test_painter.py | the desktop side |
| tests/web/test_random.py, test_events.py, test_input_events.py, test_clock.py, test_widgets.py, test_web_crowd.py | Python tests, most through Node (run_both, replay_node) |
| tests/web/apps/events.py, widgets.py | small test apps for tasks 4 to 7 |
| tests/web/js/input.test.mjs, gui.test.mjs | the frame builder's events and the drawn widgets, in Node |
| tests/web/browser/test_host_page.py, test_web_crowd_page.py | Chromium: the host page, the widgets under a real pointer and two touches |
Tasks
1Desktop: the GUI bridge captures per pointer, locates through a seam, and steps a focused Slider with the arrow keys (changes behaviour)input.py · gui/bridge.py · gui/slider.py · tests/gui/test_bridge.py · tests/gui/test_slider.py · CHANGELOG.md
This task changes one desktop behaviour: after a pointer goes down on a Slider, the arrow keys step it, as Q4 settled for the page and the parity rule then requires of the desktop. An app that drives its camera with the arrow keys and has a Slider sees the Slider move too once the user has clicked it, until a click lands outside every widget. The other two changes keep behaviour: PointerEvent gains a field with a default, and the bridge keeps one capture per pointer, which on the desktop is always pointer 0, so a new down still ends the capture as it does today (src/manifoldx/gui/bridge.py:53-61).
interfaces
_GuiBridge (src/manifoldx/gui/bridge.py:14-88), PointerEvent (src/manifoldx/input.py:38-57), hit_test · produces PointerEvent.pointer_id: int = 0, the last field; _GuiBridge._captured: dict[int, Widget]; _GuiBridge._locate(ev) -> tuple[PointerEvent, tuple[Widget, LayoutBox] | None], the event in UI pixels and the interactive widget under it, the one method a replay replaces; _GuiBridge._focused: Widget | None, set by a pointer down that hits an interactive widget, cleared by one that hits nothing; a key_down handler on the bridge; Slider._on_step(sign: int, engine); STEPS = {"ArrowLeft": -1, "ArrowDown": -1, "ArrowRight": 1, "ArrowUp": 1} in bridge.py; SLIDER_STEPS = 20 in slider.py- Write the failing tests. In
tests/gui/test_bridge.py, with the file's existing engine and panel helpers: Intests/gui/test_slider.py:test_on_step_moves_a_twentieth_of_the_range(min 2, max 4, value 3,_on_step(1, eng): value 3.1 exactly as3 + 1 * (4 - 2) / 20, events change then commit). Runuv run pytest tests/gui/test_bridge.py tests/gui/test_slider.py -q: the new tests fail (nopointer_id, no_locate, no_on_step). - Implement.
PointerEventgainspointer_id: int = 0afterphase;_InputBridge._build_pointer_eventleaves it 0 (rendercanvas's glfw backend has no touch,ntouchesis always 0). In_GuiBridge._on_pointer: the input-capture early return stays first; thenev, hit = self._locate(ev); the captured branch readsself._captured.get(ev.pointer_id)and removes only that pointer's entry; a down that hits nothing sets_focused = None; a down that hits sets_focused = widgetafter dispatching._locateholds today's scaling andhit_testcall, unchanged. The bridge registers@engine.on("key_down")beside its pointer handlers, so it stays manifoldx's own handler, not a root (reach._internal); it callsself._focused._on_step(STEPS[ev.key], engine)when the focused widget is a Slider and the key is inSTEPS.Slider._on_stepsetsvalue = max(min, min(max, value + sign * (max - min) / SLIDER_STEPS)), then emits:changeand:commitwith{"value": self.value}. - Run
uv run pytest tests/gui -q: all pass. A test that relied on the single capture is a finding: report it in the commit body. - Add to
CHANGELOG.mdunder[Unreleased],### Changed:After a pointer goes down on a Slider, the arrow keys step it by a twentieth of its range (Left and Down lower it, Right and Up raise it), emitting change and commit, until a pointer goes down outside every widget (#140).Under### Added:PointerEvent.pointer_id, 0 on the desktop; the GUI keeps one pointer capture per pointer (#140). - Commit:
feat(gui): a capture per pointer, and arrow keys on a focused Slider (#140), the body saying that the arrow keys are a behaviour change.
uv run pytest tests/gui -q: all pass, the six new tests included. Make _captured a single slot again once: test_a_capture_is_per_pointer fails.
2Desktop: the Joystick widgetgui/joystick.py · gui/painter.py · gui/__init__.py · tests/gui/test_joystick.py · tests/gui/test_painter.py
interfaces
Widget, the bridge's per-pointer capture (task 1), the painter's draw_rect · produces manifoldx.gui.Joystick(*, name: str, style=None, style_overrides=None) with _is_gui_interactive = True, _gui_captures_pointer = True, value: tuple[float, float] (starts (0.0, 0.0)), intrinsic_size() -> (96.0, 96.0), _update_from(ev), _on_pointer_down, _on_pointer_move, _on_pointer_up, each emitting gui:joystick:<name>:change with {"value": self.value} after setting it- Write the failing tests in
tests/gui/test_joystick.py, withtest_slider.py's fake engine and pointer: Intests/gui/test_painter.py:test_joystick_paints_a_pad_and_a_knob: twoRectOps, the pad the widget's box withradius == box.w / 2inbg, the knob0.4 * box.wwide infg, centred at the box's centre moved byvalue * (r - knob / 2), y down on screen for a positivevalue[1]. Runuv run pytest tests/gui/test_joystick.py tests/gui/test_painter.py -q: fails on the import. - Implement
src/manifoldx/gui/joystick.pybesideslider.py._update_from(ev):r = min(box.w, box.h) * 0.5,x = (ev.x - (box.x + box.w * 0.5)) / r,y = -(ev.y - (box.y + box.h * 0.5)) / r,n = math.sqrt(x * x + y * y), divide both bynwhenn > 1.0; nothing when the box is missing or has no width. Add the painter branch after the Slider's and the import and__all__entry inmanifoldx/gui/__init__.py; the module docstring lists it among the interactive widgets. - Run the same command: all pass. Then
uv run pytest tests/gui -q. - Commit:
feat(gui): a Joystick widget (#140).
uv run pytest tests/gui -q: all pass, the six new tests included.
3random.Random in frame code, MT19937 as CPython'sjs/pyrt.js · web/snapshot.py · web/types.py · web/transpile.py · js/manifoldx.js · tests/web/test_random.py
interfaces
_Writer.value (src/manifoldx/web/snapshot.py), LIBS and RUNTIME_SURFACE (src/manifoldx/web/types.py:630, :659), tests/web/parity.py's run_both · produces pyrt class Random with static fromState({key, pos, gauss}), getstate() -> {key, pos, gauss}, random(), getrandbits(k) for 0 <= k <= 53, uniform(a, b), randrange(start, stop = null, step = 1), randint(a, b), choice(seq); $rt.random, the module's own instance; the value form {"__random": {"key": [624 ints], "pos": int, "gauss": float | null}}; state.json's "random" (the module instance's state, written when reached code calls a module function); RANDOM = obj("random.Random") in types.py; LIBS["random"]- Write the failing tests in
tests/web/test_random.py, compared bit for bit (rel=0): Runuv run pytest tests/web/test_random.py -q: fails at transpiling (randomis not a library the subset knows). - Runtime. MT19937 as
Modules/_randommodule.c:genrand_uint32regenerates the 624 words whenposreaches 624, then tempers (y ^= y >>> 11; y ^= (y << 7) & 0x9d2c5680; y ^= (y << 15) & 0xefc60000; y ^= y >>> 18) withMath.imuland>>> 0wherever a product or shift could leave 32 bits.random():a = u32 >>> 5, b = u32 >>> 6,(a * 67108864 + b) / 9007199254740992.getrandbits(k): k 0 gives 0; k up to 32 givesu32 >>> (32 - k); past 32 the words go little-endian, the last shifted right by its unused bits, as_random_Random_getrandbits_impldoes; past 53 it throws. The rest asLib/random.pyof Python 3.13:_randbelow_with_getrandbits(k = n.bit_length(), draw until belown),randrange's three branches and theirValueErrormessages,randint(a, b) = randrange(a, b + 1),uniform(a, b) = a + (b - a) * random(),choice(seq) = seq[_randbelow(len(seq))].gaussis carried, never used. - Snapshot and types.
_Writer.valuewrites arandom.Randomas the form above; when reached code namesrandom.random,random.uniform,random.randint,random.randrangeorrandom.choice,random._inst's state goes under"random", andloadAppsets$rt.randomfrom it.LiveTypes.oftypes an instance asRANDOM; the surface gives its five methods (randomanduniformNUM,randrangeandrandintINT,choicethe element type of its list). Any other attribute ofrandomor of an instance, a call ofrandom.Random(...)orrandom.seed(...)in frame code, andfrom random import ...fail the export with the message above or the subset's usual one. - Transpile:
R.uniform(a, b)on aRANDOMis a method call on the resolved object;random.uniform(a, b)becomes$rt.random.uniform(a, b);randrange's optional arguments pass positionally. - Run the same command: all pass.
- Commit:
feat(web): random.Random in frame code, bit for bit with CPython.
uv run pytest tests/web/test_random.py tests/web/test_snapshot.py tests/web/test_types.py -q: all pass, the 14 parametrized draws and the breaking test included.
4One event queue: engine.emit, the frame event, engine.elapsed, handlers in both replaysjs/manifoldx.js · js/replay.mjs · js/browser.js · web/replay.py · web/types.py · web/reach.py · tests/web/test_events.py · tests/web/apps/events.py
interfaces
step and fire (src/manifoldx/web/js/manifoldx.js:862, :872), replay_python (src/manifoldx/web/replay.py:143-198), EventBus (src/manifoldx/events.py) · produces JS class EventBus (emit(name, payload = null), pending: [name, payload][], delivered: string[], drain(deliver) which swaps pending for a new list before delivering, as dispatch_pending does); engine.bus, engine.emit, engine.elapsed, engine.frame; advance(app, frame, dt), exported from manifoldx.js: engine.input.setFrame(frame), then elapsed, the queue (frame event first, the frame's events last), delivery, then step; step keeps its signature; fire is removed. Trace entries gain "events": [name], the names delivered this frame in order. Python: replay_python delivers each frame through engine._event_bus; DELIVERED records names by wrapping the bus's _deliver. Types: Engine.emit (fn, NONE), Engine.elapsed (NUM, read only); a handler's payload types as dict_of(STR, NUM) for "frame" and from its annotation otherwise- Write
tests/web/apps/events.py: a systemtickthat emits("ping", {"n": k})on frames 3 and 4 (counting inengine.state);@engine.on("ping") def on_ping(p: dict)appends[engine.state["frame"], p["n"]]toengine.state["pings"]and emits("pong", {})whenp["n"] == 4;on("pong")counts;on("frame") def on_frame(p: dict)storesp["frame"],p["elapsed"]andp["dt"]inengine.state; a secondon("frame")handler registered after it appends to a list, to check the registration order. Then the failing tests intests/web/test_events.py: Runuv run pytest tests/web/test_events.py -q: fails at the export (engine.emitis not on the runtime surface). - Python replay. Per frame, in this order, as
Engine._draw_frame(src/manifoldx/engine.py:1221-1253):engine.input.set_frame(frame);engine.elapsedstays 0.0 on the first frame and addsdton each later one;engine._gui_bridge.begin_frame(); each entry offrame.get("events", [])throughengine.emit(name, event_of(name, payload))(task 5 fillsevent_of; here it returns the payload);engine._event_bus._pending.insert(0, ("frame", {"dt": dt, "elapsed": engine.elapsed, "frame": engine._frame_index}));dispatch_pending(engine); the systems; the flush;engine._frame_index += 1. The names come from a wrapper ofengine._event_bus._deliverset once per replay; the trace entry's"events"holds this frame's. - Runtime.
EventBusandadvancefollow the interfaces; delivery calls each handler root of that name inapp.rootsorder with the payload (and a read-onlyQuerywhen the root has components, asfiredid).replay.mjs'sreplayandbrowser.js'srunFramecalladvanceinstead ofsetFrame,fireandstep; the agent'seventsarray inbrowser.jsstays until task 9 and is passed as the frame's events.traceEntrywritesbus.deliveredand clears it. - Types and reach.
RUNTIME_SURFACE["manifoldx.Engine"]gainsemitandelapsed. InReach's root seeding (src/manifoldx/web/reach.py:248-254), a handler's first parameter types fromEVENT_PAYLOADS, a new table intypes.pythat tasks 5 and 7 extend ({"frame": dict_of(STR, NUM)}here), unless it is annotated; an unannotated payload of another event fails with the message above. - Run
uv run pytest tests/web/test_events.py tests/web/test_replay.py tests/web/test_frames.py tests/web/test_node_suites.py -q: all pass; the older replays gainevents: ["frame"]on both sides. - Commit:
feat(web): engine.emit, the frame event and handlers in the page, in the desktop's order.
uv run pytest tests/web/test_events.py tests/web/test_replay.py tests/web/test_frames.py tests/web/test_node_suites.py tests/web/test_reach.py -q: all pass, the breaking test included.
5Input events: the DOM's events in the frame, their payload classes on both sidesjs/input.js · js/manifoldx.js · web/replay.py · web/types.py · tests/web/test_input_events.py · tests/web/js/input.test.mjs
interfaces
FrameBuilder and attachDom (src/manifoldx/web/js/input.js), advance and EVENT_PAYLOADS (task 4), KeyEvent, PointerEvent (with pointer_id, task 1), WheelEvent, ResizeEvent (src/manifoldx/input.py:28-77) · produces the frame's optional "events", entries [name, payload]: ["key_down" | "key_up", {"key", "modifiers": [str], "is_down"}], ["pointer_down" | "pointer_up" | "pointer_move", {"x", "y", "dx", "dy", "button", "buttons": [int], "modifiers": [str], "phase", "pointer_id", "gui"?}], ["wheel", {"dx", "dy", "x", "y", "buttons", "modifiers"}], ["resize", {"width", "height", "pixel_ratio"}]; FrameBuilder records them in DOM order and take() returns them; replay.event_of(name, payload) builds the dataclass for the seven input names (tuples for the lists) and returns any other payload as is; JS eventOf(name, payload) builds frozen plain objects with the same fields; EVENT_PAYLOADS gains the four classes, and RUNTIME_SURFACE their fields (key STR, modifiers tuple_of(STR, ...), x NUM, button INT, buttons a tuple of INT, pointer_id INT, width INT, pixel_ratio NUM, ...)- Write the failing Node tests in
tests/web/js/input.test.mjs: And intests/web/test_input_events.py, ontests/web/apps/events.pyextended with one handler per input event (each stores its payload's fields as a list inengine.state, the pointer handler alsoengine.input.mouse_pos): Runuv run pytest tests/web/test_input_events.py tests/web/test_node_suites.py -q: fails. - Implement in
input.js: eachFrameBuilderhandler also pushes its event;dx, dyare this event's position minus the last pointer event's on a move and 0 on a down or up, the last position re-anchored on each, as_InputBridge._build_pointer_event(src/manifoldx/input.py:346-365);buttonsare the held buttons after the event, sorted;pointer_id0 forisPrimary, elsepointerId;take(viewport)adds["resize", {width, height, pixel_ratio}]when the viewport differs from the last frame's (not on the first frame), then returnseventsand resets them.keyUpof a key not held adds nothing.blur()adds akey_upper held key and apointer_upper held button, as its releases. - In
replay.py,event_ofas the interfaces say, used by task 4's loop;KEY_EVENTS,POINTER_EVENTSas module constants beside it. Inmanifoldx.js,eventOf, used byadvance; other names go throughfromJSON. - Run the same command: all pass. Update
replay.py's module docstring with theeventsfield. - Commit:
feat(web): the desktop's input events in the page and the replay frame.
uv run pytest tests/web/test_input_events.py tests/web/test_events.py tests/web/test_node_suites.py tests/web/test_replay.py -q: all pass.
6The clock: time.time() in frame code reads the frame'sjs/pyrt.js · js/input.js · js/manifoldx.js · web/types.py · web/transpile.py · web/replay.py · tests/web/test_clock.py
interfaces
advance (task 4), LIBS · produces the frame's optional "clock", seconds since the epoch as a float, read once by FrameBuilder.take() (Date.now() / 1000), 0.0 when absent; pyrt $rt.setClock(seconds) and $rt.time_time(); advance calls setClock first; LIBS["time"] with one function, time.time (NUM); replay._clock(seconds), a context manager that sets time.time to return the frame's clock while the frame runs and restores it- Write the failing tests in
tests/web/test_clock.py: Runuv run pytest tests/web/test_clock.py -q: fails. - Implement as the interfaces say. In the Python replay,
_clockwraps the whole frame (delivery and systems); setup is outside it and sees the real time. - Run the same command: all pass.
- Commit:
feat(web): time.time() in frame code reads the frame's clock.
uv run pytest tests/web/test_clock.py tests/web/test_events.py tests/web/test_node_suites.py -q: all pass.
7The five widgets in the runtime: their state, the routed bridge, the widget code on both sidesweb/gui.py · web/types.py · web/replay.py · js/manifoldx.js · tests/web/test_widgets.py · tests/web/test_gui_spec.py · tests/web/apps/widgets.py
interfaces
gui_spec and GuiUnsupported (src/manifoldx/web/gui.py:24-63), _GuiBridge._locate and the per-pointer capture (task 1), Joystick (task 2), advance and event_of (tasks 4, 5), guiWidgets (src/manifoldx/web/js/manifoldx.js) · produces gui nodes for Button (name, label), Slider (name, min, max, value, label), Toggle (name, value, label), Joystick (name, value), Image (svg: the SVG text or null, size: svg_size); GuiUnsupported is left for widgets outside these; widget_list(engine) -> list[Widget], by "widget" index; a pointer payload's optional "gui": [widget, fx, fy], the widget the page routed the event to and the pointer's place in that widget's box as fractions of its width and height; Python replay._routed(engine, routes), which replaces engine._gui_bridge._locate for the replay: an event in routes (by id) becomes (replace(ev, x=fx, y=fy), (widget, UNIT)) with UNIT = LayoutBox(0.0, 0.0, 1.0, 1.0), any other (ev, None); JS class GuiBridge in manifoldx.js, a line-for-line port of _GuiBridge with the same _locate rule, and WIDGET_HOOKS, ports of each widget's _on_pointer_* and _on_step; the runtime widget objects gain the fields above and Button.was_clicked(); RUNTIME_SURFACE and WRITABLE for the five; EVENT_PAYLOADS for gui:button:*:click (dict_of(STR, UNKNOWN)), gui:slider:*:change|commit (dict_of(STR, NUM)), gui:toggle:*:change (dict_of(STR, BOOL)), gui:joystick:*:change (dict_of(STR, tuple_of(NUM, NUM))), matched by pattern- Write
tests/web/apps/widgets.py: one top-left panel withButton(name="go", label="Go"),Slider(name="speed", min=0, max=4, value=1, label="speed"),Toggle(name="lit", value=False, label="lit"),Joystick(name="pad")and anImageof a small SVG string; each widget a module global. A system readsGO.was_clicked(),SPEED.value,LIT.valueandPAD.valueintoengine.stateand, on frame 20, writesSPEED.value = 3.0,GO.label = "Again"andLIT.value = True; a handler per widget event appends[engine.state["frame"], payload["value"]](the click[frame]). Then the failing tests intests/web/test_widgets.py, whose script routes pointer events by widget index read fromstate.json'sgui: Intests/web/test_gui_spec.py: the five nodes with their fields;widget_list(engine)[n]is the widget whose node has"widget": n; aWidgetsubclass outside the five still fails withGuiUnsupported. Runuv run pytest tests/web/test_widgets.py tests/web/test_gui_spec.py -q: fails at the export (Button is not supported by export --web yet). - Snapshot and surface.
gui_specwrites the five nodes;Image.svg_datadecodes as UTF-8.RUNTIME_SURFACE:manifoldx.gui.Buttonname,label,was_clicked(fn,BOOL),style_overrides;Slidername,value,min,max,label,style_overrides;Togglename,value(BOOL),label,style_overrides;Joystickname,value(tuple_of(NUM, NUM)),style_overrides;Imagestyle_overrides.WRITABLE: Buttonlabel, Slidervalueminmax, Togglevalue, Joystickvalue, andstyle_overridesof each. - Python replay. After setup,
replay_pythonsetsengine._gui_bridge._locate = _routed(engine, routes); each pointer entry of the frame with a"gui"key addsroutes[id(ev)] = (widget_list(engine)[i], fx, fy)for the event object it emits. The desktop's bridge then runs as it is: the hooks, the latch, the capture per pointer,pointer_over_gui, the focus and the arrow keys. - Runtime.
createEnginemakesengine.gui.bridge = new GuiBridge(engine);advanceresetsengine.gui.pointer_over_guibefore delivery, and delivery calls the bridge forpointer_down,pointer_move,pointer_upandkey_downbefore the handler roots, as the bridge's handlers were registered first on the desktop (src/manifoldx/engine.py:364).WIDGET_HOOKSfollowbutton.py,slider.py,toggle.pyandjoystick.pystatement for statement, setting the value, thenengine.emit. The widget objects ofguiWidgetscarrykind,name, their fields and, for a Button,_latch. - Run the same command: all pass. Then
uv run pytest tests/web/test_export_web.py -q: the case that expectedButton is not supportednow expects the export to succeed; change it to a widget class the page lacks (aWidgetsubclass defined in the test). - Commit:
feat(web): Button, Slider, Toggle, Joystick and Image in the runtime, through the desktop's widget code.
uv run pytest tests/web/test_widgets.py tests/web/test_gui_spec.py tests/web/test_export_web.py tests/web/test_events.py -q: all pass, the breaking test included.
8The page draws the widgets from their style and records where each pointer wentjs/gui.js · js/input.js · js/browser.js · tests/web/js/gui.test.mjs · tests/web/js/input.test.mjs
Two page behaviours change here, both toward the desktop's. A pointer that goes down on the GUI is also a click in the frame (buttons, clicks, pos), as the desktop's input layer records every pointer event before the GUI sees it (src/manifoldx/input.py:316); today the panels swallow it. And engine.gui.pointer_over_gui comes from the bridge (an event this frame hit an interactive widget), no longer from hovering a root panel (src/manifoldx/web/js/browser.js:170).
interfaces
GuiBridge (task 7), FrameBuilder (task 5), panelCss and buildGui (src/manifoldx/web/js/gui.js) · produces widgetCss(node, scale) -> {property: value} for the four drawn widgets; buildGui(layer, spec)'s result gains targetOf(domEvent) -> [widget, fx, fy] | null (the widget that holds this pointer, else the interactive widget under domEvent.target) and hold(pointerId, widget), release(pointerId); sync(widgets) also applies label, value, min, max and the ARIA values; attachDom(canvas, builder, {gui}) listens on the GUI layer for pointerdown and passes gui.targetOf(ev) to builder.pointerDown(ev, target), and the window's pointermove and pointerup pass theirs; data-mx-widget on each widget element; pointerOver is removed- Write the failing tests in
tests/web/js/gui.test.mjs, over the file's fake document: Intests/web/js/input.test.mjs:a pointer down on the GUI is a click and carries its target(the frame'sclicksholds 1, itspointer_downpayload holdsgui). Runuv run pytest tests/web/test_node_suites.py -q: the gui and input suites fail. - Implement in
gui.js. Each widget is built fromnode.style(bg,fg,border,border_color,radius,font_size, times the scale), as the painter reads the same keys (src/manifoldx/gui/painter.py:214-292): the Button a<button type="button">with its label centred; the Slider a track with a fill of widtht(the painter'st),role="slider",aria-valuemin,aria-valuemax,aria-valuenow,aria-labelits label,tabindex="0"; the Toggle a 14 px box, its inner mark when on, and its label,role="switch",aria-checked; the Joystick a pad of its intrinsic 96 px (or its style's size) with a knob 0.4 of its width; the Image an<img>whosesrcisdata:image/svg+xml;charset=utf-8,plus the encoded SVG. Every interactive element hastouch-action: none. Onpointerdown, the Slider and the Joystick callsetPointerCaptureon their element andhold;pointerupandpointercancelrelease. Text goes in throughtextContentonly. - In
input.js,FrameBuilder.pointerDown(ev, target = null)and its move and up addgui: targetto the payload when it is not null.attachDomtakes{gui}and wires the listeners above; positions stay CSS pixels from the canvas's top-left. Inbrowser.js, the line that copiesgui.pointerOvergoes; the GUI'stargetOfis passed toattachDom, and a swapped version's GUI replaces it. - Run the same command: all pass.
- Commit:
feat(web): the page draws Button, Slider, Toggle, Joystick and Image, and routes pointers to them.
uv run pytest tests/web/test_node_suites.py -q: all pass. Chromium runs in task 11.
9The host-page bridge, and an agent's emit in the framejs/browser.js · js/input.js · js/manifoldx.js · tests/web/browser/test_host_page.py · tests/web/browser/test_run_web.py
interfaces
EventBus and advance (task 4), encodeState and fromJSON (src/manifoldx/web/js/manifoldx.js:964, :994), the dev socket's case "emit" (browser.js:327) · produces FrameBuilder.emit(name, payload), an outside event recorded in the frame's events in arrival order, its payload plain JSON; hooks.delivered(name, payload) in createEngine, called by delivery for every event except frame and the seven input events; browser.js sets it to dispatch new CustomEvent("mx:emit", {detail: {name, payload: encodeState(payload)}}) on window and, when window.parent !== window, window.parent.postMessage({mx: "emit", name, payload}, "*"); a message listener takes {mx: "emit", name: string, payload} from window.parent only and calls builder.emit; the agent's emit calls builder.emit too, and browser.js's events array goes- Write the failing tests in
tests/web/browser/test_host_page.py, ontests/web/apps/events.py's export with anon("host:hello")handler (payloaddict) that counts and emits("app:ack", {"n": payload["n"]}). The test writeshost.htmlbeside the export in a temporary copy: aniframeofindex.html, amessagelistener that collects intowindow.got, and a function that posts{mx: "emit", name: "host:hello", payload: {n: 2}}to the frame: Intests/web/browser/test_run_web.py, the agent's emit test now also asserts that the emitted event is in the frame'seventsand that a replay of the tab's frames matches. Runuv run pytest tests/web/browser/test_host_page.py -vwhere Chromium runs: fails. - Implement as the interfaces say. A payload from the host goes through
fromJSONon delivery, as an agent's does; the frame keeps the JSON, so the Python replay emits the same dict. - Run
uv run pytest tests/web/browser/test_host_page.py tests/web/browser/test_run_web.py -v: all pass, no skips. - Commit:
feat(web): a host page talks to the export through events.
uv run pytest tests/web/browser/test_host_page.py tests/web/browser/test_run_web.py tests/web/test_node_suites.py -v: all pass with no skips on a host with Chromium; otherwise push and read the browser job, which fails on any skip.
10web_crowd's controls panel, a handler per event, its Node replay and the breaking testsexamples/web_crowd.py · tests/web/test_web_crowd.py · tests/web/fixtures/web_crowd_script.json
interfaces
script, PATCHES, _copy, _patch and fixtures (tests/web/test_web_crowd.py) · produces examples/web_crowd.py with the controls panel; script(seed, n) extended with events and widget routes; WIDGETS, the widget indices read from the export's state.json; four more entries in PATCHES- Extend
examples/web_crowd.py, keeping its style (constants at the top, plain functions, the docstring's controls updated):- A second top-left panel under the first (the desktop's hit test places top-left panels only,
src/manifoldx/gui/hit_test.py:42-52) withWAVE = Button(name="wave", label="Throw a wave"),GRAVITY = Slider(name="gravity", min=0.0, max=12.0, value=6.0, label="gravity"),SPIN = Toggle(name="spin", value=True, label="spin"),WIND = Joystick(name="wind")and anImageof a short inline SVG (a compass rose). on("gui:button:wave:click")emits("throw", {});on("throw")adds 1 toengine.state["throws"];spawn_wavethrows on Space or whilethrowsis positive, taking one.driftreads gravity fromengine.state["g"], whichon("gui:slider:gravity:change")sets;:commitappends the value toengine.state["commits"]; the spin applies only whileSPIN.value;on("gui:toggle:spin:change")counts; the wind addsWIND.valuescaled by 2 m/s to x and z ofv, read in the system;on("gui:joystick:wind:change")keeps the last value.driftemits("fell", {"n": k})with the number of boxes it destroys whenk > 0;on("fell")adds toengine.state["fallen"].- Each ring is jittered by
RNG = random.Random(1107):RNG.uniform(-0.3, 0.3)per box on its radius, built with a list comprehension at the spawn. - Handlers on
frame(keepspayload["elapsed"]),key_downandkey_up(count),pointer_down,pointer_upandpointer_move(the last[x, y, pointer_id]of each),wheel(moves the camera along its view bydy, clamped),resize([width, height]). pickignores a click whileengine.gui.pointer_over_gui;WAVE.was_clicked()is read bypickto clear the pick, as a second use of the latch.- A system keeps
time.time() % 60.0inengine.state["sec"]and aValueDisplayshows it, so frame code reads the clock.
- A second top-left panel under the first (the desktop's hit test places top-left panels only,
- Extend the script in
tests/web/test_web_crowd.py(regenerate the fixture with--regen): keep 5a's keys, clicks and resize, and record each as the page does (key and pointer events, a resize event at 300); add clicks routed to the Button at 60 and 61 (two clicks, two throws), a drag on the Slider from fx 0.2 to 0.9 over frames 80 to 90, a Toggle at 100, a Joystick drag at fx (0.8, 0.5) over 220 to 260 with a Button tap ofpointer_id4 at 240, a wheel at 270, an ArrowLeft at 280, a clock from 1762500000.0 growing by 1/60. Then: The four new patches each name a real text in the exported file, chosen when the code exists, as 5a's do. - Run
uv run pytest tests/web/test_web_crowd.py -q; fix what the replay finds in the task that owns it, and note it in this plan's departures, until all pass. - Commit:
feat(examples): web_crowd's controls, every widget and event in the page.
uv run pytest tests/web/test_web_crowd.py -q: all pass, eight breaking cases included. uv run python examples/web_crowd.py opens a window where the five widgets work with the mouse and the arrow keys step the gravity Slider after it is clicked, checked by its --render --duration 2 MP4 or manifoldx look under manifoldx run on a host with a GPU or lavapipe.
11Chromium: each widget under a real pointer, two touches at once, the frame checkstests/web/browser/test_web_crowd_page.py · tests/web/browser/conftest.py
interfaces
open_page, served, crowd_export, BATCHES_OF; task 10's example and PATHS · produces open_page(..., touch=False), which makes the context with has_touch=True when asked; touch(page, points), two-finger input through page.context.new_cdp_session(page) and Input.dispatchTouchEvent; widget_box(page, name), the bounding box of [data-mx-widget] for the widget of that name- Write the tests in
tests/web/browser/test_web_crowd_page.py, one__mx.tick(1/60)after each step as 5a'sdrivedoes: Runuv run pytest tests/web/browser/test_web_crowd_page.py tests/web/browser/test_page.py tests/web/browser/test_visual.py tests/web/browser/test_run_web.py -von a host with Chromium and lavapipe. Each failure is a defect of an earlier task or of the page: fix it there, and note in the departures section what the browser forced.test_page.py's drive ofweb_walkclicks over its panel only if it did before; if a click there now changes its trace (task 8's GUI clicks), the test's frames say so and the expectation moves with them. - Commit:
test(web): web_crowd's widgets in Chromium, two pointers, the frame checks.
uv run pytest tests/web/browser -v: all pass with no skips on a host with Chromium; otherwise push and read the browser job, which fails on any skip.
12The docs: events, widgets, the clock, random, the host pageknow-how/web-export.md · know-how/agent-loop.md · CHANGELOG.md · AGENTS.md · examples/README.md
know-how/web-export.md: replace the paragraph that saysengine.emitis not there yet (line 250) with a section "Events in the page": the order of a frame's queue and that an emit waits a frame, the seven input events and their payload fields, the frame event andengine.elapsed, a handler's payload annotation,time.time()and the frame'sclock; in "The GUI", the five widgets, their fields and events, what frame code may write, the arrow keys, the Joystick's y up, top-left panels for desktop parity, and that a pointer on the GUI is also a click (checkengine.gui.pointer_over_gui);random.Randommade at setup and seeded for replays (an unseeded generator differs between any two runs); a section "A host page around the export" with the message forms; in "Replaying", the frame'seventsandclock, theguitarget of a pointer event, the trace'sevents. Add plan 5b's path to the plans line at the top.know-how/agent-loop.md:manifoldx emitreaches the tab in the next frame's events, recorded in its frames.CHANGELOG.mdunder[Unreleased],### Added: events, input events, the frame event andengine.elapsed,time.time(),random.Random, the five widgets and the Joystick, the host-page bridge, web_crowd's controls.AGENTS.md's web target line: plan 5b and its path.examples/README.md: web_crowd's line names its controls.- Commit:
docs(web): events, widgets, the clock, random and the host page.
The know-how's commands and snippets run as written: export examples/web_crowd.py, replay its fixture in Node, open the page with python -m http.server in the folder and use each widget. rg -n "not there yet" know-how/web-export.md prints nothing.
Where this plan departs from the spec
- Widget events are made during delivery, not recorded. Section 06 says the page records input and widget events in the replay frame and Python emits them. On the desktop a widget's event is emitted by its hook while the
pointer_downis being delivered (src/manifoldx/gui/button.py:44, run insidedispatch_pending,src/manifoldx/engine.py:1247), anddispatch_pendingswaps the queue before delivering (src/manifoldx/events.py:133-137), so the event reaches its handler one frame after the pointer. Recordinggui:events in the frame would deliver them a frame early and skip the widget's code (the latch, the value). The frame records the pointer event and the widget it went to; both replays run the widget code, the desktop's own in Python. - A pointer event carries its widget target, and the desktop bridge gets a seam. The page's DOM decides which widget a pointer is on; the desktop lays out widgets its own way (pixel equality is a non-goal, spec section 15) and hit-tests top-left panels only (
src/manifoldx/gui/hit_test.py:42-52). Hit-testing the page's coordinates in Python would pick other widgets._GuiBridge._locate(task 1) is the one method the replay replaces, with the frame's[widget, fx, fy]and a unit box, so every other line of the bridge and the widgets runs as on the desktop. - A capture per pointer, and
PointerEvent.pointer_id, land on the desktop. Section 07 asks for a Joystick and a Button working at once on a phone; the desktop's bridge ends any capture on a new down (src/manifoldx/gui/bridge.py:53-61), which would freeze the Joystick. Task 1 keys the capture by pointer; the desktop has one pointer, 0, so its behaviour stays. - The arrow keys step a Slider on the desktop too, through the bridge's focus. Q4 settled arrow keys on the page's Slider; the parity rule then needs them on the desktop, which has no focus. The bridge focuses the last widget a pointer went down on (task 1), in both replays from the same events, so DOM focus plays no part. This is the plan's one desktop behaviour change.
- A click on the GUI is also an input click, and
pointer_over_guiis the desktop's. Section 06 does not say; the desktop's input layer records every pointer event before the GUI sees it (src/manifoldx/input.py:316) and setspointer_over_guionly when an event of this frame hits an interactive widget (src/manifoldx/gui/bridge.py:32-35,:63-70). The page swallowed clicks on panels and set the flag on hover (src/manifoldx/web/js/browser.js:170). Task 8 changes both, and web_crowd's pick checks the flag. - The Python replay delivers through the engine's bus. It ran the systems only (
src/manifoldx/web/replay.py:189), so handlers never ran in a replay; it now follows_draw_framefrombegin_frameto the flush, and the engine's own handlers (the GUI bridge) run with the app's. - The trace gains
events, the names delivered each frame. Section 13's breaking tests on the event order need the order itself in the trace; payloads hold desktop dataclasses that the trace cannot write as JSON (replay._plain), so only names are traced, and handlers that keep payload fields inengine.statecover the values. engine.elapsedfollows the desktop's wall-clock mode. It is 0 on the first frame and adds each later frame's dt, as_compute_dtcomputes it (src/manifoldx/engine.py:1013-1027). Underset_fixed_timestepthe desktop's run loop never advances it (:1015-1016); the page does not copy that (open question 1).- The clock is
time.time()only. Section 10 says frames take the wall clock thattime.time()returns; othertimefunctions and thefrom time import timeform fail the export with a hint, and a frame withoutclockreads 0.0, as other optional fields read empty. - A
random.Randomis made at setup. Section 02 ports the generator's state; frame code that constructs or reseeds one fails the export, since seeding from an int is a second algorithm (init_by_array) no app here needs.getrandbitsstops at 53 bits, past which a JS number loses integers. - Task 3, against this plan: the draws run through the snapshot, not
run_both.run_bothtranspiles whole modules (reach of everything), where setup'srandom.Random(20261107)would be frame code and fail the export.tests/web/test_random.py:72and:91run setup in Python, take the snapshot, transpile what the roots reach and callmain()in Node afterloadState; Python'smain()runs after the snapshot, from the same state. - Task 3:
{"__random"}is a table entry, reached through{"__ref"}. As an inline value, a generator two objects hold would load as two generators drawing the same numbers. It sits in the table beside lists and arrays (src/manifoldx/web/snapshot.py:245,src/manifoldx/web/js/manifoldx.js:49), so it stays one object. - Task 3: the module's generator is set in
load, whichloadAppandloadStateshare (src/manifoldx/web/js/manifoldx.js:103), so the snapshot tests' loader gets it too.$rt.randomis a liveexport letthatsetRandomreplaces; it is null when no reached code calls a module function. - Task 3: the messages the plan leaves open.
random.seed(...)in frame code says "a reseed in frame code (seed it at setup)" (src/manifoldx/web/transpile.py:1554); anotherrandomfunction is the subset'srandom.shuffle()form; another method of a generator, or a write of its attribute, is reach's "on a random.Random, a library object the browser does not have".getrandbitspast 53 bits throws aValueErrornaming the page (src/manifoldx/web/js/pyrt.js:792). The test file adds two tests to the plan's six: the module state written under"random", and those four failing forms. - Task 1: the bridge tests use an engine stub with no canvas. The plan says "the file's existing engine and panel helpers"; those helpers open an offscreen wgpu canvas and run
_draw_frame, which the routing does not need. The five tests (tests/gui/test_bridge.py:157) use_BusEngine, a real_GuiRootwith the bus'sonandemit, and fire the handlers the bridge registered. The Slider's focus is cleared only by a down that hits nothing, as the plan says; a down while the input layer holds the pointer captured returns before_locateand leaves the focus (src/manifoldx/gui/bridge.py:55). - Task 2: the knob is 0.4 of the pad's diameter, not of its width. The plan's test fixes
0.4 * box.won a square box; the painter takes0.8 * r, r half the shorter side (src/manifoldx/gui/painter.py:305), so a non-square Joystick's knob stays inside its pad. The CHANGELOG lists the widget under Added. - Task 4: the payload error ends in the subset's words.
TranspileErrorappends "is outside the subset" to every message (src/manifoldx/web/types.py:507), so the message readsapp.py:5: the payload of on("ping") on_ping, with no type (annotate it: def on_ping(p: dict)), is outside the subset(src/manifoldx/web/reach.py:279). An annotation the transpiler cannot read, such as a baredict, counts as one; for an event inEVENT_PAYLOADSthe table's type fills it. A root with no event (a test's hand-madeRoot) is not checked. - Task 4: three test apps annotate their payloads, and
fire's users move toadvance.bump(payload)intests/web/apps/dev_orbit.py:52,tests/web/test_decorators.py:27andtests/web/test_queries.py:81now readpayload: dict, which the new rule requires.tests/web/js/runtime.test.mjs's twofiretests become threeadvancetests (delivery before the systems, an event nobody handles, an emit that waits a frame), and its traceEntry test expectsevents;test_decorators.py's runner sends the bump as the frame's event. - Task 4: the breaking test drains again after the systems. Rather than a marker in
EventBus.emit,tests/web/test_events.py:49patches the export'sadvanceto deliver aftersteptoo, so tick's ping reaches on_ping in the frame that emitted it: the faithful form of "emits delivered in the frame that made them". The test app'sticktakes an unannotated query, as web_walk's systems do. - Task 4: the page records nothing new yet.
browser.jspasses the agent's queued emits as the frame'seventsin a copy of the frame (src/manifoldx/web/js/browser.js:170);mx.frameskeeps the frame the builder made, so a Chromium replay does not see agent emits until task 9 records them.replay.mjsreads a frame's event payloads throughfromJSON, so a handler gets a Map as in the page. The engine'selapsedandframestart at 0 in each loaded version, so underrun --weba save restarts them, where the desktop'srunkeeps counting. - Task 5: a frame's event payloads cross as JSON, and
advancereads them.eventOf(src/manifoldx/web/js/manifoldx.js:903) is the one place a payload becomes runtime values (advance, :923): the seven input events as frozen objects, any other throughfromJSON. Soreplay.mjsno longer converts, and the agent's emit inbrowser.jsqueues its JSON payload (src/manifoldx/web/js/browser.js:326);fromJSONof a Map would give an empty Map.tests/web/js/runtime.test.mjs's delivery test andtests/web/test_decorators.py's runner send plain JSON. - Task 5:
take()always writesevents, empty or not. The page's frames carry the field every frame, as they carry the other optional ones, so the empty-frame test expectsevents: [](tests/web/js/input.test.mjs:16). Task 6'sclockdoes the same. - Task 5: the forms the plan leaves open. A wheel event's
x,yare the last pointer position (src/manifoldx/web/js/input.js:125):attachDomhands the wheel the DOM event, whose coordinates are the window's. Apointer_upis recorded even for a button not held, as rendercanvas sends it; a key not held adds nothing, as the plan says.blur()'s releases carry no modifiers, since it clears them first (:137). An event with noisPrimaryfield counts as primary, sopointer_idis the DOM'spointerIdonly whenisPrimaryis false (:74);attachDompasses both. The payloads' list fields (modifiers,buttons) type as lists, as atuple[X, ...]annotation does (src/manifoldx/web/types.py:731), and their fields are read only: none is inWRITABLE. - Task 6: the page's clock never runs backwards.
take()keeps the larger ofDate.now() / 1000and the last frame's clock (src/manifoldx/web/js/input.js:167), so a system clock that steps back (NTP) does not maketime.time()in frame code go back; the test steps it back once. Every frame the page builds carriesclock, as it carriesevents. - Task 6: the messages end in the subset's words. As task 4's, the hint comes before the suffix TranspileError adds:
app.py:7: `time.perf_counter()` (frame code reads time.time(), the frame's clock, or engine.elapsed) is outside the subset (reached from system tick)(src/manifoldx/web/transpile.py:1556). The import form names the import, since the name alone (time) says nothing:`from time import time` (frame code reads ...)(:936).replay._clock(src/manifoldx/web/replay.py:247) patches the module'stime.time, which the app'simport timereads. - Task 7: routes live for one frame and are taken once. The plan keys them by
id(ev); an event the bridge never locates (the input holds the pointer captured, so_on_pointerreturns first) would leave its id behind for a later event to reuse. The replay clears the routes at each frame's start, since a frame's events are delivered in that frame, and_routedpops the route it reads (src/manifoldx/web/replay.py:235, :278). The runtime keys a Map by the event object and does the same. In both replays a pointer event with noguiis on no widget: the desktop's hit test never runs there. - Task 7: the rest of the plan's open forms. A Slider's
labeltypesstr | None, its default being None (src/manifoldx/web/types.py:781). An Image node'ssvgis null for a TextureHandle. The runtime knows which widgets capture the pointer by kind (CAPTURES,src/manifoldx/web/js/manifoldx.js:963), as_gui_captures_pointersays on the desktop. The plan'stest_export_web.pycase is intests/web/test_gui_spec.py:168and the test after it, both now on aGaugewidget the test defines. The test script presses the Slider at frame 25 and sends ArrowRight at 27, since the Button tap of frame 15 holds the focus until then. An Image needs thesvgextra (thorvg) at export to measure the SVG; CI'sbrowserjob does not install it (.github/workflows/test.yml:91), so task 10's web_crowd with an Image needs--extra svgthere. - Task 7: the page's pointer_over_gui is already the bridge's.
advanceresets the flag before delivery, so the hover valuebrowser.jscopies in before it (src/manifoldx/web/js/browser.js:169) is overwritten; task 8 removes that line, as it says. - Task 8: a pointerup releases its widget after it is recorded. The plan has
pointeruprelease the hold ingui.js; a listener on the widget's element runs before the window's, so the up would lose its target and the bridge would read the canvas position against the unit box.attachDomreleases once the up has readtargetOf(src/manifoldx/web/js/input.js:225);gui.jsreleases onpointercancelonly (src/manifoldx/web/js/gui.js:313). SoattachDom'sguicarrieslayer,targetOfandrelease;browser.jspasses one that forwards to the running version's GUI, so a swap needs no new listeners (src/manifoldx/web/js/browser.js:151). - Task 8: the forms the plan leaves open. A down on the canvas asks
targetOftoo (src/manifoldx/web/js/input.js:206), so a second finger is routed as the first; it names no widget unless that pointer is held. A down on a panel's background is recorded with no target, a click in the frame, as on the desktop where the hit test finds no widget there. The Toggle hastabindex="0"as the Slider does, and a Slider with no label reads its name asaria-label(src/manifoldx/web/js/gui.js:267).widgetCssserves the Image too;data-mx-widgetmarks all five; only the four interactive ones are targets (:77). The Button's padding is the 12 by 4 its intrinsic size adds.destroykeeps no listener list, since the root panels have none now. - Task 9: the frame builder is made before the app loads. A host may post while the page loads; the builder and the
messagelistener are made at the module's top (src/manifoldx/web/js/browser.js:56), so the message waits in the builder for the first frame. The host hears each event with its payload asencodeStatewrites it, inpostMessageas inmx:emit, so a dict arrives as{"__dict": [...]}in both (:65). The hook runs after the GUI bridge and before the app's handlers (src/manifoldx/web/js/manifoldx.js:1145). A message from the page's own window, when it is not framed, is ignored too. - Task 9: the agent's emit replays in a test of its own. The plan adds the replay to
test_agent_commands, whosemanifoldx setchanges the state outside any frame, so no replay of its frames can match.test_an_agent_emit_is_in_the_frame_and_replays(tests/web/browser/test_run_web.py:280) ticks a fresh tab, emits, and replays its frames; its copy ofdev_orbit.pydrops the("cache", 1)entry, since the Python trace writesengine.stateas JSON, which has no tuple keys.tests/web/apps/events.pygains thehost:hellohandler the host tests use. - Task 10: the script is built as the page builds frames, and the Slider is pressed before the arrow key.
scriptruns a small copy ofFrameBuilder(tests/web/test_web_crowd.py:57): every wandering position is apointer_move, each press is released the frame after it, a second finger shares the left button as in the page, and no wandering move is made while a control holds the pointer, since the page would route it to that control. The tap of pointer 4 on the Button at 240 makes the Button the focused widget, so the ArrowLeft at 280 would step nothing; a tap on the Slider at its middle at 275 (:50) makes it the focus, and the arrow steps it to 5.4.WIDGETSis a constant thattest_the_widget_indices_are_the_exports(:200) checks againststate.json, soscript()needs no export. - Task 10: 5a's checks follow the new script. The thrown waves of frames 62 and 63 take slots 49 to 96 and are still up at 199, so frame 199 has 49 alive, a high water of 97, and the wave at 200 joins them in the freed slots (
tests/web/test_web_crowd.py:238). The Button's click at 60 clears the pick throughwas_clicked, so the pick of frame 120 restores nothing (:256). The wave after the resize is the seventh. - Task 10: the forms the plan leaves open in the example.
q[Transform].pos[:, 1] < FLOORgives the entity indices, not a mask, sofellcounts them withlen(examples/web_crowd.py:136). The wind is an acceleration,WIND.valuetimes 2 m/s each second, the Joystick's up blowing away from the camera. The wheel scales the camera's distance by1 + dy * 0.002, kept within 0.5 and 2 times the first. The pick is cleared bywas_clickedonly when there is one (:164), and the latch is read every frame. The Joystick and the compass sit in a nested row panel (:347): the desktop's column stretches a child across the panel, which drew the Joystick as a stadium. So the Joystick's index is 11. CI'sbrowserjob syncs thesvgextra, which the Image's export needs. - Task 11: the page needed no fix. Under Chromium the five widgets drew and worked as the fake-DOM tests said: the Toggle's mark sits 3 px inside its 14 px box, the Button has the 12 by 4 padding of its intrinsic size and fills the column's width as the desktop's column stretches it, the Slider and the Toggle carry their roles, and the Image's data URL loads. A move routed to a held Slider gets there twice over in Chromium, through
setPointerCaptureand through the hold map; the fake DOM has no pointer capture and tests only the hold map, so it stays. The frame checks fail only with both gone. - Task 11: two fingers through CDP. Chromium's
Input.dispatchTouchEventlifts the fingers atouchEndlists, not those it leaves out, and hands apointermoveto the page at its next animation frame, which a stopped loop does not reach by itself. Sotouch(page, points)sends a lift as atouchEndof the lifted fingers and waits onerequestAnimationFrame(tests/web/browser/conftest.py:284, :293). Both fingers share the page's left button, as task 10's departure says: after B lifts, A's moves carrybuttons: []. - Task 11: one capture for all pointers freezes the Joystick, it does not zero it. The plan expected the wind to drop at the Button's frame. With one capture, B's down ends A's capture; A's later moves reach the Joystick as uncaptured moves, which widgets ignore, so the value stays where A left it until A lifts. The two-finger script moves A up after B's tap, and
joystick_follows_finger_a(tests/web/browser/test_web_crowd_page.py:271) fails on that frame;comparealso reports a mismatch, since the Python replay keeps the capture per pointer. - Task 11: 5a's Chromium test drives the script's events.
drive(tests/web/browser/test_web_crowd_page.py:33) makes each frame's events with Playwright, a routed one at its fraction of the widget's real box. It leaves out pointer 4's tap (:50), since the mouse is one pointer and the two-finger test covers it, so the page throws six waves, not seven. Playwright'smouse.uphas no position, so the up that ends the Slider's drag at fx 0.9 is preceded by a move there, which the script does not have; gravity then differs from the script's for a frame and the thrown waves fall a few frames earlier than in the fixture's trace. The test checks the page against Python on the page's own frames, so 5a's fixed count at frame 199 became: two waves at 7, four at 63, and boxes destroyed before 200 (:91). - A handler's payload types from its event or its annotation. Section 10 lists the event classes as types; an app's own event has no class, so its handler annotates the payload (
def on_ping(p: dict)), and the export says so when it does not. - The host page hears what the app and its widgets emit, at delivery. Section 06 says every event the app emits; widget events are emits too (
engine.emitin the widget code), so the host hears them, and it hears each one when the queue delivers it, in the page's order. Input events and the frame event are not sent out. A message is taken fromwindow.parentonly. - An agent's
manifoldx emitis recorded in the frame. Plan 3 fired it before the systems (src/manifoldx/web/js/browser.js:171), outside any replay; it now enters the frame's events like a host message, so a replay of the tab's frames includes it. - The Joystick's numbers are fixed here. Section 07 gives a value in the unit disc; task 2 fixes the radius (half the shorter side), y up, the clip by
math.sqrt(x * x + y * y)(nothypot, whose last bit differs between libms), and the release to(0.0, 0.0)with a change event. - The Image is a data URL. Section 07 shows the SVG bytes as an
<img>; it is written into the gui node as text and shown through adata:image/svg+xmlURL, which runs no script and needs no request.
Open questions, settled
The maintainer settled all three questions on 2026-11-07 by accepting each recommendation. Each one keeps its question; its last paragraph is now the decision.
1 · Fixed timestep and engine.elapsed on the desktopsettled · maintainer
Under set_fixed_timestep, Engine.run's frames never advance engine.elapsed, so engine.delay() and elapsed_at() never resolve there; only render_frame adds the dt (src/manifoldx/engine.py:1477). The page adds every frame's dt.
decisionThe fixed timestep is out of 5b, since no replay runs that mode. Adding the fixed dt in _compute_dt on the desktop is filed as gia-uh/manifoldx#168.
2 · The arrow keys on a desktop Slidersettled · maintainer
Task 1 makes the arrow keys step a Slider after it is clicked, on the desktop as in the page. An app that steers with the arrows sees the Slider move until a click lands elsewhere. The alternative was to drop arrow keys from Q4's decision, which loses the page's keyboard access to the Slider.
decisionThe arrow keys step a clicked Slider on the desktop, and the CHANGELOG lists it under Changed as a behaviour change.
3 · Panels anchored elsewhere than top-leftsettled · maintainer
The desktop hit-tests top-left panels only (manifoldx#13), so a Button in a bottom-right panel clicks in the page and not on the desktop.
decisionweb_crowd's panels stay top-left in 5b, and #13 (anchors on the desktop) is fixed before plan 5c, whose second consumer puts its buttons in a column on a side.
Self-review
Spec coverage, 5b of section 12: emit (task 4), the input events (5), the frame's events and clock (4, 5, 6), MT19937 (3), the host-page bridge (9), Button, Slider, Toggle, Image and Joystick, desktop first (1, 2, 7, 8). Done: web_crowd's panel and a handler per event (10), its Chromium replay with each widget under Playwright's pointer and the frame checks (11). Section 13's items for 5b: random.Random over 10,000 draws per method from a seeded and a mid-stream state, rel=0 (3); the breaking tests on emits in the same frame, the widget value after its event and the random state (10); the two-pointer touch (11); Joystick in the painter and the bridge (2). Sections 06 and 07's rules: the frame event's payload and order (4), a handler's read-only query kept from 5a (4), the latch consumed on read (7), the Slider's pointer captured while dragging (1, 7, 8), ARIA roles and the arrow keys (1, 8).
Names across tasks: pointer_id, _captured, _locate, _focused, _on_step (1) in 7; Joystick (2) in 7, 8, 10; Random and {"__random"} (3) in 10; EventBus, advance, EVENT_PAYLOADS, the trace's events (4) in 5 to 11; event_of, eventOf, the frame's events (5) in 7, 9, 10; clock, setClock (6) in 10, 11; widget_list, _routed, UNIT, GuiBridge, WIDGET_HOOKS, the gui target (7) in 8, 10, 11; targetOf, data-mx-widget (8) in 11; FrameBuilder.emit, hooks.delivered (9) in 10 and 11.
Proportion: code is given for tests whose assertions carry values; implementations are named by signature and the desktop file and line they follow statement for statement.