Skip to content

feat(js): add View JS object for main-view automation + screenshots#2100

Open
edumeneses wants to merge 1 commit into
masterfrom
feature/js-view-screenshot-api
Open

feat(js): add View JS object for main-view automation + screenshots#2100
edumeneses wants to merge 1 commit into
masterfrom
feature/js-view-screenshot-api

Conversation

@edumeneses

Copy link
Copy Markdown
Contributor

What

Adds a new View JavaScript object (JsViewContext) that exposes the main
scenario view to scripting — enabling automation of the editor for tasks like
generating documentation screenshots. It is a sibling of the existing Score
(EditContext) and Util objects.

API (all methods no-op when there is no GUI, e.g. --no-gui)

Screenshots

  • View.grabScene(path) — render the scenario scene to SVG (vector), reusing the F10 snapshot code path
  • View.grabMainWindow(path) — grab the main window (with chrome) → raster (PNG by extension)
  • View.grabScreen(path) — grab the whole screen, all windows → raster

Viewport / navigation

  • View.zoom(zx, zy), View.scroll(dx, dy), View.setZoomRatio(r)
  • View.centerOn(process) — focus the view on a given ProcessModel, resolving its on-screen item in both nodal (NodeItem) and temporal (layer) modes
  • View.goToInterval(interval), View.fit(), View.recenter()

Mode

  • View.setNodal(bool) / View.isNodal() — switch between temporal and dataflow modes

zoom/scroll are also kept on Score as aliases (non-breaking).

How

  • SnapshotAction: the scene→SVG logic is extracted into an exported, reusable
    Scenario::renderSceneToSvg(scene, path, rect) so the F10 action and
    View.grabScene() share one code path (F10 behavior unchanged).
  • ScenarioDocumentPresenter: adds public setNodalMode() / recenter()
    wrappers so the view-control functionality is reachable from the JS object.
    Mode switching routes through the toolbar action so its checked state stays in sync.
  • JsViewContext reaches the document/view/presenter via
    GUIAppContext().currentDocument(), a viewDelegate() cast, and
    IDocument::try_presenterDelegate<ScenarioDocumentPresenter>() (returns null
    headless → methods no-op). Registered as View on the console and script-UI engines.

Testing

  • Builds clean (scenario + js plugins compile and link).
  • Verified in a live GUI console: View.grabScene() produced a valid 79 KB SVG,
    View.grabMainWindow() a 1882×2085 PNG, and View.isNodal() returned the
    expected value.

🤖 Generated with Claude Code

Expose the main scenario view to JavaScript automation through a new
`View` object (JsViewContext), registered on the console and script-UI
engines. Enables scripting the editor for e.g. documentation captures.

API (all no-op when there is no GUI, e.g. --no-gui):
- grabScene/grabMainWindow/grabScreen: SVG (scene) and raster screenshots
- zoom/scroll/setZoomRatio: viewport control
- centerOn(process): focus the view on a given ProcessModel, resolving its
  on-screen item in both nodal (NodeItem) and temporal (layer) modes
- goToInterval/fit/recenter: navigation
- setNodal/isNodal: switch between temporal and dataflow modes

SnapshotAction: extract the scene->SVG logic into a reusable, exported
renderSceneToSvg() so F10 and View.grabScene() share one code path.

ScenarioDocumentPresenter: add public setNodalMode()/recenter() wrappers
so the view-control functionality is reachable from the JS object.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@edumeneses edumeneses self-assigned this Jun 26, 2026
@edumeneses edumeneses requested a review from jcelerier June 26, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant