feat: new styles

This commit is contained in:
faynot
2026-07-08 23:45:37 +03:00
parent 9c279015dc
commit 75af23930f
18 changed files with 3556 additions and 816 deletions

View File

@@ -1,38 +1,45 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt;
use super::style::{ComputedStyle, StyleSheet};
#[derive(Debug, Clone)]
pub struct Element {
pub type_name: String,
pub properties: HashMap<String, String>,
pub children: Vec<Element>,
pub struct Element<'a> {
pub type_name: &'a str,
pub properties: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub children: Vec<Element<'a>>,
pub computed_style: ComputedStyle,
}
impl Element {
pub fn new(type_name: String) -> Self {
impl<'a> Element<'a> {
pub fn id(&self) -> Option<&str> {
self.properties.iter().find_map(|(k, v)| {
if **k == *"id" { Some(v.as_ref()) } else { None }
})
}
pub fn new(type_name: &'a str) -> Self {
Self {
type_name,
properties: HashMap::new(),
children: Vec::new(),
properties: Vec::with_capacity(8),
children: Vec::with_capacity(4),
computed_style: ComputedStyle::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct ComponentDef {
pub struct ComponentDef<'a> {
pub name: String,
pub params: Vec<(String, String)>,
pub children: Vec<Element>,
pub children: Vec<Element<'a>>,
}
#[derive(Debug, Clone)]
pub struct Document {
pub roots: Vec<Element>,
pub components: HashMap<String, ComponentDef>,
pub struct Document<'a> {
pub roots: Vec<Element<'a>>,
pub components: HashMap<String, ComponentDef<'a>>,
pub variables: HashMap<String, String>,
pub rhei_scripts: Vec<String>,
pub stylesheet: StyleSheet,