dark mode
[pharext/replicator.pharext.org] / public / html.php
index 13ed7be8e2a6fef63f8eadf5fed15c4ce023e6ea..759165e0ff7d68bf29f53a31a4695b0244ec1c27 100644 (file)
@@ -1,10 +1,14 @@
 <?php
 const INCLUDED = __FILE__;
 const NCURRENT = 2;
+
+$css = "concise/css/concise.min.css";
+$fnt = "//fonts.googleapis.com/css?family=Droid+Sans";
+
 require_once "index.php";
 
 ob_start($res);
-$res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/concise.min.css>; rel=preload; as=style");
+$res->addHeader("Link", "<" . dirname((new http\Env\Url)->path) . "/" . $css . ">; rel=preload; as=style");
 
 ?>
 <!doctype html>
@@ -12,9 +16,10 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
        <head>
                <meta charset="utf-8">
                <title>Replicator</title>
-               <link rel="stylesheet" href="concise/css/concise.min.css">
-               <link href="//fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css">
+               <link rel="stylesheet" href="<?=$css?>">
+               <link rel="stylesheet" href="<?=$fnt?>">
                <meta name="viewport" content="width=device-width, initial-scale=1">
+               <meta name="color-scheme" content="dark light">
                <style>
                        body {
                                padding-bottom: 2em;
@@ -32,12 +37,11 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                        }
                        .header, .footer {
                                position: fixed;
-                               box-shadow: 0px 0px .8em .4em #89a;
-                               background: #62B3E7;
                                padding: .5em 0;
                        }
                        .header h1 {
                                font-weight: bold;
+                               line-height:120%;
                        }
                        .header h1 a, .footer a:hover {
                                text-decoration: none;
@@ -49,14 +53,8 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                                /* normalize browser difference */
                                font-size: 1.3em;
                        }
