packages feed

miso-css

wrapper over miso checking CSS classes applicability through dependent types

view on Hackage

== Motivation #motivation# __miso-css__ is an evolutionary step ahead from <https://github.com/yaitskov/css-class-bindings css-class-bindings>. CSS class of an atomic selector can be applied to any DOM element, but that is not true for classes used in composite selectors. Rules with partially matched selectors are silently ignored by browser and this open a door for introducing bugs during consequent changes. Css-class-binding just cannot cope with such problem and miso-css uses dependent types to track what CSS classes can applied to HTML elements. == Usage #usage# miso-css runs a css parser to extract CSS selectors and generates Haskell constants for every CSS class with correspondent name that is found in the input. A type of such constant describes all possible ways the class can used in DOM. Besides that the library ships __E__ type representing an HTML element and a set of operators for constructing tags and combining them in DOM tree. E is miso <https://hackage-content.haskell.org/package/miso/docs/Miso-Types.html#t:View VNode> type protected with a few type parameters. === Composing tags #composing-tags# Before jumping straight to style application lets get familiar with syntax for tag composition because it is different in vanilla <https://hackage-content.haskell.org/package/miso miso>. ==== Appending a child #appending-a-child# > div_ </ p_ > <div> > <p></p> > </div> ==== Adding a sibling #adding-a-sibling# > ul_ </ li_ </ li_ > <ul> > <li></li> > <li></li> > </ul> ==== Appending a child to child #appending-a-child-to-child# > body_ </ (section_ </ p_) > <body> > <section> > <p></p> > </section> > </body> ==== Adding CDATA #adding-cdata# > a_ <@ "click" > <a>click</a> ==== Adding a raw miso DOM chunk #adding-a-raw-miso-dom-chunk# > import Miso.Html qualified as MH > import Miso.Html.Property qualified as MH > > go = div_ =< MH.p_ [] [ "h" ] > <div> > <p>h</p> > </div> ==== Adding tag attribute #adding-tag-attribute# > a_ =<| atr @"href" "http://link.com" > <a href="http://link.com"></a> ==== Binding event handler #binding-event-handler# > button_ =! onClick YourActionDc ==== Applying CSS class #applying-css-class# > {-# LANGUAGE QuasiQuotes #-} > {-# OPTIONS_GHC -Wno-missing-signatures #-} > [css|.red { color: red; }|] > > div_ =. red > <div class="red"></div> ==== Adding tag ID #adding-tag-id# Handmade tag id: > div_ =# ElementId "footer" Generated tag id: > {-# LANGUAGE QuasiQuotes #-} > {-# OPTIONS_GHC -Wno-missing-signatures #-} > [css|#footer { color: red; }|] > > div_ =# Footer > <div id="footer"></div> ==== Mix all at once #mix-all-at-once# > {-# LANGUAGE QuasiQuotes #-} > {-# OPTIONS_GHC -Wno-missing-signatures #-} > [css|.form .red { color: red; }|] > > div_ =. form =# ElementId "footer" > </ (a_ =. red =<| atr @"href" "/click.php?x=1" > </ (span_ <@ "Click me")) > <div class="form" id="footer> > <a class="red" href="/click.php?x=1"> > <span>Click me</span> > </a> > </div> === Breaking rules #breaking-rules# Until now all above samples must be valid and should type check. This section enumerates HTML snippets with ill-applied classes, expected errors and comments. ==== There can be only one #there-can-be-only-one# An element ID can be used once in a HTML document. > div_ =# ElementId "Duncan MacLeod" > </ div_ =# ElementId "Duncan MacLeod" > Couldn't match type: '[DuplicatedId "Duncan MacLeod"] > with: '[] ==== Parent class is missing #parent-class-is-missing# > [css|.a .b {}|] > > div_ =. b The error message is a list of triples where first element is a list of not applied classes, ids (hashes), tag names or attribute names. > [([C "a"], [], [])] Class __a__ and __b__ are missing: > [css|.a .b .c {}|] > > div_ =. c > [ ([C "b"], [], []) > , ([C "a"], [], []) > ] ==== B element #b-element# When selector with a child relation is partially applied the triple contains B element. It is a synthetic element preventing the failed rule from matching later somewhere upper in DOM by an accident. > [css|.a > .b {}|] > > div_ </ div_ =. b > [([B, C "a"], [], [])] ==== One of classes is missing #one-of-classes-is-missing# Second element of triple is a list of applied classes. It helps to understand what worked out and what didn’t in a composite selector. > [css|.a.b > .c {}|] > > div_ =. a </ div_ =. c > [([B, C "b"], [C "a"], [])] ===== Sibling is missing #sibling-is-missing# The third element of triple explains sibling errors. > [css|.a + .b {}|] > > div_ </ div_ =. b Class __a__ is not applied: > [([B], [], [[ [B], [C "a"]]])] === Non-leaf classes constraints #non-leaf-classes-constraints# By default non-leaf classes in selector don’t contribute to constraints. e.g. > .a > .b .c @b@ doesn’t require @a@ as immediate parent it is handled by constraints form @c@. It is possible to generate constraints for @b@ to make checking even stricter, though in such mode following DOM can’t pass type check: > enableRulesForNonLeafClasses > > [css|.a > .b .c {}|] > test_t = testGroup cssAsLiteralText > [ doNotTcNoBr [] [[[(JustNow, [B], [C "a"], [])]]] $ > div_ =. a </ (div_ =. b </ (div_ =. b </ div_ =. c)) > ] === E type #e-type# > data E > context > props > model > action > (en :: Symbol) > (es :: ElementStructure) > (re :: Maybe Root) > (ei :: Maybe Symbol) > (atrs :: [Symbol]) > (knownIds :: KnownIDS) > (cls :: [Symbol]) > (l :: [[[Seg]]]) > (children :: [[SubSeg]]) > (wantedIds :: [Symbol]) > (usedTabIndexes :: [Maybe Natural]) > (usedAccessKey :: [Char]) First 4 parameters __context__, __props__, __model__ and __action__ are forwarded to miso <https://hackage-content.haskell.org/package/miso/docs/Miso-Types.html#t:View VNode> type. ==== en - tag name #en---tag-name# In ghci session: > :t div_ > div_ > :: E model > action > "div" > ... ==== es - element structure #es---element-structure# Most often its value is __Composite__ which means that the element could have children. /Es/ parameter of /CDATA/ element is __Atomic__. ==== re - root indicator #re---root-indicator# It is a root tag indicator. A root tag cannot be adopted. > [css|:root > .a {}|] ==== ei - HTML tag hash #ei---html-tag-hash# > div_ =# ElementId "Duncan" ==== atrs - names of tag attributes #atrs---names-of-tag-attributes# > :t a_ =# ElementId "x" =<| atr @"href" "/click.php?x=1" > ... > ["href", "id"] > ... ==== knownIds - hashes used in tag descendants #knownids---hashes-used-in-tag-descendants# > :t div_ =# ElementId "x" </ div_ =# ElementId "y" </ div_ =# ElementId "z" > ... > (KnownIds '[] ["x", "y", "z"]) > ... ==== cls - classes applied to tag #cls---classes-applied-to-tag# Classes applied to children and descendants are not included. > :t div_ =. a =. b </ div_ =. c > ... > ["b", "a"] > ... ==== l - ancestor constraints #l---ancestor-constraints# The parameter describes requirements to be satisfied in ancestors of the tag. > [css|.a .b {}|] > :t div_ =. b > ... > '[ '[['(AutoClean, '[], '[], '[]), > '(NowOrLater, '[C "a"], '[], '[])]]] > ... ==== children #children# List of lists of children subselectors in reverse order. > [css|.a {} .b {}|] > :t div_ </ ul_ =. a =. b </ ol_ =# ElementId "x" > ... > [[I "x", T "ol"], [T "ul", C "b", C "a"]] > ... ==== wantedIds #wantedids# List of tag ids that are referenced somewhere by other tags through <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA ARIA> attributes: - @\<label for=\"\"\/>@ - aria-labelledby - aria-describedby > """<div> > <span id="aa">hi</span> > <span id="bb">bye</span> > <input aria-describedby="aa bb"/> > </div>""" > `go` div_ </ (span_ =# Aa <@ "hi") </ (span_ =# Bb <@ "bye") > </ input_ `ariaDescribedBy` Aa `ariaDescribedBy` Bb ==== usedTabIndexes #usedtabindexes# Tab indexes are global and should be unique as tag ids. Except values __-1__* and __0__. > """<div tabindex="-1">x</div>""" `go` tabIndexMinus1 (div_ <@ "x") > > """<div tabindex="1">x</div>""" `go` div_ `tabIndex` 1 <@ "x" ==== accessKey #accesskey# Access keys are global too. > """<div accesskey="a">x</div>""" `go` div_ `accessKey` 'a' <@ "x" === Hello World #hello-world# > {-# LANGUAGE QuasiQuotes #-} > {-# OPTIONS_GHC -Wno-missing-signatures #-} > module Miso.Css.Test.HelloWorld where > > import Miso ( component, App, CSS(Style), Component(styles), View ) > import Miso.Css > import Prelude > > type Model = () > type Action = () > > -- default name is "cssAsLiteralText" > renameCssTextConst "cssFromQq" > > [css| > .c .b .a { > color: #fc2c2c; > } > |] > > -- instead of quasi-quoted CSS > -- the whole CSS file can be included with: > -- includeCss "assets/style.css" > > app :: App Model Action > app = (component () pure viewModel) > { styles = [ Style cssFromQq ] } > > {- > viewModel produce following HTML snippet: > > <div class="c"> > <div class="b"> > <button class="a"> > Submit > </button> > </div> > </div> > > html_ and body_ don't produce tags, > because miso mount cannot be higher than body tag. > > they serve just for type checking purpose > (e.g. html_ satisfies :root pseudo class) > > -} > viewModel :: Model -> View () () Model Action > viewModel () = toView . html_ . body_ $ > div_ =. c > </ (div_ =. b > </ (button_ =. a > <@ "Submit")) == Development environment #development-environment# HLS should be available inside the default dev shell. > $ nix develop > $ emacs src/*/*/Qq.hs & > $ cabal build > $ cabal test --test-option=--hide-successes miso-css was developed with miso v1.9
versionuploadeduploaderchanges
0.0.32026-10-17 17:19 UTCDaniilIaitskov+566/−149 lines, 15 filesdep ~misoPVP: major bump suggested
0.0.22026-06-02 17:01 UTCDaniilIaitskov+7/−4 lines, 3 filesdep ~misoPVP ok
0.0.12026-06-02 16:47 UTCDaniilIaitskov+3538/−0 lines, 41 filesdep +QuickCheckdep +add-dependent-filedep +base

