@mark1russell7/site-pages 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/build/{build-CD2wc7Yl.js → build-xJqNIzdO.js} +18 -2
- package/build/build-xJqNIzdO.js.map +1 -0
- package/build/chrome.d.ts +63 -0
- package/build/chrome.d.ts.map +1 -0
- package/build/chrome.js +117 -0
- package/build/chrome.js.map +1 -0
- package/build/cli.js +29 -9
- package/build/cli.js.map +1 -1
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/package.json +14 -10
- package/build/build-CD2wc7Yl.js.map +0 -1
package/README.md
CHANGED
|
@@ -66,9 +66,10 @@ A view fails for each of these problems:
|
|
|
66
66
|
- The page shows no text.
|
|
67
67
|
- The page writes a console error, or a script throws an exception.
|
|
68
68
|
- A request to the site fails, or gets a status of 400 or more.
|
|
69
|
+
- A script or a style sheet does not load, from any origin. An example is a module script that imports `node:perf_hooks`.
|
|
69
70
|
- A check of the probe fails, or the probe makes no check.
|
|
70
71
|
|
|
71
|
-
The probe is a JavaScript file. Its code is the body of an async function. These functions are available:
|
|
72
|
+
The probe is a JavaScript file or a TypeScript file (`.ts`, `.mts` or `.cts`). Its code is the body of an async function. These functions are available:
|
|
72
73
|
|
|
73
74
|
| Function | Operation |
|
|
74
75
|
| --- | --- |
|
|
@@ -82,6 +83,8 @@ type("#editor", "Utilize the cache.");
|
|
|
82
83
|
check("the linter finds a word", await until(() => $$(".finding").length === 1), $$(".finding").length);
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
For a TypeScript probe, the check removes the types and the line `export {};` before it runs the probe. Thus the typecheck of the site examines the probe, and the site needs no build step for it. Each line stays at its position, so the line of an error is the line of the source. Declare the functions of the table with `declare const`, and add `export {};` at the end, so the file is a module. `probeScript` does the same operation for a script of your own.
|
|
87
|
+
|
|
85
88
|
The check runs the probe on the first page, in the first scheme, at each width. The folder of `--shots` gets a screenshot of each view, `report.json` and `summary.md`. The exit code is 0 when each view passes, 1 when a view fails, and 2 for an incorrect command line.
|
|
86
89
|
|
|
87
90
|
The check finds a browser in this order: `--browser`, `$SITE_CHECK_BROWSER`, the newest Chromium of Playwright, and then Chrome or Edge. The folder `src/check` imports only Node.js. Thus Node.js 22.18 or later can start `src/check/main.ts` with no install. The workflow `reusable-pages.yml` of the template uses it this way.
|
|
@@ -294,6 +297,39 @@ The class sets `overflow-x: auto` and the background color of the box. Set `--sc
|
|
|
294
297
|
}
|
|
295
298
|
```
|
|
296
299
|
|
|
300
|
+
## The page helpers
|
|
301
|
+
|
|
302
|
+
The entry `@mark1russell7/site-pages/chrome` has small helpers for the script of a page. It imports no Node.js module, so a site can bundle it for the browser. The package root does not export these helpers. Thus a Node.js program that imports the root gets no DOM types.
|
|
303
|
+
|
|
304
|
+
| Function | Operation |
|
|
305
|
+
| --- | --- |
|
|
306
|
+
| `h(tag, attrs, ...children)` | Makes an element. The attribute `class` sets the class name. `false`, `null` and `undefined` give no attribute and no child. |
|
|
307
|
+
| `byId(id)` | Gives the element with the ID. It throws when the page has no such element. |
|
|
308
|
+
| `setupTheme(button, storageKey)` | Makes a theme button: auto, light, dark, in turn. It sets `data-theme` on the `html` element and keeps the choice in `localStorage`. |
|
|
309
|
+
| `currentTheme()`, `nextTheme(storageKey)`, `applyTheme(theme, storageKey)` | Read the theme, set the next theme, or set one theme. A site with its own button, for example a React component, uses them. |
|
|
310
|
+
| `copyText(button, text, options)` | Copies a text. The button shows "Copied" or "Copy failed" for 1600 ms. |
|
|
311
|
+
| `copyToClipboard(text)` | Copies a text with the Clipboard API, else with `document.execCommand`. It gives `true` after a copy. |
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
import { byId, copyText, h, setupTheme } from "@mark1russell7/site-pages/chrome";
|
|
315
|
+
|
|
316
|
+
setupTheme(byId<HTMLButtonElement>("theme"), "my-site-theme");
|
|
317
|
+
const copy = h("button", { type: "button", class: "copy" }, "Copy");
|
|
318
|
+
copy.addEventListener("click", () => void copyText(copy, "pnpm add my-package"));
|
|
319
|
+
byId("install").append(copy);
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
The theme `auto` removes `data-theme`, and the CSS of the site then obeys `prefers-color-scheme`. Put this script in the `head` of the page, with the same key. It sets the theme before the first paint, so a dark page does not show white for a moment:
|
|
323
|
+
|
|
324
|
+
```html
|
|
325
|
+
<script>
|
|
326
|
+
try {
|
|
327
|
+
const t = localStorage.getItem("my-site-theme");
|
|
328
|
+
if (t === "light" || t === "dark") document.documentElement.dataset.theme = t;
|
|
329
|
+
} catch {}
|
|
330
|
+
</script>
|
|
331
|
+
```
|
|
332
|
+
|
|
297
333
|
## A GitHub Pages workflow
|
|
298
334
|
|
|
299
335
|
This workflow builds the site, adds the two pages, and deploys. It also starts every 3 hours, so the status page stays current without a push. A scheduled run builds the newest commit of `main` that passed CI.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripTypeScriptTypes } from "node:module";
|
|
1
2
|
import { execFileSync } from "node:child_process";
|
|
2
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { basename, dirname, isAbsolute, join, posix, resolve } from "node:path";
|
|
@@ -2336,6 +2337,21 @@ function renderStatusPage(data, options) {
|
|
|
2336
2337
|
script: STATUS_SCRIPT
|
|
2337
2338
|
}, options);
|
|
2338
2339
|
}
|
|
2340
|
+
// src/check/probe.ts
|
|
2341
|
+
/**
|
|
2342
|
+
* The probe of `site-pages check` in TypeScript. A probe source can be TypeScript, so the typecheck of the site examines it.
|
|
2343
|
+
* The check removes its types before it runs the probe, so a site needs no build step for its probe.
|
|
2344
|
+
*/
|
|
2345
|
+
/** A probe file in TypeScript: `.ts`, `.mts` or `.cts`. */
|
|
2346
|
+
const TYPESCRIPT_PROBE = /\.[cm]?ts$/i;
|
|
2347
|
+
/**
|
|
2348
|
+
* This function gives the JavaScript of a probe in TypeScript. It removes the types, and the line `export {};` that makes the
|
|
2349
|
+
* file a module for the typecheck. Each line stays at its position, so the line of an error is the line of the source. Syntax
|
|
2350
|
+
* that is not only types (an `enum`, a `namespace`) causes an error.
|
|
2351
|
+
*/
|
|
2352
|
+
function probeScript(source) {
|
|
2353
|
+
return stripTypeScriptTypes(source, { mode: "strip" }).replace(/^export \{\s*\};?[ \t]*$/m, "");
|
|
2354
|
+
}
|
|
2339
2355
|
// src/build.ts
|
|
2340
2356
|
/**
|
|
2341
2357
|
* The `site-pages build` command. It reads the sources. Then it writes the JSON data and the two
|
|
@@ -2532,6 +2548,6 @@ async function runCli(argv, io) {
|
|
|
2532
2548
|
throw error;
|
|
2533
2549
|
}
|
|
2534
2550
|
}
|
|
2535
|
-
export {
|
|
2551
|
+
export { originRepository as $, safeUrl as A, roadmapItems as B, pageShell as C, utcDay as D, shortDate as E, linksOf as F, mergeReleases as G, statusClassOf as H, markdownTables as I, globFiles as J, readChangelogs as K, parseRoadmap as L, RoadmapParseError as M, STATUS_CLASSES as N, escapeHtml as O, buildStatusBoard as P, isShallow as Q, plainText as R, BASE_CSS as S, longDate as T, DEFAULT_CHANGELOGS as U, splitRow as V, ReleaseDataError as W, headCommit as X, gitTagDates as Y, headingDate as Z, renderReleasesPage as _, runCli as a, githubOpenWork as at, releaseSummary as b, STATUS_SCRIPT as c, headingAnchor as ct, renderStatusPage as d, compareVersions as dt, NPM_REGISTRY as et, sectionsOf as f, kindOf as ft, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, checkStateOf as it, OPEN_CLASSES as j, inlineMarkdown as k, classCounts as l, parseChangelog as lt, statusLead as m, versionOfTag as mt, UsageError as n, GITHUB_API as nt, TYPESCRIPT_PROBE as o, githubReleases as ot, slugOf as p, parseVersion as pt, readReleases as q, build as r, GITHUB_GRAPHQL as rt, probeScript as s, firstSentence as st, HELP as t, npmPublishTimes as tt, openGroups as u, releaseBodyEntries as ut, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, readStatusBoard as z };
|
|
2536
2552
|
|
|
2537
|
-
//# sourceMappingURL=build-
|
|
2553
|
+
//# sourceMappingURL=build-xJqNIzdO.js.map
|