//! CSS. SVG export's style attributes and sheets, and the CSS web pages style objects with //! ([`css_rules`]: the CSS Properties panel and its exports), write each property they share in //! the same way: the declarations of transparency, fonts and type spacing come from the functions //! here, colours are `#rrggbb` (or `rgba()` where CSS has no separate opacity), gradients take the //! stops SVG export writes, and numbers go through [`fmt_num`]. use std::collections::{HashMap, HashSet}; use serde::{Deserialize, Serialize}; use vectorcraft_color::{BlendMode, Color, GradientKind, GradientPaint, Paint}; use vectorcraft_doc::{AppearanceItem, CharStyle, Document, Justify, LineCap, LiveShape, Node, NodeId, NodeKind, StrokeAlign, StrokeLayer, TextKind}; use vectorcraft_effects::RasterFx; use vectorcraft_geom::shapes::{self, CornerKind}; use vectorcraft_geom::{Affine, PathData, Point, Rect}; use crate::export::sanitize_id; use crate::fmt_num; /// CSS declarations, in order: (property, value). pub(crate) type Props = Vec<(&'static str, String)>; /// A declaration block: `property:value;property:value`. pub(crate) fn declarations<'a>(props: impl IntoIterator) -> String { props.into_iter().map(|(k, v)| format!("{k}:{v}")).collect::>().join(";") } /// A CSS string. pub(crate) fn css_string(s: &str) -> String { quoted(s, '"') } /// `s` as a CSS string in `quote`s. A backslash and the quote are escaped, and so are line breaks /// and other control characters (a newline would end the string and let the rest be rules) and /// `<` and `>` (which could end a `"), r#""w\d \"\3c /style\3e ""#); assert_eq!(css_string("wght"), "\"wght\""); } }