Dependencies of miso-css-0.0.3

QuickCheck >=0 2.18.0.0 → 2.19.0.0
2026-09-16 11:18 UTC2.19.0.0+67/−41 lines, 10 filesdep +OneTuplePVP ok
2026-02-26 12:42 UTC2.18.0.0+826/−542 lines, 23 filesPVP ok
2025-10-13 12:40 UTC2.17.1.0+18/−8 lines, 4 filesdep ~randomPVP: major bump suggested
2025-10-07 12:26 UTC2.17.0.0+667/−129 lines, 14 filesdep +data-array-bytedep +hintdep +splitdep −ghc-primdep −old-localedep −old-timedep ~basedep ~randomdep ~template-haskellPVP ok
2025-06-17 07:53 UTC2.16.0.0+477/−86 lines, 15 filesdep ~basenew-uploaderPVP ok

showing 5 of 66 versions

add-dependent-file >=0.0.2 && <1 0.0.1 → 0.0.2
2026-03-30 08:04 UTC0.0.2+29/−9 lines, 3 filesPVP ok
2026-02-26 11:25 UTC0.0.1 outside bounds+222/−0 lines, 6 filesdep +Cabaldep +Cabal-syntaxdep +base
base >=4.7 && <5 4.22.0.0 → 4.22.1.0
2026-12-01 12:38 UTC4.22.1.0+388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested
2025-12-19 11:52 UTC4.22.0.0+886/−215 lines, 28 filesdep ~ghc-internalPVP ok
2026-03-27 12:26 UTC4.21.2.0+10/−3 lines, 4 filesdep ~ghc-internalPVP ok
2025-12-27 10:31 UTC4.21.1.0+17/−5 lines, 4 filesdep ~ghc-internalPVP ok
2024-12-16 09:24 UTC4.21.0.0+1170/−396 lines, 39 filesdep ~ghc-internalPVP ok

