From c78fb670e935f965684378ae926d98d988d5ba15 Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Thu, 22 Dec 2022 18:00:37 +0000 Subject: [PATCH 1/3] start svg implementation --- typed-html/src/elements.rs | 59 ++++++++++++++++++++++++++++++++++++- typed-html/src/types/mod.rs | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/typed-html/src/elements.rs b/typed-html/src/elements.rs index 5312da1..b4ea96e 100644 --- a/typed-html/src/elements.rs +++ b/typed-html/src/elements.rs @@ -40,6 +40,7 @@ marker_trait!(PhrasingContent, FlowContent); marker_trait!(EmbeddedContent); marker_trait!(InteractiveContent); marker_trait!(FormContent); +marker_trait!(SvgContent); // Traits for elements that are more picky about their children marker_trait!(DescriptionListContent); @@ -98,7 +99,7 @@ declare_elements! { rel: SpacedList, target: Target, type: Mime, - } in [FlowContent, PhrasingContent, InteractiveContent] with FlowContent; + } in [FlowContent, PhrasingContent, InteractiveContent, SvgContent] with FlowContent; abbr in [FlowContent, PhrasingContent] with PhrasingContent; address in [FlowContent] with FlowContent; article in [FlowContent, SectioningContent] with FlowContent; @@ -435,6 +436,45 @@ declare_elements! { srclang: LanguageTag, } in [MediaContent]; + svg { + height: String, + preserveAspectRatio: PreserveAspectRatio, + viewBox: String, + x: String, + y: String, + xmlns: String, + clip-path: String, + clip-rule: String, + color: String, + color-interpolation: String, + color-rendering: String, + cursor: String, + display: String, + fill: String, + fill-opacity: String, + fill-rule: String, + filter: String, + mask: String, + opacity: String, + pointer-events: String, + shape-rendering: String, + stroke: String, + stroke-dasharray: String, + stroke-dashoffset: String, + stroke-linecap: String, + stroke-linejoin: String, + stroke-miterlimit: String, + stroke-opacity: String, + stroke-width: String, + transform: String, + vector-effect: String, + visibility: String + } in [FlowContent] with SvgContent; + path { + d: String, + pathLength: usize, + } in [SvgContent] with SvgContent; + // Don't @ me blink in [FlowContent, PhrasingContent] with PhrasingContent; marquee { @@ -488,3 +528,20 @@ fn test_aria() { frag.to_string() ); } + +#[test] +fn test_svg() { + use crate as axohtml; + use crate::{dom::DOMTree, html}; + + let frag: DOMTree = html!( + + + + ); + + assert_eq!( + "
", + frag.to_string() + ); +} diff --git a/typed-html/src/types/mod.rs b/typed-html/src/types/mod.rs index f2d81bc..b33bf38 100644 --- a/typed-html/src/types/mod.rs +++ b/typed-html/src/types/mod.rs @@ -537,3 +537,60 @@ pub enum Wrap { #[strum(to_string = "off")] Off, } + +#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] +pub enum AriaSort { + #[strum(to_string = "ascending")] + Ascending, + #[strum(to_string = "descending")] + Descending, + #[strum(to_string = "none")] + None, + #[strum(to_string = "other")] + Other, +} + +#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] +pub enum PreserveAspectRatio { + #[strum(to_string = "none meet")] + NoneMeet, + #[strum(to_string = "xMinYMin meet")] + XMinYMinMeet, + #[strum(to_string = "xMidYMin meet")] + XMidYMinMeet, + #[strum(to_string = "xMaxYMin meet")] + XMaxYMinMeet, + #[strum(to_string = "xMinYMid meet")] + XMinYMidMeet, + #[strum(to_string = "xMidYMid meet")] + XMidYMidMeet, + #[strum(to_string = "xMaxYMid meet")] + XMaxYMidMeet, + #[strum(to_string = "xMinYMax meet")] + XMinYMaxMeet, + #[strum(to_string = "xMidYMax meet")] + XMidYMaxMeet, + #[strum(to_string = "xMaxYMax meet")] + XMaxYMaxMeet, + + #[strum(to_string = "none slice")] + NoneSlice, + #[strum(to_string = "xMinYMin slice")] + XMinYMinSlice, + #[strum(to_string = "xMidYMin slice")] + XMidYMinSlice, + #[strum(to_string = "xMaxYMin slice")] + XMaxYMinSlice, + #[strum(to_string = "xMinYMid slice")] + XMinYMidSlice, + #[strum(to_string = "xMidYMid slice")] + XMidYMidSlice, + #[strum(to_string = "xMaxYMid slice")] + XMaxYMidSlice, + #[strum(to_string = "xMinYMax slice")] + XMinYMaxSlice, + #[strum(to_string = "xMidYMax slice")] + XMidYMaxSlice, + #[strum(to_string = "xMaxYMax slice")] + XMaxYMaxSlice, +} From 1bcbb94de51d215dcd234a42ca43331ebf403cfe Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Thu, 22 Dec 2022 18:15:08 +0000 Subject: [PATCH 2/3] add some more --- typed-html/src/elements.rs | 14 +++++++++++++- typed-html/src/types/mod.rs | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/typed-html/src/elements.rs b/typed-html/src/elements.rs index b4ea96e..40ec584 100644 --- a/typed-html/src/elements.rs +++ b/typed-html/src/elements.rs @@ -41,6 +41,8 @@ marker_trait!(EmbeddedContent); marker_trait!(InteractiveContent); marker_trait!(FormContent); marker_trait!(SvgContent); +marker_trait!(ClipPathContent); +marker_trait!(DefsContent); // Traits for elements that are more picky about their children marker_trait!(DescriptionListContent); @@ -473,7 +475,17 @@ declare_elements! { path { d: String, pathLength: usize, - } in [SvgContent] with SvgContent; + } in [SvgContent, ClipPathContent, DefsContent]; + circle { + cx: String, + pathLength: usize, + cy: String, + r: String + } in [SvgContent, ClipPathContent, DefsContent]; + clipPath { + clipPathUnits: ClipPathIUnits, + } in [SvgContent] with ClipPathContent; + defs in [SvgContent] with DefsContent; // Don't @ me blink in [FlowContent, PhrasingContent] with PhrasingContent; diff --git a/typed-html/src/types/mod.rs b/typed-html/src/types/mod.rs index b33bf38..4e86282 100644 --- a/typed-html/src/types/mod.rs +++ b/typed-html/src/types/mod.rs @@ -594,3 +594,11 @@ pub enum PreserveAspectRatio { #[strum(to_string = "xMaxYMax slice")] XMaxYMaxSlice, } + +#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] +pub enum ClipPathIUnits { + #[strum(to_string = "userSpaceOnUse")] + UserSpaceOnUse, + #[strum(to_string = "objectBoundingBox")] + ObjectBoundingBox, +} From c610efd4bbd4bed6546afdc977a773f8269c28f9 Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Thu, 22 Dec 2022 18:32:30 +0000 Subject: [PATCH 3/3] add some more --- typed-html/src/elements.rs | 23 +++++++++++++++++++++++ typed-html/src/types/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/typed-html/src/elements.rs b/typed-html/src/elements.rs index 40ec584..53de1eb 100644 --- a/typed-html/src/elements.rs +++ b/typed-html/src/elements.rs @@ -43,6 +43,7 @@ marker_trait!(FormContent); marker_trait!(SvgContent); marker_trait!(ClipPathContent); marker_trait!(DefsContent); +marker_trait!(FilterContent); // Traits for elements that are more picky about their children marker_trait!(DescriptionListContent); @@ -440,6 +441,7 @@ declare_elements! { svg { height: String, + width: String, preserveAspectRatio: PreserveAspectRatio, viewBox: String, x: String, @@ -486,7 +488,28 @@ declare_elements! { clipPathUnits: ClipPathIUnits, } in [SvgContent] with ClipPathContent; defs in [SvgContent] with DefsContent; + desc in [SvgContent] with PhrasingContent; + ellipse { + cx: String, + pathLength: usize, + cy: String, + rx: String, + ry: String + } in [SvgContent, ClipPathContent, DefsContent]; + feBlend { + _in: String, // TODO OMG FUCK THIS + in2: usize, + mode: Blends + } in [SvgContent, ClipPathContent, DefsContent, FilterContent]; + filter { + x: String, + y: String, + width: String, + height: String, + filterUnits: ClipPathIUnits, + primitiveUnits: ClipPathIUnits, + } in [SvgContent, ClipPathContent, DefsContent] with FilterContent; // Don't @ me blink in [FlowContent, PhrasingContent] with PhrasingContent; marquee { diff --git a/typed-html/src/types/mod.rs b/typed-html/src/types/mod.rs index 4e86282..cc14595 100644 --- a/typed-html/src/types/mod.rs +++ b/typed-html/src/types/mod.rs @@ -602,3 +602,39 @@ pub enum ClipPathIUnits { #[strum(to_string = "objectBoundingBox")] ObjectBoundingBox, } + +#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] +pub enum Blends { + #[strum(to_string = "normal")] + Normal, + #[strum(to_string = "multiply")] + Multiply, + #[strum(to_string = "screen")] + Screen, + #[strum(to_string = "overlay")] + Overlay, + #[strum(to_string = "darken")] + Darken, + #[strum(to_string = "lighten")] + Lighten, + #[strum(to_string = "color-dodge")] + ColorDodge, + #[strum(to_string = "color-burn")] + ColorBurn, + #[strum(to_string = "hard-light")] + HardLight, + #[strum(to_string = "soft-light")] + SoftLight, + #[strum(to_string = "difference")] + Difference, + #[strum(to_string = "exclusion")] + Exclusion, + #[strum(to_string = "hue")] + Hue, + #[strum(to_string = "saturation")] + Saturation, + #[strum(to_string = "color")] + Color, + #[strum(to_string = "luminosity")] + Luminosity, +}