1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! # โก PVG โ Procedural Vector Graphics Core Engine
//!
//! **PVG** is a deterministic, human-readable 2D vector graphics and procedural scene description language.
//! It combines the declarative clarity of vector graphics with native loops, typography, trigonometry,
//! and microsecond CPU evaluation.
//!
//! ## Key Features
//! - ๐ฆ **Zero GPU Dependency**: Evaluates pure vector geometry directly on the CPU.
//! - โฑ๏ธ **Microsecond CPU Evaluation**: Evaluates animated scenes in `< 40 ยตs` per frame.
//! - ๐ชถ **Sub-50 KB Memory Footprint**: Evaluates flat contiguous 2D draw lists with zero DOM overhead.
//! - ๐ **AST Caching**: Parse once into an AST, re-evaluate per frame across timeline ticks with no re-parsing.
//! - ๐ **Built-in Standalone SVG Emitter**: Direct serialization into W3C SVG XML (static & SMIL animated).
//!
//! ## Quickstart Example
//!
//! ```rust
//! use pvg::{compile, compile_at_time, Color, DrawCmd};
//!
//! let source = r#"
//! PVG 0.1
//! canvas 400 400
//! background #000000
//!
//! circle
//! center [200, 200]
//! radius 50 + 20 * sin(time * 3.0)
//! fill #00ffcc
//! "#;
//!
//! // 1. Compile at time t = 0.0s
//! let draw_list = compile(source).expect("Compilation failed");
//! assert_eq!(draw_list.canvas_width, 400.0);
//! assert_eq!(draw_list.canvas_height, 400.0);
//! assert_eq!(draw_list.items.len(), 1);
//!
//! // 2. Serialize directly to W3C SVG
//! let svg_xml = draw_list.to_svg();
//! assert!(svg_xml.contains("<svg"));
//! assert!(svg_xml.contains("<circle"));
//!
//! // 3. Animate at time t = 1.5s
//! let animated_list = compile_at_time(source, 1.5).expect("Evaluation failed");
//! assert_eq!(animated_list.items.len(), 1);
//! ```
//!
//! ## Two-Phase Compilation (AST Caching Optimization)
//!
//! For real-time 60 FPS animation loops, avoid parsing the source string repeatedly.
//! Parse the AST document once and evaluate it on each frame tick:
//!
//! ```rust
//! use pvg::{parse, Evaluator};
//!
//! let source = "PVG 0.1\ncanvas 200 200\ncircle\n center [100, 100]\n radius 40\n";
//! let doc = parse(source).expect("Failed to parse document");
//!
//! // Re-evaluate the cached AST with updated timeline timestamps
//! for frame in 0..60 {
//! let time = frame as f64 / 60.0;
//! let evaluator = Evaluator::new_with_time(time);
//! let draw_list = evaluator.evaluate_document(&doc).expect("Evaluation failed");
//! assert_eq!(draw_list.items.len(), 1);
//! }
//! ```
// Re-export core types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Parser;
pub use ;
/// Parses a PVG source string into an Abstract Syntax Tree ([`Document`]).
///
/// # Errors
/// Returns [`PvgError`] if lexical or syntax errors occur.
/// Compiles a PVG source string into a flat 2D [`DrawList`] at `time = 0.0`.
///
/// # Errors
/// Returns [`PvgError`] if parsing or procedural evaluation fails.
/// Compiles a PVG source string into a flat 2D [`DrawList`] at a specific timeline timestamp.
///
/// # Errors
/// Returns [`PvgError`] if parsing or procedural evaluation fails.
/// Transpiles a PVG source string directly into a W3C SVG XML string at `time = 0.0`.
/// Transpiles a PVG source string directly into a W3C SVG XML string at a specific timeline timestamp.
// Backwards-compatible aliases
/// Alias for [`parse`] (backwards compatibility).
/// Alias for [`compile`] (backwards compatibility).
/// Alias for [`compile_at_time`] (backwards compatibility).