mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
refactor(site): prune component CSS variants and split shell from route stylesheets (#62990)
This commit is contained in:
@@ -64,26 +64,26 @@ console.log(
|
||||
// Each page's budget in kB, gzipped: what it was when last measured, plus a kB of room. Lower a
|
||||
// budget when a page gets lighter; a page without one fails until it has one.
|
||||
const budgets: Record<string, number> = {
|
||||
"[...404].tsx": 104.1,
|
||||
"brand/index.tsx": 104.5,
|
||||
"changelog/[tag].tsx": 99.2,
|
||||
"changelog/index.tsx": 98.4,
|
||||
"desktop.tsx": 127.9,
|
||||
"devices.tsx": 56.8,
|
||||
"product/browse.tsx": 104.2,
|
||||
"font/index.tsx": 120.1,
|
||||
"ide.tsx": 127.9,
|
||||
"index.tsx": 114.9,
|
||||
"legal/index.tsx": 148.3,
|
||||
"legal/privacy-policy/index.tsx": 137.8,
|
||||
"legal/terms-of-service/index.tsx": 133.2,
|
||||
"mini.tsx": 127.9,
|
||||
"mobile.tsx": 127.9,
|
||||
"press/index.tsx": 113.2,
|
||||
"product/index.tsx": 112.7,
|
||||
"sdk.tsx": 127.9,
|
||||
"terminal.tsx": 127.9,
|
||||
"video-editor/index.tsx": 55.2,
|
||||
"[...404].tsx": 103.8,
|
||||
"brand/index.tsx": 104.4,
|
||||
"changelog/[tag].tsx": 99,
|
||||
"changelog/index.tsx": 98.2,
|
||||
"desktop.tsx": 127.5,
|
||||
"devices.tsx": 56.6,
|
||||
"product/browse.tsx": 104,
|
||||
"font/index.tsx": 119.9,
|
||||
"ide.tsx": 127.5,
|
||||
"index.tsx": 114.7,
|
||||
"legal/index.tsx": 148.1,
|
||||
"legal/privacy-policy/index.tsx": 137.7,
|
||||
"legal/terms-of-service/index.tsx": 133,
|
||||
"mini.tsx": 127.5,
|
||||
"mobile.tsx": 127.5,
|
||||
"press/index.tsx": 113,
|
||||
"product/index.tsx": 112.5,
|
||||
"sdk.tsx": 127.5,
|
||||
"terminal.tsx": 127.5,
|
||||
"video-editor/index.tsx": 55,
|
||||
}
|
||||
type Chunk = { file: string; imports?: string[] }
|
||||
const manifest: Record<string, Chunk> = await Bun.file(path.join(root, ".vite/manifest.json")).json()
|
||||
|
||||
@@ -4,17 +4,39 @@
|
||||
// (--lightningcss-light/--lightningcss-dark variables) freezes every token at the root's theme, so
|
||||
// the production page silently differs from the development server. vite.config.ts's cssTarget
|
||||
// keeps light-dark() native; this guards against that target being lowered again.
|
||||
//
|
||||
// It also fails when a stylesheet outgrows its budget (gzipped): the shell's, which every page links
|
||||
// and holds up its first paint for, and each of the others, a group of pages' or one that loads on
|
||||
// demand (script/stylesheet-groups.ts).
|
||||
// Run after `vite build`, optionally with the output directory: `bun script/check-css-output.ts .output`.
|
||||
import path from "node:path"
|
||||
import { Glob } from "bun"
|
||||
|
||||
const root = path.resolve(process.argv[2] ?? path.join(import.meta.dir, "..", ".output"), "public")
|
||||
const budgets = { shell: 27.5 * 1024, other: 10.5 * 1024 }
|
||||
const lowered: string[] = []
|
||||
const over: string[] = []
|
||||
const shells: string[] = []
|
||||
for await (const file of new Glob("**/*.css").scan(root)) {
|
||||
if ((await Bun.file(path.join(root, file)).text()).includes("--lightningcss-")) lowered.push(file)
|
||||
const css = await Bun.file(path.join(root, file)).text()
|
||||
if (css.includes("--lightningcss-")) lowered.push(file)
|
||||
if (!file.startsWith("_build/assets/")) continue
|
||||
const shell = path.basename(file).startsWith("shell-")
|
||||
if (shell) shells.push(file)
|
||||
const size = Bun.gzipSync(css, { level: 9 }).length
|
||||
const budget = shell ? budgets.shell : budgets.other
|
||||
if (size > budget) over.push(`${file} ${(size / 1024).toFixed(1)} kB (budget ${(budget / 1024).toFixed(1)} kB)`)
|
||||
}
|
||||
if (lowered.length > 0) {
|
||||
console.error(`light-dark() was lowered (--lightningcss-* variables) in:\n${lowered.join("\n")}`)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log("Production CSS keeps light-dark() native.")
|
||||
if (shells.length !== 1) {
|
||||
console.error(`expected one shell stylesheet, found ${shells.length}: ${shells.join(", ")}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (over.length > 0) {
|
||||
console.error(`stylesheets over budget (gzipped):\n${over.join("\n")}`)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log("Production CSS keeps light-dark() native, and each stylesheet is within its budget.")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Production CSS plugins shared by the site's build (vite.config.ts) and the docs' own build
|
||||
// (src/docs/script/build.ts), so both ship the same stylesheets for the same settings.
|
||||
import { readdirSync, readFileSync } from "node:fs"
|
||||
import path from "node:path"
|
||||
import type { PluginOption } from "vite"
|
||||
import variants from "../src/component/site/css-variants.json"
|
||||
|
||||
@@ -17,50 +19,38 @@ export function devOnlyCss(): PluginOption {
|
||||
}
|
||||
|
||||
/**
|
||||
* Production only: Settings and Design mode are development tools, so the site root's settings
|
||||
* attributes always carry the default settings' values (src/component/site/css-variants.json). This
|
||||
* drops, from the production CSS, each selector that needs another value of one of them, and each
|
||||
* rule left with none; the development server keeps every variant for Design mode. Only attributes
|
||||
* outside parentheses count (an attribute inside :not(), :is() or :has() keeps its selector).
|
||||
* Production only: Settings and Design mode are development tools, so the settings attributes
|
||||
* always carry the default settings' values (src/component/site/css-variants.json): on the site root,
|
||||
* and on the elements the pre-paint rules name (`scoped`, matched by their attribute values, such as
|
||||
* `[data-component="products"]`). This drops, from the production CSS, each selector that needs
|
||||
* another value of one of them, nested selectors included (read with their parents'), each rule left
|
||||
* with none, and then the at-rules left empty and the @keyframes nothing names any more; the
|
||||
* development server keeps every variant for Design mode. Only attributes outside parentheses count,
|
||||
* and an :is() or :where() none of whose selectors can match (an attribute inside :not() or :has()
|
||||
* keeps its selector).
|
||||
*/
|
||||
export function cssVariantsForProduction(): PluginOption {
|
||||
const fixed = variants as Record<string, string | null>
|
||||
const impossible = (selector: string) => {
|
||||
let depth = 0
|
||||
let top = ""
|
||||
for (const char of selector) {
|
||||
if (char === "(") depth++
|
||||
if (depth === 0) top += char
|
||||
if (char === ")") depth--
|
||||
}
|
||||
return [...top.matchAll(/\[(data-[\w-]+)(~?=)["']?([^"'\]]*)["']?\]/g)].some((match) => {
|
||||
if (!(match[1] in fixed)) return false
|
||||
const value = fixed[match[1]]
|
||||
if (value === null) return true
|
||||
return match[2] === "~=" ? !value.split(" ").includes(match[3]) : value !== match[3]
|
||||
const root = variants.root as Record<string, string | null>
|
||||
const scoped = (variants.scoped as [string, string, string | null][]).map(([element, name, value]) => ({
|
||||
element: attributes(element).map((attribute) => attribute.join("")),
|
||||
name,
|
||||
value,
|
||||
}))
|
||||
const impossible = (selector: string): boolean =>
|
||||
alternatives(selector).some((list) => split(list).every((each) => impossible(each))) ||
|
||||
compounds(selector).some((compound) => {
|
||||
const found = attributes(compound)
|
||||
const keys = new Set(found.map((attribute) => attribute.join("")))
|
||||
return found.some(([name, operator, value]) => {
|
||||
if (name in root) return !matches(root[name], operator, value)
|
||||
return scoped.some(
|
||||
(entry) =>
|
||||
entry.name === name &&
|
||||
entry.element.every((key) => keys.has(key)) &&
|
||||
!matches(entry.value, operator, value),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
const split = (selector: string) => {
|
||||
const parts: string[] = []
|
||||
let depth = 0
|
||||
let quote = ""
|
||||
let start = 0
|
||||
for (let i = 0; i < selector.length; i++) {
|
||||
const char = selector[i]
|
||||
if (quote) {
|
||||
if (char === quote) quote = ""
|
||||
continue
|
||||
}
|
||||
if (char === '"' || char === "'") quote = char
|
||||
else if (char === "(" || char === "[") depth++
|
||||
else if (char === ")" || char === "]") depth--
|
||||
else if (char === "," && depth === 0) {
|
||||
parts.push(selector.slice(start, i))
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
return [...parts, selector.slice(start)]
|
||||
}
|
||||
return {
|
||||
name: "css-variants-for-production",
|
||||
apply: "build",
|
||||
@@ -70,12 +60,37 @@ export function cssVariantsForProduction(): PluginOption {
|
||||
plugins: [
|
||||
{
|
||||
postcssPlugin: "css-variants-for-production",
|
||||
Rule(rule: { selector: string; remove(): void }) {
|
||||
const selectors = split(rule.selector)
|
||||
const kept = selectors.filter((selector) => !impossible(selector))
|
||||
if (kept.length === selectors.length) return
|
||||
if (!kept.length) return rule.remove()
|
||||
rule.selector = kept.join(",")
|
||||
OnceExit(css: Root) {
|
||||
// Each rule's selectors as written out in full, so a nested one is read with its parents'.
|
||||
const full = new WeakMap<Node, string[]>()
|
||||
css.walkRules((rule) => {
|
||||
if (/keyframes$/i.test(rule.parent?.name ?? "")) return
|
||||
const parent = parentRule(rule)
|
||||
const parents = (parent && full.get(parent)) ?? [""]
|
||||
const selectors = split(rule.selector ?? "").map((selector) => ({
|
||||
selector,
|
||||
full: parents.map((parent) => nest(parent, selector.trim())).filter((each) => !impossible(each)),
|
||||
}))
|
||||
const kept = selectors.filter((selector) => selector.full.length)
|
||||
full.set(
|
||||
rule,
|
||||
kept.flatMap((selector) => selector.full),
|
||||
)
|
||||
if (!kept.length) return rule.remove()
|
||||
if (kept.length < selectors.length)
|
||||
rule.selector = kept.map((selector) => selector.selector).join(",")
|
||||
})
|
||||
removeEmpty(css)
|
||||
// A @keyframes no declaration names any more (an animation, or a custom property one
|
||||
// reads), unless another file names it: a stylesheet built on its own, or a script.
|
||||
const named = new Set<string>()
|
||||
css.walkDecls((decl) => decl.value?.match(/[\w-]+/g)?.forEach((name) => named.add(name)))
|
||||
css.walkAtRules(/^(-webkit-)?keyframes$/i, (rule) => {
|
||||
const name = (rule.params ?? "").trim().replace(/^["']|["']$/g, "")
|
||||
if (named.has(name) || namedElsewhere(name, rule.source?.input?.file)) return
|
||||
rule.remove()
|
||||
})
|
||||
removeEmpty(css)
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -84,3 +99,151 @@ export function cssVariantsForProduction(): PluginOption {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// The PostCSS nodes this reads (the site doesn't depend on PostCSS itself; Vite runs it).
|
||||
type Node = {
|
||||
type: string
|
||||
name?: string
|
||||
params?: string
|
||||
selector?: string
|
||||
value?: string
|
||||
nodes?: Node[]
|
||||
parent?: Node
|
||||
source?: { input?: { file?: string } }
|
||||
remove(): void
|
||||
}
|
||||
type Root = Node & {
|
||||
walk(callback: (node: Node) => void): void
|
||||
walkRules(callback: (rule: Node) => void): void
|
||||
walkDecls(callback: (decl: Node) => void): void
|
||||
walkAtRules(filter: RegExp, callback: (rule: Node) => void): void
|
||||
}
|
||||
|
||||
/** The nearest rule a rule is nested in (through at-rules such as @media), if any. */
|
||||
function parentRule(rule: Node) {
|
||||
let node = rule.parent
|
||||
while (node && node.type === "atrule") node = node.parent
|
||||
return node?.type === "rule" ? node : undefined
|
||||
}
|
||||
|
||||
/** A nested selector written out against one of its parent's (CSS nesting: `&`, or a descendant). */
|
||||
function nest(parent: string, selector: string) {
|
||||
if (!parent) return selector
|
||||
return selector.includes("&") ? selector.replaceAll("&", parent) : `${parent} ${selector}`
|
||||
}
|
||||
|
||||
/** Removes the rules and at-rules (other than @font-face and the like, which hold declarations) left empty. */
|
||||
function removeEmpty(css: Root) {
|
||||
const empty: Node[] = []
|
||||
css.walk((node) => {
|
||||
if ((node.type === "rule" || node.type === "atrule") && node.nodes && node.nodes.length === 0) empty.push(node)
|
||||
})
|
||||
if (!empty.length) return
|
||||
empty.forEach((node) => node.remove())
|
||||
removeEmpty(css)
|
||||
}
|
||||
|
||||
/** A selector list's selectors. */
|
||||
function split(selector: string) {
|
||||
const parts: string[] = []
|
||||
let depth = 0
|
||||
let quote = ""
|
||||
let start = 0
|
||||
for (let i = 0; i < selector.length; i++) {
|
||||
const char = selector[i]
|
||||
if (quote) {
|
||||
if (char === quote) quote = ""
|
||||
continue
|
||||
}
|
||||
if (char === '"' || char === "'") quote = char
|
||||
else if (char === "(" || char === "[") depth++
|
||||
else if (char === ")" || char === "]") depth--
|
||||
else if (char === "," && depth === 0) {
|
||||
parts.push(selector.slice(start, i))
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
return [...parts, selector.slice(start)]
|
||||
}
|
||||
|
||||
/** A selector's compound selectors (between its combinators), without what's inside parentheses. */
|
||||
function compounds(selector: string) {
|
||||
const list = [""]
|
||||
let depth = 0
|
||||
let bracket = false
|
||||
let quote = ""
|
||||
for (const char of selector) {
|
||||
if (quote) {
|
||||
if (char === quote) quote = ""
|
||||
if (!depth) list[list.length - 1] += char
|
||||
continue
|
||||
}
|
||||
if (char === "(") depth++
|
||||
if (char === ")") depth--
|
||||
if (depth || char === ")") continue
|
||||
if (char === '"' || char === "'") quote = char
|
||||
if (char === "[") bracket = true
|
||||
if (char === "]") bracket = false
|
||||
if (!bracket && /[\s>+~]/.test(char)) {
|
||||
if (list.at(-1)) list.push("")
|
||||
continue
|
||||
}
|
||||
list[list.length - 1] += char
|
||||
}
|
||||
return list.filter(Boolean)
|
||||
}
|
||||
|
||||
/** The selector lists of a selector's own :is() and :where(), which match when one of theirs does. */
|
||||
function alternatives(selector: string) {
|
||||
const depth = (text: string) => [...text].reduce((open, char) => open + (char === "(" ? 1 : char === ")" ? -1 : 0), 0)
|
||||
return [...selector.matchAll(/:(?:is|where)\(/g)]
|
||||
.filter((match) => depth(selector.slice(0, match.index)) === 0)
|
||||
.map((match) => {
|
||||
let open = 1
|
||||
let end = match.index + match[0].length
|
||||
for (; end < selector.length && open; end++) {
|
||||
if (selector[end] === "(") open++
|
||||
if (selector[end] === ")") open--
|
||||
}
|
||||
return selector.slice(match.index + match[0].length, end - 1)
|
||||
})
|
||||
}
|
||||
|
||||
/** A compound selector's attribute selectors, as name, operator and value (a case-insensitive one is left out). */
|
||||
function attributes(compound: string) {
|
||||
return [...compound.matchAll(/\[\s*([\w-]+)\s*(?:([~|^$*]?=)\s*(?:"([^"]*)"|'([^']*)'|([^\s\]]*)))?\s*([is])?\s*\]/g)]
|
||||
.filter((match) => match[6] !== "i")
|
||||
.map((match) => [match[1], match[2] ?? "", match[3] ?? match[4] ?? match[5] ?? ""] as const)
|
||||
}
|
||||
|
||||
/** Whether an attribute with this production value (null: absent) matches an attribute selector. */
|
||||
function matches(fixed: string | null, operator: string, value: string) {
|
||||
if (fixed === null) return false
|
||||
if (operator === "") return true
|
||||
if (operator === "=") return fixed === value
|
||||
if (operator === "~=") return fixed.split(" ").includes(value)
|
||||
if (operator === "|=") return fixed === value || fixed.startsWith(`${value}-`)
|
||||
if (operator === "^=") return fixed.startsWith(value)
|
||||
if (operator === "$=") return fixed.endsWith(value)
|
||||
return fixed.includes(value)
|
||||
}
|
||||
|
||||
// The site's and its packages' sources, each file's words, read once: a @keyframes one of them names
|
||||
// stays, as a stylesheet built on its own or a script may use it.
|
||||
const sources = ["../src", "../../../packages/ui/src", "../../../packages/nav-menus/src"].map((dir) =>
|
||||
path.resolve(import.meta.dirname, dir),
|
||||
)
|
||||
let words: Map<string, Set<string>> | undefined
|
||||
function namedElsewhere(name: string, file: string | undefined) {
|
||||
words ??= new Map(
|
||||
sources.flatMap((dir) =>
|
||||
readdirSync(dir, { recursive: true, encoding: "utf8" })
|
||||
.filter((entry) => /\.(css|tsx?|mdx)$/.test(entry))
|
||||
.map((entry) => {
|
||||
const text = readFileSync(path.join(dir, entry), "utf8")
|
||||
return [path.join(dir, entry), new Set(text.match(/[\w-]+/g))] as const
|
||||
}),
|
||||
),
|
||||
)
|
||||
return [...words].some(([source, names]) => source !== file && names.has(name))
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
// Writes src/component/site/css-variants.json: each settings attribute and the one value production
|
||||
// renders for it (the default settings; null when it is left off). script/css-variants-plugin.ts drops, from the
|
||||
// production CSS only, every rule that needs another value. Run after changing a setting's default
|
||||
// or adding a settings attribute; test/css-variants.test.ts fails while the file is out of date.
|
||||
// renders for it (the default settings; null when it is left off), on the site root and on the
|
||||
// elements the pre-paint rules name. script/css-variants-plugin.ts drops, from the production CSS
|
||||
// only, every rule that needs another value. Run after changing a setting's default or adding a
|
||||
// settings attribute; test/css-variants.test.ts fails while the file is out of date.
|
||||
import path from "node:path"
|
||||
import { cssVariants } from "../src/component/site/css-variants"
|
||||
|
||||
const file = path.join(import.meta.dir, "../src/component/site/css-variants.json")
|
||||
await Bun.write(file, JSON.stringify(cssVariants(), null, 2) + "\n")
|
||||
console.log(`css-variants.json: ${Object.keys(cssVariants()).length} attributes`)
|
||||
const variants = cssVariants()
|
||||
// One element's attribute a line.
|
||||
await Bun.write(
|
||||
file,
|
||||
JSON.stringify(variants, null, 2).replace(/\[\n\s+(.+),\n\s+(.+),\n\s+(.+)\n\s+\]/g, "[$1, $2, $3]") + "\n",
|
||||
)
|
||||
console.log(
|
||||
`css-variants.json: ${Object.keys(variants.root).length} root attributes, ${variants.scoped.length} on other elements`,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { PluginOption } from "vite"
|
||||
|
||||
// Pages that share a layout share a stylesheet: the product pages with the changelog (both show
|
||||
// release notes), and otherwise each section of the site (the route's first path segment).
|
||||
const productPages = /^(product|desktop|terminal|mobile|sdk|ide|mini|changelog)(\/|$)/
|
||||
const shell = /[\\/]src[\\/](app|component[\\/]site[\\/]site)\.tsx$/
|
||||
|
||||
/**
|
||||
* Production only: every page links two stylesheets, the shell's (`shell-<hash>.css`: the site's
|
||||
* frame, its fonts and every stylesheet more than one group of pages uses) and its own group's
|
||||
* (`home-`, `product-`, `legal-<hash>.css`, …). Both are content-hashed files that browsers keep for
|
||||
* a year, so a visitor downloads the shell once and each group the first time they open one of its
|
||||
* pages, whichever page that is. Vite splits stylesheets by JavaScript chunk, so this names a chunk
|
||||
* of stylesheets for each: the stylesheets a page's code imports, and none that load on demand
|
||||
* (search, the Markdown view, the Hex pop-up), which stay with their own code. Chunks of stylesheets
|
||||
* alone leave no JavaScript (Vite's pure CSS chunks), and Vite's loader adds a group's stylesheet the
|
||||
* first time the app moves to one of its pages.
|
||||
*/
|
||||
export function stylesheetGroups(): PluginOption {
|
||||
return {
|
||||
name: "stylesheet-groups",
|
||||
apply: "build",
|
||||
configEnvironment: (name) => {
|
||||
if (name !== "client") return
|
||||
return {
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
output: {
|
||||
codeSplitting: {
|
||||
groups: [
|
||||
{
|
||||
name: (id, context) => group(id, (module) => context.getModuleInfo(module)),
|
||||
test: /\.css$/,
|
||||
// Ahead of vite.config.ts's "common" group, which takes along the modules its small
|
||||
// shared ones import, so it would otherwise take stylesheets too (the orb's, the sheet's).
|
||||
priority: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** The group a stylesheet goes in: the shell's, a group of pages', or none (it loads on demand). */
|
||||
function group(id: string, info: (id: string) => { importers: string[] } | null) {
|
||||
const groups = new Set<string>()
|
||||
const seen = new Set<string>()
|
||||
// Up the static imports only, to the shell and the page routes.
|
||||
const visit = (module: string) => {
|
||||
if (seen.has(module)) return
|
||||
seen.add(module)
|
||||
const file = module.split("?")[0]
|
||||
if (shell.test(file)) return groups.add("shell")
|
||||
const route = file.match(/[\\/]src[\\/]routes[\\/](.+)\.tsx$/)?.[1]
|
||||
if (route) return groups.add(routeGroup(route.replaceAll("\\", "/")))
|
||||
info(module)?.importers.forEach(visit)
|
||||
}
|
||||
visit(id)
|
||||
if (groups.size === 0) return null
|
||||
return groups.size === 1 ? [...groups][0] : "shell"
|
||||
}
|
||||
|
||||
function routeGroup(route: string) {
|
||||
if (productPages.test(route)) return "product"
|
||||
if (route === "index") return "home"
|
||||
if (route === "[...404]") return "not-found"
|
||||
return route.split("/")[0]
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { isServer } from "solid-js/web"
|
||||
import { Favicon } from "@opencode/ui/favicon"
|
||||
import { Font } from "@opencode/ui/font"
|
||||
import "./style/ibm-plex-mono.dev.css"
|
||||
import "./style/fonts.css"
|
||||
import "./app.css"
|
||||
import { LanguageProvider } from "~/context/language"
|
||||
import { I18nProvider, useI18n } from "~/context/i18n"
|
||||
@@ -18,7 +19,6 @@ import { viewportContent } from "~/lib/viewport"
|
||||
import { quietPreloads, setNavigating } from "~/lib/route-preloads"
|
||||
// Before the router, so its popstate listener comes first.
|
||||
import "~/component/site/popstate"
|
||||
import { monoFontFaces } from "~/component/site/mono-fonts"
|
||||
|
||||
// Pages that set their own og:image.
|
||||
const shareImagePages = [
|
||||
@@ -111,9 +111,6 @@ export default function App() {
|
||||
<I18nProvider>
|
||||
<HeadMetaProvider>
|
||||
<AppMeta />
|
||||
{/* OpenTUI Mono for every page, with or without the site shell (--font-mono and the
|
||||
token stack name it). A plain style element, which hydration keeps. */}
|
||||
<style innerHTML={monoFontFaces} />
|
||||
<Suspense>{props.children}</Suspense>
|
||||
</HeadMetaProvider>
|
||||
</I18nProvider>
|
||||
|
||||
@@ -71,7 +71,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="subhead"] {
|
||||
/* Outranks the contents rail's margin for headings (on-this-page.css), which the shell brings to every page. */
|
||||
[data-slot="subhead"][id] {
|
||||
scroll-margin-top: var(--content-top);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,78 @@
|
||||
{
|
||||
"data-spacer": "line",
|
||||
"data-hero-install": "off",
|
||||
"data-home-announcement": "off",
|
||||
"data-logo": "icon",
|
||||
"data-selection": null,
|
||||
"data-blue": null,
|
||||
"data-dark-blue": "6b8fff",
|
||||
"data-logo-size": "20×25",
|
||||
"data-menu-active": "bar",
|
||||
"data-menu-color": "grey",
|
||||
"data-button-hover": "blue",
|
||||
"data-product-button": null,
|
||||
"data-product-badges": null,
|
||||
"data-menu-align": "edge",
|
||||
"data-wide-align": null,
|
||||
"data-nav-numbers": "1",
|
||||
"data-docs-nav": "split",
|
||||
"data-section-menu": "list",
|
||||
"data-docs-variants": "typography-4 lists-3 blockquote-2 callout-3 tabs-6 code-6 codeTitle-6 codeLines-6 codeDiff-6 terminal-6 fileTree-6 steps-2 cards-3 tables-5 badges-4 details-2 media-2 api-7 config-6 cli-6 pagination-4 breadcrumbs-3 search-4 switchers-2 editLink-4 feedback-5 inlineCode-6",
|
||||
"data-status-bars": "4",
|
||||
"data-logo-menu-hover": "blue",
|
||||
"data-light-bg": "fbfbfb",
|
||||
"data-sidebar": "column",
|
||||
"data-console-height": "compact",
|
||||
"data-console-label": "left",
|
||||
"data-console-layout": "block"
|
||||
"root": {
|
||||
"data-spacer": "line",
|
||||
"data-hero-install": "off",
|
||||
"data-home-announcement": "off",
|
||||
"data-logo": "icon",
|
||||
"data-selection": null,
|
||||
"data-blue": null,
|
||||
"data-dark-blue": "6b8fff",
|
||||
"data-logo-size": "20×25",
|
||||
"data-menu-active": "bar",
|
||||
"data-menu-color": "grey",
|
||||
"data-button-hover": "blue",
|
||||
"data-product-button": null,
|
||||
"data-product-badges": null,
|
||||
"data-menu-align": "edge",
|
||||
"data-wide-align": null,
|
||||
"data-nav-numbers": "1",
|
||||
"data-docs-nav": "split",
|
||||
"data-section-menu": "list",
|
||||
"data-docs-variants": "typography-4 lists-3 blockquote-2 callout-3 tabs-6 code-6 codeTitle-6 codeLines-6 codeDiff-6 terminal-6 fileTree-6 steps-2 cards-3 tables-5 badges-4 details-2 media-2 api-7 config-6 cli-6 pagination-4 breadcrumbs-3 search-4 switchers-2 editLink-4 feedback-5 inlineCode-6",
|
||||
"data-status-bars": "4",
|
||||
"data-logo-menu-hover": "blue",
|
||||
"data-light-bg": "fbfbfb",
|
||||
"data-sidebar": "column",
|
||||
"data-console-height": "compact",
|
||||
"data-console-label": "left",
|
||||
"data-console-layout": "block"
|
||||
},
|
||||
"scoped": [
|
||||
["[data-slot=\"logo\"]", "data-variant", "icon"],
|
||||
["[data-component=\"nav\"]", "data-variant", "index"],
|
||||
["[data-component=\"hero\"][data-design~=\"hero\"]", "data-variant", "three-up"],
|
||||
["[data-section=\"openSource\"]", "data-oss-variant", "current"],
|
||||
["[data-component=\"announcement\"]", "data-style", "text"],
|
||||
["[data-component=\"announcement-banner\"]", "data-label", "badge"],
|
||||
["[data-component=\"provider-logos\"]", "data-variant", "none"],
|
||||
["[data-section=\"getStarted\"]", "data-style", "steps"],
|
||||
["[data-section=\"what\"]", "data-phone-features", "accordion"],
|
||||
["[data-section=\"byos\"]", "data-style", "grid"],
|
||||
["[data-component=\"hero-install\"][data-mode=\"row\"]", "data-style", "inline"],
|
||||
["[data-component=\"hero\"][data-design~=\"hero\"]", "data-title-size", "fitted"],
|
||||
["[data-component=\"page-title\"]", "data-sticky", null],
|
||||
["[data-component=\"docs-version-notice\"]", "data-variant", "frosted top"],
|
||||
["[data-component=\"products\"]", "data-tone", "color"],
|
||||
["[data-component=\"badges\"]", "data-style", "sans"],
|
||||
["[data-component=\"badges\"]", "data-layout", "tabs"],
|
||||
["[data-component=\"badges\"]", "data-tab-style", "underline"],
|
||||
["[data-component=\"products\"]", "data-card-info", "stacked"],
|
||||
["[data-component=\"products\"]", "data-phone-content", "overlay"],
|
||||
["[data-component=\"products-skeleton\"]", "data-phone-content", "overlay"],
|
||||
["[data-component=\"tools\"]", "data-grid", "outline"],
|
||||
["[data-component=\"product-features\"]", "data-columns", "4"],
|
||||
["[data-component=\"companions\"]", "data-style", "outline"],
|
||||
["[data-component=\"changelog-timeline\"]", "data-sticky", ""],
|
||||
["[data-component=\"changelog-timeline\"]", "data-marker", "active"],
|
||||
["[data-component=\"changelog-timeline\"]", "data-title-size", "26-500"],
|
||||
["[data-component=\"wordmark\"]", "data-hidden", null],
|
||||
["[data-component=\"wordmark\"]", "data-entrance", ""],
|
||||
["[data-slot=\"logo\"]", "data-settling", null],
|
||||
["[data-component=\"nav\"]", "data-settling", null],
|
||||
["[data-component=\"logo-wall\"]", "data-settling", null],
|
||||
["[data-slot=\"track\"]", "data-settling", null],
|
||||
["[data-component=\"tools\"]", "data-settling", null],
|
||||
["[data-component=\"stats\"]", "data-settling", null],
|
||||
["[data-component=\"site-footer\"]", "data-settling", null],
|
||||
["[data-slot=\"code-gallery\"]", "data-slot", null],
|
||||
["[data-slot=\"gallery-item\"]", "data-slot", null],
|
||||
["[data-slot=\"gallery-options\"]", "data-slot", null],
|
||||
["[data-slot=\"gallery-steps\"]", "data-slot", null],
|
||||
["[data-slot=\"gallery-table\"]", "data-slot", null],
|
||||
["[data-slot=\"blend-plain\"]", "data-slot", null],
|
||||
["[data-blend=\"a\"]", "data-blend", null],
|
||||
["[data-blend=\"b\"]", "data-blend", null],
|
||||
["[data-blend=\"c\"]", "data-blend", null],
|
||||
["[data-blend=\"d\"]", "data-blend", null]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,18 +1,38 @@
|
||||
import { defaultRootAttributes } from "./preload-settings"
|
||||
import { defaultRootAttributes, defaultScopedAttributes } from "./preload-settings"
|
||||
import { siteSettingsDefaults } from "./settings"
|
||||
|
||||
// Settings attributes whose value in production is fixed by the default settings. Left out: data-banner
|
||||
// (the dismissable banner sets it at runtime) and data-popover (the theme switcher's popover state).
|
||||
const runtime = new Set(["data-banner", "data-popover"])
|
||||
|
||||
/** Each settings attribute and its production value; script/css-variants.ts writes it to JSON. */
|
||||
/**
|
||||
* Each settings attribute and its production value: on the site root (`root`), and on the element
|
||||
* a pre-paint rule names (`scoped`, `[element, attribute, value]`). script/css-variants.ts writes
|
||||
* them to JSON.
|
||||
*/
|
||||
export function cssVariants() {
|
||||
const d = siteSettingsDefaults
|
||||
return {
|
||||
...Object.fromEntries(Object.entries(defaultRootAttributes()).filter(([name]) => !runtime.has(name))),
|
||||
// The home page's Console section (routes/index.tsx).
|
||||
"data-console-height": d.consoleHeight,
|
||||
"data-console-label": d.consoleLayout === "block" ? "left" : d.consoleLabel,
|
||||
"data-console-layout": d.consoleLayout,
|
||||
} as Record<string, string | null>
|
||||
root: {
|
||||
...Object.fromEntries(Object.entries(defaultRootAttributes()).filter(([name]) => !runtime.has(name))),
|
||||
// The home page's Console section (routes/index.tsx).
|
||||
"data-console-height": d.consoleHeight,
|
||||
"data-console-label": d.consoleLayout === "block" ? "left" : d.consoleLabel,
|
||||
"data-console-layout": d.consoleLayout,
|
||||
} as Record<string, string | null>,
|
||||
scoped: [
|
||||
...defaultScopedAttributes().map((entry) => [...entry]),
|
||||
// Markup only the docs components gallery renders (/dev/docs-components: docs-code-gallery.tsx
|
||||
// and its blend comparison), which no production page shows: its own attribute is never there.
|
||||
...[
|
||||
["data-slot", "code-gallery"],
|
||||
["data-slot", "gallery-item"],
|
||||
["data-slot", "gallery-options"],
|
||||
["data-slot", "gallery-steps"],
|
||||
["data-slot", "gallery-table"],
|
||||
["data-slot", "blend-plain"],
|
||||
...["a", "b", "c", "d"].map((value) => ["data-blend", value]),
|
||||
].map(([name, value]) => [`[${name}="${value}"]`, name, null]),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@
|
||||
}
|
||||
|
||||
/* Settings › Section menu › fan: no panel; each row is a small card on the see-through pop-up
|
||||
surface with the logo fan's ring and tight shadow (logo-fan.css), and the cards spring out one
|
||||
surface with the fan's ring and tight shadow (--fan-shadow, site.css), and the cards spring out one
|
||||
after another (docs-lockup.tsx). The rows keep the shared hover tint and active bar. Beside the
|
||||
sidebar only; the phone sheet keeps the list. */
|
||||
@media (min-width: 60.0625rem) {
|
||||
@@ -491,7 +491,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* As under the logo fan (logo-fan.css), the docs nav under the cards fades out while they're
|
||||
/* As under the logo menu, the docs nav under the cards fades out while they're
|
||||
open, so it doesn't show through the gaps and the see-through cards. */
|
||||
[data-site][data-section-menu="fan"]
|
||||
[data-component="sidebar"]:has([data-component="docs-lockup"] [data-slot="menu"]:not([hidden]))
|
||||
|
||||
@@ -9,7 +9,8 @@ export { interLatin }
|
||||
// overlap: a character in both that Inter lacks would fetch the second file only to fall back. The
|
||||
// Latin file keeps both axes (weight, optical size) but only the OpenType features the site uses
|
||||
// (pyftsubset --layout-features="calt,case,ccmp,locl,tnum,pnum,kern,mark,mkmk,cpsp,liga"): no
|
||||
// character variants or stylistic sets.
|
||||
// character variants or stylistic sets. Pages get these from src/style/fonts.css, which writes them
|
||||
// out (test/fonts.test.ts keeps the two the same).
|
||||
export const interFaces = [
|
||||
[
|
||||
interRest,
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
/* The designed print styles for legal documents (legal-print.tsx). The cover and the colophon only
|
||||
print. Everything is black on white and drawn with borders, SVG and text, never backgrounds, so it
|
||||
prints the same with "Background graphics" off. */
|
||||
|
||||
@media screen {
|
||||
[data-component="legal-print-cover"],
|
||||
[data-component="legal-print-colophon"] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
/* The designed print styles for legal documents (legal-print.tsx), which legal.tsx links for print
|
||||
only. The cover and the colophon only print (legal.css hides them on screen). Everything is black
|
||||
on white and drawn with borders, SVG and text, never backgrounds, so it prints the same with
|
||||
"Background graphics" off. */
|
||||
|
||||
/* The architect cover's parts, on paper and in the layout editor's preview (/dev/print-editor).
|
||||
Positions and sizes come from the layout (architectCoverCss in lib/legal/architect.ts). */
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import "./legal-print.css"
|
||||
import { createContext, createSignal, For, Match, onMount, Show, Switch, useContext } from "solid-js"
|
||||
import { Dynamic } from "solid-js/web"
|
||||
import { encode } from "uqr"
|
||||
|
||||
@@ -26,6 +26,7 @@ import { copySelection } from "~/lib/clipboard"
|
||||
import { architectLabelCases, architectRules, legalHistoryViews, legalPrintStyles, siteSettings } from "./settings"
|
||||
import { resolvePattern } from "~/lib/legal/cover-pattern"
|
||||
import { LegalPrint, LegalReferences, legalReferences, useLegalReference } from "./legal-print"
|
||||
import printStylesheet from "./legal-print.css?url"
|
||||
import {
|
||||
architectLayout,
|
||||
coverConcepts,
|
||||
@@ -211,6 +212,8 @@ export function LegalDocument(props: { document: LegalDocumentContent }) {
|
||||
<Meta name="robots" content="noindex, nofollow" />
|
||||
</Show>
|
||||
<Link rel="alternate" type="application/rss+xml" title={feedTitle} href={feed} />
|
||||
{/* The print styles load beside the page without holding up its first paint. */}
|
||||
<Link rel="stylesheet" href={printStylesheet} media="print" />
|
||||
{/* The legal pages are English at every locale URL, so the trail uses their English URLs. */}
|
||||
<JsonLd
|
||||
data={breadcrumbData([
|
||||
|
||||
@@ -1,626 +0,0 @@
|
||||
/* Logo menu, fan option: a column of previews under the logo, each with its label beside it in a
|
||||
small pill, like a Dock stack in Fan view. There is no panel; the gaps between items let clicks
|
||||
through to the page, which closes the fan. logo-fan.tsx runs the staggered spring. */
|
||||
/* The fan's shadows, on the site root so the section menus' fan style (docs-lockup.css) shares them. */
|
||||
[data-site] {
|
||||
/* Like the icons in a macOS Dock stack, each preview and label casts only a small, soft shadow
|
||||
close to itself, and the gap is wider than the shadow reaches, so no shadow falls on the next
|
||||
item. A hairline ring carries the edge, which matters most in the dark theme. While an item
|
||||
drops, logo-fan.tsx sets data-lift for a longer, lifted shadow that settles back. */
|
||||
--fan-shadow:
|
||||
0 0 0 1px light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1)),
|
||||
0 1px 2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4)),
|
||||
0 2px 5px -2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
|
||||
--fan-shadow-lifted:
|
||||
0 0 0 1px light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1)),
|
||||
0 2px 4px light-dark(rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.4)),
|
||||
0 4px 8px -4px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.5));
|
||||
}
|
||||
|
||||
[data-site] [data-component="logo-fan"] {
|
||||
--thumb-width: 3.5rem;
|
||||
position: absolute;
|
||||
z-index: 40;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.625rem;
|
||||
width: max-content;
|
||||
/* The padding leaves room for the shadows, and puts the first preview 16px under the logo. */
|
||||
margin-inline-start: -0.5rem;
|
||||
padding: 0.5rem 0.5rem 1rem;
|
||||
pointer-events: none;
|
||||
|
||||
&[data-scroll] {
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-width: none;
|
||||
/* The last visible item fades out, so the list reads as continuing. */
|
||||
mask-image: linear-gradient(to bottom, #000 calc(100% - 2.5rem), transparent);
|
||||
}
|
||||
|
||||
&[data-closing] a {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
a[data-lift] :is([data-slot="thumb"], [data-slot="label"]) {
|
||||
box-shadow: var(--fan-shadow-lifted);
|
||||
}
|
||||
|
||||
a {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: max-content;
|
||||
pointer-events: auto;
|
||||
outline: none;
|
||||
/* The tilt and the scale pivot on the preview. */
|
||||
transform-origin: calc(var(--thumb-width) / 2) 50%;
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
[data-slot="thumb"] {
|
||||
transform: scale(1.04);
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
color: var(--text-strong);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:active [data-slot="thumb"] {
|
||||
transform: scale(0.97);
|
||||
transition-duration: 100ms;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
[data-slot="thumb"],
|
||||
[data-slot="label"] {
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
color: var(--text-strong);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="thumb"] {
|
||||
display: grid;
|
||||
flex-shrink: 0;
|
||||
place-items: center;
|
||||
width: var(--thumb-width);
|
||||
height: 2.625rem;
|
||||
background: color-mix(in srgb, var(--popover-bg) 94%, var(--text-strong));
|
||||
box-shadow: var(--fan-shadow);
|
||||
transition:
|
||||
transform 200ms var(--ease-out),
|
||||
box-shadow 320ms var(--ease-out);
|
||||
|
||||
/* Each preview keeps its own background, so light marks sit on light and dark on dark, as on
|
||||
the brand page. */
|
||||
&[data-tone="light"] {
|
||||
background: hsl(0, 0%, 96%);
|
||||
}
|
||||
|
||||
&[data-tone="dark"] {
|
||||
background: #0a0a0a;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
&[data-kind="logo"] img {
|
||||
width: auto;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
&[data-kind="wordmark"] img {
|
||||
width: 2.75rem;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* A tiny guidelines page: the logo and three lines of text. */
|
||||
[data-slot="page"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
width: 1.5rem;
|
||||
height: 1.875rem;
|
||||
padding: 4px;
|
||||
background: var(--popover-bg);
|
||||
box-shadow: 0 1px 2px rgb(0 0 0 / 0.16);
|
||||
|
||||
[data-slot="icon"] {
|
||||
width: 6px;
|
||||
height: auto;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
i {
|
||||
display: block;
|
||||
height: 1.5px;
|
||||
background: var(--text-weaker);
|
||||
|
||||
&[data-short] {
|
||||
width: 60%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* A zip archive: a zipper down the middle and a label. */
|
||||
[data-slot="archive"] {
|
||||
position: relative;
|
||||
display: grid;
|
||||
place-items: end center;
|
||||
width: 1.5rem;
|
||||
height: 1.875rem;
|
||||
padding-bottom: 3px;
|
||||
background: var(--text-strong);
|
||||
color: var(--bg);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.4375rem;
|
||||
letter-spacing: 0.06em;
|
||||
line-height: 1;
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
width: 3px;
|
||||
height: 50%;
|
||||
translate: -50% 0;
|
||||
background: repeating-linear-gradient(to bottom, var(--bg) 0 2px, transparent 2px 4px);
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
/* The label sits on a small see-through pill of the site theme's pop-up surface, so it reads over
|
||||
the page. Mono and muted like the nav, full strength on hover and focus. */
|
||||
[data-slot="label"] {
|
||||
padding: 0.1875rem 0.4375rem;
|
||||
background: color-mix(in srgb, var(--popover-bg) 85%, transparent);
|
||||
-webkit-backdrop-filter: blur(8px);
|
||||
backdrop-filter: blur(8px);
|
||||
box-shadow: var(--fan-shadow);
|
||||
color: var(--popover-text-weak);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-micro);
|
||||
line-height: 1rem;
|
||||
white-space: nowrap;
|
||||
transition:
|
||||
color 150ms ease,
|
||||
box-shadow 320ms var(--ease-out);
|
||||
}
|
||||
|
||||
[data-slot="meta"] {
|
||||
color: var(--popover-text-weak);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
[data-slot="thumb"] {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The sidebar nav sits right under the logo, so it fades out while the fan is open (it would show
|
||||
through the gaps between items) and back in as the fan closes, with the nav's own 200ms fade. */
|
||||
[data-site]
|
||||
[data-component="sidebar"]:has([data-component="logo-fan"]:not([data-closing]))
|
||||
[data-component="nav"]:not([data-away]) {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Settings › Logo menu hover "grey" (the default): the shared menu grey (site.css › Settings › Menu
|
||||
color). In the fan, hover and keyboard focus show the light grey tint only, with no bar on the
|
||||
left; keyboard focus keeps the fan's 2px focus ring. The cards menu's rows also get the mid-grey
|
||||
bar on the left, and no blue outline. */
|
||||
[data-site][data-logo-menu-hover="grey"] {
|
||||
[data-component="logo-fan"]:not([data-item="card"]) a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover [data-slot="label"] {
|
||||
background: var(--menu-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible [data-slot="label"] {
|
||||
background: var(--menu-hover);
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="logo-fan"][data-item="card"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
background: var(--menu-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
background: var(--menu-hover);
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="asset-menu"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
background: var(--menu-hover);
|
||||
box-shadow: inset 2px 0 0 var(--menu-hint);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: none;
|
||||
background: var(--menu-hover);
|
||||
box-shadow: inset 2px 0 0 var(--menu-hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Settings › Logo menu hover, for the fan and cards logo menus. "subtle" keeps each menu's own
|
||||
hover. The list menu always uses the shared menu rows in site.css (Settings › Menu color). The blue styles outline and tint the item in the link blue; keyboard focus
|
||||
gets the same look with a 2px outline. */
|
||||
[data-site][data-logo-menu-hover^="blue"] {
|
||||
--menu-tint: color-mix(in srgb, var(--link) 10%, var(--popover-bg));
|
||||
|
||||
&[data-logo-menu-hover="blue fill"] {
|
||||
--menu-tint: color-mix(in srgb, var(--link) 16%, var(--popover-bg));
|
||||
}
|
||||
|
||||
[data-component="logo-fan"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover :is([data-slot="thumb"], [data-slot="label"]) {
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
&:hover [data-slot="label"] {
|
||||
background: var(--menu-tint);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible :is([data-slot="thumb"], [data-slot="label"]) {
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
&:focus-visible [data-slot="label"] {
|
||||
background: var(--menu-tint);
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="asset-menu"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
background: var(--menu-tint);
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
background: var(--menu-tint);
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
}
|
||||
|
||||
/* "blue fill" also turns the label blue. */
|
||||
&[data-logo-menu-hover="blue fill"] {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
[data-component="logo-fan"] a:hover [data-slot="label"],
|
||||
[data-component="asset-menu"] a:hover [data-slot="name"] {
|
||||
color: var(--link);
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="logo-fan"] a:focus-visible [data-slot="label"],
|
||||
[data-component="asset-menu"] a:focus-visible [data-slot="name"] {
|
||||
color: var(--link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* "lift": the item nudges 2px right and its shadow lifts. */
|
||||
[data-site][data-logo-menu-hover="lift"] {
|
||||
:is([data-component="logo-fan"], [data-component="asset-menu"]) a {
|
||||
transition:
|
||||
translate 160ms var(--ease-out),
|
||||
background-color 150ms ease;
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
translate: 2px 0;
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
translate: 2px 0;
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="logo-fan"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover :is([data-slot="thumb"], [data-slot="label"]) {
|
||||
box-shadow: var(--fan-shadow-lifted);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible :is([data-slot="thumb"], [data-slot="label"]) {
|
||||
box-shadow: var(--fan-shadow-lifted);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
:is([data-component="logo-fan"], [data-component="asset-menu"]) a {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Settings › Logo menu item › card: each item is one compact card holding a smaller preview and
|
||||
its label, on the same see-through pop-up surface, ring and tight shadow as the pills. The
|
||||
Logo menu hover styles apply to the whole card. */
|
||||
[data-site] [data-component="logo-fan"][data-item="card"] {
|
||||
--thumb-width: 2.375rem;
|
||||
|
||||
a {
|
||||
gap: 0.625rem;
|
||||
/* The preview sits flush on the top, left and bottom; room after the label. */
|
||||
padding-block: 0;
|
||||
padding-inline: 0 0.75rem;
|
||||
background: color-mix(in srgb, var(--popover-bg) 85%, transparent);
|
||||
-webkit-backdrop-filter: blur(8px);
|
||||
backdrop-filter: blur(8px);
|
||||
box-shadow: var(--fan-shadow);
|
||||
transition:
|
||||
background-color 150ms ease,
|
||||
box-shadow 320ms var(--ease-out),
|
||||
translate 160ms var(--ease-out);
|
||||
|
||||
/* No lifted shadow while a card drops: across a whole card it reads as the first card
|
||||
darkening for a moment as it lands on the empty page. */
|
||||
&[data-lift] {
|
||||
box-shadow: var(--fan-shadow);
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--popover-bg) 90%, var(--text-strong));
|
||||
|
||||
[data-slot="thumb"] {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
scale: 0.98;
|
||||
}
|
||||
|
||||
&:active [data-slot="thumb"] {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 1px solid var(--link);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
/* The card's own ring frames the preview on three sides; a matching hairline on its right edge
|
||||
separates it from the label. */
|
||||
a [data-slot="thumb"],
|
||||
a[data-lift] [data-slot="thumb"] {
|
||||
height: 1.75rem;
|
||||
box-shadow: inset -1px 0 0 light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1));
|
||||
}
|
||||
|
||||
a:focus-visible [data-slot="thumb"],
|
||||
a:focus-visible [data-slot="label"] {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
[data-slot="thumb"][data-kind="logo"] img {
|
||||
height: 1.125rem;
|
||||
}
|
||||
|
||||
[data-slot="thumb"][data-kind="wordmark"] img {
|
||||
width: 1.875rem;
|
||||
}
|
||||
|
||||
:is([data-slot="page"], [data-slot="archive"]) {
|
||||
scale: 0.72;
|
||||
}
|
||||
|
||||
a [data-slot="label"],
|
||||
a[data-lift] [data-slot="label"] {
|
||||
padding: 0;
|
||||
background: none;
|
||||
-webkit-backdrop-filter: none;
|
||||
backdrop-filter: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
a:active {
|
||||
scale: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-site][data-logo-menu-hover^="blue"] [data-component="logo-fan"][data-item="card"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
background: var(--menu-tint);
|
||||
/* The card's own hairline ring turns blue; nothing is drawn outside it. */
|
||||
outline: none;
|
||||
box-shadow:
|
||||
0 0 0 1px var(--link),
|
||||
0 1px 2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4)),
|
||||
0 2px 5px -2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
|
||||
|
||||
:is([data-slot="thumb"], [data-slot="label"]) {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* The divider beside the preview turns blue with the border. */
|
||||
[data-slot="thumb"] {
|
||||
box-shadow: inset -1px 0 0 var(--link);
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
background: var(--menu-tint);
|
||||
outline: none;
|
||||
box-shadow:
|
||||
0 0 0 1px var(--link),
|
||||
0 1px 2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
|
||||
|
||||
[data-slot="thumb"] {
|
||||
box-shadow: inset -1px 0 0 var(--link);
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-site][data-logo-menu-hover="lift"] [data-component="logo-fan"][data-item="card"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover {
|
||||
box-shadow: var(--fan-shadow-lifted);
|
||||
|
||||
[data-slot="label"] {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
[data-slot="thumb"] {
|
||||
box-shadow: inset -1px 0 0 light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
box-shadow: var(--fan-shadow-lifted);
|
||||
|
||||
[data-slot="label"] {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
[data-slot="thumb"] {
|
||||
box-shadow: inset 0 0 0 1px light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The Brand, Press and Brand assets thumbnails: a ruler, the Press icon and a zip file, drawn on
|
||||
the same 16px grid. */
|
||||
[data-site] [data-component="logo-fan"] {
|
||||
[data-slot="thumb"]:is([data-kind="guide"], [data-kind="press"], [data-kind="zip"]) {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: var(--text-weak);
|
||||
}
|
||||
|
||||
:is([data-slot="ruler"], [data-slot="paper"], [data-slot="zipfile"]) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
/* The cards logo menu's previews: each file on the background it is made for (light or dark). The list menu's
|
||||
small mark icons are the file used as a mask over the text colour, so they show on either pop-up. */
|
||||
[data-site] [data-component="asset-menu"] [data-slot="thumb"][data-style] {
|
||||
&[data-tone="light"] {
|
||||
background: hsl(0, 0%, 96%);
|
||||
}
|
||||
|
||||
&[data-tone="dark"] {
|
||||
background: #0a0a0a;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
&[data-kind="logo"] img {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
&[data-kind="wordmark"] img {
|
||||
width: 76%;
|
||||
}
|
||||
}
|
||||
|
||||
[data-site] [data-component="logo-menu"] a [data-slot="variant"] {
|
||||
flex-shrink: 0;
|
||||
width: 11.2px;
|
||||
height: 14px;
|
||||
margin-inline: 1.4px;
|
||||
background: currentColor;
|
||||
mask-size: contain;
|
||||
mask-repeat: no-repeat;
|
||||
}
|
||||
|
||||
/* The "ZIP" on the cards menu's archive icon: capitals, a touch heavier than the labels (the site serves
|
||||
OpenTUI Mono in regular and bold only, so a hairline stroke adds the weight, as for the site's titles). The
|
||||
"ZIP" after a label matches the other formats ("SVG", "Page"). */
|
||||
[data-site] :is([data-component="logo-fan"], [data-component="asset-menu"], [data-component="logo-menu"]) {
|
||||
[data-slot="archive"] > span {
|
||||
font-weight: 400;
|
||||
-webkit-text-stroke: 0.35px currentColor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dark previews: the hairline ring around the preview (the card's ring, the divider beside it, or a
|
||||
pill thumbnail's own ring) takes the preview's own colour, so it disappears and the dark preview
|
||||
reads at full size instead of inside a pale frame. The blue hover and focus still turn it blue. */
|
||||
[data-site] [data-component="logo-fan"] [data-slot="thumb"][data-tone="dark"] {
|
||||
--fan-shadow:
|
||||
0 0 0 1px #0a0a0a, 0 1px 2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4)),
|
||||
0 2px 5px -2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
|
||||
--fan-shadow-lifted:
|
||||
0 0 0 1px #0a0a0a, 0 2px 4px light-dark(rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.4)),
|
||||
0 4px 8px -4px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.5));
|
||||
}
|
||||
|
||||
[data-site] [data-component="logo-fan"][data-item="card"] :is(a, a[data-lift]) [data-slot="thumb"][data-tone="dark"] {
|
||||
box-shadow: 0 0 0 1px #0a0a0a;
|
||||
}
|
||||
|
||||
[data-site][data-logo-menu-hover="lift"] [data-component="logo-fan"][data-item="card"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover [data-slot="thumb"][data-tone="dark"] {
|
||||
box-shadow: 0 0 0 1px #0a0a0a;
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible [data-slot="thumb"][data-tone="dark"] {
|
||||
box-shadow: 0 0 0 1px #0a0a0a;
|
||||
}
|
||||
}
|
||||
|
||||
[data-site][data-logo-menu-hover^="blue"] [data-component="logo-fan"][data-item="card"] a {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
&:hover [data-slot="thumb"][data-tone="dark"] {
|
||||
box-shadow: 0 0 0 1px var(--link);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-visible [data-slot="thumb"][data-tone="dark"] {
|
||||
box-shadow: 0 0 0 1px var(--link);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,5 @@
|
||||
/* The Markdown view (markdown-view.tsx), loaded with it. site.css hides the page under it. */
|
||||
[data-site] {
|
||||
/* The page stays mounted under the Markdown view, so its state survives a round trip. */
|
||||
[data-component="content"] > [data-slot="page"] {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
&[data-markdown] [data-component="content"] > [data-slot="page"],
|
||||
&[data-markdown-boot] [data-component="content"] > [data-slot="page"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-component="markdown-view"] {
|
||||
--line: 1.7;
|
||||
min-width: 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createSignal, For, type JSX, Match, onCleanup, Show, Switch } from "solid-js"
|
||||
import { config } from "~/config"
|
||||
import { NewTab } from "./icons"
|
||||
import "./markdown-view.css"
|
||||
|
||||
type Block =
|
||||
| { kind: "heading"; level: number; marker: string; text: string }
|
||||
|
||||
@@ -35,7 +35,8 @@ export const monoFontPreloads: Partial<Record<string, string>> = import.meta.env
|
||||
* The overrides are divided by size-adjust, which scales them too. DejaVu Sans Mono (Linux) shares
|
||||
* Menlo's metrics. local() matches a face's full or PostScript name, not its family ("Menlo
|
||||
* Regular", not "Menlo"). The stand-ins have no unicode-range, so characters OpenTUI Mono lacks
|
||||
* (Cyrillic, Greek) set in the scaled system font, at the same advance.
|
||||
* (Cyrillic, Greek) set in the scaled system font, at the same advance. Pages get them from
|
||||
* src/style/fonts.css, which writes them out (test/fonts.test.ts keeps the two the same).
|
||||
*/
|
||||
export const monoFontFaces = [
|
||||
...[
|
||||
|
||||
@@ -249,3 +249,38 @@ export function defaultRootAttributes() {
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings attributes production renders on other elements, as `[element, attribute, value]`
|
||||
* with the default settings (`null` for one it leaves off). The element is the attribute selectors
|
||||
* with a value in the last compound of the rule's selector (`[data-component="products"]`), so a rule
|
||||
* whose element has none is left out, as is one whose value reads the element or the address. They
|
||||
* go in css-variants.json beside the root's.
|
||||
*/
|
||||
export function defaultScopedAttributes() {
|
||||
// A rule that reads the element (or the address) depends on more than the settings.
|
||||
const element = new Proxy({} as HTMLElement, {
|
||||
get: () => {
|
||||
throw new Error("reads the element")
|
||||
},
|
||||
})
|
||||
const evaluate = (rule: (typeof preloadRules)[number]) => {
|
||||
try {
|
||||
const value = rule[2](siteSettingsDefaults, element, siteSettingsDefaults)
|
||||
return [value === undefined ? null : String(value)]
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
return preloadRules
|
||||
.filter((rule) => rule[0] !== "" && rule[1].startsWith("data-"))
|
||||
.flatMap((rule) =>
|
||||
evaluate(rule).flatMap((value) =>
|
||||
rule[0].split(",").flatMap((selector) => {
|
||||
const last = selector.trim().match(/(?:[^\s>+~[\]()]|\[[^\]]*\]|\([^)]*\))+$/)?.[0] ?? ""
|
||||
const owner = last.match(/\[[\w-]+[~|^$*]?="[^"]*"\]/g)?.join("")
|
||||
return owner ? [[owner, rule[1], value] as const] : []
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -107,6 +107,17 @@ html:has([data-site][data-theme="dark"]) {
|
||||
0 1px 1px light-dark(rgb(0 0 0 / 0.04), rgb(0 0 0 / 0.3)),
|
||||
0 2px 4px -1px light-dark(rgb(0 0 0 / 0.06), rgb(0 0 0 / 0.35)),
|
||||
0 6px 12px -4px light-dark(rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.45));
|
||||
/* Cards fanned out with no panel (the section menus' fan style, the press gallery's fan): like the
|
||||
icons in a macOS Dock stack, each casts only a small, soft shadow close to itself, and a hairline
|
||||
ring carries the edge, which matters most in the dark theme. Lifted while one drops. */
|
||||
--fan-shadow:
|
||||
0 0 0 1px light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1)),
|
||||
0 1px 2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4)),
|
||||
0 2px 5px -2px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
|
||||
--fan-shadow-lifted:
|
||||
0 0 0 1px light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.1)),
|
||||
0 2px 4px light-dark(rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.4)),
|
||||
0 4px 8px -4px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.5));
|
||||
/* The brand greys: the logo ink at 20% / 70% on white (light) and 28% / 72% on #0b0b0b (dark). */
|
||||
--logo-inner: light-dark(#d2d2d2, #4b4b4b);
|
||||
--logo-open: light-dark(#626262, #aeaeae);
|
||||
@@ -591,6 +602,17 @@ html:has([data-site][data-theme="dark"]) {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* The page stays mounted under the Markdown view (markdown-view.tsx, whose styles load with it), so
|
||||
its state survives a round trip. It's hidden while the view shows, and on a reload in the view
|
||||
until the view has loaded (site.tsx). */
|
||||
[data-component="content"] > [data-slot="page"] {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
&:is([data-markdown], [data-markdown-boot]) [data-component="content"] > [data-slot="page"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-component="site-button"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
Suspense,
|
||||
} from "solid-js"
|
||||
import { Dynamic, isServer } from "solid-js/web"
|
||||
import { interFaces, interLatin } from "./inter-fonts"
|
||||
import { interLatin } from "./inter-fonts"
|
||||
import { AgentIcon, Bracket, PersonIcon, ThemeCycle } from "./site-controls"
|
||||
import logoLight from "../../asset/brand/opencode-logo-light.svg"
|
||||
import logoDark from "../../asset/brand/opencode-logo-dark.svg"
|
||||
@@ -56,8 +56,6 @@ import {
|
||||
removeNavItem,
|
||||
sortableNav,
|
||||
} from "./nav-order"
|
||||
// The Markdown view's styles load with the page: they also hide the page while the view loads.
|
||||
import "./markdown-view.css"
|
||||
import { monoFontChoice, monoFontLatin } from "./mono-fonts"
|
||||
import { NavVersions } from "./nav-versions"
|
||||
import { closeAllMenus, closeMenusOnLinks, onCloseMenus, takeMenuNavigation } from "./menu-open"
|
||||
@@ -69,8 +67,7 @@ import { SiteSearch } from "./search"
|
||||
import { navMenusOnIntent } from "./nav-intent"
|
||||
import { preloadTouchedLinks } from "./preload-touched"
|
||||
import { adoptVoice, dropVoice } from "./voice/host"
|
||||
// The logo menu's other styles (Settings › Logo menu: list, cards) and the shared nav menus in the site's colours.
|
||||
import "./logo-fan.css"
|
||||
// The shared nav menus in the site's colours.
|
||||
import "./nav-menus.css"
|
||||
import { logoVariantSvgs } from "./logo-variants"
|
||||
import { AnomalyLogo, Logo, LogoIcon, Wordmark } from "./marks"
|
||||
@@ -1295,10 +1292,6 @@ export function Site(props: {
|
||||
(siteSettings.spacer === "dither gradient" ? ditherGradientRule(siteSettings, "") : "")
|
||||
}
|
||||
/>
|
||||
{/* A plain style element, which hydration keeps: the meta <Style> is inserted again on
|
||||
hydration, and the new faces then miss font-display: optional's window, so the page
|
||||
swaps to the fallback font and reflows. */}
|
||||
<style innerHTML={interFaces} />
|
||||
{/* Fetched with the page, so Inter is ready for the first paint instead of arriving inside
|
||||
font-display: optional's short wait and reflowing the text (CLS). Only the Latin file:
|
||||
most pages need nothing else. */}
|
||||
|
||||
@@ -3,10 +3,10 @@ import { DocsLockup, docsSectionName, type DocsVersion } from "~/component/site/
|
||||
import { DocsVersionNotice } from "~/component/site/docs-version-notice"
|
||||
import { GitHubLink } from "~/component/site/github-link"
|
||||
import { Chevron, NewTab, SearchIcon } from "~/component/site/icons"
|
||||
import { interFaces, interLatin } from "~/component/site/inter-fonts"
|
||||
import { interLatin } from "~/component/site/inter-fonts"
|
||||
import { LogoIcon } from "~/component/site/marks"
|
||||
import { Bracket } from "~/component/site/site-controls"
|
||||
import { monoFontFaces, monoFontLatin } from "~/component/site/mono-fonts"
|
||||
import { monoFontLatin } from "~/component/site/mono-fonts"
|
||||
import { OnThisPage } from "~/component/site/on-this-page"
|
||||
import { defaultRootAttributes, themeScript } from "~/component/site/preload-settings"
|
||||
import { config } from "~/config"
|
||||
@@ -127,7 +127,6 @@ export function DocsLayout(props: {
|
||||
<title>{`${props.title} | OpenCode${props.set.id === "v1" ? " V1" : ""}`}</title>
|
||||
<link rel="preload" href={interLatin} as="font" type="font/woff2" crossorigin="anonymous" />
|
||||
<link rel="preload" href={monoFontLatin} as="font" type="font/woff2" crossorigin="anonymous" />
|
||||
<style innerHTML={`${interFaces}\n${monoFontFaces}`} />
|
||||
<link rel="stylesheet" href={props.assets.stylesheet} />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -170,7 +170,7 @@ console.log(`docs: built ${Object.values(render.docsSlugs).flat().length} pages`
|
||||
async function checkBudget() {
|
||||
// The shared nav menus (packages/nav-menus) are the script's one file of its own, loaded on first use (nav-intent.ts).
|
||||
// The stylesheet carries the phone bars (the sticky section row and the Contents bar under it), about 0.3 kB,
|
||||
// and the V1 docs' notice and type for their languages, about 1 kB.
|
||||
// the V1 docs' notice and type for their languages, about 1 kB, and the fonts' faces (src/style/fonts.css), about 1.3 kB.
|
||||
const budgets = { [inputs.script]: 8 * 1024, [inputs.stylesheet]: 30 * 1024 }
|
||||
const files = await Array.fromAsync(new Bun.Glob("_build/*.js").scan({ cwd: path.join(cache, "client") }))
|
||||
const lazy = manifest[inputs.script].dynamicImports?.length ?? 0
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
docs components (docs-variants.css), and below them the base rules for the docs' own parts (the
|
||||
section nav, the article, the aside, the API cards). script/build.ts builds it under /docs/_build
|
||||
with the site's production CSS plugins, so only the chosen docs options ship. */
|
||||
@import "../../style/fonts.css";
|
||||
@import "../../style/index.css";
|
||||
@import "../../component/site/site.css";
|
||||
@import "../../component/site/rtl.css";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useLanguage } from "~/context/language"
|
||||
/**
|
||||
* Server only: preloads the page's strings in its language (the locale's table, which holds the
|
||||
* shell's, and the page route's slice), so they arrive with the page's scripts rather than after
|
||||
* them. Written like Vite's own preloads, so lib/one-stylesheet.ts gives them the same priority. The
|
||||
* them. Written like Vite's own preloads, so lib/head-links.ts gives them the same priority. The
|
||||
* client build writes where each file went (script/i18n-plugin.ts); the development server has none.
|
||||
* Called inside a component (AppMeta) rather than rendered as one, so the component tree, and the ids
|
||||
* Solid derives from it, stay as they were.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { createMiddleware } from "@solidjs/start/middleware"
|
||||
import { getRequestEvent } from "solid-js/web"
|
||||
|
||||
// A page's head links, in production. Its stylesheets (the shell's and its group's,
|
||||
// script/stylesheet-groups.ts) are also named in a Link header, so the browser, and Cloudflare's Early
|
||||
// Hints before the page is ready, can start them sooner. Its module preloads get fetchpriority="low":
|
||||
// they still start with the page, but the stylesheets, the fonts and the largest image go first on a
|
||||
// slow connection, and the page's script (the same files, the same order) hydrates once they have
|
||||
// arrived. Inside the HTML cache (middleware.ts), so cached pages carry both.
|
||||
|
||||
type Middleware = ReturnType<typeof createMiddleware>[number]
|
||||
|
||||
export const headLinks: Middleware = async (_event, next) => {
|
||||
const value = await next()
|
||||
if (import.meta.env.DEV || typeof value !== "string") return value
|
||||
const page = pageHead(value)
|
||||
// On the request's response headers, which the HTML cache keeps with the page (lib/html-cache.ts).
|
||||
if (page.link) getRequestEvent()?.response.headers.set("Link", page.link)
|
||||
return page.html
|
||||
}
|
||||
|
||||
/** The page with its module preloads at low priority, and the Link header for its stylesheets. */
|
||||
export function pageHead(html: string) {
|
||||
const end = html.indexOf("</head>")
|
||||
if (end < 0) return { html }
|
||||
const head = html.slice(0, end)
|
||||
const stylesheets = [...head.matchAll(/<link href="(\/_build\/assets\/[\w-]+\.css)" rel="stylesheet" ?\/?>/g)]
|
||||
return {
|
||||
html:
|
||||
head.replace(
|
||||
/(<link href="\/_build\/assets\/[\w-]+\.js" rel="modulepreload")( ?\/?>)/g,
|
||||
'$1 fetchpriority="low"$2',
|
||||
) + html.slice(end),
|
||||
link: stylesheets.map((match) => `<${match[1]}>; rel=preload; as=style`).join(", ") || undefined,
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import type { createMiddleware } from "@solidjs/start/middleware"
|
||||
|
||||
// One stylesheet per page, in production. Vite splits the CSS by JavaScript chunk, so a page links
|
||||
// 11–16 render-blocking stylesheets. This middleware replaces them with one: /stylesheet/<names>.css
|
||||
// (routes/stylesheet/[file].ts) is their contents joined in the same order, so the cascade is
|
||||
// unchanged. The names are content hashes, so the combined file is immutable too.
|
||||
//
|
||||
// The client's chunk loader (Vite's preload helper) looks for a `link` with the file's href and
|
||||
// rel="stylesheet" before adding a chunk's CSS on a client-side navigation, so each original link
|
||||
// must stay in the document, disabled (not applied), or a second copy lands later in the cascade. A
|
||||
// script in front of the combined link adds them: Chrome's preload scanner fetches a disabled link
|
||||
// written in the HTML anyway, but not one a script adds. Its text is the same on every page (the
|
||||
// names are in its data-css attribute).
|
||||
//
|
||||
// Only the head's stylesheets are combined, and only when nothing but links sits between them (no
|
||||
// inline <style>), so the order against inline styles is the same as before.
|
||||
//
|
||||
// The same pass gives the page's module preloads `fetchpriority="low"`: they still start with the
|
||||
// page, but the stylesheet, the fonts and the largest image go first on a slow connection, and the
|
||||
// page's script (the same files, the same order) hydrates once they have arrived.
|
||||
|
||||
type Middleware = ReturnType<typeof createMiddleware>[number]
|
||||
|
||||
const link = /<link href="\/_build\/assets\/([\w-]+)\.css" rel="stylesheet" ?\/?>/g
|
||||
const disabledLinks = `for(const n of document.currentScript.dataset.css.split("~")){const l=document.createElement("link");l.rel="stylesheet";l.disabled=true;l.href="/_build/assets/"+n+".css";document.head.appendChild(l)}`
|
||||
|
||||
export const oneStylesheet: Middleware = async (_event, next) => {
|
||||
const value = await next()
|
||||
if (import.meta.env.DEV || typeof value !== "string") return value
|
||||
return lowerPreloadPriority(combineStylesheets(value))
|
||||
}
|
||||
|
||||
export function lowerPreloadPriority(html: string) {
|
||||
const end = html.indexOf("</head>")
|
||||
if (end < 0) return html
|
||||
return (
|
||||
html
|
||||
.slice(0, end)
|
||||
.replace(/(<link href="\/_build\/assets\/[\w-]+\.js" rel="modulepreload")( ?\/?>)/g, '$1 fetchpriority="low"$2') +
|
||||
html.slice(end)
|
||||
)
|
||||
}
|
||||
|
||||
export function combineStylesheets(html: string) {
|
||||
const end = html.indexOf("</head>")
|
||||
if (end < 0) return html
|
||||
const head = html.slice(0, end)
|
||||
const matches = [...head.matchAll(link)]
|
||||
if (matches.length < 2) return html
|
||||
const first = matches[0].index!
|
||||
const last = matches.at(-1)!
|
||||
const between = head.slice(first, last.index! + last[0].length)
|
||||
if (/<style[\s>]/.test(between)) return html
|
||||
const names = matches.map((match) => match[1]).join("~")
|
||||
const combined = `<script data-css="${names}">${disabledLinks}</script><link rel="stylesheet" href="/stylesheet/${names}.css" />`
|
||||
let index = 0
|
||||
const rewritten = head.replace(link, () => (index++ === 0 ? combined : ""))
|
||||
return rewritten + html.slice(end)
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import { absoluteUrl, markdownHeaders } from "~/lib/markdown"
|
||||
import { changelogEntryJson } from "~/lib/changelog-releases"
|
||||
import { findPageMarkdown, renderPageMarkdown } from "~/lib/page-markdown"
|
||||
import { htmlCache } from "~/lib/html-cache"
|
||||
import { oneStylesheet } from "~/lib/one-stylesheet"
|
||||
import { headLinks } from "~/lib/head-links"
|
||||
import securityTxt from "~/lib/legal/security.txt?raw"
|
||||
import humansTxt from "~/lib/humans.txt?raw"
|
||||
import { robotsTxt } from "~/lib/robots-txt"
|
||||
@@ -29,8 +29,8 @@ import { docsMiddleware } from "~/docs/middleware"
|
||||
|
||||
// dev.opencode.ai's noindex header on every response (lib/noindex.ts), then the docs (everything
|
||||
// under /docs and /v1/docs, and the V1 docs' old host, docs/middleware.ts), then the page middleware, then the HTML cache headers and edge
|
||||
// cache (lib/html-cache.ts), which see the request without its locale, then one stylesheet per page
|
||||
// (lib/one-stylesheet.ts), inside the cache so cached pages carry it too.
|
||||
// cache (lib/html-cache.ts), which see the request without its locale, then the page's head links
|
||||
// (lib/head-links.ts), inside the cache so cached pages carry them too.
|
||||
export default [
|
||||
noindexDev,
|
||||
...docsMiddleware,
|
||||
@@ -144,7 +144,7 @@ export default [
|
||||
},
|
||||
}),
|
||||
htmlCache,
|
||||
oneStylesheet,
|
||||
headLinks,
|
||||
]
|
||||
|
||||
// The text files above change with releases and carry dates, so they are cached for an hour.
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/* The print cover and colophon (legal-print.tsx), whose styles load for print only. */
|
||||
@media screen {
|
||||
[data-component="legal-print-cover"],
|
||||
[data-component="legal-print-colophon"] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
[data-page="legal-document"] {
|
||||
/* "Legal | Privacy Policy" in the logo row, as on the product pages, and it stays there: a sticky
|
||||
band in the page colour (the sticky title's bar) covers the window from its top edge to just
|
||||
@@ -647,8 +655,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* External links keep their arrow on the same line, just after the text. */
|
||||
:is([data-page="legal-document"], [data-page="legal-hub"]) a:has(> [data-slot="external"]) {
|
||||
/* External links keep their arrow on the same line, just after the text: in the page, not the nav, menus
|
||||
and footer, which lay out their own. */
|
||||
:is([data-page="legal-document"], [data-page="legal-hub"])
|
||||
:where([data-component="content"])
|
||||
a:has(> [data-slot="external"]) {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 0.3em;
|
||||
|
||||
@@ -37,9 +37,5 @@
|
||||
padding-block: 0 0.25rem;
|
||||
padding-inline: 1.5rem 0;
|
||||
border: 0;
|
||||
|
||||
&::before {
|
||||
top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,15 +267,6 @@
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
[data-slot="faq-question"] {
|
||||
--padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
[data-slot="faq-answer"] {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
/* Room under the last line to the divider, equal to the room from the row title to the first
|
||||
label (measured text to text: the label row is taller than a FAQ answer's first line). */
|
||||
[data-slot="faq-answer-inner"][data-slot] {
|
||||
|
||||
@@ -2,9 +2,11 @@ import type { APIEvent } from "@solidjs/start/server"
|
||||
import { assets } from "#resource"
|
||||
import { edgeCache } from "~/lib/edge-cache"
|
||||
|
||||
// A page's stylesheets as one file (lib/one-stylesheet.ts): /stylesheet/<name>~<name>….css joins
|
||||
// /_build/assets/<name>.css in the order given. The names carry content hashes, so the result never
|
||||
// changes and is cached for a year, by browsers and at the edge.
|
||||
// A page's stylesheets as one file, as pages linked them before they linked the shell's and their
|
||||
// group's stylesheets (script/stylesheet-groups.ts): /stylesheet/<name>~<name>….css joins
|
||||
// /_build/assets/<name>.css in the order given. Kept for one deploy, for pages still open from
|
||||
// before it (script/retain-assets.ts keeps their files). The names carry content hashes, so the
|
||||
// result never changes and is cached for a year, by browsers and at the edge.
|
||||
const name = /^[\w-]+$/
|
||||
|
||||
export async function GET(event: APIEvent) {
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/* The site's fonts, for every page (app.tsx) and the docs (docs.css), from a stylesheet browsers keep
|
||||
rather than inline in every page: monoFontFaces (component/site/mono-fonts.ts, OpenTUI Mono and
|
||||
its metric-matched stand-ins) and interFaces (inter-fonts.ts) written out, which test/fonts.test.ts
|
||||
keeps the same. */
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-regular-latin.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+0020-007E, U+00A0-017F, U+2000-200D, U+2010-2029, U+202F-2064, U+20AC, U+2190-21E6, U+21E8-21FF, U+2212,
|
||||
U+2500-25FF;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-regular-rest.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+01AB, U+01AE, U+0218-021B, U+0237, U+024B, U+0256, U+026B, U+026D, U+0273, U+0279, U+027B, U+027D-027E, U+0282,
|
||||
U+0285, U+0288, U+0290, U+02AF, U+02B5, U+0300-036F, U+1D6C-1D76, U+1D80-1D9A, U+1DA9-1DAA, U+1DAF, U+1DB3, U+1DB5,
|
||||
U+1DBC, U+1E03, U+1E0B, U+1E23, U+2070, U+2074-2079, U+2080-2089, U+20A1, U+20A3-20AB, U+20AD-20AF, U+20B1-20B5,
|
||||
U+20B8-20BA, U+20BC-20BF, U+20D2, U+20D8, U+20EB, U+2200-2211, U+2213-22FF, U+2948, U+2ADC, U+2AEE, U+2B30, U+2C62,
|
||||
U+2C64, U+A78E, U+A794-A795, U+A7BA-A7BF, U+A7C4-A7C6, U+AB39, U+AB5E, U+AB66-AB68, U+E0B8, U+E0BA, U+E0BC, U+E0BE,
|
||||
U+F882-F883, U+F891-F892, U+10788, U+1078B, U+1078D, U+1079D, U+1079F, U+107A7-107A8, U+107AD, U+107AF, U+107B9,
|
||||
U+1DF05, U+1DF08-1DF0A, U+1DF12-1DF1D;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-bold-latin.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+0020-007E, U+00A0-017F, U+2000-200D, U+2010-2029, U+202F-2064, U+20AC, U+2190-21E6, U+21E8-21FF, U+2212,
|
||||
U+2500-25FF;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-bold-rest.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+01AB, U+01AE, U+0218-021B, U+0237, U+024B, U+0256, U+026B, U+026D, U+0273, U+0279, U+027B, U+027D-027E, U+0282,
|
||||
U+0285, U+0288, U+0290, U+02AF, U+02B5, U+0300-036F, U+1D6C-1D76, U+1D80-1D9A, U+1DA9-1DAA, U+1DAF, U+1DB3, U+1DB5,
|
||||
U+1DBC, U+1E03, U+1E0B, U+1E23, U+2070, U+2074-2079, U+2080-2089, U+20A1, U+20A3-20AB, U+20AD-20AF, U+20B1-20B5,
|
||||
U+20B8-20BA, U+20BC-20BF, U+20D2, U+20D8, U+20EB, U+2200-2211, U+2213-22FF, U+2948, U+2ADC, U+2AEE, U+2B30, U+2C62,
|
||||
U+2C64, U+A78E, U+A794-A795, U+A7BA-A7BF, U+A7C4-A7C6, U+AB39, U+AB5E, U+AB66-AB68, U+E0B8, U+E0BA, U+E0BC, U+E0BE,
|
||||
U+F882-F883, U+F891-F892, U+10788, U+1078B, U+1078D, U+1079D, U+1079F, U+107A7-107A8, U+107AD, U+107AF, U+107B9,
|
||||
U+1DF05, U+1DF08-1DF0A, U+1DF12-1DF1D;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-italic-latin.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+0020-007E, U+00A0-017F, U+2000-200D, U+2010-2029, U+202F-2064, U+20AC, U+2190-21E6, U+21E8-21FF, U+2212,
|
||||
U+2500-25FF;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-italic-rest.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+01AB, U+01AE, U+0218-021B, U+0237, U+024B, U+0256, U+026B, U+026D, U+0273, U+0279, U+027B, U+027D-027E, U+0282,
|
||||
U+0285, U+0288, U+0290, U+02AF, U+02B5, U+0300-036F, U+1D6C-1D76, U+1D80-1D9A, U+1DA9-1DAA, U+1DAF, U+1DB3, U+1DB5,
|
||||
U+1DBC, U+1E03, U+1E0B, U+1E23, U+2070, U+2074-2079, U+2080-2089, U+20A1, U+20A3-20AB, U+20AD-20AF, U+20B1-20B5,
|
||||
U+20B8-20BA, U+20BC-20BF, U+20D2, U+20D8, U+20EB, U+2200-2211, U+2213-22FF, U+2948, U+2ADC, U+2AEE, U+2B30, U+2C62,
|
||||
U+2C64, U+A78E, U+A794-A795, U+A7BA-A7BF, U+A7C4-A7C6, U+AB39, U+AB5E, U+AB66-AB68, U+E0B8, U+E0BA, U+E0BC, U+E0BE,
|
||||
U+F882-F883, U+F891-F892, U+10788, U+1078B, U+1078D, U+1079D, U+1079F, U+107A7-107A8, U+107AD, U+107AF, U+107B9,
|
||||
U+1DF05, U+1DF08-1DF0A, U+1DF12-1DF1D;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-bold-italic-latin.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+0020-007E, U+00A0-017F, U+2000-200D, U+2010-2029, U+202F-2064, U+20AC, U+2190-21E6, U+21E8-21FF, U+2212,
|
||||
U+2500-25FF;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono";
|
||||
src: url("../asset/fonts/opentui-mono-bold-italic-rest.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-style: italic;
|
||||
font-display: swap;
|
||||
unicode-range:
|
||||
U+01AB, U+01AE, U+0218-021B, U+0237, U+024B, U+0256, U+026B, U+026D, U+0273, U+0279, U+027B, U+027D-027E, U+0282,
|
||||
U+0285, U+0288, U+0290, U+02AF, U+02B5, U+0300-036F, U+1D6C-1D76, U+1D80-1D9A, U+1DA9-1DAA, U+1DAF, U+1DB3, U+1DB5,
|
||||
U+1DBC, U+1E03, U+1E0B, U+1E23, U+2070, U+2074-2079, U+2080-2089, U+20A1, U+20A3-20AB, U+20AD-20AF, U+20B1-20B5,
|
||||
U+20B8-20BA, U+20BC-20BF, U+20D2, U+20D8, U+20EB, U+2200-2211, U+2213-22FF, U+2948, U+2ADC, U+2AEE, U+2B30, U+2C62,
|
||||
U+2C64, U+A78E, U+A794-A795, U+A7BA-A7BF, U+A7C4-A7C6, U+AB39, U+AB5E, U+AB66-AB68, U+E0B8, U+E0BA, U+E0BC, U+E0BE,
|
||||
U+F882-F883, U+F891-F892, U+10788, U+1078B, U+1078D, U+1079D, U+1079F, U+107A7-107A8, U+107AD, U+107AF, U+107B9,
|
||||
U+1DF05, U+1DF08-1DF0A, U+1DF12-1DF1D;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Menlo";
|
||||
src: local("Menlo Regular"), local("Menlo-Regular"), local("DejaVu Sans Mono");
|
||||
font-weight: 100 500;
|
||||
size-adjust: 99.66%;
|
||||
ascent-override: 96.83%;
|
||||
descent-override: 22.08%;
|
||||
line-gap-override: 6.52%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Menlo";
|
||||
src: local("Menlo Bold"), local("DejaVu Sans Mono Bold");
|
||||
font-weight: 600 900;
|
||||
size-adjust: 99.66%;
|
||||
ascent-override: 96.83%;
|
||||
descent-override: 22.08%;
|
||||
line-gap-override: 6.52%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Consolas";
|
||||
src: local("Consolas");
|
||||
font-weight: 100 500;
|
||||
size-adjust: 109.13%;
|
||||
ascent-override: 88.43%;
|
||||
descent-override: 26.12%;
|
||||
line-gap-override: 0%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Consolas";
|
||||
src: local("Consolas Bold");
|
||||
font-weight: 600 900;
|
||||
size-adjust: 109.13%;
|
||||
ascent-override: 88.43%;
|
||||
descent-override: 26.12%;
|
||||
line-gap-override: 0%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Courier";
|
||||
src: local("Courier New");
|
||||
font-weight: 100 500;
|
||||
size-adjust: 99.98%;
|
||||
ascent-override: 96.52%;
|
||||
descent-override: 28.5%;
|
||||
line-gap-override: 0%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "OpenTUI Mono Courier";
|
||||
src: local("Courier New Bold");
|
||||
font-weight: 600 900;
|
||||
size-adjust: 99.98%;
|
||||
ascent-override: 96.52%;
|
||||
descent-override: 28.5%;
|
||||
line-gap-override: 0%;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
src:
|
||||
local("Inter"),
|
||||
local("Inter Variable"),
|
||||
url("../asset/fonts/inter-rest.woff2") format("woff2");
|
||||
font-weight: 100 900;
|
||||
font-display: optional;
|
||||
unicode-range:
|
||||
U+0180-0191, U+0193-0217, U+021C-0236, U+0238-02BA, U+02BD-02C5, U+02C8, U+02CA-02D7, U+02DE-02FF, U+0309,
|
||||
U+030D-0325, U+032A-058F, U+0E3F, U+1D00-1E9D, U+1E9F-1FFF, U+2070-20AB, U+20AD-20B8, U+20BA-20BC, U+20BE-2112,
|
||||
U+2114-2115, U+2117-2121, U+2123-2125, U+2127-212D, U+212F-218F, U+2200-2211, U+2213-2214, U+2216-2218, U+221A-221D,
|
||||
U+221F-2247, U+2249-225F, U+2261-2263, U+2266-2302, U+2304-2317, U+2319-2324, U+2326-232A, U+232C-238A, U+238C-23CD,
|
||||
U+23CF-259F, U+2600-2712, U+2714, U+2716-2E7F, U+A640-A9FF, U+E000-F8FF;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
src:
|
||||
local("Inter"),
|
||||
local("Inter Variable"),
|
||||
url("../asset/fonts/inter-latin.woff2") format("woff2");
|
||||
font-weight: 100 900;
|
||||
font-display: optional;
|
||||
unicode-range:
|
||||
U+0000-017F, U+0192, U+0218-021B, U+0237, U+02BB-02BC, U+02C6-02C7, U+02C9, U+02D8-02DD, U+0300-0308, U+030A-030C,
|
||||
U+0326-0329, U+1E9E, U+2000-206F, U+20AC, U+20B9, U+20BD, U+2113, U+2116, U+2122, U+2126, U+212E, U+2190-21FF,
|
||||
U+2212, U+2215, U+2219, U+221E, U+2248, U+2260, U+2264-2265, U+2303, U+2318, U+2325, U+232B, U+238B, U+23CE,
|
||||
U+25A0-25FF, U+2713, U+2715, U+FB01-FB02, U+FEFF, U+FFFD;
|
||||
}
|
||||
@@ -1,9 +1,48 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import path from "node:path"
|
||||
import { preprocessCSS, resolveConfig } from "vite"
|
||||
import { cssVariants } from "~/component/site/css-variants"
|
||||
import variants from "~/component/site/css-variants.json"
|
||||
import { cssVariantsForProduction } from "../script/css-variants-plugin"
|
||||
|
||||
// The production build drops CSS for every settings value but these (script/css-variants-plugin.ts), so they must
|
||||
// be what production renders. Regenerate with `bun script/css-variants.ts`.
|
||||
test("css-variants.json matches the default settings", () => {
|
||||
expect(variants as Record<string, string | null>).toEqual(cssVariants())
|
||||
expect(variants as unknown).toEqual(cssVariants())
|
||||
})
|
||||
|
||||
const config = resolveConfig({ configFile: false, logLevel: "silent", plugins: [cssVariantsForProduction()] }, "build")
|
||||
const production = async (css: string) =>
|
||||
(await preprocessCSS(css, path.join(import.meta.dir, "fixture.css"), await config)).code.replace(/\s+/g, " ").trim()
|
||||
|
||||
test("production drops the CSS for other values of an element's settings attribute, nested rules too", async () => {
|
||||
// Card tone is "color" by default (settings-defaults.json); the root's logo is "icon".
|
||||
const css = await production(`
|
||||
[data-site] [data-component="products"] {
|
||||
&[data-tone="color"] a { color: red }
|
||||
&[data-tone="mono"] a { color: blue }
|
||||
&:not([data-tone="mono"]) b { color: green }
|
||||
[data-slot="media"] { &[data-active], [data-component="products"][data-tone="mono"] & { color: pink } }
|
||||
}
|
||||
[data-site]:is([data-logo="wordmark"], [data-logo="lockup"]) i { color: gray }
|
||||
[data-tone="mono"] u { color: teal }
|
||||
`)
|
||||
expect(css).toContain('&[data-tone="color"] a')
|
||||
expect(css).not.toContain('&[data-tone="mono"] a')
|
||||
expect(css).toContain(':not([data-tone="mono"]) b')
|
||||
expect(css).toContain('[data-slot="media"] { &[data-active] { color: pink } }')
|
||||
expect(css).not.toContain("gray")
|
||||
// Another element's data-tone is left alone.
|
||||
expect(css).toContain('[data-tone="mono"] u')
|
||||
})
|
||||
|
||||
test("production drops the @keyframes nothing animates with any more", async () => {
|
||||
const css = await production(`
|
||||
@keyframes css-variants-test-kept { to { opacity: 1 } }
|
||||
@keyframes css-variants-test-dropped { to { opacity: 0 } }
|
||||
a { animation: css-variants-test-kept 1s }
|
||||
[data-site][data-logo="wordmark"] a { animation: css-variants-test-dropped 1s }
|
||||
`)
|
||||
expect(css).toContain("@keyframes css-variants-test-kept")
|
||||
expect(css).not.toContain("css-variants-test-dropped")
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import path from "node:path"
|
||||
import { interFaces } from "~/component/site/inter-fonts"
|
||||
import { monoFontFaces } from "~/component/site/mono-fonts"
|
||||
|
||||
const root = path.resolve(import.meta.dir, "..")
|
||||
// The licensed mono face the site used before OpenTUI Mono, and its foundry. Built from parts so
|
||||
@@ -35,4 +37,19 @@ describe("fonts", () => {
|
||||
expect(Object.keys(ranges)).toEqual(["latin", "rest"])
|
||||
expect(await Bun.file(path.join(root, "src/asset/fonts/OpenTUIMono-OFL.txt")).exists()).toBe(true)
|
||||
})
|
||||
|
||||
test("the stylesheet's faces are the ones mono-fonts.ts and inter-fonts.ts describe", async () => {
|
||||
// Each face's declarations, with a font file named by its file name alone and numbers as numbers.
|
||||
const faces = (css: string) =>
|
||||
[...css.matchAll(/@font-face \{([^}]*)\}/g)].map((face) =>
|
||||
face[1]
|
||||
.replace(/url\("?[^)"]*[\\/]([\w-]+\.woff2)"?\)/g, "url($1)")
|
||||
.replace(/\d+\.\d+/g, (number) => String(Number(number)))
|
||||
.split(";")
|
||||
.map((declaration) => declaration.trim().replace(/\s+/g, " "))
|
||||
.filter(Boolean),
|
||||
)
|
||||
const css = await Bun.file(path.join(root, "src/style/fonts.css")).text()
|
||||
expect(faces(css)).toEqual(faces(`${monoFontFaces}\n${interFaces}`))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { pageHead } from "~/lib/head-links"
|
||||
|
||||
const css = (name: string) => `<link href="/_build/assets/${name}.css" rel="stylesheet" />`
|
||||
const js = (name: string) => `<link href="/_build/assets/${name}.js" rel="modulepreload" />`
|
||||
|
||||
test("a page's stylesheets stay as they are and are named in its Link header", () => {
|
||||
const html = `<html><head>${css("shell-a")}${css("home-b")}${js("entry")}</head><body>${css("late")}</body></html>`
|
||||
const page = pageHead(html)
|
||||
expect(page.html).toContain(`${css("shell-a")}${css("home-b")}`)
|
||||
expect(page.link).toBe(
|
||||
"</_build/assets/shell-a.css>; rel=preload; as=style, </_build/assets/home-b.css>; rel=preload; as=style",
|
||||
)
|
||||
})
|
||||
|
||||
test("module preloads in the head start at low priority", () => {
|
||||
const page = pageHead(`<head>${js("entry")}</head><body>${js("body")}</body>`)
|
||||
expect(page.html).toBe(
|
||||
`<head><link href="/_build/assets/entry.js" rel="modulepreload" fetchpriority="low" /></head><body>${js("body")}</body>`,
|
||||
)
|
||||
expect(page.link).toBeUndefined()
|
||||
})
|
||||
@@ -1,35 +0,0 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { combineStylesheets } from "~/lib/one-stylesheet"
|
||||
|
||||
const css = (name: string) => `<link href="/_build/assets/${name}.css" rel="stylesheet" />`
|
||||
const js = `<link href="/_build/assets/a.js" rel="modulepreload" />`
|
||||
|
||||
test("a page's stylesheets become one link, with no disabled link in the HTML", () => {
|
||||
const html = combineStylesheets(`<html><head>${css("a")}${js}${css("b")}</head><body>${css("c")}</body></html>`)
|
||||
expect(html).toBe(
|
||||
`<html><head><script data-css="a~b">${html.match(/<script data-css="a~b">(.*?)<\/script>/)![1]}</script>` +
|
||||
`<link rel="stylesheet" href="/stylesheet/a~b.css" />${js}</head><body>${css("c")}</body></html>`,
|
||||
)
|
||||
expect(html).not.toMatch(/<link[^>]*disabled/)
|
||||
})
|
||||
|
||||
test("the script adds each original link, disabled, for the chunk loader", () => {
|
||||
const html = combineStylesheets(`<head>${css("a")}${css("b")}</head>`)
|
||||
const script = html.match(/<script data-css="([^"]+)">(.*?)<\/script>/)!
|
||||
const added: { rel: string; disabled: boolean; href: string }[] = []
|
||||
const document = {
|
||||
currentScript: { dataset: { css: script[1] } },
|
||||
createElement: () => ({ rel: "", disabled: false, href: "" }),
|
||||
head: { appendChild: (link: (typeof added)[number]) => added.push(link) },
|
||||
}
|
||||
new Function("document", script[2])(document)
|
||||
expect(added).toEqual([
|
||||
{ rel: "stylesheet", disabled: true, href: "/_build/assets/a.css" },
|
||||
{ rel: "stylesheet", disabled: true, href: "/_build/assets/b.css" },
|
||||
])
|
||||
})
|
||||
|
||||
test("stylesheets with an inline style between them are left alone", () => {
|
||||
const html = `<head>${css("a")}<style>p{}</style>${css("b")}</head>`
|
||||
expect(combineStylesheets(html)).toBe(html)
|
||||
})
|
||||
@@ -6,6 +6,7 @@ import { docs } from "./src/docs/vite"
|
||||
import { i18nSlices } from "./script/i18n-plugin"
|
||||
import { foldSettingsForProduction } from "./script/fold-settings"
|
||||
import { cssVariantsForProduction, devOnlyCss } from "./script/css-variants-plugin"
|
||||
import { stylesheetGroups } from "./script/stylesheet-groups"
|
||||
|
||||
// Nitro's dev server drops any page the app renders with a 404 status and falls through to a bare
|
||||
// "Cannot GET". In development only, serve the not-found page's preview (/dev/404, which follows
|
||||
@@ -56,6 +57,7 @@ export default defineConfig({
|
||||
notFoundInDev(),
|
||||
devOnlyCss(),
|
||||
cssVariantsForProduction(),
|
||||
stylesheetGroups(),
|
||||
docs(),
|
||||
i18nSlices(),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user