Skip to main content

ase_swatch/
types.rs

1use serde::{Deserialize};
2use wasm_bindgen::prelude::*;
3
4/// Format of the color
5/// - Rgb - 3 floats each with range [0-1]
6/// - Lab - 3 floats with L in range [0-1] and A, B in range [-128.0, 127.0]
7/// - Cmyk - 4 floats each with range [0-1]
8/// - Gray - 1 float with range [0-1]
9#[wasm_bindgen]
10#[derive(Deserialize)]
11pub enum ColorMode {
12    Rgb,
13    Lab,
14    Cmyk,
15    Gray,
16}
17
18/// Type of the Color Object
19/// 
20/// _From <https://pypi.org/project/swatch/>_
21/// > Process colors are standard colors, this is the default if you define a new color in illustrator. As the name implies, they’re mixed from either RGB or CMYK depending on the document color mode.
22/// 
23/// > Global colors are the same thing as process colors, but they have one neat property which is that when you update them, they are updated all throughout your artwork. This makes them something like “color references” and quite useful if you’re doing something like reskinning some extant document.
24/// 
25/// > Spot colors are implicitly global but have the nifty property that you can create new swatches from them based on “tints” or, effectively some screened value of that color. The only hitch is that tints, even though they can be part of your file, can’t be stored/exchanged as swatches. I’m on the fence as to how problematic this is, but that’s just how it goes. Even illustrator won’t save them out, it’s just not supported in the app (almost certainly due to the nature of the file forma
26#[wasm_bindgen]
27#[derive(Deserialize, Clone, Copy)]
28pub enum ObjectColorType {
29    Global = 0,
30    Spot = 1,
31    Process = 2,
32}
33
34/// Color data
35/// 
36/// Stores individual color information.
37#[derive(Deserialize)]
38pub struct Color {
39    pub mode: ColorMode,
40    pub values: Vec<f32>,
41}
42
43/// A Color object
44/// 
45/// Stores data associated with a color object.
46#[derive(Deserialize)]
47pub struct ObjectColor {
48    pub name: String,
49    pub object_type: ObjectColorType,
50    pub data: Color,
51}
52
53/// Swatch object
54/// 
55/// Stores a group of `ObjectColor` under a name.
56#[derive(Deserialize)]
57pub struct ObjectSwatch {
58    pub name: String,
59    pub swatches: Vec<ObjectColor>,
60}