/*
 * Copyright (c) 2026-present, the Ladybird developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

/* Generated with cbindgen:0.29.2 */

#include <stdint.h>
#include <stddef.h>

namespace Web {
namespace CSS {
namespace StyleValueFFI {

/// A strong reference to a C++ StyleValue held from Rust-owned value data.
///
/// Nested values still point at the C++ shell objects; dropping the Rust allocation releases
/// the reference. Once the shells are collapsed into a single handle type these become
/// references between Rust allocations instead.
struct RetainedStyleValue {
    const void *pointer;
};

/// A retained polygon point: the x and y style values.
struct RetainedShapePoint {
    RetainedStyleValue x;
    RetainedStyleValue y;
};

/// A Rust-owned array of retained polygon points.
struct RetainedShapePointList {
    RetainedShapePoint *pointer;
    size_t length;
};

/// A retained AK::Utf16FlyString, stored as its one-word raw representation. Owns one reference
/// to the underlying string data unless it is a short string, which needs none; the C++ bridge
/// handles both cases.
struct RetainedUtf16FlyString {
    size_t raw;
};

/// A strong reference to a C++ CalculationNode held from Rust-owned value data. The node tree
/// is still C++-structured during the migration, like retained style values.
struct RetainedCalculationNode {
    const void *pointer;
};

/// A Rust-owned array of bytes, used for lists of C++ u8 enum values.
struct RetainedByteList {
    uint8_t *pointer;
    size_t length;
};

/// An accepted numeric range for one value type (the C++ `enum class ValueType : u8`, opaque
/// to Rust).
struct RetainedNumericRangeByType {
    uint8_t value_type;
    double min;
    double max;
};

/// A Rust-owned array of accepted numeric ranges.
struct RetainedNumericRangeList {
    RetainedNumericRangeByType *pointer;
    size_t length;
};

/// The shared leading fields of every color variant payload: the optional color type and the
/// color syntax. Placing this first in each color payload lets C++ read it without knowing
/// which color variant it has.
struct ColorBase {
    bool has_color_type;
    uint8_t color_type;
    uint8_t color_syntax;
};

/// A Rust-owned array of retained AK::Utf16FlyString values.
struct RetainedUtf16FlyStringList {
    RetainedUtf16FlyString *pointer;
    size_t length;
};

/// A retained gradient color stop: an optional transition hint, then an optional color,
/// position and second position (each null when absent). The layout matches the C++
/// ColorStopListElement, which is four reference pointers, so C++ views these in place.
struct RetainedColorStop {
    RetainedStyleValue transition_hint;
    RetainedStyleValue color;
    RetainedStyleValue position;
    RetainedStyleValue second_position;
};

/// A Rust-owned array of retained gradient color stops.
struct RetainedColorStopList {
    RetainedColorStop *pointer;
    size_t length;
};

/// A retained AK::String, stored as its one-word raw representation. Owns one reference to the
/// underlying string data unless it is a short string; the C++ bridge handles both cases.
struct RetainedString {
    size_t raw;
};

/// A retained CSS request URL modifier: the modifier type and either an enum value or a retained
/// string value (raw 0 when the value is an enum). All enums are C++ `enum class ... : u8`
/// values, opaque to Rust.
struct RetainedRequestUrlModifier {
    uint8_t modifier_type;
    uint8_t enum_value;
    RetainedUtf16FlyString string_value;
};

/// A Rust-owned array of retained request URL modifiers.
struct RetainedRequestUrlModifierList {
    RetainedRequestUrlModifier *pointer;
    size_t length;
};

/// A retained image-set() option: the image, its resolution and an optional type string (a
/// retained AK::Utf16String raw, 0 when absent, released through the same bridge as fly
/// strings).
struct RetainedImageSetOption {
    RetainedStyleValue image;
    RetainedStyleValue resolution;
    bool has_type;
    RetainedUtf16FlyString type_string;
};

/// A Rust-owned array of retained image-set() options.
struct RetainedImageSetOptionList {
    RetainedImageSetOption *pointer;
    size_t length;
};

/// A retained linear() easing stop: the output value and an optional input (null when absent).
struct RetainedLinearEasingStop {
    RetainedStyleValue output;
    RetainedStyleValue input;
};

/// A Rust-owned array of retained linear() easing stops.
struct RetainedLinearEasingStopList {
    RetainedLinearEasingStop *pointer;
    size_t length;
};

/// A retained, Rust-owned grid track list entry (see [`GridTrackEntryInput`] for the kinds).
struct RetainedGridTrackEntry {
    uint8_t kind;
    RetainedUtf16FlyStringList names;
    RetainedStyleValue size_value;
    RetainedStyleValue min_value;
    RetainedStyleValue max_value;
    uint8_t repeat_type;
    RetainedStyleValue repeat_count;
    bool repeat_is_subgrid;
    bool repeat_preserve_line_name_sets;
    RetainedGridTrackEntry *repeat_entries_pointer;
    size_t repeat_entries_length;
};

/// A Rust-owned array of retained grid track list entries.
struct RetainedGridTrackEntryList {
    RetainedGridTrackEntry *pointer;
    size_t length;
};

/// A retained named grid area: the retained area name and its grid line indices.
struct RetainedGridArea {
    RetainedUtf16FlyString name;
    size_t row_start;
    size_t row_end;
    size_t column_start;
    size_t column_end;
};

/// A Rust-owned array of retained named grid areas.
struct RetainedGridAreaList {
    RetainedGridArea *pointer;
    size_t length;
};

/// A retained counter definition: the counter name, the reversed flag and an optional retained
/// value (null when absent).
struct RetainedCounterDefinition {
    RetainedUtf16FlyString name;
    bool is_reversed;
    RetainedStyleValue value;
};

/// A Rust-owned array of retained counter definitions.
struct RetainedCounterDefinitionList {
    RetainedCounterDefinition *pointer;
    size_t length;
};

/// A retained, Rust-owned array of style value references.
struct RetainedStyleValueList {
    RetainedStyleValue *pointer;
    size_t length;
};

/// A Rust-owned array of C++ PropertyID values (`enum class PropertyID : u16`, opaque to Rust).
struct RetainedPropertyIdList {
    uint16_t *pointer;
    size_t length;
};

/// The data of a single immutable CSS style value.
///
/// Variant payload fields are read directly by the corresponding C++ StyleValue subclass, so
/// changing a payload changes the C++ accessors reading it.
struct StyleValueData {
    enum class Tag : uint8_t {
        /// A CSS keyword. The value is the generated C++ `enum class Keyword : u16`, opaque to Rust.
        Keyword,
        /// A CSS `<number>`.
        Number,
        /// A CSS `<integer>`.
        Integer,
        /// A CSS `<angle>`. The unit is the C++ `enum class AngleUnit : u8`, opaque to Rust.
        Angle,
        /// A CSS `<flex>`. The unit is the C++ `enum class FlexUnit : u8`, opaque to Rust.
        Flex,
        /// A CSS `<frequency>`. The unit is the C++ `enum class FrequencyUnit : u8`, opaque to Rust.
        Frequency,
        /// A CSS `<length>`. The unit is the C++ `enum class LengthUnit : u8`, opaque to Rust.
        Length,
        /// A CSS `<percentage>`.
        Percentage,
        /// A CSS `<resolution>`. The unit is the C++ `enum class ResolutionUnit : u8`, opaque to Rust.
        Resolution,
        /// A CSS `<time>`. The unit is the C++ `enum class TimeUnit : u8`, opaque to Rust.
        Time,
        /// A basic shape. Kinds: inset (0), xywh (1) and rect (2) use five retained value slots;
        /// circle (3) and ellipse (4) use two; polygon (5) uses the fill rule and points; path (6)
        /// uses the fill rule and the retained serialized path data string.
        BasicShape,
        /// A calc() or other math function: the retained calculation node tree root, the resolved
        /// numeric type as its raw bytes (a trivially copyable C++ NumericType, opaque to Rust)
        /// and the parse-time calculation context.
        Calculated,
        /// A CSS `<ratio>`, e.g. `16 / 9`. The numerator and denominator are style values.
        Ratio,
        /// A unicode-range, e.g. `U+0025-00FF`.
        UnicodeRange,
        /// A CSS `<opacity-value>`: a number, percentage or calculated style value.
        OpacityValue,
        /// One edge of a CSS `<position>`: an optional edge keyword (the C++ `enum class
        /// PositionEdge : u8`, opaque to Rust) and an optional offset style value (null when absent).
        Edge,
        /// The guaranteed-invalid value: https://drafts.csswg.org/css-variables/#guaranteed-invalid-value
        GuaranteedInvalid,
        /// An absent optional value in a shorthand.
        EmptyOptional,
        /// grid-auto-flow.
        GridAutoFlow,
        /// text-underline-position. Both fields are C++ `enum class ... : u8` values, opaque to Rust.
        TextUnderlinePosition,
        /// contrast-color() with its retained color style value.
        ContrastColor,
        /// superellipse() with its retained parameter style value.
        Superellipse,
        /// A pending-substitution value retaining the shorthand value it came from.
        PendingSubstitution,
        /// scrollbar-color with retained thumb and track color values.
        ScrollbarColor,
        /// rect() with four retained edge style values.
        Rect,
        /// A CSS `<string>`.
        String,
        /// An unrecognized CSS function, kept as its name and argument value.
        Function,
        /// An OpenType tag with its value, from font-feature-settings or font-variation-settings.
        /// The mode is the C++ OpenTypeTaggedStyleValue::Mode, opaque to Rust.
        OpenTypeTagged,
        /// font-style: a keyword (the C++ `enum class FontStyleKeyword : u8`, opaque to Rust) and
        /// an optional oblique angle style value (null when absent).
        FontStyle,
        /// text-indent: a length-percentage style value plus the hanging and each-line flags.
        TextIndent,
        /// overflow-clip-margin: an optional visual box (the C++ `enum class BackgroundBox : u8`,
        /// opaque to Rust) and an offset style value.
        OverflowClipMargin,
        /// sibling-count() or sibling-index(). Both fields are C++ `enum class ... : u8` values,
        /// opaque to Rust.
        TreeCountingFunction,
        /// background-size with its two retained size style values.
        BackgroundSize,
        /// A background repeat-style. Both fields are the C++ `enum class Repetition : u8`, opaque
        /// to Rust.
        RepeatStyle,
        /// border-image-slice: four retained offset style values and the fill keyword.
        BorderImageSlice,
        /// anchor-size(): an optional anchor name, an optional size keyword (the C++ `enum class
        /// AnchorSize : u8`, opaque to Rust) and an optional retained fallback value.
        AnchorSize,
        /// anchor(): an optional anchor name, the retained side style value and an optional
        /// retained fallback value.
        Anchor,
        /// A CSS `<position>` with its two retained edge style values.
        Position,
        /// A shadow. The type and placement are C++ enums, opaque to Rust; the color, blur radius
        /// and spread distance are optional retained style values (null when absent).
        Shadow,
        /// content with its retained content list and optional alt-text list (null when absent).
        Content,
        /// A @counter-style system descriptor: a plain system keyword (kind 0, the C++ `enum class
        /// CounterStyleSystem : u8`, opaque to Rust), fixed with an optional retained first symbol
        /// (kind 1), or extends with a retained counter style name (kind 2).
        CounterStyleSystem,
        /// A counter style reference: either a retained counter style name, or a symbols() function
        /// with its type (the C++ `enum class SymbolsType : u8`, opaque to Rust) and retained
        /// symbol strings.
        CounterStyle,
        /// A color function such as rgb() or oklch(): three retained channel values, an optional
        /// retained alpha, an optional name and an optional retained origin color for relative
        /// color syntax.
        ColorFunction,
        /// color-mix() with its optional retained interpolation method value and two components,
        /// each a retained color with an optional retained percentage.
        ColorMix,
        /// The shared data of every color style value: an optional color type and the color syntax
        /// (both C++ enums on ColorStyleValue, opaque to Rust).
        /// linear-gradient(): a direction (either a retained angle value or a side-or-corner
        /// keyword), the retained color stops, the gradient type, the repeating flag, an optional
        /// retained interpolation method and the color syntax. Enums are C++ types, opaque to Rust.
        LinearGradient,
        /// conic-gradient(): an optional retained from-angle, the retained position, the retained
        /// color stops, the repeating flag, an optional retained interpolation method and the color
        /// syntax (a C++ enum, opaque to Rust).
        ConicGradient,
        /// radial-gradient(): the ending shape (a C++ enum, opaque to Rust), the retained size and
        /// position values, the retained color stops, the repeating flag, an optional retained
        /// interpolation method and the color syntax.
        RadialGradient,
        /// A url() image. Only the CSS URL is immutable value data; the style sheet attachment and
        /// loading state stay on the C++ side.
        Image,
        /// image-set() with its retained options.
        ImageSet,
        /// An easing function: linear() with its retained stops (kind 0), cubic-bezier() with four
        /// retained control values (kind 1), or steps() with a retained interval count and a step
        /// position (kind 2, the C++ `enum class StepPosition : u8`, opaque to Rust).
        Easing,
        /// A cursor with its retained image value and optional retained hotspot coordinates (both
        /// null or both non-null).
        Cursor,
        /// A grid track size list: the subgrid and preserve-line-name-sets flags and the retained
        /// track entries.
        GridTrackSizeList,
        /// grid-template-areas with its retained named areas and the row and column counts.
        GridTemplateArea,
        /// counter-increment, counter-reset or counter-set with its retained counter definitions.
        CounterDefinitions,
        /// A grid-row/grid-column placement: auto (0), a span (1) or an area/line (2), with an
        /// optional retained line value and an optional retained name.
        GridTrackPlacement,
        /// counter() or counters(). The function is the C++ CounterFunction enum, opaque to Rust;
        /// the join string is empty for counter().
        Counter,
        /// light-dark() with its two retained color style values.
        LightDark,
        /// random-value-sharing: an optional retained fixed value (null when absent), the auto flag,
        /// an optional name and the element-shared flag.
        RandomValueSharing,
        /// scrollbar-gutter. The value is the C++ `enum class ScrollbarGutter : u8`, opaque to Rust.
        ScrollbarGutter,
        /// A color interpolation method: either a rectangular color space, or a polar color space
        /// with a hue interpolation method. All fields are C++ `enum class ... : u8` values, opaque
        /// to Rust.
        ColorInterpolationMethod,
        /// A list of style values. The separator and collapsible flag come from the C++
        /// StyleValueList enums, opaque to Rust.
        ValueList,
        /// A tuple of optional style values (null entries represent absent optionals).
        Tuple,
        /// A display value: the raw bytes of the C++ Display value type (a tag plus a union of
        /// packed u8 enums), opaque to Rust.
        Display,
        /// color-scheme with its retained scheme names and the only keyword flag.
        ColorScheme,
        /// An unresolved value containing arbitrary substitution functions, kept as its retained
        /// source text, an optional normalized comparison text (empty when absent), the presence
        /// flags of each substitution function and the attr-taint flag.
        Unresolved,
        /// A CSS url() or src() with its retained URL string, type (the C++ URL::Type, opaque to
        /// Rust) and request URL modifiers.
        Url,
        /// A @font-face source: either local() with a retained family name value, or a URL (encoded
        /// as in [`StyleValueData::Url`]) with an optional format string and a list of font
        /// technologies (C++ `enum class FontTech : u8`, opaque to Rust).
        FontSource,
        /// A radial gradient size: one or two components, each either a RadialExtent keyword (the
        /// C++ `enum class RadialExtent : u8`, opaque to Rust) or a retained style value.
        RadialSize,
        /// A transform function with its argument values. The property (PropertyID : u16) and
        /// function are C++ enums, opaque to Rust.
        Transformation,
        /// A shorthand property value: the shorthand id, its longhand ids (both C++
        /// `enum class PropertyID : u16`, opaque to Rust) and their values.
        Shorthand,
        /// A CSS `<custom-ident>`.
        CustomIdent,
        /// A border-radius rect of four retained corner radius style values.
        BorderRadiusRect,
        /// A single corner radius: the horizontal and vertical radii and whether they differ.
        BorderRadius,
        /// A filter function. Kinds: blur (0, value = radius), drop-shadow (1, value = shadow),
        /// hue-rotate (2, value = angle), color (3, value = amount, with the color operation).
        /// The kind and the color operation are C++ enum values, opaque to Rust.
        Filter,
    };

