Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / computed_properties_2.lucb

#==============================================================================================
#
#   computed_properties_2 - ComputedProperties: SVG paint, flex, backgrounds, transforms
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/ComputedProperties.cpp (lines 422-888): the SVG fill and stroke
#       readers, flex, order, image-rendering, the background layers (a coordinated value list
#       over the background-* longhands), border-spacing, caption-side, clip, the justify and
#       align properties, the transform readers, accent-color, appearance, the filters and
#       position.
#
#       Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: SVG fill and stroke =====================================================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:422 Web::CSS::ComputedProperties::fill_opacity.
pub func css_computed_properties_fill_opacity(this: CssComputedProperties*) -> f32:
    return (f32)css_opacity_value_style_value_resolved(css_style_value_as_opacity_value(css_computed_properties_property(this, css_data.PropertyId.fill_opacity)))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:427 Web::CSS::ComputedProperties::stroke_dasharray.
pub func css_computed_properties_stroke_dasharray(this: CssComputedProperties*) -> ak.Vector[CssLengthPercentageOrF32]:
    let value = css_computed_properties_property(this, css_data.PropertyId.stroke_dasharray)

    # none
    if css_style_value_is_keyword(value) and css_style_value_to_keyword(value) == css_data.Keyword.none_:
        return ak.Vector[CssLengthPercentageOrF32]()

    let stroke_dasharray = css_style_value_list_values(css_style_value_as_value_list(value))
    var dashes: ak.Vector[CssLengthPercentageOrF32]

    for item in ak.vector_span_const(&stroke_dasharray):
        if css_style_value_is_length(item):
            ak.vector_append_t(&dashes, CssLengthPercentageOrF32.css_length_percentage(css_length_percentage_new_css_length(css_length_style_value_length(css_style_value_as_length(item)))))
        elif css_style_value_is_percentage(item):
            ak.vector_append_t(&dashes, CssLengthPercentageOrF32.css_length_percentage(css_length_percentage_new_css_percentage(css_percentage_style_value_percentage(css_style_value_as_percentage(item)))))
        elif css_style_value_is_calculated(item):
            let calculated_value = css_style_value_as_calculated(item)

            if css_calculated_style_value_resolves_to_length(calculated_value):
                ak.vector_append_t(&dashes, CssLengthPercentageOrF32.css_length_percentage(css_length_percentage_new_css_calculated_style_value(calculated_value)))
            elif css_calculated_style_value_resolves_to_number(calculated_value):
                let number = css_calculated_style_value_resolve_number(calculated_value, CssCalculationResolutionContext()) else trap("VERIFY: Optional::value() of resolve_number()")
                ak.vector_append_t(&dashes, CssLengthPercentageOrF32.f32_((f32)number))
            else:
                trap("VERIFY_NOT_REACHED")
        elif css_style_value_is_number(item):
            ak.vector_append_t(&dashes, CssLengthPercentageOrF32.f32_((f32)css_number_style_value_number(css_style_value_as_number(item))))
        else:
            trap("VERIFY_NOT_REACHED")

    return dashes

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:463 Web::CSS::ComputedProperties::stroke_linecap.
pub func css_computed_properties_stroke_linecap(this: CssComputedProperties*) -> css_data.StrokeLinecap:
    let value = css_computed_properties_property(this, css_data.PropertyId.stroke_linecap)
    return css_data.keyword_to_stroke_linecap(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:469 Web::CSS::ComputedProperties::stroke_linejoin.
pub func css_computed_properties_stroke_linejoin(this: CssComputedProperties*) -> css_data.StrokeLinejoin:
    let value = css_computed_properties_property(this, css_data.PropertyId.stroke_linejoin)
    return css_data.keyword_to_stroke_linejoin(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:475 Web::CSS::ComputedProperties::stroke_miterlimit.
pub func css_computed_properties_stroke_miterlimit(this: CssComputedProperties*) -> f64:
    return css_number_from_style_value(css_computed_properties_property(this, css_data.PropertyId.stroke_miterlimit), none)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:480 Web::CSS::ComputedProperties::stroke_opacity.
pub func css_computed_properties_stroke_opacity(this: CssComputedProperties*) -> f32:
    return (f32)css_opacity_value_style_value_resolved(css_style_value_as_opacity_value(css_computed_properties_property(this, css_data.PropertyId.stroke_opacity)))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:485 Web::CSS::ComputedProperties::stop_opacity.
pub func css_computed_properties_stop_opacity(this: CssComputedProperties*) -> f32:
    return (f32)css_opacity_value_style_value_resolved(css_style_value_as_opacity_value(css_computed_properties_property(this, css_data.PropertyId.stop_opacity)))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:490 Web::CSS::ComputedProperties::fill_rule.
pub func css_computed_properties_fill_rule(this: CssComputedProperties*) -> css_data.FillRule:
    let value = css_computed_properties_property(this, css_data.PropertyId.fill_rule)
    return css_data.keyword_to_fill_rule(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:496 Web::CSS::ComputedProperties::clip_rule.
pub func css_computed_properties_clip_rule(this: CssComputedProperties*) -> css_data.FillRule:
    let value = css_computed_properties_property(this, css_data.PropertyId.clip_rule)
    return css_data.keyword_to_fill_rule(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:502 Web::CSS::ComputedProperties::flood_opacity.
pub func css_computed_properties_flood_opacity(this: CssComputedProperties*) -> f32:
    return (f32)css_opacity_value_style_value_resolved(css_style_value_as_opacity_value(css_computed_properties_property(this, css_data.PropertyId.flood_opacity)))

# mark: Flex and order ==========================================================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:507 Web::CSS::ComputedProperties::flex_direction.
pub func css_computed_properties_flex_direction(this: CssComputedProperties*) -> css_data.FlexDirection:
    let value = css_computed_properties_property(this, css_data.PropertyId.flex_direction)
    return css_data.keyword_to_flex_direction(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:513 Web::CSS::ComputedProperties::flex_wrap.
pub func css_computed_properties_flex_wrap(this: CssComputedProperties*) -> css_data.FlexWrap:
    let value = css_computed_properties_property(this, css_data.PropertyId.flex_wrap)
    return css_data.keyword_to_flex_wrap(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:519 Web::CSS::ComputedProperties::flex_basis.
pub func css_computed_properties_flex_basis(this: CssComputedProperties*) -> CssFlexBasis:
    let value = css_computed_properties_property(this, css_data.PropertyId.flex_basis)

    if css_style_value_is_keyword(value) and css_style_value_to_keyword(value) == css_data.Keyword.content:
        return CssFlexBasis.css_flex_basis_content(CssFlexBasisContent())

    return CssFlexBasis.css_size(css_computed_properties_size_value(this, css_data.PropertyId.flex_basis))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:529 Web::CSS::ComputedProperties::flex_grow.
pub func css_computed_properties_flex_grow(this: CssComputedProperties*) -> f32:
    let value = css_computed_properties_property(this, css_data.PropertyId.flex_grow)
    if not css_style_value_is_number(value):
        return 0.0
    return (f32)css_number_style_value_number(css_style_value_as_number(value))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:537 Web::CSS::ComputedProperties::flex_shrink.
pub func css_computed_properties_flex_shrink(this: CssComputedProperties*) -> f32:
    let value = css_computed_properties_property(this, css_data.PropertyId.flex_shrink)
    if not css_style_value_is_number(value):
        return 1.0
    return (f32)css_number_style_value_number(css_style_value_as_number(value))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:545 Web::CSS::ComputedProperties::order.
pub func css_computed_properties_order(this: CssComputedProperties*) -> i32:
    let value = css_computed_properties_property(this, css_data.PropertyId.order)
    # FIXME: Support calc()
    if not css_style_value_is_integer(value):
        return 0
    return css_integer_style_value_integer(css_style_value_as_integer(value))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:554 Web::CSS::ComputedProperties::image_rendering.
pub func css_computed_properties_image_rendering(this: CssComputedProperties*) -> css_data.ImageRendering:
    let value = css_computed_properties_property(this, css_data.PropertyId.image_rendering)
    return css_data.keyword_to_image_rendering(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

# mark: Backgrounds and tables ==================================================================

## The entry `property_id` of a coordinated value list (C++ `coordinated_value_list.get(id)`, then `->` or `.value()`).
func css_computed_properties_coordinated_values(list: const ak.HashMap[css_data.PropertyId, ak.Vector[CssStyleValue*], css_data.PropertyIdTraits]*, property_id: css_data.PropertyId) -> const ak.Vector[CssStyleValue*]*:
    return ak.hash_map_get_k_const(list, property_id) else trap("VERIFY: Optional::value() of a coordinated value list entry")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:561 Web::CSS::ComputedProperties::background_layers.
# https://drafts.csswg.org/css-backgrounds-4/#layering
pub func css_computed_properties_background_layers(this: CssComputedProperties*) -> ak.Vector[CssBackgroundLayerData]:
    let background_image_values = css_style_value_list_values(css_style_value_as_value_list(css_computed_properties_property(this, css_data.PropertyId.background_image)))

    # OPTIMIZATION: If all background-image values are `none`, we can skip computing the layers entirely
    var all_none = true
    for value in ak.vector_span_const(&background_image_values):
        if css_style_value_to_keyword(value) != css_data.Keyword.none_:
            all_none = false
            break
    if all_none:
        return ak.Vector[CssBackgroundLayerData]()

    var property_ids: ak.Vector[css_data.PropertyId]
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_attachment)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_blend_mode)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_clip)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_image)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_origin)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_position_x)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_position_y)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_repeat)
    ak.vector_append_t(&property_ids, css_data.PropertyId.background_size)
    let coordinated_value_list = css_computed_properties_assemble_coordinated_value_list(this, css_data.PropertyId.background_image, property_ids)

    let images = css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_image)
    var layers: ak.Vector[CssBackgroundLayerData]
    # The number of layers is determined by the number of comma-separated values in the background-image property
    ak.vector_ensure_capacity(&layers, ak.vector_size(images))

    for i in 0..<ak.vector_size(images):
        let background_image_value = *ak.vector_at_const(images, i)

        if css_style_value_to_keyword(background_image_value) == css_data.Keyword.none_:
            continue

        let background_attachment_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_attachment), i)
        let background_blend_mode_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_blend_mode), i)
        let background_clip_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_clip), i)
        let background_origin_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_origin), i)
        let background_position_x_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_position_x), i)
        let background_position_y_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_position_y), i)
        let background_repeat_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_repeat), i)
        let background_size_value = *ak.vector_at_const(css_computed_properties_coordinated_values(&coordinated_value_list, css_data.PropertyId.background_size), i)

        var layer: CssBackgroundLayerData = ---
        css_background_layer_data_init_fields(&layer)
        layer.background_image = css_style_value_as_abstract_image(background_image_value)

        layer.attachment = css_data.keyword_to_background_attachment(css_style_value_to_keyword(background_attachment_value)) else trap("VERIFY: Optional::value()")
        layer.blend_mode = css_data.keyword_to_mix_blend_mode(css_style_value_to_keyword(background_blend_mode_value)) else trap("VERIFY: Optional::value()")
        layer.clip = css_data.keyword_to_background_box(css_style_value_to_keyword(background_clip_value)) else trap("VERIFY: Optional::value()")

        layer.origin = css_data.keyword_to_background_box(css_style_value_to_keyword(background_origin_value)) else trap("VERIFY: Optional::value()")

        layer.position_x = css_length_percentage_from_style_value(css_edge_style_value_offset(css_style_value_as_edge(background_position_x_value)))
        layer.position_y = css_length_percentage_from_style_value(css_edge_style_value_offset(css_style_value_as_edge(background_position_y_value)))

        layer.repeat_x = css_repeat_style_style_value_repeat_x(css_style_value_as_repeat_style(background_repeat_value))
        layer.repeat_y = css_repeat_style_style_value_repeat_y(css_style_value_as_repeat_style(background_repeat_value))

        if css_style_value_is_background_size(background_size_value):
            layer.size_type = CssBackgroundSize.length_percentage
            layer.size_x = css_length_percentage_or_auto_from_style_value(css_background_size_style_value_size_x(css_style_value_as_background_size(background_size_value)))
            layer.size_y = css_length_percentage_or_auto_from_style_value(css_background_size_style_value_size_y(css_style_value_as_background_size(background_size_value)))
        elif css_style_value_is_keyword(background_size_value):
            match css_style_value_to_keyword(background_size_value):
                .contain:
                    layer.size_type = CssBackgroundSize.contain
                .cover:
                    layer.size_type = CssBackgroundSize.cover
                _:
                    trap("VERIFY_NOT_REACHED")
        else:
            trap("VERIFY_NOT_REACHED")

        ak.vector_unchecked_append_u(&layers, layer)

    return layers

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:644 Web::CSS::ComputedProperties::background_color_clip.
pub func css_computed_properties_background_color_clip(this: CssComputedProperties*) -> css_data.BackgroundBox:
    # The background color is clipped according to the final layer's background-clip value. We propagate this
    # separately to allow us to avoid computing layer data in the case a layer's `background-image` is `none`

    let background_image_values = css_style_value_list_values(css_style_value_as_value_list(css_computed_properties_property(this, css_data.PropertyId.background_image)))
    let background_clip_values = css_style_value_list_values(css_style_value_as_value_list(css_computed_properties_property(this, css_data.PropertyId.background_clip)))

    # Background clip values are coordinated against background image values so the value used for the final layer is
    # not necessarily the last specified one.
    let final_layer_index = (ak.vector_size(&background_image_values) - 1) % ak.vector_size(&background_clip_values)

    return css_data.keyword_to_background_box(css_style_value_to_keyword(*ak.vector_at_const(&background_clip_values, final_layer_index))) else trap("VERIFY: Optional::value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:659 Web::CSS::ComputedProperties::border_spacing_horizontal.
pub func css_computed_properties_border_spacing_horizontal(this: CssComputedProperties*) -> CssLength:
    let style_value = css_computed_properties_property(this, css_data.PropertyId.border_spacing)

    if css_style_value_is_value_list(style_value):
        let list = css_style_value_as_value_list(style_value)
        assert(css_style_value_list_size(list) > 0)
        return css_length_from_style_value(css_style_value_list_value_at(list, 0, false), none)

    return css_length_from_style_value(style_value, none)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:672 Web::CSS::ComputedProperties::border_spacing_vertical.
pub func css_computed_properties_border_spacing_vertical(this: CssComputedProperties*) -> CssLength:
    let style_value = css_computed_properties_property(this, css_data.PropertyId.border_spacing)

    if css_style_value_is_value_list(style_value):
        let list = css_style_value_as_value_list(style_value)
        assert(css_style_value_list_size(list) > 1)
        return css_length_from_style_value(css_style_value_list_value_at(list, 1, false), none)

    return css_length_from_style_value(style_value, none)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:685 Web::CSS::ComputedProperties::caption_side.
pub func css_computed_properties_caption_side(this: CssComputedProperties*) -> css_data.CaptionSide:
    let value = css_computed_properties_property(this, css_data.PropertyId.caption_side)
    return css_data.keyword_to_caption_side(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:691 Web::CSS::ComputedProperties::clip.
pub func css_computed_properties_clip(this: CssComputedProperties*) -> CssClip:
    let value = css_computed_properties_property(this, css_data.PropertyId.clip)
    if not css_style_value_is_rect(value):
        return css_clip_make_auto()
    var clip: CssClip = ---
    css_clip_construct_css_edge_rect(&clip, css_rect_style_value_rect(css_style_value_as_rect(value)))
    return clip

# mark: Box alignment ===========================================================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:699 Web::CSS::ComputedProperties::justify_content.
pub func css_computed_properties_justify_content(this: CssComputedProperties*) -> css_data.JustifyContent:
    let value = css_computed_properties_property(this, css_data.PropertyId.justify_content)
    return css_data.keyword_to_justify_content(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:705 Web::CSS::ComputedProperties::justify_items.
pub func css_computed_properties_justify_items(this: CssComputedProperties*) -> css_data.JustifyItems:
    let value = css_computed_properties_property(this, css_data.PropertyId.justify_items)
    return css_data.keyword_to_justify_items(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:711 Web::CSS::ComputedProperties::justify_self.
pub func css_computed_properties_justify_self(this: CssComputedProperties*) -> css_data.JustifySelf:
    let value = css_computed_properties_property(this, css_data.PropertyId.justify_self)
    return css_data.keyword_to_justify_self(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

# mark: Transforms ==============================================================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:717 Web::CSS::ComputedProperties::transformations_for_style_value.
pub func css_computed_properties_transformations_for_style_value(value: CssStyleValue*) -> ak.Vector[CssTransformationStyleValue*]:
    if css_style_value_is_keyword(value) and css_style_value_to_keyword(value) == css_data.Keyword.none_:
        return ak.Vector[CssTransformationStyleValue*]()

    if not css_style_value_is_value_list(value):
        return ak.Vector[CssTransformationStyleValue*]()

    let list = css_style_value_list_values(css_style_value_as_value_list(value))
    var transformations: ak.Vector[CssTransformationStyleValue*]
    for transform_value in ak.vector_span_const(&list):
        assert(css_style_value_is_transformation(transform_value))
        ak.vector_append_t(&transformations, css_style_value_as_transformation(transform_value))
    return transformations

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:734 Web::CSS::ComputedProperties::transformations.
pub func css_computed_properties_transformations(this: CssComputedProperties*) -> ak.Vector[CssTransformationStyleValue*]:
    return css_computed_properties_transformations_for_style_value(css_computed_properties_property(this, css_data.PropertyId.transform))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:739 Web::CSS::ComputedProperties::rotate.
pub func css_computed_properties_rotate(this: CssComputedProperties*) -> CssTransformationStyleValue*?:
    let value = css_computed_properties_property(this, css_data.PropertyId.rotate)
    if not css_style_value_is_transformation(value):
        return none
    return css_style_value_as_transformation(value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:747 Web::CSS::ComputedProperties::translate.
pub func css_computed_properties_translate(this: CssComputedProperties*) -> CssTransformationStyleValue*?:
    let value = css_computed_properties_property(this, css_data.PropertyId.translate)
    if not css_style_value_is_transformation(value):
        return none
    return css_style_value_as_transformation(value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:755 Web::CSS::ComputedProperties::scale.
pub func css_computed_properties_scale(this: CssComputedProperties*) -> CssTransformationStyleValue*?:
    let value = css_computed_properties_property(this, css_data.PropertyId.scale)
    if not css_style_value_is_transformation(value):
        return none
    return css_style_value_as_transformation(value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:763 Web::CSS::ComputedProperties::transform_box.
pub func css_computed_properties_transform_box(this: CssComputedProperties*) -> css_data.TransformBox:
    let value = css_computed_properties_property(this, css_data.PropertyId.transform_box)
    return css_data.keyword_to_transform_box(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:769 Web::CSS::ComputedProperties::perspective.
pub func css_computed_properties_perspective(this: CssComputedProperties*) -> gfx.CssPixels?:
    let value = css_computed_properties_property(this, css_data.PropertyId.perspective)
    if css_style_value_is_keyword(value) and css_style_value_to_keyword(value) == css_data.Keyword.none_:
        return none

    let length = css_length_from_style_value(value, none)
    return css_length_absolute_length_to_px(&length)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:778 Web::CSS::ComputedProperties::perspective_origin.
pub func css_computed_properties_perspective_origin(this: CssComputedProperties*) -> CssPosition:
    return css_computed_properties_position_value(this, css_data.PropertyId.perspective_origin)

## The `length_percentage_with_keywords_resolved` lambda of ComputedProperties::transform_origin.
func css_computed_properties_length_percentage_with_keywords_resolved(value: CssStyleValue*) -> CssLengthPercentage:
    if css_style_value_is_keyword(value):
        let keyword = css_style_value_to_keyword(value)
        if keyword == css_data.Keyword.left or keyword == css_data.Keyword.top:
            return css_length_percentage_new_css_percentage(css_percentage_new(0.0))
        if keyword == css_data.Keyword.center:
            return css_length_percentage_new_css_percentage(css_percentage_new(50.0))
        if keyword == css_data.Keyword.right or keyword == css_data.Keyword.bottom:
            return css_length_percentage_new_css_percentage(css_percentage_new(100.0))

        trap("VERIFY_NOT_REACHED")
    return css_length_percentage_from_style_value(value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:783 Web::CSS::ComputedProperties::transform_origin.
pub func css_computed_properties_transform_origin(this: CssComputedProperties*) -> CssTransformOrigin:
    let value = css_computed_properties_property(this, css_data.PropertyId.transform_origin)
    if not css_style_value_is_value_list(value) or css_style_value_list_size(css_style_value_as_value_list(value)) != 3:
        return css_transform_origin_new()
    let list = css_style_value_list_values(css_style_value_as_value_list(value))

    let x_value = css_computed_properties_length_percentage_with_keywords_resolved(*ak.vector_at_const(&list, 0))
    let y_value = css_computed_properties_length_percentage_with_keywords_resolved(*ak.vector_at_const(&list, 1))
    let z_value = css_length_percentage_from_style_value(*ak.vector_at_const(&list, 2))
    return CssTransformOrigin(x = x_value, y = y_value, z = z_value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:811 Web::CSS::ComputedProperties::transform_style.
pub func css_computed_properties_transform_style(this: CssComputedProperties*) -> css_data.TransformStyle:
    let value = css_computed_properties_property(this, css_data.PropertyId.transform_style)
    return css_data.keyword_to_transform_style(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

# mark: Accent color, alignment, appearance, filters ============================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:817 Web::CSS::ComputedProperties::accent_color.
pub func css_computed_properties_accent_color(this: CssComputedProperties*, color_resolution_context: CssColorResolutionContext) -> gfx.Color:
    let value = css_computed_properties_property(this, css_data.PropertyId.accent_color)

    if css_style_value_to_keyword(value) == css_data.Keyword.auto:
        return css_system_color_accent_color(color_resolution_context.color_scheme else trap("VERIFY: Optional::value() of the color scheme"))

    return css_style_value_to_color(value, color_resolution_context) else trap("VERIFY: Optional::value() of to_color()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:827 Web::CSS::ComputedProperties::align_content.
pub func css_computed_properties_align_content(this: CssComputedProperties*) -> css_data.AlignContent:
    let value = css_computed_properties_property(this, css_data.PropertyId.align_content)
    return css_data.keyword_to_align_content(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:833 Web::CSS::ComputedProperties::align_items.
pub func css_computed_properties_align_items(this: CssComputedProperties*) -> css_data.AlignItems:
    let value = css_computed_properties_property(this, css_data.PropertyId.align_items)
    return css_data.keyword_to_align_items(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:839 Web::CSS::ComputedProperties::align_self.
pub func css_computed_properties_align_self(this: CssComputedProperties*) -> css_data.AlignSelf:
    let value = css_computed_properties_property(this, css_data.PropertyId.align_self)
    return css_data.keyword_to_align_self(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:845 Web::CSS::ComputedProperties::appearance.
pub func css_computed_properties_appearance(this: CssComputedProperties*) -> css_data.Appearance:
    let value = css_computed_properties_property(this, css_data.PropertyId.appearance)
    var appearance = css_data.keyword_to_appearance(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")
    match appearance:
        # Note: All these compatibility values can be treated as 'auto'
        .searchfield, .textarea, .push_button, .slider_horizontal, .checkbox, .radio, .square_button, .menulist, .listbox, .meter, .progress_bar, .button:
            appearance = css_data.Appearance.auto
        # NB: <compat-special> values behave like auto but can also have an effect. Preserve them.
        .textfield, .menulist_button:
            _ = appearance
        _:
            _ = appearance
    return appearance

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:875 Web::CSS::ComputedProperties::backdrop_filter.
pub func css_computed_properties_backdrop_filter(this: CssComputedProperties*) -> CssFilter:
    let value = css_computed_properties_property(this, css_data.PropertyId.backdrop_filter)
    if css_style_value_is_filter_value_list(value):
        var filter: CssFilter = ---
        css_filter_construct(&filter, css_style_value_as_filter_value_list(value).css_style_value())
        return filter
    return css_filter_make_none()

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:883 Web::CSS::ComputedProperties::filter.
pub func css_computed_properties_filter(this: CssComputedProperties*) -> CssFilter:
    let value = css_computed_properties_property(this, css_data.PropertyId.filter)
    if css_style_value_is_filter_value_list(value):
        var filter: CssFilter = ---
        css_filter_construct(&filter, css_style_value_as_filter_value_list(value).css_style_value())
        return filter
    return css_filter_make_none()

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:891 Web::CSS::ComputedProperties::position.
pub func css_computed_properties_position(this: CssComputedProperties*) -> css_data.Positioning:
    let value = css_computed_properties_property(this, css_data.PropertyId.position)
    return css_data.keyword_to_positioning(css_style_value_to_keyword(value)) else trap("VERIFY: Optional::release_value()")