From 533f17c28b8e9b107f7d17caa85415974d3c4aa8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 2 Jul 2025 18:33:05 +0200 Subject: [PATCH] New `#[elem]` implementation --- .../typst-library/src/foundations/content.rs | 132 ++- .../typst-library/src/foundations/element.rs | 805 ++++++++++++++++-- .../typst-library/src/foundations/selector.rs | 2 +- .../typst-library/src/foundations/styles.rs | 133 +-- crates/typst-macros/src/elem.rs | 794 +++++------------ 5 files changed, 1105 insertions(+), 761 deletions(-) diff --git a/crates/typst-library/src/foundations/content.rs b/crates/typst-library/src/foundations/content.rs index 0d17b4578..e10ef7bb6 100644 --- a/crates/typst-library/src/foundations/content.rs +++ b/crates/typst-library/src/foundations/content.rs @@ -15,9 +15,9 @@ use typst_utils::{fat, singleton, LazyHash, SmallBitSet}; use crate::diag::{SourceResult, StrResult}; use crate::engine::Engine; use crate::foundations::{ - elem, func, scope, ty, Context, Dict, Element, Fields, IntoValue, Label, - NativeElement, Recipe, RecipeIndex, Repr, Selector, Str, Style, StyleChain, Styles, - Value, + elem, func, repr, scope, ty, Context, Dict, Element, Field, IntoValue, Label, + NativeElement, Property, Recipe, RecipeIndex, Repr, Selector, SettableProperty, Str, + Style, StyleChain, Styles, Value, }; use crate::introspection::Location; use crate::layout::{AlignElem, Alignment, Axes, Length, MoveElem, PadElem, Rel, Sides}; @@ -372,6 +372,15 @@ impl Content { Self::sequence(std::iter::repeat_with(|| self.clone()).take(count)) } + /// Sets a style property on the content. + pub fn set(self, field: Field, value: E::Type) -> Self + where + E: SettableProperty, + E::Type: Debug + Clone + Hash + Send + Sync + 'static, + { + self.styled(Property::new(field, value)) + } + /// Style this content with a style entry. pub fn styled(mut self, style: impl Into