项目作者: MakeupStudio

项目描述 :
CSS DSL written in Swift
高级语言: Swift
项目地址: git://github.com/MakeupStudio/CSSKit.git
创建时间: 2020-01-28T21:17:16Z
项目社区:https://github.com/MakeupStudio/CSSKit

开源协议:

下载




CSS DSL written in Swift.

Draft readme

Styles support

For now it has only direct support for styles

  1. Style.display(.flex)
  2. Style.position(.absolute)
  3. // etc.

Almost all keys for styles are already here, but factories for values are still in development, anyway you can use strings for initialization for now

  1. Style.margin("10pt")

Transform functions are implemented btw :)

  1. Style.transform(.translate(x: 10%))
  2. // Or you can create custom ones like so
  3. extension Style.TransformFunction {
  4. func someNew3DFunction(
  5. x: Dimension.Length,
  6. y: Dimension.Length,
  7. z: Dimension.Length
  8. ) -> Self {
  9. Style.TransformFunction(
  10. name: "someNew3DFunction",
  11. arguments: [
  12. x.erased,
  13. y.erased,
  14. z.erased
  15. ]
  16. )
  17. }
  18. }

Use StylesCollections for elements

  1. let styles: StylesCollection = [ // the same as `let styles: [Style] = [...`
  2. .alignSelf(.center),
  3. .background(Color.brown.hex(uppercase: true, hashTagPrefix: true)),
  4. .borderRadius(1.in.px.render())
  5. ]
  6. styles.render() // "align-self:center;background:#A52A2AFF;border-radius:1.0px;"

Dimensions

Dimensions are present but not integrated in styles factory, so u can render them manually for now

  1. Style.margin(10.in.pt.render())
  2. // the same as
  3. Style.margin(Dimension.Length(value: 10, unit: .pt).render())
  4. // or
  5. Style.margin(Dimension.Length.pt(10)).render())
  6. // Need for `render()` call will be removed in beta releases (It's currently alpha)

Also you can convert some dimensions or replace units

  1. // - Convert
  2. 1000.in.ms // 1000 ms
  3. 1.in.s.converted(to: .ms) // 1000 ms
  4. 1.in.kHz // 1kHz
  5. 1000.in.hz.converted(to: .kHz) // 1kHz
  6. // - Replace units
  7. 1.in.s.in(.ms) // 1ms
  8. 1.in.s.value.in.pt // 1pt
  9. // - Other
  10. 10% // Dimension.Length(value: 10, unit: .percent) or 10.in.percent

Corneres & Edges are supported too

Colors

See GenericColor and Palette for more.

  1. Style.background(color: .livingCoral)
  2. Style.foreground(color: .hex("ffffff")!)

Fonts

I’m gonna provide a static factory for google fonts later, and Font type behaviour may change.

  1. Style.fontFamily("arial")
  2. Style.fontSize(.pt(10))
  3. Style.fontWeight(.bold)

Installation

  1. .package(
  2. url: "https://github.com/MakeupStudio/CSSKit.git",
  3. .upToNextMajor(from: "1.0.0-alpha.1.0")
  4. )

Integration

You can use generateIntegration methods from CSSKit itself by passing needed arguments or use this tool for autogenerating integration code.

So it will generate all the needed fields for your container type, for example for HTML type it will look like

  1. // MARK: - Implementation
  2. extension HTML {
  3. internal func appendingStyle(_ style: Style) -> Self {
  4. <#Implementation#>
  5. }
  6. }
  7. // MARK: - Generated
  8. extension HTML {
  9. public func alignContent(_ value: String) -> Self {
  10. appendingStyle(.alignContent(value))
  11. }
  12. public func alignItems(_ value: String) -> Self {
  13. appendingStyle(.alignItems(value))
  14. }
  15. // ...
  16. }

And you’ll be able to use chaining like this

  1. someHTMLInstance
  2. .display(.flex)
  3. .transform(.rotate(x: .deg(30)))

Hopefully I’ll add more typo-free static factories & extend fonts support a bit next week

Feel free to open issues if you need any functionality