use ecow::EcoString;
use typst_syntax::Spanned;
use crate::World;
use crate::diag::At;
use crate::foundations::{Bytes, Cast, Derived, PathOrStr, elem};
use crate::introspection::Locatable;
#[elem(keywords = ["embed"], Locatable)]
pub struct AttachElem {
#[required]
#[parse(
let Spanned { v: path, span } =
args.expect::<Spanned<PathOrStr>>("path")?;
let resolved = path.resolve_if_some(span.id()).at(span)?;
// The derived part is the virtual-root-relative resolved path.
let derived = resolved.vpath().get_without_slash().into();
Derived::new(path, derived)
)]
pub path: Derived<PathOrStr, EcoString>,
#[positional]
#[required]
#[parse(
match args.eat::<Bytes>()? {
Some(data) => data,
None => engine.world.file(resolved.intern()).at(span)?,
}
)]
pub data: Bytes,
pub relationship: Option<AttachedFileRelationship>,
pub mime_type: Option<EcoString>,
pub description: Option<EcoString>,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum AttachedFileRelationship {
Source,
Data,
Alternative,
Supplement,
}