showing 5 of 61 versions

bytestring >=0 0.12.1.0 → 0.12.2.0
2024-12-06 21:41 UTC0.12.2.0+538/−437 lines, 44 filesdep ~QuickCheckdep ~basePVP ok
2024-02-16 03:27 UTC0.12.1.0+3398/−1642 lines, 37 filesdep +sybdep ~basePVP: major bump suggested
2023-08-16 01:53 UTC0.12.0.2+16/−2 lines, 3 files
2023-08-05 00:03 UTC0.12.0.1+47/−9 lines, 3 files
2023-07-07 01:45 UTC0.12.0.0+1459/−520 lines, 21 filesdep +data-array-bytePVP ok

showing 5 of 49 versions

containers <1 0.8 → 0.8.1
2026-10-04 06:08 UTC0.8.1+8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested
2025-03-01 13:03 UTC0.8+8447/−7031 lines, 37 filesnew-uploaderPVP ok
2023-09-27 12:15 UTC0.7+76/−33 lines, 3 filesPVP ok
2023-09-28 04:21 UTC0.6.8+644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested
2023-02-01 03:11 UTC0.6.7+783/−229 lines, 20 filesPVP: major bump suggested

showing 5 of 43 versions

css-parser <1 (empty) → 0.0.1
2026-05-15 18:08 UTC0.0.1+6405/−0 lines, 50 filesdep +QuickCheckdep +arraydep +base
filepath <2 1.5.4.0 → 1.5.5.0
2026-01-20 08:14 UTC1.5.5.0+68/−12 lines, 8 filesdep +QuickCheckdep +template-haskell-liftdep +template-haskell-quasiquoterPVP ok
2024-11-17 13:06 UTC1.5.4.0+26/−6 lines, 3 filesdep ~basePVP ok
2024-06-29 15:30 UTC1.5.3.0+876/−871 lines, 13 filesdep −QuickCheckdep ~basePVP: major bump suggested
2024-01-26 07:02 UTC1.5.2.0+330/−256 lines, 11 filesdep +generic-derivingdep +generic-randomdep +tastydep ~basedep ~os-stringPVP ok
2023-11-25 08:29 UTC1.5.0.0+53/−3744 lines, 35 filesdep +os-stringdep ~basePVP ok

