Extract category definitions into individual functions
This commit is contained in:
parent
156aef10c4
commit
1fa56a317c
@ -8,3 +8,31 @@ mod foundations;
|
||||
pub use self::construct::*;
|
||||
pub use self::data::*;
|
||||
pub use self::foundations::*;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Hook up all compute definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("type", type_);
|
||||
global.define("repr", repr);
|
||||
global.define("panic", panic);
|
||||
global.define("assert", assert);
|
||||
global.define("eval", eval);
|
||||
global.define("int", int);
|
||||
global.define("float", float);
|
||||
global.define("luma", luma);
|
||||
global.define("rgb", rgb);
|
||||
global.define("cmyk", cmyk);
|
||||
global.define("symbol", symbol);
|
||||
global.define("str", str);
|
||||
global.define("label", label);
|
||||
global.define("regex", regex);
|
||||
global.define("range", range);
|
||||
global.define("read", read);
|
||||
global.define("csv", csv);
|
||||
global.define("json", json);
|
||||
global.define("toml", toml);
|
||||
global.define("yaml", yaml);
|
||||
global.define("xml", xml);
|
||||
global.define("calc", calc::module());
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ use super::GridLayouter;
|
||||
/// Display: Bullet List
|
||||
/// Category: layout
|
||||
#[element(Layout)]
|
||||
#[scope(
|
||||
scope.define("item", ListItem::func());
|
||||
scope
|
||||
)]
|
||||
pub struct ListElem {
|
||||
/// If this is `{false}`, the items are spaced apart with [list
|
||||
/// spacing]($func/list.spacing). If it is `{true}`, they use normal
|
||||
|
@ -57,9 +57,38 @@ use crate::meta::DocumentElem;
|
||||
use crate::prelude::*;
|
||||
use crate::shared::BehavedBuilder;
|
||||
use crate::text::{LinebreakElem, SmartQuoteElem, SpaceElem, TextElem};
|
||||
use crate::visualize::PathElem;
|
||||
use crate::visualize::PolygonElem;
|
||||
use crate::visualize::{CircleElem, EllipseElem, ImageElem, RectElem, SquareElem};
|
||||
use crate::visualize::{
|
||||
CircleElem, EllipseElem, ImageElem, PathElem, PolygonElem, RectElem, SquareElem,
|
||||
};
|
||||
|
||||
/// Hook up all layout definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("page", PageElem::func());
|
||||
global.define("pagebreak", PagebreakElem::func());
|
||||
global.define("v", VElem::func());
|
||||
global.define("par", ParElem::func());
|
||||
global.define("parbreak", ParbreakElem::func());
|
||||
global.define("h", HElem::func());
|
||||
global.define("box", BoxElem::func());
|
||||
global.define("block", BlockElem::func());
|
||||
global.define("list", ListElem::func());
|
||||
global.define("enum", EnumElem::func());
|
||||
global.define("terms", TermsElem::func());
|
||||
global.define("table", TableElem::func());
|
||||
global.define("stack", StackElem::func());
|
||||
global.define("grid", GridElem::func());
|
||||
global.define("columns", ColumnsElem::func());
|
||||
global.define("colbreak", ColbreakElem::func());
|
||||
global.define("place", PlaceElem::func());
|
||||
global.define("align", AlignElem::func());
|
||||
global.define("pad", PadElem::func());
|
||||
global.define("repeat", RepeatElem::func());
|
||||
global.define("move", MoveElem::func());
|
||||
global.define("scale", ScaleElem::func());
|
||||
global.define("rotate", RotateElem::func());
|
||||
global.define("hide", HideElem::func());
|
||||
global.define("measure", measure);
|
||||
}
|
||||
|
||||
/// Root-level layout.
|
||||
pub trait LayoutRoot {
|
||||
|
@ -22,6 +22,10 @@ use crate::prelude::*;
|
||||
/// Display: Term List
|
||||
/// Category: layout
|
||||
#[element(Layout)]
|
||||
#[scope(
|
||||
scope.define("item", TermItem::func());
|
||||
scope
|
||||
)]
|
||||
pub struct TermsElem {
|
||||
/// If this is `{false}`, the items are spaced apart with [term list
|
||||
/// spacing]($func/terms.spacing). If it is `{true}`, they use normal
|
||||
|
@ -23,121 +23,24 @@ use self::layout::LayoutRoot;
|
||||
/// Construct the standard library.
|
||||
pub fn build() -> Library {
|
||||
let math = math::module();
|
||||
let calc = compute::calc::module();
|
||||
let global = global(math.clone(), calc);
|
||||
let global = global(math.clone());
|
||||
Library { global, math, styles: styles(), items: items() }
|
||||
}
|
||||
|
||||
/// Construct the module with global definitions.
|
||||
#[tracing::instrument(skip_all)]
|
||||
fn global(math: Module, calc: Module) -> Module {
|
||||
fn global(math: Module) -> Module {
|
||||
let mut global = Scope::deduplicating();
|
||||
|
||||
// Text.
|
||||
global.define("text", text::TextElem::func());
|
||||
global.define("linebreak", text::LinebreakElem::func());
|
||||
global.define("smartquote", text::SmartQuoteElem::func());
|
||||
global.define("strong", text::StrongElem::func());
|
||||
global.define("emph", text::EmphElem::func());
|
||||
global.define("lower", text::lower);
|
||||
global.define("upper", text::upper);
|
||||
global.define("smallcaps", text::smallcaps);
|
||||
global.define("sub", text::SubElem::func());
|
||||
global.define("super", text::SuperElem::func());
|
||||
global.define("underline", text::UnderlineElem::func());
|
||||
global.define("strike", text::StrikeElem::func());
|
||||
global.define("overline", text::OverlineElem::func());
|
||||
global.define("raw", text::RawElem::func());
|
||||
global.define("lorem", text::lorem);
|
||||
|
||||
// Math.
|
||||
// Categories.
|
||||
text::define(&mut global);
|
||||
layout::define(&mut global);
|
||||
visualize::define(&mut global);
|
||||
meta::define(&mut global);
|
||||
compute::define(&mut global);
|
||||
symbols::define(&mut global);
|
||||
global.define("math", math);
|
||||
|
||||
// Layout.
|
||||
global.define("page", layout::PageElem::func());
|
||||
global.define("pagebreak", layout::PagebreakElem::func());
|
||||
global.define("v", layout::VElem::func());
|
||||
global.define("par", layout::ParElem::func());
|
||||
global.define("parbreak", layout::ParbreakElem::func());
|
||||
global.define("h", layout::HElem::func());
|
||||
global.define("box", layout::BoxElem::func());
|
||||
global.define("block", layout::BlockElem::func());
|
||||
global.define("list", layout::ListElem::func());
|
||||
global.define("enum", layout::EnumElem::func());
|
||||
global.define("terms", layout::TermsElem::func());
|
||||
global.define("table", layout::TableElem::func());
|
||||
global.define("stack", layout::StackElem::func());
|
||||
global.define("grid", layout::GridElem::func());
|
||||
global.define("columns", layout::ColumnsElem::func());
|
||||
global.define("colbreak", layout::ColbreakElem::func());
|
||||
global.define("place", layout::PlaceElem::func());
|
||||
global.define("align", layout::AlignElem::func());
|
||||
global.define("pad", layout::PadElem::func());
|
||||
global.define("repeat", layout::RepeatElem::func());
|
||||
global.define("move", layout::MoveElem::func());
|
||||
global.define("scale", layout::ScaleElem::func());
|
||||
global.define("rotate", layout::RotateElem::func());
|
||||
global.define("hide", layout::HideElem::func());
|
||||
global.define("measure", layout::measure);
|
||||
|
||||
// Visualize.
|
||||
global.define("image", visualize::ImageElem::func());
|
||||
global.define("line", visualize::LineElem::func());
|
||||
global.define("rect", visualize::RectElem::func());
|
||||
global.define("square", visualize::SquareElem::func());
|
||||
global.define("ellipse", visualize::EllipseElem::func());
|
||||
global.define("circle", visualize::CircleElem::func());
|
||||
global.define("polygon", visualize::PolygonElem::func());
|
||||
global.define("path", visualize::PathElem::func());
|
||||
|
||||
// Meta.
|
||||
global.define("document", meta::DocumentElem::func());
|
||||
global.define("ref", meta::RefElem::func());
|
||||
global.define("link", meta::LinkElem::func());
|
||||
global.define("outline", meta::OutlineElem::func());
|
||||
global.define("heading", meta::HeadingElem::func());
|
||||
global.define("figure", meta::FigureElem::func());
|
||||
global.define("cite", meta::CiteElem::func());
|
||||
global.define("bibliography", meta::BibliographyElem::func());
|
||||
global.define("locate", meta::locate);
|
||||
global.define("style", meta::style);
|
||||
global.define("layout", meta::layout);
|
||||
global.define("counter", meta::counter);
|
||||
global.define("numbering", meta::numbering);
|
||||
global.define("state", meta::state);
|
||||
global.define("query", meta::query);
|
||||
global.define("selector", meta::selector);
|
||||
|
||||
// Symbols.
|
||||
global.define("sym", symbols::sym());
|
||||
global.define("emoji", symbols::emoji());
|
||||
|
||||
// Compute.
|
||||
global.define("type", compute::type_);
|
||||
global.define("repr", compute::repr);
|
||||
global.define("panic", compute::panic);
|
||||
global.define("assert", compute::assert);
|
||||
global.define("eval", compute::eval);
|
||||
global.define("int", compute::int);
|
||||
global.define("float", compute::float);
|
||||
global.define("luma", compute::luma);
|
||||
global.define("rgb", compute::rgb);
|
||||
global.define("cmyk", compute::cmyk);
|
||||
global.define("symbol", compute::symbol);
|
||||
global.define("str", compute::str);
|
||||
global.define("label", compute::label);
|
||||
global.define("regex", compute::regex);
|
||||
global.define("range", compute::range);
|
||||
global.define("read", compute::read);
|
||||
global.define("csv", compute::csv);
|
||||
global.define("json", compute::json);
|
||||
global.define("toml", compute::toml);
|
||||
global.define("yaml", compute::yaml);
|
||||
global.define("xml", compute::xml);
|
||||
|
||||
// Calc.
|
||||
global.define("calc", calc);
|
||||
|
||||
// Colors.
|
||||
global.define("black", Color::BLACK);
|
||||
global.define("gray", Color::GRAY);
|
||||
|
@ -26,8 +26,27 @@ pub use self::query::*;
|
||||
pub use self::reference::*;
|
||||
pub use self::state::*;
|
||||
|
||||
use typst::doc::Lang;
|
||||
use typst::doc::Region;
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Hook up all meta definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("document", DocumentElem::func());
|
||||
global.define("ref", RefElem::func());
|
||||
global.define("link", LinkElem::func());
|
||||
global.define("outline", OutlineElem::func());
|
||||
global.define("heading", HeadingElem::func());
|
||||
global.define("figure", FigureElem::func());
|
||||
global.define("cite", CiteElem::func());
|
||||
global.define("bibliography", BibliographyElem::func());
|
||||
global.define("locate", locate);
|
||||
global.define("style", style);
|
||||
global.define("layout", layout);
|
||||
global.define("counter", counter);
|
||||
global.define("numbering", numbering);
|
||||
global.define("state", state);
|
||||
global.define("query", query);
|
||||
global.define("selector", selector);
|
||||
}
|
||||
|
||||
/// The named with which an element is referenced.
|
||||
pub trait LocalName {
|
||||
|
@ -16,7 +16,7 @@ pub use typst::doc::*;
|
||||
#[doc(no_inline)]
|
||||
pub use typst::eval::{
|
||||
array, cast_from_value, cast_to_value, dict, format_str, func, Args, Array, Cast,
|
||||
CastInfo, Dict, Func, Never, Str, Symbol, Value, Vm,
|
||||
CastInfo, Dict, Func, Never, Scope, Str, Symbol, Value, Vm,
|
||||
};
|
||||
#[doc(no_inline)]
|
||||
pub use typst::geom::*;
|
||||
|
@ -5,3 +5,11 @@ mod sym;
|
||||
|
||||
pub use emoji::*;
|
||||
pub use sym::*;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Hook up all symbol definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("sym", sym());
|
||||
global.define("emoji", emoji());
|
||||
}
|
||||
|
@ -22,6 +22,25 @@ use typst::font::{FontMetrics, FontStretch, FontStyle, FontWeight, VerticalFontM
|
||||
use crate::layout::ParElem;
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Hook up all text definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("text", TextElem::func());
|
||||
global.define("linebreak", LinebreakElem::func());
|
||||
global.define("smartquote", SmartQuoteElem::func());
|
||||
global.define("strong", StrongElem::func());
|
||||
global.define("emph", EmphElem::func());
|
||||
global.define("lower", lower);
|
||||
global.define("upper", upper);
|
||||
global.define("smallcaps", smallcaps);
|
||||
global.define("sub", SubElem::func());
|
||||
global.define("super", SuperElem::func());
|
||||
global.define("underline", UnderlineElem::func());
|
||||
global.define("strike", StrikeElem::func());
|
||||
global.define("overline", OverlineElem::func());
|
||||
global.define("raw", RawElem::func());
|
||||
global.define("lorem", lorem);
|
||||
}
|
||||
|
||||
/// Customize the look and layout of text in a variety of ways.
|
||||
///
|
||||
/// This function is used often, both with set rules and directly. While the set
|
||||
|
@ -11,3 +11,17 @@ pub use self::line::*;
|
||||
pub use self::path::*;
|
||||
pub use self::polygon::*;
|
||||
pub use self::shape::*;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Hook up all visualize definitions.
|
||||
pub(super) fn define(global: &mut Scope) {
|
||||
global.define("image", ImageElem::func());
|
||||
global.define("line", LineElem::func());
|
||||
global.define("rect", RectElem::func());
|
||||
global.define("square", SquareElem::func());
|
||||
global.define("ellipse", EllipseElem::func());
|
||||
global.define("circle", CircleElem::func());
|
||||
global.define("polygon", PolygonElem::func());
|
||||
global.define("path", PathElem::func());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user