ApplyOp when your application edits YAML and needs a fresh render. Keep persistence explicit: applying an edit returns source; it does not save an application-owned file.
Direct-manipulation editing (for embedders)
This is the contract a cloud service or a WASM client uses to turn a canvas gesture into a new DSL document — the same logic that powers Studio’s drag/edit, exposed as pure, stateless functions:- The transform is a pure function of
(format, src, op)— no server state. (Studio works by POSTing the whole DSL each time; the text is the only source of truth.) - The rewrite preserves the user’s comments and formatting — it is line/regex text surgery, not a reformatting YAML round-trip.
EditOp kinds (the field set read depends on Kind):
move-segment indexes ConnectorRoute.World3D from a render of the same
source. A UI should hit-test Drawing.Editable intervals, which map final
polyline segment parameters back to RouteSegment using the producer’s exact
source record. Curves, ambiguous final projected overlaps and displaced
coincident paths have no edit mapping. These intervals are not proven pixel
visibility: intersect them with the active coverage result and native hit
testing. Studio also checks pointer ambiguity in client coordinates: a
different visible leg within one CSS pixel of the best hit distance prevents
selection, including a visible leg that has no edit mapping. Covered geometry
does not compete in that pointer-distance check.
The operation leaves input unchanged on rejection or a zero effective delta.
It rejects unsupported routes, invalid indices/coordinates, oversized results
and aliased connector mappings. YAML surgery targets the selected scene and
connector, preserving surrounding source and comments; the selected flow
mapping or waypoint field may be reformatted. JSON keeps fields and values,
with normalized indentation. Undo belongs to the caller: record history only
after accepting a valid source and SVG response.
For the lowest level — the individual comment-preserving text operations — import
the yamledit sub-package.
HTTP and persistence
Studio wraps the same contracts with local HTTP endpoints. See the endpoint table for routes, parameters and result fields./api/save is the separate write-back path; the Studio frontend invokes it automatically for parseable nonempty edits in serve mode.
Source editing is YAML-oriented. D2 and JSON parsing support does not imply every text-surgery operation supports those formats. Choose a format.