showing 5 of 35 versions

miso >=1.14 && <1.15 1.14.0.0 → 1.15.0.0 newer than bounds
2026-11-10 23:34 UTC1.15.0.0 newer than bounds+4142/−1312 lines, 55 filesdep −ghcjs-primPVP ok
2026-09-13 19:27 UTC1.14.0.0+1454/−772 lines, 39 filesdep ~ghc-experimentaldep ~ghcjs-basedep ~ghcjs-primPVP ok
2026-08-30 22:19 UTC1.13.0.0 outside bounds+20771/−5857 lines, 144 filesdep +aesondep +scientificPVP ok
2026-06-27 03:07 UTC1.12.0.0 outside bounds+7808/−2192 lines, 73 filesPVP ok
2026-05-25 12:04 UTC1.11.0.0 outside bounds+508/−205 lines, 13 filesPVP ok

showing 5 of 68 versions

mtl <3 2.3.1 → 2.3.2
2025-12-08 04:58 UTC2.3.2+112/−21 lines, 12 filesdep ~basenew-uploaderPVP: major bump suggested
2022-10-31 21:28 UTC2.3.1+188/−33 lines, 8 filesdep ~basePVP: major bump suggested
2022-05-07 20:34 UTC2.3+1284/−520 lines, 29 filesdep ~basedep ~transformersnew-uploaderPVP ok
2018-02-24 22:15 UTC2.2.2+152/−36 lines, 14 filesdep ~basePVP: major bump suggested
2014-06-02 02:22 UTC2.2.1+179/−4 lines, 8 filesdep ~basedep ~transformersPVP: major bump suggested

showing 5 of 20 versions

tagged <1 0.8.11 → 0.9
2026-09-28 11:22 UTC0.9+7/−104 lines, 3 filesdep −template-haskellPVP ok
2026-09-28 11:16 UTC0.8.11+11/−15 lines, 3 filesPVP ok
2025-12-08 00:55 UTC0.8.10+40/−16 lines, 4 filesdep −transformersdep ~template-haskellPVP: major bump suggested
2024-12-03 12:15 UTC0.8.9+39/−439 lines, 5 filesdep −ghc-primdep −transformers-compatdep ~basedep ~template-haskelldep ~transformersPVP ok
2023-08-08 10:32 UTC0.8.8+14/−10 lines, 3 filesdep ~deepseqdep ~template-haskellPVP ok

showing 5 of 41 versions

tasty >=0 1.5.4 → 1.5.5
2026-10-20 23:13 UTC1.5.5+53/−26 lines, 7 filesdep +terminal-sizePVP ok
2026-03-25 20:04 UTC1.5.4+332/−166 lines, 22 filesdep −semigroupsPVP ok
2025-01-05 19:52 UTC1.5.3+36/−11 lines, 3 filesdep ~containersdep ~optparse-applicativePVP: major bump suggested
2024-11-03 00:34 UTC1.5.2+22/−5 lines, 4 filesdep ~basePVP ok
2024-06-22 10:14 UTC1.5.1+131/−63 lines, 10 filesdep ~basePVP: major bump suggested

