/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! [Calc expressions][calc]. //! //! [calc]: https://drafts.csswg.org/css-values/#calc-notation use crate::color::AbsoluteColor; use crate::color::parsing::ChannelKeyword; use crate::derives::*; use crate::parser::{Parse, ParserContext}; use crate::typed_om::{NumericBaseType, NumericType, ToTyped, TypedValue}; use crate::values::DashedIdent; use crate::values::computed::{self, ToComputedValue}; use crate::values::generics::Optional; use crate::values::generics::calc::{ self as generic, CalcNodeLeaf, CalcType, GenericAnchorFunctionFallback, GenericRandomFunction, MinMaxOp, ModRemOp, ProgressClampingMode, RoundingStrategy, SimplificationResult, SortKey, }; use crate::values::generics::length::GenericAnchorSizeFunction; use crate::values::generics::position::{ AnchorSideKeyword, GenericAnchorFunction, GenericAnchorSide, TreeScoped, }; use crate::values::specified::length::NoCalcLength; use crate::values::specified::random::RandomKey; use crate::values::specified::{ NoCalcAngle, NoCalcNumber, NoCalcPercentage, NoCalcResolution, NoCalcTime, TreeCountingFunction, }; use cssparser::{CowRcStr, Parser, Token, match_ignore_ascii_case}; use debug_unreachable::debug_unreachable; use smallvec::SmallVec; use std::cmp; use std::convert::AsRef; use strum::IntoEnumIterator; use strum_macros::{AsRefStr, EnumIter}; use style_traits::values::specified::AllowedNumericType; use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind}; use thin_vec::ThinVec; /// The name of the mathematical function that we're parsing. #[derive(AsRefStr, Clone, Copy, Debug, EnumIter, Parse)] #[strum(serialize_all = "lowercase")] pub enum MathFunction { /// `calc()`: https://drafts.csswg.org/css-values-4/#funcdef-calc Calc, /// `min()`: https://drafts.csswg.org/css-values-4/#funcdef-min Min, /// `max()`: https://drafts.csswg.org/css-values-4/#funcdef-max Max, /// `clamp()`: https://drafts.csswg.org/css-values-4/#funcdef-clamp Clamp, /// `round()`: https://drafts.csswg.org/css-values-4/#funcdef-round Round, /// `mod()`: https://drafts.csswg.org/css-values-4/#funcdef-mod Mod, /// `rem()`: https://drafts.csswg.org/css-values-4/#funcdef-rem Rem, /// `sin()`: https://drafts.csswg.org/css-values-4/#funcdef-sin Sin, /// `cos()`: https://drafts.csswg.org/css-values-4/#funcdef-cos Cos, /// `tan()`: https://drafts.csswg.org/css-values-4/#funcdef-tan Tan, /// `asin()`: https://drafts.csswg.org/css-values-4/#funcdef-asin Asin, /// `acos()`: https://drafts.csswg.org/css-values-4/#funcdef-acos Acos, /// `atan()`: https://drafts.csswg.org/css-values-4/#funcdef-atan Atan, /// `atan2()`: https://drafts.csswg.org/css-values-4/#funcdef-atan2 Atan2, /// `pow()`: https://drafts.csswg.org/css-values-4/#funcdef-pow Pow, /// `sqrt()`: https://drafts.csswg.org/css-values-4/#funcdef-sqrt Sqrt, /// `hypot()`: https://drafts.csswg.org/css-values-4/#funcdef-hypot Hypot, /// `log()`: https://drafts.csswg.org/css-values-4/#funcdef-log Log, /// `exp()`: https://drafts.csswg.org/css-values-4/#funcdef-exp Exp, /// `abs()`: https://drafts.csswg.org/css-values-4/#funcdef-abs Abs, /// `sign()`: https://drafts.csswg.org/css-values-4/#funcdef-sign Sign, /// `progress()`: https://drafts.csswg.org/css-values-5/#funcdef-progress Progress, /// `random()`: https://drafts.csswg.org/css-values-5/#funcdef-random Random, /// `sibling-count()`: https://drafts.csswg.org/css-values-5/#funcdef-sibling-count #[strum(serialize = "sibling-count")] SiblingCount, /// `sibling-index()`: https://drafts.csswg.org/css-values-5/#funcdef-sibling-index #[strum(serialize = "sibling-index")] SiblingIndex, } impl MathFunction { /// Returns an iterator for the enum variants pub fn variants() -> MathFunctionIter { MathFunction::iter() } } pub use crate::values::generics::calc::CalcPercentageLeaf; /// A leaf node inside a `Calc` expression's AST. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToShmem)] #[repr(u8)] pub enum Leaf { /// `` Length(NoCalcLength), /// `` Angle(NoCalcAngle), /// `