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
pub mod bounded_size;
pub mod color;
pub mod point;
pub mod rect;
pub mod rotation;
pub mod sides;
pub mod size;

pub use bounded_size::BoundedSize;
pub use color::Color;
pub use point::Point;
pub use rect::Rect;
pub use rotation::Rotation;
pub use sides::{abs::Sides, percent::Sides as SidesPercent};
pub use size::Size;

use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum CropMode {
    Custom { x: i64, y: i64 },
    Center,
    Bottom,
    Top,
    Left,
    Right,
}

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum ResizeMode {
    Fill,
    Cover,
    Contain,
}

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum Orientation {
    Portrait,
    Landscape,
}

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum Axis {
    X,
    Y,
}

impl std::fmt::Display for Axis {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Axis::X => write!(f, "x axis"),
            Axis::Y => write!(f, "y axis"),
        }
    }
}

#[wasm_bindgen]
#[derive(Serialize, Deserialize, Hash, PartialEq, Eq, Debug, Copy, Clone)]
pub enum FitMode {
    Image,
    Border,
}

impl Default for FitMode {
    #[inline]
    fn default() -> Self {
        FitMode::Image
    }
}

impl std::str::FromStr for FitMode {
    type Err = super::error::ParseEnum;

    #[inline]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let s = s.to_ascii_lowercase();
        match s.as_str() {
            "image" => Ok(FitMode::Image),
            "border" => Ok(FitMode::Border),
            _ => Err(super::error::ParseEnum::Unknown(s.to_string())),
        }
    }
}