use bitmask_enum::bitmask;
use crate::{CssAtomSet, UnitlessZeroResolves};
#[bitmask(u128)]
#[bitmask_config(vec_debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PropertyGroup {
Align,
AnchorPosition,
AnimationTriggers,
Animations,
Backgrounds,
Borders,
Box,
Break,
Cascade,
Color,
ColorAdjust,
ColorHdr,
Compositing,
Conditional,
Contain,
Content,
CounterStyle,
Display,
Exclusions,
FillStroke,
FilterEffects,
Flexbox,
Fonts,
Forms,
Gaps,
Gcpm,
Grid,
Images,
ImageAnimation,
Inline,
LineGrid,
LinkParams,
Lists,
Logical,
Masking,
Motion,
Multicol,
Nav,
Overflow,
Overscroll,
Page,
PageFloats,
PointerAnimations,
Position,
Regions,
Rhythm,
RoundDisplay,
Ruby,
ScrollAnchoring,
ScrollAnimations,
ScrollSnap,
Scrollbars,
Shaders,
Shapes,
SizeAdjust,
Sizing,
Speech,
Tables,
Text,
TextDecor,
Transforms,
Transitions,
Ui,
Values,
Variables,
ViewTransitions,
Viewport,
WillChange,
WritingModes,
}
pub enum Inherits {
False,
True,
Unknown,
}
impl Inherits {
pub fn to_bool(self, unknown: bool) -> bool {
match self {
Self::False => false,
Self::True => true,
Self::Unknown => unknown,
}
}
}
pub enum Percentages {
None,
ContainingBlock,
BorderBox,
Number,
FontSize,
ParentFontSize,
Scrollport,
ContentArea,
BorderEdge,
BackgroundPositioningArea,
ReferenceBox,
SelfSize,
LineBox,
FlexContainer,
BorderImageArea,
NormalizedRange,
Unknown,
}
#[bitmask(u16)]
#[bitmask_config(vec_debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AppliesTo {
Block,
Grid,
Flex,
Inline,
Float,
Ruby,
AbsPos,
Text,
PseudoElements,
Elements,
Unknown,
}
pub enum AnimationType {
None,
Discrete,
ByComputedValue,
RepeatableList,
TransformList,
ShadowList,
Length,
Number,
Unknown,
}
pub enum ComputedValueType {
AsSpecified,
AbsoluteLength,
AbsoluteLengthOrPercentage,
AbsoluteLengthOrNone,
SpecifiedKeywordPlusAbsoluteLength,
TwoAbsoluteLengths,
ListOfAbsoluteLengths,
SpecifiedWithAbsoluteLengths,
SpecifiedWithAbsoluteUrls,
SeeIndividualProperties,
Complex,
Unknown,
}
#[bitmask(u8)]
#[bitmask_config(vec_debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BoxSide {
Top = 0b00000001,
Bottom = 0b00000010,
Left = 0b00000100,
Right = 0b00001000,
BlockStart = 0b00010000,
BlockEnd = 0b00100000,
InlineStart = 0b01000000,
InlineEnd = 0b10000000,
}
impl BoxSide {
#[inline]
pub fn num_sides(&self, logical: bool) -> u32 {
if logical { (self.bits() & 0b11110000).count_ones() } else { (self.bits() & 0b00001111).count_ones() }
}
}
#[bitmask(u8)]
#[bitmask_config(vec_debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BoxPortion {
Size,
Margin,
Padding,
Border,
Position,
}
pub trait DeclarationMetadata: Sized {
fn initial() -> &'static str;
fn inherits() -> Inherits {
Inherits::False
}
fn applies_to() -> AppliesTo {
AppliesTo::none()
}
fn percentages() -> Percentages {
Percentages::None
}
fn animation_type() -> AnimationType {
AnimationType::None
}
fn is_shorthand() -> bool {
false
}
fn is_longhand() -> bool {
Self::shorthand_group() == CssAtomSet::_None
}
fn longhands() -> Option<&'static [CssAtomSet]> {
None
}
fn shorthand_group() -> CssAtomSet {
CssAtomSet::_None
}
fn property_group() -> PropertyGroup {
PropertyGroup::none()
}
fn computed_value_type() -> ComputedValueType {
ComputedValueType::Unknown
}
fn canonical_order() -> Option<&'static str> {
None
}
fn logical_property_group() -> Option<CssAtomSet> {
None
}
fn box_side() -> BoxSide {
BoxSide::none()
}
fn box_portion() -> BoxPortion {
BoxPortion::none()
}
fn unitless_zero_resolves() -> UnitlessZeroResolves {
UnitlessZeroResolves::Length
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn test_box_side_count() {
assert_eq!(BoxSide::Top.num_sides(false), 1);
assert_eq!((BoxSide::Top | BoxSide::Right).num_sides(false), 2);
assert_eq!((BoxSide::Top | BoxSide::Right | BoxSide::Bottom).num_sides(false), 3);
assert_eq!((BoxSide::Top | BoxSide::Right | BoxSide::Bottom | BoxSide::Left).num_sides(false), 4);
assert_eq!((BoxSide::Top | BoxSide::Right | BoxSide::Bottom | BoxSide::Left).num_sides(true), 0);
assert_eq!(BoxSide::all_bits().num_sides(false), 4);
assert_eq!(BoxSide::all_bits().num_sides(true), 4);
assert_eq!(BoxSide::BlockStart.num_sides(true), 1);
assert_eq!((BoxSide::BlockStart | BoxSide::BlockEnd).num_sides(true), 2);
assert_eq!((BoxSide::BlockStart | BoxSide::BlockEnd | BoxSide::InlineStart).num_sides(true), 3);
assert_eq!(
(BoxSide::BlockStart | BoxSide::BlockEnd | BoxSide::InlineStart | BoxSide::InlineEnd).num_sides(true),
4
);
assert_eq!(
(BoxSide::BlockStart | BoxSide::BlockEnd | BoxSide::InlineStart | BoxSide::InlineEnd).num_sides(false),
0
);
}
}