2021-03-22 13:41:47 -03:00
/*
2021-04-28 17:46:44 -03:00
* Copyright ( c ) 2020 - 2021 , the SerenityOS developers .
2024-08-16 12:42:16 -03:00
* Copyright ( c ) 2021 - 2024 , Sam Atkins < sam @ ladybird . org >
2021-03-22 13:41:47 -03:00
*
2021-04-22 05:24:48 -03:00
* SPDX - License - Identifier : BSD - 2 - Clause
2021-03-22 13:41:47 -03:00
*/
# pragma once
2022-04-27 07:04:16 -03:00
# include <AK/Error.h>
2021-07-12 13:30:40 -03:00
# include <AK/RefPtr.h>
2021-03-22 13:41:47 -03:00
# include <AK/Vector.h>
2023-12-09 19:30:01 -03:00
# include <LibGfx/Font/UnicodeRange.h>
2021-10-08 11:54:16 -03:00
# include <LibWeb/CSS/CSSStyleDeclaration.h>
2024-08-14 07:10:54 -03:00
# include <LibWeb/CSS/CSSStyleValue.h>
2021-11-22 14:27:09 -03:00
# include <LibWeb/CSS/GeneralEnclosed.h>
2021-09-29 08:56:37 -03:00
# include <LibWeb/CSS/MediaQuery.h>
2024-05-07 12:18:37 -03:00
# include <LibWeb/CSS/ParsedFontFace.h>
2022-03-31 07:43:07 -03:00
# include <LibWeb/CSS/Parser/ComponentValue.h>
2023-08-17 11:43:30 -03:00
# include <LibWeb/CSS/Parser/Dimension.h>
2023-08-17 11:47:00 -03:00
# include <LibWeb/CSS/Parser/ParsingContext.h>
2022-09-27 12:05:57 -03:00
# include <LibWeb/CSS/Parser/TokenStream.h>
2021-03-22 13:41:47 -03:00
# include <LibWeb/CSS/Parser/Tokenizer.h>
2024-10-11 07:17:10 -03:00
# include <LibWeb/CSS/Parser/Types.h>
2023-03-25 11:11:11 -03:00
# include <LibWeb/CSS/PropertyID.h>
2022-03-06 10:48:32 -03:00
# include <LibWeb/CSS/Ratio.h>
2021-03-22 13:41:47 -03:00
# include <LibWeb/CSS/Selector.h>
2023-03-24 13:42:50 -03:00
# include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
2024-09-18 13:27:47 -03:00
# include <LibWeb/CSS/StyleValues/CSSMathValue.h>
2021-10-08 11:54:16 -03:00
# include <LibWeb/CSS/Supports.h>
2022-04-12 07:32:18 -03:00
# include <LibWeb/Forward.h>
2021-03-22 13:41:47 -03:00
2022-04-12 08:00:07 -03:00
namespace Web : : CSS : : Parser {
2021-03-22 13:41:47 -03:00
2023-09-04 07:16:49 -03:00
class PropertyDependencyNode ;
2021-03-22 13:41:47 -03:00
class Parser {
public :
2024-07-26 11:20:26 -03:00
static Parser create ( ParsingContext const & , StringView input , StringView encoding = " utf-8 " sv ) ;
2023-03-06 14:17:08 -03:00
Parser ( Parser & & ) ;
2021-03-22 13:41:47 -03:00
2024-03-18 00:22:27 -03:00
CSSStyleSheet * parse_as_css_stylesheet ( Optional < URL : : URL > location ) ;
2022-08-07 11:21:26 -03:00
ElementInlineCSSStyleDeclaration * parse_as_style_attribute ( DOM : : Element & ) ;
2022-08-07 10:46:44 -03:00
CSSRule * parse_as_css_rule ( ) ;
2022-03-30 08:05:16 -03:00
Optional < StyleProperty > parse_as_supports_condition ( ) ;
2022-03-28 12:37:54 -03:00
2022-03-17 12:14:01 -03:00
enum class SelectorParsingMode {
Standard ,
// `<forgiving-selector-list>` and `<forgiving-relative-selector-list>`
// are handled with this parameter, not as separate functions.
// https://drafts.csswg.org/selectors/#forgiving-selector
Forgiving
} ;
2021-07-03 08:34:25 -03:00
// Contrary to the name, these parse a comma-separated list of selectors, according to the spec.
2022-03-17 12:14:01 -03:00
Optional < SelectorList > parse_as_selector ( SelectorParsingMode = SelectorParsingMode : : Standard ) ;
Optional < SelectorList > parse_as_relative_selector ( SelectorParsingMode = SelectorParsingMode : : Standard ) ;
2021-07-30 13:06:48 -03:00
2024-08-06 08:44:43 -03:00
Optional < Selector : : PseudoElement > parse_as_pseudo_element_selector ( ) ;
2023-03-06 10:17:01 -03:00
Vector < NonnullRefPtr < MediaQuery > > parse_as_media_query_list ( ) ;
2021-09-29 08:56:37 -03:00
RefPtr < MediaQuery > parse_as_media_query ( ) ;
2021-10-08 11:54:16 -03:00
RefPtr < Supports > parse_as_supports ( ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_as_css_value ( PropertyID ) ;
2021-07-30 13:48:23 -03:00
2023-09-04 08:57:12 -03:00
Optional < ComponentValue > parse_as_component_value ( ) ;
2024-05-13 15:02:38 -03:00
Vector < ParsedFontFace : : Source > parse_as_font_face_src ( ) ;
2024-11-22 08:01:42 -03:00
Vector < ComponentValue > parse_as_list_of_component_values ( ) ;
2024-08-14 07:10:54 -03:00
static NonnullRefPtr < CSSStyleValue > resolve_unresolved_style_value ( ParsingContext const & , DOM : : Element & , Optional < CSS : : Selector : : PseudoElement : : Type > , PropertyID , UnresolvedStyleValue const & ) ;
2021-12-03 09:32:12 -03:00
2024-09-11 12:41:18 -03:00
[ [ nodiscard ] ] LengthOrCalculated parse_as_sizes_attribute ( DOM : : Element const & element , HTML : : HTMLImageElement const * img = nullptr ) ;
2023-05-11 11:56:01 -03:00
2021-07-30 13:06:48 -03:00
private :
2023-03-06 14:17:08 -03:00
Parser ( ParsingContext const & , Vector < Token > ) ;
2022-04-27 07:04:16 -03:00
enum class ParseError {
2021-09-12 13:47:58 -03:00
IncludesIgnoredVendorPrefix ,
2023-05-02 09:03:51 -03:00
InternalError ,
2021-09-12 13:42:11 -03:00
SyntaxError ,
} ;
2022-04-27 07:04:16 -03:00
template < typename T >
using ParseErrorOr = ErrorOr < T , ParseError > ;
2021-09-12 13:42:11 -03:00
2022-03-29 10:13:39 -03:00
// "Parse a stylesheet" is intended to be the normal parser entry point, for parsing stylesheets.
struct ParsedStyleSheet {
2024-03-18 00:22:27 -03:00
Optional < URL : : URL > location ;
2024-10-11 07:17:10 -03:00
Vector < Rule > rules ;
2022-03-29 10:13:39 -03:00
} ;
2021-07-30 13:06:48 -03:00
template < typename T >
2024-03-18 00:22:27 -03:00
ParsedStyleSheet parse_a_stylesheet ( TokenStream < T > & , Optional < URL : : URL > location ) ;
2022-03-29 10:13:39 -03:00
2024-10-11 07:17:10 -03:00
// "Parse a stylesheet’ s contents" is intended for use by the CSSStyleSheet replace() method, and similar, which parse text into the contents of an existing stylesheet.
2021-07-30 13:06:48 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Vector < Rule > parse_a_stylesheets_contents ( TokenStream < T > & ) ;
// "Parse a block’ s contents" is intended for parsing the contents of any block in CSS (including things like the style attribute),
// and APIs such as the CSSStyleDeclaration cssText attribute.
template < typename T >
Vector < RuleOrListOfDeclarations > parse_a_blocks_contents ( TokenStream < T > & ) ;
2022-03-30 07:48:54 -03:00
// "Parse a rule" is intended for use by the CSSStyleSheet#insertRule method, and similar functions which might exist, which parse text into a single rule.
2021-07-30 13:06:48 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Optional < Rule > parse_a_rule ( TokenStream < T > & ) ;
2022-03-30 07:48:54 -03:00
2022-03-30 08:05:16 -03:00
// "Parse a declaration" is used in @supports conditions. [CSS3-CONDITIONAL]
2021-07-30 13:06:48 -03:00
template < typename T >
2022-03-31 10:36:12 -03:00
Optional < Declaration > parse_a_declaration ( TokenStream < T > & ) ;
2022-03-30 08:23:07 -03:00
2022-03-30 08:32:42 -03:00
// "Parse a component value" is for things that need to consume a single value, like the parsing rules for attr().
2021-07-30 13:06:48 -03:00
template < typename T >
2022-03-31 07:43:07 -03:00
Optional < ComponentValue > parse_a_component_value ( TokenStream < T > & ) ;
2022-03-30 08:39:36 -03:00
2024-10-11 07:17:10 -03:00
// "Parse a list of component values" is for the contents of presentational attributes, which parse text into a single declaration’ s value,
// or for parsing a stand-alone selector [SELECT] or list of Media Queries [MEDIAQ], as in Selectors API or the media HTML attribute.
2021-07-30 13:06:48 -03:00
template < typename T >
2022-03-31 07:43:07 -03:00
Vector < ComponentValue > parse_a_list_of_component_values ( TokenStream < T > & ) ;
2022-03-30 08:39:36 -03:00
2021-07-30 13:06:48 -03:00
template < typename T >
2022-03-31 07:43:07 -03:00
Vector < Vector < ComponentValue > > parse_a_comma_separated_list_of_component_values ( TokenStream < T > & ) ;
2022-03-17 16:29:40 -03:00
enum class SelectorType {
Standalone ,
Relative
} ;
2021-07-03 11:40:06 -03:00
template < typename T >
2022-04-27 07:04:16 -03:00
ParseErrorOr < SelectorList > parse_a_selector_list ( TokenStream < T > & , SelectorType , SelectorParsingMode = SelectorParsingMode : : Standard ) ;
2022-03-17 16:29:40 -03:00
2021-09-29 08:56:37 -03:00
template < typename T >
2023-03-06 10:17:01 -03:00
Vector < NonnullRefPtr < MediaQuery > > parse_a_media_query_list ( TokenStream < T > & ) ;
2021-10-08 11:54:16 -03:00
template < typename T >
RefPtr < Supports > parse_a_supports ( TokenStream < T > & ) ;
2021-03-22 13:41:47 -03:00
2022-04-27 08:03:42 -03:00
Optional < Selector : : SimpleSelector : : ANPlusBPattern > parse_a_n_plus_b_pattern ( TokenStream < ComponentValue > & ) ;
2021-03-22 13:41:47 -03:00
2024-10-11 07:17:10 -03:00
template < typename T >
[ [ nodiscard ] ] Vector < Rule > consume_a_stylesheets_contents ( TokenStream < T > & ) ;
enum class Nested {
2022-03-29 09:46:16 -03:00
No ,
2024-10-11 07:17:10 -03:00
Yes ,
2022-03-29 09:46:16 -03:00
} ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Optional < AtRule > consume_an_at_rule ( TokenStream < T > & , Nested nested = Nested : : No ) ;
struct InvalidRuleError { } ;
template < typename T >
Variant < Empty , QualifiedRule , InvalidRuleError > consume_a_qualified_rule ( TokenStream < T > & , Optional < Token : : Type > stop_token = { } , Nested = Nested : : No ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Vector < RuleOrListOfDeclarations > consume_a_block ( TokenStream < T > & ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Vector < RuleOrListOfDeclarations > consume_a_blocks_contents ( TokenStream < T > & ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Optional < Declaration > consume_a_declaration ( TokenStream < T > & , Nested = Nested : : No ) ;
2022-03-30 12:44:13 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
void consume_the_remnants_of_a_bad_declaration ( TokenStream < T > & , Nested ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
[ [ nodiscard ] ] Vector < ComponentValue > consume_a_list_of_component_values ( TokenStream < T > & , Optional < Token : : Type > stop_token = { } , Nested = Nested : : No ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2022-03-31 07:43:07 -03:00
[ [ nodiscard ] ] ComponentValue consume_a_component_value ( TokenStream < T > & ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
SimpleBlock consume_a_simple_block ( TokenStream < T > & ) ;
2021-07-03 11:40:06 -03:00
template < typename T >
2024-10-11 07:17:10 -03:00
Function consume_a_function ( TokenStream < T > & ) ;
// TODO: consume_a_unicode_range_value()
2021-03-22 13:41:47 -03:00
2022-03-31 07:43:07 -03:00
Optional < GeneralEnclosed > parse_general_enclosed ( TokenStream < ComponentValue > & ) ;
2021-10-08 11:54:16 -03:00
2024-05-13 15:02:38 -03:00
template < typename T >
Vector < ParsedFontFace : : Source > parse_font_face_src ( TokenStream < T > & ) ;
2022-03-28 16:32:28 -03:00
2024-09-03 09:18:18 -03:00
enum class AllowBlankLayerName {
No ,
Yes ,
} ;
Optional < FlyString > parse_layer_name ( TokenStream < ComponentValue > & , AllowBlankLayerName ) ;
2024-11-01 11:46:35 -03:00
bool is_valid_in_the_current_context ( Declaration const & ) const ;
bool is_valid_in_the_current_context ( AtRule const & ) const ;
bool is_valid_in_the_current_context ( QualifiedRule const & ) const ;
2024-11-14 12:01:23 -03:00
GC : : Ptr < CSSRule > convert_to_rule ( Rule const & , Nested ) ;
GC : : Ptr < CSSStyleRule > convert_to_style_rule ( QualifiedRule const & , Nested ) ;
GC : : Ptr < CSSFontFaceRule > convert_to_font_face_rule ( AtRule const & ) ;
GC : : Ptr < CSSKeyframesRule > convert_to_keyframes_rule ( AtRule const & ) ;
GC : : Ptr < CSSImportRule > convert_to_import_rule ( AtRule const & ) ;
GC : : Ptr < CSSRule > convert_to_layer_rule ( AtRule const & , Nested ) ;
GC : : Ptr < CSSMediaRule > convert_to_media_rule ( AtRule const & , Nested ) ;
GC : : Ptr < CSSNamespaceRule > convert_to_namespace_rule ( AtRule const & ) ;
GC : : Ptr < CSSSupportsRule > convert_to_supports_rule ( AtRule const & , Nested ) ;
GC : : Ptr < CSSPropertyRule > convert_to_property_rule ( AtRule const & rule ) ;
2024-10-11 07:17:10 -03:00
PropertyOwningCSSStyleDeclaration * convert_to_style_declaration ( Vector < Declaration > const & ) ;
2022-03-31 10:36:12 -03:00
Optional < StyleProperty > convert_to_style_property ( Declaration const & ) ;
2021-07-09 12:34:29 -03:00
2022-03-31 07:43:07 -03:00
Optional < Dimension > parse_dimension ( ComponentValue const & ) ;
2023-12-28 09:43:38 -03:00
Optional < AngleOrCalculated > parse_angle ( TokenStream < ComponentValue > & ) ;
Optional < AnglePercentage > parse_angle_percentage ( TokenStream < ComponentValue > & ) ;
Optional < FlexOrCalculated > parse_flex ( TokenStream < ComponentValue > & ) ;
Optional < FrequencyOrCalculated > parse_frequency ( TokenStream < ComponentValue > & ) ;
Optional < FrequencyPercentage > parse_frequency_percentage ( TokenStream < ComponentValue > & ) ;
Optional < IntegerOrCalculated > parse_integer ( TokenStream < ComponentValue > & ) ;
Optional < LengthOrCalculated > parse_length ( TokenStream < ComponentValue > & ) ;
Optional < LengthPercentage > parse_length_percentage ( TokenStream < ComponentValue > & ) ;
Optional < NumberOrCalculated > parse_number ( TokenStream < ComponentValue > & ) ;
2024-10-30 22:29:03 -03:00
Optional < NumberPercentage > parse_number_percentage ( TokenStream < ComponentValue > & ) ;
2023-12-28 09:43:38 -03:00
Optional < ResolutionOrCalculated > parse_resolution ( TokenStream < ComponentValue > & ) ;
Optional < TimeOrCalculated > parse_time ( TokenStream < ComponentValue > & ) ;
Optional < TimePercentage > parse_time_percentage ( TokenStream < ComponentValue > & ) ;
2023-12-30 14:06:14 -03:00
Optional < LengthOrCalculated > parse_source_size_value ( TokenStream < ComponentValue > & ) ;
2022-03-31 07:43:07 -03:00
Optional < Ratio > parse_ratio ( TokenStream < ComponentValue > & ) ;
2023-12-09 19:30:01 -03:00
Optional < Gfx : : UnicodeRange > parse_unicode_range ( TokenStream < ComponentValue > & ) ;
Optional < Gfx : : UnicodeRange > parse_unicode_range ( StringView ) ;
2024-05-09 17:02:52 -03:00
Vector < Gfx : : UnicodeRange > parse_unicode_ranges ( TokenStream < ComponentValue > & ) ;
2022-10-30 09:27:57 -03:00
Optional < GridSize > parse_grid_size ( ComponentValue const & ) ;
2024-07-22 17:49:52 -03:00
Optional < GridFitContent > parse_fit_content ( Vector < ComponentValue > const & ) ;
2022-10-30 09:27:57 -03:00
Optional < GridMinMax > parse_min_max ( Vector < ComponentValue > const & ) ;
Optional < GridRepeat > parse_repeat ( Vector < ComponentValue > const & ) ;
Optional < ExplicitGridTrack > parse_track_sizing_function ( ComponentValue const & ) ;
2021-10-29 09:38:50 -03:00
2024-08-09 09:36:11 -03:00
Optional < URL : : URL > parse_url_function ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_url_value ( TokenStream < ComponentValue > & ) ;
2022-03-31 07:43:07 -03:00
2024-10-26 21:58:52 -03:00
Optional < ShapeRadius > parse_shape_radius ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_basic_shape_value ( TokenStream < ComponentValue > & ) ;
2024-05-25 20:20:09 -03:00
2023-12-27 08:48:36 -03:00
template < typename TElement >
Optional < Vector < TElement > > parse_color_stop_list ( TokenStream < ComponentValue > & tokens , auto is_position , auto get_position ) ;
2022-11-08 17:33:00 -03:00
Optional < Vector < LinearColorStopListElement > > parse_linear_color_stop_list ( TokenStream < ComponentValue > & ) ;
Optional < Vector < AngularColorStopListElement > > parse_angular_color_stop_list ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_linear_gradient_function ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_conic_gradient_function ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_radial_gradient_function ( TokenStream < ComponentValue > & ) ;
2022-07-11 20:15:05 -03:00
2024-10-14 12:23:35 -03:00
ParseErrorOr < NonnullRefPtr < CSSStyleValue > > parse_css_value ( PropertyID , TokenStream < ComponentValue > & , Optional < String > original_source_text = { } ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_css_value_for_property ( PropertyID , TokenStream < ComponentValue > & ) ;
2023-05-17 13:23:42 -03:00
struct PropertyAndValue {
PropertyID property ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > style_value ;
2023-05-17 13:23:42 -03:00
} ;
2023-08-19 11:26:57 -03:00
Optional < PropertyAndValue > parse_css_value_for_properties ( ReadonlySpan < PropertyID > , TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_builtin_value ( TokenStream < ComponentValue > & ) ;
2024-09-18 13:27:47 -03:00
RefPtr < CSSMathValue > parse_calculated_value ( ComponentValue const & ) ;
2024-07-26 12:03:01 -03:00
RefPtr < CustomIdentStyleValue > parse_custom_ident_value ( TokenStream < ComponentValue > & , std : : initializer_list < StringView > blacklist ) ;
2023-07-13 10:59:31 -03:00
// NOTE: Implemented in generated code. (GenerateCSSMathFunctions.cpp)
2023-08-19 11:20:23 -03:00
OwnPtr < CalculationNode > parse_math_function ( PropertyID , Function const & ) ;
2023-08-19 10:48:27 -03:00
OwnPtr < CalculationNode > parse_a_calc_function_node ( Function const & ) ;
2024-08-14 10:06:03 -03:00
RefPtr < CSSStyleValue > parse_keyword_value ( TokenStream < ComponentValue > & ) ;
2024-11-03 07:46:05 -03:00
RefPtr < CSSStyleValue > parse_hue_none_value ( TokenStream < ComponentValue > & ) ;
2024-08-16 12:42:16 -03:00
RefPtr < CSSStyleValue > parse_solidus_and_alpha_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_rgb_color_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_hsl_color_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_hwb_color_value ( TokenStream < ComponentValue > & ) ;
2024-10-26 16:42:03 -03:00
Optional < Array < RefPtr < CSSStyleValue > , 4 > > parse_lab_like_color_value ( TokenStream < ComponentValue > & , StringView ) ;
LibGfx+LibWeb/CSS: Add support for the `lab()` color function
The support in LibWeb is quite easy as the previous commits introduced
helpers to support lab-like colors.
Now for the methods in Color:
- The formulas in `from_lab()` are derived from the CIEXYZ to CIELAB
formulas the "Colorimetry" paper published by the CIE.
- The conversion in `from_xyz50()` can be decomposed in multiple steps
XYZ D50 -> XYZ D65 -> Linear sRGB -> sRGB. The two first conversion
are done with a singular matrix operation. This matrix was generated
with a Python script [1].
This commit makes us pass all the `css/css-color/lab-00*.html` WPT
tests (0 to 7 at the time of writing).
[1] Python script used to generate the XYZ D50 -> Linear sRGB
conversion:
```python
import numpy as np
# http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
# First let's convert from D50 to D65 using the Bradford method.
m_a = np.array([
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
])
# D50
chromaticities_source = np.array([0.96422, 1, 0.82521])
# D65
chromaticities_destination = np.array([0.9505, 1, 1.0890])
cone_response_source = m_a @ chromaticities_source
cone_response_destination = m_a @ chromaticities_destination
cone_response_ratio = cone_response_destination / cone_response_source
m = np.linalg.inv(m_a) @ np.diagflat(cone_response_ratio) @ m_a
D50_to_D65 = m
# https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
# Then, the matrix to convert to linear sRGB.
xyz_65_to_srgb = np.array([
[3.2406, - 1.5372, - 0.4986],
[-0.9689, + 1.8758, 0.0415],
[0.0557, - 0.2040, 1.0570]
])
# Finally, let's retrieve the final transformation.
xyz_50_to_srgb = xyz_65_to_srgb @ D50_to_D65
print(xyz_50_to_srgb)
```
2024-10-26 18:16:13 -03:00
RefPtr < CSSStyleValue > parse_lab_color_value ( TokenStream < ComponentValue > & ) ;
2024-08-16 12:42:16 -03:00
RefPtr < CSSStyleValue > parse_oklab_color_value ( TokenStream < ComponentValue > & ) ;
2024-10-27 20:49:25 -03:00
Optional < Array < RefPtr < CSSStyleValue > , 4 > > parse_lch_like_color_value ( TokenStream < ComponentValue > & , StringView ) ;
2024-10-27 21:19:10 -03:00
RefPtr < CSSStyleValue > parse_lch_color_value ( TokenStream < ComponentValue > & ) ;
2024-08-16 12:42:16 -03:00
RefPtr < CSSStyleValue > parse_oklch_color_value ( TokenStream < ComponentValue > & ) ;
2024-10-27 01:42:13 -03:00
RefPtr < CSSStyleValue > parse_color_function ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_color_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_counter_value ( TokenStream < ComponentValue > & ) ;
2024-07-24 11:47:11 -03:00
enum class AllowReversed {
No ,
Yes ,
} ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_counter_definitions_value ( TokenStream < ComponentValue > & , AllowReversed , i32 default_value_if_not_reversed ) ;
RefPtr < CSSStyleValue > parse_rect_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_ratio_value ( TokenStream < ComponentValue > & ) ;
2024-09-30 10:10:27 -03:00
RefPtr < StringStyleValue > parse_string_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_image_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_paint_value ( TokenStream < ComponentValue > & ) ;
2023-11-20 12:33:21 -03:00
enum class PositionParsingMode {
Normal ,
BackgroundPosition ,
} ;
RefPtr < PositionStyleValue > parse_position_value ( TokenStream < ComponentValue > & , PositionParsingMode = PositionParsingMode : : Normal ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_filter_value_list_value ( TokenStream < ComponentValue > & ) ;
2024-09-30 10:38:17 -03:00
RefPtr < StringStyleValue > parse_opentype_tag_value ( TokenStream < ComponentValue > & ) ;
2023-12-07 12:16:51 -03:00
2024-08-16 05:41:10 -03:00
RefPtr < CSSStyleValue > parse_dimension_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_angle_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_angle_percentage_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_flex_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_frequency_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_frequency_percentage_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_integer_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_length_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_length_percentage_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_number_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_number_percentage_value ( TokenStream < ComponentValue > & tokens ) ;
2024-11-03 07:46:05 -03:00
RefPtr < CSSStyleValue > parse_number_percentage_none_value ( TokenStream < ComponentValue > & tokens ) ;
2024-08-16 05:41:10 -03:00
RefPtr < CSSStyleValue > parse_percentage_value ( TokenStream < ComponentValue > & tokens ) ;
RefPtr < CSSStyleValue > parse_resolution_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_time_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_time_percentage_value ( TokenStream < ComponentValue > & ) ;
2021-11-08 14:19:55 -03:00
template < typename ParseFunction >
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_comma_separated_value_list ( TokenStream < ComponentValue > & , ParseFunction ) ;
RefPtr < CSSStyleValue > parse_simple_comma_separated_value_list ( PropertyID , TokenStream < ComponentValue > & ) ;
2024-09-30 11:17:01 -03:00
RefPtr < CSSStyleValue > parse_all_as_single_keyword_value ( TokenStream < ComponentValue > & , Keyword ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_aspect_ratio_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_background_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_single_background_position_x_or_y_value ( TokenStream < ComponentValue > & , PropertyID ) ;
RefPtr < CSSStyleValue > parse_single_background_repeat_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_single_background_size_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_border_value ( PropertyID , TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_border_radius_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_border_radius_shorthand_value ( TokenStream < ComponentValue > & ) ;
2024-08-21 12:09:08 -03:00
RefPtr < CSSStyleValue > parse_columns_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_content_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_counter_increment_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_counter_reset_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_counter_set_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_display_value ( TokenStream < ComponentValue > & ) ;
2024-08-16 05:41:10 -03:00
RefPtr < CSSStyleValue > parse_flex_shorthand_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_flex_flow_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_font_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_font_family_value ( TokenStream < ComponentValue > & ) ;
2024-09-27 13:11:05 -03:00
RefPtr < CSSStyleValue > parse_font_language_override_value ( TokenStream < ComponentValue > & ) ;
2024-10-01 05:37:43 -03:00
RefPtr < CSSStyleValue > parse_font_feature_settings_value ( TokenStream < ComponentValue > & ) ;
2024-10-01 05:20:06 -03:00
RefPtr < CSSStyleValue > parse_font_variation_settings_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_list_style_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_math_depth_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_overflow_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_place_content_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_place_items_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_place_self_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_quotes_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_scrollbar_gutter_value ( TokenStream < ComponentValue > & ) ;
2022-03-23 13:59:44 -03:00
enum class AllowInsetKeyword {
No ,
Yes ,
} ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_shadow_value ( TokenStream < ComponentValue > & , AllowInsetKeyword ) ;
RefPtr < CSSStyleValue > parse_single_shadow_value ( TokenStream < ComponentValue > & , AllowInsetKeyword ) ;
RefPtr < CSSStyleValue > parse_text_decoration_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_text_decoration_line_value ( TokenStream < ComponentValue > & ) ;
2024-10-16 03:50:35 -03:00
RefPtr < CSSStyleValue > parse_rotate_value ( TokenStream < ComponentValue > & ) ;
2024-11-20 21:23:10 -03:00
RefPtr < CSSStyleValue > parse_stroke_dasharray_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_easing_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_transform_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_transform_origin_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_transition_value ( TokenStream < ComponentValue > & ) ;
2024-11-22 12:42:20 -03:00
RefPtr < CSSStyleValue > parse_translate_value ( TokenStream < ComponentValue > & ) ;
2024-11-22 14:07:16 -03:00
RefPtr < CSSStyleValue > parse_scale_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_grid_track_size_list ( TokenStream < ComponentValue > & , bool allow_separate_line_name_blocks = false ) ;
RefPtr < CSSStyleValue > parse_grid_auto_track_sizes ( TokenStream < ComponentValue > & ) ;
2023-12-07 14:42:43 -03:00
RefPtr < GridAutoFlowStyleValue > parse_grid_auto_flow_value ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_grid_track_size_list_shorthand_value ( PropertyID , TokenStream < ComponentValue > & ) ;
2024-08-28 11:47:30 -03:00
RefPtr < GridTrackPlacementStyleValue > parse_grid_track_placement ( TokenStream < ComponentValue > & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSSStyleValue > parse_grid_track_placement_shorthand_value ( PropertyID , TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_grid_template_areas_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_grid_area_shorthand_value ( TokenStream < ComponentValue > & ) ;
RefPtr < CSSStyleValue > parse_grid_shorthand_value ( TokenStream < ComponentValue > & ) ;
2021-07-14 12:20:06 -03:00
2023-08-19 11:20:23 -03:00
OwnPtr < CalculationNode > parse_a_calculation ( Vector < ComponentValue > const & ) ;
2022-03-31 07:43:07 -03:00
2022-04-27 07:04:16 -03:00
ParseErrorOr < NonnullRefPtr < Selector > > parse_complex_selector ( TokenStream < ComponentValue > & , SelectorType ) ;
ParseErrorOr < Optional < Selector : : CompoundSelector > > parse_compound_selector ( TokenStream < ComponentValue > & ) ;
2022-03-31 07:43:07 -03:00
Optional < Selector : : Combinator > parse_selector_combinator ( TokenStream < ComponentValue > & ) ;
2023-08-07 12:48:44 -03:00
enum class AllowWildcardName {
No ,
Yes ,
} ;
Optional < Selector : : SimpleSelector : : QualifiedName > parse_selector_qualified_name ( TokenStream < ComponentValue > & , AllowWildcardName ) ;
2022-04-27 07:04:16 -03:00
ParseErrorOr < Selector : : SimpleSelector > parse_attribute_simple_selector ( ComponentValue const & ) ;
ParseErrorOr < Selector : : SimpleSelector > parse_pseudo_simple_selector ( TokenStream < ComponentValue > & ) ;
ParseErrorOr < Optional < Selector : : SimpleSelector > > parse_simple_selector ( TokenStream < ComponentValue > & ) ;
2022-03-31 07:43:07 -03:00
NonnullRefPtr < MediaQuery > parse_media_query ( TokenStream < ComponentValue > & ) ;
OwnPtr < MediaCondition > parse_media_condition ( TokenStream < ComponentValue > & , MediaCondition : : AllowOr allow_or ) ;
Optional < MediaFeature > parse_media_feature ( TokenStream < ComponentValue > & ) ;
Optional < MediaQuery : : MediaType > parse_media_type ( TokenStream < ComponentValue > & ) ;
OwnPtr < MediaCondition > parse_media_in_parens ( TokenStream < ComponentValue > & ) ;
Optional < MediaFeatureValue > parse_media_feature_value ( MediaFeatureID , TokenStream < ComponentValue > & ) ;
OwnPtr < Supports : : Condition > parse_supports_condition ( TokenStream < ComponentValue > & ) ;
Optional < Supports : : InParens > parse_supports_in_parens ( TokenStream < ComponentValue > & ) ;
Optional < Supports : : Feature > parse_supports_feature ( TokenStream < ComponentValue > & ) ;
2021-10-08 11:54:16 -03:00
2024-08-14 07:10:54 -03:00
NonnullRefPtr < CSSStyleValue > resolve_unresolved_style_value ( DOM : : Element & , Optional < Selector : : PseudoElement : : Type > , PropertyID , UnresolvedStyleValue const & ) ;
2024-03-15 16:32:45 -03:00
bool expand_variables ( DOM : : Element & , Optional < Selector : : PseudoElement : : Type > , FlyString const & property_name , HashMap < FlyString , NonnullRefPtr < PropertyDependencyNode > > & dependencies , TokenStream < ComponentValue > & source , Vector < ComponentValue > & dest ) ;
bool expand_unresolved_values ( DOM : : Element & , FlyString const & property_name , TokenStream < ComponentValue > & source , Vector < ComponentValue > & dest ) ;
bool substitute_attr_function ( DOM : : Element & element , FlyString const & property_name , Function const & attr_function , Vector < ComponentValue > & dest ) ;
2023-09-04 07:16:49 -03:00
2021-11-10 20:55:02 -03:00
static bool has_ignored_vendor_prefix ( StringView ) ;
2024-10-31 13:03:06 -03:00
static bool is_generic_font_family ( Keyword ) ;
2021-09-12 12:49:09 -03:00
2022-03-29 11:01:38 -03:00
struct PropertiesAndCustomProperties {
Vector < StyleProperty > properties ;
2023-11-05 00:19:16 -03:00
HashMap < FlyString , StyleProperty > custom_properties ;
2022-03-29 11:01:38 -03:00
} ;
2024-10-11 07:17:10 -03:00
PropertiesAndCustomProperties extract_properties ( Vector < RuleOrListOfDeclarations > const & ) ;
void extract_property ( Declaration const & , Parser : : PropertiesAndCustomProperties & ) ;
2022-03-29 11:01:38 -03:00
2021-07-02 16:25:13 -03:00
ParsingContext m_context ;
2021-03-22 13:41:47 -03:00
Vector < Token > m_tokens ;
2021-07-03 10:00:41 -03:00
TokenStream < Token > m_token_stream ;
2024-11-01 11:46:35 -03:00
enum class ContextType {
Unknown ,
Style ,
AtMedia ,
AtFontFace ,
AtKeyframes ,
Keyframe ,
AtSupports ,
SupportsCondition ,
AtLayer ,
AtProperty ,
} ;
static ContextType context_type_for_at_rule ( FlyString const & ) ;
Vector < ContextType > m_rule_context ;
2024-11-14 09:18:10 -03:00
Vector < PseudoClass > m_pseudo_class_context ; // Stack of pseudo-class functions we're currently inside
2021-03-22 13:41:47 -03:00
} ;
}
2021-07-30 13:48:23 -03:00
namespace Web {
2024-03-18 00:22:27 -03:00
CSS : : CSSStyleSheet * parse_css_stylesheet ( CSS : : Parser : : ParsingContext const & , StringView , Optional < URL : : URL > location = { } ) ;
2022-08-07 11:21:26 -03:00
CSS : : ElementInlineCSSStyleDeclaration * parse_css_style_attribute ( CSS : : Parser : : ParsingContext const & , StringView , DOM : : Element & ) ;
2024-08-14 07:10:54 -03:00
RefPtr < CSS : : CSSStyleValue > parse_css_value ( CSS : : Parser : : ParsingContext const & , StringView , CSS : : PropertyID property_id = CSS : : PropertyID : : Invalid ) ;
2022-04-12 08:00:07 -03:00
Optional < CSS : : SelectorList > parse_selector ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2024-11-08 14:50:38 -03:00
Optional < CSS : : SelectorList > parse_selector_for_nested_style_rule ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2024-08-06 08:44:43 -03:00
Optional < CSS : : Selector : : PseudoElement > parse_pseudo_element_selector ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2022-08-07 10:46:44 -03:00
CSS : : CSSRule * parse_css_rule ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2022-04-12 08:00:07 -03:00
RefPtr < CSS : : MediaQuery > parse_media_query ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2023-03-06 10:17:01 -03:00
Vector < NonnullRefPtr < CSS : : MediaQuery > > parse_media_query_list ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2022-04-12 08:00:07 -03:00
RefPtr < CSS : : Supports > parse_css_supports ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2023-03-06 11:46:21 -03:00
Optional < CSS : : StyleProperty > parse_css_supports_condition ( CSS : : Parser : : ParsingContext const & , StringView ) ;
2021-07-30 13:48:23 -03:00
}