@mark1russell7/site-pages 0.5.2 → 0.5.4
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 +1 -0
- package/build/chrome.d.ts +7 -1
- package/build/chrome.d.ts.map +1 -1
- package/build/chrome.js +21 -2
- package/build/chrome.js.map +1 -1
- package/build/config/site-config.d.ts +114 -0
- package/build/config/site-config.d.ts.map +1 -0
- package/build/config/site-config.js +211 -0
- package/build/config/site-config.js.map +1 -0
- package/build/explorer/index.d.ts.map +1 -1
- package/build/explorer/index.js +45 -51
- package/build/explorer/index.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -516,6 +516,7 @@ The entry `@mark1russell7/site-pages/chrome` has small helpers for the script of
|
|
|
516
516
|
| Function | Operation |
|
|
517
517
|
| --- | --- |
|
|
518
518
|
| `h(tag, attrs, ...children)` | Makes an element. The attribute `class` sets the class name. `false`, `null` and `undefined` give no attribute and no child. |
|
|
519
|
+
| `svg(tag, attrs, ...children)` | Makes an SVG element, with the rules of `h`. The attribute `class` sets the attribute `class`. |
|
|
519
520
|
| `byId(id)` | Gives the element with the ID. It throws when the page has no such element. |
|
|
520
521
|
| `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`. |
|
|
521
522
|
| `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. |
|
package/build/chrome.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The small helpers of a page in the browser: the element
|
|
2
|
+
* The small helpers of a page in the browser: the element helpers, the element lookup, the theme
|
|
3
3
|
* button, the copy button and the build stamp. It also has a radio group with one focus stop.
|
|
4
4
|
* This module imports no Node.js module, so a site can bundle it. Import it from
|
|
5
5
|
* `@mark1russell7/site-pages/chrome`, because the package root also has Node.js code.
|
|
@@ -13,6 +13,12 @@ export type AttributeValue = string | number | boolean | null | undefined;
|
|
|
13
13
|
* `false`, `null` or `undefined` is not set. The attribute `class` sets the class name.
|
|
14
14
|
*/
|
|
15
15
|
export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, attrs?: Readonly<Record<string, AttributeValue>>, ...children: readonly (Child | readonly Child[])[]): HTMLElementTagNameMap[K];
|
|
16
|
+
/**
|
|
17
|
+
* This function makes an SVG element with attributes and children, with the rules of `h`. The
|
|
18
|
+
* attribute `class` sets the attribute `class`, because the class name of an SVG element is
|
|
19
|
+
* read-only.
|
|
20
|
+
*/
|
|
21
|
+
export declare function svg<K extends keyof SVGElementTagNameMap>(tag: K, attrs?: Readonly<Record<string, AttributeValue>>, ...children: readonly (Child | readonly Child[])[]): SVGElementTagNameMap[K];
|
|
16
22
|
/**
|
|
17
23
|
* This function gives the element with the ID. The page has each ID that the code asks for. Thus
|
|
18
24
|
* a missing ID is an error of the page, and the function throws an `Error`.
|
package/build/chrome.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chrome.d.ts","names":[],"sources":["../src/chrome.ts"],"mappings":";;;;;;;YASY,QAAQ;;YAGR;;;;;wBAMI,EAAE,gBAAgB,uBAChC,KAAK,GACL,QAAO,SAAS,eAAe,qBAC5B,oBAAoB,iBAAiB,aACvC,sBAAsB;;;;;
|
|
1
|
+
{"version":3,"file":"chrome.d.ts","names":[],"sources":["../src/chrome.ts"],"mappings":";;;;;;;YASY,QAAQ;;YAGR;;;;;wBAMI,EAAE,gBAAgB,uBAChC,KAAK,GACL,QAAO,SAAS,eAAe,qBAC5B,oBAAoB,iBAAiB,aACvC,sBAAsB;;;;;;wBAeT,IAAI,gBAAgB,sBAClC,KAAK,GACL,QAAO,SAAS,eAAe,qBAC5B,oBAAoB,iBAAiB,aACvC,qBAAqB;;;;;wBA8BR,KAAK,UAAU,cAAc,aAAa,aAAa;;qBAO1D;;YAGD,gBAAgB;;;;;wBAMZ,gBAAgB;;;;;wBAShB,WAAW,OAAO,OAAO;;wBAazB,UAAU,qBAAqB;;;;;;;;;wBAc/B,WAAW,QAAQ,mBAAmB;;iBAUrC;;WAEN;;WAEA;;WAEA;;;;;;;;;wBAUK,UAAU,SAAS,aAAa,OAAO,WAAW;;;;;wBAS5C,gBAAgB,eAAe;;iBA0BpC;;WAEN;;WAEA;;WAEA;;;;;;wBAOW,SAAS,QAAQ,mBAAmB,cAAc,UAAS,kBAAuB;;;YAY5F;;;;;;wBAaI,YAAY,aAAa,eAAe,eAAe,OAAM;;iBAQ5D,OAAO;;WAEb,OAAO;;WAEP;;WAEA;;;;;;;qBAQE,UAAU;mBACJ;mBACA;mBACA;UACT;;;;;EAMR,YAAY,WAAW,aAAa,kBAAkB,OAAO,MAAM,SAAS,GAAG,WAAW,OAAO,YAAY,OAAM;;MAyB/G,SAAS;;EAKb,IAAI,OAAO;UAKH;UAOA"}
|
package/build/chrome.js
CHANGED
|
@@ -5,9 +5,28 @@
|
|
|
5
5
|
*/
|
|
6
6
|
function h(tag, attrs = {}, ...children) {
|
|
7
7
|
const el = document.createElement(tag);
|
|
8
|
+
return fill(el, attrs, children, (value) => {
|
|
9
|
+
el.className = value;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** The namespace of the SVG elements. */
|
|
13
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
14
|
+
/**
|
|
15
|
+
* This function makes an SVG element with attributes and children, with the rules of `h`. The
|
|
16
|
+
* attribute `class` sets the attribute `class`, because the class name of an SVG element is
|
|
17
|
+
* read-only.
|
|
18
|
+
*/
|
|
19
|
+
function svg(tag, attrs = {}, ...children) {
|
|
20
|
+
const el = document.createElementNS(SVG_NS, tag);
|
|
21
|
+
return fill(el, attrs, children, (value) => {
|
|
22
|
+
el.setAttribute("class", value);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** This function sets the attributes and adds the children of an element of `h` or `svg`. */
|
|
26
|
+
function fill(el, attrs, children, setClass) {
|
|
8
27
|
for (const [name, value] of Object.entries(attrs)) {
|
|
9
28
|
if (value === false || value === null || value === void 0) continue;
|
|
10
|
-
if (name === "class")
|
|
29
|
+
if (name === "class") setClass(String(value));
|
|
11
30
|
else el.setAttribute(name, value === true ? "" : String(value));
|
|
12
31
|
}
|
|
13
32
|
for (const child of children.flat()) {
|
|
@@ -214,6 +233,6 @@ var Segmented = class {
|
|
|
214
233
|
});
|
|
215
234
|
}
|
|
216
235
|
};
|
|
217
|
-
export { Segmented, THEMES, applyTheme, byId, copyText, copyToClipboard, currentTheme, h, nextTheme, rovingIndex, setupTheme, showBuild };
|
|
236
|
+
export { Segmented, THEMES, applyTheme, byId, copyText, copyToClipboard, currentTheme, h, nextTheme, rovingIndex, setupTheme, showBuild, svg };
|
|
218
237
|
|
|
219
238
|
//# sourceMappingURL=chrome.js.map
|
package/build/chrome.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chrome.js","names":[],"sources":["../src/chrome.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * The small helpers of a page in the browser: the element helper, the element lookup, the theme\n * button, the copy button and the build stamp. It also has a radio group with one focus stop.\n * This module imports no Node.js module, so a site can bundle it. Import it from\n * `@mark1russell7/site-pages/chrome`, because the package root also has Node.js code.\n */\n\n/** A child of `h`: a node or a text. The values `null`, `undefined` and `false` give no child. */\nexport type Child = Node | string | null | undefined | false;\n\n/** The value of an attribute of `h`. The value `true` gives an empty attribute. */\nexport type AttributeValue = string | number | boolean | null | undefined;\n\n/**\n * This function makes an element with attributes and children. An attribute with the value\n * `false`, `null` or `undefined` is not set. The attribute `class` sets the class name.\n */\nexport function h<K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attrs: Readonly<Record<string, AttributeValue>> = {},\n ...children: readonly (Child | readonly Child[])[]\n): HTMLElementTagNameMap[K] {\n const el = document.createElement(tag);\n for (const [name, value] of Object.entries(attrs)) {\n if (value === false || value === null || value === undefined) continue;\n if (name === \"class\") el.className = String(value);\n else el.setAttribute(name, value === true ? \"\" : String(value));\n }\n for (const child of children.flat()) {\n if (child === null || child === undefined || child === false) continue;\n el.append(child);\n }\n return el;\n}\n\n/**\n * This function gives the element with the ID. The page has each ID that the code asks for. Thus\n * a missing ID is an error of the page, and the function throws an `Error`.\n */\nexport function byId<T extends HTMLElement = HTMLElement>(id: string): T {\n const el = document.getElementById(id);\n if (el === null) throw new Error(`The page has no element \"${id}\".`);\n return el as T;\n}\n\n/** The themes of the theme button, in the sequence of the clicks. `auto` follows the setting of the system. */\nexport const THEMES: readonly [\"auto\", \"light\", \"dark\"] = [\"auto\", \"light\", \"dark\"];\n\n/** A theme of the page. */\nexport type Theme = (typeof THEMES)[number];\n\n/**\n * This function gives the theme of the page from the attribute `data-theme` of the `html` element.\n * Without the attribute, or with another value, the theme is `auto`.\n */\nexport function currentTheme(): Theme {\n const theme = document.documentElement.dataset[\"theme\"];\n return theme === \"light\" || theme === \"dark\" ? theme : \"auto\";\n}\n\n/**\n * This function sets the theme of the page, and keeps it in `localStorage` under `storageKey`.\n * The theme `auto` removes the attribute `data-theme` and the stored value.\n */\nexport function applyTheme(theme: Theme, storageKey: string): void {\n const root = document.documentElement;\n if (theme === \"auto\") delete root.dataset[\"theme\"];\n else root.dataset[\"theme\"] = theme;\n try {\n if (theme === \"auto\") localStorage.removeItem(storageKey);\n else localStorage.setItem(storageKey, theme);\n } catch {\n // A browser with no storage keeps the theme until the page closes.\n }\n}\n\n/** This function sets the next theme after the current theme (auto, light, dark, auto), and gives it. */\nexport function nextTheme(storageKey: string): Theme {\n const next = THEMES[(THEMES.indexOf(currentTheme()) + 1) % THEMES.length] ?? \"auto\";\n applyTheme(next, storageKey);\n return next;\n}\n\n/**\n * This function makes a theme button. Each click sets the next theme. The text of the button is\n * \"Theme: auto\", \"Theme: light\" or \"Theme: dark\", and its `aria-label` tells the same theme.\n *\n * @remarks Before the first paint, a script in the `head` of the page reads `storageKey` from\n * `localStorage` and sets `data-theme`. Thus a dark page does not show white for a moment. The\n * plugin `siteShell` of the entry `./vite` adds that script.\n */\nexport function setupTheme(button: HTMLButtonElement, storageKey: string): void {\n const show = (theme: Theme): void => {\n button.textContent = `Theme: ${theme}`;\n button.setAttribute(\"aria-label\", `Color theme: ${theme}. Select to change.`);\n };\n show(currentTheme());\n button.addEventListener(\"click\", () => show(nextTheme(storageKey)));\n}\n\n/** The data of a build: `siteShell` writes it, and `showBuild` shows it. */\nexport interface BuildInfo {\n /** The first 7 characters of the commit, or `local` for a build outside CI. */\n readonly sha: string;\n /** The date of the build, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The version of the package. A site without a version does not set it. */\n readonly version?: string | undefined;\n}\n\n/**\n * This function shows the version and the build of the site in an element. The text is \"Version\n * 1.2.3, build abc1234 of 2026-11-03\", and the commit is a link to GitHub. A build with no version\n * starts with \"Build\", and a local build has no link.\n *\n * @param repository - The repository as \"owner/name\".\n */\nexport function showBuild(element: HTMLElement, build: BuildInfo, repository: string): void {\n const commit = build.sha === \"local\" ? \"local\" : h(\"a\", { href: `https://github.com/${repository}/commit/${build.sha}` }, build.sha);\n element.append(build.version === undefined ? \"Build \" : `Version ${build.version}, build `, commit, ` of ${build.date}`);\n}\n\n/**\n * This function copies a text to the clipboard, and gives `true` when the copy is done. It uses\n * the Clipboard API. When that API is not available or refuses, it uses `document.execCommand`.\n */\nexport async function copyToClipboard(text: string): Promise<boolean> {\n try {\n await navigator.clipboard.writeText(text);\n return true;\n } catch {\n // An insecure page has no Clipboard API, and a browser can refuse the copy. The old command is the fallback.\n }\n try {\n const area = document.createElement(\"textarea\");\n area.value = text;\n area.setAttribute(\"readonly\", \"\");\n area.style.position = \"fixed\";\n area.style.opacity = \"0\";\n document.body.append(area);\n area.select();\n try {\n return document.execCommand(\"copy\");\n } finally {\n area.remove();\n }\n } catch {\n return false;\n }\n}\n\n/** The options of `copyText`. */\nexport interface CopyTextOptions {\n /** The text of the button after a copy. The default is \"Copied\". */\n readonly copied?: string;\n /** The text of the button after a failure. The default is \"Copy failed\". */\n readonly failed?: string;\n /** The time in milliseconds until the button shows its label again. The default is 1600. */\n readonly ms?: number;\n}\n\n/**\n * This function copies a text to the clipboard with `copyToClipboard`. The button tells the result\n * for a short time, then it shows its label again. The function gives the result of the copy.\n */\nexport async function copyText(button: HTMLButtonElement, text: string, options: CopyTextOptions = {}): Promise<boolean> {\n const label = button.textContent;\n const ok = await copyToClipboard(text);\n button.textContent = ok ? (options.copied ?? \"Copied\") : (options.failed ?? \"Copy failed\");\n window.setTimeout(() => {\n button.textContent = label;\n }, options.ms ?? 1600);\n return ok;\n}\n\n/** The arrow keys of a group: `horizontal` (Left and Right), `vertical` (Up and Down) or `both`. */\n/** The arrow keys of a group: left and right, up and down, or the four arrows. */\nexport type RovingAxis = \"horizontal\" | \"vertical\" | \"both\";\n\nconst ROVING_STEPS: Readonly<Record<RovingAxis, Readonly<Record<string, number>>>> = {\n horizontal: { ArrowRight: 1, ArrowLeft: -1 },\n vertical: { ArrowDown: 1, ArrowUp: -1 },\n both: { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 },\n};\n\n/**\n * This function gives the index of the next item after an arrow key, in a group of `count` items. The index\n * wraps at each end. A key that is not an arrow of the axis gives `undefined`, and so does an empty group. An\n * index outside the group goes to the first item on a step forward, and to the last item on a step back.\n */\nexport function rovingIndex(key: string, index: number, count: number, axis: RovingAxis = \"both\"): number | undefined {\n const step = ROVING_STEPS[axis][key];\n if (step === undefined || count <= 0) return undefined;\n if (!Number.isInteger(index) || index < 0 || index >= count) return step > 0 ? 0 : count - 1;\n return (index + step + count) % count;\n}\n\n/** A choice of a `Segmented` control. */\nexport interface Choice<T extends string> {\n /** The value of the choice. */\n readonly value: T;\n /** The text of the button. */\n readonly label: string;\n /** The tooltip and the accessible name of the button. Without it, the button has neither. */\n readonly title?: string;\n}\n\n/**\n * A group of radio buttons with one focus stop. The selected button has `tabIndex` 0, and the others have -1.\n * The arrow keys select the next button, with a wrap at each end, and move the focus to it. The container keeps\n * its own role and label, for example `role=\"radiogroup\"` in the HTML.\n */\nexport class Segmented<T extends string> {\n private readonly buttons: readonly HTMLButtonElement[];\n private readonly choices: readonly Choice<T>[];\n private readonly onChange: (value: T) => void;\n private current: T;\n\n /**\n * This constructor puts one button for each choice into the container, in place of its children. The listener\n * gets each change by a click or a key, and no event for the choice that is already selected.\n */\n constructor(container: HTMLElement, choices: readonly Choice<T>[], current: T, onChange: (value: T) => void, axis: RovingAxis = \"both\") {\n this.choices = choices;\n this.current = current;\n this.onChange = onChange;\n this.buttons = choices.map((choice) => {\n const button = h(\n \"button\",\n { type: \"button\", role: \"radio\", \"data-value\": choice.value, title: choice.title, \"aria-label\": choice.title },\n choice.label,\n );\n button.addEventListener(\"click\", () => this.choose(choice.value, false));\n return button;\n });\n container.replaceChildren(...this.buttons);\n container.addEventListener(\"keydown\", (event) => {\n const index = this.choices.findIndex((c) => c.value === this.current);\n const next = rovingIndex(event.key, index, this.choices.length, axis);\n if (next === undefined) return;\n event.preventDefault();\n this.choose(this.choices[next]!.value, true);\n });\n this.show();\n }\n\n /** The value of the control. */\n get value(): T {\n return this.current;\n }\n\n /** This function sets the value. The listener gets no event. */\n set(value: T): void {\n this.current = value;\n this.show();\n }\n\n private choose(value: T, focus: boolean): void {\n const changed = value !== this.current;\n this.set(value);\n if (focus) this.buttons[this.choices.findIndex((c) => c.value === value)]?.focus();\n if (changed) this.onChange(value);\n }\n\n private show(): void {\n this.choices.forEach((choice, i) => {\n const button = this.buttons[i]!;\n const on = choice.value === this.current;\n button.setAttribute(\"aria-checked\", String(on));\n button.tabIndex = on ? 0 : -1;\n });\n }\n}\n"],"mappings":";;;;;AAkBA,SAAgB,EACd,KACA,QAAkD,CAAC,GACnD,GAAG,UACuB;CAC1B,MAAM,KAAK,SAAS,cAAc,GAAG;CACrC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,GAAG;EACjD,IAAI,UAAU,SAAS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,KAAK,SAAS,KAAK;CAClC;CAEQ,OAAa;EACnB,KAAK,QAAQ,SAAS,QAAQ,MAAM;GAClC,MAAM,SAAS,KAAK,QAAQ;GAC5B,MAAM,KAAK,OAAO,UAAU,KAAK;GACjC,OAAO,aAAa,gBAAgB,OAAO,EAAE,CAAC;GAC9C,OAAO,WAAW,KAAK,IAAI;EAC7B,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"chrome.js","names":[],"sources":["../src/chrome.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * The small helpers of a page in the browser: the element helpers, the element lookup, the theme\n * button, the copy button and the build stamp. It also has a radio group with one focus stop.\n * This module imports no Node.js module, so a site can bundle it. Import it from\n * `@mark1russell7/site-pages/chrome`, because the package root also has Node.js code.\n */\n\n/** A child of `h`: a node or a text. The values `null`, `undefined` and `false` give no child. */\nexport type Child = Node | string | null | undefined | false;\n\n/** The value of an attribute of `h`. The value `true` gives an empty attribute. */\nexport type AttributeValue = string | number | boolean | null | undefined;\n\n/**\n * This function makes an element with attributes and children. An attribute with the value\n * `false`, `null` or `undefined` is not set. The attribute `class` sets the class name.\n */\nexport function h<K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attrs: Readonly<Record<string, AttributeValue>> = {},\n ...children: readonly (Child | readonly Child[])[]\n): HTMLElementTagNameMap[K] {\n const el = document.createElement(tag);\n return fill(el, attrs, children, (value) => {\n el.className = value;\n });\n}\n\n/** The namespace of the SVG elements. */\nconst SVG_NS = \"http://www.w3.org/2000/svg\";\n\n/**\n * This function makes an SVG element with attributes and children, with the rules of `h`. The\n * attribute `class` sets the attribute `class`, because the class name of an SVG element is\n * read-only.\n */\nexport function svg<K extends keyof SVGElementTagNameMap>(\n tag: K,\n attrs: Readonly<Record<string, AttributeValue>> = {},\n ...children: readonly (Child | readonly Child[])[]\n): SVGElementTagNameMap[K] {\n const el = document.createElementNS(SVG_NS, tag);\n return fill(el, attrs, children, (value) => {\n el.setAttribute(\"class\", value);\n });\n}\n\n/** This function sets the attributes and adds the children of an element of `h` or `svg`. */\nfunction fill<E extends Element>(\n el: E,\n attrs: Readonly<Record<string, AttributeValue>>,\n children: readonly (Child | readonly Child[])[],\n setClass: (value: string) => void,\n): E {\n for (const [name, value] of Object.entries(attrs)) {\n if (value === false || value === null || value === undefined) continue;\n if (name === \"class\") setClass(String(value));\n else el.setAttribute(name, value === true ? \"\" : String(value));\n }\n for (const child of children.flat()) {\n if (child === null || child === undefined || child === false) continue;\n el.append(child);\n }\n return el;\n}\n\n/**\n * This function gives the element with the ID. The page has each ID that the code asks for. Thus\n * a missing ID is an error of the page, and the function throws an `Error`.\n */\nexport function byId<T extends HTMLElement = HTMLElement>(id: string): T {\n const el = document.getElementById(id);\n if (el === null) throw new Error(`The page has no element \"${id}\".`);\n return el as T;\n}\n\n/** The themes of the theme button, in the sequence of the clicks. `auto` follows the setting of the system. */\nexport const THEMES: readonly [\"auto\", \"light\", \"dark\"] = [\"auto\", \"light\", \"dark\"];\n\n/** A theme of the page. */\nexport type Theme = (typeof THEMES)[number];\n\n/**\n * This function gives the theme of the page from the attribute `data-theme` of the `html` element.\n * Without the attribute, or with another value, the theme is `auto`.\n */\nexport function currentTheme(): Theme {\n const theme = document.documentElement.dataset[\"theme\"];\n return theme === \"light\" || theme === \"dark\" ? theme : \"auto\";\n}\n\n/**\n * This function sets the theme of the page, and keeps it in `localStorage` under `storageKey`.\n * The theme `auto` removes the attribute `data-theme` and the stored value.\n */\nexport function applyTheme(theme: Theme, storageKey: string): void {\n const root = document.documentElement;\n if (theme === \"auto\") delete root.dataset[\"theme\"];\n else root.dataset[\"theme\"] = theme;\n try {\n if (theme === \"auto\") localStorage.removeItem(storageKey);\n else localStorage.setItem(storageKey, theme);\n } catch {\n // A browser with no storage keeps the theme until the page closes.\n }\n}\n\n/** This function sets the next theme after the current theme (auto, light, dark, auto), and gives it. */\nexport function nextTheme(storageKey: string): Theme {\n const next = THEMES[(THEMES.indexOf(currentTheme()) + 1) % THEMES.length] ?? \"auto\";\n applyTheme(next, storageKey);\n return next;\n}\n\n/**\n * This function makes a theme button. Each click sets the next theme. The text of the button is\n * \"Theme: auto\", \"Theme: light\" or \"Theme: dark\", and its `aria-label` tells the same theme.\n *\n * @remarks Before the first paint, a script in the `head` of the page reads `storageKey` from\n * `localStorage` and sets `data-theme`. Thus a dark page does not show white for a moment. The\n * plugin `siteShell` of the entry `./vite` adds that script.\n */\nexport function setupTheme(button: HTMLButtonElement, storageKey: string): void {\n const show = (theme: Theme): void => {\n button.textContent = `Theme: ${theme}`;\n button.setAttribute(\"aria-label\", `Color theme: ${theme}. Select to change.`);\n };\n show(currentTheme());\n button.addEventListener(\"click\", () => show(nextTheme(storageKey)));\n}\n\n/** The data of a build: `siteShell` writes it, and `showBuild` shows it. */\nexport interface BuildInfo {\n /** The first 7 characters of the commit, or `local` for a build outside CI. */\n readonly sha: string;\n /** The date of the build, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The version of the package. A site without a version does not set it. */\n readonly version?: string | undefined;\n}\n\n/**\n * This function shows the version and the build of the site in an element. The text is \"Version\n * 1.2.3, build abc1234 of 2026-11-03\", and the commit is a link to GitHub. A build with no version\n * starts with \"Build\", and a local build has no link.\n *\n * @param repository - The repository as \"owner/name\".\n */\nexport function showBuild(element: HTMLElement, build: BuildInfo, repository: string): void {\n const commit = build.sha === \"local\" ? \"local\" : h(\"a\", { href: `https://github.com/${repository}/commit/${build.sha}` }, build.sha);\n element.append(build.version === undefined ? \"Build \" : `Version ${build.version}, build `, commit, ` of ${build.date}`);\n}\n\n/**\n * This function copies a text to the clipboard, and gives `true` when the copy is done. It uses\n * the Clipboard API. When that API is not available or refuses, it uses `document.execCommand`.\n */\nexport async function copyToClipboard(text: string): Promise<boolean> {\n try {\n await navigator.clipboard.writeText(text);\n return true;\n } catch {\n // An insecure page has no Clipboard API, and a browser can refuse the copy. The old command is the fallback.\n }\n try {\n const area = document.createElement(\"textarea\");\n area.value = text;\n area.setAttribute(\"readonly\", \"\");\n area.style.position = \"fixed\";\n area.style.opacity = \"0\";\n document.body.append(area);\n area.select();\n try {\n return document.execCommand(\"copy\");\n } finally {\n area.remove();\n }\n } catch {\n return false;\n }\n}\n\n/** The options of `copyText`. */\nexport interface CopyTextOptions {\n /** The text of the button after a copy. The default is \"Copied\". */\n readonly copied?: string;\n /** The text of the button after a failure. The default is \"Copy failed\". */\n readonly failed?: string;\n /** The time in milliseconds until the button shows its label again. The default is 1600. */\n readonly ms?: number;\n}\n\n/**\n * This function copies a text to the clipboard with `copyToClipboard`. The button tells the result\n * for a short time, then it shows its label again. The function gives the result of the copy.\n */\nexport async function copyText(button: HTMLButtonElement, text: string, options: CopyTextOptions = {}): Promise<boolean> {\n const label = button.textContent;\n const ok = await copyToClipboard(text);\n button.textContent = ok ? (options.copied ?? \"Copied\") : (options.failed ?? \"Copy failed\");\n window.setTimeout(() => {\n button.textContent = label;\n }, options.ms ?? 1600);\n return ok;\n}\n\n/** The arrow keys of a group: `horizontal` (Left and Right), `vertical` (Up and Down) or `both`. */\n/** The arrow keys of a group: left and right, up and down, or the four arrows. */\nexport type RovingAxis = \"horizontal\" | \"vertical\" | \"both\";\n\nconst ROVING_STEPS: Readonly<Record<RovingAxis, Readonly<Record<string, number>>>> = {\n horizontal: { ArrowRight: 1, ArrowLeft: -1 },\n vertical: { ArrowDown: 1, ArrowUp: -1 },\n both: { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 },\n};\n\n/**\n * This function gives the index of the next item after an arrow key, in a group of `count` items. The index\n * wraps at each end. A key that is not an arrow of the axis gives `undefined`, and so does an empty group. An\n * index outside the group goes to the first item on a step forward, and to the last item on a step back.\n */\nexport function rovingIndex(key: string, index: number, count: number, axis: RovingAxis = \"both\"): number | undefined {\n const step = ROVING_STEPS[axis][key];\n if (step === undefined || count <= 0) return undefined;\n if (!Number.isInteger(index) || index < 0 || index >= count) return step > 0 ? 0 : count - 1;\n return (index + step + count) % count;\n}\n\n/** A choice of a `Segmented` control. */\nexport interface Choice<T extends string> {\n /** The value of the choice. */\n readonly value: T;\n /** The text of the button. */\n readonly label: string;\n /** The tooltip and the accessible name of the button. Without it, the button has neither. */\n readonly title?: string;\n}\n\n/**\n * A group of radio buttons with one focus stop. The selected button has `tabIndex` 0, and the others have -1.\n * The arrow keys select the next button, with a wrap at each end, and move the focus to it. The container keeps\n * its own role and label, for example `role=\"radiogroup\"` in the HTML.\n */\nexport class Segmented<T extends string> {\n private readonly buttons: readonly HTMLButtonElement[];\n private readonly choices: readonly Choice<T>[];\n private readonly onChange: (value: T) => void;\n private current: T;\n\n /**\n * This constructor puts one button for each choice into the container, in place of its children. The listener\n * gets each change by a click or a key, and no event for the choice that is already selected.\n */\n constructor(container: HTMLElement, choices: readonly Choice<T>[], current: T, onChange: (value: T) => void, axis: RovingAxis = \"both\") {\n this.choices = choices;\n this.current = current;\n this.onChange = onChange;\n this.buttons = choices.map((choice) => {\n const button = h(\n \"button\",\n { type: \"button\", role: \"radio\", \"data-value\": choice.value, title: choice.title, \"aria-label\": choice.title },\n choice.label,\n );\n button.addEventListener(\"click\", () => this.choose(choice.value, false));\n return button;\n });\n container.replaceChildren(...this.buttons);\n container.addEventListener(\"keydown\", (event) => {\n const index = this.choices.findIndex((c) => c.value === this.current);\n const next = rovingIndex(event.key, index, this.choices.length, axis);\n if (next === undefined) return;\n event.preventDefault();\n this.choose(this.choices[next]!.value, true);\n });\n this.show();\n }\n\n /** The value of the control. */\n get value(): T {\n return this.current;\n }\n\n /** This function sets the value. The listener gets no event. */\n set(value: T): void {\n this.current = value;\n this.show();\n }\n\n private choose(value: T, focus: boolean): void {\n const changed = value !== this.current;\n this.set(value);\n if (focus) this.buttons[this.choices.findIndex((c) => c.value === value)]?.focus();\n if (changed) this.onChange(value);\n }\n\n private show(): void {\n this.choices.forEach((choice, i) => {\n const button = this.buttons[i]!;\n const on = choice.value === this.current;\n button.setAttribute(\"aria-checked\", String(on));\n button.tabIndex = on ? 0 : -1;\n });\n }\n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AAE,UAAU,KAAK,OAAO;GACpE,MAAM,OAAO,YAAY,MAAM,KAAK,OAAO,KAAK,QAAQ,QAAQ,IAAI;GACpE,IAAI,SAAS,KAAA,GAAW;GACxB,MAAM,eAAe;GACrB,KAAK,OAAO,KAAK,QAAQ,KAAK,CAAE,OAAO,IAAI;EAC7C,CAAC;EACD,KAAK,KAAK;CACZ;;CAGA,IAAI,QAAW;EACb,OAAO,KAAK;CACd;;CAGA,IAAI,OAAgB;EAClB,KAAK,UAAU;EACf,KAAK,KAAK;CACZ;CAEQ,OAAO,OAAU,OAAsB;EAC7C,MAAM,UAAU,UAAU,KAAK;EAC/B,KAAK,IAAI,KAAK;EACd,IAAI,OAAO,KAAK,QAAQ,KAAK,QAAQ,WAAW,MAAM,EAAE,UAAU,KAAK,EAAE,EAAE,MAAM;EACjF,IAAI,SAAS,KAAK,SAAS,KAAK;CAClC;CAEQ,OAAa;EACnB,KAAK,QAAQ,SAAS,QAAQ,MAAM;GAClC,MAAM,SAAS,KAAK,QAAQ;GAC5B,MAAM,KAAK,OAAO,UAAU,KAAK;GACjC,OAAO,aAAa,gBAAgB,OAAO,EAAE,CAAC;GAC9C,OAAO,WAAW,KAAK,IAAI;EAC7B,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site config of a repository: the one home of the inputs of its site build (CI.md, "The site config").
|
|
3
|
+
*
|
|
4
|
+
* The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and
|
|
5
|
+
* `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two
|
|
6
|
+
* workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.
|
|
7
|
+
*
|
|
8
|
+
* A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old
|
|
9
|
+
* caller keeps its site. A repository that has the file and also gives a site input gets an error.
|
|
10
|
+
*
|
|
11
|
+
* In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,
|
|
12
|
+
* so the workflow starts it from the template commit with no install.
|
|
13
|
+
*/
|
|
14
|
+
/** The path of the site config in a repository. */
|
|
15
|
+
export declare const SITE_CONFIG_PATH = ".github/site.json";
|
|
16
|
+
/** The type of a key: a string, a boolean or a map of environment variables. */
|
|
17
|
+
export type SiteConfigKind = "string" | "boolean" | "env";
|
|
18
|
+
/** The site config: a value for each key. CI.md tells each key. */
|
|
19
|
+
export interface SiteConfig {
|
|
20
|
+
/** The command that builds the site. It is the one necessary key, with `out`. */
|
|
21
|
+
readonly build: string;
|
|
22
|
+
/** The folder of the built site. */
|
|
23
|
+
readonly out: string;
|
|
24
|
+
/** The environment variables of the build. `{owner}` and `{repo}` change in each value. */
|
|
25
|
+
readonly env: Readonly<Record<string, string>>;
|
|
26
|
+
/** `true` gives the build the token of the job as `GITHUB_TOKEN`. */
|
|
27
|
+
readonly "github-token": boolean;
|
|
28
|
+
/** The Node.js version of the build. */
|
|
29
|
+
readonly "node-version": string;
|
|
30
|
+
/** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */
|
|
31
|
+
readonly "node-version-file": string;
|
|
32
|
+
/** `true` adds the Releases page and the Status page. */
|
|
33
|
+
readonly "site-pages": boolean;
|
|
34
|
+
/** The npm version of site-pages for its pages. Empty uses the template commit. */
|
|
35
|
+
readonly "site-pages-version": string;
|
|
36
|
+
/** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */
|
|
37
|
+
readonly roadmap: string;
|
|
38
|
+
/** The base path of the site, for example `/{repo}/`. */
|
|
39
|
+
readonly base: string;
|
|
40
|
+
/** The npm packages of the Releases page, with commas between them. */
|
|
41
|
+
readonly packages: string;
|
|
42
|
+
/** The folder of the changesets of the Status page. */
|
|
43
|
+
readonly changesets: string;
|
|
44
|
+
/** The group of the pages of the site. */
|
|
45
|
+
readonly group: string;
|
|
46
|
+
/** A style file of the site for the pages of site-pages. */
|
|
47
|
+
readonly css: string;
|
|
48
|
+
/** The name of the site in the bar and in the titles. */
|
|
49
|
+
readonly "site-name": string;
|
|
50
|
+
/** `true` writes only the data files of the pages, with no HTML. */
|
|
51
|
+
readonly "data-only": boolean;
|
|
52
|
+
/** A file of data stamps, for the freshness gate. */
|
|
53
|
+
readonly "data-stamps": string;
|
|
54
|
+
/** `true` checks the pages in a browser at each width. */
|
|
55
|
+
readonly "site-check": boolean;
|
|
56
|
+
/** The pages of the site check, with commas between them. */
|
|
57
|
+
readonly "site-check-pages": string;
|
|
58
|
+
/** The widths of the site check, with commas between them. */
|
|
59
|
+
readonly "site-check-widths": string;
|
|
60
|
+
/** A probe script of the site check. */
|
|
61
|
+
readonly "site-check-probe": string;
|
|
62
|
+
/** The Playwright version of the site check. */
|
|
63
|
+
readonly "site-check-playwright": string;
|
|
64
|
+
/** `true` gives each page the bar of the site. */
|
|
65
|
+
readonly "site-bar": boolean;
|
|
66
|
+
/** The pages of the bar, with commas between them. */
|
|
67
|
+
readonly "site-bar-pages": string;
|
|
68
|
+
/** The npm name of the package of the site, for the npm link of the bar. */
|
|
69
|
+
readonly "site-bar-npm": string;
|
|
70
|
+
/** `true` gives each code block the scroll cue. */
|
|
71
|
+
readonly "scroll-cue": boolean;
|
|
72
|
+
/** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */
|
|
73
|
+
readonly "indexnow-key": string;
|
|
74
|
+
}
|
|
75
|
+
/** A key of the site config. */
|
|
76
|
+
export type SiteConfigKey = keyof SiteConfig;
|
|
77
|
+
/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */
|
|
78
|
+
export interface SiteConfigKeySpec<T> {
|
|
79
|
+
readonly kind: SiteConfigKind;
|
|
80
|
+
readonly default: T;
|
|
81
|
+
}
|
|
82
|
+
/** The keys of the site config, with their types and their defaults. */
|
|
83
|
+
export declare const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]>; };
|
|
84
|
+
/** The input of {@link resolveSiteConfig}. */
|
|
85
|
+
export interface SiteConfigInput {
|
|
86
|
+
/** The text of .github/site.json, or undefined when the repository has no such file. */
|
|
87
|
+
readonly file: string | undefined;
|
|
88
|
+
/** The path of the file, for the messages. */
|
|
89
|
+
readonly path: string;
|
|
90
|
+
/** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */
|
|
91
|
+
readonly inputs: Readonly<Record<string, unknown>> | undefined;
|
|
92
|
+
/** The repository, "owner/name". */
|
|
93
|
+
readonly repository: string;
|
|
94
|
+
}
|
|
95
|
+
/** The site config and its source, or an error. */
|
|
96
|
+
export type SiteConfigResult = {
|
|
97
|
+
readonly config: SiteConfig;
|
|
98
|
+
readonly source: "file" | "inputs";
|
|
99
|
+
} | {
|
|
100
|
+
readonly error: string;
|
|
101
|
+
};
|
|
102
|
+
/** This function puts the owner and the name of the repository in for {owner} and {repo}. */
|
|
103
|
+
export declare function fillRepository(value: string, repository: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.
|
|
106
|
+
* The input `env` of `reusable-pages.yml` is a JSON string, and `"{}"` or an empty string is its default.
|
|
107
|
+
*/
|
|
108
|
+
export declare function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[];
|
|
109
|
+
/**
|
|
110
|
+
* This function gives the site config of a repository from its file, or from the old inputs when it has no file. The
|
|
111
|
+
* workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.
|
|
112
|
+
*/
|
|
113
|
+
export declare function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult;
|
|
114
|
+
//# sourceMappingURL=site-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.d.ts","names":[],"sources":["../../src/config/site-config.ts"],"mappings":";;;;;;;;;;;;;;qBAea;;YAGD;;iBAGK;;WAEN;;WAEA;;WAEA,KAAK,SAAS;;WAEd;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;YAIC,sBAAsB;;iBAGjB,kBAAkB;WACxB,MAAM;WACN,SAAS;;;qBAIP,8BAA8B,KAAK,gBAAgB,kBAAkB,WAAW;;iBA+B5E;;WAEN;;WAEA;;WAEA,QAAQ,SAAS;;WAEjB;;;YAIC;WAA8B,QAAQ;WAAqB;;WAAyC;;;wBAKhG,eAAe,eAAe;;;;;wBA4B9B,YAAY,QAAQ,SAAS,2BAA2B;;;;;wBAaxD,kBAAkB,OAAO,kBAAkB"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// src/config/site-config.ts
|
|
2
|
+
/**
|
|
3
|
+
* The site config of a repository: the one home of the inputs of its site build (CI.md, "The site config").
|
|
4
|
+
*
|
|
5
|
+
* The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and
|
|
6
|
+
* `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two
|
|
7
|
+
* workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.
|
|
8
|
+
*
|
|
9
|
+
* A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old
|
|
10
|
+
* caller keeps its site. A repository that has the file and also gives a site input gets an error.
|
|
11
|
+
*
|
|
12
|
+
* In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,
|
|
13
|
+
* so the workflow starts it from the template commit with no install.
|
|
14
|
+
*/
|
|
15
|
+
/** The path of the site config in a repository. */
|
|
16
|
+
const SITE_CONFIG_PATH = ".github/site.json";
|
|
17
|
+
/** The keys of the site config, with their types and their defaults. */
|
|
18
|
+
const SITE_CONFIG_KEYS = {
|
|
19
|
+
build: {
|
|
20
|
+
kind: "string",
|
|
21
|
+
default: ""
|
|
22
|
+
},
|
|
23
|
+
out: {
|
|
24
|
+
kind: "string",
|
|
25
|
+
default: ""
|
|
26
|
+
},
|
|
27
|
+
env: {
|
|
28
|
+
kind: "env",
|
|
29
|
+
default: {}
|
|
30
|
+
},
|
|
31
|
+
"github-token": {
|
|
32
|
+
kind: "boolean",
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
"node-version": {
|
|
36
|
+
kind: "string",
|
|
37
|
+
default: "26"
|
|
38
|
+
},
|
|
39
|
+
"node-version-file": {
|
|
40
|
+
kind: "string",
|
|
41
|
+
default: ""
|
|
42
|
+
},
|
|
43
|
+
"site-pages": {
|
|
44
|
+
kind: "boolean",
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
"site-pages-version": {
|
|
48
|
+
kind: "string",
|
|
49
|
+
default: ""
|
|
50
|
+
},
|
|
51
|
+
roadmap: {
|
|
52
|
+
kind: "string",
|
|
53
|
+
default: ""
|
|
54
|
+
},
|
|
55
|
+
base: {
|
|
56
|
+
kind: "string",
|
|
57
|
+
default: ""
|
|
58
|
+
},
|
|
59
|
+
packages: {
|
|
60
|
+
kind: "string",
|
|
61
|
+
default: ""
|
|
62
|
+
},
|
|
63
|
+
changesets: {
|
|
64
|
+
kind: "string",
|
|
65
|
+
default: ""
|
|
66
|
+
},
|
|
67
|
+
group: {
|
|
68
|
+
kind: "string",
|
|
69
|
+
default: ""
|
|
70
|
+
},
|
|
71
|
+
css: {
|
|
72
|
+
kind: "string",
|
|
73
|
+
default: ""
|
|
74
|
+
},
|
|
75
|
+
"site-name": {
|
|
76
|
+
kind: "string",
|
|
77
|
+
default: ""
|
|
78
|
+
},
|
|
79
|
+
"data-only": {
|
|
80
|
+
kind: "boolean",
|
|
81
|
+
default: false
|
|
82
|
+
},
|
|
83
|
+
"data-stamps": {
|
|
84
|
+
kind: "string",
|
|
85
|
+
default: ""
|
|
86
|
+
},
|
|
87
|
+
"site-check": {
|
|
88
|
+
kind: "boolean",
|
|
89
|
+
default: false
|
|
90
|
+
},
|
|
91
|
+
"site-check-pages": {
|
|
92
|
+
kind: "string",
|
|
93
|
+
default: ""
|
|
94
|
+
},
|
|
95
|
+
"site-check-widths": {
|
|
96
|
+
kind: "string",
|
|
97
|
+
default: ""
|
|
98
|
+
},
|
|
99
|
+
"site-check-probe": {
|
|
100
|
+
kind: "string",
|
|
101
|
+
default: ""
|
|
102
|
+
},
|
|
103
|
+
"site-check-playwright": {
|
|
104
|
+
kind: "string",
|
|
105
|
+
default: "1.64.1"
|
|
106
|
+
},
|
|
107
|
+
"site-bar": {
|
|
108
|
+
kind: "boolean",
|
|
109
|
+
default: false
|
|
110
|
+
},
|
|
111
|
+
"site-bar-pages": {
|
|
112
|
+
kind: "string",
|
|
113
|
+
default: ""
|
|
114
|
+
},
|
|
115
|
+
"site-bar-npm": {
|
|
116
|
+
kind: "string",
|
|
117
|
+
default: ""
|
|
118
|
+
},
|
|
119
|
+
"scroll-cue": {
|
|
120
|
+
kind: "boolean",
|
|
121
|
+
default: true
|
|
122
|
+
},
|
|
123
|
+
"indexnow-key": {
|
|
124
|
+
kind: "string",
|
|
125
|
+
default: ""
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
129
|
+
/** This function puts the owner and the name of the repository in for {owner} and {repo}. */
|
|
130
|
+
function fillRepository(value, repository) {
|
|
131
|
+
const [owner = "", repo = ""] = repository.split("/");
|
|
132
|
+
return value.replaceAll("{owner}", owner).replaceAll("{repo}", repo);
|
|
133
|
+
}
|
|
134
|
+
/** This function checks one value against the type of its key, and gives the value or an error. */
|
|
135
|
+
function check(key, value, where, repository) {
|
|
136
|
+
const kind = SITE_CONFIG_KEYS[key].kind;
|
|
137
|
+
if (kind === "boolean") return typeof value === "boolean" ? { value } : { error: `${where}: "${key}" must be true or false.` };
|
|
138
|
+
if (kind === "string") return typeof value === "string" ? { value: fillRepository(value, repository) } : { error: `${where}: "${key}" must be a string.` };
|
|
139
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return { error: `${where}: "env" must be an object of strings.` };
|
|
140
|
+
const env = {};
|
|
141
|
+
for (const [name, text] of Object.entries(value)) {
|
|
142
|
+
if (!NAME.test(name)) return { error: `${where}: "${name}" of "env" is not a name of an environment variable.` };
|
|
143
|
+
if (typeof text !== "string") return { error: `${where}: the value of "${name}" of "env" must be a string.` };
|
|
144
|
+
env[name] = fillRepository(text, repository);
|
|
145
|
+
}
|
|
146
|
+
return { value: env };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.
|
|
150
|
+
* The input `env` of `reusable-pages.yml` is a JSON string, and `"{}"` or an empty string is its default.
|
|
151
|
+
*/
|
|
152
|
+
function inputsGiven(inputs) {
|
|
153
|
+
return Object.keys(SITE_CONFIG_KEYS).filter((key) => {
|
|
154
|
+
const value = inputs[key];
|
|
155
|
+
if (value === void 0) return false;
|
|
156
|
+
if (key === "env") return !(value === "" || typeof value === "string" && value.replace(/\s/g, "") === "{}");
|
|
157
|
+
return value !== SITE_CONFIG_KEYS[key].default;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* This function gives the site config of a repository from its file, or from the old inputs when it has no file. The
|
|
162
|
+
* workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.
|
|
163
|
+
*/
|
|
164
|
+
function resolveSiteConfig(input) {
|
|
165
|
+
const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default]));
|
|
166
|
+
let source;
|
|
167
|
+
if (input.file !== void 0) {
|
|
168
|
+
const given = input.inputs === void 0 ? [] : inputsGiven(input.inputs);
|
|
169
|
+
if (given.length > 0) return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(", ")}. Give the site values only in ${input.path}.` };
|
|
170
|
+
let data;
|
|
171
|
+
try {
|
|
172
|
+
data = JSON.parse(input.file);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return { error: `${input.path} is not JSON: ${error.message}` };
|
|
175
|
+
}
|
|
176
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };
|
|
177
|
+
for (const [key, value] of Object.entries(data)) {
|
|
178
|
+
if (key === "$schema" || key === "$comment") continue;
|
|
179
|
+
if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: "${key}" is not a key of the site config. CI.md tells the keys.` };
|
|
180
|
+
const checked = check(key, value, input.path, input.repository);
|
|
181
|
+
if ("error" in checked) return checked;
|
|
182
|
+
config[key] = checked.value;
|
|
183
|
+
}
|
|
184
|
+
source = "file";
|
|
185
|
+
} else if (input.inputs !== void 0) {
|
|
186
|
+
for (const key of Object.keys(SITE_CONFIG_KEYS)) {
|
|
187
|
+
let value = input.inputs[key];
|
|
188
|
+
if (value === void 0) continue;
|
|
189
|
+
if (key === "env") {
|
|
190
|
+
if (value === "") continue;
|
|
191
|
+
try {
|
|
192
|
+
value = JSON.parse(String(value));
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return { error: `The input env is not JSON: ${error.message}` };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const checked = check(key, value, "the inputs", input.repository);
|
|
198
|
+
if ("error" in checked) return checked;
|
|
199
|
+
config[key] = checked.value;
|
|
200
|
+
}
|
|
201
|
+
source = "inputs";
|
|
202
|
+
} else return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, "The site config").` };
|
|
203
|
+
for (const key of ["build", "out"]) if (config[key] === "") return { error: `${source === "file" ? input.path : "the inputs of the workflow"} gives no "${key}". The site config needs "build" and "out".` };
|
|
204
|
+
return {
|
|
205
|
+
config,
|
|
206
|
+
source
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export { SITE_CONFIG_KEYS, SITE_CONFIG_PATH, fillRepository, inputsGiven, resolveSiteConfig };
|
|
210
|
+
|
|
211
|
+
//# sourceMappingURL=site-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.js","names":[],"sources":["../../src/config/site-config.ts"],"sourcesContent":["/**\n * The site config of a repository: the one home of the inputs of its site build (CI.md, \"The site config\").\n *\n * The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and\n * `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two\n * workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.\n *\n * A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old\n * caller keeps its site. A repository that has the file and also gives a site input gets an error.\n *\n * In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,\n * so the workflow starts it from the template commit with no install.\n */\n\n/** The path of the site config in a repository. */\nexport const SITE_CONFIG_PATH = \".github/site.json\";\n\n/** The type of a key: a string, a boolean or a map of environment variables. */\nexport type SiteConfigKind = \"string\" | \"boolean\" | \"env\";\n\n/** The site config: a value for each key. CI.md tells each key. */\nexport interface SiteConfig {\n /** The command that builds the site. It is the one necessary key, with `out`. */\n readonly build: string;\n /** The folder of the built site. */\n readonly out: string;\n /** The environment variables of the build. `{owner}` and `{repo}` change in each value. */\n readonly env: Readonly<Record<string, string>>;\n /** `true` gives the build the token of the job as `GITHUB_TOKEN`. */\n readonly \"github-token\": boolean;\n /** The Node.js version of the build. */\n readonly \"node-version\": string;\n /** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */\n readonly \"node-version-file\": string;\n /** `true` adds the Releases page and the Status page. */\n readonly \"site-pages\": boolean;\n /** The npm version of site-pages for its pages. Empty uses the template commit. */\n readonly \"site-pages-version\": string;\n /** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */\n readonly roadmap: string;\n /** The base path of the site, for example `/{repo}/`. */\n readonly base: string;\n /** The npm packages of the Releases page, with commas between them. */\n readonly packages: string;\n /** The folder of the changesets of the Status page. */\n readonly changesets: string;\n /** The group of the pages of the site. */\n readonly group: string;\n /** A style file of the site for the pages of site-pages. */\n readonly css: string;\n /** The name of the site in the bar and in the titles. */\n readonly \"site-name\": string;\n /** `true` writes only the data files of the pages, with no HTML. */\n readonly \"data-only\": boolean;\n /** A file of data stamps, for the freshness gate. */\n readonly \"data-stamps\": string;\n /** `true` checks the pages in a browser at each width. */\n readonly \"site-check\": boolean;\n /** The pages of the site check, with commas between them. */\n readonly \"site-check-pages\": string;\n /** The widths of the site check, with commas between them. */\n readonly \"site-check-widths\": string;\n /** A probe script of the site check. */\n readonly \"site-check-probe\": string;\n /** The Playwright version of the site check. */\n readonly \"site-check-playwright\": string;\n /** `true` gives each page the bar of the site. */\n readonly \"site-bar\": boolean;\n /** The pages of the bar, with commas between them. */\n readonly \"site-bar-pages\": string;\n /** The npm name of the package of the site, for the npm link of the bar. */\n readonly \"site-bar-npm\": string;\n /** `true` gives each code block the scroll cue. */\n readonly \"scroll-cue\": boolean;\n /** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */\n readonly \"indexnow-key\": string;\n}\n\n/** A key of the site config. */\nexport type SiteConfigKey = keyof SiteConfig;\n\n/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */\nexport interface SiteConfigKeySpec<T> {\n readonly kind: SiteConfigKind;\n readonly default: T;\n}\n\n/** The keys of the site config, with their types and their defaults. */\nexport const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]> } = {\n build: { kind: \"string\", default: \"\" },\n out: { kind: \"string\", default: \"\" },\n env: { kind: \"env\", default: {} },\n \"github-token\": { kind: \"boolean\", default: false },\n \"node-version\": { kind: \"string\", default: \"26\" },\n \"node-version-file\": { kind: \"string\", default: \"\" },\n \"site-pages\": { kind: \"boolean\", default: true },\n \"site-pages-version\": { kind: \"string\", default: \"\" },\n roadmap: { kind: \"string\", default: \"\" },\n base: { kind: \"string\", default: \"\" },\n packages: { kind: \"string\", default: \"\" },\n changesets: { kind: \"string\", default: \"\" },\n group: { kind: \"string\", default: \"\" },\n css: { kind: \"string\", default: \"\" },\n \"site-name\": { kind: \"string\", default: \"\" },\n \"data-only\": { kind: \"boolean\", default: false },\n \"data-stamps\": { kind: \"string\", default: \"\" },\n \"site-check\": { kind: \"boolean\", default: false },\n \"site-check-pages\": { kind: \"string\", default: \"\" },\n \"site-check-widths\": { kind: \"string\", default: \"\" },\n \"site-check-probe\": { kind: \"string\", default: \"\" },\n \"site-check-playwright\": { kind: \"string\", default: \"1.64.1\" },\n \"site-bar\": { kind: \"boolean\", default: false },\n \"site-bar-pages\": { kind: \"string\", default: \"\" },\n \"site-bar-npm\": { kind: \"string\", default: \"\" },\n \"scroll-cue\": { kind: \"boolean\", default: true },\n \"indexnow-key\": { kind: \"string\", default: \"\" },\n};\n\n/** The input of {@link resolveSiteConfig}. */\nexport interface SiteConfigInput {\n /** The text of .github/site.json, or undefined when the repository has no such file. */\n readonly file: string | undefined;\n /** The path of the file, for the messages. */\n readonly path: string;\n /** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */\n readonly inputs: Readonly<Record<string, unknown>> | undefined;\n /** The repository, \"owner/name\". */\n readonly repository: string;\n}\n\n/** The site config and its source, or an error. */\nexport type SiteConfigResult = { readonly config: SiteConfig; readonly source: \"file\" | \"inputs\" } | { readonly error: string };\n\nconst NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** This function puts the owner and the name of the repository in for {owner} and {repo}. */\nexport function fillRepository(value: string, repository: string): string {\n const [owner = \"\", repo = \"\"] = repository.split(\"/\");\n return value.replaceAll(\"{owner}\", owner).replaceAll(\"{repo}\", repo);\n}\n\n/** This function checks one value against the type of its key, and gives the value or an error. */\nfunction check(key: SiteConfigKey, value: unknown, where: string, repository: string): { value: SiteConfig[SiteConfigKey] } | { error: string } {\n const kind: SiteConfigKind = SITE_CONFIG_KEYS[key].kind;\n if (kind === \"boolean\") {\n return typeof value === \"boolean\" ? { value } : { error: `${where}: \"${key}\" must be true or false.` };\n }\n if (kind === \"string\") {\n return typeof value === \"string\" ? { value: fillRepository(value, repository) } : { error: `${where}: \"${key}\" must be a string.` };\n }\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return { error: `${where}: \"env\" must be an object of strings.` };\n const env: Record<string, string> = {};\n for (const [name, text] of Object.entries(value)) {\n if (!NAME.test(name)) return { error: `${where}: \"${name}\" of \"env\" is not a name of an environment variable.` };\n if (typeof text !== \"string\") return { error: `${where}: the value of \"${name}\" of \"env\" must be a string.` };\n env[name] = fillRepository(text, repository);\n }\n return { value: env };\n}\n\n/**\n * This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.\n * The input `env` of `reusable-pages.yml` is a JSON string, and `\"{}\"` or an empty string is its default.\n */\nexport function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[] {\n return (Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]).filter((key) => {\n const value = inputs[key];\n if (value === undefined) return false;\n if (key === \"env\") return !(value === \"\" || (typeof value === \"string\" && value.replace(/\\s/g, \"\") === \"{}\"));\n return value !== SITE_CONFIG_KEYS[key].default;\n });\n}\n\n/**\n * This function gives the site config of a repository from its file, or from the old inputs when it has no file. The\n * workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.\n */\nexport function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult {\n const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default])) as Record<SiteConfigKey, unknown>;\n let source: \"file\" | \"inputs\";\n if (input.file !== undefined) {\n const given = input.inputs === undefined ? [] : inputsGiven(input.inputs);\n if (given.length > 0) {\n return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(\", \")}. Give the site values only in ${input.path}.` };\n }\n let data: unknown;\n try {\n data = JSON.parse(input.file);\n } catch (error) {\n return { error: `${input.path} is not JSON: ${(error as Error).message}` };\n }\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };\n for (const [key, value] of Object.entries(data)) {\n if (key === \"$schema\" || key === \"$comment\") continue;\n if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: \"${key}\" is not a key of the site config. CI.md tells the keys.` };\n const checked = check(key as SiteConfigKey, value, input.path, input.repository);\n if (\"error\" in checked) return checked;\n config[key as SiteConfigKey] = checked.value;\n }\n source = \"file\";\n } else if (input.inputs !== undefined) {\n for (const key of Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]) {\n let value = input.inputs[key];\n if (value === undefined) continue;\n // The input env of reusable-pages.yml is a JSON string, and an empty string means no variables.\n if (key === \"env\") {\n if (value === \"\") continue;\n try {\n value = JSON.parse(String(value));\n } catch (error) {\n return { error: `The input env is not JSON: ${(error as Error).message}` };\n }\n }\n const checked = check(key, value, \"the inputs\", input.repository);\n if (\"error\" in checked) return checked;\n config[key] = checked.value;\n }\n source = \"inputs\";\n } else {\n return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, \"The site config\").` };\n }\n for (const key of [\"build\", \"out\"] as const) {\n if (config[key] === \"\") {\n const home = source === \"file\" ? input.path : \"the inputs of the workflow\";\n return { error: `${home} gives no \"${key}\". The site config needs \"build\" and \"out\".` };\n }\n }\n return { config: config as SiteConfig, source };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,mBAAmB;;AAyEhC,MAAa,mBAAwF;CACnG,OAAO;EAAE,MAAM;EAAU,SAAS;CAAG;CACrC,KAAK;EAAE,MAAM;EAAU,SAAS;CAAG;CACnC,KAAK;EAAE,MAAM;EAAO,SAAS,CAAC;CAAE;CAChC,gBAAgB;EAAE,MAAM;EAAW,SAAS;CAAM;CAClD,gBAAgB;EAAE,MAAM;EAAU,SAAS;CAAK;CAChD,qBAAqB;EAAE,MAAM;EAAU,SAAS;CAAG;CACnD,cAAc;EAAE,MAAM;EAAW,SAAS;CAAK;CAC/C,sBAAsB;EAAE,MAAM;EAAU,SAAS;CAAG;CACpD,SAAS;EAAE,MAAM;EAAU,SAAS;CAAG;CACvC,MAAM;EAAE,MAAM;EAAU,SAAS;CAAG;CACpC,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