Skip to main content

svg2excal_core/
lib.rs

1//! Deterministic, security-bounded SVG to Excalidraw conversion.
2//!
3//! The crate parses SVG or SVGZ bytes without external I/O, resolves SVG paint
4//! semantics through `usvg`, and emits a typed Excalidraw v2 document. Use
5//! [`convert`] for the deny-by-default path or [`convert_with_resources`] when
6//! a caller intentionally provides bounded relative resources.
7//!
8//! # Example
9//!
10//! ```
11//! use svg2excal_core::{convert, ConversionOptions};
12//!
13//! let svg = br##"<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10">
14//!   <rect width="20" height="10" fill="#4dabf7"/>
15//! </svg>"##;
16//! let result = convert(svg, &ConversionOptions::default())?;
17//! let json = result.document.to_pretty_json()?;
18//! assert!(json.contains("\"type\": \"rectangle\""));
19//! # Ok::<(), svg2excal_core::ConversionError>(())
20//! ```
21
22#![forbid(unsafe_code)]
23#![warn(rust_2024_compatibility, missing_docs, missing_debug_implementations)]
24
25mod convert;
26mod error;
27mod identity;
28mod ingest;
29mod options;
30mod report;
31mod resource;
32mod source;
33mod target;
34
35pub use convert::{convert, convert_with_resources};
36pub use error::{ConversionError, InputRejection, LimitResource};
37pub use options::{
38    CancellationFlag, ConversionLimits, ConversionOptions, ConversionProfile, FontOptions,
39    GeometryOptions, ProvenanceMode, RasterOptions,
40};
41pub use report::{
42    ConversionDiagnostic, ConversionReport, ConversionResult, DiagnosticCode, DiagnosticSeverity,
43};
44pub use resource::{
45    ProvidedResource, ProvidedResourcePolicy, RelativeFilePolicy, ResourceContext, ResourceError,
46    ResourceProvider, ResourceRequest,
47};
48pub use target::{
49    BinaryFile, ExcalidrawAppState, ExcalidrawDocument, ExcalidrawElement, FileId, GroupId,
50    ImageMimeType,
51};