| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2025-08-11 12:41:57 +01:00
										 |  |  |  |  * Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include <AK/StringView.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/CSS/PropertyID.h>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 12:41:57 +01:00
										 |  |  |  | inline bool is_invalid_custom_property_name_string(StringView string) | 
					
						
							| 
									
										
										
										
											2025-06-25 11:43:14 +01:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     // https://drafts.csswg.org/css-variables-2/#typedef-custom-property-name
 | 
					
						
							|  |  |  |  |     // The <custom-property-name> production corresponds to this: it’s defined as any <dashed-ident>
 | 
					
						
							|  |  |  |  |     // (a valid identifier that starts with two dashes), except -- itself, which is reserved for future use by CSS.
 | 
					
						
							|  |  |  |  |     return string == "--"sv; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  | // https://drafts.css-houdini.org/css-typed-om-1/#custom-property-name-string
 | 
					
						
							| 
									
										
										
										
											2025-08-11 12:41:57 +01:00
										 |  |  |  | inline bool is_a_custom_property_name_string(StringView string) | 
					
						
							| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |     // A string is a custom property name string if it starts with two dashes (U+002D HYPHEN-MINUS), like --foo.
 | 
					
						
							| 
									
										
										
										
											2025-06-25 11:43:14 +01:00
										 |  |  |  |     return string.starts_with("--"sv) && !is_invalid_custom_property_name_string(string); | 
					
						
							| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 12:41:57 +01:00
										 |  |  |  | // https://drafts.css-houdini.org/css-typed-om-1/#valid-css-property
 | 
					
						
							|  |  |  |  | inline bool is_a_valid_css_property(StringView string) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     // A string is a valid CSS property if it is a custom property name string, or is a CSS property name recognized by
 | 
					
						
							|  |  |  |  |     // the user agent.
 | 
					
						
							|  |  |  |  |     return is_a_custom_property_name_string(string) || property_id_from_string(string).has_value(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-09 17:49:30 +01:00
										 |  |  |  | } |