Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / css / property_name_and_id.lucb

#==============================================================================================
#
#   property_name_and_id - PropertyNameAndID: a property's name with its PropertyID
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/PropertyNameAndID.h (lines 1-61). `m_name` is `mutable` in C++:
#       name() caches the name on a const object, so it casts the const away to store it.
#
#       Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:18 Web::CSS::PropertyNameAndID::from_name.
pub func css_property_name_and_id_from_name(name: ak.FlyString) -> CssPropertyNameAndId?:
    let name_view = ak.fly_string_bytes_as_string_view(&name)
    if css_data.is_a_custom_property_name_string(name_view):
        return css_property_name_and_id_new(name, css_data.PropertyId.custom)
    if let property_id = css_data.property_id_from_string(name_view):
        return css_property_name_and_id_new(css_data.string_from_property_id(property_id), property_id)
    return none

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:29 Web::CSS::PropertyNameAndID::from_id.
pub func css_property_name_and_id_from_id(property_id: css_data.PropertyId) -> CssPropertyNameAndId:
    assert(property_id != css_data.PropertyId.custom)
    return css_property_name_and_id_new(none, property_id)

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:35 Web::CSS::PropertyNameAndID::is_custom_property.
pub func css_property_name_and_id_is_custom_property(this: const CssPropertyNameAndId*) -> bool:
    return this.m_property_id == css_data.PropertyId.custom

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:36 Web::CSS::PropertyNameAndID::id.
pub func css_property_name_and_id_id(this: const CssPropertyNameAndId*) -> css_data.PropertyId:
    return this.m_property_id

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:38 Web::CSS::PropertyNameAndID::name.
pub func css_property_name_and_id_name(this: const CssPropertyNameAndId*) -> ak.FlyString:
    if this.m_name == none:
        let mutable_this = (CssPropertyNameAndId*)this
        mutable_this.m_name = css_data.string_from_property_id(this.m_property_id)
    return this.m_name else trap("VERIFY: a name")

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:45 Web::CSS::PropertyNameAndID::to_string.
pub func css_property_name_and_id_to_string(this: const CssPropertyNameAndId*) -> ak.String:
    let name = css_property_name_and_id_name(this)
    return css_syntax.serialize_an_identifier_string_view(ak.fly_string_bytes_as_string_view(&name))

## Ported from Libraries/LibWeb/CSS/PropertyNameAndID.h:51 Web::CSS::PropertyNameAndID::PropertyNameAndID.
pub func css_property_name_and_id_construct(this: CssPropertyNameAndId*, name: ak.FlyString?, id: css_data.PropertyId):
    this.m_name = name
    this.m_property_id = id

## `PropertyNameAndID(name, id)` as a value.
func css_property_name_and_id_new(name: ak.FlyString?, id: css_data.PropertyId) -> CssPropertyNameAndId:
    var result: CssPropertyNameAndId = ---
    css_property_name_and_id_construct(&result, name, id)
    return result