use ecow::EcoString;
use typst_syntax::Spanned;
use crate::World;
use crate::diag::At;
use crate::foundations::{Bytes, Cast, Derived, elem};
use crate::introspection::Locatable;
#[elem(keywords = ["embed"], Locatable)]
pub struct AttachElem {
#[required]
#[parse(
let Spanned { v: path, span } =
args.expect::<Spanned<EcoString>>("path")?;
let id = span.resolve_path(&path).at(span)?;
// The derived part is the project-relative resolved path.
let resolved = id.vpath().as_rootless_path().to_string_lossy().replace("\\", "/").into();
Derived::new(path.clone(), resolved)
)]
pub path: Derived<EcoString, EcoString>,
#[positional]
#[required]
#[parse(
match args.eat::<Bytes>()? {
Some(data) => data,
None => engine.world.file(id).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,
}