/* * Copyright (c) 2026, Callum Law * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Web::CSS { struct CounterStyleRangeEntry { i32 start; i32 end; bool operator==(CounterStyleRangeEntry const&) const = default; }; // https://drafts.csswg.org/css-counter-styles-3/#counter-style-symbols // = | | // Note: The syntax in is currently at-risk. No implementations have plans to implement it currently, // and it complicates some usages of counter() in ways that haven’t been fully handled. // FIXME: Given the above note we don't currently support here - we may need to revisit this if other browsers // implement it. using CounterStyleSymbol = FlyString; struct CounterStyleNegativeSign { CounterStyleSymbol prefix; CounterStyleSymbol suffix; bool operator==(CounterStyleNegativeSign const&) const = default; }; struct CounterStylePad { i32 minimum_length; CounterStyleSymbol symbol; bool operator==(CounterStylePad const&) const = default; }; struct AdditiveCounterStyleAlgorithm { struct AdditiveTuple { i32 weight; CounterStyleSymbol symbol; bool operator==(AdditiveTuple const&) const = default; }; Vector symbol_list; bool operator==(AdditiveCounterStyleAlgorithm const&) const = default; }; struct FixedCounterStyleAlgorithm { i32 first_symbol; Vector symbol_list; bool operator==(FixedCounterStyleAlgorithm const&) const = default; }; struct GenericCounterStyleAlgorithm { CounterStyleSystem type; Vector symbol_list; bool operator==(GenericCounterStyleAlgorithm const&) const = default; }; struct EthiopicNumericCounterStyleAlgorithm { bool operator==(EthiopicNumericCounterStyleAlgorithm const&) const = default; }; struct ExtendedCJKCounterStyleAlgorithm { enum class Type : u8 { SimpChineseInformal, SimpChineseFormal, TradChineseInformal, TradChineseFormal, JapaneseInformal, JapaneseFormal, KoreanHangulFormal, KoreanHanjaInformal, KoreanHanjaFormal, } type; bool operator==(ExtendedCJKCounterStyleAlgorithm const&) const = default; }; using CounterStyleAlgorithm = Variant; using CounterStyleAlgorithmOrExtends = Variant; struct AutoRange { static Vector resolve(CounterStyleAlgorithm const&); }; class CounterStyleDefinition { public: static CounterStyleDefinition create(FlyString name, CounterStyleAlgorithmOrExtends algorithm, Optional negative_sign, Optional prefix, Optional suffix, Variant> range, Optional fallback, Optional pad) { return CounterStyleDefinition(move(name), move(algorithm), move(negative_sign), move(prefix), move(suffix), move(range), move(fallback), move(pad)); } static Optional from_counter_style_rule(CSSCounterStyleRule const&, ComputationContext const&); FlyString const& name() const { return m_name; } CounterStyleAlgorithmOrExtends const& algorithm() const { return m_algorithm; } void set_algorithm(CounterStyleAlgorithmOrExtends algorithm) { m_algorithm = move(algorithm); } Optional const& negative_sign() const { return m_negative_sign; } Optional const& prefix() const { return m_prefix; } Optional const& suffix() const { return m_suffix; } Variant> const& range() const { return m_range; } Optional const& fallback() const { return m_fallback; } Optional const& pad() const { return m_pad; } private: static Variant resolve_algorithm(NonnullRefPtr const& system_style_value, RefPtr const& symbols_style_value, RefPtr const& additive_symbols_style_value, ComputationContext const&); static Vector resolve_symbols(NonnullRefPtr const& symbols_style_value); static Vector resolve_additive_symbols(NonnullRefPtr const& additive_symbols_style_value, ComputationContext const&); static CounterStyleNegativeSign resolve_negative_sign(NonnullRefPtr const&); static Variant> resolve_range(NonnullRefPtr const&, ComputationContext const&); static CounterStylePad resolve_pad(NonnullRefPtr const&, ComputationContext const&); CounterStyleDefinition(FlyString name, CounterStyleAlgorithmOrExtends algorithm, Optional negative_sign, Optional prefix, Optional suffix, Variant> range, Optional fallback, Optional pad) : m_name(move(name)) , m_algorithm(move(algorithm)) , m_negative_sign(move(negative_sign)) , m_prefix(move(prefix)) , m_suffix(move(suffix)) , m_range(move(range)) , m_fallback(move(fallback)) , m_pad(move(pad)) { } FlyString m_name; CounterStyleAlgorithmOrExtends m_algorithm; Optional m_negative_sign; Optional m_prefix; Optional m_suffix; Variant> m_range; Optional m_fallback; Optional m_pad; }; }