    struct Keyword_Body {
        uint16_t keyword;
    };

    struct Number_Body {
        double value;
    };

    struct Integer_Body {
        int32_t value;
    };

    struct Angle_Body {
        double value;
        uint8_t unit;
    };

    struct Flex_Body {
        double value;
        uint8_t unit;
    };

    struct Frequency_Body {
        double value;
        uint8_t unit;
    };

    struct Length_Body {
        double value;
        uint8_t unit;
    };

    struct Percentage_Body {
        double value;
    };

    struct Resolution_Body {
        double value;
        uint8_t unit;
    };

    struct Time_Body {
        double value;
        uint8_t unit;
    };

    struct BasicShape_Body {
        uint8_t kind;
        RetainedStyleValue v0;
        RetainedStyleValue v1;
        RetainedStyleValue v2;
        RetainedStyleValue v3;
        RetainedStyleValue v4;
        uint8_t fill_rule;
        RetainedShapePointList points;
        RetainedUtf16FlyString path_string;
    };

    struct Calculated_Body {
        RetainedCalculationNode calculation;
        RetainedByteList resolved_type;
        bool has_percentages_resolve_as;
        uint8_t percentages_resolve_as;
        bool resolve_numbers_as_integers;
        RetainedNumericRangeList accepted_ranges;
    };

