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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// <FILE>crates/tui-vfx-shadow/src/lib.rs</FILE> - <DESC>Shadow rendering effects for TUI applications</DESC>
// <VERS>VERSION: 0.1.1</VERS>
// <WCTX>Enhanced API documentation with comprehensive details</WCTX>
// <CLOG>Add detailed documentation for styles, pipeline integration, and usage patterns</CLOG>
//! # TUI VFX Shadow
//!
//! Shadow rendering effects for terminal user interfaces.
//!
//! This crate provides theme-aware shadow rendering with multiple styles,
//! configurable offsets, edge selection, and animation support.
//!
//! ## Features
//!
//! - **Multiple shadow styles**: HalfBlock, Braille, Solid, and Gradient
//! - **Sub-cell precision**: Half-block characters provide smooth shadow edges
//! - **Configurable offsets**: Position shadows in any direction (±x, ±y)
//! - **Edge selection**: Render shadows on specific edges (top, bottom, left, right)
//! - **Animation support**: Animate shadows in/out with progress parameter
//! - **Theme integration**: Works with any color from your theme system
//!
//! ## Architecture & Pipeline Position
//!
//! Shadows are rendered **before** the element they belong to, following the
//! standard rendering order:
//!
//! ```text
//! 1. Background layer (surface color)
//! 2. Shadow layer ← render_shadow() goes here
//! 3. Element layer ← your UI element
//! 4. Compositor effects ← wipes, dissolves, fades, etc.
//! ```
//!
//! This ensures shadows appear "behind" elements and can be animated
//! independently using the compositor pipeline.
//!
//! ## Quick Start
//!
//! ```
//! use tui_vfx_shadow::{render_shadow, ShadowConfig, ShadowEdges, ShadowStyle};
//! use tui_vfx_types::{Color, OwnedGrid, Rect};
//!
//! // Create a grid to render into
//! let mut grid = OwnedGrid::new(40, 20);
//!
//! // Define the element that casts the shadow
//! let element_rect = Rect::new(10, 5, 15, 8);
//!
//! // Configure the shadow
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(128))
//! .with_offset(2, 1)
//! .with_style(ShadowStyle::HalfBlock)
//! .with_edges(ShadowEdges::BOTTOM_RIGHT)
//! .with_soft_edges(true);
//!
//! // Render the shadow (progress=1.0 for full shadow)
//! render_shadow(&mut grid, element_rect, &config, 1.0);
//! ```
//!
//! ## Shadow Styles
//!
//! ### Style Comparison
//!
//! | Style | Characters | Sub-cell | Compatibility | Best For |
//! |-------|------------|----------|---------------|----------|
//! | HalfBlock | ▐▄▌▀ | Yes (2x) | Good | Default, most UIs |
//! | Braille | ⣿⡇⠿ | Yes (2x4) | Variable | Dithered effects |
//! | Solid | (space) | No | Excellent | Maximum compat |
//! | Gradient | (space) | No | Excellent | Soft drop shadows |
//!
//! ### HalfBlock (Default)
//!
//! Uses Unicode half-block characters for sub-cell precision. The shadow
//! edge uses half-block characters with `fg=shadow_color` and `bg=surface_color`,
//! while the shadow interior uses solid background color.
//!
//! ```text
//! ┌──────────┐
//! │ Modal │▐░░
//! │ Window │▐░░
//! └──────────┘▐░░
//! ▄▄▄▄▄▄▄▄▄▄▄░░
//!
//! ▐ = RIGHT_HALF (soft edge)
//! ▄ = LOWER_HALF (soft edge)
//! ░ = solid shadow cells
//! ```
//!
//! ```
//! use tui_vfx_shadow::{ShadowConfig, ShadowStyle};
//! use tui_vfx_types::Color;
//!
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(128))
//! .with_style(ShadowStyle::HalfBlock)
//! .with_soft_edges(true) // Use half-blocks at shadow boundary
//! .with_surface_color(Color::rgb(40, 40, 50)); // Background for blending
//! ```
//!
//! ### Braille
//!
//! Uses braille patterns (U+2800-U+28FF) for dithered shadows. Each character
//! provides a 2x4 subpixel grid (8 dots), allowing fine-grained density control.
//!
//! ```text
//! Density mapping:
//! 0.0 → ⠀ (empty)
//! 0.25 → ⠃
//! 0.5 → ⡇
//! 0.75 → ⣷
//! 1.0 → ⣿ (full)
//! ```
//!
//! ```
//! use tui_vfx_shadow::{ShadowConfig, ShadowStyle};
//! use tui_vfx_types::Color;
//!
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(200))
//! .with_style(ShadowStyle::braille(0.7)); // 70% density
//! ```
//!
//! **Note:** Braille rendering depends on terminal font support. Some fonts
//! may not render braille characters at the expected size.
//!
//! ### Solid
//!
//! The simplest style - fills shadow cells with solid background color.
//! Maximum compatibility but no sub-cell precision.
//!
//! ```
//! use tui_vfx_shadow::{ShadowConfig, ShadowStyle};
//! use tui_vfx_types::Color;
//!
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(100))
//! .with_style(ShadowStyle::Solid);
//! ```
//!
//! ### Gradient
//!
//! Multi-layer shadows with progressively lighter colors. Each layer extends
//! further from the element with decreasing intensity.
//!
//! ```text
//! Layer 1 (closest): alpha = base_alpha * 1.0
//! Layer 2: alpha = base_alpha * 0.67
//! Layer 3 (furthest): alpha = base_alpha * 0.33
//! ```
//!
//! ```
//! use tui_vfx_shadow::{ShadowConfig, ShadowStyle};
//! use tui_vfx_types::Color;
//!
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(200))
//! .with_offset(1, 1)
//! .with_style(ShadowStyle::gradient(3)); // 3 gradient layers
//! ```
//!
//! ## Edge Configuration
//!
//! Control which edges of the element cast shadows using [`ShadowEdges`]:
//!
//! ```
//! use tui_vfx_shadow::ShadowEdges;
//!
//! // Common configurations
//! let drop_shadow = ShadowEdges::BOTTOM_RIGHT; // Standard drop shadow
//! let all_sides = ShadowEdges::ALL; // Shadow on all edges
//! let custom = ShadowEdges::RIGHT | ShadowEdges::BOTTOM | ShadowEdges::TOP;
//! ```
//!
//! Edge rendering depends on offset direction:
//! - **RIGHT** edge: only rendered when `offset_x > 0`
//! - **BOTTOM** edge: only rendered when `offset_y > 0`
//! - **LEFT** edge: only rendered when `offset_x < 0`
//! - **TOP** edge: only rendered when `offset_y < 0`
//!
//! ## Offset Configuration
//!
//! The offset determines shadow position relative to the element:
//!
//! ```
//! use tui_vfx_shadow::ShadowConfig;
//! use tui_vfx_types::Color;
//!
//! // Standard drop shadow (down-right)
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(128))
//! .with_offset(2, 1); // 2 cells right, 1 cell down
//!
//! // Inverted shadow (up-left)
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(128))
//! .with_offset(-1, -1); // 1 cell left, 1 cell up
//!
//! // Horizontal-only shadow
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(128))
//! .with_offset(2, 0); // 2 cells right, no vertical offset
//! ```
//!
//! ## Animation Support
//!
//! The `progress` parameter (0.0 to 1.0) controls shadow intensity, enabling
//! smooth fade-in/fade-out animations:
//!
//! ```
//! use tui_vfx_shadow::{render_shadow, ShadowConfig};
//! use tui_vfx_types::{Color, OwnedGrid, Rect};
//!
//! let mut grid = OwnedGrid::new(40, 20);
//! let rect = Rect::new(10, 5, 15, 8);
//! let config = ShadowConfig::new(Color::BLACK.with_alpha(200));
//!
//! // Animate shadow from 0% to 100% over time
//! for frame in 0..60 {
//! let progress = frame as f64 / 60.0;
//! render_shadow(&mut grid, rect, &config, progress);
//! }
//! ```
//!
//! The progress value interpolates the shadow color's alpha channel:
//! - `progress = 0.0`: shadow alpha = 0 (invisible)
//! - `progress = 0.5`: shadow alpha = base_alpha * 0.5
//! - `progress = 1.0`: shadow alpha = base_alpha (full)
//!
//! ## Integration Patterns
//!
//! ### With the TUI-VFX Compositor
//!
//! Shadows render directly to the grid before compositor effects are applied:
//!
//! ```ignore
//! use tui_vfx::prelude::*;
//!
//! // 1. Clear or prepare your destination grid
//! dest.fill(Cell::default());
//!
//! // 2. Render shadow first
//! render_shadow(&mut dest, modal_rect, &shadow_config, animation_progress);
//!
//! // 3. Render your element (modal, popup, etc.)
//! render_modal(&mut dest, modal_rect, &theme);
//!
//! // 4. Apply compositor effects (wipe reveal, dissolve, etc.)
//! render_pipeline(&source, &mut dest, width, height, 0, 0, compositor_options, None);
//! ```
//!
//! ### With Theme Systems
//!
//! Create shadow configs from theme definitions:
//!
//! ```ignore
//! // Example theme-driven shadow configuration
//! fn shadow_from_theme(theme: &Theme) -> ShadowConfig {
//! ShadowConfig::new(theme.shadow.color)
//! .with_offset(theme.shadow.offset_x, theme.shadow.offset_y)
//! .with_surface_color(theme.surface.background)
//! .with_style(match theme.shadow.style {
//! "braille" => ShadowStyle::braille(theme.shadow.density),
//! "gradient" => ShadowStyle::gradient(theme.shadow.layers),
//! "solid" => ShadowStyle::Solid,
//! _ => ShadowStyle::HalfBlock,
//! })
//! }
//! ```
//!
//! ### Synchronized with Modal Animations
//!
//! For modals with wipe animations, sync shadow progress with wipe progress:
//!
//! ```ignore
//! fn render_modal_with_shadow(
//! grid: &mut impl Grid,
//! modal_rect: Rect,
//! shadow_config: &ShadowConfig,
//! wipe_progress: f64, // 0.0 = closed, 1.0 = fully open
//! ) {
//! // Shadow fades in with the modal
//! render_shadow(grid, modal_rect, shadow_config, wipe_progress);
//!
//! // Modal content rendered separately with wipe mask...
//! }
//! ```
//!
//! ## Performance Considerations
//!
//! - **HalfBlock** and **Solid**: O(shadow_area) - linear in cells rendered
//! - **Braille**: Same as HalfBlock, plus character lookup
//! - **Gradient**: O(shadow_area × layers) - renders multiple overlapping layers
//!
//! For large shadows or performance-critical rendering:
//! 1. Use **Solid** style for maximum speed
//! 2. Limit **Gradient** layers to 2-3
//! 3. Consider caching shadow renders for static elements
//!
//! ## Module Structure
//!
//! - [`render_shadow`] - Main entry point for shadow rendering
//! - [`render_shadow_simple`] - Convenience function with defaults
//! - [`ShadowConfig`] - Configuration struct with builder pattern
//! - [`ShadowStyle`] - Enum of rendering styles
//! - [`ShadowEdges`] - Bitflags for edge selection
//! - [`renderers`] - Direct access to individual renderer implementations
// Re-export main functions
pub use ;
// Re-export types at crate root for convenience
pub use ;
// Re-export renderers for direct access if needed
pub use ;
// <FILE>crates/tui-vfx-shadow/src/lib.rs</FILE> - <DESC>Shadow rendering effects for TUI applications</DESC>
// <VERS>END OF VERSION: 0.1.1</VERS>