//! Typst's standard library. pub mod basics; pub mod compute; pub mod layout; pub mod math; pub mod meta; pub mod prelude; pub mod shared; pub mod text; pub mod visualize; use typst::geom::{Align, Color, Dir, GenAlign}; use typst::model::{LangItems, Library, Node, NodeId, Scope, StyleMap}; use self::layout::LayoutRoot; /// Construct the standard library. pub fn build() -> Library { Library { scope: scope(), styles: styles(), items: items() } } /// Construct the standard scope. fn scope() -> Scope { let mut std = Scope::new(); // Basics. std.def_func::("heading"); std.def_func::("list"); std.def_func::("enum"); std.def_func::("terms"); std.def_func::("table"); // Text. std.def_func::("text"); std.def_func::("linebreak"); std.def_func::("symbol"); std.def_func::("smartquote"); std.def_func::("strong"); std.def_func::("emph"); std.def_func::("lower"); std.def_func::("upper"); std.def_func::("smallcaps"); std.def_func::("sub"); std.def_func::("super"); std.def_func::("underline"); std.def_func::("strike"); std.def_func::("overline"); std.def_func::("raw"); // Math. std.def_func::("math"); std.def_func::("acc"); std.def_func::("frac"); std.def_func::("binom"); std.def_func::("script"); std.def_func::("sqrt"); std.def_func::("floor"); std.def_func::("ceil"); std.def_func::("vec"); std.def_func::("cases"); std.def_func::("serif"); std.def_func::("sans"); std.def_func::("bold"); std.def_func::("ital"); std.def_func::("cal"); std.def_func::("frak"); std.def_func::("mono"); std.def_func::("bb"); // Layout. std.def_func::("page"); std.def_func::("pagebreak"); std.def_func::("v"); std.def_func::("par"); std.def_func::("parbreak"); std.def_func::("h"); std.def_func::("box"); std.def_func::("block"); std.def_func::("stack"); std.def_func::("grid"); std.def_func::("columns"); std.def_func::("colbreak"); std.def_func::("place"); std.def_func::("align"); std.def_func::("pad"); std.def_func::("repeat"); std.def_func::("move"); std.def_func::("scale"); std.def_func::("rotate"); std.def_func::("hide"); // Visualize. std.def_func::("image"); std.def_func::("line"); std.def_func::("rect"); std.def_func::("square"); std.def_func::("ellipse"); std.def_func::("circle"); // Meta. std.def_func::("document"); std.def_func::("ref"); std.def_func::("link"); std.def_func::("outline"); // Compute. std.def_func::("type"); std.def_func::("repr"); std.def_func::("assert"); std.def_func::("eval"); std.def_func::("int"); std.def_func::("float"); std.def_func::("luma"); std.def_func::("rgb"); std.def_func::("cmyk"); std.def_func::("str"); std.def_func::("label"); std.def_func::("regex"); std.def_func::("range"); std.def_func::("abs"); std.def_func::("min"); std.def_func::("max"); std.def_func::("even"); std.def_func::("odd"); std.def_func::("mod"); std.def_func::("read"); std.def_func::("csv"); std.def_func::("json"); std.def_func::("xml"); std.def_func::("lorem"); std.def_func::("numbering"); // Colors. std.define("black", Color::BLACK); std.define("gray", Color::GRAY); std.define("silver", Color::SILVER); std.define("white", Color::WHITE); std.define("navy", Color::NAVY); std.define("blue", Color::BLUE); std.define("aqua", Color::AQUA); std.define("teal", Color::TEAL); std.define("eastern", Color::EASTERN); std.define("purple", Color::PURPLE); std.define("fuchsia", Color::FUCHSIA); std.define("maroon", Color::MAROON); std.define("red", Color::RED); std.define("orange", Color::ORANGE); std.define("yellow", Color::YELLOW); std.define("olive", Color::OLIVE); std.define("green", Color::GREEN); std.define("lime", Color::LIME); // Other constants. std.define("ltr", Dir::LTR); std.define("rtl", Dir::RTL); std.define("ttb", Dir::TTB); std.define("btt", Dir::BTT); std.define("start", GenAlign::Start); std.define("end", GenAlign::End); std.define("left", GenAlign::Specific(Align::Left)); std.define("center", GenAlign::Specific(Align::Center)); std.define("right", GenAlign::Specific(Align::Right)); std.define("top", GenAlign::Specific(Align::Top)); std.define("horizon", GenAlign::Specific(Align::Horizon)); std.define("bottom", GenAlign::Specific(Align::Bottom)); std } /// Construct the standard style map. fn styles() -> StyleMap { StyleMap::new() } /// Construct the standard lang item mapping. fn items() -> LangItems { LangItems { layout: |world, content, styles| content.layout_root(world, styles), em: |styles| styles.get(text::TextNode::SIZE), dir: |styles| styles.get(text::TextNode::DIR), space: || text::SpaceNode.pack(), linebreak: || text::LinebreakNode { justify: false }.pack(), text: |text| text::TextNode(text).pack(), text_id: NodeId::of::(), text_str: |content| Some(&content.to::()?.0), symbol: |notation| text::SymbolNode(notation).pack(), smart_quote: |double| text::SmartQuoteNode { double }.pack(), parbreak: || layout::ParbreakNode.pack(), strong: |body| text::StrongNode(body).pack(), emph: |body| text::EmphNode(body).pack(), raw: |text, lang, block| { let content = text::RawNode { text, block }.pack(); match lang { Some(_) => content.styled(text::RawNode::LANG, lang), None => content, } }, link: |url| meta::LinkNode::from_url(url).pack(), ref_: |target| meta::RefNode(target).pack(), heading: |level, body| basics::HeadingNode { level, title: body }.pack(), list_item: |body| layout::ListItem::List(body).pack(), enum_item: |number, body| layout::ListItem::Enum(number, body).pack(), term_item: |term, description| { layout::ListItem::Term(basics::TermItem { term, description }).pack() }, math: |children, block| math::MathNode { children, block }.pack(), math_atom: |atom| math::AtomNode(atom).pack(), math_script: |base, sub, sup| math::ScriptNode { base, sub, sup }.pack(), math_frac: |num, denom| math::FracNode { num, denom }.pack(), math_align_point: || math::AlignPointNode.pack(), } }