    struct Ratio_Body {
        RetainedStyleValue numerator;
        RetainedStyleValue denominator;
    };

    struct UnicodeRange_Body {
        uint32_t min_code_point;
        uint32_t max_code_point;
    };

    struct OpacityValue_Body {
        RetainedStyleValue value;
    };

    struct Edge_Body {
        bool has_edge;
        uint8_t edge;
        RetainedStyleValue offset;
    };

    struct GridAutoFlow_Body {
        bool row;
        bool dense;
    };

    struct TextUnderlinePosition_Body {
        uint8_t horizontal;
        uint8_t vertical;
    };

    struct ContrastColor_Body {
        ColorBase color_base;
        RetainedStyleValue color;
    };

    struct Superellipse_Body {
        RetainedStyleValue parameter;
    };

    struct PendingSubstitution_Body {
        RetainedStyleValue original_shorthand_value;
    };

    struct ScrollbarColor_Body {
        RetainedStyleValue thumb_color;
        RetainedStyleValue track_color;
    };

    struct Rect_Body {
        RetainedStyleValue top;
        RetainedStyleValue right;
        RetainedStyleValue bottom;
        RetainedStyleValue left;
    };

    struct String_Body {
        RetainedUtf16FlyString string;
    };

    struct Function_Body {
        RetainedUtf16FlyString name;
        RetainedStyleValue value;
    };