showing 5 of 76 versions

tasty-discover >=0 5.1.0 → 5.2.0
2025-10-25 01:49 UTC5.2.0+347/−38 lines, 7 filesdep ~tasty-quickcheckPVP ok
2025-08-10 03:11 UTC5.1.0+1691/−102 lines, 17 filesdep +ansi-terminaldep +directorydep +processdep ~tasty-quickcheckPVP ok
2025-06-01 05:23 UTC5.0.2+16/−9 lines, 6 filesPVP ok
2025-01-13 13:49 UTC5.0.1+90/−68 lines, 8 filesdep −directorydep ~basedep ~hspecdep ~hspec-corePVP ok
2022-07-08 03:47 UTC5.0.0+16/−36 lines, 6 filesdep ~hspecdep ~tasty-hedgehogPVP ok

showing 5 of 27 versions

tasty-hunit >=0 0.10.1 → 0.10.2
2024-06-22 10:14 UTC0.10.2+15/−7 lines, 4 filesPVP ok
2023-09-10 00:12 UTC0.10.1+30/−52 lines, 5 filesdep ~basedep ~call-stackdep ~tastynew-uploaderPVP ok
2020-12-18 09:42 UTC0.10.0.3+55/−10 lines, 4 filesdep ~basePVP ok
2019-05-15 05:50 UTC0.10.0.2+38/−8 lines, 3 filesdep ~tastyPVP: major bump suggested
2017-12-01 19:24 UTC0.10.0.1+51/−29 lines, 4 filesPVP: major bump suggested

showing 5 of 15 versions

tasty-quickcheck >=0 0.11 → 0.11.1
2025-01-05 19:53 UTC0.11.1+66/−33 lines, 4 filesdep +regex-tdfadep −pcre-lightdep ~QuickCheckdep ~basedep ~optparse-applicativePVP: major bump suggested
2024-06-22 10:14 UTC0.11+132/−49 lines, 4 filesdep ~QuickCheckPVP ok
2023-09-10 00:10 UTC0.10.3+52/−14 lines, 3 filesdep ~QuickCheckdep ~optparse-applicativedep ~randomnew-uploaderPVP ok
2021-11-20 19:17 UTC0.10.2+21/−13 lines, 3 filesdep ~basePVP: major bump suggested
2020-12-18 09:42 UTC0.10.1.2+27/−13 lines, 4 filesdep ~basePVP: major bump suggested

showing 5 of 23 versions

template-haskell <3 2.23.0.0 → 2.24.0.0
2025-12-19 11:53 UTC2.24.0.0+606/−68 lines, 9 filesdep +ghc-internaldep ~basedep ~ghc-boot-thPVP ok
2024-12-16 09:29 UTC2.23.0.0+104/−5685 lines, 9 filesdep −ghc-primdep −prettydep ~basedep ~ghc-boot-thnew-uploaderPVP ok
2024-05-15 13:07 UTC2.22.0.0+176/−81 lines, 7 filesdep ~basedep ~ghc-boot-thPVP ok
2023-10-10 00:23 UTC2.21.0.0+275/−148 lines, 7 filesdep ~basedep ~ghc-boot-thPVP ok
2023-03-28 13:43 UTC2.20.0.0+215/−139 lines, 9 filesdep −filepathdep ~basedep ~ghc-boot-thPVP ok

showing 5 of 26 versions

text <3 2.1.4 → 2.1.5
2026-11-27 23:30 UTC2.1.5+33786/−32979 lines, 58 filesPVP: major bump suggested
2026-01-28 08:30 UTC2.1.4+30991/−20199 lines, 35 filesdep +template-haskell-liftdep ~QuickCheckdep ~template-haskellPVP ok
2025-08-01 20:08 UTC2.1.3+2107/−1827 lines, 30 filesdep +splitmixdep +temporarydep ~QuickCheckdep ~ghc-primdep ~template-haskellPVP ok
2024-10-26 13:22 UTC2.1.2+43588/−15378 lines, 41 filesdep ~basedep ~binaryPVP: major bump suggested
2024-02-16 22:16 UTC2.1.1+986/−412 lines, 26 filesdep ~QuickCheckdep ~ghc-primdep ~template-haskellPVP: major bump suggested

showing 5 of 83 versions

Reverse dependencies

no known reverse dependencies