sealed-surface 0.4.0

Non-extractable data surface: tables, timeseries, scatter, treemap as glyphs, never DOM text
Documentation
//! What the host is allowed to put in HTML / clipboard.

/// One host-visible string. Must not be a cell datum in sealed mode.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HostText {
    /// Role for audits (`caption`, `inspect`).
    pub kind: &'static str,
    /// Unicode the host may emit.
    pub text: String,
}

/// Clipboard payload produced only in copyable mode.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ClipboardPayload {
    /// Nothing.
    None,
    /// Tab-separated viewport including headers.
    Tsv(String),
}

impl ClipboardPayload {
    /// True when no Unicode dump is offered.
    #[must_use]
    pub const fn is_none(&self) -> bool {
        matches!(self, Self::None)
    }
}

/// Leak surface. Contract tests serialize this, not the pixmap.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostProjection {
    /// Strings the host may place in the DOM / ARIA.
    pub text_nodes: Vec<HostText>,
    /// Clipboard. [`ClipboardPayload::None`] when sealed.
    pub clipboard: Option<ClipboardPayload>,
}

impl HostProjection {
    pub(crate) fn sealed() -> Self {
        Self {
            text_nodes: Vec::new(),
            clipboard: None,
        }
    }

    /// Concatenate host text + clipboard for grep tests.
    #[must_use]
    pub fn audit_text(&self) -> String {
        let mut s = String::new();
        for t in &self.text_nodes {
            s.push_str(&t.text);
            s.push('\n');
        }
        if let Some(ClipboardPayload::Tsv(tsv)) = &self.clipboard {
            s.push_str(tsv);
        }
        s
    }
}