Skip to main content

Crate muskitty_cascade

Crate muskitty_cascade 

Source
Expand description

MusKitty Cascade — CSS Cascade Level 5 引擎。

实现 CSS Cascade Level 5 的核心算法:从 DOM 树 + 多源 CSSStyleSheet 列表 → 每元素每属性的 computed value。

§数据流

DOM 树 + CssStyleSheet[] (带 origin 元数据)
    │  §5 Filtering
    ▼
DeclaredValue[] (每元素每属性,无序)
    │  §6.1 Cascade 排序
    ▼
DeclaredValue[] (有序,按 7 准则降序)
    │  取首项 → §4.2 Cascaded Value
    ▼
    │  §4.3 + §7 Defaulting (initial/inherit/unset)
    ▼
SpecifiedValue
    │  §4.4 Computed Value (相对单位解析、var() 求值)
    ▼
ComputedValue

§规范依据

  • CSS Cascade Level 5: d:\csswg\css-cascade-5\Overview.md
  • CSS Variables Level 1: d:\csswg\css-variables-1\Overview.md

§快速上手

use muskitty_cascade::collect_declared_values;
use muskitty_cssom::CssStyleSheet;
use muskitty_selectors::matching::DomElement;
use muskitty_dom::Node;
use std::rc::Rc;
use std::cell::RefCell;

// let element = DomElement::new(Rc::clone(&node));
// let sheets: Vec<CssStyleSheet> = Vec::new();
// let declared = collect_declared_values(&element, &sheets);

Re-exports§

pub use cascade::cascade_for_element;
pub use cascade::cascade_winner;
pub use compute::compute_value;
pub use compute::compute_value_with;
pub use compute::ComputeContext;
pub use compute::CustomPropertySource;
pub use custom_properties::collect_custom_properties;
pub use defaulting::apply_defaulting;
pub use filter::collect_declared_values;
pub use filter::collect_declared_values_prepared;
pub use filter::prepare_sheets;
pub use filter::prepare_sheets_with_context;
pub use filter::MediaContext;
pub use filter::PreparedSheets;
pub use registry::lookup_property;
pub use registry::PropertyDefinition;
pub use registry::BUILTIN_PROPERTIES;
pub use style::ComputedStyle;
pub use style::ComputedValue;
pub use style::DeclaredValue;
pub use style_tree::compute_styles;
pub use style_tree::StyleTreeOptions;
pub use text_props::apply_text_transform;
pub use text_props::text_transform_keyword;
pub use text_props::used_line_height_px;
pub use text_props::NORMAL_LINE_HEIGHT;

Modules§

cascade
§6.1 Cascade 排序算法。
compute
§4.4 Computed Value — 相对单位解析、var() 求值、百分比解析。
custom_properties
§4.3 Computed Value — 自定义属性收集。
defaulting
§7 Defaulting — initial/inherit/unset 关键字处理。
filter
§5 Filtering — 收集 declared values。
origin
Cascade origin。从 cssom re-export 保持一致。
registry
§7.1/§7.2: Property registry — 属性元数据(初始值、继承标志)。
style
§4.1 DeclaredValue + §4.4 ComputedValue + ComputedStyle。
style_tree
§4.3/§4.4 — 整树 computed style 计算。
text_props
文本相关属性的使用值语义(line-height / text-transform)。

Enums§

Origin
§6.2: Cascade origin。标识 stylesheet 的来源层级。