Theme engine v2, the document side: component tokens, layout variants, decoration, icon packs
A theme may now say how each piece of a site is built, not only one radius and one density: - components (themeComponents.ts): 36 generic parts with clamped tokens (radius, border incl. 98.css-style bevels, fill by color role / glass / gradient, padding, sizes, type, shadow, shape, hover/active/focus), presets and parents; compiled over a site's part map as soft values (--wb-part-*) and rigid rules; text on a chosen fill keeps its contrast. - variants (themeVariants.ts): fixed words on six axes; the owner holds an axis or switches layout changes off; the look of a variant is the site's skin. - decoration (themeDecor.ts): dividers, chrome (title bar, masthead, prompt), a focus ring that is always visible, selection, scrollbars, links, motion under reduced-motion. - icon packs (themeIcons.ts): a standalone document of glyphs by semantic name (path data, colored layers or a small PNG, never an SVG document), with license, source and credits; a theme only names a pack; the owner's icon choice is separate; drawn as CSS masks of the current color over the site's own svg boxes, behind forced-colors and mask-support guards, per group. - a theme document gains the optional groups components, variants, decor, icons and colors.actions; a theme without them is sanitized to exactly what it was. - theme.schema.json and the new icons.schema.json are generated from the same tables (scripts/theme-schema.mjs; a test fails when they are stale).
This commit is contained in:
parent
507cd95d8e
commit
582c3d9460
12 changed files with 6689 additions and 88 deletions
646
packages/waybetter/icons.schema.json
Normal file
646
packages/waybetter/icons.schema.json
Normal file
|
|
@ -0,0 +1,646 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://unpkg.com/waybetter/icons.schema.json",
|
||||
"title": "wayBetter icon pack",
|
||||
"description": "Glyphs by semantic name, drawn over a site's own icons. Path data, colored layers of path data, or small PNGs: never an SVG document.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"license",
|
||||
"glyphs"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9-]{1,40}$"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 60
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 200
|
||||
},
|
||||
"author": {
|
||||
"type": "string",
|
||||
"maxLength": 60
|
||||
},
|
||||
"license": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 60,
|
||||
"description": "SPDX id, \"own\" for the author's own drawings, or a plain name for artwork under other terms."
|
||||
},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"maxLength": 200
|
||||
},
|
||||
"credits": {
|
||||
"type": "string",
|
||||
"maxLength": 400
|
||||
},
|
||||
"version": {
|
||||
"const": 1
|
||||
},
|
||||
"style": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"stroke": {
|
||||
"type": "number",
|
||||
"minimum": 1,
|
||||
"maximum": 2.5
|
||||
},
|
||||
"cap": {
|
||||
"enum": [
|
||||
"round",
|
||||
"square",
|
||||
"butt"
|
||||
]
|
||||
},
|
||||
"join": {
|
||||
"enum": [
|
||||
"round",
|
||||
"miter",
|
||||
"bevel"
|
||||
]
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.8,
|
||||
"maximum": 1.25
|
||||
}
|
||||
}
|
||||
},
|
||||
"glyphs": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"home": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"home.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"explore": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"explore.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"notifications": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"notifications.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"messages": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"messages.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"grok": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"bookmarks": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"bookmarks.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"lists": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"communities": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"premium": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"profile": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"profile.active": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"more": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"compose": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"reply": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"repost": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"repost.on": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"like": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"like.on": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"views": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"bookmark": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"bookmark.on": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"share": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"verified": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"logo": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"caret": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"back": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"close": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"search": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"settings": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"media": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"gif": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"poll": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"emoji": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"schedule": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"location": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"pinned": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"repostContext": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
},
|
||||
"lock": {
|
||||
"$ref": "#/$defs/glyph"
|
||||
}
|
||||
},
|
||||
"maxProperties": 64,
|
||||
"minProperties": 1
|
||||
},
|
||||
"symbols": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"like": {
|
||||
"enum": [
|
||||
"heart",
|
||||
"star",
|
||||
"custom"
|
||||
]
|
||||
},
|
||||
"separator": {
|
||||
"enum": [
|
||||
"dot",
|
||||
"bullet",
|
||||
"slash",
|
||||
"dash",
|
||||
"pipe",
|
||||
"none"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"reply": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
},
|
||||
"repost": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
},
|
||||
"like": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
},
|
||||
"views": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
},
|
||||
"bookmark": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
},
|
||||
"share": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 12,
|
||||
"pattern": "^[^\\u0000-\\u001f\"\\\\<>&{};'`]+$"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"hex": {
|
||||
"type": "string",
|
||||
"pattern": "^#[0-9a-fA-F]{6}$"
|
||||
},
|
||||
"role": {
|
||||
"description": "A color role of the theme. Components never carry a color literal.",
|
||||
"enum": [
|
||||
"bg",
|
||||
"surface",
|
||||
"elevated",
|
||||
"page",
|
||||
"border",
|
||||
"text",
|
||||
"muted",
|
||||
"accent",
|
||||
"onAccent",
|
||||
"inverse",
|
||||
"onInverse"
|
||||
]
|
||||
},
|
||||
"fontRoleName": {
|
||||
"enum": [
|
||||
"interface",
|
||||
"post",
|
||||
"heading",
|
||||
"numbers",
|
||||
"mono",
|
||||
"chrome",
|
||||
"dialog"
|
||||
]
|
||||
},
|
||||
"shadow": {
|
||||
"enum": [
|
||||
"none",
|
||||
"soft",
|
||||
"deep",
|
||||
"hard",
|
||||
"inset",
|
||||
"glow"
|
||||
]
|
||||
},
|
||||
"fill": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
{
|
||||
"const": "transparent"
|
||||
}
|
||||
]
|
||||
},
|
||||
"state": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"fill": {
|
||||
"$ref": "#/$defs/fill"
|
||||
},
|
||||
"text": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"borderColor": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"shadow": {
|
||||
"$ref": "#/$defs/shadow"
|
||||
},
|
||||
"lift": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 4
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.96,
|
||||
"maximum": 1.04
|
||||
},
|
||||
"underline": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fillGlass": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
{
|
||||
"const": "transparent"
|
||||
},
|
||||
{
|
||||
"const": "glass"
|
||||
}
|
||||
]
|
||||
},
|
||||
"stateGlass": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"fill": {
|
||||
"$ref": "#/$defs/fillGlass"
|
||||
},
|
||||
"text": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"borderColor": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"shadow": {
|
||||
"$ref": "#/$defs/shadow"
|
||||
},
|
||||
"lift": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 4
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.96,
|
||||
"maximum": 1.04
|
||||
},
|
||||
"underline": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fillGradient": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
{
|
||||
"const": "transparent"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"from": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"to": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"angle": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 360
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"from",
|
||||
"to"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"stateGradient": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"fill": {
|
||||
"$ref": "#/$defs/fillGradient"
|
||||
},
|
||||
"text": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"borderColor": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"shadow": {
|
||||
"$ref": "#/$defs/shadow"
|
||||
},
|
||||
"lift": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 4
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.96,
|
||||
"maximum": 1.04
|
||||
},
|
||||
"underline": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fillGlassGradient": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
{
|
||||
"const": "transparent"
|
||||
},
|
||||
{
|
||||
"const": "glass"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"from": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"to": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"angle": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 360
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"from",
|
||||
"to"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"stateGlassGradient": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"fill": {
|
||||
"$ref": "#/$defs/fillGlassGradient"
|
||||
},
|
||||
"text": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"borderColor": {
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
"shadow": {
|
||||
"$ref": "#/$defs/shadow"
|
||||
},
|
||||
"lift": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 4
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.96,
|
||||
"maximum": 1.04
|
||||
},
|
||||
"underline": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pathData": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 4000,
|
||||
"pattern": "^[MmLlHhVvCcSsQqTtAaZz0-9eE\\s,.+-]+$"
|
||||
},
|
||||
"glyph": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"d": {
|
||||
"$ref": "#/$defs/pathData"
|
||||
},
|
||||
"rule": {
|
||||
"const": "evenodd"
|
||||
},
|
||||
"stroke": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"d"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"layers": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"maxItems": 6,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"d": {
|
||||
"$ref": "#/$defs/pathData"
|
||||
},
|
||||
"fill": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/role"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/hex"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"from": {
|
||||
"$ref": "#/$defs/hex"
|
||||
},
|
||||
"to": {
|
||||
"$ref": "#/$defs/hex"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"from",
|
||||
"to"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"opacity": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"rule": {
|
||||
"const": "evenodd"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"d",
|
||||
"fill"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"layers"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"png": {
|
||||
"type": "string",
|
||||
"maxLength": 6022,
|
||||
"pattern": "^data:image/png;base64,[A-Za-z0-9+/]+={0,2}$"
|
||||
},
|
||||
"pixel": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"png"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +185,7 @@
|
|||
"import": "./dist/shell/*.js"
|
||||
},
|
||||
"./theme.schema.json": "./theme.schema.json",
|
||||
"./icons.schema.json": "./icons.schema.json",
|
||||
"./store-catalog.schema.json": "./store-catalog.schema.json",
|
||||
"./cli/store": "./cli/store.mjs",
|
||||
"./cli/release": "./cli/release.mjs",
|
||||
|
|
@ -200,6 +201,7 @@
|
|||
"build",
|
||||
"cli",
|
||||
"theme.schema.json",
|
||||
"icons.schema.json",
|
||||
"store-catalog.schema.json",
|
||||
"i18n.schema.json",
|
||||
"i18n-meta.schema.json",
|
||||
|
|
|
|||
32
packages/waybetter/scripts/theme-schema.mjs
Normal file
32
packages/waybetter/scripts/theme-schema.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Writes the generated parts of `theme.schema.json` (a theme's structure groups: components,
|
||||
// variants, decoration, icons, action colors) and the whole `icons.schema.json` (icon packs) from
|
||||
// the runtime's vocabulary tables, so a range or a word is defined once.
|
||||
//
|
||||
// node scripts/theme-schema.mjs rewrite both files
|
||||
// node scripts/theme-schema.mjs --check exit 1 when a file is stale (the test runs this)
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { actionColorsSchema, iconPackSchema, structureDefs, structureProperties } from '../../runtime/src/themeSchema.ts';
|
||||
|
||||
const check = process.argv.includes('--check');
|
||||
const file = name => new URL(`../${name}`, import.meta.url);
|
||||
|
||||
/** The theme schema with its generated parts replaced. */
|
||||
export function themeSchema(current) {
|
||||
const schema = structuredClone(current);
|
||||
Object.assign(schema.properties, structureProperties());
|
||||
const colors = schema.properties.colors.oneOf.find(option => option.type === 'object');
|
||||
colors.properties.actions = actionColorsSchema();
|
||||
Object.assign(schema.$defs, structureDefs());
|
||||
return schema;
|
||||
}
|
||||
export const iconsSchema = () => iconPackSchema('https://unpkg.com/waybetter/icons.schema.json');
|
||||
|
||||
const stale = [];
|
||||
for (const [name, build] of [['theme.schema.json', () => themeSchema(JSON.parse(readFileSync(file('theme.schema.json'), 'utf8')))], ['icons.schema.json', iconsSchema]]) {
|
||||
const next = `${JSON.stringify(build(), null, 2)}\n`;
|
||||
let current = '';
|
||||
try { current = readFileSync(file(name), 'utf8').replace(/\r\n/g, '\n'); } catch { /* Not written yet. */ }
|
||||
if (current === next) continue;
|
||||
if (check) stale.push(name); else { writeFileSync(file(name), next); console.log(`wrote ${name}`); }
|
||||
}
|
||||
if (stale.length) { console.error(`stale: ${stale.join(', ')} (run node scripts/theme-schema.mjs)`); process.exit(1); }
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue