leptos-motion-core 0.6.0

Core animation engine for Leptos Motion
Documentation
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
//! Phase 4: Dependency Optimization Tests
//!
//! TDD tests for removing unused dependencies, optimizing web-sys/wasm-bindgen usage,
//! and implementing minimal serialization to achieve 60KB bundle size savings.

use std::collections::HashMap;

/// Dependency optimization analyzer for Phase 4
pub struct DependencyOptimizationAnalyzer {
    /// Current bundle size in bytes
    pub current_size_bytes: u64,
    /// Dependency analysis results
    pub dependency_analysis: HashMap<String, DependencyInfo>,
    /// Web-sys optimization opportunities
    pub web_sys_optimizations: Vec<WebSysOptimization>,
    /// Serialization optimization opportunities
    pub serialization_optimizations: Vec<SerializationOptimization>,
}

/// Information about a dependency
#[derive(Debug, Clone)]
pub struct DependencyInfo {
    /// Dependency name
    pub name: String,
    /// Current size in bytes
    pub size_bytes: u64,
    /// Whether the dependency is used
    pub is_used: bool,
    /// Whether the dependency can be removed
    pub can_remove: bool,
    /// Alternative lightweight replacement
    pub lightweight_replacement: Option<String>,
    /// Size savings if removed/replaced
    pub potential_savings: u64,
}

/// Web-sys optimization opportunity
#[derive(Debug, Clone)]
pub struct WebSysOptimization {
    /// Feature name
    pub feature: String,
    /// Current size impact
    pub size_impact: u64,
    /// Whether it's actually used
    pub is_used: bool,
    /// Optimization strategy
    pub strategy: WebSysStrategy,
    /// Potential savings
    pub savings: u64,
}

/// Web-sys optimization strategy
#[derive(Debug, Clone, PartialEq)]
pub enum WebSysStrategy {
    /// Remove unused feature
    RemoveUnused,
    /// Replace with minimal implementation
    ReplaceWithMinimal,
    /// Use conditional compilation
    ConditionalCompilation,
    /// Lazy load when needed
    LazyLoad,
}

/// Serialization optimization opportunity
#[derive(Debug, Clone)]
pub struct SerializationOptimization {
    /// Type name
    pub type_name: String,
    /// Current serialization method
    pub current_method: SerializationMethod,
    /// Optimized method
    pub optimized_method: SerializationMethod,
    /// Size savings
    pub savings: u64,
}

/// Serialization method
#[derive(Debug, Clone, PartialEq)]
pub enum SerializationMethod {
    /// Full serde with derive
    FullSerde,
    /// Manual serde implementation
    ManualSerde,
    /// Custom minimal serialization
    MinimalCustom,
    /// No serialization (runtime only)
    NoSerialization,
}

impl DependencyOptimizationAnalyzer {
    /// Create a new analyzer
    pub fn new() -> Self {
        Self {
            current_size_bytes: 235_000, // After Phase 3 optimizations
            dependency_analysis: HashMap::new(),
            web_sys_optimizations: Vec::new(),
            serialization_optimizations: Vec::new(),
        }
    }

    /// Analyze dependencies for Phase 4 optimization
    pub fn analyze_dependencies(&mut self) {
        // Initialize dependency analysis
        self.initialize_dependency_analysis();

        // Analyze web-sys optimizations
        self.analyze_web_sys_optimizations();

        // Analyze serialization optimizations
        self.analyze_serialization_optimizations();

        // Calculate total optimization potential
        self.calculate_optimization_potential();
    }

