//! Cotton Story's rules: what each line of a scene is, what Return and Tab do //! in the writer, the element bar, a scene heading's parts, the names to //! offer, a scene's worked-out figures, the whole story laid out as pages by //! screenplay rules, Fountain out and in, and a scene read as a chat. //! //! A scene's body is plain Fountain without its heading line, the person's //! own text: nothing here rewrites it except the key or the element the //! person pressed. Every rule is pure (no store, no clock); the core reads //! and writes the rows (`cotton_core::story`), the phones draw what these //! answer, and the Worker runs the same rules as WASM (`boundary`). //! //! Offsets are UTF-16 code units, the unit Kotlin and Swift text views count //! in. A character line is known by its place (alone after a blank, with //! speech under it) and by the story's names, never only by capitals: a //! Telugu name the story knows is a character line (owner's contract, //! 17 Nov 2026). pub mod beats; pub mod chat; pub mod fdx; pub mod figures; pub mod fountain; pub mod heading; pub mod identity; pub mod layout; pub mod lines; pub mod names; pub mod press; pub mod script_in; pub use lines::{lines, Kind, Line}; #[cfg(test)] mod tests; /// UTF-16 length of `text`. pub(crate) fn utf16_len(text: &str) -> usize { text.encode_utf16().count() } /// The byte offset in `text` of a UTF-16 offset, clamped to the text and /// moved back to a character boundary. pub(crate) fn byte_at(text: &str, utf16: usize) -> usize { let mut units = 0; for (index, char) in text.char_indices() { if units >= utf16 { return index; } units += char.len_utf16(); } text.len() }