1use crate::bridge_common;
2use std::ffi::{c_char, CStr, CString};
3use std::ptr;
4
5#[unsafe(no_mangle)]
6pub extern "C" fn themed_styler_version() -> *const c_char {
7 static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");
8 VERSION.as_ptr() as *const c_char
9}
10
11#[unsafe(no_mangle)]
12pub unsafe extern "C" fn themed_styler_render_css(themes_json: *const c_char) -> *mut c_char {
13 if themes_json.is_null() {
14 return ptr::null_mut();
15 }
16
17 let themes_str = match unsafe { CStr::from_ptr(themes_json).to_str() } {
18 Ok(s) => s,
19 Err(_) => return ptr::null_mut(),
20 };
21
22 let themes_input = bridge_common::parse_themes_json(themes_str);
23 let state = bridge_common::build_state(themes_input);
24 let css = state.css_for_web();
25
26 match CString::new(css) {
27 Ok(c_str) => c_str.into_raw(),
28 Err(_) => ptr::null_mut(),
29 }
30}
31
32#[unsafe(no_mangle)]
33pub unsafe extern "C" fn themed_styler_free_string(s: *mut c_char) {
34 if !s.is_null() {
35 unsafe { drop(CString::from_raw(s)) };
36 }
37}