-                       .header h1 a, .footer, .footer a {
-                               color: #fdfdfd;
-                               text-shadow: grey 0 0 .1em;
-                       }
                        .header h1 small {
-                               color: #666;
                                font-size: 1.3rem;
-                               text-shadow: white 0 0 .2em;
                        }
                        li {
                                list-style-type: circle;
@@ -79,6 +77,9 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                        .row>h3 {
                                margin-bottom: 0;
                        }
+                       hr {
+                               margin: 2em 0;
+                       }
                        @media(max-width: 80em) {
                                .column-8 {
                                        float: none;
@@ -88,6 +89,54 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                        .old-version, #new-toggle {
                                display: none;
                        }
+                       p.package-description, div.package-description p {
+                               white-space: pre-line;
+                       }
+                       .package-list {
+                       }
+                       .package-ch {
+                       }
+                       form * {
+                               display: inline-block;
+                               margin-right: 1em;
+                       }
+                       form label input{
+                               margin-left: 1em;
+                               vertical-align: middle;
+                       }
+                       form input[type=reset] {
+                               padding: 0;
+                       }
+                       .header, .footer {
+                               box-shadow: 0px 0px .8em .4em #89a;
+                               background: #62B3E7;
+                       }
+                       .header h1 a, .footer, .footer a {
+                               color: #fdfdfd;
+                               text-shadow: grey 0 0 .1em;
+                       }
+                       .header h1 small {
+                               color: #666;
+                               text-shadow: white 0 0 .2em;
+                       }
+                       @media (prefers-color-scheme: dark) {
+                               .header, .footer {
+                                       box-shadow: 0px 0px .8em .4em #123;
+                                       background: #305872;
+                               }
+                               .header h1 a, .footer, .footer a {
+                                       color: #bdbdbd;
+                                       text-shadow: dimgrey 0 0 .1em;
+                               }
+                               .header h1 small {
+                                       color: #aaa;
+                                       text-shadow: black 0 0 .2em;
+                               }
+                               body, h2, h3, h4, h5, h6 {
+                                       background: #3a3b3f;
+                                       color: #bdbdbd;
+                               }
+                       }
                </style>
        </head>
        <body>
@@ -102,9 +151,28 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                </div>
                <div class="container">
 
-                       <?php if (!empty($package)) : $versions = package_versions($package); ?>
+                       <?php if (!empty($package)) : $versions = package_versions($package); $info = package_info($package); ?>
 
                        <h2><?= htmlspecialchars($package) ?></h2>
+                       <?php if ($info) : ?>
+                               <h3><?= htmlspecialchars($info["title"]) ?><br>
+                                       <small>License: <?= htmlspecialchars($info["license"]) ?><br>
+                                               <a href="//pecl.php.net/package/<?= htmlspecialchars($package) ?>">View at PECL</a></small></h3>
+                               <?php if (extension_loaded("discount")) : ?>
+                               <div class="package-description">
+                                       <?php
+                                       $md = MarkdownDocument::createFromString($info["description"]);
+                                       $md->compile(   MarkdownDocument::AUTOLINK |
+                                                                       MarkdownDocument::ONE_COMPAT);
+                                       echo $md->getHtml();
+                                       ?>
+                               </div>
+                               <?php else : ?>
+                               <p class="package-description">
+                                       <?= htmlspecialchars($info["description"]) ?>
+                               </p>
+                               <?php endif; ?>
+                       <?php endif; ?>
                        <table class="table table-full versions">
                                <thead>
                                        <tr>
@@ -156,19 +224,21 @@ $res->addHeader("Link", "<".dirname((new http\Env\Url)->path)."concise/css/conci
                                                        less versions &laquo;</a>
                                        </p>
                                <?php endif; ?>
+
                        <?php else:     ?>
 
                        <h2>Available Packages</h2>
-                       <ul class="list-inline">
+                       <form name="search"></form>
+                       <ul class="list-inline package-list">
                        <?php foreach (array_map("htmlspecialchars", $packages) as $index => $pkg) : ?>
-                               <?php $next = strtolower($pkg{0}); ?>
+                               <?php $next = strtolower($pkg[0]); ?>
                                <?php if (isset($prev) && $next != $prev) : ?>
 
                        </ul>
-                       <ul class="list-inline">
+                       <ul class="list-inline package-list">
                                <?php endif; ?>
 
-                               <li><a href="?<?= $pkg ?>"><?=  $pkg ?></a></li>
+                               <li id="<?= strtolower($pkg) ?>"><a href="?<?= $pkg ?>"><?=  $pkg ?></a></li>
                                <?php $prev = $next; ?>
                        <?php endforeach; ?>
 
@@ -230,6 +300,95 @@ gpg --verify <?= htmlspecialchars(basename($phar)).".asc" ?> \
                        </footer>
                </div>
                <script type="text/javascript">
+               function searchPackages(search, regex) {
+                       console.log("searchPackages", search, regex);
+                       document.querySelectorAll("ul.package-list li").forEach(function(li) {
+                               if (regex) {
+                                       if (li.id.match(search.toLowerCase())) {
+                                               li.style.removeProperty("display");
+                                       } else {
+                                               li.style.display = "none";
+                                       }
+                               } else {
+                                       if (li.id.startsWith(search.toLowerCase())) {
+                                               li.style.removeProperty("display");
+                                       } else {
+                                               li.style.display = "none";
+                                       }
+                               }
+                       });
+               }
+
+               document.body.onload = function() {
+                       var form = document.querySelector("form[name=search]");
+
+                       if (!form) return;
+
+                       var input = document.createElement("input");
+                       var reset = document.createElement("input");
+                       var prefix_label = document.createElement("label");
+                       var prefix = document.createElement("input");
+                       var regex_label = document.createElement("label");
+                       var regex = document.createElement("input");
+
+                       form.onreset = function() {
+                               searchPackages("", false);
+                       };
+
+                       input.id = "s";
+                       input.autocomplete = "off";
+                       input.name = "s";
+                       input.type = "search";
+                       input.placeholder = "Search...";
+                       input.oninput = function() {
+                               searchPackages(input.value, regex.checked);
+                       };
+                       input.style.paddingRight = "4ch";
+                       form.appendChild(input);
+
+                       reset.id = "r";
+                       reset.name = "r";
+                       reset.type = "reset";
+                       reset.value = "☒";
+                       reset.title = "Reset";
+                       reset.style.marginLeft = "-4ch";
+                       reset.style.marginRight = "4ch";
+                       reset.style.border = "none";
+                       reset.style.background = "transparent";
+                       form.appendChild(reset);
+
+                       prefix.id = "prefix";
+                       prefix.name = "by";
+                       prefix.value = "prefix";
+                       prefix.type = "radio";
+                       prefix.defaultChecked = true;
+                       prefix.checked = true;
+                       prefix.onchange = function() {
+                               searchPackages(input.value, regex.checked);
+                       };
+                       //form.appendChild(prefix);
+                       prefix_label.innerText = "by Prefix";
+                       prefix_label.appendChild(prefix);
+                       form.appendChild(prefix_label);
+
+                       regex.id = "regex";
+                       regex.name = "by";
+                       regex.value = "regex";
+                       regex.type = "radio";
+                       regex.checked = false;
+                       regex.onchange = function() {
+                               searchPackages(input.value, regex.checked);
+                       };
+                       //form.appendChild(regex);
+                       regex_label.innerText = "by RegExp";
+                       regex_label.appendChild(regex);
+                       form.appendChild(regex_label);
+
+                       form.after(document.createElement("HR"));
+
+                       input.focus();
+               };
+
                function toggleOldVersions(a) {
                        var nodes, row_style;