Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / style_values / counter_style_system_style_value.lucb

#==============================================================================================
#
#   counter_style_system_style_value - CounterStyleSystemStyleValue: @counter-style's system
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp (lines 1-142) and the
#       inline members of CounterStyleSystemStyleValue.h: a system keyword, `fixed <integer>?` or
#       `extends <counter-style-name>`, and the symbol-count rules each system imposes.
#
#       Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Allocates and constructs a CounterStyleSystemStyleValue (the `adopt_ref(*new CounterStyleSystemStyleValue(value))`
## of the three creates).
func css_counter_style_system_style_value_new(value: CssCounterStyleSystemStyleValueValue) -> CssCounterStyleSystemStyleValue*:
    let this = &(new CssCounterStyleSystemStyleValue[1] --- else trap("out of memory"))[0]
    css_counter_style_system_style_value_construct(this, value)
    return this

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:15 Web::CSS::CounterStyleSystemStyleValue::create.
pub func css_counter_style_system_style_value_create(system: css_data.CounterStyleSystem) -> CssStyleValue*:
    return css_counter_style_system_style_value_new(CssCounterStyleSystemStyleValueValue.counter_style_system(system)).css_style_value()

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:20 Web::CSS::CounterStyleSystemStyleValue::create_fixed.
pub func css_counter_style_system_style_value_create_fixed(first_symbol: CssStyleValue*?) -> CssStyleValue*:
    return css_counter_style_system_style_value_new(CssCounterStyleSystemStyleValueValue.css_counter_style_system_style_value_fixed(CssCounterStyleSystemStyleValueFixed(first_symbol = first_symbol))).css_style_value()

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:25 Web::CSS::CounterStyleSystemStyleValue::create_extends.
pub func css_counter_style_system_style_value_create_extends(name: ak.FlyString) -> CssStyleValue*:
    return css_counter_style_system_style_value_new(CssCounterStyleSystemStyleValueValue.css_counter_style_system_style_value_extends(CssCounterStyleSystemStyleValueExtends(name = name))).css_style_value()

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:57 Web::CSS::CounterStyleSystemStyleValue::CounterStyleSystemStyleValue.
pub func css_counter_style_system_style_value_construct(this: CssCounterStyleSystemStyleValue*, value: CssCounterStyleSystemStyleValueValue):
    css_style_value_construct(this.css_style_value(), CssStyleValueType.counter_style_system)
    css_style_value_set_class(this.css_style_value(), (const CssStyleValueVTable*)&css_counter_style_system_style_value_vtable, &css_counter_style_system_style_value_class)
    this.m_value = value

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp:13 Web::CSS::CounterStyleSystemStyleValue::serialize (override).
pub func css_counter_style_system_style_value_serialize_impl(base: CssStyleValue*, builder: ak.StringBuilder*, mode: css_syntax.SerializationMode):
    let this = (CssCounterStyleSystemStyleValue*)base
    match this.m_value:
        .counter_style_system(system):
            ak.string_builder_append_string_view(builder, css_data.to_string_counter_style_system(system))
        .css_counter_style_system_style_value_fixed(fixed):
            ak.string_builder_append(builder, "fixed")
            if let first_symbol = fixed.first_symbol:
                ak.string_builder_append_u8(builder, ' ')
                css_style_value_serialize(first_symbol, builder, mode)
        .css_counter_style_system_style_value_extends(extends):
            ak.string_builder_append(builder, "extends ")
            css_syntax.serialize_an_identifier_string_builder(builder, ak.fly_string_bytes_as_string_view(&extends.name))

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp:32 Web::CSS::CounterStyleSystemStyleValue::absolutized (override).
pub func css_counter_style_system_style_value_absolutized_impl(base: CssStyleValue*, context: CssComputationContext) -> CssStyleValue*:
    let this = (CssCounterStyleSystemStyleValue*)base
    match this.m_value:
        .counter_style_system(_):
            return base
        .css_counter_style_system_style_value_fixed(fixed):
            let first_symbol = fixed.first_symbol else return base

            let absolutized_value = css_style_value_absolutized(first_symbol, context)
            if css_style_values_equal(absolutized_value, first_symbol):
                return base

            return css_counter_style_system_style_value_create_fixed(absolutized_value)
        .css_counter_style_system_style_value_extends(_):
            return base

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp:54 Web::CSS::CounterStyleSystemStyleValue::algorithm_differs_from.
pub func css_counter_style_system_style_value_algorithm_differs_from(this: CssCounterStyleSystemStyleValue*, other: CssCounterStyleSystemStyleValue*) -> bool:
    match this.m_value:
        .counter_style_system(system):
            match other.m_value:
                .counter_style_system(other_system): return system != other_system
                _: return true
        .css_counter_style_system_style_value_fixed(_):
            match other.m_value:
                .css_counter_style_system_style_value_fixed(_): return false
                _: return true
        .css_counter_style_system_style_value_extends(extends):
            match other.m_value:
                .css_counter_style_system_style_value_extends(other_extends):
                    # FIXME: We don't know which counter style the 'extends' refers to here, so we have to assume it might
                    #        differ if the names differ. Is this correct?
                    return not ak.fly_string_eq_fly_string(&extends.name, &other_extends.name)
                _: return true

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp:73 Web::CSS::CounterStyleSystemStyleValue::is_valid_symbol_count.
pub func css_counter_style_system_style_value_is_valid_symbol_count(this: CssCounterStyleSystemStyleValue*, count: usize) -> bool:
    match this.m_value:
        .counter_style_system(system):
            match system:
                # https://drafts.csswg.org/css-counter-styles-3/#cyclic-system
                # If the system is cyclic, the symbols descriptor must contain at least one counter symbol, otherwise the
                # rule does not define a counter style (but is still a valid rule)
                # https://drafts.csswg.org/css-counter-styles-3/#symbolic-system
                # If the system is symbolic, the symbols descriptor must contain at least one counter symbol, otherwise the
                # rule does not define a counter style (but is still a valid rule).
                .cyclic, .symbolic:
                    return count >= 1
                # https://drafts.csswg.org/css-counter-styles-3/#alphabetic-system
                # If the system is alphabetic, the symbols descriptor must contain at least two counter symbols, otherwise
                # the rule does not define a counter style (but is still a valid rule).
                # https://drafts.csswg.org/css-counter-styles-3/#numeric-system
                # If the system is numeric, the symbols descriptor must contain at least two counter symbols, otherwise the
                # rule does not define a counter style (but is still a valid rule).
                .alphabetic, .numeric:
                    return count >= 2
                .additive:
                    # NB: Additive relies on the `additive-symbols` descriptor instead and `symbols` is ignored.
                    return true
                _:
                    trap("VERIFY_NOT_REACHED")
        .css_counter_style_system_style_value_fixed(_):
            # https://drafts.csswg.org/css-counter-styles-3/#fixed-system
            # If the system is fixed, the symbols descriptor must contain at least one counter symbol, otherwise the
            # rule does not define a counter style (but is still a valid rule).
            return count >= 1
        .css_counter_style_system_style_value_extends(_):
            # https://drafts.csswg.org/css-counter-styles-3/#extends-system
            # If a @counter-style uses the extends system, it must not contain a symbols or additive-symbols
            # descriptor, otherwise the rule does not define a counter style (but is still a valid rule).
            return false

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.cpp:117 Web::CSS::CounterStyleSystemStyleValue::is_valid_additive_symbol_count.
pub func css_counter_style_system_style_value_is_valid_additive_symbol_count(this: CssCounterStyleSystemStyleValue*, count: usize) -> bool:
    match this.m_value:
        .counter_style_system(system):
            # https://drafts.csswg.org/css-counter-styles-3/#additive-system
            # If the system is additive, the additive-symbols descriptor must contain at least one additive tuple,
            # otherwise the rule does not define a counter style (but is still a valid rule).
            if system == css_data.CounterStyleSystem.additive:
                return count >= 1

            # NB: Other systems ignore rely on the `symbols` descriptor instead and `additive-symbols` is ignored.
            return true
        .css_counter_style_system_style_value_fixed(_):
            # NB: Fixed relies on the `symbols` descriptor instead and `additive-symbols` is ignored.
            return true
        .css_counter_style_system_style_value_extends(_):
            # https://drafts.csswg.org/css-counter-styles-3/#extends-system
            # If a @counter-style uses the extends system, it must not contain a symbols or additive-symbols
            # descriptor, otherwise the rule does not define a counter style (but is still a valid rule).
            return false

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:49 Web::CSS::CounterStyleSystemStyleValue::value.
pub func css_counter_style_system_style_value_value(this: CssCounterStyleSystemStyleValue*) -> CssCounterStyleSystemStyleValueValue:
    return this.m_value

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:51 Web::CSS::CounterStyleSystemStyleValue::properties_equal.
pub func css_counter_style_system_style_value_properties_equal(this: CssCounterStyleSystemStyleValue*, other: CssCounterStyleSystemStyleValue*) -> bool:
    # Value's operator== (the same alternative, and Fixed's and Extends' defaulted operator==).
    match this.m_value:
        .counter_style_system(system):
            match other.m_value:
                .counter_style_system(other_system): return system == other_system
                _: return false
        .css_counter_style_system_style_value_fixed(fixed):
            match other.m_value:
                .css_counter_style_system_style_value_fixed(other_fixed): return css_optional_style_values_equal(fixed.first_symbol, other_fixed.first_symbol)
                _: return false
        .css_counter_style_system_style_value_extends(extends):
            match other.m_value:
                .css_counter_style_system_style_value_extends(other_extends): return ak.fly_string_eq_fly_string(&extends.name, &other_extends.name)
                _: return false

## Ported from Libraries/LibWeb/CSS/StyleValues/CounterStyleSystemStyleValue.h:54 Web::CSS::CounterStyleSystemStyleValue::is_computationally_independent (override).
# NB: We only use this style value within the @counter-style at-rule so will never call this
pub func css_counter_style_system_style_value_is_computationally_independent_impl(base: CssStyleValue*) -> bool:
    _ = base
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/StyleValues/StyleValue.h:202 Web::CSS::StyleValueWithDefaultOperators::equals for Web::CSS::CounterStyleSystemStyleValue (CRTP helper) (override).
pub func css_counter_style_system_style_value_equals_impl(base: CssStyleValue*, other: CssStyleValue*) -> bool:
    if css_style_value_type(base) != css_style_value_type(other):
        return false
    return css_counter_style_system_style_value_properties_equal((CssCounterStyleSystemStyleValue*)base, (CssCounterStyleSystemStyleValue*)other)