~alcinnz/CatTrap

dff208a654ba290b5be7b4ab79a72dacdf62037a — Adrian Cochrane 11 months ago 156ac2a
Upload missing files.
3 files changed, 338 insertions(+), 0 deletions(-)

A app/Integration2.hs
A app/useragent.css
A test.html
A app/Integration2.hs => app/Integration2.hs +66 -0
@@ 0,0 1,66 @@
module Main where

import Text.HTML.DOM as HTML
import Text.XML as X
import Data.HTML2CSS (html2css, el2stylist)
import Network.URI (nullURI)

import Data.CSS.Preprocessor.Conditions as CSSCond
import qualified Data.CSS.Preprocessor.PsuedoClasses as CSSPseudo
import qualified Data.CSS.Style as Style
import Stylist.Tree (StyleTree(..), preorder, treeMap)
import qualified Data.CSS.Preprocessor.Text as CSSTxt
import Data.Maybe (fromMaybe)

import Graphics.Layout.CSS.Font (placeholderFont)
import Graphics.Layout.CSS (finalizeCSS', CSSBox)
import Graphics.Layout (LayoutItem, boxLayout)
import Graphics.Layout.Box (Length, Size(..), PaddedBox(..), zeroBox)

import Control.Exception (evaluate)
import qualified Graphics.Text.Font.Choose as FC

import Control.Concurrent.MVar (putMVar, newEmptyMVar, readMVar)
import Control.Concurrent (forkIO)
import Control.DeepSeq (NFData(..), ($!!))

resolve' = CSSCond.resolve lowerVars lowerToks
lowerVars _ = CSSCond.B False
lowerToks _ = CSSCond.B False

stylize' style = preorder inner
  where
    inner parent _ el = Style.cascade style el [] $
            Style.inherit $ fromMaybe Style.temp parent

main :: IO ()
main = do
    FC.init
    doc <- HTML.readFile "test.html"
    let css' :: CSSCond.ConditionalStyles (Style.VarParser (CSSTxt.TextStyle
                (CSSBox Nil)))
        css' = html2css doc nullURI $ CSSCond.conditionalStyles nullURI "temp"
    css' `seq` print "Parsed page with CSS!"
    let pseudoFilter = CSSPseudo.htmlPsuedoFilter Style.queryableStyleSheet
    let css = CSSPseudo.inner $ resolve' pseudoFilter css'
    let styles = CSSTxt.resolve $ treeMap Style.innerParser $
            stylize' css $ el2stylist $ X.documentRoot doc
    styles `seq` print "Styled page!"
    let layout :: LayoutItem Length Length Nil
        layout = finalizeCSS' placeholderFont styles
    layout `seq` print "Laying out page!"
    res <- forkCompute $ boxLayout zeroBox { size = Size 1280 480 } layout False
    readMVar res
    FC.fini

data Nil = Nil deriving Eq
instance Style.PropertyParser Nil where
    temp = Nil
    inherit _ = Nil
    longhand _ _ _ _ = Nothing
instance NFData Nil where rnf Nil = ()

forkCompute dat = do
    ret <- newEmptyMVar
    forkIO $ putMVar ret $!! dat
    return ret

