summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/introspection
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-07-09 10:16:36 +0200
committerGitHub <noreply@github.com>2025-07-09 08:16:36 +0000
commite5e1dcd9c01341d2cd3473ac94a70223d5966086 (patch)
treed648efad9463cb10270d55ba35210eeb1e91ee22 /crates/typst-library/src/introspection
parent0a3c6939dd274f40672484695d909c2cc0d0d755 (diff)
Target-specific native show rules (#6569)
Diffstat (limited to 'crates/typst-library/src/introspection')
-rw-r--r--crates/typst-library/src/introspection/counter.rs40
-rw-r--r--crates/typst-library/src/introspection/metadata.rs12
-rw-r--r--crates/typst-library/src/introspection/state.rs13
3 files changed, 21 insertions, 44 deletions
diff --git a/crates/typst-library/src/introspection/counter.rs b/crates/typst-library/src/introspection/counter.rs
index a7925e13..b3c52de4 100644
--- a/crates/typst-library/src/introspection/counter.rs
+++ b/crates/typst-library/src/introspection/counter.rs
@@ -12,7 +12,7 @@ use crate::engine::{Engine, Route, Sink, Traced};
use crate::foundations::{
cast, elem, func, scope, select_where, ty, Args, Array, Construct, Content, Context,
Element, Func, IntoValue, Label, LocatableSelector, NativeElement, Packed, Repr,
- Selector, Show, Smart, Str, StyleChain, Value,
+ Selector, ShowFn, Smart, Str, StyleChain, Value,
};
use crate::introspection::{Introspector, Locatable, Location, Tag};
use crate::layout::{Frame, FrameItem, PageElem};
@@ -683,8 +683,8 @@ cast! {
}
/// Executes an update of a counter.
-#[elem(Construct, Locatable, Show, Count)]
-struct CounterUpdateElem {
+#[elem(Construct, Locatable, Count)]
+pub struct CounterUpdateElem {
/// The key that identifies the counter.
#[required]
key: CounterKey,
@@ -701,12 +701,6 @@ impl Construct for CounterUpdateElem {
}
}
-impl Show for Packed<CounterUpdateElem> {
- fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
- Ok(Content::empty())
- }
-}
-
impl Count for Packed<CounterUpdateElem> {
fn update(&self) -> Option<CounterUpdate> {
Some(self.update.clone())
@@ -714,7 +708,7 @@ impl Count for Packed<CounterUpdateElem> {
}
/// Executes a display of a counter.
-#[elem(Construct, Locatable, Show)]
+#[elem(Construct, Locatable)]
pub struct CounterDisplayElem {
/// The counter.
#[required]
@@ -738,20 +732,18 @@ impl Construct for CounterDisplayElem {
}
}
-impl Show for Packed<CounterDisplayElem> {
- fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
- Ok(self
- .counter
- .display_impl(
- engine,
- self.location().unwrap(),
- self.numbering.clone(),
- self.both,
- Some(styles),
- )?
- .display())
- }
-}
+pub const COUNTER_DISPLAY_RULE: ShowFn<CounterDisplayElem> = |elem, engine, styles| {
+ Ok(elem
+ .counter
+ .display_impl(
+ engine,
+ elem.location().unwrap(),
+ elem.numbering.clone(),
+ elem.both,
+ Some(styles),
+ )?
+ .display())
+};
/// An specialized handler of the page counter that tracks both the physical
/// and the logical page counter.
diff --git a/crates/typst-library/src/introspection/metadata.rs b/crates/typst-library/src/introspection/metadata.rs
index 06000174..8ad74b96 100644
--- a/crates/typst-library/src/introspection/metadata.rs
+++ b/crates/typst-library/src/introspection/metadata.rs
@@ -1,6 +1,4 @@
-use crate::diag::SourceResult;
-use crate::engine::Engine;
-use crate::foundations::{elem, Content, Packed, Show, StyleChain, Value};
+use crate::foundations::{elem, Value};
use crate::introspection::Locatable;
/// Exposes a value to the query system without producing visible content.
@@ -24,15 +22,9 @@ use crate::introspection::Locatable;
/// query(<note>).first().value
/// }
/// ```
-#[elem(Show, Locatable)]
+#[elem(Locatable)]
pub struct MetadataElem {
/// The value to embed into the document.
#[required]
pub value: Value,
}
-
-impl Show for Packed<MetadataElem> {
- fn show(&self, _: &mut Engine, _styles: StyleChain) -> SourceResult<Content> {
- Ok(Content::empty())
- }
-}
diff --git a/crates/typst-library/src/introspection/state.rs b/crates/typst-library/src/introspection/state.rs
index 784f2acb..2d15a5de 100644
--- a/crates/typst-library/src/introspection/state.rs
+++ b/crates/typst-library/src/introspection/state.rs
@@ -6,8 +6,7 @@ use crate::diag::{bail, At, SourceResult};
use crate::engine::{Engine, Route, Sink, Traced};
use crate::foundations::{
cast, elem, func, scope, select_where, ty, Args, Construct, Content, Context, Func,
- LocatableSelector, NativeElement, Packed, Repr, Selector, Show, Str, StyleChain,
- Value,
+ LocatableSelector, NativeElement, Repr, Selector, Str, Value,
};
use crate::introspection::{Introspector, Locatable, Location};
use crate::routines::Routines;
@@ -372,8 +371,8 @@ cast! {
}
/// Executes a display of a state.
-#[elem(Construct, Locatable, Show)]
-struct StateUpdateElem {
+#[elem(Construct, Locatable)]
+pub struct StateUpdateElem {
/// The key that identifies the state.
#[required]
key: Str,
@@ -389,9 +388,3 @@ impl Construct for StateUpdateElem {
bail!(args.span, "cannot be constructed manually");
}
}
-
-impl Show for Packed<StateUpdateElem> {
- fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
- Ok(Content::empty())
- }
-}