1 /* 2 * Copyright (C) 2022-2023 Alexander Borisov 3 * 4 * Author: Alexander Borisov <borisov@lexbor.com> 5 */ 6 7 #ifndef LXB_CSS_VALUE_H 8 #define LXB_CSS_VALUE_H 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #include "lexbor/css/base.h" 15 #include "lexbor/css/value/const.h" 16 #include "lexbor/css/unit/const.h" 17 18 typedef struct { 19 double num; 20 bool is_float; 21 } 22 lxb_css_value_number_t; 23 24 typedef struct { 25 long num; 26 } 27 lxb_css_value_integer_t; 28 29 typedef lxb_css_value_number_t lxb_css_value_percentage_t; 30 31 typedef struct { 32 double num; 33 bool is_float; 34 lxb_css_unit_t unit; 35 } 36 lxb_css_value_length_t; 37 38 typedef struct { 39 lxb_css_value_type_t type; 40 41 union { 42 lxb_css_value_length_t length; 43 lxb_css_value_percentage_t percentage; 44 } u; 45 } 46 lxb_css_value_length_percentage_t; 47 48 typedef struct { 49 lxb_css_value_type_t type; 50 51 union { 52 lxb_css_value_number_t number; 53 lxb_css_value_length_t length; 54 lxb_css_value_percentage_t percentage; 55 } u; 56 } 57 lxb_css_value_number_length_percentage_t; 58 59 typedef struct { 60 lxb_css_value_type_t type; 61 62 union { 63 lxb_css_value_number_t number; 64 lxb_css_value_length_t length; 65 } u; 66 } 67 lxb_css_value_number_length_t; 68 69 typedef struct { 70 lxb_css_value_type_t type; 71 72 union { 73 lxb_css_value_number_t number; 74 lxb_css_value_percentage_t percentage; 75 } u; 76 } 77 lxb_css_value_number_percentage_t; 78 79 typedef struct { 80 lxb_css_value_type_t type; 81 lxb_css_value_number_t number; 82 } 83 lxb_css_value_number_type_t; 84 85 typedef struct { 86 lxb_css_value_type_t type; 87 lxb_css_value_integer_t integer; 88 } 89 lxb_css_value_integer_type_t; 90 91 typedef struct { 92 lxb_css_value_type_t type; 93 lxb_css_value_percentage_t percentage; 94 } 95 lxb_css_value_percentage_type_t; 96 97 typedef struct { 98 lxb_css_value_type_t type; 99 lxb_css_value_length_t length; 100 } 101 lxb_css_value_length_type_t; 102 103 typedef struct { 104 lxb_css_value_type_t type; 105 lxb_css_value_length_percentage_t length; 106 } 107 lxb_css_value_length_percentage_type_t; 108 109 typedef struct { 110 double num; 111 bool is_float; 112 lxb_css_unit_angel_t unit; 113 } 114 lxb_css_value_angle_t; 115 116 typedef struct { 117 lxb_css_value_type_t type; 118 lxb_css_value_angle_t angle; 119 } 120 lxb_css_value_angle_type_t; 121 122 typedef struct { 123 lxb_css_value_type_t type; 124 125 union { 126 lxb_css_value_number_t number; 127 lxb_css_value_angle_t angle; 128 } u; 129 } 130 lxb_css_value_hue_t; 131 132 typedef struct { 133 uint8_t r; 134 uint8_t g; 135 uint8_t b; 136 uint8_t a; 137 } 138 lxb_css_value_color_hex_rgba_t; 139 140 typedef enum { 141 LXB_CSS_PROPERTY_COLOR_HEX_TYPE_3 = 0x00, 142 LXB_CSS_PROPERTY_COLOR_HEX_TYPE_4, 143 LXB_CSS_PROPERTY_COLOR_HEX_TYPE_6, 144 LXB_CSS_PROPERTY_COLOR_HEX_TYPE_8 145 } 146 lxb_css_value_color_hex_type_t; 147 148 typedef struct { 149 lxb_css_value_color_hex_rgba_t rgba; 150 lxb_css_value_color_hex_type_t type; 151 } 152 lxb_css_value_color_hex_t; 153 154 typedef struct { 155 /* 156 * If R is <percent> when G and B should be <percent> to. 157 * If R is <number> when G and B should be <number> to. 158 * R, G, B can be NONE regardless of neighboring values. 159 * 'A' can be <percentage> or <number> or NONE. 160 */ 161 162 lxb_css_value_number_percentage_t r; 163 lxb_css_value_number_percentage_t g; 164 lxb_css_value_number_percentage_t b; 165 lxb_css_value_number_percentage_t a; 166 167 bool old; 168 } 169 lxb_css_value_color_rgba_t; 170 171 typedef struct { 172 lxb_css_value_hue_t h; 173 lxb_css_value_percentage_type_t s; 174 lxb_css_value_percentage_type_t l; 175 lxb_css_value_number_percentage_t a; 176 177 bool old; 178 } 179 lxb_css_value_color_hsla_t; 180 181 typedef struct { 182 lxb_css_value_number_percentage_t l; 183 lxb_css_value_number_percentage_t a; 184 lxb_css_value_number_percentage_t b; 185 lxb_css_value_number_percentage_t alpha; 186 } 187 lxb_css_value_color_lab_t; 188 189 typedef struct { 190 lxb_css_value_number_percentage_t l; 191 lxb_css_value_number_percentage_t c; 192 lxb_css_value_hue_t h; 193 lxb_css_value_number_percentage_t a; 194 } 195 lxb_css_value_color_lch_t; 196 197 typedef struct { 198 lxb_css_value_type_t type; 199 200 union { 201 lxb_css_value_color_hex_t hex; 202 lxb_css_value_color_rgba_t rgb; 203 lxb_css_value_color_hsla_t hsl; 204 lxb_css_value_color_hsla_t hwb; 205 lxb_css_value_color_lab_t lab; 206 lxb_css_value_color_lch_t lch; 207 } u; 208 } 209 lxb_css_value_color_t; 210 211 212 LXB_API const lxb_css_data_t * 213 lxb_css_value_by_id(uintptr_t id); 214 215 LXB_API lxb_css_value_type_t 216 lxb_css_value_by_name(const lxb_char_t *name, size_t length); 217 218 LXB_API lxb_status_t 219 lxb_css_value_serialize(lxb_css_value_type_t type, 220 lexbor_serialize_cb_f cb, void *ctx); 221 222 LXB_API lxb_status_t 223 lxb_css_value_percentage_sr(const lxb_css_value_percentage_t *percent, 224 lexbor_serialize_cb_f cb, void *ctx); 225 226 LXB_API lxb_status_t 227 lxb_css_value_length_sr(const lxb_css_value_length_t *len, 228 lexbor_serialize_cb_f cb, void *ctx); 229 230 LXB_API lxb_status_t 231 lxb_css_value_number_sr(const lxb_css_value_number_t *number, 232 lexbor_serialize_cb_f cb, void *ctx); 233 234 LXB_API lxb_status_t 235 lxb_css_value_integer_sr(const lxb_css_value_integer_t *integer, 236 lexbor_serialize_cb_f cb, void *ctx); 237 238 LXB_API lxb_status_t 239 lxb_css_value_length_percentage_sr(const lxb_css_value_length_percentage_t *lp, 240 lexbor_serialize_cb_f cb, void *ctx); 241 242 LXB_API lxb_status_t 243 lxb_css_value_number_length_sr(const lxb_css_value_number_length_t *nl, 244 lexbor_serialize_cb_f cb, void *ctx); 245 246 LXB_API lxb_status_t 247 lxb_css_value_number_percentage_sr(const lxb_css_value_number_percentage_t *np, 248 lexbor_serialize_cb_f cb, void *ctx); 249 250 LXB_API lxb_status_t 251 lxb_css_value_length_type_sr(const lxb_css_value_length_type_t *lt, 252 lexbor_serialize_cb_f cb, void *ctx); 253 254 LXB_API lxb_status_t 255 lxb_css_value_percentage_type_sr(const lxb_css_value_percentage_type_t *pt, 256 lexbor_serialize_cb_f cb, void *ctx); 257 258 LXB_API lxb_status_t 259 lxb_css_value_number_type_sr(const lxb_css_value_number_type_t *num, 260 lexbor_serialize_cb_f cb, void *ctx); 261 262 LXB_API lxb_status_t 263 lxb_css_value_integer_type_sr(const lxb_css_value_integer_type_t *num, 264 lexbor_serialize_cb_f cb, void *ctx); 265 266 LXB_API lxb_status_t 267 lxb_css_value_length_percentage_type_sr(const lxb_css_value_length_percentage_type_t *lpt, 268 lexbor_serialize_cb_f cb, void *ctx); 269 270 LXB_API lxb_status_t 271 lxb_css_value_number_length_percentage_type_sr(const lxb_css_value_number_length_percentage_t *nlp, 272 lexbor_serialize_cb_f cb, void *ctx); 273 274 LXB_API lxb_status_t 275 lxb_css_value_angle_sr(const lxb_css_value_angle_t *angle, 276 lexbor_serialize_cb_f cb, void *ctx); 277 278 LXB_API lxb_status_t 279 lxb_css_value_hue_sr(const lxb_css_value_hue_t *hue, 280 lexbor_serialize_cb_f cb, void *ctx); 281 282 LXB_API lxb_status_t 283 lxb_css_value_color_serialize(const lxb_css_value_color_t *color, 284 lexbor_serialize_cb_f cb, void *ctx); 285 286 #ifdef __cplusplus 287 } /* extern "C" */ 288 #endif 289 290 #endif /* LXB_CSS_VALUE_H */ 291