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-- | The page's body: what dreamstop is, a clear ChangeLog entry, a menu of
-- examples for each codepoint position, a minimal pair, and the manual.
-- Every word is in the rendered HTML, so the page reads in full without
-- JavaScript: the render shows every position's examples, and the stylesheet
-- shows only the selected position once the script runs. Every sentence of
-- prose is annotated in prose/front.vx.
--
-- @since 0.1.0.0
module Site.View
( Model
, Action
, app
) where
import Control.Monad (unless, void, when)
import Data.Char (isUpper)
import Data.Kind (Type)
import Data.List (groupBy)
import DesignKit.Brand (fontDisplay, gradientText)
import DesignKit.Effects (scrollProgressBar)
import Miso (App, Component (subs), Effect, component,
io_)
import Miso.DSL (FromJSVal (fromJSValUnchecked), isNull,
jsg, syncCallback1, (!), (#))
import Miso.Effect (Sub)
import Miso.Event.Types (KeyCode (KeyCode))
import Miso.FFI (focus)
import Miso.Html.Element (a_, blockquote_, button_, code_, div_,
footer_, h1_, h2_, h3_, h4_, header_, li_,
nav_, ol_, p_, section_, span_, ul_)
import Miso.Html.Event (onClick, onKeyDown)
import Miso.Html.Property (aria_, href_, id_, role_, tabindex_, type_)
import Miso.Property (classList)
import Miso.State (put)
import Miso.String (MisoString, fromMisoString, toMisoString)
import Miso.Types (View, text)
import Site.Content (Entry (entryHeading, entrySentences),
Example (exampleLabel, exampleReadings, exampleSentence),
Layer,
LayerExample (layerDecides, layerExample),
Reading (readingCodes, readingGloss),
entry, layerExamples, layerName, layers,
manual, package, pair, pairSlot,
repository)
import Site.Page (name)
-- | The position whose examples the menu shows.
--
-- @since 0.1.0.0
type Model :: Type
newtype Model = MkModel Layer
deriving stock (Eq)
-- | Selecting a position, by a click or by a key on its tab.
--
-- @since 0.1.0.0
type Action :: Type
data Action
= Select Layer
| Key Layer KeyCode
-- | Rendered and hydrated with the same view, the first position selected.
--
-- @since 0.1.0.0
app :: App Model Action
app = (component (MkModel minBound) update (const view)) {subs = [holdTabKeys]}
update :: Action -> Effect parent props Model Action
update = \case
Select l -> put (MkModel l)
Key l (KeyCode k) -> case k of
37 -> go (step (-1) l)
39 -> go (step 1 l)
36 -> go minBound
35 -> go maxBound
_ -> pure ()
where
go :: Layer -> Effect parent props Model Action
go l = put (MkModel l) >> io_ (focus (tabId l))
-- | Keeps the arrow, Home and End keys on a tab from scrolling the page: the
-- menu uses them to move between tabs. Other keys keep their defaults.
holdTabKeys :: Sub action
holdTabKeys _ = do
document <- jsg "document"
listener <- syncCallback1 $ \event -> do
target <- event ! "target"
role <- target # "getAttribute" $ ("role" :: MisoString)
absent <- isNull role
unless absent $ do
r <- fromJSValUnchecked role :: IO MisoString
k <- fromJSValUnchecked =<< (event ! "key") :: IO MisoString
when (r == "tab" && k `elem` ["ArrowLeft", "ArrowRight", "Home", "End"]) $
void (event # "preventDefault" $ ())
void (document # "addEventListener" $ ("keydown" :: MisoString, listener))
-- | Moves @n@ positions along the menu from the given one, wrapping at
-- either end.
step :: Int -> Layer -> Layer
step n l = toEnum ((fromEnum l + n) `mod` length layers)
view :: Model -> View Model Action
view (MkModel selected) =
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 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_ "entry"]
[ div_
[classList ["container"]]
[ h2_ [classList ["section-title"], fontDisplay] ["A clear ChangeLog entry"]
, div_
[classList ["changelog"]]
[ p_ [classList ["entry-heading"]] [text (entryHeading entry)]
, ul_ [classList ["entry-bullets"]] (map bullet (entrySentences entry))
]
]
]
, section_
[classList ["band"], id_ "verdicts"]
[ div_
[classList ["container"]]
[ h2_ [classList ["section-title"], fontDisplay] ["Clear, ambiguous or nonsense"]
, div_
[classList ["tabs"], role_ "tablist", aria_ "label" "Kinds of meaning"]
(map tab layers)
, div_ [classList ["panels"]] (map panel layers)
]
]
, 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 kind of document, such as a ChangeLog, a README or a manual, has its own rules about which sentence shapes it allows. \
\Every rule comes with examples: a sentence that breaks it and the smallest edit that fixes it."
]
]
]
, 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]
bullet :: Example -> View Model Action
bullet e =
li_
[]
(blockquote_ [classList ["entry"]] [text (exampleSentence e)] : readings (exampleReadings e))
tab :: Layer -> View Model Action
tab l =
button_
[ type_ "button"
, role_ "tab"
, id_ (tabId l)
, aria_ "controls" (panelId l)
, aria_ "selected" (if l == selected then "true" else "false")
, tabindex_ (if l == selected then "0" else "-1")
, classList ["tab", layerClass l, if l == selected then "active" else "inactive"]
, onClick (Select l)
, onKeyDown (Key l)
]
[text (layerName l)]
panel :: Layer -> View Model Action
panel l =
div_
[ role_ "tabpanel"
, id_ (panelId l)
, aria_ "labelledby" (tabId l)
, tabindex_ "0"
, classList ["panel", if l == selected then "active" else "inactive"]
]
[ h3_ [classList ["panel-title", layerClass l]] [text (layerName l)]
, ul_ [classList ["readings"]] (map layerCard (layerExamples l))
]
layerCard :: LayerExample -> View Model Action
layerCard x =
li_
[]
( [ h4_ [] [text (exampleLabel (layerExample x))]
, blockquote_ [classList ["entry"]] [text (exampleSentence (layerExample x))]
]
<> readings (exampleReadings (layerExample x))
<> [p_ [classList ["decides"]] [text (layerDecides x)]]
)
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)]
-- | A position's tab.
tabId :: Layer -> MisoString
tabId l = "tab-" <> layerName l
-- | A position's panel.
panelId :: Layer -> MisoString
panelId l = "panel-" <> layerName l
-- | A reading's codes, each in its own class, which codepoints.css colours by
-- the code's position, with brackets, separators and places 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 position.
layerClass :: Layer -> MisoString
layerClass l = "cp-" <> layerName l