(.module: [library [lux (#- and) [data ["." maybe] [number ["." nat]] ["." text ["%" format (#+ format)] ["." encoding (#+ Encoding)]] [collection ["." list ("#\." functor)]]] [type abstract] [world [net (#+ URL)]]]] ["." / #_ ["#." selector (#+ Selector Combinator)] ["#." value (#+ Value Animation Percentage)] ["#." font (#+ Font)] ["#." style (#+ Style)] ["#." query (#+ Query)]]) (abstract: #export Common Any) (abstract: #export Special Any) (abstract: #export (CSS brand) Text (def: #export css (-> (CSS Any) Text) (|>> :representation)) (def: #export empty (CSS Common) (:abstraction "")) (def: #export (rule selector style) (-> (Selector Any) Style (CSS Common)) (:abstraction (format (/selector.selector selector) "{" (/style.inline style) "}"))) (def: #export char-set (-> Encoding (CSS Special)) (|>> encoding.name %.text (text.enclose ["@charset " ";"]) :abstraction)) (def: #export (font font) (-> Font (CSS Special)) (let [with-unicode (case (get@ #/font.unicode-range font) (#.Some unicode-range) (let [unicode-range' (format "U+" (\ nat.hex encode (get@ #/font.start unicode-range)) "-" (\ nat.hex encode (get@ #/font.end unicode-range)))] (list ["unicode-range" unicode-range'])) #.None (list))] (|> (list& ["font-family" (get@ #/font.family font)] ["src" (format "url(" (get@ #/font.source font) ")")] ["font-stretch" (|> font (get@ #/font.stretch) (maybe.default /value.normal-stretch) /value.value)] ["font-style" (|> font (get@ #/font.style) (maybe.default /value.normal-style) /value.value)] ["font-weight" (|> font (get@ #/font.weight) (maybe.default /value.normal-weight) /value.value)] with-unicode) (list\map (function (_ [property value]) (format property ": " value ";"))) (text.join-with /style.separator) (text.enclose ["{" "}"]) (format "@font-face") :abstraction))) (def: #export (import url query) (-> URL (Maybe Query) (CSS Special)) (:abstraction (format (format "@import url(" (%.text url) ")") (case query (#.Some query) (format " " (/query.query query)) #.None "") ";"))) (def: css-separator text.new-line) (type: #export Frame {#when Percentage #what Style}) (def: #export (key-frames animation frames) (-> (Value Animation) (List Frame) (CSS Special)) (:abstraction (format "@keyframes " (/value.value animation) " {" (|> frames (list\map (function (_ frame) (format (/value.percentage (get@ #when frame)) " {" (/style.inline (get@ #what frame)) "}"))) (text.join-with ..css-separator)) "}"))) (template: (!compose
) (:abstraction (format (:representation ) ..css-separator (:representation)))) (def: #export (and pre post) (-> (CSS Any) (CSS Any) (CSS Any)) (!compose pre post)) (def: #export (alter combinator selector css) (-> Combinator (Selector Any) (CSS Common) (CSS Common)) (|> css :representation (text.split-all-with ..css-separator) (list\map (|>> (format (/selector.selector (|> selector (combinator (/selector.tag ""))))))) (text.join-with ..css-separator) :abstraction)) (def: #export (dependent combinator selector style inner) (-> Combinator (Selector Any) Style (CSS Common) (CSS Common)) (!compose (..rule selector style) (..alter combinator selector inner))) (template [ ] [(def: #export (-> (Selector Any) Style (CSS Common) (CSS Common)) (..dependent ))] [with-descendants /selector.in] [with-children /selector.sub] ) )