CiderCSSKit is lightweight CSS parser written as a pure Swift package. It was primarily designed to work with CiderKit, but the goal is to make it as agnostic as possible.
CiderCSSKit is still a work-in-progress. So many CSS features are not currenlty supported.
Here's the list of existing and missing features:
- provides easy access to style properties, in bulk or individually
- named colors are already implemented
- built-in functions are limited to
rgb
andrgba
- complex CSS combinators (
>
,+
, and~
) are not implemented - no support pseudo-elements (like
::first-line
for example) - no support for parametric pseudo-classes (like
:nth-child()
for example) - no support for attribute selectors (like
a[target]
ora[target="_blank"]
)
The list of supported attributes is fairly limited for now but will expand over time.
background-color
border-image
and its sub-attributesborder-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
color
font
and its sub-attributesfont-family
font-size
font-stretch
font-style
font-variant
font-weight
line-height
padding
and its sub-attributespadding-bottom
padding-left
padding-right
padding-top
text-align
transform-origin
vertical-align
visibility
z-index
Even if the ultimate goal is to support all syntax features, there is a long road ahead. Below is a list of short-term planned improvements:
- Add support for
hsl()
color function (#12) - Add support for the adjacent sibling combinator (
+
) (#6) - Add support for the child combinator (
>
) (#7) - Add support for the general sibling combinator (
~
) (#8) - Provides basic validation configurations for most common attributes, functions and keywords
The full documentation of the package is available here.
CiderCSSKit is available through Swift Package Manager.
To install it, simply add the dependency to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/chsxf/CiderCSSKit.git", requirement: .branch("main")),
],
targets: [
.target(name: "YourTarget", dependencies: ["CiderCSSKit"]),
]
- In Xcode, select File > Add Packages... and enter
https://github.com/chsxf/CiderCSSKit.git
in the search field (top-right). - Then select Branch as the Dependency Rule with
main
in the associated text field. - Then select the project of your choice in the Add to Project list.
- Finally, click the Add Package button.
Unless stated otherwise, all source code and assets are distributed under the MIT License.