    struct OpenTypeTagged_Body {
        uint8_t mode;
        RetainedUtf16FlyString tag;
        RetainedStyleValue value;
    };

    struct FontStyle_Body {
        uint8_t font_style;
        RetainedStyleValue angle_value;
    };

    struct TextIndent_Body {
        RetainedStyleValue length_percentage;
        bool hanging;
        bool each_line;
    };

    struct OverflowClipMargin_Body {
        bool has_visual_box;
        uint8_t visual_box;
        RetainedStyleValue offset;
    };

    struct TreeCountingFunction_Body {
        uint8_t function;
        uint8_t computed_type;
    };

    struct BackgroundSize_Body {
        RetainedStyleValue size_x;
        RetainedStyleValue size_y;
    };

    struct RepeatStyle_Body {
        uint8_t repeat_x;
        uint8_t repeat_y;
    };

    struct BorderImageSlice_Body {
        RetainedStyleValue top;
        RetainedStyleValue right;
        RetainedStyleValue bottom;
        RetainedStyleValue left;
        bool fill;
    };

    struct AnchorSize_Body {
        bool has_anchor_name;
        RetainedUtf16FlyString anchor_name;
        bool has_anchor_size;
        uint8_t anchor_size;
        RetainedStyleValue fallback_value;
    };

    struct Anchor_Body {
        bool has_anchor_name;
        RetainedUtf16FlyString anchor_name;
        RetainedStyleValue anchor_side;
        RetainedStyleValue fallback_value;
    };

    struct Position_Body {
        RetainedStyleValue edge_x;
        RetainedStyleValue edge_y;
    };

    struct Shadow_Body {
        uint8_t shadow_type;
        RetainedStyleValue color;
        RetainedStyleValue offset_x;
        RetainedStyleValue offset_y;
        RetainedStyleValue blur_radius;
        RetainedStyleValue spread_distance;
        uint8_t placement;
    };

    struct Content_Body {
        RetainedStyleValue content;
        RetainedStyleValue alt_text;
    };

    struct CounterStyleSystem_Body {
        uint8_t kind;
        uint8_t system;
        RetainedStyleValue first_symbol;
        RetainedUtf16FlyString name;
    };

    struct CounterStyle_Body {
        bool is_symbols;
        RetainedUtf16FlyString name;
        uint8_t symbols_type;
        RetainedUtf16FlyStringList symbols;
    };

    struct ColorFunction_Body {
        ColorBase color_base;
        RetainedStyleValue channel_0;
        RetainedStyleValue channel_1;
        RetainedStyleValue channel_2;
        RetainedStyleValue alpha;
        bool has_name;
        RetainedUtf16FlyString name;
        RetainedStyleValue origin_color;
    };

    struct ColorMix_Body {
        ColorBase color_base;
        RetainedStyleValue color_interpolation_method;
        RetainedStyleValue first_color;
        RetainedStyleValue first_percentage;
        RetainedStyleValue second_color;
        RetainedStyleValue second_percentage;
    };

    struct LinearGradient_Body {
        bool has_direction_value;
        RetainedStyleValue direction_value;
        uint8_t side_or_corner;
        RetainedColorStopList color_stop_list;
        uint8_t gradient_type;
        bool repeating;
        RetainedStyleValue color_interpolation_method;
        uint8_t color_syntax;
    };

    struct ConicGradient_Body {
        RetainedStyleValue from_angle;
        RetainedStyleValue position;
        RetainedColorStopList color_stop_list;
        bool repeating;
        RetainedStyleValue color_interpolation_method;
        uint8_t color_syntax;
    };

    struct RadialGradient_Body {
        uint8_t ending_shape;
        RetainedStyleValue size;
        RetainedStyleValue position;
        RetainedColorStopList color_stop_list;
        bool repeating;
        RetainedStyleValue color_interpolation_method;
        uint8_t color_syntax;
    };

