cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
css_composer.h
Go to the documentation of this file.
1
6#ifndef __CWIST_CSS_COMPOSER_H__
7#define __CWIST_CSS_COMPOSER_H__
8
10#include <stdbool.h>
11
15typedef struct cwist_color_rgb {
16 unsigned char r;
17 unsigned char g;
18 unsigned char b;
20
24typedef struct cwist_color_hsl {
25 float h;
26 float s;
27 float l;
29
41
42struct cwist_css_scope_entry;
43
52typedef struct cwist_css_scope {
53 char suffix[9];
54 struct cwist_css_scope_entry *entries;
55 size_t count;
56 size_t capacity;
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
69
76
83
89void cwist_color_rgb_to_hex(cwist_color_rgb rgb, char out_hex[8]);
90
96
104
111
118
139cwist_sstring *cwist_css_minify(const char *css);
140
155cwist_sstring *cwist_css_bundle(const char *const *parts, size_t count, bool minify);
156
163void cwist_css_scope_init(cwist_css_scope *scope, const char *component_name);
164
179const char *cwist_css_scope_class(cwist_css_scope *scope, const char *base_class);
180
198int cwist_css_scope_add_rule(cwist_css_scope *scope, const char *base_class,
199 const char *declarations);
200
211
222
223#ifdef __cplusplus
224}
225#endif
226
227#endif
Safe string type with helper methods.
cwist_sstring * cwist_css_bundle(const char *const *parts, size_t count, bool minify)
Concatenate stylesheets in order into one bundle, optionally minified.
cwist_sstring * cwist_css_generate_stylesheet(const cwist_css_config *cfg)
High-level helper to generate a complete stylesheet (Variables + Utilities).
const char * cwist_css_scope_class(cwist_css_scope *scope, const char *base_class)
Map a base class to its scoped name ("btn" -> "btn-a1b2c3d4").
int cwist_css_scope_add_rule(cwist_css_scope *scope, const char *base_class, const char *declarations)
Attach declarations to a base class, replacing any earlier ones.
cwist_sstring * cwist_css_generate_variables(const cwist_css_config *cfg)
Generates a CSS string containing CSS Custom Properties (:root variables). Extrapolates hover states,...
void cwist_css_config_init(cwist_css_config *cfg)
Initializes a CSS configuration with sensible defaults.
cwist_color_rgb cwist_color_hex_to_rgb(const char *hex)
Parses a hex string (e.g., "#FF0000", "FF0000", "#F00", or "F00") into an RGB struct.
cwist_sstring * cwist_css_scope_generate_stylesheet(const cwist_css_scope *scope)
Emit one rule per class that is both used and has declarations.
cwist_color_rgb cwist_color_hsl_to_rgb(cwist_color_hsl hsl)
Converts an HSL color back to RGB color space.
cwist_sstring * cwist_css_minify(const char *css)
Minify a stylesheet without changing what it means.
void cwist_color_rgb_to_hex(cwist_color_rgb rgb, char out_hex[8])
Formats an RGB struct into a 7-character hex string (e.g., "#FFFFFF").
void cwist_css_scope_init(cwist_css_scope *scope, const char *component_name)
Initialise a scope for one component.
cwist_sstring * cwist_css_generate_utility_classes(const cwist_css_config *cfg)
Generates a set of utility classes based on the design system configuration.
cwist_color_hsl cwist_color_rgb_to_hsl(cwist_color_rgb rgb)
Converts an RGB color to HSL color space.
void cwist_css_scope_destroy(cwist_css_scope *scope)
Release everything the scope owns and reset it to an empty state.
size_t count
Definition otel.c:58
HSL Color representation for dynamic manipulation.
float s
Saturation percentage (0.0 to 1.0)
float h
Hue angle in degrees (0.0 to 360.0)
float l
Lightness percentage (0.0 to 1.0)
RGB Color representation.
unsigned char g
Green channel (0-255)
unsigned char b
Blue channel (0-255)
unsigned char r
Red channel (0-255)
Dynamic CSS configuration parameters. Contains base metrics used to extrapolate an entire design syst...
float spacing_base_px
Base spacing unit in pixels (e.g. 4.0)
cwist_color_rgb secondary_color
Secondary/Accent color.
float roundness_px
Base border radius in pixels (e.g. 8.0)
bool is_dark_mode
Flag to trigger dark mode palette generation.
cwist_color_rgb primary_color
Base primary brand color.
Component-scoped class names and the rules attached to them.
size_t capacity
Allocated entries.
char suffix[9]
8 lowercase hex digits + NUL
size_t count
Number of known base classes.
struct cwist_css_scope_entry * entries
Per-class state, private.