├── .gitignore ├── LICENSE ├── README.md ├── flake.lock ├── flake.nix ├── packages.dhall ├── spago-packages.nix ├── spago.dhall ├── src └── Style │ ├── Declaration.purs │ ├── Declaration │ ├── Property.purs │ └── Value.purs │ ├── Render.purs │ ├── Ruleset.purs │ └── Selector.purs └── test └── Main.purs /.gitignore: -------------------------------------------------------------------------------- 1 | /.psa* 2 | /.psc* 3 | /.psc-package/ 4 | /.purs* 5 | /.spago 6 | /.spago2nix 7 | /generated-docs/ 8 | /output/ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Paul Young 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-style 2 | 3 | [![Build Status](https://travis-ci.com/paulyoung/purescript-style.svg?branch=master)](https://travis-ci.com/paulyoung/purescript-style) 4 | 5 | ## Usage 6 | 7 | ```purescript 8 | inline 9 | [ backgroundColor $ rgb 127 127 127 10 | , color black 11 | , fontSize $ 16.0 # px 12 | , height $ 100.0 # pct 13 | , margin zero 14 | , padding $ 2.0 # em 15 | , textAlign center 16 | , width auto 17 | ] 18 | ``` 19 | 20 | ``` 21 | "background-color: rgb(127, 127, 127); color: rgb(0, 0, 0); font-size: 16px; height: 100%; margin: 0; padding: 2em; text-align: center; width: auto;" 22 | ``` 23 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "easy-purescript-nix": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1649768932, 7 | "narHash": "sha256-T96xGZV2AEP07smv/L2s5U7jY1LTdJEiTnA90gJ3Fco=", 8 | "owner": "justinwoo", 9 | "repo": "easy-purescript-nix", 10 | "rev": "d56c436a66ec2a8a93b309c83693cef1507dca7a", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "justinwoo", 15 | "repo": "easy-purescript-nix", 16 | "type": "github" 17 | } 18 | }, 19 | "flake-utils": { 20 | "locked": { 21 | "lastModified": 1649676176, 22 | "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", 23 | "owner": "numtide", 24 | "repo": "flake-utils", 25 | "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", 26 | "type": "github" 27 | }, 28 | "original": { 29 | "owner": "numtide", 30 | "repo": "flake-utils", 31 | "type": "github" 32 | } 33 | }, 34 | "nixpkgs": { 35 | "locked": { 36 | "lastModified": 1638239011, 37 | "narHash": "sha256-AjhmbT4UBlJWqxY0ea8a6GU2C2HdKUREkG43oRr3TZg=", 38 | "owner": "NixOS", 39 | "repo": "nixpkgs", 40 | "rev": "a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31", 41 | "type": "github" 42 | }, 43 | "original": { 44 | "owner": "NixOS", 45 | "ref": "21.11", 46 | "repo": "nixpkgs", 47 | "type": "github" 48 | } 49 | }, 50 | "root": { 51 | "inputs": { 52 | "easy-purescript-nix": "easy-purescript-nix", 53 | "flake-utils": "flake-utils", 54 | "nixpkgs": "nixpkgs" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | easy-purescript-nix = { 4 | url = "github:justinwoo/easy-purescript-nix"; 5 | flake = false; 6 | }; 7 | nixpkgs.url = "github:NixOS/nixpkgs/21.11"; 8 | flake-utils.url = "github:numtide/flake-utils"; 9 | }; 10 | 11 | outputs = { 12 | self, 13 | nixpkgs, 14 | easy-purescript-nix, 15 | flake-utils, 16 | }: 17 | flake-utils.lib.eachDefaultSystem ( 18 | system: let 19 | pkgs = import nixpkgs { 20 | inherit system; 21 | }; 22 | 23 | easy-ps = import easy-purescript-nix { inherit pkgs; }; 24 | spagoPkgs = import ./spago-packages.nix { inherit pkgs; }; 25 | in 26 | rec { 27 | # `nix build` 28 | packages.purescript-style = pkgs.stdenv.mkDerivation { 29 | name = "purescript-style"; 30 | buildInputs = [ 31 | spagoPkgs.installSpagoStyle 32 | spagoPkgs.buildSpagoStyle 33 | ]; 34 | nativeBuildInputs = [ 35 | easy-ps.purs 36 | easy-ps.spago 37 | ]; 38 | src = ./.; 39 | unpackPhase = '' 40 | cp $src/spago.dhall . 41 | cp $src/packages.dhall . 42 | cp -R $src/src . 43 | install-spago-style 44 | ''; 45 | buildPhase = '' 46 | build-spago-style "./src/**/*.purs" --codegen corefn 47 | ''; 48 | installPhase = '' 49 | mkdir $out 50 | mv output $out/ 51 | ''; 52 | }; 53 | 54 | defaultPackage = packages.purescript-style; 55 | 56 | # `nix develop` 57 | devShell = pkgs.mkShell { 58 | buildInputs = [ 59 | easy-ps.psa 60 | easy-ps.purs 61 | easy-ps.purs-tidy 62 | easy-ps.purescript-language-server 63 | easy-ps.spago 64 | easy-ps.spago2nix 65 | pkgs.nodejs 66 | ]; 67 | }; 68 | } 69 | ); 70 | } 71 | -------------------------------------------------------------------------------- /packages.dhall: -------------------------------------------------------------------------------- 1 | {- 2 | Welcome to your new Dhall package-set! 3 | 4 | Below are instructions for how to edit this file for most use 5 | cases, so that you don't need to know Dhall to use it. 6 | 7 | ## Use Cases 8 | 9 | Most will want to do one or both of these options: 10 | 1. Override/Patch a package's dependency 11 | 2. Add a package not already in the default package set 12 | 13 | This file will continue to work whether you use one or both options. 14 | Instructions for each option are explained below. 15 | 16 | ### Overriding/Patching a package 17 | 18 | Purpose: 19 | - Change a package's dependency to a newer/older release than the 20 | default package set's release 21 | - Use your own modified version of some dependency that may 22 | include new API, changed API, removed API by 23 | using your custom git repo of the library rather than 24 | the package set's repo 25 | 26 | Syntax: 27 | where `entityName` is one of the following: 28 | - dependencies 29 | - repo 30 | - version 31 | ------------------------------- 32 | let upstream = -- 33 | in upstream 34 | with packageName.entityName = "new value" 35 | ------------------------------- 36 | 37 | Example: 38 | ------------------------------- 39 | let upstream = -- 40 | in upstream 41 | with halogen.version = "master" 42 | with halogen.repo = "https://example.com/path/to/git/repo.git" 43 | 44 | with halogen-vdom.version = "v4.0.0" 45 | with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies 46 | ------------------------------- 47 | 48 | ### Additions 49 | 50 | Purpose: 51 | - Add packages that aren't already included in the default package set 52 | 53 | Syntax: 54 | where `` is: 55 | - a tag (i.e. "v4.0.0") 56 | - a branch (i.e. "master") 57 | - commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") 58 | ------------------------------- 59 | let upstream = -- 60 | in upstream 61 | with new-package-name = 62 | { dependencies = 63 | [ "dependency1" 64 | , "dependency2" 65 | ] 66 | , repo = 67 | "https://example.com/path/to/git/repo.git" 68 | , version = 69 | "" 70 | } 71 | ------------------------------- 72 | 73 | Example: 74 | ------------------------------- 75 | let upstream = -- 76 | in upstream 77 | with benchotron = 78 | { dependencies = 79 | [ "arrays" 80 | , "exists" 81 | , "profunctor" 82 | , "strings" 83 | , "quickcheck" 84 | , "lcg" 85 | , "transformers" 86 | , "foldable-traversable" 87 | , "exceptions" 88 | , "node-fs" 89 | , "node-buffer" 90 | , "node-readline" 91 | , "datetime" 92 | , "now" 93 | ] 94 | , repo = 95 | "https://github.com/hdgarrood/purescript-benchotron.git" 96 | , version = 97 | "v7.0.0" 98 | } 99 | ------------------------------- 100 | -} 101 | let upstream = 102 | https://github.com/purescript/package-sets/releases/download/psc-0.14.7-20220418/packages.dhall 103 | sha256:2523a5659d0f3b198ffa2f800da147e0120578842e492a7148e4b44f357848b3 104 | 105 | in upstream 106 | -------------------------------------------------------------------------------- /spago-packages.nix: -------------------------------------------------------------------------------- 1 | # This file was generated by Spago2Nix 2 | 3 | { pkgs ? import {} }: 4 | 5 | let 6 | inputs = { 7 | 8 | "arrays" = pkgs.stdenv.mkDerivation { 9 | name = "arrays"; 10 | version = "v6.0.1"; 11 | src = pkgs.fetchgit { 12 | url = "https://github.com/purescript/purescript-arrays.git"; 13 | rev = "c0aa3176b077ad7a46b11ef34487485c28142e53"; 14 | sha256 = "0lm0m5hapimchzgfywr648pkw1hpggr6qibh8d19p2impbnc94c0"; 15 | }; 16 | phases = "installPhase"; 17 | installPhase = "ln -s $src $out"; 18 | }; 19 | 20 | "bifunctors" = pkgs.stdenv.mkDerivation { 21 | name = "bifunctors"; 22 | version = "v5.0.0"; 23 | src = pkgs.fetchgit { 24 | url = "https://github.com/purescript/purescript-bifunctors.git"; 25 | rev = "a31d0fc4bbebf19d5e9b21b65493c28b8d3fba62"; 26 | sha256 = "0xc2hf8ccdgqw3m9qcmr38kmzv05fsxvakd07wyrqshvkzg3xn0d"; 27 | }; 28 | phases = "installPhase"; 29 | installPhase = "ln -s $src $out"; 30 | }; 31 | 32 | "colors" = pkgs.stdenv.mkDerivation { 33 | name = "colors"; 34 | version = "v6.0.0"; 35 | src = pkgs.fetchgit { 36 | url = "https://github.com/purescript-contrib/purescript-colors.git"; 37 | rev = "328e61f371aadfafb496834ac048fe36e33240cd"; 38 | sha256 = "05gdjx8xhv7xxm1prrrc2brxjn1gi19qf1004syk8qx37slrjf87"; 39 | }; 40 | phases = "installPhase"; 41 | installPhase = "ln -s $src $out"; 42 | }; 43 | 44 | "console" = pkgs.stdenv.mkDerivation { 45 | name = "console"; 46 | version = "v5.0.0"; 47 | src = pkgs.fetchgit { 48 | url = "https://github.com/purescript/purescript-console.git"; 49 | rev = "d7cb69ef8fed8a51466afe1b623868bb29e8586e"; 50 | sha256 = "0fzzzqjgrz33pb2jf7cdqpg09ilxb7bsrc7sbfq52wjg0sx9aq6g"; 51 | }; 52 | phases = "installPhase"; 53 | installPhase = "ln -s $src $out"; 54 | }; 55 | 56 | "const" = pkgs.stdenv.mkDerivation { 57 | name = "const"; 58 | version = "v5.0.0"; 59 | src = pkgs.fetchgit { 60 | url = "https://github.com/purescript/purescript-const.git"; 61 | rev = "3a3a4bdc44f71311cf27de9bd22039b110277540"; 62 | sha256 = "0aq9qjbrvf8mf8hmas6imv4mg6n3zi13hkf449ns1hn12lw8qv4g"; 63 | }; 64 | phases = "installPhase"; 65 | installPhase = "ln -s $src $out"; 66 | }; 67 | 68 | "contravariant" = pkgs.stdenv.mkDerivation { 69 | name = "contravariant"; 70 | version = "v5.0.0"; 71 | src = pkgs.fetchgit { 72 | url = "https://github.com/purescript/purescript-contravariant.git"; 73 | rev = "ae1a765f7ddbfd96ae1f12e399e46d554d8e3b38"; 74 | sha256 = "029hb8i3n4759x4gc06wkfgr7wim5x1w5jy2bsiy42n0g731h5qc"; 75 | }; 76 | phases = "installPhase"; 77 | installPhase = "ln -s $src $out"; 78 | }; 79 | 80 | "control" = pkgs.stdenv.mkDerivation { 81 | name = "control"; 82 | version = "v5.0.0"; 83 | src = pkgs.fetchgit { 84 | url = "https://github.com/purescript/purescript-control.git"; 85 | rev = "18d582e311f1f8523f9eb55fb93c91bd21e22837"; 86 | sha256 = "06dc06yli4g5yr8fb9sdpqbhiaff37g977qcsbds9q2mlhnjgfx9"; 87 | }; 88 | phases = "installPhase"; 89 | installPhase = "ln -s $src $out"; 90 | }; 91 | 92 | "distributive" = pkgs.stdenv.mkDerivation { 93 | name = "distributive"; 94 | version = "v5.0.0"; 95 | src = pkgs.fetchgit { 96 | url = "https://github.com/purescript/purescript-distributive.git"; 97 | rev = "11f3f87ca5720899e1739cedb58dd6227cae6ad5"; 98 | sha256 = "0788znmdyh6b1c9pln624ah397l88xmd3fxlxiy3z1qy8bzr4r54"; 99 | }; 100 | phases = "installPhase"; 101 | installPhase = "ln -s $src $out"; 102 | }; 103 | 104 | "effect" = pkgs.stdenv.mkDerivation { 105 | name = "effect"; 106 | version = "v3.0.0"; 107 | src = pkgs.fetchgit { 108 | url = "https://github.com/purescript/purescript-effect.git"; 109 | rev = "985d97bd5721ddcc41304c55a7ca2bb0c0bfdc2a"; 110 | sha256 = "1n9qr85knvpm4i0qhm8xbgfk46v9y843p76j278phfs9l6aywzsn"; 111 | }; 112 | phases = "installPhase"; 113 | installPhase = "ln -s $src $out"; 114 | }; 115 | 116 | "either" = pkgs.stdenv.mkDerivation { 117 | name = "either"; 118 | version = "v5.0.0"; 119 | src = pkgs.fetchgit { 120 | url = "https://github.com/purescript/purescript-either.git"; 121 | rev = "c1a1af35684f10eecaf6ac7d38dbf6bd48af2ced"; 122 | sha256 = "18dk159yyv7vs0xsnh9m5fajd7zy6zw5b2mpyd6nqdh3c6bb9wh6"; 123 | }; 124 | phases = "installPhase"; 125 | installPhase = "ln -s $src $out"; 126 | }; 127 | 128 | "enums" = pkgs.stdenv.mkDerivation { 129 | name = "enums"; 130 | version = "v5.0.0"; 131 | src = pkgs.fetchgit { 132 | url = "https://github.com/purescript/purescript-enums.git"; 133 | rev = "170d959644eb99e0025f4ab2e38f5f132fd85fa4"; 134 | sha256 = "1lci5iy6s6cmh93bpkfcmp0j4n5dnij7dswb0075bk0kzd9xp7rs"; 135 | }; 136 | phases = "installPhase"; 137 | installPhase = "ln -s $src $out"; 138 | }; 139 | 140 | "exists" = pkgs.stdenv.mkDerivation { 141 | name = "exists"; 142 | version = "v5.1.0"; 143 | src = pkgs.fetchgit { 144 | url = "https://github.com/purescript/purescript-exists.git"; 145 | rev = "c34820f8b2d15be29abdd5097c3d636f5df8f28c"; 146 | sha256 = "15qp52cpp2yvxihkzfmn6gabyvx5s6iz5lafvqhyfgp4wfnz0bds"; 147 | }; 148 | phases = "installPhase"; 149 | installPhase = "ln -s $src $out"; 150 | }; 151 | 152 | "foldable-traversable" = pkgs.stdenv.mkDerivation { 153 | name = "foldable-traversable"; 154 | version = "v5.0.1"; 155 | src = pkgs.fetchgit { 156 | url = "https://github.com/purescript/purescript-foldable-traversable.git"; 157 | rev = "d581caf260772b1b446c11ac3c8be807b290b220"; 158 | sha256 = "182na4np7hk2dqyxywy4jij2csrzx4bz02m6bq8yx1j27hlgjvsd"; 159 | }; 160 | phases = "installPhase"; 161 | installPhase = "ln -s $src $out"; 162 | }; 163 | 164 | "functions" = pkgs.stdenv.mkDerivation { 165 | name = "functions"; 166 | version = "v5.0.0"; 167 | src = pkgs.fetchgit { 168 | url = "https://github.com/purescript/purescript-functions.git"; 169 | rev = "691b3345bc2feaf914e5299796c606b6a6bf9ca9"; 170 | sha256 = "1gnk6xh5x04zcahn82gwp49qpglxd5jkfqn0i58m27jfihvblaxd"; 171 | }; 172 | phases = "installPhase"; 173 | installPhase = "ln -s $src $out"; 174 | }; 175 | 176 | "functors" = pkgs.stdenv.mkDerivation { 177 | name = "functors"; 178 | version = "v4.1.1"; 179 | src = pkgs.fetchgit { 180 | url = "https://github.com/purescript/purescript-functors.git"; 181 | rev = "e936f7a8d2ec53a344c478ccada5add93273848c"; 182 | sha256 = "0i1x14r54758s5jx5d7zy4l07mg6gabljadgybldnbpmdqk6b966"; 183 | }; 184 | phases = "installPhase"; 185 | installPhase = "ln -s $src $out"; 186 | }; 187 | 188 | "gen" = pkgs.stdenv.mkDerivation { 189 | name = "gen"; 190 | version = "v3.0.0"; 191 | src = pkgs.fetchgit { 192 | url = "https://github.com/purescript/purescript-gen.git"; 193 | rev = "85c369f56545a3de834b7e7475a56bc9193bb4b4"; 194 | sha256 = "1h396rqn1fc2c155i58vnaksqjrpajly128ah6wq1w426vwr1vrf"; 195 | }; 196 | phases = "installPhase"; 197 | installPhase = "ln -s $src $out"; 198 | }; 199 | 200 | "identity" = pkgs.stdenv.mkDerivation { 201 | name = "identity"; 202 | version = "v5.0.0"; 203 | src = pkgs.fetchgit { 204 | url = "https://github.com/purescript/purescript-identity.git"; 205 | rev = "5c150ac5ee4fa6f145932f6322a1020463dae8e9"; 206 | sha256 = "0a58y71ihvb5b7plnn2sxsbphqzd9nzfafak4d5a576agn76q0ql"; 207 | }; 208 | phases = "installPhase"; 209 | installPhase = "ln -s $src $out"; 210 | }; 211 | 212 | "integers" = pkgs.stdenv.mkDerivation { 213 | name = "integers"; 214 | version = "v5.0.0"; 215 | src = pkgs.fetchgit { 216 | url = "https://github.com/purescript/purescript-integers.git"; 217 | rev = "8a783f2d92596c43afca53066ac18eb389d15981"; 218 | sha256 = "1rrygw0ai61brnvgap7dfhdzacyhg5439pz6yrmmyg32cvf0znhv"; 219 | }; 220 | phases = "installPhase"; 221 | installPhase = "ln -s $src $out"; 222 | }; 223 | 224 | "invariant" = pkgs.stdenv.mkDerivation { 225 | name = "invariant"; 226 | version = "v5.0.0"; 227 | src = pkgs.fetchgit { 228 | url = "https://github.com/purescript/purescript-invariant.git"; 229 | rev = "c421b49dec7a1511073bb408a08bdd8c9d17d7b1"; 230 | sha256 = "0vwkbh7kv00g50xjgvxc0mv5b99mrj6q0sxznxwk32hb9hkbhy5l"; 231 | }; 232 | phases = "installPhase"; 233 | installPhase = "ln -s $src $out"; 234 | }; 235 | 236 | "lazy" = pkgs.stdenv.mkDerivation { 237 | name = "lazy"; 238 | version = "v5.0.0"; 239 | src = pkgs.fetchgit { 240 | url = "https://github.com/purescript/purescript-lazy.git"; 241 | rev = "2f73f61e7ac1ae1cfe05564112e3313530e673ff"; 242 | sha256 = "1wxfx019911gbkifq266hgn67zwm89pxhi83bai77mva5n9j3f6l"; 243 | }; 244 | phases = "installPhase"; 245 | installPhase = "ln -s $src $out"; 246 | }; 247 | 248 | "lists" = pkgs.stdenv.mkDerivation { 249 | name = "lists"; 250 | version = "v6.0.1"; 251 | src = pkgs.fetchgit { 252 | url = "https://github.com/purescript/purescript-lists.git"; 253 | rev = "6383c4f202b3f69474f9f7da182c2d42fcc3111c"; 254 | sha256 = "0xmg918s3mqvfvwgjfqcs1yvcz6hy2n7h3ygqz2iyvk868gz25qs"; 255 | }; 256 | phases = "installPhase"; 257 | installPhase = "ln -s $src $out"; 258 | }; 259 | 260 | "math" = pkgs.stdenv.mkDerivation { 261 | name = "math"; 262 | version = "v3.0.0"; 263 | src = pkgs.fetchgit { 264 | url = "https://github.com/purescript/purescript-math.git"; 265 | rev = "59746cc74e23fb1f04e09342884c5d1e3943a04f"; 266 | sha256 = "0hkf0vyiga21992d9vbvdbnzdkvgljmsi497jjas1rk3vhblx8sq"; 267 | }; 268 | phases = "installPhase"; 269 | installPhase = "ln -s $src $out"; 270 | }; 271 | 272 | "maybe" = pkgs.stdenv.mkDerivation { 273 | name = "maybe"; 274 | version = "v5.0.0"; 275 | src = pkgs.fetchgit { 276 | url = "https://github.com/purescript/purescript-maybe.git"; 277 | rev = "8e96ca0187208e78e8df6a464c281850e5c9400c"; 278 | sha256 = "0vyk3r9gklvv7awzpph7ra53zxxbin1ngmqflb5vvr2365v5xyqy"; 279 | }; 280 | phases = "installPhase"; 281 | installPhase = "ln -s $src $out"; 282 | }; 283 | 284 | "newtype" = pkgs.stdenv.mkDerivation { 285 | name = "newtype"; 286 | version = "v4.0.0"; 287 | src = pkgs.fetchgit { 288 | url = "https://github.com/purescript/purescript-newtype.git"; 289 | rev = "7b292fcd2ac7c4a25d7a7a8d3387d0ee7de89b13"; 290 | sha256 = "1fgzbxslckva2psn0sia30hfakx8xchz3wx2kkh3w8rr4nn2py8v"; 291 | }; 292 | phases = "installPhase"; 293 | installPhase = "ln -s $src $out"; 294 | }; 295 | 296 | "nonempty" = pkgs.stdenv.mkDerivation { 297 | name = "nonempty"; 298 | version = "v6.1.0"; 299 | src = pkgs.fetchgit { 300 | url = "https://github.com/purescript/purescript-nonempty.git"; 301 | rev = "7696eaf915da5333173bca7d779a51f91a525b83"; 302 | sha256 = "0hhhw5x5xvs2bd9373gklja1545glnzi1xc2sj16kkznnayrmvsn"; 303 | }; 304 | phases = "installPhase"; 305 | installPhase = "ln -s $src $out"; 306 | }; 307 | 308 | "numbers" = pkgs.stdenv.mkDerivation { 309 | name = "numbers"; 310 | version = "v8.0.0"; 311 | src = pkgs.fetchgit { 312 | url = "https://github.com/purescript/purescript-numbers.git"; 313 | rev = "f5bbd96cbed58403c4445bd4c73df50fc8d86f46"; 314 | sha256 = "00pm2x4kh4fm91r7nmik1v5jclkgh7gpxz13ambyqxbxbiqjq0vg"; 315 | }; 316 | phases = "installPhase"; 317 | installPhase = "ln -s $src $out"; 318 | }; 319 | 320 | "orders" = pkgs.stdenv.mkDerivation { 321 | name = "orders"; 322 | version = "v5.0.0"; 323 | src = pkgs.fetchgit { 324 | url = "https://github.com/purescript/purescript-orders.git"; 325 | rev = "c25b7075426cf82bcb960495f28d2541c9a75510"; 326 | sha256 = "0wwy3ycjll0s590ra35zf5gjvs86w97rln09bj428axhg7cvfl0a"; 327 | }; 328 | phases = "installPhase"; 329 | installPhase = "ln -s $src $out"; 330 | }; 331 | 332 | "partial" = pkgs.stdenv.mkDerivation { 333 | name = "partial"; 334 | version = "v3.0.0"; 335 | src = pkgs.fetchgit { 336 | url = "https://github.com/purescript/purescript-partial.git"; 337 | rev = "2f0a5239efab68179a684603263bcec8f1489b08"; 338 | sha256 = "0acxf686hvaj793hyb7kfn9lf96kv3nk0lls2p9j095ylp55sldb"; 339 | }; 340 | phases = "installPhase"; 341 | installPhase = "ln -s $src $out"; 342 | }; 343 | 344 | "prelude" = pkgs.stdenv.mkDerivation { 345 | name = "prelude"; 346 | version = "v5.0.1"; 347 | src = pkgs.fetchgit { 348 | url = "https://github.com/purescript/purescript-prelude.git"; 349 | rev = "68f8012bc2309d9bf5832cdf7316ad052d586905"; 350 | sha256 = "1x0cacvv9mmw80vy6f40y0p959q1dz28fwjswhyd7ws6npbklcy0"; 351 | }; 352 | phases = "installPhase"; 353 | installPhase = "ln -s $src $out"; 354 | }; 355 | 356 | "profunctor" = pkgs.stdenv.mkDerivation { 357 | name = "profunctor"; 358 | version = "v5.0.0"; 359 | src = pkgs.fetchgit { 360 | url = "https://github.com/purescript/purescript-profunctor.git"; 361 | rev = "4551b8e437a00268cc9b687cbe691d75e812e82b"; 362 | sha256 = "0fvd2xiv77sp4jd4spgdp4i9812p6pdzzbg4pa96mbr0h19jf39c"; 363 | }; 364 | phases = "installPhase"; 365 | installPhase = "ln -s $src $out"; 366 | }; 367 | 368 | "psci-support" = pkgs.stdenv.mkDerivation { 369 | name = "psci-support"; 370 | version = "v5.0.0"; 371 | src = pkgs.fetchgit { 372 | url = "https://github.com/purescript/purescript-psci-support.git"; 373 | rev = "f26fe8266a63494080476333e22f971404ea8846"; 374 | sha256 = "16vhf8hapd7rcgmafmjpiq7smhzdh3300f2idk1q4kk01yxn8ddj"; 375 | }; 376 | phases = "installPhase"; 377 | installPhase = "ln -s $src $out"; 378 | }; 379 | 380 | "record" = pkgs.stdenv.mkDerivation { 381 | name = "record"; 382 | version = "v3.0.0"; 383 | src = pkgs.fetchgit { 384 | url = "https://github.com/purescript/purescript-record.git"; 385 | rev = "091495d61fcaa9d8d8232e7b800f403a3165a38f"; 386 | sha256 = "0yidfvwiajiv8xflfsi2p8dqnp0qmmcz9jry58jyn9ga82z2pqn6"; 387 | }; 388 | phases = "installPhase"; 389 | installPhase = "ln -s $src $out"; 390 | }; 391 | 392 | "refs" = pkgs.stdenv.mkDerivation { 393 | name = "refs"; 394 | version = "v5.0.0"; 395 | src = pkgs.fetchgit { 396 | url = "https://github.com/purescript/purescript-refs.git"; 397 | rev = "f66d3cdf6a6bf4510e5181b3fac215054d8f1e2e"; 398 | sha256 = "1jhc2v784jy8bvkqy4zsh2z7pnqrhwa8n5kx98xhxx73n1bf38sg"; 399 | }; 400 | phases = "installPhase"; 401 | installPhase = "ln -s $src $out"; 402 | }; 403 | 404 | "safe-coerce" = pkgs.stdenv.mkDerivation { 405 | name = "safe-coerce"; 406 | version = "v1.0.0"; 407 | src = pkgs.fetchgit { 408 | url = "https://github.com/purescript/purescript-safe-coerce.git"; 409 | rev = "e719defd227d932da067a1f0d62a60b3d3ff3637"; 410 | sha256 = "0m942lc23317izspz1sxw957mwl9yb9bgk8dh23f7b3a8w9hh8ff"; 411 | }; 412 | phases = "installPhase"; 413 | installPhase = "ln -s $src $out"; 414 | }; 415 | 416 | "st" = pkgs.stdenv.mkDerivation { 417 | name = "st"; 418 | version = "v5.0.1"; 419 | src = pkgs.fetchgit { 420 | url = "https://github.com/purescript/purescript-st.git"; 421 | rev = "994eb5e650f3caedac385dcc61694f691df57983"; 422 | sha256 = "14hz254f1y0k3v83z719np0ddrgbca0hdsd9dvv244i07vlvm2zj"; 423 | }; 424 | phases = "installPhase"; 425 | installPhase = "ln -s $src $out"; 426 | }; 427 | 428 | "strings" = pkgs.stdenv.mkDerivation { 429 | name = "strings"; 430 | version = "v5.0.0"; 431 | src = pkgs.fetchgit { 432 | url = "https://github.com/purescript/purescript-strings.git"; 433 | rev = "157e372a23e4becd594d7e7bff6f372a6f63dd82"; 434 | sha256 = "0hyaa4d8gyyvac2nxnwqkn2rvi5vax4bi4yv10mpk7rgb8rv7mb8"; 435 | }; 436 | phases = "installPhase"; 437 | installPhase = "ln -s $src $out"; 438 | }; 439 | 440 | "tailrec" = pkgs.stdenv.mkDerivation { 441 | name = "tailrec"; 442 | version = "v5.0.1"; 443 | src = pkgs.fetchgit { 444 | url = "https://github.com/purescript/purescript-tailrec.git"; 445 | rev = "5fbf0ac05dc6ab1a228b2897630195eb7483b962"; 446 | sha256 = "1jjl2q2hyhjcdxpamzr1cdlxhmq2bl170x5p3jajb9zgwkqx0x22"; 447 | }; 448 | phases = "installPhase"; 449 | installPhase = "ln -s $src $out"; 450 | }; 451 | 452 | "tuples" = pkgs.stdenv.mkDerivation { 453 | name = "tuples"; 454 | version = "v6.0.1"; 455 | src = pkgs.fetchgit { 456 | url = "https://github.com/purescript/purescript-tuples.git"; 457 | rev = "d4fe8ffe9e8c512111ee0bc18a6ba0fd056a6773"; 458 | sha256 = "0s2ar2gih4r34km8r8dqngh21s8899yb93mb7mips08ndy3ajq3a"; 459 | }; 460 | phases = "installPhase"; 461 | installPhase = "ln -s $src $out"; 462 | }; 463 | 464 | "type-equality" = pkgs.stdenv.mkDerivation { 465 | name = "type-equality"; 466 | version = "v4.0.0"; 467 | src = pkgs.fetchgit { 468 | url = "https://github.com/purescript/purescript-type-equality.git"; 469 | rev = "f7644468f22ed267a15d398173d234fa6f45e2e0"; 470 | sha256 = "126pg4zg3bsrn8dzvv75xp586nznxyswzgjlr7cag3ij3j1z0kl0"; 471 | }; 472 | phases = "installPhase"; 473 | installPhase = "ln -s $src $out"; 474 | }; 475 | 476 | "typelevel-prelude" = pkgs.stdenv.mkDerivation { 477 | name = "typelevel-prelude"; 478 | version = "v6.0.0"; 479 | src = pkgs.fetchgit { 480 | url = "https://github.com/purescript/purescript-typelevel-prelude.git"; 481 | rev = "83ddcdb23d06c8d5ea6196596a70438f42cd4afd"; 482 | sha256 = "1vwf3yhn8mir5y41wvlyszkgd5fxvrcyfd0l8cn20c8vfq36yzgk"; 483 | }; 484 | phases = "installPhase"; 485 | installPhase = "ln -s $src $out"; 486 | }; 487 | 488 | "unfoldable" = pkgs.stdenv.mkDerivation { 489 | name = "unfoldable"; 490 | version = "v5.0.0"; 491 | src = pkgs.fetchgit { 492 | url = "https://github.com/purescript/purescript-unfoldable.git"; 493 | rev = "bbcc2b062b9b7d3d61f123cfb32cc8c7fb811aa6"; 494 | sha256 = "1v3bz04wj6hj7s6mcf49hajylg6w58n78q54sqi2ra2zq8h99kpw"; 495 | }; 496 | phases = "installPhase"; 497 | installPhase = "ln -s $src $out"; 498 | }; 499 | 500 | "unsafe-coerce" = pkgs.stdenv.mkDerivation { 501 | name = "unsafe-coerce"; 502 | version = "v5.0.0"; 503 | src = pkgs.fetchgit { 504 | url = "https://github.com/purescript/purescript-unsafe-coerce.git"; 505 | rev = "ee24f0d3b94bf925d9c50fcc2b449579580178c0"; 506 | sha256 = "0l2agnm1k910v4yp1hz19wrsrywsr5scb397762y7pigm3frzs8r"; 507 | }; 508 | phases = "installPhase"; 509 | installPhase = "ln -s $src $out"; 510 | }; 511 | 512 | "variant" = pkgs.stdenv.mkDerivation { 513 | name = "variant"; 514 | version = "v7.1.0"; 515 | src = pkgs.fetchgit { 516 | url = "https://github.com/natefaubion/purescript-variant.git"; 517 | rev = "131d7fb43861ee10825e1c96bd98c4b3358dcc62"; 518 | sha256 = "064aijlcphyg5mjhxx4acwjlnh7ha3v033zzan31rhkqi6m4r3da"; 519 | }; 520 | phases = "installPhase"; 521 | installPhase = "ln -s $src $out"; 522 | }; 523 | 524 | }; 525 | 526 | cpPackage = pkg: 527 | let 528 | target = ".spago/${pkg.name}/${pkg.version}"; 529 | in '' 530 | if [ ! -e ${target} ]; then 531 | echo "Installing ${target}." 532 | mkdir -p ${target} 533 | cp --no-preserve=mode,ownership,timestamp -r ${toString pkg.outPath}/* ${target} 534 | else 535 | echo "${target} already exists. Skipping." 536 | fi 537 | ''; 538 | 539 | getGlob = pkg: ''".spago/${pkg.name}/${pkg.version}/src/**/*.purs"''; 540 | 541 | getStoreGlob = pkg: ''"${pkg.outPath}/src/**/*.purs"''; 542 | 543 | in { 544 | inherit inputs; 545 | 546 | installSpagoStyle = pkgs.writeShellScriptBin "install-spago-style" '' 547 | set -e 548 | echo installing dependencies... 549 | ${builtins.toString (builtins.map cpPackage (builtins.attrValues inputs))} 550 | echo "echo done." 551 | ''; 552 | 553 | buildSpagoStyle = pkgs.writeShellScriptBin "build-spago-style" '' 554 | set -e 555 | echo building project... 556 | purs compile ${builtins.toString (builtins.map getGlob (builtins.attrValues inputs))} "$@" 557 | echo done. 558 | ''; 559 | 560 | buildFromNixStore = pkgs.writeShellScriptBin "build-from-store" '' 561 | set -e 562 | echo building project using sources from nix store... 563 | purs compile ${builtins.toString ( 564 | builtins.map getStoreGlob (builtins.attrValues inputs))} "$@" 565 | echo done. 566 | ''; 567 | 568 | mkBuildProjectOutput = 569 | { src, purs }: 570 | 571 | pkgs.stdenv.mkDerivation { 572 | name = "build-project-output"; 573 | src = src; 574 | 575 | buildInputs = [ purs ]; 576 | 577 | installPhase = '' 578 | mkdir -p $out 579 | purs compile "$src/**/*.purs" ${builtins.toString 580 | (builtins.map 581 | (x: ''"${x.outPath}/src/**/*.purs"'') 582 | (builtins.attrValues inputs))} 583 | mv output $out 584 | ''; 585 | }; 586 | } 587 | -------------------------------------------------------------------------------- /spago.dhall: -------------------------------------------------------------------------------- 1 | {- 2 | Welcome to a Spago project! 3 | You can edit this file as you like. 4 | 5 | Need help? See the following resources: 6 | - Spago documentation: https://github.com/purescript/spago 7 | - Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html 8 | 9 | When creating a new Spago project, you can use 10 | `spago init --no-comments` or `spago init -C` 11 | to generate this file without the comments in this block. 12 | -} 13 | { name = "style" 14 | , dependencies = 15 | [ "arrays" 16 | , "colors" 17 | , "console" 18 | , "effect" 19 | , "integers" 20 | , "maybe" 21 | , "newtype" 22 | , "numbers" 23 | , "prelude" 24 | , "variant" 25 | ] 26 | , packages = ./packages.dhall 27 | , sources = [ "src/**/*.purs", "test/**/*.purs" ] 28 | } 29 | -------------------------------------------------------------------------------- /src/Style/Declaration.purs: -------------------------------------------------------------------------------- 1 | module Style.Declaration where 2 | 3 | import Prelude 4 | 5 | import Color as C 6 | import Data.Variant (expand) 7 | import Style.Declaration.Property (Property(..)) 8 | import Style.Declaration.Property as Property 9 | import Style.Declaration.Value (Value) 10 | import Style.Declaration.Value as V 11 | 12 | data Declaration = Declaration Property Value 13 | 14 | derive instance eqDeclaration :: Eq Declaration 15 | 16 | instance ordDeclaration :: Ord Declaration where 17 | compare (Declaration p1 v1) (Declaration p2 v2) = 18 | p1 `compare` p2 <> V.render v1 `compare` V.render v2 19 | 20 | instance showDeclaration :: Show Declaration where 21 | show (Declaration p v) = "(Declaration " <> show p <> " " <> show v <> ")" 22 | 23 | render :: Declaration -> String 24 | render (Declaration p v) = Property.render p <> ": " <> V.render v <> ";" 25 | 26 | type WSC w s c = 27 | { width :: w 28 | , style :: s 29 | , color :: c 30 | } 31 | 32 | wsc 33 | :: forall w s c 34 | . Property 35 | -> (WSC w s c -> Value) 36 | -> w 37 | -> s 38 | -> c 39 | -> Declaration 40 | wsc p v w s c = Declaration p $ v { width: w, style: s, color: c } 41 | 42 | type TRBL a = 43 | { top :: a 44 | , right :: a 45 | , bottom :: a 46 | , left :: a 47 | } 48 | 49 | trbl 50 | :: forall a 51 | . Property 52 | -> (TRBL a -> Value) 53 | -> a 54 | -> a 55 | -> a 56 | -> a 57 | -> Declaration 58 | trbl p v t r b l = 59 | Declaration p $ v { top: t, right: r, bottom: b, left: l } 60 | 61 | backgroundColor' :: V.BackgroundColorValue -> Declaration 62 | backgroundColor' = Declaration BackgroundColor <<< expand 63 | 64 | backgroundColor :: C.Color -> Declaration 65 | backgroundColor = backgroundColor' <<< V.color_ 66 | 67 | border' 68 | :: V.BorderWidthValue 69 | -> V.BorderStyleValue 70 | -> V.BorderColorValue 71 | -> Declaration 72 | border' = wsc Border V.border 73 | 74 | border 75 | :: V.BorderWidthValue 76 | -> V.BorderStyleValue 77 | -> C.Color 78 | -> Declaration 79 | border w s = border' w s <<< V.color_ 80 | 81 | borderTop' 82 | :: V.BorderWidthValue 83 | -> V.BorderStyleValue 84 | -> V.BorderColorValue 85 | -> Declaration 86 | borderTop' = wsc BorderTop V.border 87 | 88 | borderTop 89 | :: V.BorderWidthValue 90 | -> V.BorderStyleValue 91 | -> C.Color 92 | -> Declaration 93 | borderTop w s = borderTop' w s <<< V.color_ 94 | 95 | borderRight' 96 | :: V.BorderWidthValue 97 | -> V.BorderStyleValue 98 | -> V.BorderColorValue 99 | -> Declaration 100 | borderRight' = wsc BorderRight V.border 101 | 102 | borderRight 103 | :: V.BorderWidthValue 104 | -> V.BorderStyleValue 105 | -> C.Color 106 | -> Declaration 107 | borderRight w s = borderRight' w s <<< V.color_ 108 | 109 | borderBottom' 110 | :: V.BorderWidthValue 111 | -> V.BorderStyleValue 112 | -> V.BorderColorValue 113 | -> Declaration 114 | borderBottom' = wsc BorderBottom V.border 115 | 116 | borderBottom 117 | :: V.BorderWidthValue 118 | -> V.BorderStyleValue 119 | -> C.Color 120 | -> Declaration 121 | borderBottom w s = borderBottom' w s <<< V.color_ 122 | 123 | borderLeft' 124 | :: V.BorderWidthValue 125 | -> V.BorderStyleValue 126 | -> V.BorderColorValue 127 | -> Declaration 128 | borderLeft' = wsc BorderLeft V.border 129 | 130 | borderLeft 131 | :: V.BorderWidthValue 132 | -> V.BorderStyleValue 133 | -> C.Color 134 | -> Declaration 135 | borderLeft w s = borderLeft' w s <<< V.color_ 136 | 137 | borderColor' 138 | :: V.BorderColorValue 139 | -> V.BorderColorValue 140 | -> V.BorderColorValue 141 | -> V.BorderColorValue 142 | -> Declaration 143 | borderColor' = trbl BorderColor V.borderColor 144 | 145 | borderColor 146 | :: C.Color 147 | -> C.Color 148 | -> C.Color 149 | -> C.Color 150 | -> Declaration 151 | borderColor t r b l = 152 | borderColor' (V.color_ t) (V.color_ r) (V.color_ b) (V.color_ l) 153 | 154 | borderTopColor' :: V.BorderColorValue -> Declaration 155 | borderTopColor' = Declaration BorderTopColor <<< expand 156 | 157 | borderTopColor :: C.Color -> Declaration 158 | borderTopColor = borderTopColor' <<< V.color_ 159 | 160 | borderRightColor' :: V.BorderColorValue -> Declaration 161 | borderRightColor' = Declaration BorderRightColor <<< expand 162 | 163 | borderRightColor :: C.Color -> Declaration 164 | borderRightColor = borderRightColor' <<< V.color_ 165 | 166 | borderBottomColor' :: V.BorderColorValue -> Declaration 167 | borderBottomColor' = Declaration BorderBottomColor <<< expand 168 | 169 | borderBottomColor :: C.Color -> Declaration 170 | borderBottomColor = borderBottomColor' <<< V.color_ 171 | 172 | borderLeftColor' :: V.BorderColorValue -> Declaration 173 | borderLeftColor' = Declaration BorderLeftColor <<< expand 174 | 175 | borderLeftColor :: C.Color -> Declaration 176 | borderLeftColor = borderLeftColor' <<< V.color_ 177 | 178 | borderStyle 179 | :: V.BorderStyleValue 180 | -> V.BorderStyleValue 181 | -> V.BorderStyleValue 182 | -> V.BorderStyleValue 183 | -> Declaration 184 | borderStyle = trbl BorderStyle V.borderStyle 185 | 186 | borderTopStyle :: V.BorderStyleValue -> Declaration 187 | borderTopStyle = Declaration BorderTopStyle <<< expand 188 | 189 | borderRightStyle :: V.BorderStyleValue -> Declaration 190 | borderRightStyle = Declaration BorderRightStyle <<< expand 191 | 192 | borderBottomStyle :: V.BorderStyleValue -> Declaration 193 | borderBottomStyle = Declaration BorderBottomStyle <<< expand 194 | 195 | borderLeftStyle :: V.BorderStyleValue -> Declaration 196 | borderLeftStyle = Declaration BorderLeftStyle <<< expand 197 | 198 | borderWidth 199 | :: V.BorderWidthValue 200 | -> V.BorderWidthValue 201 | -> V.BorderWidthValue 202 | -> V.BorderWidthValue 203 | -> Declaration 204 | borderWidth = trbl BorderWidth V.borderWidth 205 | 206 | borderTopWidth :: V.BorderWidthValue -> Declaration 207 | borderTopWidth = Declaration BorderTopWidth <<< expand 208 | 209 | borderRightWidth :: V.BorderWidthValue -> Declaration 210 | borderRightWidth = Declaration BorderRightWidth <<< expand 211 | 212 | borderBottomWidth :: V.BorderWidthValue -> Declaration 213 | borderBottomWidth = Declaration BorderBottomWidth <<< expand 214 | 215 | borderLeftWidth :: V.BorderWidthValue -> Declaration 216 | borderLeftWidth = Declaration BorderLeftWidth <<< expand 217 | 218 | borderRadius 219 | :: V.BorderRadiusValue 220 | -> V.BorderRadiusValue 221 | -> V.BorderRadiusValue 222 | -> V.BorderRadiusValue 223 | -> Declaration 224 | borderRadius tl tr br bl = 225 | Declaration BorderRadius $ V.borderRadius 226 | { topLeft: tl 227 | , topRight: tr 228 | , bottomRight: br 229 | , bottomLeft: bl 230 | } 231 | 232 | borderBottomLeftRadius :: V.BorderRadiusValue -> Declaration 233 | borderBottomLeftRadius = Declaration BorderBottomLeftRadius <<< expand 234 | 235 | borderBottomRightRadius :: V.BorderRadiusValue -> Declaration 236 | borderBottomRightRadius = Declaration BorderBottomRightRadius <<< expand 237 | 238 | borderTopLeftRadius :: V.BorderRadiusValue -> Declaration 239 | borderTopLeftRadius = Declaration BorderTopLeftRadius <<< expand 240 | 241 | borderTopRightRadius :: V.BorderRadiusValue -> Declaration 242 | borderTopRightRadius = Declaration BorderTopRightRadius <<< expand 243 | 244 | boxShadow :: Array V.BoxShadowRep -> Declaration 245 | boxShadow = 246 | Declaration BoxShadow 247 | <<< (expand :: V.BoxShadowValue -> Value) 248 | <<< V.boxShadow 249 | 250 | color' :: V.ColorValue -> Declaration 251 | color' = Declaration Color <<< expand 252 | 253 | color :: C.Color -> Declaration 254 | color = color' <<< V.color_ 255 | 256 | fontSize :: V.FontSizeValue -> Declaration 257 | fontSize = Declaration FontSize <<< expand 258 | 259 | fontWeight :: V.FontWeightValue -> Declaration 260 | fontWeight = Declaration FontWeight <<< expand 261 | 262 | height :: V.HeightValue -> Declaration 263 | height = Declaration Height <<< expand 264 | 265 | margin 266 | :: V.MarginValue 267 | -> V.MarginValue 268 | -> V.MarginValue 269 | -> V.MarginValue 270 | -> Declaration 271 | margin = trbl Margin V.margin 272 | 273 | marginBottom :: V.MarginValue -> Declaration 274 | marginBottom = Declaration MarginBottom <<< expand 275 | 276 | marginLeft :: V.MarginValue -> Declaration 277 | marginLeft = Declaration MarginLeft <<< expand 278 | 279 | marginRight :: V.MarginValue -> Declaration 280 | marginRight = Declaration MarginRight <<< expand 281 | 282 | marginTop :: V.MarginValue -> Declaration 283 | marginTop = Declaration MarginTop <<< expand 284 | 285 | outline' 286 | :: V.OutlineWidthValue 287 | -> V.OutlineStyleValue 288 | -> V.OutlineColorValue 289 | -> Declaration 290 | outline' w s c = Declaration Outline $ V.outline { width: w, style: s, color: c } 291 | 292 | outline 293 | :: V.OutlineWidthValue 294 | -> V.OutlineStyleValue 295 | -> C.Color 296 | -> Declaration 297 | outline w s = outline' w s <<< V.color_ 298 | 299 | outlineColor' :: V.OutlineColorValue -> Declaration 300 | outlineColor' = Declaration OutlineColor <<< expand 301 | 302 | outlineColor :: C.Color -> Declaration 303 | outlineColor = outlineColor' <<< V.color_ 304 | 305 | outlineStyle :: V.OutlineStyleValue -> Declaration 306 | outlineStyle = Declaration OutlineStyle <<< expand 307 | 308 | outlineWidth :: V.OutlineWidthValue -> Declaration 309 | outlineWidth = Declaration OutlineWidth <<< expand 310 | 311 | padding 312 | :: V.PaddingValue 313 | -> V.PaddingValue 314 | -> V.PaddingValue 315 | -> V.PaddingValue 316 | -> Declaration 317 | padding = trbl Padding V.padding 318 | 319 | paddingBottom :: V.PaddingValue -> Declaration 320 | paddingBottom = Declaration PaddingBottom <<< expand 321 | 322 | paddingLeft :: V.PaddingValue -> Declaration 323 | paddingLeft = Declaration PaddingLeft <<< expand 324 | 325 | paddingRight :: V.PaddingValue -> Declaration 326 | paddingRight = Declaration PaddingRight <<< expand 327 | 328 | paddingTop :: V.PaddingValue -> Declaration 329 | paddingTop = Declaration PaddingTop <<< expand 330 | 331 | textAlign :: V.TextAlignValue -> Declaration 332 | textAlign = Declaration TextAlign <<< expand 333 | 334 | width :: V.WidthValue -> Declaration 335 | width = Declaration Width <<< expand 336 | -------------------------------------------------------------------------------- /src/Style/Declaration/Property.purs: -------------------------------------------------------------------------------- 1 | module Style.Declaration.Property where 2 | 3 | import Prelude 4 | 5 | data Property 6 | = BackgroundColor 7 | | Border 8 | | BorderColor 9 | | BorderStyle 10 | | BorderWidth 11 | | BorderTop 12 | | BorderRight 13 | | BorderBottom 14 | | BorderLeft 15 | | BorderBottomColor 16 | | BorderLeftColor 17 | | BorderRightColor 18 | | BorderTopColor 19 | | BorderBottomStyle 20 | | BorderLeftStyle 21 | | BorderRightStyle 22 | | BorderTopStyle 23 | | BorderBottomWidth 24 | | BorderLeftWidth 25 | | BorderRightWidth 26 | | BorderTopWidth 27 | | BorderRadius 28 | | BorderBottomLeftRadius 29 | | BorderBottomRightRadius 30 | | BorderTopLeftRadius 31 | | BorderTopRightRadius 32 | | BoxShadow 33 | | Color 34 | | FontSize 35 | | FontWeight 36 | | Height 37 | | Margin 38 | | MarginBottom 39 | | MarginLeft 40 | | MarginRight 41 | | MarginTop 42 | | Outline 43 | | OutlineColor 44 | | OutlineStyle 45 | | OutlineWidth 46 | | Padding 47 | | PaddingBottom 48 | | PaddingLeft 49 | | PaddingRight 50 | | PaddingTop 51 | | TextAlign 52 | | Width 53 | 54 | derive instance eqProperty :: Eq Property 55 | derive instance ordProperty :: Ord Property 56 | 57 | instance showProperty :: Show Property where 58 | show = case _ of 59 | BackgroundColor -> "BackgroundColor" 60 | Border -> "Border" 61 | BorderColor -> "BorderColor" 62 | BorderStyle -> "BorderStyle" 63 | BorderWidth -> "BorderWidth" 64 | BorderTop -> "BorderTop" 65 | BorderRight -> "BorderRight" 66 | BorderBottom -> "BorderBottom" 67 | BorderLeft -> "BorderLeft" 68 | BorderBottomColor -> "BorderBottomColor" 69 | BorderLeftColor -> "BorderLeftColor" 70 | BorderRightColor -> "BorderRightColor" 71 | BorderTopColor -> "BorderTopColor" 72 | BorderBottomStyle -> "BorderBottomStyle" 73 | BorderLeftStyle -> "BorderLeftStyle" 74 | BorderRightStyle -> "BorderRightStyle" 75 | BorderTopStyle -> "BorderTopStyle" 76 | BorderBottomWidth -> "BorderBottomWidth" 77 | BorderLeftWidth -> "BorderLeftWidth" 78 | BorderRightWidth -> "BorderRightWidth" 79 | BorderTopWidth -> "BorderTopWidth" 80 | BorderRadius -> "BorderRadius" 81 | BorderBottomLeftRadius -> "BorderBottomLeftRadius" 82 | BorderBottomRightRadius -> "BorderBottomRightRadius" 83 | BorderTopLeftRadius -> "BorderTopLeftRadius" 84 | BorderTopRightRadius -> "BorderTopRightRadius" 85 | BoxShadow -> "BoxShadow" 86 | Color -> "Color" 87 | FontSize -> "FontSize" 88 | FontWeight -> "FontWeight" 89 | Height -> "Height" 90 | Margin -> "Margin" 91 | MarginBottom -> "MarginBottom" 92 | MarginLeft -> "MarginLeft" 93 | MarginRight -> "MarginRight" 94 | MarginTop -> "MarginTop" 95 | Outline -> "Outline" 96 | OutlineColor -> "OutlineColor" 97 | OutlineStyle -> "OutlineStyle" 98 | OutlineWidth -> "OutlineWidth" 99 | Padding -> "Padding" 100 | PaddingBottom -> "PaddingBottom" 101 | PaddingLeft -> "PaddingLeft" 102 | PaddingRight -> "PaddingRight" 103 | PaddingTop -> "PaddingTop" 104 | TextAlign -> "TextAlign" 105 | Width -> "Width" 106 | 107 | render :: Property -> String 108 | render = case _ of 109 | BackgroundColor -> "background-color" 110 | Border -> "border" 111 | BorderColor -> "border-color" 112 | BorderStyle -> "border-style" 113 | BorderWidth -> "border-width" 114 | BorderTop -> "border-top" 115 | BorderRight -> "border-right" 116 | BorderBottom -> "border-bottom" 117 | BorderLeft -> "border-left" 118 | BorderBottomColor -> "border-bottom-color" 119 | BorderLeftColor -> "border-left-color" 120 | BorderRightColor -> "border-right-color" 121 | BorderTopColor -> "border-top-color" 122 | BorderBottomStyle -> "border-bottom-style" 123 | BorderLeftStyle -> "border-left-style" 124 | BorderRightStyle -> "border-right-style" 125 | BorderTopStyle -> "border-top-style" 126 | BorderBottomWidth -> "border-bottom-width" 127 | BorderLeftWidth -> "border-left-width" 128 | BorderRightWidth -> "border-right-width" 129 | BorderTopWidth -> "border-top-width" 130 | BorderRadius -> "border-radius" 131 | BorderBottomLeftRadius -> "border-bottom-left-radius" 132 | BorderBottomRightRadius -> "border-bottom-right-radius" 133 | BorderTopLeftRadius -> "border-top-left-radius" 134 | BorderTopRightRadius -> "border-top-right-radius" 135 | BoxShadow -> "box-shadow" 136 | Color -> "color" 137 | FontSize -> "font-size" 138 | FontWeight -> "font-weight" 139 | Height -> "height" 140 | Margin -> "margin" 141 | MarginBottom -> "margin-bottom" 142 | MarginLeft -> "margin-left" 143 | MarginRight -> "margin-right" 144 | MarginTop -> "margin-top" 145 | Outline -> "outline" 146 | OutlineColor -> "outline-color" 147 | OutlineStyle -> "outline-style" 148 | OutlineWidth -> "outline-width" 149 | Padding -> "padding" 150 | PaddingBottom -> "padding-bottom" 151 | PaddingLeft -> "padding-left" 152 | PaddingRight -> "padding-right" 153 | PaddingTop -> "padding-top" 154 | TextAlign -> "text-align" 155 | Width -> "width" 156 | -------------------------------------------------------------------------------- /src/Style/Declaration/Value.purs: -------------------------------------------------------------------------------- 1 | module Style.Declaration.Value where 2 | 3 | import Prelude 4 | 5 | import Color (cssStringHSLA) 6 | import Color as C 7 | import Data.Array as Array 8 | import Data.Number.Format as Number 9 | import Data.Variant (Variant, case_, inj, on) 10 | import Type.Proxy (Proxy(..)) 11 | 12 | -- https://github.com/purescript/purescript/issues/4105#issuecomment-1103324211 13 | type RowApply (f :: Row Type -> Row Type) (a :: Row Type) = f a 14 | 15 | infixr 0 type RowApply as + 16 | 17 | type Value = 18 | Variant 19 | ( Auto 20 | + Bold 21 | + Bolder 22 | + Border 23 | + BorderColor 24 | + BorderStyle 25 | + BorderWidth 26 | + BorderRadius 27 | + BoxShadow 28 | + Center 29 | + Ch 30 | + Cm 31 | + Color_ 32 | + CurrentColor 33 | + Dashed 34 | + Dotted 35 | + Double 36 | + Em 37 | + Ex 38 | + Groove 39 | + Hidden 40 | + In 41 | + Inherit 42 | + Initial 43 | + Inset 44 | + Invert 45 | + Justify 46 | + JustifyAll 47 | + Large 48 | + Larger 49 | + Left 50 | + Lighter 51 | + Margin 52 | + Medium 53 | + Mm 54 | + None 55 | + Normal 56 | + Number_ 57 | + Outline 58 | + Outset 59 | + Padding 60 | + Pc 61 | + Pct 62 | + Pt 63 | + Px 64 | + Rem 65 | + Ridge 66 | + Right 67 | + Small 68 | + Smaller 69 | + Solid 70 | + Thick 71 | + Thin 72 | + Transparent 73 | + Unset 74 | + Vh 75 | + Vmax 76 | + Vmin 77 | + Vw 78 | + XLarge 79 | + XSmall 80 | + XxLarge 81 | + XxSmall 82 | + Zero 83 | + () 84 | ) 85 | 86 | render :: Value -> String 87 | render = 88 | case_ 89 | # renderAuto 90 | >>> renderBold 91 | >>> renderBolder 92 | >>> renderBorder 93 | >>> renderBorderColor 94 | >>> renderBorderStyle 95 | >>> renderBorderWidth 96 | >>> renderBorderRadius 97 | >>> renderBoxShadow 98 | >>> renderCenter 99 | >>> renderCh 100 | >>> renderCm 101 | >>> renderColor_ 102 | >>> renderCurrentColor 103 | >>> renderDashed 104 | >>> renderDotted 105 | >>> renderDouble 106 | >>> renderEm 107 | >>> renderEx 108 | >>> renderGroove 109 | >>> renderHidden 110 | >>> renderIn 111 | >>> renderInherit 112 | >>> renderInitial 113 | >>> renderInset 114 | >>> renderJustify 115 | >>> renderJustifyAll 116 | >>> renderInvert 117 | >>> renderLarge 118 | >>> renderLarger 119 | >>> renderLeft 120 | >>> renderLighter 121 | >>> renderMargin 122 | >>> renderMedium 123 | >>> renderMm 124 | >>> renderNone 125 | >>> renderNormal 126 | >>> renderNumber_ 127 | >>> renderOutline 128 | >>> renderOutset 129 | >>> renderPadding 130 | >>> renderPc 131 | >>> renderPct 132 | >>> renderPt 133 | >>> renderPx 134 | >>> renderRem 135 | >>> renderRidge 136 | >>> renderRight 137 | >>> renderSmall 138 | >>> renderSmaller 139 | >>> renderSolid 140 | >>> renderThick 141 | >>> renderThin 142 | >>> renderTransparent 143 | >>> renderUnset 144 | >>> renderVh 145 | >>> renderVmax 146 | >>> renderVmin 147 | >>> renderVw 148 | >>> renderXLarge 149 | >>> renderXSmall 150 | >>> renderXxLarge 151 | >>> renderXxSmall 152 | >>> renderZero 153 | 154 | -- Standalone values 155 | 156 | type Auto v = (auto :: Unit | v) 157 | 158 | _auto = Proxy :: Proxy "auto" 159 | 160 | auto :: forall v. Variant (Auto v) 161 | auto = inj _auto unit 162 | 163 | renderAuto :: forall v. (Variant v -> String) -> Variant (Auto v) -> String 164 | renderAuto = on _auto $ const "auto" 165 | 166 | type Bold v = (bold :: Unit | v) 167 | 168 | _bold = Proxy :: Proxy "bold" 169 | 170 | bold :: forall v. Variant (Bold v) 171 | bold = inj _bold unit 172 | 173 | renderBold :: forall v. (Variant v -> String) -> Variant (Bold v) -> String 174 | renderBold = on _bold $ const "bold" 175 | 176 | type Bolder v = (bolder :: Unit | v) 177 | 178 | _bolder = Proxy :: Proxy "bolder" 179 | 180 | bolder :: forall v. Variant (Bolder v) 181 | bolder = inj _bolder unit 182 | 183 | renderBolder :: forall v. (Variant v -> String) -> Variant (Bolder v) -> String 184 | renderBolder = on _bolder $ const "bolder" 185 | 186 | type Center v = (center :: Unit | v) 187 | 188 | _center = Proxy :: Proxy "center" 189 | 190 | center :: forall v. Variant (Center v) 191 | center = inj _center unit 192 | 193 | renderCenter :: forall v. (Variant v -> String) -> Variant (Center v) -> String 194 | renderCenter = on _center $ const "center" 195 | 196 | type CurrentColor v = (currentColor :: Unit | v) 197 | 198 | _currentColor = Proxy :: Proxy "currentColor" 199 | 200 | currentColor :: forall v. Variant (CurrentColor v) 201 | currentColor = inj _currentColor unit 202 | 203 | renderCurrentColor :: forall v. (Variant v -> String) -> Variant (CurrentColor v) -> String 204 | renderCurrentColor = on _currentColor $ const "currentColor" 205 | 206 | type Ch v = (ch :: Number | v) 207 | 208 | _ch = Proxy :: Proxy "ch" 209 | 210 | ch :: forall v. Number -> Variant (Ch v) 211 | ch = inj _ch 212 | 213 | renderCh :: forall v. (Variant v -> String) -> Variant (Ch v) -> String 214 | renderCh = on _ch \n -> Number.toString n <> "ch" 215 | 216 | type Cm v = (cm :: Number | v) 217 | 218 | _cm = Proxy :: Proxy "cm" 219 | 220 | cm :: forall v. Number -> Variant (Cm v) 221 | cm = inj _cm 222 | 223 | renderCm :: forall v. (Variant v -> String) -> Variant (Cm v) -> String 224 | renderCm = on _cm \n -> Number.toString n <> "cm" 225 | 226 | type Dashed v = (dashed :: Unit | v) 227 | 228 | _dashed = Proxy :: Proxy "dashed" 229 | 230 | dashed :: forall v. Variant (Dashed v) 231 | dashed = inj _dashed unit 232 | 233 | renderDashed :: forall v. (Variant v -> String) -> Variant (Dashed v) -> String 234 | renderDashed = on _dashed $ const "dashed" 235 | 236 | type Dotted v = (dotted :: Unit | v) 237 | 238 | _dotted = Proxy :: Proxy "dotted" 239 | 240 | dotted :: forall v. Variant (Dotted v) 241 | dotted = inj _dotted unit 242 | 243 | renderDotted :: forall v. (Variant v -> String) -> Variant (Dotted v) -> String 244 | renderDotted = on _dotted $ const "dotted" 245 | 246 | type Double v = (double :: Unit | v) 247 | 248 | _double = Proxy :: Proxy "double" 249 | 250 | double :: forall v. Variant (Double v) 251 | double = inj _double unit 252 | 253 | renderDouble :: forall v. (Variant v -> String) -> Variant (Double v) -> String 254 | renderDouble = on _double $ const "double" 255 | 256 | type Em v = (em :: Number | v) 257 | 258 | _em = Proxy :: Proxy "em" 259 | 260 | em :: forall v. Number -> Variant (Em v) 261 | em = inj _em 262 | 263 | renderEm :: forall v. (Variant v -> String) -> Variant (Em v) -> String 264 | renderEm = on _em \n -> Number.toString n <> "em" 265 | 266 | type Ex v = (ex :: Number | v) 267 | 268 | _ex = Proxy :: Proxy "ex" 269 | 270 | ex :: forall v. Number -> Variant (Ex v) 271 | ex = inj _ex 272 | 273 | renderEx :: forall v. (Variant v -> String) -> Variant (Ex v) -> String 274 | renderEx = on _ex \n -> Number.toString n <> "ex" 275 | 276 | type In v = (in :: Number | v) 277 | 278 | _in = Proxy :: Proxy "in" 279 | 280 | in_ :: forall v. Number -> Variant (In v) 281 | in_ = inj _in 282 | 283 | renderIn :: forall v. (Variant v -> String) -> Variant (In v) -> String 284 | renderIn = on _in \n -> Number.toString n <> "in" 285 | 286 | type Inherit v = (inherit :: Unit | v) 287 | 288 | _inherit = Proxy :: Proxy "inherit" 289 | 290 | inherit :: forall v. Variant (Inherit v) 291 | inherit = inj _inherit unit 292 | 293 | renderInherit :: forall v. (Variant v -> String) -> Variant (Inherit v) -> String 294 | renderInherit = on _inherit $ const "inherit" 295 | 296 | type Initial v = (initial :: Unit | v) 297 | 298 | _initial = Proxy :: Proxy "initial" 299 | 300 | initial :: forall v. Variant (Initial v) 301 | initial = inj _initial unit 302 | 303 | renderInitial :: forall v. (Variant v -> String) -> Variant (Initial v) -> String 304 | renderInitial = on _initial $ const "initial" 305 | 306 | type Invert v = (invert :: Unit | v) 307 | 308 | _invert = Proxy :: Proxy "invert" 309 | 310 | invert :: forall v. Variant (Invert v) 311 | invert = inj _invert unit 312 | 313 | renderInvert :: forall v. (Variant v -> String) -> Variant (Invert v) -> String 314 | renderInvert = on _invert $ const "invert" 315 | 316 | type Justify v = (justify :: Unit | v) 317 | 318 | _justify = Proxy :: Proxy "justify" 319 | 320 | justify :: forall v. Variant (Justify v) 321 | justify = inj _justify unit 322 | 323 | renderJustify :: forall v. (Variant v -> String) -> Variant (Justify v) -> String 324 | renderJustify = on _justify $ const "justify" 325 | 326 | type JustifyAll v = (justifyAll :: Unit | v) 327 | 328 | _justifyAll = Proxy :: Proxy "justifyAll" 329 | 330 | justifyAll :: forall v. Variant (JustifyAll v) 331 | justifyAll = inj _justifyAll unit 332 | 333 | renderJustifyAll :: forall v. (Variant v -> String) -> Variant (JustifyAll v) -> String 334 | renderJustifyAll = on _justifyAll $ const "justify-all" 335 | 336 | type Groove v = (groove :: Unit | v) 337 | 338 | _groove = Proxy :: Proxy "groove" 339 | 340 | groove :: forall v. Variant (Groove v) 341 | groove = inj _groove unit 342 | 343 | renderGroove :: forall v. (Variant v -> String) -> Variant (Groove v) -> String 344 | renderGroove = on _groove $ const "groove" 345 | 346 | type Hidden v = (hidden :: Unit | v) 347 | 348 | _hidden = Proxy :: Proxy "hidden" 349 | 350 | hidden :: forall v. Variant (Hidden v) 351 | hidden = inj _hidden unit 352 | 353 | renderHidden :: forall v. (Variant v -> String) -> Variant (Hidden v) -> String 354 | renderHidden = on _hidden $ const "hidden" 355 | 356 | type Inset v = (inset :: Unit | v) 357 | 358 | _inset = Proxy :: Proxy "inset" 359 | 360 | inset :: forall v. Variant (Inset v) 361 | inset = inj _inset unit 362 | 363 | renderInset :: forall v. (Variant v -> String) -> Variant (Inset v) -> String 364 | renderInset = on _inset $ const "inset" 365 | 366 | type Large v = (large :: Unit | v) 367 | 368 | _large = Proxy :: Proxy "large" 369 | 370 | large :: forall v. Variant (Large v) 371 | large = inj _large unit 372 | 373 | renderLarge :: forall v. (Variant v -> String) -> Variant (Large v) -> String 374 | renderLarge = on _large $ const "large" 375 | 376 | type Larger v = (larger :: Unit | v) 377 | 378 | _larger = Proxy :: Proxy "larger" 379 | 380 | larger :: forall v. Variant (Larger v) 381 | larger = inj _larger unit 382 | 383 | renderLarger :: forall v. (Variant v -> String) -> Variant (Larger v) -> String 384 | renderLarger = on _larger $ const "larger" 385 | 386 | type Left v = (left :: Unit | v) 387 | 388 | _left = Proxy :: Proxy "left" 389 | 390 | left :: forall v. Variant (Left v) 391 | left = inj _left unit 392 | 393 | renderLeft :: forall v. (Variant v -> String) -> Variant (Left v) -> String 394 | renderLeft = on _left $ const "left" 395 | 396 | type Lighter v = (lighter :: Unit | v) 397 | 398 | _lighter = Proxy :: Proxy "lighter" 399 | 400 | lighter :: forall v. Variant (Lighter v) 401 | lighter = inj _lighter unit 402 | 403 | renderLighter :: forall v. (Variant v -> String) -> Variant (Lighter v) -> String 404 | renderLighter = on _lighter $ const "lighter" 405 | 406 | type Medium v = (medium :: Unit | v) 407 | 408 | _medium = Proxy :: Proxy "medium" 409 | 410 | medium :: forall v. Variant (Medium v) 411 | medium = inj _medium unit 412 | 413 | renderMedium :: forall v. (Variant v -> String) -> Variant (Medium v) -> String 414 | renderMedium = on _medium $ const "medium" 415 | 416 | type Mm v = (mm :: Number | v) 417 | 418 | _mm = Proxy :: Proxy "mm" 419 | 420 | mm :: forall v. Number -> Variant (Mm v) 421 | mm = inj _mm 422 | 423 | renderMm :: forall v. (Variant v -> String) -> Variant (Mm v) -> String 424 | renderMm = on _mm \n -> Number.toString n <> "mm" 425 | 426 | type None v = (none :: Unit | v) 427 | 428 | _none = Proxy :: Proxy "none" 429 | 430 | none :: forall v. Variant (None v) 431 | none = inj _none unit 432 | 433 | renderNone :: forall v. (Variant v -> String) -> Variant (None v) -> String 434 | renderNone = on _none $ const "none" 435 | 436 | type Normal v = (normal :: Unit | v) 437 | 438 | _normal = Proxy :: Proxy "normal" 439 | 440 | normal :: forall v. Variant (Normal v) 441 | normal = inj _normal unit 442 | 443 | renderNormal :: forall v. (Variant v -> String) -> Variant (Normal v) -> String 444 | renderNormal = on _normal $ const "normal" 445 | 446 | type Outset v = (outset :: Unit | v) 447 | 448 | _outset = Proxy :: Proxy "outset" 449 | 450 | outset :: forall v. Variant (Outset v) 451 | outset = inj _outset unit 452 | 453 | renderOutset :: forall v. (Variant v -> String) -> Variant (Outset v) -> String 454 | renderOutset = on _outset $ const "outset" 455 | 456 | type Pc v = (pc :: Number | v) 457 | 458 | _pc = Proxy :: Proxy "pc" 459 | 460 | pc :: forall v. Number -> Variant (Pc v) 461 | pc = inj _pc 462 | 463 | renderPc :: forall v. (Variant v -> String) -> Variant (Pc v) -> String 464 | renderPc = on _pc \n -> Number.toString n <> "pc" 465 | 466 | type Pct v = (pct :: Number | v) 467 | 468 | _pct = Proxy :: Proxy "pct" 469 | 470 | pct :: forall v. Number -> Variant (Pct v) 471 | pct = inj _pct 472 | 473 | renderPct :: forall v. (Variant v -> String) -> Variant (Pct v) -> String 474 | renderPct = on _pct \n -> Number.toString n <> "pct" 475 | 476 | type Pt v = (pt :: Number | v) 477 | 478 | _pt = Proxy :: Proxy "pt" 479 | 480 | pt :: forall v. Number -> Variant (Pt v) 481 | pt = inj _pt 482 | 483 | renderPt :: forall v. (Variant v -> String) -> Variant (Pt v) -> String 484 | renderPt = on _pt \n -> Number.toString n <> "pt" 485 | 486 | type Px v = (px :: Number | v) 487 | 488 | _px = Proxy :: Proxy "px" 489 | 490 | px :: forall v. Number -> Variant (Px v) 491 | px = inj _px 492 | 493 | renderPx :: forall v. (Variant v -> String) -> Variant (Px v) -> String 494 | renderPx = on _px \n -> Number.toString n <> "px" 495 | 496 | type Rem v = (rem :: Number | v) 497 | 498 | _rem = Proxy :: Proxy "rem" 499 | 500 | rem :: forall v. Number -> Variant (Rem v) 501 | rem = inj _rem 502 | 503 | renderRem :: forall v. (Variant v -> String) -> Variant (Rem v) -> String 504 | renderRem = on _rem \n -> Number.toString n <> "rem" 505 | 506 | type Ridge v = (ridge :: Unit | v) 507 | 508 | _ridge = Proxy :: Proxy "ridge" 509 | 510 | ridge :: forall v. Variant (Ridge v) 511 | ridge = inj _ridge unit 512 | 513 | renderRidge :: forall v. (Variant v -> String) -> Variant (Ridge v) -> String 514 | renderRidge = on _ridge $ const "ridge" 515 | 516 | type Right v = (right :: Unit | v) 517 | 518 | _right = Proxy :: Proxy "right" 519 | 520 | right :: forall v. Variant (Right v) 521 | right = inj _right unit 522 | 523 | renderRight :: forall v. (Variant v -> String) -> Variant (Right v) -> String 524 | renderRight = on _right $ const "right" 525 | 526 | type Small v = (small :: Unit | v) 527 | 528 | _small = Proxy :: Proxy "small" 529 | 530 | small :: forall v. Variant (Small v) 531 | small = inj _small unit 532 | 533 | renderSmall :: forall v. (Variant v -> String) -> Variant (Small v) -> String 534 | renderSmall = on _small $ const "small" 535 | 536 | type Smaller v = (smaller :: Unit | v) 537 | 538 | _smaller = Proxy :: Proxy "smaller" 539 | 540 | smaller :: forall v. Variant (Smaller v) 541 | smaller = inj _smaller unit 542 | 543 | renderSmaller :: forall v. (Variant v -> String) -> Variant (Smaller v) -> String 544 | renderSmaller = on _smaller $ const "smaller" 545 | 546 | type Solid v = (solid :: Unit | v) 547 | 548 | _solid = Proxy :: Proxy "solid" 549 | 550 | solid :: forall v. Variant (Solid v) 551 | solid = inj _solid unit 552 | 553 | renderSolid :: forall v. (Variant v -> String) -> Variant (Solid v) -> String 554 | renderSolid = on _solid $ const "solid" 555 | 556 | type Thick v = (thick :: Unit | v) 557 | 558 | _thick = Proxy :: Proxy "thick" 559 | 560 | thick :: forall v. Variant (Thick v) 561 | thick = inj _thick unit 562 | 563 | renderThick :: forall v. (Variant v -> String) -> Variant (Thick v) -> String 564 | renderThick = on _thick $ const "thick" 565 | 566 | type Thin v = (thin :: Unit | v) 567 | 568 | _thin = Proxy :: Proxy "thin" 569 | 570 | thin :: forall v. Variant (Thin v) 571 | thin = inj _thin unit 572 | 573 | renderThin :: forall v. (Variant v -> String) -> Variant (Thin v) -> String 574 | renderThin = on _thin $ const "thin" 575 | 576 | type Transparent v = (transparent :: Unit | v) 577 | 578 | _transparent = Proxy :: Proxy "transparent" 579 | 580 | transparent :: forall v. Variant (Transparent v) 581 | transparent = inj _transparent unit 582 | 583 | renderTransparent :: forall v. (Variant v -> String) -> Variant (Transparent v) -> String 584 | renderTransparent = on _transparent $ const "transparent" 585 | 586 | type Unset v = (unset :: Unit | v) 587 | 588 | _unset = Proxy :: Proxy "unset" 589 | 590 | unset :: forall v. Variant (Unset v) 591 | unset = inj _unset unit 592 | 593 | renderUnset :: forall v. (Variant v -> String) -> Variant (Unset v) -> String 594 | renderUnset = on _unset $ const "unset" 595 | 596 | type Vh v = (vh :: Number | v) 597 | 598 | _vh = Proxy :: Proxy "vh" 599 | 600 | vh :: forall v. Number -> Variant (Vh v) 601 | vh = inj _vh 602 | 603 | renderVh :: forall v. (Variant v -> String) -> Variant (Vh v) -> String 604 | renderVh = on _vh \n -> Number.toString n <> "vh" 605 | 606 | type Vmax v = (vmax :: Number | v) 607 | 608 | _vmax = Proxy :: Proxy "vmax" 609 | 610 | vmax :: forall v. Number -> Variant (Vmax v) 611 | vmax = inj _vmax 612 | 613 | renderVmax :: forall v. (Variant v -> String) -> Variant (Vmax v) -> String 614 | renderVmax = on _vmax \n -> Number.toString n <> "vmax" 615 | 616 | type Vmin v = (vmin :: Number | v) 617 | 618 | _vmin = Proxy :: Proxy "vmin" 619 | 620 | vmin :: forall v. Number -> Variant (Vmin v) 621 | vmin = inj _vmin 622 | 623 | renderVmin :: forall v. (Variant v -> String) -> Variant (Vmin v) -> String 624 | renderVmin = on _vmin \n -> Number.toString n <> "vmin" 625 | 626 | type Vw v = (vw :: Number | v) 627 | 628 | _vw = Proxy :: Proxy "vw" 629 | 630 | vw :: forall v. Number -> Variant (Vw v) 631 | vw = inj _vw 632 | 633 | renderVw :: forall v. (Variant v -> String) -> Variant (Vw v) -> String 634 | renderVw = on _vw \n -> Number.toString n <> "vw" 635 | 636 | type XLarge v = (xLarge :: Unit | v) 637 | 638 | _xLarge = Proxy :: Proxy "xLarge" 639 | 640 | xLarge :: forall v. Variant (XLarge v) 641 | xLarge = inj _xLarge unit 642 | 643 | renderXLarge :: forall v. (Variant v -> String) -> Variant (XLarge v) -> String 644 | renderXLarge = on _xLarge $ const "x-large" 645 | 646 | type XSmall v = (xSmall :: Unit | v) 647 | 648 | _xSmall = Proxy :: Proxy "xSmall" 649 | 650 | xSmall :: forall v. Variant (XSmall v) 651 | xSmall = inj _xSmall unit 652 | 653 | renderXSmall :: forall v. (Variant v -> String) -> Variant (XSmall v) -> String 654 | renderXSmall = on _xSmall $ const "x-small" 655 | 656 | type XxLarge v = (xxLarge :: Unit | v) 657 | 658 | _xxLarge = Proxy :: Proxy "xxLarge" 659 | 660 | xxLarge :: forall v. Variant (XxLarge v) 661 | xxLarge = inj _xxLarge unit 662 | 663 | renderXxLarge :: forall v. (Variant v -> String) -> Variant (XxLarge v) -> String 664 | renderXxLarge = on _xxLarge $ const "xx-large" 665 | 666 | type XxSmall v = (xxSmall :: Unit | v) 667 | 668 | _xxSmall = Proxy :: Proxy "xxSmall" 669 | 670 | xxSmall :: forall v. Variant (XxSmall v) 671 | xxSmall = inj _xxSmall unit 672 | 673 | renderXxSmall :: forall v. (Variant v -> String) -> Variant (XxSmall v) -> String 674 | renderXxSmall = on _xxSmall $ const "xx-small" 675 | 676 | -- Property values 677 | 678 | type BackgroundColorValue = Variant (BackgroundColorFields ()) 679 | 680 | type BackgroundColorFields r = 681 | ( ColorFields 682 | + GlobalFields 683 | + r 684 | ) 685 | 686 | type BorderRadiusValue = Variant (BorderRadiusFields ()) 687 | 688 | type BorderRadiusFields r = 689 | ( GlobalFields 690 | + LengthFields 691 | + Pct 692 | + Zero 693 | + r 694 | ) 695 | 696 | type BoxShadowValue = Variant (BoxShadowFields ()) 697 | 698 | type BoxShadowFields r = 699 | ( BoxShadow 700 | + GlobalFields 701 | + r 702 | ) 703 | 704 | type ColorValue = Variant (ColorValueFields ()) 705 | 706 | type ColorValueFields r = 707 | ( ColorFields 708 | + GlobalFields 709 | + r 710 | ) 711 | 712 | type FontSizeValue = Variant (FontSizeValueFields ()) 713 | 714 | type FontSizeValueFields r = 715 | ( AbsoluteSizeFields 716 | + GlobalFields 717 | + LengthFields 718 | + Pct 719 | + RelativeSizeFields 720 | + Zero 721 | + r 722 | ) 723 | 724 | type FontWeightValue = Variant (FontWeightValueFields ()) 725 | 726 | type FontWeightValueFields r = 727 | ( FontWeightKeywordFields 728 | + FontWeightKeywordRelativeFields 729 | + GlobalFields 730 | + Number_ 731 | + r 732 | ) 733 | 734 | type HeightValue = Variant (HeightValueFields ()) 735 | 736 | type HeightValueFields r = 737 | ( Auto 738 | + GlobalFields 739 | + LengthFields 740 | + Pct 741 | + Zero 742 | + r 743 | ) 744 | 745 | type TextAlignValue = Variant (TextAlignValueFields ()) 746 | 747 | type TextAlignValueFields r = 748 | ( Center 749 | + GlobalFields 750 | + Justify 751 | + JustifyAll 752 | + Left 753 | + Right 754 | + r 755 | ) 756 | 757 | type WidthValue = Variant (WidthValueFields ()) 758 | 759 | type WidthValueFields r = 760 | ( Auto 761 | + GlobalFields 762 | + LengthFields 763 | + Pct 764 | + Zero 765 | + r 766 | ) 767 | 768 | -- Helpers 769 | 770 | type Color_ v = (color_ :: C.Color | v) 771 | 772 | _color_ = Proxy :: Proxy "color_" 773 | 774 | color_ :: forall v. C.Color -> Variant (ColorFields v) 775 | color_ = inj _color_ 776 | 777 | renderColor_ :: forall v. (Variant v -> String) -> Variant (Color_ v) -> String 778 | renderColor_ = on _color_ cssStringHSLA 779 | 780 | type Number_ v = (number_ :: Number | v) 781 | 782 | _number_ = Proxy :: Proxy "number_" 783 | 784 | number_ :: forall v. Number -> Variant (Number_ v) 785 | number_ = inj _number_ 786 | 787 | renderNumber_ :: forall v. (Variant v -> String) -> Variant (Number_ v) -> String 788 | renderNumber_ = on _number_ Number.toString 789 | 790 | type Zero v = (zero :: Unit | v) 791 | 792 | _zero = Proxy :: Proxy "zero" 793 | 794 | zero :: forall v. Variant (Zero v) 795 | zero = inj _zero unit 796 | 797 | renderZero :: forall v. (Variant v -> String) -> Variant (Zero v) -> String 798 | renderZero = on _zero $ const "0" 799 | 800 | -- Shorthand property values 801 | 802 | type Border v = (border :: BorderRep | v) 803 | 804 | type BorderRep = 805 | { width :: BorderWidthValue 806 | , style :: BorderStyleValue 807 | , color :: BorderColorValue 808 | } 809 | 810 | _border = Proxy :: Proxy "border" 811 | 812 | border :: forall v. BorderRep -> Variant (Border v) 813 | border = inj _border 814 | 815 | renderBorder 816 | :: forall v 817 | . (Variant v -> String) 818 | -> Variant (Border v) 819 | -> String 820 | renderBorder = on _border \b -> 821 | Array.intercalate " " 822 | [ renderBorderWidthFields case_ $ b.width 823 | , renderBorderStyleFields case_ $ b.style 824 | , renderBorderColorFields case_ $ b.color 825 | ] 826 | 827 | type BorderColor v = (borderColor :: BorderColorRep | v) 828 | 829 | type BorderColorRep = 830 | { top :: BorderColorValue 831 | , right :: BorderColorValue 832 | , bottom :: BorderColorValue 833 | , left :: BorderColorValue 834 | } 835 | 836 | type BorderColorValue = Variant (BorderColorFields ()) 837 | 838 | type BorderColorFields r = 839 | ( ColorFields 840 | + GlobalFields 841 | + r 842 | ) 843 | 844 | _borderColor = Proxy :: Proxy "borderColor" 845 | 846 | borderColor :: forall v. BorderColorRep -> Variant (BorderColor v) 847 | borderColor = inj _borderColor 848 | 849 | renderBorderColorFields 850 | :: forall v 851 | . (Variant v -> String) 852 | -> Variant (BorderColorFields v) 853 | -> String 854 | renderBorderColorFields = renderColorFields >>> renderGlobalFields 855 | 856 | renderBorderColor 857 | :: forall v 858 | . (Variant v -> String) 859 | -> Variant (BorderColor v) 860 | -> String 861 | renderBorderColor = on _borderColor \s -> 862 | Array.intercalate " " 863 | [ renderBorderColorFields case_ $ s.top 864 | , renderBorderColorFields case_ $ s.right 865 | , renderBorderColorFields case_ $ s.bottom 866 | , renderBorderColorFields case_ $ s.left 867 | ] 868 | 869 | type BorderStyle v = (borderStyle :: BorderStyleRep | v) 870 | 871 | type BorderStyleRep = 872 | { top :: BorderStyleValue 873 | , right :: BorderStyleValue 874 | , bottom :: BorderStyleValue 875 | , left :: BorderStyleValue 876 | } 877 | 878 | type BorderStyleValue = Variant (BorderStyleFields ()) 879 | 880 | type BorderStyleFields r = 881 | ( Dashed 882 | + Dotted 883 | + Double 884 | + GlobalFields 885 | + Groove 886 | + Hidden 887 | + Inset 888 | + None 889 | + Outset 890 | + Ridge 891 | + Solid 892 | + r 893 | ) 894 | 895 | _borderStyle = Proxy :: Proxy "borderStyle" 896 | 897 | borderStyle :: forall v. BorderStyleRep -> Variant (BorderStyle v) 898 | borderStyle = inj _borderStyle 899 | 900 | renderBorderStyleFields 901 | :: forall v 902 | . (Variant v -> String) 903 | -> Variant (BorderStyleFields v) 904 | -> String 905 | renderBorderStyleFields = 906 | renderDashed 907 | >>> renderDotted 908 | >>> renderDouble 909 | >>> renderGlobalFields 910 | >>> renderGroove 911 | >>> renderHidden 912 | >>> renderInset 913 | >>> renderNone 914 | >>> renderOutset 915 | >>> renderRidge 916 | >>> renderSolid 917 | 918 | renderBorderStyle 919 | :: forall v 920 | . (Variant v -> String) 921 | -> Variant (BorderStyle v) 922 | -> String 923 | renderBorderStyle = on _borderStyle \s -> 924 | Array.intercalate " " 925 | [ renderBorderStyleFields case_ $ s.top 926 | , renderBorderStyleFields case_ $ s.right 927 | , renderBorderStyleFields case_ $ s.bottom 928 | , renderBorderStyleFields case_ $ s.left 929 | ] 930 | 931 | type BorderWidth v = (borderWidth :: BorderWidthRep | v) 932 | 933 | type BorderWidthRep = 934 | { top :: BorderWidthValue 935 | , right :: BorderWidthValue 936 | , bottom :: BorderWidthValue 937 | , left :: BorderWidthValue 938 | } 939 | 940 | type BorderWidthValue = Variant (BorderWidthFields ()) 941 | 942 | type BorderWidthFields r = 943 | ( GlobalFields 944 | + LengthFields 945 | + BorderWidthKeywordFields 946 | + Zero 947 | + r 948 | ) 949 | 950 | _borderWidth = Proxy :: Proxy "borderWidth" 951 | 952 | borderWidth :: forall v. BorderWidthRep -> Variant (BorderWidth v) 953 | borderWidth = inj _borderWidth 954 | 955 | renderBorderWidthFields 956 | :: forall v 957 | . (Variant v -> String) 958 | -> Variant (BorderWidthFields v) 959 | -> String 960 | renderBorderWidthFields = 961 | renderBorderWidthKeywordFields 962 | >>> renderGlobalFields 963 | >>> renderLengthFields 964 | >>> renderZero 965 | 966 | renderBorderWidth 967 | :: forall v 968 | . (Variant v -> String) 969 | -> Variant (BorderWidth v) 970 | -> String 971 | renderBorderWidth = on _borderWidth \s -> 972 | Array.intercalate " " 973 | [ renderBorderWidthFields case_ $ s.top 974 | , renderBorderWidthFields case_ $ s.right 975 | , renderBorderWidthFields case_ $ s.bottom 976 | , renderBorderWidthFields case_ $ s.left 977 | ] 978 | 979 | type BorderRadius v = (borderRadius :: BorderRadiusRep | v) 980 | 981 | type BorderRadiusRep = 982 | { topLeft :: BorderRadiusValue 983 | , topRight :: BorderRadiusValue 984 | , bottomRight :: BorderRadiusValue 985 | , bottomLeft :: BorderRadiusValue 986 | } 987 | 988 | _borderRadius = Proxy :: Proxy "borderRadius" 989 | 990 | borderRadius :: forall v. BorderRadiusRep -> Variant (BorderRadius v) 991 | borderRadius = inj _borderRadius 992 | 993 | renderBorderRadiusFields 994 | :: forall v 995 | . (Variant v -> String) 996 | -> Variant (BorderRadiusFields v) 997 | -> String 998 | renderBorderRadiusFields = 999 | renderGlobalFields 1000 | >>> renderLengthFields 1001 | >>> renderPct 1002 | >>> renderZero 1003 | 1004 | renderBorderRadius 1005 | :: forall v 1006 | . (Variant v -> String) 1007 | -> Variant (BorderRadius v) 1008 | -> String 1009 | renderBorderRadius = on _borderRadius \r -> 1010 | Array.intercalate " " 1011 | [ renderBorderRadiusFields case_ $ r.topLeft 1012 | , renderBorderRadiusFields case_ $ r.topRight 1013 | , renderBorderRadiusFields case_ $ r.bottomRight 1014 | , renderBorderRadiusFields case_ $ r.bottomLeft 1015 | ] 1016 | 1017 | type BoxShadow v = (boxShadow :: Array BoxShadowRep | v) 1018 | 1019 | type BoxShadowRep = 1020 | { inset :: Boolean 1021 | , offsetX :: Variant (LengthFields_ ()) 1022 | , offsetY :: Variant (LengthFields_ ()) 1023 | , blurRadius :: Variant (LengthFields_ ()) 1024 | , spreadRadius :: Variant (LengthFields_ ()) 1025 | , color :: Variant (ColorFields ()) 1026 | } 1027 | 1028 | boxShadow_' 1029 | :: Boolean 1030 | -> Variant (LengthFields_ ()) 1031 | -> Variant (LengthFields_ ()) 1032 | -> Variant (LengthFields_ ()) 1033 | -> Variant (LengthFields_ ()) 1034 | -> Variant (ColorFields ()) 1035 | -> BoxShadowRep 1036 | boxShadow_' = 1037 | { inset: _ 1038 | , offsetX: _ 1039 | , offsetY: _ 1040 | , blurRadius: _ 1041 | , spreadRadius: _ 1042 | , color: _ 1043 | } 1044 | 1045 | boxShadow_ 1046 | :: Boolean 1047 | -> Variant (LengthFields_ ()) 1048 | -> Variant (LengthFields_ ()) 1049 | -> Variant (LengthFields_ ()) 1050 | -> Variant (LengthFields_ ()) 1051 | -> C.Color 1052 | -> BoxShadowRep 1053 | boxShadow_ i x y b s = boxShadow_' i x y b s <<< color_ 1054 | 1055 | _boxShadow = Proxy :: Proxy "boxShadow" 1056 | 1057 | boxShadow :: forall v. Array BoxShadowRep -> Variant (BoxShadow v) 1058 | boxShadow = inj _boxShadow 1059 | 1060 | renderBoxShadow 1061 | :: forall v 1062 | . (Variant v -> String) 1063 | -> Variant (BoxShadow v) 1064 | -> String 1065 | renderBoxShadow = on _boxShadow renderShadows 1066 | where 1067 | 1068 | renderShadows :: Array BoxShadowRep -> String 1069 | renderShadows = Array.intercalate ", " <<< map renderShadow 1070 | 1071 | renderShadow :: BoxShadowRep -> String 1072 | renderShadow shadow = 1073 | shadowInset <> Array.intercalate " " 1074 | [ renderLengthFields_ case_ $ shadow.offsetX 1075 | , renderLengthFields_ case_ $ shadow.offsetY 1076 | , renderLengthFields_ case_ $ shadow.blurRadius 1077 | , renderLengthFields_ case_ $ shadow.spreadRadius 1078 | , renderColorFields case_ $ shadow.color 1079 | ] 1080 | 1081 | where 1082 | 1083 | shadowInset :: String 1084 | shadowInset 1085 | | shadow.inset = "inset " 1086 | | otherwise = "" 1087 | 1088 | type Margin v = (margin :: MarginRep | v) 1089 | 1090 | type MarginRep = 1091 | { top :: MarginValue 1092 | , right :: MarginValue 1093 | , bottom :: MarginValue 1094 | , left :: MarginValue 1095 | } 1096 | 1097 | type MarginValue = Variant (MarginFields ()) 1098 | 1099 | type MarginFields r = 1100 | ( Auto 1101 | + GlobalFields 1102 | + LengthFields 1103 | + Pct 1104 | + Zero 1105 | + r 1106 | ) 1107 | 1108 | _margin = Proxy :: Proxy "margin" 1109 | 1110 | margin :: forall v. MarginRep -> Variant (Margin v) 1111 | margin = inj _margin 1112 | 1113 | renderMarginFields 1114 | :: forall v 1115 | . (Variant v -> String) 1116 | -> Variant (MarginFields v) 1117 | -> String 1118 | renderMarginFields = 1119 | renderAuto 1120 | >>> renderGlobalFields 1121 | >>> renderLengthFields 1122 | >>> renderPct 1123 | >>> renderZero 1124 | 1125 | renderMargin 1126 | :: forall v 1127 | . (Variant v -> String) 1128 | -> Variant (Margin v) 1129 | -> String 1130 | renderMargin = on _margin \m -> 1131 | Array.intercalate " " 1132 | [ renderMarginFields case_ $ m.top 1133 | , renderMarginFields case_ $ m.right 1134 | , renderMarginFields case_ $ m.bottom 1135 | , renderMarginFields case_ $ m.left 1136 | ] 1137 | 1138 | type Outline v = (outline :: OutlineRep | v) 1139 | 1140 | type OutlineRep = 1141 | { width :: OutlineWidthValue 1142 | , style :: OutlineStyleValue 1143 | , color :: OutlineColorValue 1144 | } 1145 | 1146 | _outline = Proxy :: Proxy "outline" 1147 | 1148 | outline :: forall v. OutlineRep -> Variant (Outline v) 1149 | outline = inj _outline 1150 | 1151 | renderOutline 1152 | :: forall v 1153 | . (Variant v -> String) 1154 | -> Variant (Outline v) 1155 | -> String 1156 | renderOutline = on _outline \o -> 1157 | Array.intercalate " " 1158 | [ renderOutlineWidthFields case_ $ o.width 1159 | , renderOutlineStyleFields case_ $ o.style 1160 | , renderOutlineColorFields case_ $ o.color 1161 | ] 1162 | 1163 | type OutlineColorValue = Variant (OutlineColorFields ()) 1164 | 1165 | type OutlineColorFields r = 1166 | ( ColorFields 1167 | + GlobalFields 1168 | + Invert 1169 | + r 1170 | ) 1171 | 1172 | renderOutlineColorFields 1173 | :: forall v 1174 | . (Variant v -> String) 1175 | -> Variant (OutlineColorFields v) 1176 | -> String 1177 | renderOutlineColorFields = 1178 | renderColorFields 1179 | >>> renderGlobalFields 1180 | >>> renderInvert 1181 | 1182 | type OutlineStyleValue = Variant (OutlineStyleFields ()) 1183 | 1184 | type OutlineStyleFields r = 1185 | ( Auto 1186 | + Dashed 1187 | + Dotted 1188 | + Double 1189 | + GlobalFields 1190 | + Groove 1191 | + Inset 1192 | + None 1193 | + Outset 1194 | + Ridge 1195 | + Solid 1196 | + r 1197 | ) 1198 | 1199 | renderOutlineStyleFields 1200 | :: forall v 1201 | . (Variant v -> String) 1202 | -> Variant (OutlineStyleFields v) 1203 | -> String 1204 | renderOutlineStyleFields = 1205 | renderAuto 1206 | >>> renderDashed 1207 | >>> renderDotted 1208 | >>> renderDouble 1209 | >>> renderGlobalFields 1210 | >>> renderGroove 1211 | >>> renderInset 1212 | >>> renderNone 1213 | >>> renderOutset 1214 | >>> renderRidge 1215 | >>> renderSolid 1216 | 1217 | type OutlineWidthValue = Variant (OutlineWidthFields ()) 1218 | 1219 | type OutlineWidthFields r = 1220 | ( GlobalFields 1221 | + LengthFields 1222 | + OutlineWidthKeywordFields 1223 | + Zero 1224 | + r 1225 | ) 1226 | 1227 | renderOutlineWidthFields 1228 | :: forall v 1229 | . (Variant v -> String) 1230 | -> Variant (OutlineWidthFields v) 1231 | -> String 1232 | renderOutlineWidthFields = 1233 | renderGlobalFields 1234 | >>> renderLengthFields 1235 | >>> renderOutlineWidthKeyword 1236 | >>> renderZero 1237 | 1238 | type Padding v = (padding :: PaddingRep | v) 1239 | 1240 | type PaddingRep = 1241 | { top :: PaddingValue 1242 | , right :: PaddingValue 1243 | , bottom :: PaddingValue 1244 | , left :: PaddingValue 1245 | } 1246 | 1247 | type PaddingValue = Variant (PaddingFields ()) 1248 | 1249 | type PaddingFields r = 1250 | ( GlobalFields 1251 | + LengthFields 1252 | + Pct 1253 | + Zero 1254 | + r 1255 | ) 1256 | 1257 | _padding = Proxy :: Proxy "padding" 1258 | 1259 | padding :: forall v. PaddingRep -> Variant (Padding v) 1260 | padding = inj _padding 1261 | 1262 | renderPaddingFields 1263 | :: forall v 1264 | . (Variant v -> String) 1265 | -> Variant (PaddingFields v) 1266 | -> String 1267 | renderPaddingFields = 1268 | renderGlobalFields 1269 | >>> renderLengthFields 1270 | >>> renderPct 1271 | >>> renderZero 1272 | 1273 | renderPadding 1274 | :: forall v 1275 | . (Variant v -> String) 1276 | -> Variant (Padding v) 1277 | -> String 1278 | renderPadding = on _padding \p -> 1279 | Array.intercalate " " 1280 | [ renderPaddingFields case_ $ p.top 1281 | , renderPaddingFields case_ $ p.right 1282 | , renderPaddingFields case_ $ p.bottom 1283 | , renderPaddingFields case_ $ p.left 1284 | ] 1285 | 1286 | -- CSS data type values 1287 | 1288 | type AbsoluteLengthFields r = 1289 | ( Cm 1290 | + In 1291 | + Mm 1292 | + Pc 1293 | + Pt 1294 | + Px 1295 | + r 1296 | ) 1297 | 1298 | renderAbsoluteLengthFields 1299 | :: forall v 1300 | . (Variant v -> String) 1301 | -> Variant (AbsoluteLengthFields v) 1302 | -> String 1303 | renderAbsoluteLengthFields = 1304 | renderCm 1305 | >>> renderIn 1306 | >>> renderMm 1307 | >>> renderPc 1308 | >>> renderPt 1309 | >>> renderPx 1310 | 1311 | type AbsoluteSizeFields r = 1312 | ( XxSmall 1313 | + XSmall 1314 | + Small 1315 | + Medium 1316 | + Large 1317 | + XLarge 1318 | + XxLarge 1319 | + r 1320 | ) 1321 | 1322 | renderAbsoluteSizeFields 1323 | :: forall v 1324 | . (Variant v -> String) 1325 | -> Variant (AbsoluteSizeFields v) 1326 | -> String 1327 | renderAbsoluteSizeFields = 1328 | renderXxSmall 1329 | >>> renderXSmall 1330 | >>> renderSmall 1331 | >>> renderMedium 1332 | >>> renderLarge 1333 | >>> renderXLarge 1334 | >>> renderXxLarge 1335 | 1336 | type BorderWidthKeywordFields r = 1337 | ( Medium 1338 | + Thick 1339 | + Thin 1340 | + r 1341 | ) 1342 | 1343 | renderBorderWidthKeywordFields 1344 | :: forall v 1345 | . (Variant v -> String) 1346 | -> Variant (BorderWidthKeywordFields v) 1347 | -> String 1348 | renderBorderWidthKeywordFields = 1349 | renderMedium 1350 | >>> renderThick 1351 | >>> renderThin 1352 | 1353 | type ColorFields r = 1354 | ( Color_ 1355 | + CurrentColor 1356 | + Transparent 1357 | + r 1358 | ) 1359 | 1360 | renderColorFields 1361 | :: forall v 1362 | . (Variant v -> String) 1363 | -> Variant (ColorFields v) 1364 | -> String 1365 | renderColorFields = 1366 | renderColor_ 1367 | >>> renderCurrentColor 1368 | >>> renderTransparent 1369 | 1370 | type FontRelativeLengthFields r = 1371 | ( Ch 1372 | + Em 1373 | + Ex 1374 | + Rem 1375 | + r 1376 | ) 1377 | 1378 | renderFontRelativeLengthFields 1379 | :: forall v 1380 | . (Variant v -> String) 1381 | -> Variant (FontRelativeLengthFields v) 1382 | -> String 1383 | renderFontRelativeLengthFields = 1384 | renderCh 1385 | >>> renderEm 1386 | >>> renderEx 1387 | >>> renderRem 1388 | 1389 | type FontWeightKeywordFields r = 1390 | ( Bold 1391 | + Normal 1392 | + r 1393 | ) 1394 | 1395 | renderFontWeightKeywordFields 1396 | :: forall v 1397 | . (Variant v -> String) 1398 | -> Variant (FontWeightKeywordFields v) 1399 | -> String 1400 | renderFontWeightKeywordFields = renderBold >>> renderNormal 1401 | 1402 | type FontWeightKeywordRelativeFields r = 1403 | ( Bolder 1404 | + Lighter 1405 | + r 1406 | ) 1407 | 1408 | renderFontWeightKeywordRelativeFields 1409 | :: forall v 1410 | . (Variant v -> String) 1411 | -> Variant (FontWeightKeywordRelativeFields v) 1412 | -> String 1413 | renderFontWeightKeywordRelativeFields = renderBolder >>> renderLighter 1414 | 1415 | type GlobalFields r = 1416 | ( Inherit 1417 | + Initial 1418 | + Unset 1419 | + r 1420 | ) 1421 | 1422 | renderGlobalFields 1423 | :: forall v 1424 | . (Variant v -> String) 1425 | -> Variant (GlobalFields v) 1426 | -> String 1427 | renderGlobalFields = 1428 | renderInherit 1429 | >>> renderInitial 1430 | >>> renderUnset 1431 | 1432 | type LengthFields r = 1433 | ( AbsoluteLengthFields 1434 | + FontRelativeLengthFields 1435 | + ViewportPercentageLengthFields 1436 | + r 1437 | ) 1438 | 1439 | renderLengthFields 1440 | :: forall v 1441 | . (Variant v -> String) 1442 | -> Variant (LengthFields v) 1443 | -> String 1444 | renderLengthFields = 1445 | renderAbsoluteLengthFields 1446 | >>> renderFontRelativeLengthFields 1447 | >>> renderViewportPercentageLengthFields 1448 | 1449 | type LengthFields_ r = 1450 | ( LengthFields 1451 | + Zero 1452 | + r 1453 | ) 1454 | 1455 | renderLengthFields_ 1456 | :: forall v 1457 | . (Variant v -> String) 1458 | -> Variant (LengthFields_ v) 1459 | -> String 1460 | renderLengthFields_ = renderLengthFields >>> renderZero 1461 | 1462 | type OutlineWidthKeywordFields r = 1463 | ( Medium 1464 | + Thick 1465 | + Thin 1466 | + r 1467 | ) 1468 | 1469 | renderOutlineWidthKeyword 1470 | :: forall v 1471 | . (Variant v -> String) 1472 | -> Variant (OutlineWidthKeywordFields v) 1473 | -> String 1474 | renderOutlineWidthKeyword = 1475 | renderMedium 1476 | >>> renderThick 1477 | >>> renderThin 1478 | 1479 | type RelativeSizeFields r = 1480 | ( Smaller 1481 | + Larger 1482 | + r 1483 | ) 1484 | 1485 | renderRelativeSizeFields 1486 | :: forall v 1487 | . (Variant v -> String) 1488 | -> Variant (RelativeSizeFields v) 1489 | -> String 1490 | renderRelativeSizeFields = renderLarger >>> renderSmaller 1491 | 1492 | type ViewportPercentageLengthFields r = 1493 | ( Vh 1494 | + Vmax 1495 | + Vmin 1496 | + Vw 1497 | + r 1498 | ) 1499 | 1500 | renderViewportPercentageLengthFields 1501 | :: forall v 1502 | . (Variant v -> String) 1503 | -> Variant (ViewportPercentageLengthFields v) 1504 | -> String 1505 | renderViewportPercentageLengthFields = 1506 | renderVh 1507 | >>> renderVmax 1508 | >>> renderVmin 1509 | >>> renderVw 1510 | -------------------------------------------------------------------------------- /src/Style/Render.purs: -------------------------------------------------------------------------------- 1 | module Style.Render where 2 | 3 | import Prelude 4 | 5 | import Data.Array (intercalate) 6 | import Data.Array.NonEmpty (NonEmptyArray) 7 | import Data.Array.NonEmpty as NonEmptyArray 8 | import Style.Declaration (Declaration) 9 | import Style.Declaration as Declaration 10 | 11 | inline :: NonEmptyArray Declaration -> String 12 | inline = intercalate " " <<< map Declaration.render <<< NonEmptyArray.toArray 13 | -------------------------------------------------------------------------------- /src/Style/Ruleset.purs: -------------------------------------------------------------------------------- 1 | module Style.Ruleset where 2 | 3 | import Prelude 4 | 5 | import Data.Array as Array 6 | import Data.Array.NonEmpty (NonEmptyArray) 7 | import Data.Array.NonEmpty as NonEmptyArray 8 | import Style.Declaration (Declaration) 9 | import Style.Declaration as Declaration 10 | import Style.Selector (Selector) 11 | import Style.Selector as Selector 12 | 13 | data Ruleset = Ruleset (NonEmptyArray Selector) (NonEmptyArray Declaration) 14 | 15 | derive instance eqRuleset :: Eq Ruleset 16 | derive instance ordRuleset :: Ord Ruleset 17 | 18 | render :: Ruleset -> String 19 | render (Ruleset ss ds) = selectors <> "{" <> declarations <> "}" 20 | 21 | where 22 | 23 | selectors :: String 24 | selectors = Array.intercalate ",\n" (Selector.render <$> NonEmptyArray.toArray ss) <> " " 25 | 26 | declarations :: String 27 | declarations = "\n " <> Array.intercalate "\n " (Declaration.render <$> NonEmptyArray.toArray ds) <> "\n" 28 | -------------------------------------------------------------------------------- /src/Style/Selector.purs: -------------------------------------------------------------------------------- 1 | module Style.Selector where 2 | 3 | import Prelude 4 | 5 | import Data.Int as Int 6 | import Data.Maybe (Maybe, maybe) 7 | import Data.Newtype (class Newtype, unwrap) 8 | 9 | data Selector 10 | = TypeSelector String 11 | | ClassSelector String 12 | | IDSelector String 13 | | UniversalSelector {-Namespace-} 14 | | AttributeSelector (Maybe Selector) Attribute 15 | | CombinedSelector Selector Combinator Selector 16 | | PseudoClassSelector Selector PseudoClass 17 | | PseudoElementSelector Selector PseudoElement 18 | 19 | derive instance eqSelector :: Eq Selector 20 | derive instance ordSelector :: Ord Selector 21 | 22 | render :: Selector -> String 23 | render = case _ of 24 | TypeSelector el -> el 25 | ClassSelector c -> "." <> c 26 | IDSelector i -> "#" <> i 27 | UniversalSelector -> "*" 28 | AttributeSelector s a -> 29 | maybe (renderAttribute a) (\s' -> render s' <> renderAttribute a) s 30 | CombinedSelector s1 c s2 -> render s1 <> renderCombinator c <> render s2 31 | PseudoClassSelector s pc -> render s <> renderPseudoClass pc 32 | PseudoElementSelector s pe -> render s <> renderPseudoElement pe 33 | 34 | data Attribute 35 | = Equal AttributeName AttributeValue 36 | | TildeEqual AttributeName AttributeValue 37 | | PipeEqual AttributeName AttributeValue 38 | | CaretEqual AttributeName AttributeValue 39 | | DollarEqual AttributeName AttributeValue 40 | | AsteriskEqual AttributeName AttributeValue 41 | | CaseInsensitive Attribute 42 | 43 | derive instance eqAttribute :: Eq Attribute 44 | derive instance ordAttribute :: Ord Attribute 45 | 46 | renderAttribute :: Attribute -> String 47 | renderAttribute = case _ of 48 | Equal n v -> renderAttribute' "=" n v 49 | TildeEqual n v -> renderAttribute' "~=" n v 50 | PipeEqual n v -> renderAttribute' "|=" n v 51 | CaretEqual n v -> renderAttribute' "^=" n v 52 | DollarEqual n v -> renderAttribute' "$=" n v 53 | AsteriskEqual n v -> renderAttribute' "*=" n v 54 | CaseInsensitive a -> renderAttribute a <> " i" 55 | 56 | where 57 | 58 | renderAttribute' :: String -> AttributeName -> AttributeValue -> String 59 | renderAttribute' op n v = 60 | "[" <> renderAttributeName n <> op <> renderAttributeValue v <> "]" 61 | 62 | newtype AttributeName = AttributeName String 63 | 64 | derive instance newtypeAttributeName :: Newtype AttributeName _ 65 | derive newtype instance eqAttributeName :: Eq AttributeName 66 | derive newtype instance ordAttributeName :: Ord AttributeName 67 | 68 | renderAttributeName :: AttributeName -> String 69 | renderAttributeName = unwrap 70 | 71 | newtype AttributeValue = AttributeValue String 72 | 73 | derive instance newtypeAttributeValue :: Newtype AttributeValue _ 74 | derive newtype instance eqAttributeValue :: Eq AttributeValue 75 | derive newtype instance ordAttributeValue :: Ord AttributeValue 76 | 77 | renderAttributeValue :: AttributeValue -> String 78 | renderAttributeValue = unwrap 79 | 80 | data Combinator 81 | = AdjacentSibling 82 | | GeneralSibling 83 | | Child 84 | | Descendant 85 | 86 | derive instance eqCombinator :: Eq Combinator 87 | derive instance ordCombinator :: Ord Combinator 88 | 89 | renderCombinator :: Combinator -> String 90 | renderCombinator = case _ of 91 | AdjacentSibling -> " + " 92 | GeneralSibling -> " ~ " 93 | Child -> " > " 94 | Descendant -> " " 95 | 96 | data Directionality 97 | = LeftToRight 98 | | RightToLeft 99 | 100 | derive instance eqDirectionality :: Eq Directionality 101 | derive instance ordDirectionality :: Ord Directionality 102 | 103 | renderDirectionality :: Directionality -> String 104 | renderDirectionality = case _ of 105 | LeftToRight -> "ltr" 106 | RightToLeft -> "rtl" 107 | 108 | newtype LanguageCode = LanguageCode String 109 | 110 | derive instance newtypeLanguageCode :: Newtype LanguageCode _ 111 | derive newtype instance eqLanguageCode :: Eq LanguageCode 112 | derive newtype instance ordLanguageCode :: Ord LanguageCode 113 | 114 | renderLanguageCode :: LanguageCode -> String 115 | renderLanguageCode = unwrap 116 | 117 | data Position 118 | = AnPlusB Int (Maybe Int) 119 | | Even 120 | | Odd 121 | 122 | derive instance eqPosition :: Eq Position 123 | derive instance ordPosition :: Ord Position 124 | 125 | renderPosition :: Position -> String 126 | renderPosition = case _ of 127 | AnPlusB a b -> 128 | intToString a <> "n" <> maybe "" (\b' -> "+" <> intToString b') b 129 | Even -> "even" 130 | Odd -> "odd" 131 | 132 | where 133 | 134 | intToString :: Int -> String 135 | intToString = Int.toStringAs Int.decimal 136 | 137 | data PseudoClass 138 | = Active 139 | | Any 140 | | AnyLink 141 | | Checked 142 | | Default 143 | | Defined 144 | | Dir Directionality 145 | | Disabled 146 | | Empty 147 | | Enabled 148 | | First 149 | | FirstChild 150 | | FirstOfType 151 | | Fullscreen 152 | | Focus 153 | | FocusVisible 154 | | Host (Maybe Selector) 155 | | HostContext Selector 156 | | Hover 157 | | Indeterminate 158 | | InRange 159 | | Invalid 160 | | Lang LanguageCode 161 | | LastChild 162 | | LastOfType 163 | | Left 164 | | Link 165 | | Not Selector 166 | | NthChild Position 167 | | NthLastChild Position 168 | | NthLastOfType Position 169 | | NthOfType Position 170 | | OnlyChild 171 | | OnlyOfType 172 | | Optional 173 | | OutOfRange 174 | | ReadOnly 175 | | ReadWrite 176 | | Required 177 | | Right 178 | | Root 179 | | Scope 180 | | Target 181 | | Valid 182 | | Visited 183 | 184 | derive instance eqPseudoClass :: Eq PseudoClass 185 | derive instance ordPseudoClass :: Ord PseudoClass 186 | 187 | renderPseudoClass :: PseudoClass -> String 188 | renderPseudoClass pc = ":" <> case pc of 189 | Active -> "active" 190 | Any -> "any" 191 | AnyLink -> "any-link" 192 | Checked -> "checked" 193 | Default -> "default" 194 | Defined -> "defined" 195 | Dir d -> "dir(" <> renderDirectionality d <> ")" 196 | Disabled -> "disabled" 197 | Empty -> "empty" 198 | Enabled -> "enabled" 199 | First -> "first" 200 | FirstChild -> "first-child" 201 | FirstOfType -> "first-of-type" 202 | Fullscreen -> "fullscreen" 203 | Focus -> "focus" 204 | FocusVisible -> "focus-visible" 205 | Host h -> maybe "host" (\h' -> "host(" <> render h' <> ")") h 206 | HostContext s -> "host-context(" <> render s <> ")" 207 | Hover -> "hover" 208 | Indeterminate -> "indeterminate" 209 | InRange -> "in-range" 210 | Invalid -> "invalid" 211 | Lang l -> "lang(" <> renderLanguageCode l <> ")" 212 | LastChild -> "last-child" 213 | LastOfType -> "last-of-type" 214 | Left -> "left" 215 | Link -> "link" 216 | Not s -> "not(" <> render s <> ")" 217 | NthChild p -> "nth-child(" <> renderPosition p <> ")" 218 | NthLastChild p -> "nth-last-child(" <> renderPosition p <> ")" 219 | NthLastOfType p -> "nth-last-of-type(" <> renderPosition p <> ")" 220 | NthOfType p -> "nth-of-type(" <> renderPosition p <> ")" 221 | OnlyChild -> "only-child" 222 | OnlyOfType -> "only-of-type" 223 | Optional -> "optional" 224 | OutOfRange -> "out-of-range" 225 | ReadOnly -> "read-only" 226 | ReadWrite -> "read-write" 227 | Required -> "required" 228 | Right -> "right" 229 | Root -> "root" 230 | Scope -> "scope" 231 | Target -> "target" 232 | Valid -> "valid" 233 | Visited -> "visited" 234 | 235 | data PseudoElement 236 | = After 237 | | Backdrop 238 | | Before 239 | | Cue 240 | | FirstLetter 241 | | FirstLine 242 | | GrammarError 243 | | Marker 244 | | Placeholder 245 | | Selection 246 | | Slotted 247 | | SpellingError 248 | 249 | derive instance eqPseudoElement :: Eq PseudoElement 250 | derive instance ordPseudoElement :: Ord PseudoElement 251 | 252 | renderPseudoElement :: PseudoElement -> String 253 | renderPseudoElement pe = "::" <> case pe of 254 | After -> "after" 255 | Backdrop -> "backdrop" 256 | Before -> "before" 257 | Cue -> "cue" 258 | FirstLetter -> "first-letter" 259 | FirstLine -> "first-line" 260 | GrammarError -> "grammar-error" 261 | Marker -> "marker" 262 | Placeholder -> "placeholder" 263 | Selection -> "selection" 264 | Slotted -> "slotted" 265 | SpellingError -> "spelling-error" 266 | -------------------------------------------------------------------------------- /test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main where 2 | 3 | import Prelude hiding (zero) 4 | 5 | import Color (black, rgb, white) 6 | import Color.Scheme.HTML (blue, green, red, silver, yellow) 7 | import Color.Scheme.X11 (gold, orange) 8 | import Data.Array.NonEmpty (NonEmptyArray, fromArray) 9 | import Data.Maybe (Maybe, maybe) 10 | import Effect (Effect) 11 | import Effect.Console (log) 12 | import Style.Declaration (Declaration) 13 | import Style.Declaration as CSS 14 | import Style.Declaration.Value (auto, boxShadow_, boxShadow_', center, currentColor, dashed, dotted, double, em, groove, hidden, in_, inset, invert, mm, none, number_, outset, pct, px, rem, ridge, solid, zero) 15 | import Style.Render (inline) 16 | import Style.Ruleset (Ruleset(..)) 17 | import Style.Ruleset as Ruleset 18 | import Style.Selector (Selector(..)) 19 | 20 | selectors :: Maybe (NonEmptyArray Selector) 21 | selectors = fromArray 22 | [ TypeSelector "body" 23 | , ClassSelector "foo" 24 | , IDSelector "bar" 25 | ] 26 | 27 | declarations :: Maybe (NonEmptyArray Declaration) 28 | declarations = fromArray $ 29 | [ CSS.backgroundColor $ rgb 127 127 127 30 | , CSS.border' (1.0 # px) solid currentColor 31 | , CSS.border (1.0 # px) solid gold 32 | , CSS.borderTop (2.0 # px) dashed silver 33 | , CSS.borderRight (3.0 # px) dotted red 34 | , CSS.borderBottom (4.0 # px) double green 35 | , CSS.borderLeft (5.0 # px) groove blue 36 | , CSS.borderWidth (6.0 # px) (2.0 # px) (3.0 # px) (4.0 # px) 37 | , CSS.borderStyle hidden inset none outset 38 | , CSS.borderColor red orange yellow green 39 | , CSS.borderRadius (5.0 # px) (6.0 # px) (7.0 # px) (8.0 # px) 40 | , CSS.borderTopLeftRadius $ 5.0 # px 41 | , CSS.borderTopRightRadius $ 6.0 # px 42 | , CSS.borderBottomRightRadius $ 7.0 # px 43 | , CSS.borderBottomLeftRadius $ 8.0 # px 44 | , CSS.borderTopWidth $ 7.0 # px 45 | , CSS.borderTopStyle ridge 46 | , CSS.borderTopColor white 47 | , CSS.boxShadow 48 | [ boxShadow_ false (3.0 # px) (3.0 # px) zero zero red 49 | , boxShadow_' true (-1.0 # em) zero zero (0.4 # em) currentColor 50 | ] 51 | , CSS.color black 52 | , CSS.fontSize $ 16.0 # px 53 | , CSS.fontWeight $ number_ 300.0 54 | , CSS.height $ 100.0 # pct 55 | , CSS.margin auto (8.0 # px) (50.0 # pct) zero 56 | , CSS.marginTop auto 57 | , CSS.marginRight $ 8.0 # px 58 | , CSS.marginBottom $ 50.0 # pct 59 | , CSS.marginLeft zero 60 | , CSS.outline' (1.0 # px) solid invert 61 | , CSS.outline (1.0 # px) solid gold 62 | , CSS.outlineWidth $ 1.0 # px 63 | , CSS.outlineStyle solid 64 | , CSS.outlineColor gold 65 | , CSS.padding (1.0 # em) (2.0 # in_) (3.0 # mm) (4.0 # rem) 66 | , CSS.paddingTop $ 1.0 # em 67 | , CSS.paddingRight $ 2.0 # in_ 68 | , CSS.paddingBottom $ 3.0 # mm 69 | , CSS.paddingLeft $ 4.0 # rem 70 | , CSS.textAlign center 71 | , CSS.width auto 72 | ] 73 | 74 | ruleset :: Maybe Ruleset 75 | ruleset = Ruleset <$> selectors <*> declarations 76 | 77 | main :: Effect Unit 78 | main = do 79 | log "" 80 | log $ maybe "" inline declarations 81 | log "" 82 | log $ maybe "" Ruleset.render ruleset 83 | log "" 84 | --------------------------------------------------------------------------------