NixLabConnectionconnecting
ProjectsProject
web /

dreamstop.openfp.net

publicguest

dreamstop.openfp.net, the website and user manual of dreamstop, a language for continuous disambiguation

git clone git@nixlab.openfp.net:web/dreamstop.openfp.net.git
a08e816170b2c5086d79c84e265f2a6a6009feaddreamstop-openfp-net-web/src/Site/View.hs
-- | The page's body: what dreamstop is, the three verdicts, a minimal pair,
-- and the manual.
-- Every word is in the rendered HTML, so the page reads in full without
-- JavaScript. Every sentence of prose is annotated in prose/front.vx.
--
-- @since 0.1.0.0
module Site.View
  ( Model
  , Action
  , app
  ) where

import           Data.Char          (isUpper)
import           Data.Kind          (Type)
import           Data.List          (groupBy)
import           DesignKit.Brand    (fontDisplay, gradientText)
import           DesignKit.Effects  (scrollProgressBar)
import           Miso               (App, Effect, component)
import           Miso.Html.Element  (a_, blockquote_, code_, div_, footer_, h1_,
                                     h2_, h3_, header_, li_, nav_, ol_, p_,
                                     section_, span_, ul_)
import           Miso.Html.Property (aria_, href_, id_)
import           Miso.Property      (classList)
import           Miso.String        (MisoString, fromMisoString, toMisoString)
import           Miso.Types         (View, text)
import           Site.Content       (Example (exampleLabel, exampleReadings, exampleSentence),
                                     Reading (readingCodes, readingGloss),
                                     manual, modalities, package, pair,
                                     pairSlot, repository, verdicts)
import           Site.Page          (name)

-- | The page holds no state.
--
-- @since 0.1.0.0
type Model :: Type
data Model = MkModel
  deriving stock (Eq)

-- | The page has no actions.
--
-- @since 0.1.0.0
type Action :: Type
data Action

-- | Rendered and hydrated with the same view.
--
-- @since 0.1.0.0
app :: App Model Action
app = component MkModel update (const view)

update :: Action -> Effect parent props Model Action
update = \case {}

view :: Model -> View Model Action
view _ =
  div_
    [classList ["page"]]
    [ scrollProgressBar
    , header_
        [classList ["chrome"]]
        [ div_
            [classList ["container"]]
            [ wordmark
            , nav_
                [classList ["links"], aria_ "label" "Site"]
                [ a_ [href_ "#verdicts"] ["Verdicts"]
                , a_ [href_ "#pairs"] ["Minimal pairs"]
                , a_ [href_ manual] ["Manual"]
                ]
            ]
        ]
    , section_
        [classList ["hero"]]
        [ div_
            [classList ["container"]]
            [ h1_ [classList ["display"], fontDisplay] [gradientText [text name]]
            , p_
                []
                [ "dreamstop is a language for disambiguating text. \
                  \It checks that a piece of writing very likely means only one thing. \
                  \A program marks up every clause with three-letter codepoints that identify its grammatical meaning: \
                  \whether it states something or tells you to do something, whether it is done or still happening, \
                  \whether it is required or only allowed. \
                  \A sentence is clear when there is only one way to read it. \
                  \It is ambiguous when there is more than one way to read it, and it is nonsense when there is no way to read it."
                ]
            , p_
                [classList ["actions"]]
                [a_ [classList ["btn"], id_ "manual", href_ manual] ["Read the manual"]]
            ]
        ]
    , section_
        [classList ["band"], id_ "verdicts"]
        [ div_
            [classList ["container"]]
            [ h2_ [classList ["section-title"], fontDisplay] ["Clear, ambiguous or nonsense"]
            , legend
            , ul_ [classList ["readings"]] (map example verdicts)
            , h2_ [classList ["section-title"], fontDisplay] ["Required or only allowed"]
            , ul_ [classList ["readings"]] (map example modalities)
            ]
        ]
    , section_
        [classList ["band"], id_ "pairs"]
        [ div_
            [classList ["container"]]
            [ h2_ [classList ["section-title"], fontDisplay] ["Minimal pairs"]
            , p_
                []
                ["A minimal pair is two sentences that differ by the smallest possible edit that makes the sentence clear."]
            , ul_ [classList ["readings"]] (map example pair)
            , p_ [classList ["annotation"]] [text pairSlot]
            , p_
                []
                [ "Each document kind is a set of patterns, specified by its pairs. \
                  \A pattern with no pair is not part of the kind."
                ]
            , p_
                []
                [ "The manual covers every code, the clause positions, the verdicts, the questions, the six document kinds and how reviews use them. "
                , "The dreamstop package in dreamstop/dreamstop checks every pair of a kind against its patterns."
                ]
            ]
        ]
    , footer_
        [classList ["chrome"]]
        [ div_
            [classList ["container"]]
            [ wordmark
            , span_
                [classList ["copy"]]
                [ a_ [href_ repository] ["Page source"]
                , ". "
                , a_ [href_ package] ["Package source"]
                , ". © 2026 Homotopic.Tech Ltd. An "
                , a_ [href_ "https://openfp.net"] ["openfp"]
                , " project."
                ]
            ]
        ]
    ]
  where
    wordmark :: View Model Action
    wordmark = a_ [classList ["wordmark"], href_ "/"] [text name]

    example :: Example -> View Model Action
    example e =
      li_
        []
        ( [ h3_ [] [text (exampleLabel e)]
          , blockquote_ [classList ["entry"]] [text (exampleSentence e)]
          ]
            <> readings (exampleReadings e)
        )

    readings :: [Reading] -> [View Model Action]
    readings = \case
      [] -> [p_ [classList ["annotation"]] ["No reading"]]
      [r] -> [p_ [classList ["annotation"]] (reading r)]
      rs ->
        [ p_ [classList ["annotation"]] ["Readings:"]
        , ol_ [classList ["annotation"]] (map (li_ [] . reading) rs)
        ]

    reading :: Reading -> [View Model Action]
    reading r = [codepoints (readingCodes r), text (": " <> readingGloss r)]

    legend :: View Model Action
    legend =
      ul_
        [classList ["legend"], aria_ "label" "Codepoint colours"]
        [ li_ [classList [layerClass l]] [text l]
        | l <- ["Force", "Mood", "Aspect", "Phase", "Modality", "Negation", "Bound", "Evidence", "Nominalisation"]
        ]

-- | A reading's codes, each in its own class, which codepoints.css colours by
-- the code's layer, with brackets, separators and positions in neutral grey.
codepoints :: MisoString -> View model action
codepoints s =
  code_ [] (map token (groupBy sameCase (fromMisoString s :: String)))
  where
    sameCase :: Char -> Char -> Bool
    sameCase a b = isUpper a == isUpper b

    token :: String -> View model action
    token w = span_ [classList [if length w == 3 && all isUpper w then "cp-" <> toMisoString w else "cp-mark"]] [text (toMisoString w)]

-- | The CSS class of a layer.
layerClass :: MisoString -> MisoString
layerClass l = "cp-" <> l