    struct Image_Body {
        RetainedString url;
        uint8_t url_type;
        RetainedRequestUrlModifierList url_modifiers;
    };

    struct ImageSet_Body {
        RetainedImageSetOptionList options;
    };

    struct Easing_Body {
        uint8_t kind;
        RetainedLinearEasingStopList linear_stops;
        RetainedStyleValue x1;
        RetainedStyleValue y1;
        RetainedStyleValue x2;
        RetainedStyleValue y2;
        RetainedStyleValue number_of_intervals;
        uint8_t step_position;
    };

    struct Cursor_Body {
        RetainedStyleValue image;
        RetainedStyleValue x;
        RetainedStyleValue y;
    };

    struct GridTrackSizeList_Body {
        bool is_subgrid;
        bool preserve_line_name_sets;
        RetainedGridTrackEntryList entries;
    };

    struct GridTemplateArea_Body {
        RetainedGridAreaList grid_areas;
        size_t row_count;
        size_t column_count;
    };

    struct CounterDefinitions_Body {
        RetainedCounterDefinitionList counter_definitions;
    };

    struct GridTrackPlacement_Body {
        uint8_t kind;
        RetainedStyleValue value;
        bool has_name;
        RetainedUtf16FlyString name;
    };

    struct Counter_Body {
        uint8_t function;
        RetainedUtf16FlyString counter_name;
        RetainedStyleValue counter_style;
        RetainedUtf16FlyString join_string;
    };

    struct LightDark_Body {
        ColorBase color_base;
        RetainedStyleValue light;
        RetainedStyleValue dark;
    };

    struct RandomValueSharing_Body {
        RetainedStyleValue fixed_value;
        bool is_auto;
        bool has_name;
        RetainedUtf16FlyString name;
        bool element_shared;
    };

    struct ScrollbarGutter_Body {
        uint8_t value;
    };

    struct ColorInterpolationMethod_Body {
        bool is_polar;
        uint8_t color_space;
        uint8_t hue_interpolation_method;
    };

    struct ValueList_Body {
        RetainedStyleValueList values;
        uint8_t separator;
        bool collapsible;
    };

    struct Tuple_Body {
        RetainedStyleValueList values;
    };

    struct Display_Body {
        uint32_t raw;
    };

    struct ColorScheme_Body {
        RetainedUtf16FlyStringList schemes;
        bool only;
    };

    struct Unresolved_Body {
        RetainedString source_text;
        RetainedString value_comparison_text;
        bool presence_attr;
        bool presence_env;
        bool presence_if;
        bool presence_inherit;
        bool presence_var;
        bool contains_attr_tainted_values;
    };

    struct Url_Body {
        RetainedString url;
        uint8_t url_type;
        RetainedRequestUrlModifierList modifiers;
    };

    struct FontSource_Body {
        bool is_local;
        RetainedStyleValue local_name;
        RetainedString url;
        uint8_t url_type;
        RetainedRequestUrlModifierList url_modifiers;
        bool has_format;
        RetainedUtf16FlyString format;
        RetainedByteList tech;
    };

    struct RadialSize_Body {
        uint8_t component_count;
        bool is_extent_0;
        uint8_t extent_0;
        RetainedStyleValue value_0;
        bool is_extent_1;
        uint8_t extent_1;
        RetainedStyleValue value_1;
    };

    struct Transformation_Body {
        uint16_t property;
        uint8_t transform_function;
        RetainedStyleValueList values;
    };

    struct Shorthand_Body {
        uint16_t shorthand_property;
        RetainedPropertyIdList sub_properties;
        RetainedStyleValueList values;
    };

    struct CustomIdent_Body {
        RetainedUtf16FlyString custom_ident;
    };

    struct BorderRadiusRect_Body {
        RetainedStyleValue top_left;
        RetainedStyleValue top_right;
        RetainedStyleValue bottom_right;
        RetainedStyleValue bottom_left;
    };

    struct BorderRadius_Body {
        bool is_elliptical;
        RetainedStyleValue horizontal_radius;
        RetainedStyleValue vertical_radius;
    };

    struct Filter_Body {
        uint8_t kind;
        uint8_t color_operation;
        RetainedStyleValue value;
    };

