Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start svg implementation #13

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion typed-html/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ marker_trait!(PhrasingContent, FlowContent);
marker_trait!(EmbeddedContent);
marker_trait!(InteractiveContent);
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);
Expand Down Expand Up @@ -98,7 +102,7 @@ declare_elements! {
rel: SpacedList<LinkType>,
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;
Expand Down Expand Up @@ -435,6 +439,77 @@ declare_elements! {
srclang: LanguageTag,
} in [MediaContent];

svg {
height: String,
width: 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, 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;
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 {
Expand Down Expand Up @@ -488,3 +563,20 @@ fn test_aria() {
frag.to_string()
);
}

#[test]
fn test_svg() {
use crate as axohtml;
use crate::{dom::DOMTree, html};

let frag: DOMTree<String> = html!(
<svg width="29.018px" height="29.018px" viewBox="0 -0.59 29.018 29.018" id="_25_-_Star" xmlns="http://www.w3.org/2000/svg">
<path id="_25_-_Star-2" d="M13.645,4.01l-2.057,6.334a1.013,1.013,0,0,1-.962.7H3.967a2.475,2.475,0,0,0-1.456,4.478L7.9,19.435a1.011,1.011,0,0,1,.367,1.131L6.208,26.9a2.476,2.476,0,0,0,3.81,2.768l5.388-3.914a1.012,1.012,0,0,1,1.188,0l5.388,3.914a2.476,2.476,0,0,0,3.81-2.768l-2.058-6.333a1.011,1.011,0,0,1,.367-1.131l5.388-3.914a2.475,2.475,0,0,0-1.456-4.478H21.374a1.013,1.013,0,0,1-.962-.7L18.355,4.01a2.477,2.477,0,0,0-4.71,0Zm1.9.618a.475.475,0,0,1,.9,0l2.058,6.334a3.012,3.012,0,0,0,2.864,2.081h6.659a.475.475,0,0,1,.28.86l-5.387,3.914a3.011,3.011,0,0,0-1.094,3.367l2.058,6.333a.476.476,0,0,1-.733.532L17.77,24.135a3.011,3.011,0,0,0-3.54,0L8.843,28.049a.476.476,0,0,1-.733-.532l2.058-6.333a3.011,3.011,0,0,0-1.094-3.367L3.687,13.9a.475.475,0,0,1,.28-.86h6.659a3.012,3.012,0,0,0,2.864-2.081l2.058-6.334Z" transform="translate(-1.491 -2.3)" fill-rule="evenodd"/>
</svg>
);

assert_eq!(
"<div aria-hidden=\"true\" aria-label=\"hello\"></div>",
frag.to_string()
);
}
101 changes: 101 additions & 0 deletions typed-html/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,104 @@ 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,
}

#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)]
pub enum ClipPathIUnits {
#[strum(to_string = "userSpaceOnUse")]
UserSpaceOnUse,
#[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,
}