diff options
Diffstat (limited to 'stdlib/source/library/lux/data/format/css/value.lux')
-rw-r--r-- | stdlib/source/library/lux/data/format/css/value.lux | 198 |
1 files changed, 131 insertions, 67 deletions
diff --git a/stdlib/source/library/lux/data/format/css/value.lux b/stdlib/source/library/lux/data/format/css/value.lux index a05cabdf5..0a46fddbe 100644 --- a/stdlib/source/library/lux/data/format/css/value.lux +++ b/stdlib/source/library/lux/data/format/css/value.lux @@ -4,8 +4,9 @@ [control ["[0]" maybe]] [data - ["[0]" color] ["[0]" product] + ["[0]" color (.only) + ["[0]" rgb]] ["[0]" text (.only) ["%" \\format (.only Format format)]] [collection @@ -61,11 +62,14 @@ Text (def .public value - (-> (Value Any) Text) + (-> (Value Any) + Text) (|>> representation)) (with_template [<name> <value>] - [(def .public <name> Value (abstraction <value>))] + [(def .public <name> + Value + (abstraction <value>))] [initial "initial"] [inherit "inherit"] @@ -775,10 +779,12 @@ []] ) - (def value_separator ",") + (def value_separator + ",") (def (apply name inputs) - (-> Text (List Text) Value) + (-> Text (List Text) + Value) (|> inputs (text.interposed ..value_separator) (text.enclosed ["(" ")"]) @@ -794,18 +800,21 @@ []) (def .public (steps intervals step) - (-> Nat Step (Value Timing)) + (-> Nat Step + (Value Timing)) (..apply "steps" (list (%.nat intervals) (..step step)))) (def .public (cubic_bezier p0 p1 p2 p3) - (-> Frac Frac Frac Frac (Value Timing)) + (-> Frac Frac Frac Frac + (Value Timing)) (|> (list p0 p1 p2 p3) (list#each %number) (..apply "cubic-bezier"))) (with_template [<name> <brand>] [(def .public <name> - (-> Nat (Value <brand>)) + (-> Nat + (Value <brand>)) (|>> %.nat abstraction))] [iteration Iteration] @@ -815,30 +824,34 @@ ) (def .public animation - (-> Label (Value Animation)) + (-> Label + (Value Animation)) (|>> abstraction)) (def .public (rgb color) - (-> color.Color (Value Color)) + (-> color.Color + (Value Color)) (let [[red green blue] (color.rgb color)] - (..apply "rgb" (list (%.nat red) - (%.nat green) - (%.nat blue))))) + (..apply "rgb" (list (%.nat (rgb.number red)) + (%.nat (rgb.number green)) + (%.nat (rgb.number blue)))))) (def .public (rgba pigment) - (-> color.Pigment (Value Color)) + (-> color.Pigment + (Value Color)) (let [(open "_[0]") pigment [red green blue] (color.rgb _#color)] - (..apply "rgba" (list (%.nat red) - (%.nat green) - (%.nat blue) + (..apply "rgba" (list (%.nat (rgb.number red)) + (%.nat (rgb.number green)) + (%.nat (rgb.number blue)) (if (r.= (at r.interval top) _#alpha) "1.0" (format "0" (%.rev _#alpha))))))) (with_template [<name> <suffix>] [(def .public (<name> value) - (-> Frac (Value Length)) + (-> Frac + (Value Length)) (abstraction (format (%number value) <suffix>)))] [em "em"] @@ -867,7 +880,8 @@ (with_template [<name> <suffix>] [(def .public (<name> value) - (-> Int (Value Time)) + (-> Int + (Value Time)) (abstraction (format (if (i.< +0 value) (%.int value) (%.nat (.nat value))) @@ -879,13 +893,15 @@ ) (def .public thickness - (-> (Value Length) (Value Thickness)) + (-> (Value Length) + (Value Thickness)) (|>> transmutation)) (def slice_separator " ") (def .public (slice_number/2 horizontal vertical) - (-> Nat Nat (Value Slice)) + (-> Nat Nat + (Value Slice)) (abstraction (format (%.nat horizontal) ..slice_separator (%.nat vertical)))) @@ -893,18 +909,22 @@ Text (def .public stop - (-> (Value Color) Stop) + (-> (Value Color) + Stop) (|>> (representation Value) (abstraction Stop))) - (def stop_separator " ") + (def stop_separator + " ") (def .public (single_stop length color) - (-> (Value Length) (Value Color) Stop) + (-> (Value Length) (Value Color) + Stop) (abstraction (format (representation Value color) ..stop_separator (representation Value length)))) (def .public (double_stop start end color) - (-> (Value Length) (Value Length) (Value Color) Stop) + (-> (Value Length) (Value Length) (Value Color) + Stop) (abstraction (format (representation Value color) ..stop_separator (representation Value start) ..stop_separator (representation Value end)))) @@ -913,11 +933,13 @@ Text (def .public hint - (-> (Value Length) Hint) + (-> (Value Length) + Hint) (|>> (representation Value) (abstraction Hint))) (def (with_hint [hint stop]) - (-> [(Maybe Hint) Stop] Text) + (-> [(Maybe Hint) Stop] + Text) (when hint {.#None} (representation Stop stop) @@ -932,17 +954,22 @@ Text (def .public angle - (-> Angle Text) + (-> Angle + Text) (|>> representation)) (def .public (turn value) - (-> Rev Angle) + (-> Rev + Angle) (abstraction (format (%.rev value) "turn"))) - (def degree_limit Nat 360) + (def degree_limit + Nat + 360) (def .public (degree value) - (-> Nat Angle) + (-> Nat + Angle) (abstraction (format (%.nat (n.% ..degree_limit value)) "deg"))) (with_template [<degree> <name>] @@ -958,7 +985,8 @@ (with_template [<name> <function>] [(def .public (<name> angle start next) - (-> Angle Stop (List/1 [(Maybe Hint) Stop]) (Value Image)) + (-> Angle Stop (List/1 [(Maybe Hint) Stop]) + (Value Image)) (let [[now after] next] (..apply <function> (list.partial (representation Angle angle) (with_hint now) @@ -969,25 +997,31 @@ ) ) - (def percentage_limit Nat (.++ 100)) + (def percentage_limit + Nat + (.++ 100)) (def .public (%% value) - (-> Nat (Value Percentage)) + (-> Nat + (Value Percentage)) (abstraction (format (%.nat (n.% percentage_limit value)) "%"))) (def .public slice_percent/1 - (-> (Value Percentage) (Value Slice)) + (-> (Value Percentage) + (Value Slice)) (|>> transmutation)) (def .public (slice_percent/2 horizontal vertical) - (-> (Value Percentage) (Value Percentage) (Value Slice)) + (-> (Value Percentage) (Value Percentage) + (Value Slice)) (abstraction (format (representation horizontal) ..slice_separator (representation vertical)))) (with_template [<input> <pre> <function>+] [(`` (with_template [<name> <function>] [(def .public <name> - (-> <input> (Value Filter)) + (-> <input> + (Value Filter)) (|>> <pre> (list) (..apply <function>)))] (,, (template.spliced <function>+))))] @@ -1007,10 +1041,12 @@ ) (def .public svg_filter - (-> URL (Value Filter)) + (-> URL + (Value Filter)) (|>> (list) (..apply "url"))) - (def default_shadow_length (px +0.0)) + (def default_shadow_length + (px +0.0)) (def .public (drop_shadow horizontal vertical blur spread color) (-> (Value Length) (Value Length) @@ -1026,11 +1062,13 @@ (list) (..apply "drop-shadow"))) - (def length_separator " ") + (def length_separator + " ") (with_template [<name> <type>] [(def .public (<name> horizontal vertical) - (-> (Value Length) (Value Length) (Value <type>)) + (-> (Value Length) (Value Length) + (Value <type>)) (abstraction (format (representation horizontal) ..length_separator (representation vertical))))] @@ -1040,11 +1078,13 @@ ) (def .public (fit/1 length) - (-> (Value Length) (Value Fit)) + (-> (Value Length) + (Value Fit)) (..fit length length)) (def .public image - (-> URL (Value Image)) + (-> URL + (Value Image)) (|>> %.text (list) (..apply "url"))) @@ -1114,30 +1154,36 @@ #left (Value Length)])) (def .public (clip rectangle) - (-> Rectangle (Value Clip)) + (-> Rectangle + (Value Clip)) (`` (..apply "rect" (list (,, (with_template [<side>] [(representation (the <side> rectangle))] [#top] [#right] [#bottom] [#left])))))) (def .public counter - (-> Label (Value Counter)) + (-> Label + (Value Counter)) (|>> abstraction)) (def .public current_count - (-> (Value Counter) (Value Content)) + (-> (Value Counter) + (Value Content)) (|>> representation (list) (..apply "counter"))) (def .public text - (-> Text (Value Content)) + (-> Text + (Value Content)) (|>> %.text abstraction)) (def .public attribute - (-> Label (Value Content)) + (-> Label + (Value Content)) (|>> (list) (..apply "attr"))) (def .public media - (-> URL (Value Content)) + (-> URL + (Value Content)) (|>> (list) (..apply "url"))) (enumeration @@ -1166,35 +1212,42 @@ ..initial))]) (def .public font_size - (-> (Value Length) (Value Font_Size)) + (-> (Value Length) + (Value Font_Size)) (|>> transmutation)) (def .public number - (-> Frac (Value Number)) + (-> Frac + (Value Number)) (|>> %number abstraction)) (def .public grid - (-> Label (Value Grid)) + (-> Label + (Value Grid)) (|>> abstraction)) (def .public fit_content - (-> (Value Length) (Value Grid_Content)) + (-> (Value Length) + (Value Grid_Content)) (|>> representation (list) (..apply "fit-content"))) (def .public (min_max min max) - (-> (Value Grid_Content) (Value Grid_Content) (Value Grid_Content)) + (-> (Value Grid_Content) (Value Grid_Content) + (Value Grid_Content)) (..apply "minmax" (list (representation min) (representation max)))) (def .public grid_span - (-> Nat (Value Grid_Span)) + (-> Nat + (Value Grid_Span)) (|>> %.nat (format "span ") abstraction)) (def grid_column_separator " ") (def grid_row_separator " ") (def .public grid_template - (-> (List (List (Maybe (Value Grid)))) (Value Grid_Template)) + (-> (List (List (Maybe (Value Grid)))) + (Value Grid_Template)) (let [empty (is (Value Grid) (abstraction "."))] (|>> (list#each (|>> (list#each (|>> (maybe.else empty) @@ -1205,11 +1258,13 @@ abstraction))) (def .public (resolution dpi) - (-> Nat (Value Resolution)) + (-> Nat + (Value Resolution)) (abstraction (format (%.nat dpi) "dpi"))) (def .public (ratio numerator denominator) - (-> Nat Nat (Value Ratio)) + (-> Nat Nat + (Value Ratio)) (abstraction (format (%.nat numerator) "/" (%.nat denominator)))) (enumeration @@ -1234,7 +1289,8 @@ (def quote_separator " ") (def .public (quotes [left0 right0] [left1 right1]) - (-> [Quote Quote] [Quote Quote] (Value Quotes)) + (-> [Quote Quote] [Quote Quote] + (Value Quotes)) (|> (list left0 right0 left1 right1) (list#each (|>> ..quote_text %.text)) (text.interposed ..quote_separator) @@ -1261,7 +1317,8 @@ (with_template [<name> <function> <input_types> <input_values>] [(`` (def .public (<name> [(,, (template.spliced <input_values>))]) - (-> [(,, (template.spliced <input_types>))] (Value Transform)) + (-> [(,, (template.spliced <input_types>))] + (Value Transform)) (|> (list (,, (template.spliced <input_values>))) (list#each %number) (..apply <function>))))] @@ -1283,7 +1340,8 @@ (with_template [<name> <function> <input_types> <input_values>] [(`` (def .public (<name> [(,, (template.spliced <input_values>))]) - (-> [(,, (template.spliced <input_types>))] (Value Transform)) + (-> [(,, (template.spliced <input_types>))] + (Value Transform)) (|> (list (,, (template.spliced <input_values>))) (list#each ..angle) (..apply <function>))))] @@ -1299,36 +1357,42 @@ ) (def .public (rotate_3d [x y z angle]) - (-> [Frac Frac Frac Angle] (Value Transform)) + (-> [Frac Frac Frac Angle] + (Value Transform)) (..apply "rotate3d" (list (%number x) (%number y) (%number z) (..angle angle)))) (def origin_separator " ") (def .public (origin_2d x y) - (-> (Value Length) (Value Length) (Value Transform_Origin)) + (-> (Value Length) (Value Length) + (Value Transform_Origin)) (abstraction (format (representation x) ..origin_separator (representation y)))) (def .public (origin_3d x y z) - (-> (Value Length) (Value Length) (Value Length) (Value Transform_Origin)) + (-> (Value Length) (Value Length) (Value Length) + (Value Transform_Origin)) (abstraction (format (representation x) ..origin_separator (representation y) ..origin_separator (representation z)))) (def .public vertical_align - (-> (Value Length) (Value Vertical_Align)) + (-> (Value Length) + (Value Vertical_Align)) (|>> transmutation)) (def .public (z_index index) - (-> Int (Value Z_Index)) + (-> Int + (Value Z_Index)) (abstraction (if (i.< +0 index) (%.int index) (%.nat (.nat index))))) (with_template [<separator> <type> <multi>] [(def .public (<multi> pre post) - (-> (Value <type>) (Value <type>) (Value <type>)) + (-> (Value <type>) (Value <type>) + (Value <type>)) (abstraction (format (representation pre) <separator> (representation post))))] |