diff --git a/brand/README.md b/brand/README.md
index 0aa7ddbad..8dd789aee 100644
--- a/brand/README.md
+++ b/brand/README.md
@@ -25,6 +25,19 @@ add the beam, a screen, or effects to the mark.
The mark is part of this repository and is licensed with it (MIT), and so is its
glyph in the VS Code icon font (below).
+## Social preview
+
+`social-preview.png` (dark) and `social-preview-light.png` are drawn by
+`tools/scripts/social-preview.mjs` (`npm run social-preview`;
+`npm run check:social-preview` fails when either is out of date). The script
+holds the slogan, the colours and the scene: the mark at 10× with its glass
+glowing, a beam through dust, and the wordmark and slogan in Projector Sans, the
+renderer SDK's vendored font. It needs no browser, and it writes the same bytes
+on every machine. Don't edit the images by hand: change the script and run it.
+
+GitHub doesn't read the image from the repository. After a change, upload the
+dark one in the repository's Settings → Social preview.
+
## Part icons
`parts/` holds the icons of a projection's three parts, drawn from one geometry
diff --git a/brand/social-preview-light.png b/brand/social-preview-light.png
index a0bc14a34..0bb8bac59 100644
Binary files a/brand/social-preview-light.png and b/brand/social-preview-light.png differ
diff --git a/brand/social-preview.png b/brand/social-preview.png
index 9fd265cb5..9850d063a 100644
Binary files a/brand/social-preview.png and b/brand/social-preview.png differ
diff --git a/package-lock.json b/package-lock.json
index 785135485..aaa68a535 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -30,6 +30,7 @@
"devDependencies": {
"@eslint-react/eslint-plugin": "^5.30.1",
"@eslint/js": "^10.0.1",
+ "@resvg/resvg-wasm": "^2.6.2",
"@types/node": "^22.18.0",
"ajv": "^8.17.1",
"eslint": "^10.13.0",
@@ -39,6 +40,7 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-regexp": "^3.3.3",
"eslint-plugin-unicorn": "^79.0.0",
+ "fontkit": "^3.0.0",
"globals": "^17.12.0",
"oxfmt": "^0.75.0",
"stylelint": "^18.1.0",
@@ -3704,6 +3706,16 @@
"integrity": "sha512-JtyZR+mqgBibTo8xea3B6ZRmzZiM/YeVBtUkas6zMuXjAlfIFIW2FgqeM9eLyvEaYX66vr6DJMK+4U6LV0KhNw==",
"license": "MIT"
},
+ "node_modules/@resvg/resvg-wasm": {
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/@resvg/resvg-wasm/-/resvg-wasm-2.6.2.tgz",
+ "integrity": "sha1-Eoumvgmpr3dssBs+eVfVaAck6zQ=",
+ "dev": true,
+ "license": "MPL-2.0",
+ "engines": {
+ "node": ">= 10"
+ }
+ },
"node_modules/@rolldown/binding-android-arm-eabi": {
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.16.tgz",
@@ -6106,6 +6118,27 @@
"node": "18 || 20 || >=22"
}
},
+ "node_modules/base64-js": {
+ "version": "1.5.1",
+ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
+ "integrity": "sha1-GxtEAWClv3rUC2UPCVljSBkDkwo=",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/feross"
+ },
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/feross"
+ },
+ {
+ "type": "consulting",
+ "url": "https://feross.org/support"
+ }
+ ],
+ "license": "MIT"
+ },
"node_modules/baseline-browser-mapping": {
"version": "2.11.34",
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.34.tgz",
@@ -6132,6 +6165,16 @@
"node": "20 || >=22"
}
},
+ "node_modules/brotli": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/brotli/-/brotli-2.1.0.tgz",
+ "integrity": "sha512-4KAtOr4Z3jaIQlXy9AeuaVz1vPWTyZ6eiQYu4SsSz6VcUsV6Epz6kA3Vf7eTGTaspaqlnQLBqvkozKP5WyQMZQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "base64-js": "^1.5.1"
+ }
+ },
"node_modules/browserslist": {
"version": "4.29.5",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.5.tgz",
@@ -6542,6 +6585,13 @@
"integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==",
"license": "MIT"
},
+ "node_modules/dfa": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/dfa/-/dfa-2.0.0.tgz",
+ "integrity": "sha512-4Z/ig4JY/6CyXaPvkjuJu7q5+6SikugixA/1wf/52A9Z+WOJr8NFKd60pv6KCwsdVdDmCCE3JrGwPFYxNcw8xw==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/doctrine": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
@@ -7149,6 +7199,13 @@
}
}
},
+ "node_modules/fflate": {
+ "version": "0.8.3",
+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",
+ "integrity": "sha1-vCfY6zA0PU1RKrsDSAICzmXYJfw=",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/file-entry-cache": {
"version": "11.1.5",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-11.1.5.tgz",
@@ -7214,6 +7271,21 @@
"dev": true,
"license": "ISC"
},
+ "node_modules/fontkit": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/fontkit/-/fontkit-3.0.0.tgz",
+ "integrity": "sha512-sjSkmtEw6RYJcvEbd+LHHLp2HFDaXdAia2RTbaGcBu/5QaDhxz35249eH9G07E0PzrtlkPF9FYXHF6YXxcAa1w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "brotli": "^2.1.0",
+ "dfa": "^2.0.0",
+ "fflate": "^0.8.3",
+ "restructure": "^3.0.2",
+ "unicode-properties": "^2.0.1",
+ "unicode-trie": "^3.0.0"
+ }
+ },
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -9245,6 +9317,13 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/restructure": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/restructure/-/restructure-3.0.2.tgz",
+ "integrity": "sha1-5rL60hT3jt7iF5f6gWD+9Q65tJo=",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/rolldown": {
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.16.tgz",
@@ -10117,6 +10196,29 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/unicode-properties": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/unicode-properties/-/unicode-properties-2.0.2.tgz",
+ "integrity": "sha512-7MWOxBC6aT/+xeMKjdnp3GEuAMLmu0uRGD3jAN3PrGnjKynnellVkvQ6OYdeSIBwSdo67+zvgs1//7Qenb9iSA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "unicode-trie": "^3.0.0"
+ }
+ },
+ "node_modules/unicode-trie": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-3.0.0.tgz",
+ "integrity": "sha512-Cy+7EIpopVQ7ZCVZ8dFo1fmTk1lHMNxY62SeEhxsVEmISZEryEGgKSLzz6z6pquJXXopamfpi2AzsDCJ7KmAOA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "fflate": "^0.8.3"
+ },
+ "engines": {
+ "node": ">=20.17.0"
+ }
+ },
"node_modules/unrs-resolver": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/unrs-resolver/-/unrs-resolver-1.13.0.tgz",
diff --git a/package.json b/package.json
index bc06ded60..ee1d2a7c8 100644
--- a/package.json
+++ b/package.json
@@ -44,6 +44,7 @@
"typecheck": "node tools/scripts/workspaces.mjs typecheck",
"lint": "node tools/scripts/lint.mjs --quiet",
"icons": "node tools/scripts/product-icons.mjs",
+ "social-preview": "node tools/scripts/social-preview.mjs",
"format": "oxfmt",
"format:check": "oxfmt --check",
"check:boundaries": "node --test tools/scripts/engine-contracts.test.mjs && node tools/scripts/check-boundaries.mjs",
@@ -57,6 +58,7 @@
"check:readmes": "node tools/cli/src/bin.ts check --only readmes",
"check:links": "node tools/cli/src/bin.ts check --only links",
"check:icons": "node tools/scripts/product-icons.mjs --check",
+ "check:social-preview": "node tools/scripts/social-preview.mjs --check",
"check:considered": "node --test tools/scripts/considered-variances.test.mjs && node tools/scripts/considered.mjs check",
"check:machines": "node --test tools/scripts/check-machines.test.mjs && node tools/scripts/check-machines.mjs",
"check:tsdoc": "node tools/scripts/reference-docs.mjs --check --only tsdoc",
@@ -65,7 +67,7 @@
"check:changelog": "node tools/cli/src/bin.ts check --only changelog",
"considered": "node tools/scripts/considered.mjs",
"check": "npm run check:no-test && npm test",
- "check:no-test": "npm run check:boundaries && npm run check:casing && npm run check:portability && npm run check:silent-failures && npm run check:styles && npm run check:change-hues && npm run check:readmes && npm run check:links && npm run check:icons && npm run check:considered && npm run check:machines && npm run check:tsdoc && npm run check:versions && npm run check:changelog && npm run check:lockfile && npm run format:check && npm run build && npm run check:notices && npm run check:comparators && npm run typecheck && npm run lint",
+ "check:no-test": "npm run check:boundaries && npm run check:casing && npm run check:portability && npm run check:silent-failures && npm run check:styles && npm run check:change-hues && npm run check:readmes && npm run check:links && npm run check:icons && npm run check:social-preview && npm run check:considered && npm run check:machines && npm run check:tsdoc && npm run check:versions && npm run check:changelog && npm run check:lockfile && npm run format:check && npm run build && npm run check:notices && npm run check:comparators && npm run typecheck && npm run lint",
"storybook": "npm run storybook --workspace @githubnext/projections-storybook",
"docs:generate": "node tools/scripts/reference-docs.mjs",
"docs:check": "node --test tools/scripts/reference-docs/agents.test.mjs && node tools/scripts/reference-docs.mjs --check",
@@ -75,6 +77,7 @@
"devDependencies": {
"@eslint-react/eslint-plugin": "^5.30.1",
"@eslint/js": "^10.0.1",
+ "@resvg/resvg-wasm": "^2.6.2",
"@types/node": "^22.18.0",
"ajv": "^8.17.1",
"eslint": "^10.13.0",
@@ -84,6 +87,7 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-regexp": "^3.3.3",
"eslint-plugin-unicorn": "^79.0.0",
+ "fontkit": "^3.0.0",
"globals": "^17.12.0",
"oxfmt": "^0.75.0",
"stylelint": "^18.1.0",
diff --git a/tools/cli/src/lib/gates.ts b/tools/cli/src/lib/gates.ts
index 3fef6d0d6..b7f69fca3 100644
--- a/tools/cli/src/lib/gates.ts
+++ b/tools/cli/src/lib/gates.ts
@@ -113,6 +113,13 @@ export const gates: Gate[] = [
plan: () => ({commands: [npm('run', '--silent', 'check:icons')]}),
fix: 'npm run icons',
},
+ {
+ name: 'social-preview',
+ fast: true,
+ description: 'The repository social preview images are current (npm run check:social-preview)',
+ plan: () => ({commands: [npm('run', '--silent', 'check:social-preview')]}),
+ fix: 'npm run social-preview',
+ },
{
name: 'considered',
fast: true,
diff --git a/tools/cli/src/lib/generated.ts b/tools/cli/src/lib/generated.ts
index 58e178afe..83c3f448c 100644
--- a/tools/cli/src/lib/generated.ts
+++ b/tools/cli/src/lib/generated.ts
@@ -127,6 +127,16 @@ export const generators: Generator[] = [
needs: [],
fix: true,
},
+ {
+ name: 'social-preview',
+ description: 'The repository social preview, brand/social-preview.png (dark) and brand/social-preview-light.png',
+ outputs: ['brand/social-preview.png', 'brand/social-preview-light.png'],
+ inputs: ['tools/scripts/social-preview.mjs', 'packages/renderers/sdk/vendor/fonts/projector-sans.woff2'],
+ generate: [npm('run', 'social-preview')],
+ check: {mode: 'script', commands: [npm('run', 'check:social-preview')]},
+ needs: [],
+ fix: true,
+ },
{
name: 'codicon-tokens',
description: 'packages/host/vscode-ui/src/icons.generated.ts: the renderer icon tokens as codicons',
diff --git a/tools/scripts/social-preview.mjs b/tools/scripts/social-preview.mjs
new file mode 100644
index 000000000..b8bf53c50
--- /dev/null
+++ b/tools/scripts/social-preview.mjs
@@ -0,0 +1,234 @@
+#!/usr/bin/env node
+// Draws the repository's social preview, brand/social-preview.png (dark) and brand/social-preview-light.png, 1280×640:
+// the two-tone mark with its glass glowing and a beam projected up and to the right through drifting dust, the
+// wordmark beside it and the slogan below, in Projector Sans. Change the words or the scene here and run it again:
+//
+// node tools/scripts/social-preview.mjs write them (npm run social-preview)
+// node tools/scripts/social-preview.mjs --check fail if either is out of date (npm run check:social-preview)
+//
+// No browser: the whole scene is one SVG, rasterized by resvg's WebAssembly build. The text is drawn as glyph paths
+// that fontkit reads from the renderer SDK's vendored font (a variable WOFF2), instanced at weights 400 and 700 and
+// shaped with its kerning, so the font has one source and nothing depends on the machine's fonts. Every step is
+// plain JavaScript or WebAssembly, so the images are the same bytes on every machine and CI can check them. After a
+// change, upload the dark image in the repository's Settings → Social preview.
+import {readFile, writeFile} from 'node:fs/promises'
+import {createRequire} from 'node:module'
+import {fileURLToPath, pathToFileURL} from 'node:url'
+import {initWasm, Resvg} from '@resvg/resvg-wasm'
+import * as fontkit from 'fontkit'
+
+const root = new URL('../../', import.meta.url)
+const fontFile = new URL('packages/renderers/sdk/vendor/fonts/projector-sans.woff2', root)
+
+/** The slogan, one line per entry. */
+export const slogan = ['Review code changes', 'without reviewing code']
+
+export const size = {width: 1280, height: 640}
+
+/** Each theme's colours: the mark's body and glass (brand/README.md), the slogan, the backdrop, the beam and the dust. */
+const themes = {
+ dark: {
+ file: 'brand/social-preview.png',
+ body: '#f6f5f2',
+ glass: '#3dbfe2',
+ slogan: '#d0d2d6',
+ backdrop: ['#0b0c0d', '#030404'],
+ beam: '#d8f6ff',
+ beamOpacity: 0.42,
+ dust: '#c4ccd0',
+ dustOpacity: 0.55,
+ },
+ light: {
+ file: 'brand/social-preview-light.png',
+ body: '#1a1b1c',
+ glass: '#007798',
+ slogan: '#3a3b3e',
+ backdrop: ['#c6c4bf', '#a9a7a1'],
+ beam: '#f4fdff',
+ beamOpacity: 0.8,
+ dust: '#7d8284',
+ dustOpacity: 0.55,
+ },
+}
+
+/**
+ * The lockup and the slogan, in pixels. The mark is drawn on its 16px grid at a whole multiple, as brand/README.md
+ * asks, with its housing on the wordmark's baseline. The block from the wordmark's cap height to the slogan's last
+ * baseline is centred, `lift` above the middle, and the lockup and each slogan line are centred on their ink.
+ */
+const type = {
+ markScale: 10,
+ gap: 48,
+ wordmark: {weight: 700, size: 154, tracking: -0.001},
+ slogan: {weight: 500, size: 60, firstBaseline: 132, leading: 84},
+ lift: -6,
+}
+
+/** The mark's geometry, from brand/projections-mark-two-tone.svg: its body, the glass and their ink on the grid. */
+const mark = {
+ body: [
+ 'M3 6h2.5a.5.5 0 0 1 0 1H3a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V9.5a.5.5 0 0 1 1 0V12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2Z',
+ 'M10.5 2a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7Zm0 1.5a2 2 0 1 1 0 4 2 2 0 0 1 0-4Z',
+ 'M4.5 9h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1ZM3 13h2v1a1 1 0 0 1-2 0v-1Zm8 0h2v1a1 1 0 0 1-2 0v-1Z',
+ ],
+ lens: {x: 10.5, y: 5.5, r: 1.25},
+ ink: {left: 1, right: 15},
+ baseline: 14,
+}
+
+/** The beam leaves the lens at `angle` degrees above the horizontal and opens to `spread` degrees either side. */
+const beam = {angle: 12, spread: 22, length: 1100}
+
+/** A small seeded generator, so the dust lands in the same places every run. */
+function random(seed) {
+ let state = seed >>> 0
+ return () => {
+ state = (state + 0x6d2b79f5) >>> 0
+ let t = state
+ t = Math.imul(t ^ (t >>> 15), t | 1)
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296
+ }
+}
+
+/** Dust motes inside the beam: polar positions from the lens, sizes and opacities, the same every run. */
+function dust(count = 46) {
+ const next = random(20261204)
+ return Array.from({length: count}, () => {
+ const distance = 170 + next() * 900
+ const offset = (next() * 2 - 1) * beam.spread * 0.95
+ return {distance, offset, radius: 1 + next() ** 2 * 3.5, opacity: 0.35 + next() * 0.65}
+ })
+}
+
+/** `value` rounded to `digits` decimals, as SVG text. */
+const number = (value, digits = 2) => String(Math.round(value * 10 ** digits) / 10 ** digits)
+
+/**
+ * One line of text, shaped at `weight` and `size` pixels with `tracking` em between letters: its ink extent from the
+ * origin, and `path(x, baseline)`, its glyph outlines as SVG path data with the origin at (x, baseline).
+ */
+function shape(font, text, {weight, size: pixels, tracking = 0}) {
+ const instance = font.getVariation({wght: weight})
+ const scale = pixels / instance.unitsPerEm
+ // Like CSS, letter-spacing turns optional ligatures off.
+ const run = instance.layout(text, tracking ? {liga: false} : {})
+ const glyphs = []
+ let pen = 0
+ for (const [index, glyph] of run.glyphs.entries()) {
+ const position = run.positions[index]
+ glyphs.push({glyph, x: pen + position.xOffset, y: position.yOffset})
+ pen += position.xAdvance + tracking * instance.unitsPerEm
+ }
+ const left = Math.min(...glyphs.map(({glyph, x}) => x + glyph.bbox.minX)) * scale
+ const right = Math.max(...glyphs.map(({glyph, x}) => x + glyph.bbox.maxX)) * scale
+ const path = (originX, baseline) =>
+ glyphs
+ .map(({glyph, x, y}) =>
+ glyph.path.commands
+ .map(({command, args}) => {
+ const points = []
+ for (let i = 0; i < args.length; i += 2) {
+ points.push(number(originX + (x + args[i]) * scale), number(baseline - (y + args[i + 1]) * scale))
+ }
+ return {moveTo: 'M', lineTo: 'L', quadraticCurveTo: 'Q', bezierCurveTo: 'C', closePath: 'Z'}[command] + points.join(' ')
+ })
+ .join(''),
+ )
+ .join('')
+ return {left, right, width: right - left, capHeight: instance.capHeight * scale, path}
+}
+
+/** The scene's SVG for `theme`. */
+export function draw(font, theme) {
+ const {markScale: unit} = type
+ const wordmark = shape(font, 'Projections', type.wordmark)
+ const lines = slogan.map(text => shape(font, text, type.slogan))
+
+ const top = -wordmark.capHeight
+ const bottom = type.slogan.firstBaseline + (lines.length - 1) * type.slogan.leading
+ const baseline = Math.round(size.height / 2 - type.lift - (top + bottom) / 2)
+ const lockupWidth = (mark.ink.right - mark.ink.left) * unit + type.gap + wordmark.width
+ const markX = Math.round((size.width - lockupWidth) / 2) - mark.ink.left * unit
+ const markY = baseline - mark.baseline * unit
+ const wordmarkX = markX + mark.ink.right * unit + type.gap - wordmark.left
+
+ const x = markX + mark.lens.x * unit
+ const y = markY + mark.lens.y * unit
+ const radians = degrees => (degrees * Math.PI) / 180
+ const ray = (degrees, length) => [x + Math.cos(radians(degrees)) * length, y - Math.sin(radians(degrees)) * length]
+ const points = (...rays) =>
+ [[x, y], ...rays.map(([degrees, length]) => ray(degrees, length))].map(p => p.map(v => number(v)).join(',')).join(' ')
+ const glow = 7 * unit
+ const motes = dust()
+ .map(({distance, offset, radius, opacity}) => {
+ const [dx, dy] = ray(beam.angle + offset, distance)
+ const fade = 1 - Math.abs(offset) / beam.spread / 2
+ return ``
+ })
+ .join('')
+ const stop = (offset, color, opacity) => ``
+
+ return `
+`
+}
+
+/** The images, by path from the repository root. */
+export async function render() {
+ await initWasm(readFile(createRequire(import.meta.url).resolve('@resvg/resvg-wasm/index_bg.wasm')))
+ const font = fontkit.create(await readFile(fontFile))
+ return Object.fromEntries(
+ Object.values(themes).map(theme => [
+ theme.file,
+ Buffer.from(new Resvg(draw(font, theme), {font: {loadSystemFonts: false}}).render().asPng()),
+ ]),
+ )
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
+ const check = process.argv.includes('--check')
+ const stale = []
+ for (const [path, image] of Object.entries(await render())) {
+ const file = new URL(path, root)
+ // A missing image is out of date; any other read error is reported.
+ const current = await readFile(file).catch(error => {
+ if (error.code === 'ENOENT') return null
+ throw error
+ })
+ if (current?.equals(image)) continue
+ if (check) stale.push(path)
+ else {
+ await writeFile(file, image)
+ console.log(`wrote ${fileURLToPath(file)}`)
+ }
+ }
+ if (stale.length) {
+ console.error(`Out of date (run npm run social-preview): ${stale.join(', ')}`)
+ process.exit(1)
+ }
+}