16. Lifecycle of a canvas#
Status: decided by the author, 2026-11-13 (rest renamed ready, and made a moment, later the same day). Not built yet. It covers a canvas (and a display or
a readout) and its own listeners on-view and on-ready. No control is involved.
16.1. Timeline#
sequenceDiagram
participant Page
participant Copy as Canvas copy
participant Scene
Page->>Copy: page loads
Note over Copy,Scene: state -1: the values at page load
Copy->>Copy: first comes into view
Copy->>Scene: on-view plays (priority 1000)
Note over Copy,Scene: state 0: the values when on-view ends.<br/>Copy is ready: data-mtp-ready, mtp-state.<br/>Still images are captured now.
Copy->>Scene: on-ready plays (priority 300)
A canvas with no on-view has no state -1: the values at page load are its state 0, it is
ready from the start, and its on-ready is triggered when the page loads.
16.2. Rules#
State -1 of a canvas copy is the values at page load. It exists only when the canvas has an
on-view.on-viewis triggered when the copy first comes into view, if the scene still has the values at page load. Otherwise it is not triggered. It may not loop (compile error).State 0 is exactly the values after the
on-viewhas played from the values at page load.Ready: a canvas is ready, in every copy at once, from the first moment the
on-viewof one of its copies has ended, or from page load if it has noon-view. It stays ready from then on. Ready is a moment, not a comparison of values. A copy whoseon-viewis not triggered, because its values had already changed, is ready because its canvas is.on-viewhas priority 1000. Until a canvas is ready, every input that belongs to it is disabled, and it is enabled once the canvas is ready. An input belongs to a canvas when it is a listener inside the canvas’s body, or a control that writes a value some shape the canvas shows depends on (the compiler works this out).on-readyis triggered once, when the canvas becomes ready. It may play any animation, at priority 300.Compile errors: an
on-viewthat loops, and a move inon-viewwhosetoexpression depends on the value it moves.Still images are captured at the moment a canvas becomes ready.
The page is ready once every canvas, display and readout on it is ready. Controls do not count. A display or a readout has no
on-view, so it is ready from the start. The page is static: no view or control is added to or removed from it after it loads.On the page (docs/page-interface.md): each copy has
data-mtp-readyonce ready and firesmtp-statethen.<mtp-model>hasdata-mtp-readyonce the page is ready. The model’s oldmtp-readyevent (the model has loaded) is renamedmtp-loaded.on-showandon-hideare not part of the lifecycle (the author, 2026-11-14): nothing but theon-viewplays before state 0, ready never waits for them, and they play only when a copy starts or stops showing a shape after state 0.