drishti 0.2.0

Rust frontend orchestration framework: design publication plus deterministic reference cores for the Logical Works ink lab, the GPU residency model and the Logic OS Canvas protocol, motion, scene and native host broker; no qualified GPU backend yet.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
//! Prepared presentation frames and their frame-local authority.
//!
//! Split from the model for the size law: the model owns the input
//! vocabulary, resource envelope, lease and artifact; this module owns the
//! frame the reducer prepares and the token that admits input against it.

use std::sync::Arc;

use super::model::{Artifact, CommitStatus, View};

/// Frame-local authority. Cannot be constructed outside [`crate::canvas_scene::Canvas`];
/// not a capability token or an authenticated lease. Equality is instance
/// identity plus generation, serial, and revision.
///
/// # Examples
///
/// ```
/// # use drishti::canvas_protocol::SessionInvariant;
/// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
/// # let id = "11111111-1111-1111-1111-111111111111";
/// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
/// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
/// let first = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?.token();
/// let second = canvas.prepare(0.0, 900, 600, true)?.ok_or("forced frame")?.token();
/// assert_eq!(first.clone(), first);
/// assert_ne!(first, second);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[derive(Clone, Debug)]
pub struct FrameToken {
    /// Presenting instance identity.
    pub(crate) instance: Arc<()>,
    /// Instance generation.
    pub(crate) generation: u64,
    /// Frame serial within the instance.
    pub(crate) serial: u64,
    /// Scene revision the frame was prepared at.
    pub(crate) revision: u64,
}

impl PartialEq for FrameToken {
    fn eq(&self, other: &Self) -> bool {
        Arc::ptr_eq(&self.instance, &other.instance)
            && self.generation == other.generation
            && self.serial == other.serial
            && self.revision == other.revision
    }
}

impl Eq for FrameToken {}

/// One prepared presentation frame.
///
/// Fields are private: the reducer builds frames through [`Frame::new`] and
/// every reader goes through the accessors.
///
/// # Examples
///
/// ```
/// # use drishti::canvas_protocol::SessionInvariant;
/// # use drishti::canvas_scene::{Artifact, Canvas, Limits, View};
/// # let id = "11111111-1111-1111-1111-111111111111";
/// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
/// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
/// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
/// assert_eq!(frame.artifact().key(), id);
/// assert_eq!((frame.width(), frame.height(), frame.target()), (900, 600, View::Source));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Frame {
    /// Frame-local authority.
    pub(crate) token: FrameToken,
    /// Presented artifact.
    artifact: Arc<Artifact>,
    /// Visible status (optimistic overlay when set).
    commit_status: CommitStatus,
    /// Confirmed domain status, never the overlay.
    confirmed_commit_status: CommitStatus,
    /// Whether an optimistic overlay is active.
    optimistic: bool,
    /// Spring position on the 0/1/2 view axis.
    position: f64,
    /// Spring velocity.
    velocity: f64,
    /// Navigation target.
    target: View,
    /// Scroll offsets in [`View::index`] order.
    scroll: [usize; 3],
    /// Viewport width.
    width: u32,
    /// Viewport height.
    height: u32,
    /// Reduced-motion mode.
    reduced_motion: bool,
    /// Whether motion is still settling.
    animating: bool,
}

impl Frame {
    /// Assemble one prepared frame. Only the reducer builds these: the core
    /// identity (authority, artifact, statuses, spring state) arrives here
    /// and the view state attaches through [`Frame::set_target`],
    /// [`Frame::set_scroll`], [`Frame::set_viewport`],
    /// [`Frame::set_reduced_motion`], and [`Frame::set_animating`], so one
    /// expression still admits no half-built frame while this constructor
    /// stays at the seven-argument clipping bound.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, CommitStatus, Frame, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let prepared = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// let frame = Frame::new(prepared.token(), prepared.artifact().clone(), CommitStatus::Running, CommitStatus::Proposed, false, 0.0, 1.0);
    /// assert_eq!((frame.commit_status(), frame.position(), frame.velocity()), (CommitStatus::Running, 1.0, 0.0));
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub fn new(
        token: FrameToken,
        artifact: Arc<Artifact>,
        commit_status: CommitStatus,
        confirmed_commit_status: CommitStatus,
        optimistic: bool,
        velocity: f64,
        position: f64,
    ) -> Self {
        Self {
            token,
            artifact,
            commit_status,
            confirmed_commit_status,
            optimistic,
            velocity,
            position,
            target: View::Source,
            scroll: [0, 0, 0],
            width: 0,
            height: 0,
            reduced_motion: false,
            animating: false,
        }
    }

