use reflexo::typst::TypstPagedDocument;
pub use reflexo_typst2vec::font::{FontGlyphProvider, GlyphProvider, IGlyphProvider};
pub use reflexo_typst2vec::ir::{self, geom, FlatModule, Module, MultiVecDocument, VecDocument};
pub(crate) mod utils;
pub(crate) mod backend;
use backend::generate_text;
pub use backend::SvgGlyphBuilder;
pub use backend::SvgText;
pub(crate) mod frontend;
pub use frontend::{
DynamicLayoutSvgExporter, IncrSvgDocClient, IncrSvgDocServer, IncrementalRenderContext,
};
pub use frontend::{SvgExporter, SvgTask};
pub(crate) mod transform;
#[derive(Default)]
pub struct SvgDataSelection {
pub body: bool,
pub defs: bool,
pub css: bool,
pub js: bool,
}
pub trait ExportFeature: Send + Sync + 'static {
const ENABLE_TRACING: bool;
const SHOULD_ATTACH_DEBUG_INFO: bool;
const ENABLE_INLINED_SVG: bool;
const SHOULD_RENDER_TEXT_ELEMENT: bool;
const USE_STABLE_GLYPH_ID: bool;
const SHOULD_RASTERIZE_TEXT: bool;
const WITH_BUILTIN_CSS: bool;
const WITH_RESPONSIVE_JS: bool;
const AWARE_HTML_ENTITY: bool;
}
pub struct DefaultExportFeature;
pub type DefaultSvgTask = SvgTask<'static, DefaultExportFeature>;
impl ExportFeature for DefaultExportFeature {
const ENABLE_INLINED_SVG: bool = false;
const ENABLE_TRACING: bool = false;
const SHOULD_ATTACH_DEBUG_INFO: bool = false;
const SHOULD_RENDER_TEXT_ELEMENT: bool = true;
const USE_STABLE_GLYPH_ID: bool = true;
const SHOULD_RASTERIZE_TEXT: bool = false;
const WITH_BUILTIN_CSS: bool = true;
const WITH_RESPONSIVE_JS: bool = true;
const AWARE_HTML_ENTITY: bool = true;
}
pub struct SvgExportFeature;
pub type PlainSvgTask = SvgTask<'static, SvgExportFeature>;
impl ExportFeature for SvgExportFeature {
const ENABLE_INLINED_SVG: bool = false;
const ENABLE_TRACING: bool = false;
const SHOULD_ATTACH_DEBUG_INFO: bool = false;
const SHOULD_RENDER_TEXT_ELEMENT: bool = true;
const USE_STABLE_GLYPH_ID: bool = true;
const SHOULD_RASTERIZE_TEXT: bool = false;
const WITH_BUILTIN_CSS: bool = true;
const WITH_RESPONSIVE_JS: bool = false;
const AWARE_HTML_ENTITY: bool = false;
}
pub fn render_svg_html<Feat: ExportFeature>(output: &TypstPagedDocument) -> String {
let mut doc = SvgExporter::<Feat>::svg_doc(output);
doc.module.prepare_glyphs();
let mut svg = SvgExporter::<Feat>::render(&doc.module, &doc.pages, None);
let mut html: Vec<SvgText> = Vec::with_capacity(svg.len() + 3);
html.push(r#"<!DOCTYPE html><html><head><meta charset="utf-8" /><title>"#.into());
html.push(SvgText::Plain(
output
.info
.title
.as_ref()
.map(|s| s.to_string())
.unwrap_or_else(|| "Typst TypstPagedDocument".into()),
));
html.push(r#"</title></head><body>"#.into());
html.append(&mut svg);
html.push(r#"</body></html>"#.into());
generate_text(transform::minify(html))
}
pub fn render_svg(output: &TypstPagedDocument) -> String {
type UsingExporter = SvgExporter<SvgExportFeature>;
let mut doc = UsingExporter::svg_doc(output);
doc.module.prepare_glyphs();
let svg_text = UsingExporter::render(&doc.module, &doc.pages, None);
generate_text(transform::minify(svg_text))
}