Repository navigation
feat: new CG specification profiles #5482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63d29cc
4e000a1
830f6c5
b498fbe
f8efc5f
9c1bde9
369adb5
08aa006
aa0fd30
8a4dce8
ce72847
927b40e
3c11468
7a899e0
b6806b2
1e9db73
317c745
45fa2f6
4efe6d1
b2dc889
3c3b92f
67b919e
8c64bf0
3e24e94
fc42f44
50c9c1e
c751bda
3f96c4f
30c9a50
b91141d
e334ac5
1e89490
05fc0b7
9ed28ab
cdd4922
48c9bc0
2fb924d
bfff152
de8086d
b6d55ea
033025a
e988c38
8445d87
900be9e
5737206
fe41c6d
944c769
b255f6c
ccf666e
59197cc
c085bae
aad01e2
b2e6b6f
a6fd21c
ddc7c62
bceb3b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Prioritized Task Scheduling</title> | ||
| <script src="../profiles/w3c.js" type="module" class="remove"></script> | ||
| <script class="remove"> | ||
| // All config options at https://respec.org/docs/ | ||
| var respecConfig = { | ||
| // A living specification in the Community Group redesign. Use | ||
| // "CG-SNAPSHOT" for an archival copy of one. | ||
| specStatus: "CG-LIVING", | ||
| // "draft" (default), "transferred" or "unmaintained". | ||
| cgMaturity: "draft", | ||
| // Required: the collected status metadata is looked up by short name. | ||
| shortName: "scheduling-apis", | ||
| group: "wicg", | ||
| github: "WICG/scheduling-apis", | ||
| // Required if cgMaturity: "transferred" | ||
| // transferredTo: { name: "ACME", url: "https://acme.org/" }, | ||
| editors: [ | ||
| { | ||
| name: "Your Name", | ||
| url: "https://your-site.com", | ||
| }, | ||
| ], | ||
| }; | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <section id="abstract"> | ||
| <p> | ||
| This specification defines APIs for scheduling and controlling | ||
| prioritized tasks. | ||
| </p> | ||
| </section> | ||
| <section id="sotd"></section> | ||
| <section class="informative"> | ||
| <h2>Introduction</h2> | ||
| <p>Some informative introductory text.</p> | ||
| </section> | ||
| <section> | ||
| <h2>Start your spec!</h2> | ||
| <p>Replace this with the specification's normative content.</p> | ||
| </section> | ||
| <section id="conformance"> | ||
| <p> | ||
| This is required for specifications that contain normative material. | ||
| </p> | ||
| </section> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: sometimes we are returning .href and other times, a URL object... make sure it's consistent and with intent.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, the return type is consistent across the different functions for the CG-related code at least. |
||
| } | ||
|
|
||
| /** | ||
| * 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: why are these dropped?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I see now... I wonder if we should prevent the original ones from being added in the first place in this mode. |
||
| */ | ||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems fragile... how about a making this an option for createStyleLink()? Also, this seems duplicative. Don't we have a similar function in utils? |
||
| ? html`<link | ||
| rel="stylesheet" | ||
| class="dark-mode" | ||
| media="(prefers-color-scheme: dark)" | ||
| href="${href}" | ||
| />` | ||
| : html`<link rel="stylesheet" href="${href}" />`; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} path | ||
| * @param {object} [options] | ||
| * @param {boolean} [options.defer] | ||
| */ | ||
| function createScript(path, { defer = false } = {}) { | ||
| return html`<script | ||
| src="${cgAssetUrl(path)}" | ||
| defer=${defer} | ||
| async=${false} | ||
| ></script>`; | ||
| } | ||
|
|
||
| /** | ||
| * 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 `<html>` 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 } | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // @ts-check | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please rename this file? We use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed into |
||
| /** | ||
| * 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`<meta name="cg-spec-type" content="${type}" />`, | ||
| html`<meta name="cg-spec-shortname" content="${conf.shortName}" />`, | ||
| html`<meta name="cg-spec-maturity" content="${conf.cgMaturity}" />` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Questions: has
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, |
||
| ); | ||
|
|
||
| // 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(); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we should add this example at all to be honest.