/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
usecrate::values::animated::{lists, Animate, Procedure, ToAnimatedZero}; usecrate::values::distance::{ComputeSquaredDistance, SquaredDistance}; usecrate::values::generics::border::GenericBorderRadius; usecrate::values::generics::position::GenericPositionOrAuto; usecrate::values::generics::rect::Rect; usecrate::values::specified::svg_path::{PathCommand, SVGPathData}; usecrate::Zero; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// <https://drafts.fxtf.org/css-masking-1/#typedef-geometry-box> #[allow(missing_docs)] #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum ShapeGeometryBox { /// Depending on which kind of element this style value applied on, the /// default value of the reference-box can be different. For an HTML /// element, the default value of reference-box is border-box; for an SVG /// element, the default value is fill-box. Since we can not determine the /// default value at parsing time, we keep this value to make a decision on /// it. #[css(skip)]
ElementDependent,
FillBox,
StrokeBox,
ViewBox,
ShapeBox(ShapeBox),
}
/// Skip the serialization if the author omits the box or specifies border-box. #[inline] fn is_default_box_for_clip_path(b: &ShapeGeometryBox) -> bool { // Note: for clip-path, ElementDependent is always border-box, so we have to check both of them // for serialization.
matches!(b, ShapeGeometryBox::ElementDependent) ||
matches!(b, ShapeGeometryBox::ShapeBox(ShapeBox::BorderBox))
}
/// A value for the `shape-outside` property. #[allow(missing_docs)] #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[animation(no_bound(I))] #[repr(u8)] pubenum GenericShapeOutside<BasicShape, I> { #[animation(error)]
None, #[animation(error)]
Image(I),
Shape(Box<BasicShape>, #[css(skip_if = "is_default")] ShapeBox), #[animation(error)] Box(ShapeBox),
}
pubuseself::GenericShapeOutside as ShapeOutside;
/// The <basic-shape>. /// /// https://drafts.csswg.org/css-shapes-1/#supported-basic-shapes #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(C, u8)] pubenum GenericBasicShape<
Angle,
Position,
LengthPercentage,
NonNegativeLengthPercentage,
BasicShapeRect,
> { /// The <basic-shape-rect>.
Rect(BasicShapeRect), /// Defines a circle with a center and a radius.
Circle( #[css(field_bound)] #[shmem(field_bound)]
Circle<Position, NonNegativeLengthPercentage>,
), /// Defines an ellipse with a center and x-axis/y-axis radii.
Ellipse( #[css(field_bound)] #[shmem(field_bound)]
Ellipse<Position, NonNegativeLengthPercentage>,
), /// Defines a polygon with pair arguments.
Polygon(GenericPolygon<LengthPercentage>), /// Defines a path() or shape().
PathOrShape( #[animation(field_bound)] #[css(field_bound)]
GenericPathOrShapeFunction<Angle, LengthPercentage>,
),
}
/// A generic type for representing the `polygon()` function /// /// <https://drafts.csswg.org/css-shapes/#funcdef-polygon> #[derive(
Clone,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[css(comma, function = "polygon")] #[repr(C)] pubstruct GenericPolygon<LengthPercentage> { /// The filling rule for a polygon. #[css(skip_if = "is_default")] pub fill: FillRule, /// A collection of (x, y) coordinates to draw the polygon. #[css(iterable)] pub coordinates: crate::OwnedSlice<PolygonCoord<LengthPercentage>>,
}
/// path() function or shape() function. #[derive(
Clone,
ComputeSquaredDistance,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(C, u8)] pubenum GenericPathOrShapeFunction<Angle, LengthPercentage> { /// Defines a path with SVG path syntax.
Path(Path), /// Defines a shape function, which is identical to path() but it uses the CSS syntax.
Shape(#[css(field_bound)] Shape<Angle, LengthPercentage>),
}
// https://drafts.csswg.org/css-shapes/#typedef-fill-rule // NOTE: Basic shapes spec says that these are the only two values, however // https://www.w3.org/TR/SVG/painting.html#FillRuleProperty // says that it can also be `inherit` #[allow(missing_docs)] #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
Eq,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum FillRule {
Nonzero,
Evenodd,
}
/// The path function. /// /// https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-path #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[css(comma, function = "path")] #[repr(C)] pubstruct Path { /// The filling rule for the svg path. #[css(skip_if = "is_default")] pub fill: FillRule, /// The svg path data. pub path: SVGPathData,
}
impl Path { /// Returns the slice of PathCommand. #[inline] pubfn commands(&self) -> &[PathCommand] { self.path.commands()
}
}
impl<Position, NonNegativeLengthPercentage> ToCss for Circle<Position, NonNegativeLengthPercentage> where
Position: ToCss,
NonNegativeLengthPercentage: ToCss + PartialEq,
{ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{ let has_radius = self.radius != Default::default();
dest.write_str("circle(")?; if has_radius { self.radius.to_css(dest)?;
}
// Preserve the `at <position>` even if it specified the default value. // https://github.com/w3c/csswg-drafts/issues/8695 if !matches!(self.position, GenericPositionOrAuto::Auto) { if has_radius {
dest.write_char(' ')?;
}
dest.write_str("at ")?; self.position.to_css(dest)?;
}
dest.write_char(')')
}
}
impl<Position, NonNegativeLengthPercentage> ToCss for Ellipse<Position, NonNegativeLengthPercentage> where
Position: ToCss,
NonNegativeLengthPercentage: ToCss + PartialEq,
{ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{ let has_radii = self.semiaxis_x != Default::default() || self.semiaxis_y != Default::default();
dest.write_str("ellipse(")?; if has_radii { self.semiaxis_x.to_css(dest)?;
dest.write_char(' ')?; self.semiaxis_y.to_css(dest)?;
}
// Preserve the `at <position>` even if it specified the default value. // https://github.com/w3c/csswg-drafts/issues/8695 if !matches!(self.position, GenericPositionOrAuto::Auto) { if has_radii {
dest.write_char(' ')?;
}
dest.write_str("at ")?; self.position.to_css(dest)?;
}
dest.write_char(')')
}
}
/// The shape function defined in css-shape-2. /// shape() = shape(<fill-rule>? from <coordinate-pair>, <shape-command>#) /// /// https://drafts.csswg.org/css-shapes-2/#shape-function #[derive(
Clone,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToResolvedValue,
ToShmem,
)] #[repr(C)] pubstruct Shape<Angle, LengthPercentage> { /// The filling rule for this shape. pub fill: FillRule, /// The shape command data. Note that the starting point will be the first command in this /// slice. // Note: The first command is always GenericShapeCommand::Move. pub commands: crate::OwnedSlice<GenericShapeCommand<Angle, LengthPercentage>>,
}
if matches!(arc_sweep, ArcSweep::Cw) {
dest.write_str(" cw")?;
}
if matches!(arc_size, ArcSize::Large) {
dest.write_str(" large")?;
}
if !rotate.is_zero() {
dest.write_str(" rotate ")?;
rotate.to_css(dest)?;
}
Ok(())
},
Close => dest.write_str("close"),
}
}
}
/// This indicates the command is absolute or relative. /// https://drafts.csswg.org/css-shapes-2/#typedef-shape-by-to #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum ByTo { /// This indicates that the <coordinate-pair>s are relative to the command’s starting point.
By, /// This relative to the top-left corner of the reference box.
To,
}
impl ByTo { /// Return true if it is absolute, i.e. it is To. #[inline] pubfn is_abs(&self) -> bool {
matches!(self, ByTo::To)
}
/// Create ByTo based on the flag if it is absolute. #[inline] pubfn new(is_abs: bool) -> Self { if is_abs { Self::To
} else { Self::By
}
}
}
/// Defines a pair of coordinates, representing a rightward and downward offset, respectively, from /// a specified reference point. Percentages are resolved against the width or height, /// respectively, of the reference box. /// https://drafts.csswg.org/css-shapes-2/#typedef-shape-coordinate-pair #[allow(missing_docs)] #[derive(
AddAssign,
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(C)] pubstruct CoordinatePair<LengthPercentage> { pub x: LengthPercentage, pub y: LengthPercentage,
}
/// This indicates that the arc that is traced around the ellipse clockwise or counter-clockwise /// from the center. /// https://drafts.csswg.org/css-shapes-2/#typedef-shape-arc-sweep #[derive(
Clone,
Copy,
Debug,
Deserialize,
FromPrimitive,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum ArcSweep { /// Counter-clockwise. The default value. (This also represents 0 in the svg path.)
Ccw = 0, /// Clockwise. (This also represents 1 in the svg path.)
Cw = 1,
}
impl Animate for ArcSweep { fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { use num_traits::FromPrimitive; // If an arc command has different <arc-sweep> between its starting and ending list, then // the interpolated result uses cw for any progress value between 0 and 1.
(*selfas i32)
.animate(&(*other as i32), procedure)
.map(|v| ArcSweep::from_u8((v > 0) as u8).unwrap_or(ArcSweep::Ccw))
}
}
impl ComputeSquaredDistance for ArcSweep { fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
(*selfas i32).compute_squared_distance(&(*other as i32))
}
}
/// This indicates that the larger or smaller, respectively, of the two possible arcs must be /// chosen. /// https://drafts.csswg.org/css-shapes-2/#typedef-shape-arc-size #[derive(
Clone,
Copy,
Debug,
Deserialize,
FromPrimitive,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum ArcSize { /// Choose the small one. The default value. (This also represents 0 in the svg path.)
Small = 0, /// Choose the large one. (This also represents 1 in the svg path.)
Large = 1,
}
impl Animate for ArcSize { fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { use num_traits::FromPrimitive; // If it has different <arc-size> keywords, then the interpolated result uses large for any // progress value between 0 and 1.
(*selfas i32)
.animate(&(*other as i32), procedure)
.map(|v| ArcSize::from_u8((v > 0) as u8).unwrap_or(ArcSize::Small))
}
}
impl ComputeSquaredDistance for ArcSize { fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
(*selfas i32).compute_squared_distance(&(*other as i32))
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.