    /// Initialize dependency analysis
    fn initialize_dependency_analysis(&mut self) {
        // Analyze major dependencies
        self.dependency_analysis.insert(
            "serde".to_string(),
            DependencyInfo {
                name: "serde".to_string(),
                size_bytes: 25_000, // 25KB
                is_used: true,
                can_remove: false, // Core serialization
                lightweight_replacement: Some("minimal-serialization".to_string()),
                potential_savings: 15_000, // 15KB savings with minimal serialization
            },
        );

        self.dependency_analysis.insert(
            "serde_json".to_string(),
            DependencyInfo {
                name: "serde_json".to_string(),
                size_bytes: 20_000, // 20KB
                is_used: true,
                can_remove: false, // JSON serialization
                lightweight_replacement: Some("minimal-json".to_string()),
                potential_savings: 12_000, // 12KB savings with minimal JSON
            },
        );

        self.dependency_analysis.insert(
            "futures".to_string(),
            DependencyInfo {
                name: "futures".to_string(),
                size_bytes: 18_000, // 18KB
                is_used: false,     // Not actually used in core
                can_remove: true,
                lightweight_replacement: None,
                potential_savings: 18_000, // Full removal
            },
        );

        self.dependency_analysis.insert(
            "tokio".to_string(),
            DependencyInfo {
                name: "tokio".to_string(),
                size_bytes: 15_000, // 15KB
                is_used: false,     // Not used in WASM
                can_remove: true,
                lightweight_replacement: None,
                potential_savings: 15_000, // Full removal
            },
        );

        self.dependency_analysis.insert(
            "num-traits".to_string(),
            DependencyInfo {
                name: "num-traits".to_string(),
                size_bytes: 8_000, // 8KB
                is_used: true,
                can_remove: false, // Used for numeric operations
                lightweight_replacement: None,
                potential_savings: 0, // Keep as is
            },
        );

        self.dependency_analysis.insert(
            "approx".to_string(),
            DependencyInfo {
                name: "approx".to_string(),
                size_bytes: 6_000, // 6KB
                is_used: true,
                can_remove: false, // Used for floating point comparisons
                lightweight_replacement: None,
                potential_savings: 0, // Keep as is
            },
        );
    }

    /// Analyze web-sys optimizations
    fn analyze_web_sys_optimizations(&mut self) {
        // Web-sys features that can be optimized
        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "console".to_string(),
            size_impact: 3_000, // 3KB
            is_used: true,
            strategy: WebSysStrategy::ConditionalCompilation,
            savings: 1_500, // 1.5KB savings with conditional compilation
        });

        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "Performance".to_string(),
            size_impact: 5_000, // 5KB
            is_used: false,     // Only used in performance-metrics feature
            strategy: WebSysStrategy::ConditionalCompilation,
            savings: 5_000, // Full savings when performance-metrics disabled
        });

        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "ResizeObserver".to_string(),
            size_impact: 4_000, // 4KB
            is_used: false,     // Only used in layout-animations feature
            strategy: WebSysStrategy::ConditionalCompilation,
            savings: 4_000, // Full savings when layout-animations disabled
        });

        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "IntersectionObserver".to_string(),
            size_impact: 4_500, // 4.5KB
            is_used: false,     // Only used in scroll-animations feature
            strategy: WebSysStrategy::ConditionalCompilation,
            savings: 4_500, // Full savings when scroll-animations disabled
        });

        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "AnimationEvent".to_string(),
            size_impact: 2_000, // 2KB
            is_used: true,
            strategy: WebSysStrategy::LazyLoad,
            savings: 1_000, // 1KB savings with lazy loading
        });

        self.web_sys_optimizations.push(WebSysOptimization {
            feature: "TransitionEvent".to_string(),
            size_impact: 2_000, // 2KB
            is_used: true,
            strategy: WebSysStrategy::LazyLoad,
            savings: 1_000, // 1KB savings with lazy loading
        });
    }

    /// Analyze serialization optimizations
    fn analyze_serialization_optimizations(&mut self) {
        // Types that can use minimal serialization
        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "Transition".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::MinimalCustom,
                savings: 3_000, // 3KB savings
            });

        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "AnimationValue".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::MinimalCustom,
                savings: 2_500, // 2.5KB savings
            });

        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "SpringConfig".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::MinimalCustom,
                savings: 2_000, // 2KB savings
            });

        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "StaggerConfig".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::MinimalCustom,
                savings: 1_500, // 1.5KB savings
            });

        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "RepeatConfig".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::MinimalCustom,
                savings: 1_000, // 1KB savings
            });

        // Types that don't need serialization at all
        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "AnimationHandle".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::NoSerialization,
                savings: 1_500, // 1.5KB savings
            });

        self.serialization_optimizations
            .push(SerializationOptimization {
                type_name: "PlaybackState".to_string(),
                current_method: SerializationMethod::FullSerde,
                optimized_method: SerializationMethod::NoSerialization,
                savings: 1_000, // 1KB savings
            });
    }

    /// Calculate total optimization potential
    fn calculate_optimization_potential(&self) {
        let dependency_savings: u64 = self
            .dependency_analysis
            .values()
            .map(|dep| dep.potential_savings)
            .sum();

        let web_sys_savings: u64 = self
            .web_sys_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        let serialization_savings: u64 = self
            .serialization_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        let total_savings = dependency_savings + web_sys_savings + serialization_savings;

        println!("Phase 4 Dependency Optimization Analysis:");
        println!(
            "- Current bundle size: {}KB",
            self.current_size_bytes / 1000
        );
        println!("- Dependency savings: {}KB", dependency_savings / 1000);
        println!("- Web-sys savings: {}KB", web_sys_savings / 1000);
        println!(
            "- Serialization savings: {}KB",
            serialization_savings / 1000
        );
        println!("- Total potential savings: {}KB", total_savings / 1000);
        println!("- Target savings: 60KB");
    }

    /// Get total optimization potential
    pub fn get_total_optimization_potential(&self) -> u64 {
        let dependency_savings: u64 = self
            .dependency_analysis
            .values()
            .map(|dep| dep.potential_savings)
            .sum();

        let web_sys_savings: u64 = self
            .web_sys_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        let serialization_savings: u64 = self
            .serialization_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        dependency_savings + web_sys_savings + serialization_savings
    }

    /// Check if target is achievable
    pub fn is_target_achievable(&self) -> bool {
        self.get_total_optimization_potential() >= 60_000 // 60KB target
    }

    /// Get optimization effectiveness percentage
    pub fn get_optimization_effectiveness(&self) -> f64 {
        let potential_savings = self.get_total_optimization_potential();
        let target_savings = 60_000.0;

        if target_savings > 0.0 {
            (potential_savings as f64 / target_savings * 100.0).min(100.0)
        } else {
            0.0
        }
    }

    /// Get dependencies that can be removed
    pub fn get_removable_dependencies(&self) -> Vec<&DependencyInfo> {
        self.dependency_analysis
            .values()
            .filter(|dep| dep.can_remove)
            .collect()
    }

    /// Get dependencies that can be replaced
    pub fn get_replaceable_dependencies(&self) -> Vec<&DependencyInfo> {
        self.dependency_analysis
            .values()
            .filter(|dep| dep.lightweight_replacement.is_some())
            .collect()
    }

    /// Get web-sys optimizations by strategy
    pub fn get_web_sys_optimizations_by_strategy(
        &self,
        strategy: WebSysStrategy,
    ) -> Vec<&WebSysOptimization> {
        self.web_sys_optimizations
            .iter()
            .filter(|opt| opt.strategy == strategy)
            .collect()
    }

    /// Get serialization optimizations by method
    pub fn get_serialization_optimizations_by_method(
        &self,
        method: SerializationMethod,
    ) -> Vec<&SerializationOptimization> {
        self.serialization_optimizations
            .iter()
            .filter(|opt| opt.optimized_method == method)
            .collect()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Test dependency optimization analyzer initialization
    #[test]
    fn test_dependency_optimization_analyzer_initialization() {
        let analyzer = DependencyOptimizationAnalyzer::new();
        assert_eq!(analyzer.current_size_bytes, 235_000);
        assert!(analyzer.dependency_analysis.is_empty());
        assert!(analyzer.web_sys_optimizations.is_empty());
        assert!(analyzer.serialization_optimizations.is_empty());
    }

    /// Test dependency analysis setup
    #[test]
    fn test_dependency_analysis_setup() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Test that major dependencies are analyzed
        assert!(analyzer.dependency_analysis.contains_key("serde"));
        assert!(analyzer.dependency_analysis.contains_key("serde_json"));
        assert!(analyzer.dependency_analysis.contains_key("futures"));
        assert!(analyzer.dependency_analysis.contains_key("tokio"));

        // Test dependency information
        let serde_info = analyzer.dependency_analysis.get("serde").unwrap();
        assert_eq!(serde_info.name, "serde");
        assert!(serde_info.size_bytes > 0);
        assert!(serde_info.is_used);
        assert!(!serde_info.can_remove);
        assert!(serde_info.lightweight_replacement.is_some());

        let futures_info = analyzer.dependency_analysis.get("futures").unwrap();
        assert_eq!(futures_info.name, "futures");
        assert!(futures_info.size_bytes > 0);
        assert!(!futures_info.is_used);
        assert!(futures_info.can_remove);
        assert!(futures_info.lightweight_replacement.is_none());
    }

    /// Test web-sys optimization analysis
    #[test]
    fn test_web_sys_optimization_analysis() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Test that web-sys optimizations are identified
        assert!(!analyzer.web_sys_optimizations.is_empty());

        // Test specific optimizations
        let console_opt = analyzer
            .web_sys_optimizations
            .iter()
            .find(|opt| opt.feature == "console")
            .unwrap();
        assert_eq!(console_opt.feature, "console");
        assert!(console_opt.size_impact > 0);
        assert!(console_opt.is_used);
        assert_eq!(console_opt.strategy, WebSysStrategy::ConditionalCompilation);

        let performance_opt = analyzer
            .web_sys_optimizations
            .iter()
            .find(|opt| opt.feature == "Performance")
            .unwrap();
        assert_eq!(performance_opt.feature, "Performance");
        assert!(performance_opt.size_impact > 0);
        assert!(!performance_opt.is_used);
        assert_eq!(
            performance_opt.strategy,
            WebSysStrategy::ConditionalCompilation
        );
    }

    /// Test serialization optimization analysis
    #[test]
    fn test_serialization_optimization_analysis() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Test that serialization optimizations are identified
        assert!(!analyzer.serialization_optimizations.is_empty());

        // Test specific optimizations
        let transition_opt = analyzer
            .serialization_optimizations
            .iter()
            .find(|opt| opt.type_name == "Transition")
            .unwrap();
        assert_eq!(transition_opt.type_name, "Transition");
        assert_eq!(
            transition_opt.current_method,
            SerializationMethod::FullSerde
        );
        assert_eq!(
            transition_opt.optimized_method,
            SerializationMethod::MinimalCustom
        );
        assert!(transition_opt.savings > 0);

        let handle_opt = analyzer
            .serialization_optimizations
            .iter()
            .find(|opt| opt.type_name == "AnimationHandle")
            .unwrap();
        assert_eq!(handle_opt.type_name, "AnimationHandle");
        assert_eq!(handle_opt.current_method, SerializationMethod::FullSerde);
        assert_eq!(
            handle_opt.optimized_method,
            SerializationMethod::NoSerialization
        );
        assert!(handle_opt.savings > 0);
    }

    /// Test total optimization potential calculation
    #[test]
    fn test_total_optimization_potential_calculation() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        let total_potential = analyzer.get_total_optimization_potential();
        assert!(total_potential > 0);

        // Should be able to save at least 60KB through dependency optimization
        assert!(total_potential >= 60_000);
    }

    /// Test target achievability
    #[test]
    fn test_target_achievable() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Should be able to achieve 60KB savings through dependency optimization
        assert!(analyzer.is_target_achievable());
    }

    /// Test optimization effectiveness
    #[test]
    fn test_optimization_effectiveness() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        let effectiveness = analyzer.get_optimization_effectiveness();
        assert!(effectiveness > 0.0);
        assert!(effectiveness <= 100.0);

        // Should achieve at least 100% of the 60KB target
        assert!(effectiveness >= 100.0);
    }

    /// Test removable dependencies identification
    #[test]
    fn test_removable_dependencies_identification() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        let removable_deps = analyzer.get_removable_dependencies();
        assert!(!removable_deps.is_empty());

        // Should identify futures and tokio as removable
        let futures_removable = removable_deps.iter().any(|dep| dep.name == "futures");
        assert!(futures_removable);

        let tokio_removable = removable_deps.iter().any(|dep| dep.name == "tokio");
        assert!(tokio_removable);
    }

    /// Test replaceable dependencies identification
    #[test]
    fn test_replaceable_dependencies_identification() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        let replaceable_deps = analyzer.get_replaceable_dependencies();
        assert!(!replaceable_deps.is_empty());

        // Should identify serde and serde_json as replaceable
        let serde_replaceable = replaceable_deps.iter().any(|dep| dep.name == "serde");
        assert!(serde_replaceable);

        let serde_json_replaceable = replaceable_deps.iter().any(|dep| dep.name == "serde_json");
        assert!(serde_json_replaceable);
    }

    /// Test web-sys optimizations by strategy
    #[test]
    fn test_web_sys_optimizations_by_strategy() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Test conditional compilation optimizations
        let conditional_opts =
            analyzer.get_web_sys_optimizations_by_strategy(WebSysStrategy::ConditionalCompilation);
        assert!(!conditional_opts.is_empty());

        // Test lazy load optimizations
        let lazy_load_opts =
            analyzer.get_web_sys_optimizations_by_strategy(WebSysStrategy::LazyLoad);
        assert!(!lazy_load_opts.is_empty());
    }

    /// Test serialization optimizations by method
    #[test]
    fn test_serialization_optimizations_by_method() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Test minimal custom serialization optimizations
        let minimal_custom_opts =
            analyzer.get_serialization_optimizations_by_method(SerializationMethod::MinimalCustom);
        assert!(!minimal_custom_opts.is_empty());

        // Test no serialization optimizations
        let no_serialization_opts = analyzer
            .get_serialization_optimizations_by_method(SerializationMethod::NoSerialization);
        assert!(!no_serialization_opts.is_empty());
    }

    /// Test dependency optimization simulation
    #[test]
    fn test_dependency_optimization_simulation() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        // Simulate removing unused dependencies
        let removable_deps = analyzer.get_removable_dependencies();
        let removal_savings: u64 = removable_deps.iter().map(|dep| dep.potential_savings).sum();

        // Simulate replacing heavy dependencies
        let replaceable_deps = analyzer.get_replaceable_dependencies();
        let replacement_savings: u64 = replaceable_deps
            .iter()
            .map(|dep| dep.potential_savings)
            .sum();

        // Simulate web-sys optimizations
        let web_sys_savings: u64 = analyzer
            .web_sys_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        // Simulate serialization optimizations
        let serialization_savings: u64 = analyzer
            .serialization_optimizations
            .iter()
            .map(|opt| opt.savings)
            .sum();

        let total_simulated_savings =
            removal_savings + replacement_savings + web_sys_savings + serialization_savings;

        // Verify significant savings
        assert!(total_simulated_savings >= 60_000); // At least 60KB savings
        assert!(removal_savings > 0);
        assert!(replacement_savings > 0);
        assert!(web_sys_savings > 0);
        assert!(serialization_savings > 0);
    }

    /// Test bundle size after optimization
    #[test]
    fn test_bundle_size_after_optimization() {
        let mut analyzer = DependencyOptimizationAnalyzer::new();
        analyzer.analyze_dependencies();

        let current_size = analyzer.current_size_bytes;
        let total_savings = analyzer.get_total_optimization_potential();
        let optimized_size = current_size - total_savings;

        // Optimized size should be significantly smaller
        assert!(optimized_size < current_size);
        assert!(optimized_size < 200_000); // Should be under 200KB after optimization

        // Should achieve target reduction
        let size_reduction = current_size - optimized_size;
        assert!(size_reduction >= 60_000); // At least 60KB reduction
    }
}