leaf_core/lib.rs
1//! leaf-core — the frontend-neutral heart of leaf.
2//!
3//! A [`Doc`] is a `twig::Editor` plus a byte-offset caret and selection: every
4//! mutation is one of twig's offset-addressed ops, and the document stays a
5//! live, round-trippable AST the whole time you type into it. The [`wysiwyg`]
6//! module resolves that AST into a [`wysiwyg::VisualMap`] — rendered glyphs that
7//! each point back at the source byte they came from, so a caret can ride the
8//! *visible* text and step over hidden markup delimiters.
9//!
10//! The [`source`] module is that map's opposite number: where [`wysiwyg`]
11//! resolves the markup away, it styles the markup *itself*, so the source view
12//! can paint a heading's `# ` and a link's destination as the scaffolding they
13//! are. Both read the same twig AST, so the two views cannot disagree about what
14//! the document is.
15//!
16//! The [`counts`] module reads that same rendering back as numbers — words,
17//! characters, paragraphs — so a host's word count is a count of what the page
18//! shows rather than of the markup underneath it.
19//!
20//! The [`frame`] module is for the bindings that hand that rendering across a
21//! boundary: it says which rows one frame changed from the frame before, so a
22//! binding can cross only those.
23//!
24//! Nothing here depends on a UI toolkit. Glyphs carry a toolkit-agnostic
25//! [`Style`], which a frontend crate (`leaf-tui`, and next `leaf-gui`) maps onto
26//! its own styling. Both frontends share this exact caret math, edit surface,
27//! and offset⇄position mapping — the split is what lets a GUI reuse the hard
28//! parts instead of re-deriving them.
29
30pub mod counts;
31pub mod doc;
32pub mod frame;
33mod html;
34pub mod source;
35pub mod style;
36#[cfg(feature = "syntax")]
37pub mod syntax;
38pub mod wysiwyg;
39
40pub use counts::TextCounts;
41pub use doc::{
42 Capabilities, DiskState, Doc, FootnoteDef, FootnoteRef, Highlight, HighlightCursor,
43 InlineMarks, Landing, LineFlow, MarkupMode, PAGE_BREAK, Quote, View, VisualKey,
44};
45pub use frame::{RowDelta, apply_row_delta, row_delta};
46pub use source::{SourceMap, StyledRun};
47pub use style::{
48 Align, Baseline, FaceId, FaceRef, FaceTable, FontFace, FontFamily, FontSize, Hundredths,
49 LineHeight, LineSpacing, MarkColor, Role, SizeStep, Style, TextColor, Token,
50};
51pub use wysiwyg::{
52 BlockClass, Boundary, CodeBlockInfo, ColorScheme, Glyph, MathInfo, MathMark, MediaInfo,
53 MediaKind, MediaSource, Reveal, Surface, TableCell, TableInfo, TableRow, VRow, VisualMap,
54};
55
56// Re-export the twig types a frontend needs to name when calling into a `Doc`
57// (the toolbar's block/inline kinds), so frontends don't each depend on twig.
58// `Alignment` comes with `TableCell`, which carries one.
59// `Format` too: a filesystem-free host (wasm/FFI) picks the document's format
60// itself when it calls `Doc::from_source`, since there's no file extension to
61// sniff it from the way `Doc::open` does.
62// `Gesture` names one authoring capability for `Doc::supports`, the finer-grained
63// half of `Capabilities` — a frontend wanting a mark leaf's own toolbar doesn't
64// offer asks with one of these.
65pub use twig::{Alignment, BlockContainerKind, BlockKind, Format, Gesture, InlineKind};