    Tag tag;
    union {
        Keyword_Body keyword;
        Number_Body number;
        Integer_Body integer;
        Angle_Body angle;
        Flex_Body flex;
        Frequency_Body frequency;
        Length_Body length;
        Percentage_Body percentage;
        Resolution_Body resolution;
        Time_Body time;
        BasicShape_Body basic_shape;
        Calculated_Body calculated;
        Ratio_Body ratio;
        UnicodeRange_Body unicode_range;
        OpacityValue_Body opacity_value;
        Edge_Body edge;
        GridAutoFlow_Body grid_auto_flow;
        TextUnderlinePosition_Body text_underline_position;
        ContrastColor_Body contrast_color;
        Superellipse_Body superellipse;
        PendingSubstitution_Body pending_substitution;
        ScrollbarColor_Body scrollbar_color;
        Rect_Body rect;
        String_Body string;
        Function_Body function;
        OpenTypeTagged_Body open_type_tagged;
        FontStyle_Body font_style;
        TextIndent_Body text_indent;
        OverflowClipMargin_Body overflow_clip_margin;
        TreeCountingFunction_Body tree_counting_function;
        BackgroundSize_Body background_size;
        RepeatStyle_Body repeat_style;
        BorderImageSlice_Body border_image_slice;
        AnchorSize_Body anchor_size;
        Anchor_Body anchor;
        Position_Body position;
        Shadow_Body shadow;
        Content_Body content;
        CounterStyleSystem_Body counter_style_system;
        CounterStyle_Body counter_style;
        ColorFunction_Body color_function;
        ColorMix_Body color_mix;
        LinearGradient_Body linear_gradient;
        ConicGradient_Body conic_gradient;
        RadialGradient_Body radial_gradient;
        Image_Body image;
        ImageSet_Body image_set;
        Easing_Body easing;
        Cursor_Body cursor;
        GridTrackSizeList_Body grid_track_size_list;
        GridTemplateArea_Body grid_template_area;
        CounterDefinitions_Body counter_definitions;
        GridTrackPlacement_Body grid_track_placement;
        Counter_Body counter;
        LightDark_Body light_dark;
        RandomValueSharing_Body random_value_sharing;
        ScrollbarGutter_Body scrollbar_gutter;
        ColorInterpolationMethod_Body color_interpolation_method;
        ValueList_Body value_list;
        Tuple_Body tuple;
        Display_Body display;
        ColorScheme_Body color_scheme;
        Unresolved_Body unresolved;
        Url_Body url;
        FontSource_Body font_source;
        RadialSize_Body radial_size;
        Transformation_Body transformation;
        Shorthand_Body shorthand;
        CustomIdent_Body custom_ident;
        BorderRadiusRect_Body border_radius_rect;
        BorderRadius_Body border_radius;
        Filter_Body filter;
    };
};

/// Borrowed input description of one grid track list entry, used when creating a grid track
/// size list. Kinds: 0 = line names, 1 = a single size, 2 = minmax, 3 = repeat with a nested
/// entry list.
struct GridTrackEntryInput {
    uint8_t kind;
    const size_t *names;
    size_t name_count;
    const void *size_value;
    const void *min_value;
    const void *max_value;
    uint8_t repeat_type;
    const void *repeat_count;
    bool repeat_is_subgrid;
    bool repeat_preserve_line_name_sets;
    const GridTrackEntryInput *repeat_entries;
    size_t repeat_entry_count;
};

extern "C" {

extern void ladybird_style_value_unref(const void *style_value);

extern void ladybird_utf16_fly_string_unref(size_t raw);

extern void ladybird_string_unref(size_t raw);

extern void ladybird_calculation_node_unref(const void *node);

StyleValueData *rust_style_value_create_keyword(uint16_t keyword);

StyleValueData *rust_style_value_create_number(double value);

StyleValueData *rust_style_value_create_integer(int32_t value);

StyleValueData *rust_style_value_create_angle(double value, uint8_t unit);

StyleValueData *rust_style_value_create_flex(double value, uint8_t unit);

StyleValueData *rust_style_value_create_frequency(double value, uint8_t unit);

StyleValueData *rust_style_value_create_length(double value, uint8_t unit);

StyleValueData *rust_style_value_create_percentage(double value);

StyleValueData *rust_style_value_create_resolution(double value, uint8_t unit);

StyleValueData *rust_style_value_create_time(double value, uint8_t unit);

/// Takes ownership of one strong reference to each of the numerator and denominator.
StyleValueData *rust_style_value_create_ratio(const void *numerator, const void *denominator);

StyleValueData *rust_style_value_create_unicode_range(uint32_t min_code_point, uint32_t max_code_point);

/// Takes ownership of one strong reference to the value.
StyleValueData *rust_style_value_create_opacity_value(const void *value);

/// Takes ownership of one strong reference to the offset if it is non-null.
StyleValueData *rust_style_value_create_edge(bool has_edge, uint8_t edge, const void *offset);

StyleValueData *rust_style_value_create_guaranteed_invalid();

StyleValueData *rust_style_value_create_empty_optional();

StyleValueData *rust_style_value_create_grid_auto_flow(bool row, bool dense);

StyleValueData *rust_style_value_create_text_underline_position(uint8_t horizontal, uint8_t vertical);

/// Takes ownership of one strong reference to the color.
StyleValueData *rust_style_value_create_contrast_color(bool has_color_type,
                                                       uint8_t color_type,
                                                       uint8_t color_syntax,
                                                       const void *color);

/// Takes ownership of one strong reference to the parameter.
StyleValueData *rust_style_value_create_superellipse(const void *parameter);

/// Takes ownership of one strong reference to the original shorthand value.
StyleValueData *rust_style_value_create_pending_substitution(const void *original_shorthand_value);

/// Takes ownership of one strong reference to each color.
StyleValueData *rust_style_value_create_scrollbar_color(const void *thumb_color, const void *track_color);

/// Takes ownership of one strong reference to each edge.
StyleValueData *rust_style_value_create_rect(const void *top, const void *right, const void *bottom, const void *left);

/// Takes ownership of one strong reference to the filter's value.
StyleValueData *rust_style_value_create_filter(uint8_t kind, uint8_t color_operation, const void *value);

/// Takes ownership of one strong reference to each radius.
StyleValueData *rust_style_value_create_border_radius(bool is_elliptical,
                                                      const void *horizontal_radius,
                                                      const void *vertical_radius);

/// Takes ownership of one strong reference to each corner radius.
StyleValueData *rust_style_value_create_border_radius_rect(const void *top_left,
                                                           const void *top_right,
                                                           const void *bottom_right,
                                                           const void *bottom_left);

/// Takes ownership of one leaked reference to the string.
StyleValueData *rust_style_value_create_string(size_t string);

/// Takes ownership of one leaked reference to the string.
StyleValueData *rust_style_value_create_custom_ident(size_t custom_ident);

/// Takes ownership of one leaked reference to the name and one strong reference to the value.
StyleValueData *rust_style_value_create_function(size_t name, const void *value);

/// Takes ownership of one leaked reference to the tag and one strong reference to the value.
StyleValueData *rust_style_value_create_open_type_tagged(uint8_t mode, size_t tag, const void *value);

/// Takes ownership of one strong reference to the angle value if it is non-null.
StyleValueData *rust_style_value_create_font_style(uint8_t font_style, const void *angle_value);

/// Takes ownership of one strong reference to the length-percentage.
StyleValueData *rust_style_value_create_text_indent(const void *length_percentage, bool hanging, bool each_line);

/// Takes ownership of one strong reference to the offset.
StyleValueData *rust_style_value_create_overflow_clip_margin(bool has_visual_box,
                                                             uint8_t visual_box,
                                                             const void *offset);

StyleValueData *rust_style_value_create_tree_counting_function(uint8_t function, uint8_t computed_type);

/// Takes ownership of one strong reference to each size.
StyleValueData *rust_style_value_create_background_size(const void *size_x, const void *size_y);

StyleValueData *rust_style_value_create_repeat_style(uint8_t repeat_x, uint8_t repeat_y);

/// Takes ownership of one strong reference to each offset.
StyleValueData *rust_style_value_create_border_image_slice(const void *top,
                                                           const void *right,
                                                           const void *bottom,
                                                           const void *left,
                                                           bool fill);

/// Takes ownership of one leaked reference to the anchor name (0 when absent) and one strong
/// reference to the fallback value if it is non-null.
StyleValueData *rust_style_value_create_anchor_size(bool has_anchor_name,
                                                    size_t anchor_name,
                                                    bool has_anchor_size,
                                                    uint8_t anchor_size,
                                                    const void *fallback_value);

/// Takes ownership of one leaked reference to the anchor name (0 when absent), one strong
/// reference to the side and one strong reference to the fallback value if it is non-null.
StyleValueData *rust_style_value_create_anchor(bool has_anchor_name,
                                               size_t anchor_name,
                                               const void *anchor_side,
                                               const void *fallback_value);

/// Takes ownership of one strong reference to each edge.
StyleValueData *rust_style_value_create_position(const void *edge_x, const void *edge_y);

/// Takes ownership of one strong reference to each non-null style value.
StyleValueData *rust_style_value_create_shadow(uint8_t shadow_type,
                                               const void *color,
                                               const void *offset_x,
                                               const void *offset_y,
                                               const void *blur_radius,
                                               const void *spread_distance,
                                               uint8_t placement);

/// Takes ownership of one strong reference to the content list and, when non-null, the
/// alt-text list.
StyleValueData *rust_style_value_create_content(const void *content, const void *alt_text);

/// Takes ownership of one leaked reference to each string and one strong reference to the
/// counter style.
StyleValueData *rust_style_value_create_counter(uint8_t function,
                                                size_t counter_name,
                                                const void *counter_style,
                                                size_t join_string);

/// Takes ownership of one strong reference to each color.
StyleValueData *rust_style_value_create_light_dark(bool has_color_type,
                                                   uint8_t color_type,
                                                   uint8_t color_syntax,
                                                   const void *light,
                                                   const void *dark);

/// Takes ownership of one strong reference to the fixed value and one leaked reference to the
/// name when they are present.
StyleValueData *rust_style_value_create_random_value_sharing(const void *fixed_value,
                                                             bool is_auto,
                                                             bool has_name,
                                                             size_t name,
                                                             bool element_shared);

StyleValueData *rust_style_value_create_scrollbar_gutter(uint8_t value);

StyleValueData *rust_style_value_create_color_interpolation_method(bool is_polar,
                                                                   uint8_t color_space,
                                                                   uint8_t hue_interpolation_method);

/// Takes ownership of one strong reference to each of the `length` values.
StyleValueData *rust_style_value_create_value_list(const void *const *values,
                                                   size_t length,
                                                   uint8_t separator,
                                                   bool collapsible);

/// Takes ownership of one strong reference to each non-null value.
StyleValueData *rust_style_value_create_tuple(const void *const *values, size_t length);

/// Takes ownership of one strong reference to each value.
StyleValueData *rust_style_value_create_transformation(uint16_t property,
                                                       uint8_t transform_function,
                                                       const void *const *values,
                                                       size_t length);

/// Takes ownership of one strong reference to each value; the property ids are copied.
StyleValueData *rust_style_value_create_shorthand(uint16_t shorthand_property,
                                                  const uint16_t *sub_properties,
                                                  size_t sub_property_count,
                                                  const void *const *values,
                                                  size_t value_count);

StyleValueData *rust_style_value_create_display(uint32_t raw);

/// Takes ownership of one strong reference to each non-null component value.
StyleValueData *rust_style_value_create_radial_size(uint8_t component_count,
                                                    bool is_extent_0,
                                                    uint8_t extent_0,
                                                    const void *value_0,
                                                    bool is_extent_1,
                                                    uint8_t extent_1,
                                                    const void *value_1);

/// Takes ownership of one leaked reference to the URL string and to each modifier's retained
/// string.
StyleValueData *rust_style_value_create_url(size_t url,
                                            uint8_t url_type,
                                            const RetainedRequestUrlModifier *modifiers,
                                            size_t modifier_count);

/// Takes ownership of one strong reference to the local name if local, or one leaked reference
/// to the URL string and each modifier string otherwise, plus the format string when present.
StyleValueData *rust_style_value_create_font_source(bool is_local,
                                                    const void *local_name,
                                                    size_t url,
                                                    uint8_t url_type,
                                                    const RetainedRequestUrlModifier *url_modifiers,
                                                    size_t url_modifier_count,
                                                    bool has_format,
                                                    size_t format,
                                                    const uint8_t *tech,
                                                    size_t tech_count);

/// Takes ownership of one leaked reference to each scheme name.
StyleValueData *rust_style_value_create_color_scheme(const size_t *schemes, size_t scheme_count, bool only);

/// Takes ownership of one leaked reference to each string.
StyleValueData *rust_style_value_create_unresolved(size_t source_text,
                                                   size_t value_comparison_text,
                                                   bool presence_attr,
                                                   bool presence_env,
                                                   bool presence_if,
                                                   bool presence_inherit,
                                                   bool presence_var,
                                                   bool contains_attr_tainted_values);

/// Takes ownership of the definitions' retained strings and values.
StyleValueData *rust_style_value_create_counter_definitions(const RetainedCounterDefinition *definitions,
                                                            size_t length);

/// Takes ownership of one strong reference to the value and one leaked reference to the name
/// when they are present.
StyleValueData *rust_style_value_create_grid_track_placement(uint8_t kind,
                                                             const void *value,
                                                             bool has_name,
                                                             size_t name);

/// Takes ownership of one strong reference to the first symbol and one leaked reference to the
/// name when they are present.
StyleValueData *rust_style_value_create_counter_style_system(uint8_t kind,
                                                             uint8_t system,
                                                             const void *first_symbol,
                                                             size_t name);

/// Takes ownership of one leaked reference to the name (0 when this is a symbols() function)
/// and to each symbol string.
StyleValueData *rust_style_value_create_counter_style(bool is_symbols,
                                                      size_t name,
                                                      uint8_t symbols_type,
                                                      const size_t *symbols,
                                                      size_t symbol_count);

/// Takes ownership of one strong reference to the image and to each non-null coordinate.
StyleValueData *rust_style_value_create_cursor(const void *image, const void *x, const void *y);

/// Takes ownership of one strong reference to each non-null value and one leaked reference to
/// the name when present.
StyleValueData *rust_style_value_create_color_function(bool has_color_type,
                                                       uint8_t color_type,
                                                       uint8_t color_syntax,
                                                       const void *channel_0,
                                                       const void *channel_1,
                                                       const void *channel_2,
                                                       const void *alpha,
                                                       bool has_name,
                                                       size_t name,
                                                       const void *origin_color);

/// Takes ownership of one strong reference to each non-null value.
StyleValueData *rust_style_value_create_color_mix(bool has_color_type,
                                                  uint8_t color_type,
                                                  uint8_t color_syntax,
                                                  const void *color_interpolation_method,
                                                  const void *first_color,
                                                  const void *first_percentage,
                                                  const void *second_color,
                                                  const void *second_percentage);

/// Takes ownership of the options' retained values and strings.
StyleValueData *rust_style_value_create_image_set(const RetainedImageSetOption *options, size_t length);

/// Takes ownership of one strong reference to each non-null value and of the stops' retained
/// values.
StyleValueData *rust_style_value_create_linear_gradient(bool has_direction_value,
                                                        const void *direction_value,
                                                        uint8_t side_or_corner,
                                                        const RetainedColorStop *stops,
                                                        size_t stop_count,
                                                        uint8_t gradient_type,
                                                        bool repeating,
                                                        const void *color_interpolation_method,
                                                        uint8_t color_syntax);

/// Takes ownership of one strong reference to each non-null value and of the stops' retained
/// values.
StyleValueData *rust_style_value_create_conic_gradient(const void *from_angle,
                                                       const void *position,
                                                       const RetainedColorStop *stops,
                                                       size_t stop_count,
                                                       bool repeating,
                                                       const void *color_interpolation_method,
                                                       uint8_t color_syntax);

/// Takes ownership of one strong reference to each non-null value and of the stops' retained
/// values.
StyleValueData *rust_style_value_create_radial_gradient(uint8_t ending_shape,
                                                        const void *size,
                                                        const void *position,
                                                        const RetainedColorStop *stops,
                                                        size_t stop_count,
                                                        bool repeating,
                                                        const void *color_interpolation_method,
                                                        uint8_t color_syntax);

/// Takes ownership of the areas' retained names.
StyleValueData *rust_style_value_create_grid_template_area(const RetainedGridArea *areas,
                                                           size_t area_count,
                                                           size_t row_count,
                                                           size_t column_count);

/// Takes ownership of one strong reference to each non-null value and of the stops' retained
/// values.
StyleValueData *rust_style_value_create_easing(uint8_t kind,
                                               const RetainedLinearEasingStop *linear_stops,
                                               size_t linear_stop_count,
                                               const void *x1,
                                               const void *y1,
                                               const void *x2,
                                               const void *y2,
                                               const void *number_of_intervals,
                                               uint8_t step_position);

/// Takes ownership of the entries' retained values and names, recursively.
StyleValueData *rust_style_value_create_grid_track_size_list(bool is_subgrid,
                                                             bool preserve_line_name_sets,
                                                             const GridTrackEntryInput *entries,
                                                             size_t entry_count);

/// Takes ownership of one strong reference to each non-null value, of the points' retained
/// values and of one leaked reference to the path string when present.
StyleValueData *rust_style_value_create_basic_shape(uint8_t kind,
                                                    const void *v0,
                                                    const void *v1,
                                                    const void *v2,
                                                    const void *v3,
                                                    const void *v4,
                                                    uint8_t fill_rule,
                                                    const RetainedShapePoint *points,
                                                    size_t point_count,
                                                    size_t path_string);

/// Takes ownership of one strong reference to the calculation node; the byte blob and ranges
/// are copied.
StyleValueData *rust_style_value_create_calculated(const void *calculation,
                                                   const uint8_t *resolved_type,
                                                   size_t resolved_type_length,
                                                   bool has_percentages_resolve_as,
                                                   uint8_t percentages_resolve_as,
                                                   bool resolve_numbers_as_integers,
                                                   const RetainedNumericRangeByType *accepted_ranges,
                                                   size_t accepted_range_count);

/// Takes ownership of one leaked reference to the URL string and each modifier string.
StyleValueData *rust_style_value_create_image(size_t url,
                                              uint8_t url_type,
                                              const RetainedRequestUrlModifier *url_modifiers,
                                              size_t url_modifier_count);

void rust_style_value_destroy(StyleValueData *value);

}  // extern "C"

}  // namespace StyleValueFFI
}  // namespace CSS
}  // namespace Web
