- STRING_LENGTHS =
Set.new(["px", "full", "screen"]).freeze
- ARBITRARY_VALUE_REGEX =
/^\[(?:([a-z-]+):)?(.+)\]$/i
- FRACTION_REGEX =
%r{^\d+/\d+$}
- LENGTH_UNIT_REGEX =
/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/
- TSHIRT_UNIT_REGEX =
/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
- COLOR_FUNCTION_REGEX =
/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/
- SHADOW_REGEX =
Shadow always begins with x and y offset separated by underscore optionally prepended by inset
/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
- IMAGE_REGEX =
/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/
- SIZE_LABELS =
Set.new(["length", "size", "percentage"]).freeze
- IMAGE_LABELS =
Set.new(["image", "url"]).freeze
- IS_LENGTH =
->(value) {
numeric?(value) ||
STRING_LENGTHS.include?(value) ||
FRACTION_REGEX.match?(value)
}
- IS_ARBITRARY_LENGTH =
->(value) {
arbitrary_value?(value, "length", is_length_only)
}
- IS_ARBITRARY_NUMBER =
->(value) {
arbitrary_value?(value, "number", is_number)
}
- IS_NUMBER =
->(value) {
is_number.call(value)
}
- IS_INTEGER =
->(value) {
is_integer_only.call(value)
}
- IS_PERCENT =
->(value) {
value.end_with?("%") && is_number.call(value[0..-2])
}
- IS_ARBITRARY_VALUE =
->(value) {
ARBITRARY_VALUE_REGEX.match(value)
}
- IS_TSHIRT_SIZE =
->(value) {
TSHIRT_UNIT_REGEX.match?(value)
}
- IS_ARBITRARY_SIZE =
->(value) {
arbitrary_value?(value, SIZE_LABELS, is_never)
}
- IS_ARBITRARY_POSITION =
->(value) {
arbitrary_value?(value, "position", is_never)
}
- IS_ARBITRARY_IMAGE =
->(value) {
arbitrary_value?(value, IMAGE_LABELS, is_image)
}
- IS_ARBITRARY_SHADOW =
->(value) {
arbitrary_value?(value, "", is_shadow)
}
- IS_ANY =
->(_) { true }