+ This specification defines APIs for scheduling and controlling
+ prioritized tasks.
+
+
+
+
+
Introduction
+
Some informative introductory text.
+
+
+
Start your spec!
+
Replace this with the specification's normative content.
+
+
+
+ This is required for specifications that contain normative material.
+
+
+
+
diff --git a/profiles/w3c.js b/profiles/w3c.js
index 6baf54eeb5..843c7c4400 100644
--- a/profiles/w3c.js
+++ b/profiles/w3c.js
@@ -14,6 +14,7 @@ const modules = [
import("../src/core/reindent.js"),
import("../src/core/title.js"),
import("../src/w3c/level.js"),
+ import("../src/w3c/cg-identity.js"),
import("../src/w3c/headers.js"),
import("../src/w3c/abstract.js"),
import("../src/core/data-transform.js"),
@@ -42,6 +43,7 @@ const modules = [
import("../src/core/fix-headers.js"),
import("../src/core/webidl-index.js"),
import("../src/core/cddl-index.js"),
+ import("../src/w3c/cg-sections.js"),
import("../src/core/structure.js"),
import("../src/core/informative.js"),
import("../src/core/id-headers.js"),
diff --git a/src/type-helper.d.ts b/src/type-helper.d.ts
index 1e35021e3e..8668c242ba 100644
--- a/src/type-helper.d.ts
+++ b/src/type-helper.d.ts
@@ -131,6 +131,17 @@ interface Conf {
* not dark-aware yet.
*/
darkMode?: boolean;
+ /**
+ * Maturity stage of a Community Group specification using the redesign, i.e.
+ * one with a `specStatus` of `"CG-LIVING"` or `"CG-SNAPSHOT"`. Defaults to
+ * `"draft"`, and has no effect on any other kind of document.
+ */
+ cgMaturity?: "draft" | "transferred" | "unmaintained";
+ /**
+ * The organization that has taken up the work, named in the notice of a CG
+ * redesign specification whose `cgMaturity` is `"transferred"`.
+ */
+ transferredTo?: string | { name: string; url?: string };
/** Indicates whether the document is a preview */
isPreview?: boolean;
@@ -278,6 +289,8 @@ interface Conf {
wgPatentHTML?: string | unknown[];
/** Type of W3C group */
groupType?: string | string[];
+ /** The group's own homepage(s) */
+ groupHomeURI?: string | string[];
/** Base URL for linking to issues */
issueBase?: string;
/** URL to the issue tracker */
@@ -411,6 +424,7 @@ type GroupDetails = {
wgPatentURI: string;
wgPatentPolicy: string;
groupType: string;
+ groupHomeURI: string;
};
type LicenseInfo = {
diff --git a/src/w3c/cg-assets.js b/src/w3c/cg-assets.js
new file mode 100644
index 0000000000..78ee0a5991
--- /dev/null
+++ b/src/w3c/cg-assets.js
@@ -0,0 +1,174 @@
+// @ts-check
+/**
+ * Module w3c/cg-assets
+ *
+ * The style sheets and scripts of the Community Group specification redesign,
+ * which live in w3c/cg-spec-assets rather than in /StyleSheets/TR/2021/. Only
+ * the `cgRedesignStatus` documents use them; `CG-DRAFT` and `CG-FINAL` keep
+ * the older W3C-hosted CG styles.
+ *
+ * The markup this emits is the contract documented in cg-spec-assets' README,
+ * under "How a specification uses these".
+ */
+
+import { createResourceHint } from "../core/utils.js";
+import { disableDarkStyles } from "../core/insert-style.js";
+import { html } from "../core/import-maps.js";
+import { sub } from "../core/pubsubhub.js";
+
+export const name = "w3c/cg-assets";
+
+export const CG_ASSETS_BASE = "https://incubation.w3.org/assets/specs-2026/";
+
+/** @param {string} path */
+export function cgAssetUrl(path) {
+ return new URL(path, CG_ASSETS_BASE).href;
+}
+
+/**
+ * base.css, cg-spec.css and dark.css all set the same `:root` custom properties
+ * at equal specificity, so a document that loads them out of order gets the
+ * wrong colours. Keep them adjacent and in this order, live and on save.
+ */
+const STYLES = ["css/base.css", "css/cg-spec.css", "css/dark.css"];
+
+/** Dark mode assets */
+const DARK_STYLE = "css/dark.css";
+const DARK_SCRIPT = "js/dark.js";
+
+/** @type {{ path: string; defer?: boolean }[]} */
+const SCRIPTS = [
+ { path: "js/cg-fixup.js" },
+ { path: "js/dark.js" },
+ { path: "js/cg-metadata.js", defer: true },
+];
+
+/**
+ * Drops the w3.org styles and hints that this module's sibling w3c/style adds
+ * at import time, before any configuration is readable.
+ */
+function removeTRAssets() {
+ const selectors = [
+ 'head link[rel~="preconnect"][href^="https://www.w3.org"]',
+ 'head link[rel~="preload"][href^="https://www.w3.org/StyleSheets/TR/"]',
+ 'head link[rel~="preload"][href^="https://www.w3.org/scripts/TR/"]',
+ 'head link[rel~="stylesheet"][href^="https://www.w3.org/StyleSheets/TR/"]',
+ ];
+ for (const link of document.querySelectorAll(selectors.join(", "))) {
+ link.remove();
+ }
+}
+
+/** @param {string[]} styles */
+function createResourceHints(styles) {
+ /** @type {ResourceHintOption[]} */
+ const opts = [{ hint: "preconnect", href: CG_ASSETS_BASE }];
+ for (const path of styles) {
+ opts.push({ hint: "preload", href: cgAssetUrl(path), as: "style" });
+ }
+ return opts.map(createResourceHint);
+}
+
+/**
+ * The dark sheet carries `media` so that a reader without JavaScript still gets
+ * a palette matching their system, and `class="dark-mode"` so that
+ * cg-spec-assets' dark.js can find the sheet it drives from the theme picker.
+ *
+ * @param {string} path
+ */
+function createStyleLink(path) {
+ const href = cgAssetUrl(path);
+ return path.endsWith("dark.css")
+ ? html``
+ : html``;
+}
+
+/**
+ * @param {string} path
+ * @param {object} [options]
+ * @param {boolean} [options.defer]
+ */
+function createScript(path, { defer = false } = {}) {
+ return html``;
+}
+
+/**
+ * Puts the exported document back the way the generator wrote it.
+ *
+ * The three scripts run in ReSpec's own browser, so whatever they did to suit
+ * that one reader -- which theme was showing, whether the status metadata
+ * loaded -- would otherwise be published as everyone's starting state. This is
+ * the same job w3c/style's `styleMover` and `restoreDarkLinkState` do for the
+ * W3C TR assets.
+ *
+ * Note this receives the cloned `` element, not a document; see
+ * core/exporter.
+ *
+ * @param {Element} exportRoot
+ */
+function restoreExportedState(exportRoot) {
+ const head = exportRoot.querySelector("head");
+ // Order matters as much on disk as it does live: all three sheets set the
+ // same `:root` custom properties at equal specificity.
+ for (const path of STYLES) {
+ const link = exportRoot.querySelector(
+ `head link[rel~="stylesheet"][href="${cgAssetUrl(path)}"]`
+ );
+ if (!link) continue;
+ head?.append(link);
+ // dark.js swaps the media list for "all" / "not all" to follow the reader's
+ // theme. Published like that, a reader without scripting gets either an
+ // unconditional dark page or no dark palette at all.
+ if (path.endsWith("dark.css")) {
+ link.setAttribute("media", "(prefers-color-scheme: dark)");
+ }
+ }
+
+ // dark.js also marks the body while dark is showing. core/exporter already
+ // drops cg-fixup.js's `toc-sidebar` / `toc-inline` for the same reason.
+ exportRoot.querySelector("body")?.classList.remove("darkmode");
+}
+
+/**
+ * Inserts the CG style sheets and scripts, replacing the W3C TR ones.
+ *
+ * `darkMode: false` drops the dark.css and dark.js.
+ *
+ * @param {Conf} conf
+ */
+export function insertCGAssets(conf) {
+ const darkMode = conf.darkMode !== false;
+ const styles = darkMode ? STYLES : STYLES.filter(p => p !== DARK_STYLE);
+ const scripts = darkMode
+ ? SCRIPTS
+ : SCRIPTS.filter(({ path }) => path !== DARK_SCRIPT);
+
+ removeTRAssets();
+ if (!darkMode) disableDarkStyles();
+ document.head.prepend(...createResourceHints(styles));
+ for (const path of styles) {
+ document.head.appendChild(createStyleLink(path));
+ }
+ sub("beforesave", restoreExportedState);
+
+ // At the end, like w3c/style does for fixup.js: these scripts read the
+ // finished document.
+ sub(
+ "end-all",
+ () => {
+ for (const { path, defer } of scripts) {
+ document.body.appendChild(createScript(path, { defer }));
+ }
+ },
+ { once: true }
+ );
+}
diff --git a/src/w3c/cg-identity.js b/src/w3c/cg-identity.js
new file mode 100644
index 0000000000..91bfc99692
--- /dev/null
+++ b/src/w3c/cg-identity.js
@@ -0,0 +1,56 @@
+// @ts-check
+/**
+ * Module w3c/cg-identity
+ *
+ * Declares what a Community Group specification is, for cg-spec-assets'
+ * cg-metadata.js: which kind of document it is, which entry of the collected
+ * status metadata belongs to it, and how mature it is.
+ *
+ * This runs after core/github and w3c/level, both of which can still change
+ * `shortName`, and that name is the metadata lookup key.
+ */
+
+import { docLink, showError } from "../core/utils.js";
+import { html } from "../core/import-maps.js";
+import { isCGSpec } from "./headers.js";
+import { sub } from "../core/pubsubhub.js";
+
+export const name = "w3c/cg-identity";
+
+/** @param {Conf} conf */
+export function run(conf) {
+ if (!isCGSpec(conf)) return;
+
+ if (!conf.shortName) {
+ const specStatus = conf.specStatus ?? "";
+ const msg = docLink`The ${"[shortName]"} configuration option is required for a \`"${specStatus}"\` document.`;
+ const hint = docLink`The status metadata of a Community Group specification is looked up by short name. Please set ${"[shortName]"} to the specification's short name.`;
+ showError(msg, name, { hint });
+ // Without it there is nothing to look the metadata up by, so say nothing
+ // rather than publish an identity that cannot resolve.
+ return;
+ }
+
+ const type = conf.specStatus === "CG-SNAPSHOT" ? "snapshot" : "living";
+ document.head.append(
+ html``,
+ html``,
+ html``
+ );
+
+ // State of the metadata for this document. cg-metadata.js overwrites it
+ // with "fresh", "stale" or "unknown-type".
+ document.documentElement.dataset.cgMetadata = "static";
+ sub(
+ "beforesave",
+ /** @param {HTMLElement} exportRoot */ exportRoot => {
+ exportRoot.dataset.cgMetadata = "static";
+ // reset regions populated by cg-metadata.js
+ for (const region of exportRoot.querySelectorAll("[data-cg-region]")) {
+ for (const node of [...region.childNodes]) {
+ if (node.nodeName !== "NOSCRIPT") node.remove();
+ }
+ }
+ }
+ );
+}
diff --git a/src/w3c/cg-sections.js b/src/w3c/cg-sections.js
new file mode 100644
index 0000000000..ed69adc015
--- /dev/null
+++ b/src/w3c/cg-sections.js
@@ -0,0 +1,126 @@
+// @ts-check
+/**
+ * Module w3c/cg-sections
+ *
+ * The two boilerplate sections at the foot of a Community Group specification:
+ * how to get involved, and the usage guidance.
+ *
+ * Registered after the index-generating modules and before core/structure, so
+ * these land last in the document and in the table of contents, but are not
+ * numbered.
+ */
+
+import {
+ cgVariant,
+ createRegion,
+ repeatedNotice,
+} from "./templates/cg-headers.js";
+import { html } from "../core/import-maps.js";
+import { isCGSpec } from "./headers.js";
+
+export const name = "w3c/cg-sections";
+
+const COMMUNITY = "https://www.w3.org/community/";
+
+/**
+ * The "Get involved" section: where to give feedback, and how to join the
+ * group behind the specification.
+ *
+ * @param {Conf} conf
+ */
+function getInvolved(conf) {
+ // @ts-expect-error -- conf.github is normalized to object form by core/github
+ const issuesURL = conf.github?.issuesURL;
+ const hasIssueSummary = !!document.getElementById("issue-summary");
+ const joinURL =
+ typeof conf.groupHomeURI === "string"
+ ? new URL("join", conf.groupHomeURI.replace(/\/?$/, "/")).href
+ : null;
+
+ // `introductory` is how ReSpec says "list this in the table of contents but
+ // do not number it": boilerplate, not part of the specification's own
+ // sequence of sections. See core/structure's `isIntro`.
+ return html`
+
Get involved
+
There are many ways to support this W3C Community Group incubation.
+ `;
+}
+
+/**
+ * A living specification carries the collected usage guidance, so the section
+ * is an empty container for cg-metadata.js to fill.
+ */
+function draftGuidance() {
+ return html`${createRegion(
+ "usage-guidance",
+ "The usage guidance for this specification is loaded from the status metadata, which needs JavaScript."
+ )}
+
+ Disclaimer: The data in these tables is managed outside
+ the document and is updated automatically. While W3C strives to ensure the
+ accuracy of status data, we do not guarantee that the information is
+ error-free. Any mention of specific products or services is solely for
+ informational purposes and does not imply endorsement by W3C, Inc. or its
+ Members.
+
`;
+}
+
+/**
+ * Guidance for someone deciding whether to build on this.
+ *
+ * A living specification still in development has collected guidance, which
+ * cg-metadata.js fills in. The other three have none: a snapshot is archival,
+ * and a transferred or unmaintained specification is not somewhere to build
+ * on at all. For those, the section repeats the notice from the head of the
+ * document, so a reader who arrives at the foot -- from the table of contents,
+ * or a link to `#usage-guidance` -- reads it where they are.
+ *
+ * @param {Conf} conf
+ */
+function usageGuidance(conf) {
+ return html`
+
Usage guidance
+ ${cgVariant(conf) === "draft" ? draftGuidance() : repeatedNotice(conf)}
+ `;
+}
+
+/** @param {Conf} conf */
+export function run(conf) {
+ if (!isCGSpec(conf)) return;
+
+ // Nothing to get involved in once a specification is unmaintained: the
+ // section would only point at a dormant repository.
+ if (cgVariant(conf) !== "unmaintained") {
+ document.body.append(getInvolved(conf));
+ }
+ document.body.append(usageGuidance(conf));
+}
diff --git a/src/w3c/defaults.js b/src/w3c/defaults.js
index 7cc866a9f9..959fc63cfb 100644
--- a/src/w3c/defaults.js
+++ b/src/w3c/defaults.js
@@ -6,7 +6,9 @@ export const name = "w3c/defaults";
import {
W3CNotes,
bgStatus,
+ cgRedesignStatus,
cgStatus,
+ isCGSpec,
recTrackStatus,
registryTrackStatus,
status2text,
@@ -81,6 +83,7 @@ export function run(conf) {
}
validateStatusForGroup(conf);
+ validateAndNormalizeCGMaturity(conf);
processLogos(/** @type {NormalizedConf} */ (conf));
}
@@ -110,6 +113,61 @@ function processLogos(conf) {
}
}
+const CG_MATURITIES = ["draft", "transferred", "unmaintained"];
+
+/**
+ * The maturity stage of a CG specification, which is a separate axis from its
+ * status: either of the two redesign statuses can be at any of the three
+ * stages, and the stage changes the markup rather than a value.
+ *
+ * @param {Conf} conf
+ */
+function validateAndNormalizeCGMaturity(conf) {
+ // Silently irrelevant elsewhere: nothing about a document that is not one of
+ // these two statuses should change because this option exists.
+ if (!isCGSpec(conf)) return;
+
+ if (conf.cgMaturity === undefined) {
+ conf.cgMaturity = "draft";
+ } else if (!CG_MATURITIES.includes(conf.cgMaturity)) {
+ const choices = codedJoinOr(CG_MATURITIES, { quotes: true });
+ const msg = docLink`\`"${conf.cgMaturity}"\` is not a supported value for the ${"[cgMaturity]"} configuration option.`;
+ const hint = `Please use one of: ${choices}. Automatically falling back to \`"draft"\`.`;
+ showError(msg, name, { hint });
+ conf.cgMaturity = "draft";
+ }
+
+ validateTransferredTo(conf);
+}
+
+/**
+ * @param {Conf["transferredTo"]} to
+ */
+function organizationName(to) {
+ if (typeof to === "string") return to.trim();
+ if (to && typeof to === "object" && typeof to.name === "string") {
+ return to.name.trim();
+ }
+ return "";
+}
+
+/**
+ * A transferred specification must say who took the work up.
+ *
+ * @param {Conf} conf
+ */
+function validateTransferredTo(conf) {
+ if (conf.cgMaturity !== "transferred") return;
+ if (organizationName(conf.transferredTo)) return;
+
+ const msg = conf.transferredTo
+ ? docLink`The ${"[transferredTo]"} configuration option needs the name of an organization.`
+ : docLink`The ${"[transferredTo]"} configuration option is required when ${"[cgMaturity]"} is \`"transferred"\`.`;
+ const hint = docLink`Set ${"[transferredTo]"} to the organization that has taken the work up: a name, or \`{ name, url }\`. Until it is set, the notice reads "Another organization".`;
+ showError(msg, name, { hint });
+ delete conf.transferredTo;
+}
+
/**
* @param {Conf} conf
*/
@@ -138,9 +196,16 @@ function validateStatusForGroup(conf) {
switch (groupType) {
case "cg": {
- if (![...cgStatus, "unofficial", "UD"].includes(specStatus)) {
+ if (
+ ![...cgStatus, ...cgRedesignStatus, "unofficial", "UD"].includes(
+ specStatus
+ )
+ ) {
const msg = docLink`W3C Community Group documents can't use \`"${specStatus}"\` for the ${"[specStatus]"} configuration option.`;
- const supportedStatus = codedJoinOr(cgStatus, { quotes: true });
+ const supportedStatus = codedJoinOr(
+ [...cgStatus, ...cgRedesignStatus],
+ { quotes: true }
+ );
const hint = `Please use one of: ${supportedStatus}. Automatically falling back to \`"CG-DRAFT"\`.`;
showError(msg, name, { hint });
conf.specStatus = "CG-DRAFT";
diff --git a/src/w3c/group.js b/src/w3c/group.js
index e6b7d68f9b..e765cc3045 100644
--- a/src/w3c/group.js
+++ b/src/w3c/group.js
@@ -41,6 +41,7 @@ async function getMultipleGroupDetails(groups) {
wgPatentURI: [],
wgPatentPolicy: [],
groupType: [],
+ groupHomeURI: [],
};
for (const groupDetails of details.filter(Boolean)) {
for (const key of Object.keys(result)) {
@@ -74,8 +75,17 @@ async function getGroupDetails(group) {
patentPolicy: wgPatentPolicy,
type: groupType,
wgURI,
+ URI: groupHomeURI,
} = json;
- return { wg, wgId, wgURI, wgPatentURI, wgPatentPolicy, groupType };
+ return {
+ wg,
+ wgId,
+ wgURI,
+ wgPatentURI,
+ wgPatentPolicy,
+ groupType,
+ groupHomeURI,
+ };
}
const text = await res.text();
diff --git a/src/w3c/headers.js b/src/w3c/headers.js
index 5b7624c572..900862395a 100644
--- a/src/w3c/headers.js
+++ b/src/w3c/headers.js
@@ -93,6 +93,8 @@ import {
showError,
showWarning,
} from "../core/utils.js";
+import cgHeadersTmpl, { snapshotAddress } from "./templates/cg-headers.js";
+import cgSotdTmpl from "./templates/cg-sotd.js";
import cgbgHeadersTmpl from "./templates/cgbg-headers.js";
import cgbgSotdTmpl from "./templates/cgbg-sotd.js";
import headersTmpl from "./templates/headers.js";
@@ -146,6 +148,8 @@ export const status2text = {
"editor-draft-finding": "Draft TAG Finding",
"CG-DRAFT": "Draft Community Group Report",
"CG-FINAL": "Final Community Group Report",
+ "CG-LIVING": "Community Group Living Specification",
+ "CG-SNAPSHOT": "Community Group Snapshot",
"BG-DRAFT": "Draft Business Group Report",
"BG-FINAL": "Final Business Group Report",
};
@@ -189,8 +193,15 @@ export const recTrackStatus = [
export const registryTrackStatus = ["DRY", "CRY", "CRYD", "RY"];
export const tagStatus = ["draft-finding", "finding", "editor-draft-finding"];
export const cgStatus = ["CG-DRAFT", "CG-FINAL"];
+// The two statuses of the CG specification redesign, which uses the
+// cg-spec-assets style sheets and scripts rather than the
+// /StyleSheets/TR/2021/cg-* ones.
+// Deliberately kept out of `cgStatus`, so that nothing an existing Community
+// Group report does changes: these join only the lists they have to be in to be
+// treated as Community Group reports at all.
+export const cgRedesignStatus = ["CG-LIVING", "CG-SNAPSHOT"];
export const bgStatus = ["BG-DRAFT", "BG-FINAL"];
-export const cgbgStatus = [...cgStatus, ...bgStatus];
+export const cgbgStatus = [...cgStatus, ...cgRedesignStatus, ...bgStatus];
export const trStatus = [
...W3CNotes,
...recTrackStatus,
@@ -199,6 +210,7 @@ export const trStatus = [
export const noTrackStatus = [
"base",
...cgStatus,
+ ...cgRedesignStatus,
...bgStatus,
"editor-draft-finding",
"draft-finding",
@@ -206,6 +218,15 @@ export const noTrackStatus = [
"MO",
"unofficial",
];
+
+/**
+ * Whether the document is a CG-SNAPSHOT or CG-LIVING specification.
+ *
+ * @param {Conf} conf
+ */
+export const isCGSpec = conf =>
+ cgRedesignStatus.includes(conf.specStatus ?? "");
+
/** @type {Map} */
export const licenses = new Map([
[
@@ -322,6 +343,17 @@ function deriveLicenseInfo(conf) {
return licenseInfo;
}
+/**
+ * Select the appropriate header and SoTD templates.
+ *
+ * @param {Conf} conf
+ */
+function templatesFor(conf) {
+ if (isCGSpec(conf)) return { header: cgHeadersTmpl, sotd: cgSotdTmpl };
+ if (conf.isCGBG) return { header: cgbgHeadersTmpl, sotd: cgbgSotdTmpl };
+ return { header: headersTmpl, sotd: sotdTmpl };
+}
+
/** @param {Conf} conf */
export async function run(conf) {
// specStatus is always set by defaults before this module runs
@@ -399,6 +431,12 @@ export async function run(conf) {
conf.thisVersion = w3Url(`${pubSpace}/${year}${docVersion}/`);
}
+ // check if a CG snapshot address can be derived
+ if (!conf.thisVersion) {
+ const address = snapshotAddress(conf);
+ if (address) conf.thisVersion = address;
+ }
+
if (conf.isEd) conf.thisVersion = conf.edDraftURI;
if (conf.isCGBG) validateCGBG(conf);
if (conf.latestVersion !== null) {
@@ -522,7 +560,7 @@ export async function run(conf) {
};
// insert into document
- const header = (conf.isCGBG ? cgbgHeadersTmpl : headersTmpl)(conf, options);
+ const header = templatesFor(conf).header(conf, options);
document.body.prepend(header);
document.body.classList.add("h-entry");
@@ -828,8 +866,7 @@ function populateSoTD(conf, sotd) {
return `mailto:${conf.wgPublicList}-request@w3.org?subject=subscribe`;
},
};
- const template = conf.isCGBG ? cgbgSotdTmpl : sotdTmpl;
- return template(conf, options);
+ return templatesFor(conf).sotd(conf, options);
}
/**
diff --git a/src/w3c/seo.js b/src/w3c/seo.js
index 717224c9b3..01587a0b3c 100644
--- a/src/w3c/seo.js
+++ b/src/w3c/seo.js
@@ -25,6 +25,7 @@ export const requiresCanonicalLink = new Set([
...registryTrackStatus,
"BG-FINAL",
"CG-FINAL",
+ "CG-SNAPSHOT",
"CRY",
"DRY",
"draft-finding",
diff --git a/src/w3c/style.js b/src/w3c/style.js
index d939683f5f..b4b8a898f1 100644
--- a/src/w3c/style.js
+++ b/src/w3c/style.js
@@ -4,10 +4,16 @@
* Inserts a link to the appropriate W3C style for the specification's maturity level.
* */
-import { W3CNotes, recTrackStatus, registryTrackStatus } from "./headers.js";
+import {
+ W3CNotes,
+ isCGSpec,
+ recTrackStatus,
+ registryTrackStatus,
+} from "./headers.js";
import { createResourceHint } from "../core/utils.js";
import { disableDarkStyles } from "../core/insert-style.js";
import { html } from "../core/import-maps.js";
+import { insertCGAssets } from "./cg-assets.js";
import { sub } from "../core/pubsubhub.js";
export const name = "w3c/style";
@@ -134,6 +140,14 @@ function restoreDarkLinkState(exportDoc) {
* @param {Conf} conf
*/
export function run(conf) {
+ // The CG specification design has its own style sheets and scripts, and
+ // none of the W3C TR ones below apply to it.
+ // `darkMode` does apply, and insertCGAssets honours it.
+ if (isCGSpec(conf)) {
+ insertCGAssets(conf);
+ return;
+ }
+
// Attach W3C fixup script after we are done.
if (!conf.noTOC) {
sub("end-all", attachFixupScript, { once: true });
diff --git a/src/w3c/templates/cg-headers.js b/src/w3c/templates/cg-headers.js
new file mode 100644
index 0000000000..5e1df8e493
--- /dev/null
+++ b/src/w3c/templates/cg-headers.js
@@ -0,0 +1,434 @@
+// @ts-check
+/**
+ * The header box of a Community Group specification using the redesign, i.e.
+ * one whose `specStatus` is "CG-LIVING" or "CG-SNAPSHOT".
+ *
+ * cg-spec-assets' cg-metadata.js builds it into the `data-cg-region`
+ * containers at load time. A container left empty renders as nothing.
+ */
+
+import { W3CDate, concatDate } from "../../core/utils.js";
+import { getSpecSubTitleElem, l10n } from "./headers.js";
+import { html } from "../../core/import-maps.js";
+import showPeople from "../../core/templates/show-people.js";
+
+export const LIFECYCLE =
+ "https://github.com/w3c/cg-program/blob/main/proposals/spec-lifecycle.md#maturity-stages";
+export const COMMUNITY = "https://www.w3.org/community/";
+const LIVING_V_SNAPSHOT =
+ "https://github.com/w3c/cg-program/blob/main/beta-2026/w3c-programs.md#living-specification-v-snapshot";
+const INCUBATION = "https://incubation.w3.org/";
+
+const NO_SCRIPT = {
+ livingSpec:
+ "The address of the living specification and its last-edited date are loaded from the status metadata, which needs JavaScript.",
+ thisSpec:
+ "The address of this specification and its last-edited date are loaded from the status metadata, which needs JavaScript.",
+ lastEdited:
+ "The last-edited date is loaded from the status metadata, which needs JavaScript.",
+ progress:
+ "The progress towards standardization is loaded from the status metadata, which needs JavaScript.",
+ browserSupport:
+ "Browser support is loaded from the status metadata, which needs JavaScript.",
+};
+
+/**
+ * An empty container for cg-metadata.js + no JavaScript fallback.
+ *
+ * @param {string} name
+ * @param {string} noScriptText
+ * @param {"div" | "li"} elementName
+ */
+export function createRegion(name, noScriptText, elementName = "div") {
+ const fallback = html``;
+ const region = document.createElement(elementName);
+ region.dataset.cgRegion = name;
+ region.append(fallback);
+ return region;
+}
+
+/**
+ * Returns one of "draft", "transferred", "unmaintained", or "snapshot".
+ * CG-SNAPSHOTS are considered "snapshot" variant.
+ *
+ * @param {Conf} conf
+ */
+export function cgVariant(conf) {
+ if (conf.specStatus === "CG-SNAPSHOT") return "snapshot";
+ return conf.cgMaturity ?? "draft";
+}
+
+/**
+ * The address of the snapshots index for this specification, or null without
+ * a short name to build it from.
+ *
+ * @param {Conf} conf
+ * @returns {string | null}
+ */
+function snapshotsIndex(conf) {
+ if (!conf.shortName) return null;
+ const path = `specs/${encodeURIComponent(conf.shortName)}/snapshots/`;
+ return new URL(path, INCUBATION).href;
+}
+
+/**
+ * The address of this snapshot, or null when the document is not one, or when
+ * there is no shortname or publication date.
+ *
+ * @param {Conf} conf
+ * @returns {string | null}
+ */
+export function snapshotAddress(conf) {
+ if (conf.specStatus !== "CG-SNAPSHOT") return null;
+ if (!conf.shortName || !conf.publishDate) return null;
+ const dated = `${conf.shortName}-${concatDate(conf.publishDate)}`;
+ return new URL(`specs/${encodeURIComponent(dated)}/`, INCUBATION).href;
+}
+
+/** @param {Conf} conf */
+function transferredTo(conf) {
+ const to = conf.transferredTo;
+ if (!to) return "Another organization";
+ if (typeof to === "string") return to;
+ return to.url ? html`${to.name}` : to.name;
+}
+
+/**
+ * @param {Conf} conf
+ * @param {Node | string} [endorsement]
+ */
+function snapshotFacts(conf, endorsement = "") {
+ return html`
+ This document instance is archival and is not intended to
+ change.
+
+ Rather than use or reference this specification, please consult the
+ guidance of the organization to which the specification has been
+ transferred.
+
+
+ ${transferredTo(conf)} has taken up the work for standardization and so
+ the W3C Community Group is no longer the “owner”.
+
`;
+}
+
+/** The notice for a specification nobody is maintaining any more. */
+function noticeBoxUnmaintained() {
+ return html`
+
+ This specification is no longer in development and is
+ unmaintained
+
+
+ ${unmaintainedFacts(
+ html`
This specification is not endorsed by W3C.
`
+ )}
+
+
`;
+}
+
+/**
+ * The same notice again, at the foot, as the usage guidance of a document that
+ * has no collected guidance to show. The heading repeats the one at the head
+ * unlinked and in short form, the way the demo documents in cg-spec-assets do.
+ *
+ * A draft is not here: its guidance is collected data, and w3c/cg-sections
+ * leaves a region for it instead.
+ *
+ * @param {Conf} conf
+ */
+export function repeatedNotice(conf) {
+ switch (cgVariant(conf)) {
+ case "snapshot":
+ return html`
`;
+}
+
+/**
+ * The notice depending on the type of CG spec
+ *
+ * @param {Conf} conf
+ */
+function noticeBox(conf) {
+ switch (cgVariant(conf)) {
+ case "snapshot":
+ return noticeBoxSnapshot(conf);
+ case "transferred":
+ return noticeBoxTransferred(conf);
+ case "unmaintained":
+ return noticeBoxUnmaintained();
+ default:
+ return noticeBoxDraft();
+ }
+}
+
+/**
+ * Where to go for what this document does not carry. A snapshot points at the
+ * living specification; a living specification points at its own foot.
+ *
+ * @param {Conf} conf
+ */
+function whereToLook(conf) {
+ const isSnapshot = cgVariant(conf) === "snapshot";
+ const snapshots = snapshotsIndex(conf);
+ const livingSpec = createRegion(
+ "living-spec",
+ isSnapshot ? NO_SCRIPT.livingSpec : NO_SCRIPT.thisSpec,
+ "li"
+ );
+ return html`
+
+ ${
+ isSnapshot
+ ? "Visit the living specification for the latest updates on this incubation"
+ : "This document has the latest updates on this incubation"
+ }
+
`;
+};
diff --git a/src/w3c/templates/cg-sotd.js b/src/w3c/templates/cg-sotd.js
new file mode 100644
index 0000000000..de8ed3eda4
--- /dev/null
+++ b/src/w3c/templates/cg-sotd.js
@@ -0,0 +1,27 @@
+// @ts-check
+/**
+ * The Status of This Document of a Community Group specification using the
+ * redesign.
+ *
+ * It adds nothing. Everything the old CG boilerplate said here -- what kind of
+ * document this is, which agreement applies, how much to rely on it, where to
+ * send comments -- the redesigned header box and the "Get involved" section
+ * now say, in the places a reader actually looks. Saying it twice is two
+ * wordings to keep in step, so this template carries only the heading and
+ * whatever the editors wrote themselves.
+ */
+
+import { l10n, renderPreview } from "./sotd.js";
+import { html } from "../../core/import-maps.js";
+
+/**
+ * @param {Conf} conf
+ * @param {{ additionalContent: DocumentFragment; additionalSections: NodeList }} opts
+ */
+export default (conf, opts) => {
+ return html`
+
${l10n.sotd}
+ ${conf.isPreview ? renderPreview(conf) : ""} ${opts.additionalContent}
+ ${opts.additionalSections}
+ `;
+};
diff --git a/tests/spec/w3c/cg-spec.js b/tests/spec/w3c/cg-spec.js
new file mode 100644
index 0000000000..e61827b616
--- /dev/null
+++ b/tests/spec/w3c/cg-spec.js
@@ -0,0 +1,783 @@
+"use strict";
+
+import {
+ errorFilters,
+ flushIframes,
+ makeRSDoc,
+ makeStandardOps,
+} from "../SpecHelper.js";
+
+import { cgRedesignStatus } from "../../../src/w3c/headers.js";
+import { seedGroupCache } from "../respec-cache-helper.js";
+
+const cgIdentityErrors = errorFilters.filter("w3c/cg-identity");
+const defaultErrors = errorFilters.filter("w3c/defaults");
+const headerErrors = errorFilters.filter("w3c/headers");
+
+const BASE = "https://incubation.w3.org/assets/specs-2026/";
+const INCUBATION = "https://incubation.w3.org/";
+const STYLES = ["css/base.css", "css/cg-spec.css", "css/dark.css"];
+const SCRIPTS = ["js/cg-fixup.js", "js/dark.js", "js/cg-metadata.js"];
+
+const sheet = path => `link[rel~="stylesheet"][href="${BASE}${path}"]`;
+
+// Parse rather than load the export. `getExportedDoc` puts the result in an
+// iframe, where the three cg-spec-assets scripts run again and immediately undo
+// what is being asserted -- they are doing their job, on what has become a live
+// document for a new reader. What ships is the markup, so assert on that.
+const exportedDoc = async doc =>
+ new DOMParser().parseFromString(await doc.respec.toHTML(), "text/html");
+
+const cgOps = (config = {}) =>
+ makeStandardOps({
+ specStatus: "CG-LIVING",
+ group: "wicg",
+ shortName: "scheduling-apis",
+ ...config,
+ });
+
+const norm = el => el.textContent.replace(/\s+/g, " ").trim();
+
+// The notice the usage guidance section repeats at the foot, as opposed to
+// the one in the header box.
+const footNotice = (doc, notice) =>
+ doc
+ .getElementById("usage-guidance")
+ .closest("section")
+ .querySelector(`.${notice}`);
+
+const regionsOf = doc =>
+ [...doc.querySelectorAll("[data-cg-region]")].map(el => el.dataset.cgRegion);
+
+// The four variants of the header box
+const VARIANTS = [
+ {
+ label: "a draft living specification",
+ config: { specStatus: "CG-LIVING", cgMaturity: "draft" },
+ tag: "Draft",
+ notice: "box--information",
+ regions: [
+ "last-edited",
+ "progress",
+ "browser-support",
+ "living-spec",
+ "usage-guidance",
+ ],
+ getInvolved: true,
+ agreement: "Contributor License Agreement",
+ endorsement: "This specification is not endorsed by W3C.",
+ },
+ {
+ label: "a transferred living specification",
+ config: {
+ specStatus: "CG-LIVING",
+ cgMaturity: "transferred",
+ transferredTo: "WHATWG",
+ },
+ tag: "Transferred",
+ notice: "box--information",
+ regions: ["living-spec"],
+ getInvolved: true,
+ agreement: "Contributor License Agreement",
+ endorsement: "This specification itself is not endorsed by W3C.",
+ },
+ {
+ label: "an unmaintained living specification",
+ config: { specStatus: "CG-LIVING", cgMaturity: "unmaintained" },
+ tag: "Unmaintained",
+ notice: "box--warning",
+ regions: ["living-spec"],
+ getInvolved: false,
+ agreement: "Contributor License Agreement",
+ endorsement: "This specification is not endorsed by W3C.",
+ },
+ {
+ label: "a snapshot",
+ config: { specStatus: "CG-SNAPSHOT" },
+ tag: null,
+ notice: "box--information",
+ regions: ["living-spec", "living-spec"],
+ getInvolved: true,
+ agreement: "Final Specification Agreement",
+ endorsement: "This specification is not endorsed by W3C.",
+ },
+];
+
+describe("W3C — CG specification redesign", () => {
+ afterAll(flushIframes);
+ beforeAll(seedGroupCache);
+
+ describe("identity metadata", () => {
+ const TYPES = [
+ ["CG-LIVING", "living"],
+ ["CG-SNAPSHOT", "snapshot"],
+ ];
+ for (const [specStatus, type] of TYPES) {
+ it(`declares ${specStatus} as a "${type}" document`, async () => {
+ const doc = await makeRSDoc(cgOps({ specStatus }));
+ expect(doc.querySelector("meta[name='cg-spec-type']").content).toBe(
+ type
+ );
+ expect(
+ doc.querySelector("meta[name='cg-spec-shortname']").content
+ ).toBe("scheduling-apis");
+ expect(doc.querySelector("meta[name='cg-spec-maturity']").content).toBe(
+ "draft"
+ );
+ expect(cgIdentityErrors(doc)).toHaveSize(0);
+ });
+ }
+
+ it("takes the shortname from the final value, after core/github has set it", async () => {
+ // core/github runs after w3c/style but before w3c/cg-identity, and derives
+ // shortName from the repository when the author has not set one.
+ const ops = cgOps({
+ shortName: undefined,
+ github: "WICG/scheduling-apis",
+ });
+ const doc = await makeRSDoc(ops);
+ expect(doc.querySelector("meta[name='cg-spec-shortname']").content).toBe(
+ "scheduling-apis"
+ );
+ expect(cgIdentityErrors(doc)).toHaveSize(0);
+ });
+
+ it("errors and emits no identity at all when there is no shortName", async () => {
+ const ops = cgOps({ shortName: undefined });
+ const doc = await makeRSDoc(ops);
+ const errors = cgIdentityErrors(doc);
+ expect(errors).toHaveSize(1);
+ expect(errors[0].message).toContain("shortName");
+ // A half-written identity would have cg-metadata.js look up nothing, or
+ // worse, the wrong spec.
+ expect(doc.querySelector("meta[name='cg-spec-type']")).toBeNull();
+ expect(doc.querySelector("meta[name='cg-spec-shortname']")).toBeNull();
+ expect(doc.querySelector("meta[name='cg-spec-maturity']")).toBeNull();
+ });
+
+ it("says nothing about CG identity on a document that is not one", async () => {
+ const doc = await makeRSDoc(
+ makeStandardOps({ specStatus: "CG-DRAFT", group: "wicg" })
+ );
+ expect(doc.querySelector("meta[name='cg-spec-type']")).toBeNull();
+ expect(doc.documentElement.dataset.cgMetadata).toBeUndefined();
+ });
+
+ it("exports the identity", async () => {
+ const doc = await exportedDoc(await makeRSDoc(cgOps()));
+ expect(doc.querySelector("meta[name='cg-spec-type']").content).toBe(
+ "living"
+ );
+ expect(doc.querySelector("meta[name='cg-spec-shortname']").content).toBe(
+ "scheduling-apis"
+ );
+ });
+
+ it("exports the state cg-metadata.js starts from, not the one it reached", async () => {
+ // cg-metadata.js runs in the generator's browser too, and sets this to
+ // say how its own fetch went. Standing in for it here rather than
+ // waiting on the real script: whatever state the live document is in at
+ // save time, the published file starts from "static", or it ships a
+ // currency claim no reader's browser ever made.
+ const live = await makeRSDoc(cgOps());
+ live.documentElement.dataset.cgMetadata = "fresh";
+ const doc = await exportedDoc(live);
+ expect(doc.documentElement.dataset.cgMetadata).toBe("static");
+ });
+
+ it("exports the regions empty, keeping their noscript fallback", async () => {
+ const live = await makeRSDoc(cgOps());
+ const region = live.querySelector('[data-cg-region="usage-guidance"]');
+ region.append(live.createElement("table"), "as of the last fetch");
+ const doc = await exportedDoc(live);
+ const saved = doc.querySelector('[data-cg-region="usage-guidance"]');
+ expect([...saved.childNodes].map(node => node.nodeName)).toEqual([
+ "NOSCRIPT",
+ ]);
+ });
+ });
+
+ describe("cgMaturity", () => {
+ for (const cgMaturity of ["draft", "transferred", "unmaintained"]) {
+ it(`accepts "${cgMaturity}"`, async () => {
+ // "transferred" additionally requires an organization; see below.
+ const doc = await makeRSDoc(
+ cgOps({ cgMaturity, transferredTo: "WHATWG" })
+ );
+ expect(doc.querySelector("meta[name='cg-spec-maturity']").content).toBe(
+ cgMaturity
+ );
+ expect(defaultErrors(doc)).toHaveSize(0);
+ });
+ }
+
+ it("errors and falls back to draft on an unsupported value", async () => {
+ const doc = await makeRSDoc(cgOps({ cgMaturity: "nonsense" }));
+ const errors = defaultErrors(doc);
+ expect(errors).toHaveSize(1);
+ expect(errors[0].message).toContain("cgMaturity");
+ expect(doc.querySelector("meta[name='cg-spec-maturity']").content).toBe(
+ "draft"
+ );
+ });
+
+ it("is silently irrelevant to a document that is not one of the two", async () => {
+ const ops = makeStandardOps({
+ specStatus: "CG-DRAFT",
+ group: "wicg",
+ cgMaturity: "transferred",
+ });
+ const doc = await makeRSDoc(ops);
+ expect(defaultErrors(doc)).toHaveSize(0);
+ expect(doc.respec.warnings).toHaveSize(0);
+ expect(doc.querySelector("meta[name='cg-spec-maturity']")).toBeNull();
+ });
+ });
+
+ describe("assets", () => {
+ it("loads the cg-spec-assets style sheets and scripts", async () => {
+ const doc = await makeRSDoc(cgOps());
+ for (const path of STYLES) {
+ expect(doc.querySelector(sheet(path)))
+ .withContext(path)
+ .toBeTruthy();
+ }
+ for (const path of SCRIPTS) {
+ expect(doc.querySelector(`script[src="${BASE}${path}"]`))
+ .withContext(path)
+ .toBeTruthy();
+ }
+ });
+
+ it("defers cg-metadata.js, which reads the finished document", async () => {
+ const doc = await makeRSDoc(cgOps());
+ const script = doc.querySelector(
+ `script[src="${BASE}js/cg-metadata.js"]`
+ );
+ expect(script.hasAttribute("defer")).toBeTrue();
+ });
+
+ it("gives the dark sheet the class and media dark.js needs", async () => {
+ // dark.js takes the media list over once it runs, so the assertion that
+ // matters is on the exported document: published with dark.js's own
+ // "all" / "not all", a reader without scripting gets either an
+ // unconditional dark page or no dark palette at all.
+ const doc = await exportedDoc(await makeRSDoc(cgOps()));
+ const dark = doc.querySelector(sheet("css/dark.css"));
+ expect(dark.classList).toContain("dark-mode");
+ expect(dark.media).toBe("(prefers-color-scheme: dark)");
+ });
+
+ it("keeps the three sheets adjacent and in order, on export", async () => {
+ // The order is the assertion: all three set the same `:root` custom
+ // properties at equal specificity, so the last one loaded wins.
+ const doc = await exportedDoc(await makeRSDoc(cgOps()));
+ const [base, cgSpec, dark] = STYLES.map(path =>
+ doc.querySelector(sheet(path))
+ );
+ expect(base.nextElementSibling).toBe(cgSpec);
+ expect(cgSpec.nextElementSibling).toBe(dark);
+ expect(dark.nextElementSibling).toBeNull();
+ });
+
+ describe("darkMode: false", () => {
+ const MEDIA_DARK = /@media\s*\([^)]*prefers-color-scheme\s*:\s*dark/;
+ const noDarkOps = () => cgOps({ darkMode: false });
+
+ it("drops the dark sheet and dark.js", async () => {
+ const doc = await makeRSDoc(noDarkOps());
+ expect(
+ doc.querySelector(`link[href="${BASE}css/dark.css"]`)
+ ).toBeNull();
+ expect(doc.querySelector(`script[src="${BASE}js/dark.js"]`)).toBeNull();
+ });
+
+ it("keeps the rest of the CG assets", async () => {
+ const doc = await makeRSDoc(noDarkOps());
+ for (const path of ["css/base.css", "css/cg-spec.css"]) {
+ expect(doc.querySelector(sheet(path)))
+ .withContext(path)
+ .toBeTruthy();
+ }
+ for (const path of ["js/cg-fixup.js", "js/cg-metadata.js"]) {
+ expect(doc.querySelector(`script[src="${BASE}${path}"]`))
+ .withContext(path)
+ .toBeTruthy();
+ }
+ });
+
+ it("strips the dark rules from ReSpec's own styles", async () => {
+ const doc = await makeRSDoc(noDarkOps());
+ const headStyleText = [...doc.querySelectorAll("head style")]
+ .map(style => style.textContent)
+ .join("");
+ expect(headStyleText).not.toMatch(MEDIA_DARK);
+ expect(
+ doc.getElementById("respec-mainstyle").textContent.length
+ ).toBeGreaterThan(0);
+ });
+ });
+
+ it("drops every W3C TR style sheet, hint and script", async () => {
+ const doc = await makeRSDoc(cgOps());
+ // Unfiltered by `rel` on purpose, so preload hints fail this too.
+ expect(
+ doc.querySelector(`link[href^="https://www.w3.org/StyleSheets/TR/"]`)
+ ).toBeNull();
+ expect(
+ doc.querySelector(`script[src^="https://www.w3.org/scripts/TR/"]`)
+ ).toBeNull();
+ // cg-spec-assets' dark.js drives the theme from localStorage and matchMedia,
+ // so this tag would be markup nothing reads.
+ expect(doc.querySelector("meta[name='color-scheme']")).toBeNull();
+ });
+ });
+
+ describe("the header box", () => {
+ it("has a variant for every redesign status", () => {
+ // Adding a status without adding it here would leave its header box
+ // entirely uncovered.
+ const covered = [...new Set(VARIANTS.map(v => v.config.specStatus))];
+ expect(covered.sort()).toEqual([...cgRedesignStatus].sort());
+ });
+
+ for (const variant of VARIANTS) {
+ describe(variant.label, () => {
+ /** @type {Document} */
+ let doc;
+ beforeAll(async () => {
+ doc = await makeRSDoc(cgOps(variant.config));
+ });
+
+ it("uses the redesigned header box, not the old CG one", () => {
+ const head = doc.querySelector(".box.box--head");
+ expect(head).toBeTruthy();
+ expect(head.querySelector("h1#title")).toBeTruthy();
+ // The old template's giveaway: a bare `
` of version URLs.
+ expect(doc.querySelector(".head")).toBeNull();
+ });
+
+ it("leaves exactly the containers this kind of document may show", () => {
+ // A container the script must not fill is one the generator must
+ // not emit: the type gate in cg-metadata.js is the backstop, not
+ // the mechanism.
+ expect(regionsOf(doc)).toEqual(variant.regions);
+ });
+
+ it("gives every container a noscript fallback", () => {
+ for (const container of doc.querySelectorAll("[data-cg-region]")) {
+ expect(container.querySelector("noscript"))
+ .withContext(container.dataset.cgRegion)
+ .toBeTruthy();
+ }
+ });
+
+ it(`renders the ${variant.notice} notice`, () => {
+ const box = doc.querySelector(`.box--head .${variant.notice}`);
+ expect(box).toBeTruthy();
+ expect(box.querySelector("h2")).toBeTruthy();
+ // cg-spec-assets' cg-fixup.js links a transferred spec's banner to
+ // `#top-status-block`, so every notice that can be linked to carries
+ // the id. The unmaintained warning is not linked to and has none.
+ expect(box.id).toBe(
+ variant.notice === "box--warning" ? "" : "top-status-block"
+ );
+ });
+
+ it("says the specification is not endorsed by W3C", () => {
+ const box = doc.querySelector(`.box--head .${variant.notice}`);
+ expect(box.textContent.replace(/\s+/g, " ")).toContain(
+ variant.endorsement
+ );
+ });
+
+ it(
+ variant.tag
+ ? `tags the title "${variant.tag}"`
+ : "does not tag the title with a maturity stage",
+ () => {
+ const tag = doc.querySelector("h1#title .link--button--tag");
+ if (!variant.tag) {
+ expect(tag).toBeNull();
+ return;
+ }
+ expect(tag.textContent.trim()).toBe(variant.tag);
+ // The chevron is part of the control, and textContent would eat
+ // it if anything ever tried to rewrite the label.
+ expect(tag.querySelector("svg.icon")).toBeTruthy();
+ }
+ );
+
+ it(`publishes under the ${variant.agreement}`, () => {
+ const copyright = doc.querySelector(".box--head .copyright");
+ expect(copyright.textContent).toContain(variant.agreement);
+ });
+
+ it(
+ variant.getInvolved
+ ? "invites the reader to get involved"
+ : "does not invite the reader to get involved",
+ () => {
+ const section = doc.getElementById("cg-get-involved");
+ expect(Boolean(section)).toBe(variant.getInvolved);
+ }
+ );
+
+ it("adds nothing of its own to the Status of This Document", () => {
+ const sotd = doc.getElementById("sotd");
+ // The header box and "Get involved" say all of this, where a reader
+ // looks for it. Repeating it here is two wordings to keep in step.
+ for (const phrase of [
+ "not a W3C Standard",
+ "not (yet) ready",
+ "Contributor License Agreement",
+ "beta-test",
+ ]) {
+ expect(sotd.textContent).withContext(phrase).not.toContain(phrase);
+ }
+ expect(sotd.querySelector('a[href="#usage-guidance"]')).toBeNull();
+ expect(sotd.querySelector('a[href="#cg-get-involved"]')).toBeNull();
+ // Exactly what the editors wrote, and nothing else:
+ // makeDefaultBody's sotd is a single paragraph reading "foo".
+ expect(sotd.querySelectorAll("p")).toHaveSize(1);
+ expect(sotd.textContent).toContain("foo");
+ });
+
+ it("names the incubating group, and is not a W3C publication", () => {
+ const head = doc.querySelector(".box--head");
+ expect(head.textContent).toContain("Incubation by:");
+ expect(doc.querySelector("img[alt='W3C']")).toBeNull();
+ // The maturity tag is appended to the same h1 the copyright is
+ // built from, so a clone taken too late would read "the Foo Draft
+ // Specification".
+ const copyright = doc.querySelector(".box--head .copyright");
+ expect(copyright.textContent).not.toContain(`${variant.tag} Spec`);
+ });
+
+ it("reports nothing", () => {
+ expect(defaultErrors(doc)).toHaveSize(0);
+ expect(headerErrors(doc)).toHaveSize(0);
+ expect(cgIdentityErrors(doc)).toHaveSize(0);
+ });
+ });
+ }
+ });
+
+ describe("an empty Status of This Document", () => {
+ it("is left empty, with only its heading", async () => {
+ const ops = cgOps();
+ ops.body = "";
+ const doc = await makeRSDoc(ops);
+ const sotd = doc.getElementById("sotd");
+ expect(sotd.querySelectorAll("p")).toHaveSize(0);
+ expect(sotd.querySelector("h2").textContent).toContain(
+ "Status of This Document"
+ );
+ });
+ });
+
+ describe("the foot sections", () => {
+ it("lists them in the table of contents, unnumbered", async () => {
+ const doc = await makeRSDoc(cgOps({ cgMaturity: "draft" }));
+ for (const id of ["cg-get-involved", "usage-guidance"]) {
+ const link = doc.querySelector(`#toc a[href="#${id}"]`);
+ expect(link).withContext(id).toBeTruthy();
+ // Boilerplate, not part of the spec's own sequence of sections.
+ expect(link.querySelector(".secno")).withContext(id).toBeNull();
+ }
+ });
+
+ it("leaves the usage guidance to the table of contents", async () => {
+ const doc = await makeRSDoc(cgOps({ cgMaturity: "draft" }));
+ // The header box used to link to it. The link went so that the box stays
+ // short; the section itself is still there, and still in the TOC.
+ // Scoped to the box--information-alt rather than the whole header box:
+ // the usage guidance section is itself a `.box--head`, and core/structure
+ // gives its heading a self-link to the very same fragment.
+ expect(
+ doc.querySelector('.box--information-alt a[href="#usage-guidance"]')
+ ).toBeNull();
+ expect(doc.getElementById("usage-guidance")).toBeTruthy();
+ });
+
+ it("repeats the snapshot notice as the usage guidance of a snapshot", async () => {
+ // A snapshot is archival: there is no collected guidance to show, so the
+ // section says what the document is and sends the reader to the one that
+ // does carry current guidance.
+ const doc = await makeRSDoc(
+ cgOps({ specStatus: "CG-SNAPSHOT", publishDate: "2025-05-30" })
+ );
+ const box = footNotice(doc, "box--information");
+ expect(box.querySelector("h3").textContent).toContain(
+ "This is a snapshot"
+ );
+ const text = norm(box);
+ expect(text).toContain(
+ "This document instance is archival and is not intended to change."
+ );
+ expect(text).toContain("It was published on 30 May 2025.");
+ expect(
+ box.querySelector(
+ `a[href="${INCUBATION}specs/scheduling-apis-20250530/"]`
+ )
+ ).toBeTruthy();
+ expect(text).toContain(
+ "Updated usage guidance is in the latest version."
+ );
+ // The address of that latest version is status data, so it is a region
+ // rather than something the generator claims to know.
+ const region = box.querySelector('[data-cg-region="living-spec"]');
+ expect(region.localName).toBe("li");
+ expect(region.querySelector("noscript")).toBeTruthy();
+ expect(
+ box.querySelector("time.dt-updated").getAttribute("datetime")
+ ).toBe("2025-05-30");
+ });
+
+ it("repeats the transferred notice as the usage guidance", async () => {
+ const doc = await makeRSDoc(
+ cgOps({ cgMaturity: "transferred", transferredTo: "WHATWG" })
+ );
+ const box = footNotice(doc, "box--information");
+ expect(box.querySelector("h3").textContent).toContain(
+ "This specification has been transferred"
+ );
+ const text = norm(box);
+ expect(text).toContain(
+ "Rather than use or reference this specification, please consult the guidance of the organization to which the specification has been transferred."
+ );
+ expect(text).toContain(
+ "WHATWG has taken up the work for standardization"
+ );
+ expect(box.querySelector("[data-cg-region]")).toBeNull();
+ });
+
+ it("repeats the unmaintained notice as the usage guidance", async () => {
+ const doc = await makeRSDoc(cgOps({ cgMaturity: "unmaintained" }));
+ // A warning box, as at the head: the same state, said the same way.
+ const box = footNotice(doc, "box--warning");
+ expect(box.querySelector("h3").textContent).toContain(
+ "This specification is no longer in development and is unmaintained"
+ );
+ const text = norm(box);
+ expect(text).toContain("Do not use or reference.");
+ expect(text).toContain(
+ "If these circumstances change in the future, we will review our guidance."
+ );
+ });
+
+ for (const { label, config, notice } of [
+ {
+ label: "a snapshot",
+ config: { specStatus: "CG-SNAPSHOT" },
+ notice: "box--information",
+ },
+ {
+ label: "a transferred specification",
+ config: { cgMaturity: "transferred", transferredTo: "WHATWG" },
+ notice: "box--information",
+ },
+ {
+ label: "an unmaintained specification",
+ config: { cgMaturity: "unmaintained" },
+ notice: "box--warning",
+ },
+ ]) {
+ it(`says the endorsement sentence once, at the head, for ${label}`, async () => {
+ // The foot repeats the notice so a reader who lands on the usage
+ // guidance reads it there. Repeating "not endorsed by W3C" with it
+ // would say it twice in one document.
+ const doc = await makeRSDoc(cgOps(config));
+ const box = footNotice(doc, notice);
+ expect(norm(box)).not.toContain("endorsed by W3C");
+ expect(norm(doc.querySelector(`.box--head > .${notice}`))).toContain(
+ "endorsed by W3C"
+ );
+ });
+ }
+
+ it("takes the join page from the group's own homepage", async () => {
+ const doc = await makeRSDoc(cgOps());
+ const join = doc.querySelector('#cg-join-group ~ dd a[href$="/join"]');
+ expect(join.getAttribute("href")).toBe(
+ "https://www.w3.org/community/wicg/join"
+ );
+ });
+
+ it("omits the join page for a joint publication", async () => {
+ const doc = await makeRSDoc(cgOps({ group: ["wicg", "maps4html"] }));
+ expect(doc.querySelector('a[href$="/join"]')).toBeNull();
+ });
+
+ it("links to Get involved from the header box of a draft", async () => {
+ const doc = await makeRSDoc(cgOps({ cgMaturity: "draft" }));
+ expect(
+ doc.querySelector('.box--information-alt a[href="#cg-get-involved"]')
+ ).toBeTruthy();
+ });
+ });
+
+ describe("the snapshots index", () => {
+ const snapshotsLink = doc =>
+ [...doc.querySelectorAll(".box--head a")].filter(a =>
+ a.textContent.includes("Snapshots of this specification")
+ );
+
+ it("derives the address from the short name", async () => {
+ const doc = await makeRSDoc(cgOps());
+ const [link] = snapshotsLink(doc);
+ expect(link.getAttribute("href")).toBe(
+ `${INCUBATION}specs/scheduling-apis/snapshots/`
+ );
+ });
+
+ it("escapes a short name that would change the URL's shape", async () => {
+ const doc = await makeRSDoc(cgOps({ shortName: "c#d" }));
+ const [link] = snapshotsLink(doc);
+ expect(link.getAttribute("href")).toBe(
+ `${INCUBATION}specs/c%23d/snapshots/`
+ );
+ });
+
+ it("drops the link when there is no index to point at", async () => {
+ // w3c/cg-identity has already reported the missing short name; an `href=""`
+ // would send the reader back to this document.
+ const doc = await makeRSDoc(cgOps({ shortName: undefined }));
+ expect(snapshotsLink(doc)).toHaveSize(0);
+ });
+ });
+
+ describe("a snapshot's own identity", () => {
+ const snapOps = (config = {}) =>
+ cgOps({
+ specStatus: "CG-SNAPSHOT",
+ publishDate: "2025-05-30",
+ ...config,
+ });
+
+ it("states when it was published, and where it lives", async () => {
+ const doc = await makeRSDoc(snapOps());
+ const notice = doc.querySelector(".box--head .box--information");
+ const time = notice.querySelector("time.dt-updated");
+ // Its own date and address are facts the generator knows; only the
+ // living specification's are fetched.
+ expect(time.getAttribute("datetime")).toBe("2025-05-30");
+ expect(notice.textContent).toContain("30 May 2025");
+ });
+
+ it("derives the address from the short name and the publication date", async () => {
+ const doc = await makeRSDoc(snapOps());
+ const url = `${INCUBATION}specs/scheduling-apis-20250530/`;
+ expect(doc.defaultView.respecConfig.thisVersion).toBe(url);
+ const notice = doc.querySelector(".box--head .box--information");
+ expect(notice.querySelector(`a[href="${url}"]`).textContent).toBe(url);
+ });
+
+ it("follows the publication date", async () => {
+ const doc = await makeRSDoc(snapOps({ publishDate: "2026-01-02" }));
+ expect(doc.defaultView.respecConfig.thisVersion).toBe(
+ `${INCUBATION}specs/scheduling-apis-20260102/`
+ );
+ });
+
+ it("lets an editor override it", async () => {
+ const url = "https://example.com/snapshots/2025-05-30/";
+ const doc = await makeRSDoc(snapOps({ thisVersion: url }));
+ expect(doc.defaultView.respecConfig.thisVersion).toBe(url);
+ const notice = doc.querySelector(".box--head .box--information");
+ expect(notice.querySelector(`a[href="${url}"]`)).toBeTruthy();
+ });
+
+ it("omits the address line when there is no short name to derive it from", async () => {
+ const doc = await makeRSDoc(snapOps({ shortName: undefined }));
+ const notice = doc.querySelector(".box--head .box--information");
+ expect(notice.textContent).not.toContain("The address of this snapshot");
+ });
+ });
+
+ describe("transferredTo", () => {
+ it("names and links the organization that took the work up", async () => {
+ const doc = await makeRSDoc(
+ cgOps({
+ cgMaturity: "transferred",
+ transferredTo: { name: "WHATWG", url: "https://whatwg.org/" },
+ })
+ );
+ const notice = doc.querySelector(".box--head .box--information");
+ const link = notice.querySelector('a[href="https://whatwg.org/"]');
+ expect(link.textContent).toBe("WHATWG");
+ expect(notice.textContent).toContain("has taken up the work");
+ });
+
+ it("accepts a plain name", async () => {
+ const doc = await makeRSDoc(
+ cgOps({ cgMaturity: "transferred", transferredTo: "WHATWG" })
+ );
+ const notice = doc.querySelector(".box--head .box--information");
+ expect(notice.textContent).toContain("WHATWG has taken up the work");
+ expect(defaultErrors(doc)).toHaveSize(0);
+ });
+
+ // Tests on transferred CG specs and its requirements
+ const UNUSABLE = [
+ ["it is missing", undefined],
+ ["it is empty", ""],
+ ["it is only whitespace", " "],
+ ["the object has no name", { url: "https://whatwg.org/" }],
+ ["the object's name is empty", { name: "", url: "https://whatwg.org/" }],
+ ];
+ for (const [label, transferredTo] of UNUSABLE) {
+ it(`errors when ${label}`, async () => {
+ const doc = await makeRSDoc(
+ cgOps({ cgMaturity: "transferred", transferredTo })
+ );
+ const errors = defaultErrors(doc);
+ expect(errors).toHaveSize(1);
+ expect(errors[0].message).toContain("transferredTo");
+
+ const notice = doc.querySelector(".box--head .box--information");
+ expect(notice.textContent).toContain(
+ "Another organization has taken up the work"
+ );
+ expect(
+ notice.querySelector('a[href="https://whatwg.org/"]')
+ ).toBeNull();
+ });
+ }
+
+ it("says nothing about it on a document that has not been transferred", async () => {
+ const doc = await makeRSDoc(
+ cgOps({ cgMaturity: "draft", transferredTo: undefined })
+ );
+ expect(defaultErrors(doc)).toHaveSize(0);
+ });
+ });
+
+ describe("CG-DRAFT", () => {
+ /** @type {Document} */
+ let doc;
+ beforeAll(async () => {
+ doc = await makeRSDoc(
+ makeStandardOps({ specStatus: "CG-DRAFT", group: "wicg" })
+ );
+ });
+
+ it("still gets the old header, untouched", () => {
+ expect(doc.querySelector(".head")).toBeTruthy();
+ expect(doc.querySelector(".box--head")).toBeNull();
+ expect(regionsOf(doc)).toEqual([]);
+ expect(doc.getElementById("cg-get-involved")).toBeNull();
+ expect(doc.getElementById("usage-guidance")).toBeNull();
+ expect(headerErrors(doc)).toHaveSize(0);
+ });
+
+ it("still gets the W3C TR assets", () => {
+ expect(
+ doc.querySelector(
+ `link[rel~="stylesheet"][href="https://www.w3.org/StyleSheets/TR/2021/cg-draft"]`
+ )
+ ).toBeTruthy();
+ expect(doc.querySelector(`link[href^="${BASE}"]`)).toBeNull();
+ });
+ });
+});