OpenFresco.Editor.Ops (open_fresco v0.1.0)

Copy Markdown View Source

Pure scene-mutation and hit-test operations for the editor — the server-authoritative core the editor LiveComponent and its JS hook drive. Keeping them pure (no LiveView, no DOM) makes the editing model fully testable without a browser; the interactive layer is a thin shell over these.

All coordinates are canvas pixels (the same space scenes use). The drag gestures the browser reports are converted to canvas deltas by the hook, then applied here.

Summary

Functions

Move an element to the top of the z-order (rendered last / on top).

Remove an element by id.

The id of the top-most element containing {x, y} (canvas px), or nil.

Translate an element's box by (dx, dy).

Resize an element by dragging a corner handle (0 TL, 1 TR, 2 BR, 3 BL) by (dx, dy). Width/height are clamped to a small minimum and normalized if a corner is dragged past its opposite.

Set an element's box directly (absolute canvas px), clamped/normalized.

Functions

bring_to_front(scene, id)

@spec bring_to_front(OpenFresco.Scene.t(), String.t()) :: OpenFresco.Scene.t()

Move an element to the top of the z-order (rendered last / on top).

delete(scene, id)

Remove an element by id.

hit_test(scene, x, y)

@spec hit_test(OpenFresco.Scene.t(), number(), number()) :: String.t() | nil

The id of the top-most element containing {x, y} (canvas px), or nil.

move(scene, id, dx, dy)

Translate an element's box by (dx, dy).

resize(scene, id, corner, dx, dy)

@spec resize(OpenFresco.Scene.t(), String.t(), 0..3, number(), number()) ::
  OpenFresco.Scene.t()

Resize an element by dragging a corner handle (0 TL, 1 TR, 2 BR, 3 BL) by (dx, dy). Width/height are clamped to a small minimum and normalized if a corner is dragged past its opposite.

set_box(scene, id, box)

@spec set_box(OpenFresco.Scene.t(), String.t(), map()) :: OpenFresco.Scene.t()

Set an element's box directly (absolute canvas px), clamped/normalized.