    /// Attach the navigation target.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits, View};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let mut frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// frame.set_target(View::Evidence);
    /// assert_eq!(frame.target(), View::Evidence);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn set_target(&mut self, target: View) {
        self.target = target;
    }

    /// Attach the scroll offsets in [`View::index`] order.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let mut frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// frame.set_scroll([0, 1, 0]);
    /// assert_eq!(frame.scroll(), [0, 1, 0]);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn set_scroll(&mut self, scroll: [usize; 3]) {
        self.scroll = scroll;
    }

    /// Attach the viewport size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let mut frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// frame.set_viewport(1024, 768);
    /// assert_eq!((frame.width(), frame.height()), (1024, 768));
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn set_viewport(&mut self, width: u32, height: u32) {
        self.width = width;
        self.height = height;
    }

    /// Mark the frame as prepared under reduced motion, so a renderer snaps
    /// instead of tweening.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let mut frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// frame.set_reduced_motion(true);
    /// assert!(frame.reduced_motion());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn set_reduced_motion(&mut self, reduced_motion: bool) {
        self.reduced_motion = reduced_motion;
    }

    /// Attach whether motion is still settling.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let mut frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// frame.set_animating(true);
    /// assert!(frame.animating());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn set_animating(&mut self, animating: bool) {
        self.animating = animating;
    }

    /// Frame-local authority.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.token(), frame.token());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub fn token(&self) -> FrameToken {
        self.token.clone()
    }

    /// Shared handle to the artifact this frame presents; its text is what
    /// the renderer draws.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits, View};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.artifact().text(View::Source), "one\ntwo");
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub fn artifact(&self) -> &Arc<Artifact> {
        &self.artifact
    }

    /// Visible status (optimistic overlay when set).
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, CommitStatus, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.commit_status(), CommitStatus::Proposed);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn commit_status(&self) -> CommitStatus {
        self.commit_status
    }

    /// Confirmed domain status, never the overlay.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, CommitStatus, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.confirmed_commit_status(), CommitStatus::Proposed);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn confirmed_commit_status(&self) -> CommitStatus {
        self.confirmed_commit_status
    }

    /// Whether an optimistic overlay is active.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert!(!frame.optimistic());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn optimistic(&self) -> bool {
        self.optimistic
    }

    /// Spring position on the 0/1/2 view axis.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert!((0.0..=2.0).contains(&frame.position()));
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn position(&self) -> f64 {
        self.position
    }

    /// Spring velocity in view-axis units per second; finite for every
    /// prepared frame.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert!(frame.velocity().is_finite());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn velocity(&self) -> f64 {
        self.velocity
    }

    /// View the spring is travelling to (the navigation target at prepare time).
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits, View};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.target(), View::Source);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn target(&self) -> View {
        self.target
    }

    /// Scroll offsets in [`View::index`] order.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.scroll(), [0, 0, 0]);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn scroll(&self) -> [usize; 3] {
        self.scroll
    }

    /// Viewport width in pixels this frame was prepared for.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 800, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.width(), 800);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn width(&self) -> u32 {
        self.width
    }

    /// Viewport height in pixels this frame was prepared for.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 800, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.height(), 600);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn height(&self) -> u32 {
        self.height
    }

    /// Whether the frame was prepared under reduced motion, which snaps the
    /// spring instead of animating it.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert!(!frame.reduced_motion());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn reduced_motion(&self) -> bool {
        self.reduced_motion
    }

    /// Whether motion is still settling.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, CommitStatus, Frame, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let prepared = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// let frame = Frame::new(prepared.token(), prepared.artifact().clone(), CommitStatus::Proposed, CommitStatus::Proposed, false, 0.0, 0.0);
    /// assert!(!frame.animating());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn animating(&self) -> bool {
        self.animating
    }

    /// Pending visual state must never impersonate confirmed domain state.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, CommitStatus, Frame, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let prepared = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(prepared.status_label(), "Proposed");
    /// let pending = Frame::new(prepared.token(), prepared.artifact().clone(), CommitStatus::Committed, CommitStatus::Proposed, true, 0.0, 0.0);
    /// assert_eq!(pending.status_label(), "Commit pending");
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn status_label(&self) -> &'static str {
        if !self.optimistic {
            return self.commit_status.label();
        }
        match self.commit_status {
            CommitStatus::Proposed => "Proposal pending",
            CommitStatus::Running => "Run pending",
            CommitStatus::Failed => "Failure pending",
            CommitStatus::Committed => "Commit pending",
        }
    }

    /// Revision of the scene when this frame was prepared; a frame older
    /// than the canvas revision is stale.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.scene_revision(), canvas.revision());
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub const fn scene_revision(&self) -> u64 {
        self.token.revision
    }

    /// Navigation hit test against the presented viewport. The bar occupies
    /// the bottom 56 pixels in three equal thirds; anything else, or any
    /// non-finite coordinate, misses.
    ///
    /// # Examples
    ///
    /// ```
    /// # use drishti::canvas_protocol::SessionInvariant;
    /// # use drishti::canvas_scene::{Artifact, Canvas, Limits, View};
    /// # let id = "11111111-1111-1111-1111-111111111111";
    /// # let session = SessionInvariant::new(id.into(), id.into(), id.into(), "t".into(), id.into())?;
    /// # let mut canvas = Canvas::new(session, 1, Artifact::new(id, 1, "one\ntwo", None, None, Limits::default())?, Limits::default())?;
    /// let frame = canvas.prepare(0.0, 900, 600, false)?.ok_or("frame owed")?;
    /// assert_eq!(frame.hit_test(10.0, 590.0), Some(View::Source));
    /// assert_eq!(frame.hit_test(450.0, 590.0), Some(View::Proposal));
    /// assert_eq!(frame.hit_test(850.0, 590.0), Some(View::Evidence));
    /// assert_eq!(frame.hit_test(450.0, 100.0), None);
    /// assert_eq!(frame.hit_test(f64::NAN, 590.0), None);
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    #[must_use]
    pub fn hit_test(&self, x: f64, y: f64) -> Option<View> {
        let width = f64::from(self.width);
        let height = f64::from(self.height);
        if !x.is_finite()
            || !y.is_finite()
            || x < 0.0
            || x >= width
            || y < height - 56.0
            || y >= height
        {
            return None;
        }
        let third = width / 3.0;
        if x < third {
            Some(View::Source)
        } else if x < third + third {
            Some(View::Proposal)
        } else {
            Some(View::Evidence)
        }
    }
}