A app/useragent.css => app/useragent.css +78 -0
@@ 0,0 1,78 @@
html, address,
blockquote,
body, dd, div,
dl, dt, fieldset, form,
frame, frameset,
h1, h2, h3, h4,
h5, h6, noframes,
ol, p, ul, center,
dir, hr, menu, pre   { display: block; unicode-bidi: embed }
li              { display: list-item }
head            { display: none }
table           { display: table }
tr              { display: table-row }
thead           { display: table-header-group }
tbody           { display: table-row-group }
tfoot           { display: table-footer-group }
col             { display: table-column }
colgroup        { display: table-column-group }
td, th          { display: table-cell }
caption         { display: table-caption }
th              { font-weight: bolder; text-align: center }
caption         { text-align: center }
body            { margin: 8px }
h1              { font-size: 2em; margin: .67em 0 }
h2              { font-size: 1.5em; margin: .75em 0 }
h3              { font-size: 1.17em; margin: .83em 0 }
h4, p,
blockquote, ul,
fieldset, form,
ol, dl, dir,
menu            { margin: 1.12em 0 }
h5              { font-size: .83em; margin: 1.5em 0 }
h6              { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4,
h5, h6, b,
strong          { font-weight: bolder }
blockquote      { margin-left: 40px; margin-right: 40px }
i, cite, em,
var, address    { font-style: italic }
pre, tt, code,
kbd, samp       { font-family: monospace }
pre             { white-space: pre }
button, textarea,
input, select   { display: inline-block }
big             { font-size: 1.17em }
small, sub, sup { font-size: .83em }
sub             { vertical-align: sub }
sup             { vertical-align: super }
table           { border-spacing: 2px; }
thead, tbody,
tfoot           { vertical-align: middle }
td, th, tr      { vertical-align: inherit }
s, strike, del  { text-decoration: line-through }
hr              { border: 1px inset }
ol, ul, dir,
menu, dd        { margin-left: 40px }
ol              { list-style-type: decimal }
ol ul, ul ol,
ul ul, ol ol    { margin-top: 0; margin-bottom: 0 }
u, ins          { text-decoration: underline }
br:before       { content: "\A"; white-space: pre-line }
center          { text-align: center }
:link, :visited { text-decoration: underline }
:focus          { outline: thin dotted invert }

/* Begin bidirectionality settings (do not change) */
BDO[DIR="ltr"]  { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"]  { direction: rtl; unicode-bidi: bidi-override }

*[DIR="ltr"]    { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"]    { direction: rtl; unicode-bidi: embed }

@media print {
  h1            { page-break-before: always }
  h1, h2, h3,
  h4, h5, h6    { page-break-after: avoid }
  ul, ol, dl    { page-break-before: avoid }
}

A test.html => test.html +194 -0
@@ 0,0 1,194 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf8"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>~alcinnz/CatTrap - Argonaut Constellation git</title>
<link href="/static/logo.svg" rel="icon" type="image/svg+xml"/>
<link href="/static/logo.png" rel="icon" type="image/png"/>
<link href="/static/main.min.33101d6b.css" rel="stylesheet"/>
<meta content="git" name="vcs"/>
<meta content="main" name="vcs:default-branch"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap" name="vcs:clone"/>
<meta content="git@git.argonaut-constellation.org:~alcinnz/CatTrap" name="vcs:clone"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap" name="forge:summary"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap/tree/{ref}/item/{path}" name="forge:dir"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap/tree/{ref}/item/{path}" name="forge:file"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap/blob/{ref}/{path}" name="forge:rawfile"/>
<meta content="https://git.argonaut-constellation.org/~alcinnz/CatTrap/tree/{ref}/item/{path}#L{line}" name="forge:line"/>
<meta content="git.argonaut-constellation.org/~alcinnz/CatTrap git https://git.argonaut-constellation.org/~alcinnz/CatTrap" name="go-import"/>
</head>
<body>
<nav class="container navbar navbar-light navbar-expand-sm">
<span class="navbar-brand">
<span aria-hidden="true" class="icon icon-circle"><svg height="22" viewbox="0 0 512 512" width="22" xmlns="http://www.w3.org/2000/svg"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z"></path></svg>
</span>
<a class="navbar-brand" href="/">
    Argonaut Constellation
    <span class="text-danger">git</span>
</a>
</span>
<ul class="navbar-nav">
</ul>
<div class="login">
<span class="navbar-text">
<a href="https://meta.argonaut-constellation.org/oauth/authorize?client_id=2dda1cfc-1c88-4508-88bd-69dbe35ae79a&amp;scopes=profile,keys&amp;state=%2F~alcinnz%2FCatTrap%3F" rel="nofollow">Log in</a>
    <a href="https://meta.argonaut-constellation.org">Register</a>
</span>
</div>
</nav>
<div class="header-tabbed">
<div class="container">
<h2>
<a href="/~alcinnz/">~alcinnz</a>/<wbr/>CatTrap
    </h2>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="/~alcinnz/CatTrap">summary</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/~alcinnz/CatTrap/tree">tree</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/~alcinnz/CatTrap/log">log</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/~alcinnz/CatTrap/refs">refs</a>
</li>
</ul>
</div>
</div>
<div class="header-extension">
<div class="container">
<div class="row">
<div class="col-md-6">
        Lays out the CSS Box Model, this being the internet some of these boxes will contain cats!
      </div>
<div class="col-md-6 licenses">

</div>
</div>
</div>
</div>
<div class="container">
<div class="row" style="margin-bottom: 1rem">
<div class="col-md-6">
<div class="event-list" style="margin-bottom: 0.5rem">
<div class="event">
<div>
<a href="/~alcinnz/CatTrap/commit/9478d6300bcae4f6d5c29d7777a7544303358dba" title="9478d6300bcae4f6d5c29d7777a7544303358dba">9478d630</a>
  
  
  
  Adrian Cochrane
  
  <small class="pull-right">
<a href="/~alcinnz/CatTrap/log?from=9478d6300bcae4f6d5c29d7777a7544303358dba#log-9478d6300bcae4f6d5c29d7777a7544303358dba" id="log-9478d6300bcae4f6d5c29d7777a7544303358dba"><span title="2023-09-27 21:26:36 UTC">6 days ago</span></a>
</small>
</div>
<pre class="commit">Performance optimizations: Concurrency, &amp; move download/styling/layout to out-of-thread.</pre>
</div>
<div class="event">
<div>
<a href="/~alcinnz/CatTrap/commit/6db35caa19f922eee56e22eb36034e2232de05dd" title="6db35caa19f922eee56e22eb36034e2232de05dd">6db35caa</a>
  
  
  
  Adrian Cochrane
  
  <small class="pull-right">
<a href="/~alcinnz/CatTrap/log?from=6db35caa19f922eee56e22eb36034e2232de05dd#log-6db35caa19f922eee56e22eb36034e2232de05dd" id="log-6db35caa19f922eee56e22eb36034e2232de05dd"><span title="2023-07-14 03:03:28 UTC">2 months ago</span></a>
</small>
</div>
<pre class="commit">Fix for Balkon update.</pre>
</div>
<div class="event">
<div>
<a href="/~alcinnz/CatTrap/commit/590ef319be4179b113a8fc2212fe0f27b0dc3daf" title="590ef319be4179b113a8fc2212fe0f27b0dc3daf">590ef319</a>
  
  
  
  Adrian Cochrane
  
  <small class="pull-right">
<a href="/~alcinnz/CatTrap/log?from=590ef319be4179b113a8fc2212fe0f27b0dc3daf#log-590ef319be4179b113a8fc2212fe0f27b0dc3daf" id="log-590ef319be4179b113a8fc2212fe0f27b0dc3daf"><span title="2023-07-03 05:03:15 UTC">3 months ago</span></a>
</small>
</div>
<pre class="commit">Fix inline sizing, handle length units for callers.</pre>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-4">
<h3>refs</h3>
<dl>
<dt>main</dt>
<dd>
<a href="/~alcinnz/CatTrap/tree">browse <span aria-hidden="true" class="icon icon-caret-right"><svg viewbox="0 0 192 512" xmlns="http://www.w3.org/2000/svg"><path d="M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z"></path></svg>
</span></a>
<a href="/~alcinnz/CatTrap/log">log <span aria-hidden="true" class="icon icon-caret-right"><svg viewbox="0 0 192 512" xmlns="http://www.w3.org/2000/svg"><path d="M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z"></path></svg>
</span></a>
</dd>
</dl>
</div>
<div class="col-md-8">
<h3>clone</h3>
<dl>
<dt>read-only</dt>
<dd><a href="https://git.argonaut-constellation.org/~alcinnz/CatTrap">https://git.argonaut-constellation.org/~alcinnz/CatTrap</a></dd>
<dt>read/write</dt>
<dd>git@git.argonaut-constellation.org:~alcinnz/CatTrap</dd>
</dl>
</div>
</div>
<div class="row">
<div class="col-md-8 offset-md-4">
<form action="/clone" method="POST">
<input dir="auto" name="_csrf_token" type="hidden" value="7d4824827f4b7ae51d24b9dafc30829684f8784cd9aabc99938558fb1a7ce5ad63b2257bc9d777e7b1b251e46d693ecb2a18a9a76bfa9bc23f9e31433d17ead4"/>
<input dir="auto" name="cloneUrl" type="hidden" value="https://git.argonaut-constellation.org/~alcinnz/CatTrap"/>
<input dir="auto" name="name" type="hidden" value="CatTrap"/>
<input dir="auto" name="description" type="hidden" value="Clone of https://git.argonaut-constellation.org/~alcinnz/CatTrap"/>
<input dir="auto" name="visibility" type="hidden" value="UNLISTED"/>
<button class="btn btn-primary btn-block" type="submit">
              Clone repo to your account <span aria-hidden="true" class="icon icon-caret-right"><svg viewbox="0 0 192 512" xmlns="http://www.w3.org/2000/svg"><path d="M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z"></path></svg>
</span>
</button>
<p class="text-muted text-centered">
<small>
                You can also use your local clone with
                <a href="https://git-send-email.io">git send-email</a>.
              </small>
</p>
</form>
</div>
</div>
</div>
</div>
<div class="row" id="readme">
<div class="col-md-10">
<style>.highlight { background: inherit; }</style><div class="markdown"><h2 id="cattrap"><a href="#cattrap" rel="nofollow noopener">#</a>CatTrap</h2>
<p><a href="https://git.argonaut-constellation.org/~alcinnz/CatTrap" rel="nofollow noopener">Repository</a> | <a href="https://todo.argonaut-constellation.org/" rel="nofollow noopener">Issue Tracker</a></p>
<p>Lays out boxes according to the <a href="https://www.w3.org/TR/css-box-3/" rel="nofollow noopener">CSS Box Model</a>, computing where to place e.g. images, paragraphs, containers, tables, etc onscreen given desired amounts of whitespace.</p>
<p>It is a layout engine for <a href="https://argonaut-constellation.org/" rel="nofollow noopener">The Argonaut Stack</a> browser engine, and as such this being the internet some of these boxes will inevitably contain cats.</p>
<p>TODO: Say more about how to use this once its implemented.</p>
<h3 id="contributing"><a href="#contributing" rel="nofollow noopener">#</a>Contributing</h3>
<p>Please send patches to our <a href="https://todo.argonaut-constellation.org/~alcinnz/CatTrap" rel="nofollow noopener">issue tracker</a> by either:</p>
<ul>
<li>Attaching the output of <code>git format-patch</code>.</li>
<li><a href="https://git-send-email.io/" rel="nofollow noopener">git send-email</a> to <a href="mailto:~alcinnz/CatTrap@todo.argonaut-constellation.org" rel="nofollow noopener">~alcinnz/CatTrap@todo.argonaut-constellation.org</a> .</li>
<li>Linking to your fork elsewhere.</li>
</ul>
<p>Whichever you find most convenient.</p>
<p>If you'd prefer to not make your email address public please contact <a href="mailto:alcinnz@argonaut-constellation.org" rel="nofollow noopener">alcinnz@argonaut-constellation.org</a> !</p>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file