diff --git a/DESIGN.md b/DESIGN.md
index 6d8bd166..52031636 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -331,9 +331,27 @@ pub struct HtmlParser {
css_parser: CssParser,
condition_parser: ConditionParser,
handlebars_parser: HandlebarsParser,
+ css_strategy: CssStrategy,
// Other fields...
}
```
+
+#### CSS Strategy
+```rust
+/// Strategy for how component CSS is delivered in rendered output.
+pub enum CssStrategy {
+ /// Emit `` tags (default).
+ External,
+ /// Embed CSS content inline in `", css.trim())),
};
- let processed = self.process_component_template(&html_content, css_path.as_deref());
+ let processed =
+ self.process_component_template(&html_content, css_injection.as_deref());
self.parse(tag_name, &processed)?;
}
@@ -972,32 +1002,27 @@ impl HtmlParser {
}
/// Process component template HTML: wrap in shadow DOM template if needed,
- /// inject stylesheet link, and strip runtime-only attributes.
- fn process_component_template(&mut self, html: &str, styles: Option<&str>) -> String {
+ /// inject CSS snippet (link or inline style), and strip runtime-only attributes.
+ fn process_component_template(&mut self, html: &str, css_snippet: Option<&str>) -> String {
let trimmed = html.trim();
let has_template = trimmed.starts_with(" in the template tag
+ if let Some(snippet) = css_snippet {
+ // Inject CSS snippet after the first > in the template tag
if let Some(pos) = stripped.find('>') {
- let mut result = String::with_capacity(stripped.len() + style_path.len() + 50);
+ let mut result = String::with_capacity(stripped.len() + snippet.len() + 16);
result.push_str(&stripped[..=pos]);
- result.push_str(&format!(
- "",
- style_path
- ));
+ result.push_str(snippet);
result.push_str(&stripped[pos + 1..]);
return result;
}
}
stripped
- } else if let Some(style_path) = styles {
- format!(
- "{trimmed}"
- )
+ } else if let Some(snippet) = css_snippet {
+ format!("{snippet}{trimmed}")
} else {
format!("{trimmed}")
}
@@ -2257,4 +2282,58 @@ mod tests {
raw.value.contains("