@brunosouzas/signwright 0.0.0-stage → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +567 -2
- package/dist/scripts/cover.d.ts +29 -0
- package/dist/scripts/cover.js +186 -0
- package/dist/src/fonts/embed.d.ts +7 -0
- package/dist/src/fonts/embed.js +221 -0
- package/dist/src/pieces/bank-objects.d.ts +12 -0
- package/dist/src/pieces/bank-objects.js +52 -0
- package/dist/src/pieces/brand-cast.d.ts +105 -0
- package/dist/src/pieces/brand-cast.js +221 -0
- package/dist/src/pieces/brand-notation-icons.d.ts +12 -0
- package/dist/src/pieces/brand-notation-icons.js +79 -0
- package/dist/src/pieces/category-icon.d.ts +12 -0
- package/dist/src/pieces/category-icon.js +55 -0
- package/dist/src/pieces/cover.d.ts +138 -0
- package/dist/src/pieces/cover.js +635 -0
- package/dist/src/pieces/diagram.d.ts +141 -0
- package/dist/src/pieces/diagram.js +201 -0
- package/dist/src/pieces/eip-icons.d.ts +12 -0
- package/dist/src/pieces/eip-icons.js +468 -0
- package/dist/src/pieces/emote.d.ts +13 -0
- package/dist/src/pieces/emote.js +88 -0
- package/dist/src/pieces/headline.d.ts +11 -0
- package/dist/src/pieces/headline.js +37 -0
- package/dist/src/pieces/index.d.ts +17 -0
- package/dist/src/pieces/index.js +20 -0
- package/dist/src/pieces/ink.d.ts +71 -0
- package/dist/src/pieces/ink.js +57 -0
- package/dist/src/pieces/keyboard.d.ts +9 -0
- package/dist/src/pieces/keyboard.js +33 -0
- package/dist/src/pieces/library.d.ts +320 -0
- package/dist/src/pieces/library.js +355 -0
- package/dist/src/pieces/link-icons.d.ts +23 -0
- package/dist/src/pieces/link-icons.js +101 -0
- package/dist/src/pieces/metro.d.ts +137 -0
- package/dist/src/pieces/metro.js +288 -0
- package/dist/src/pieces/node.d.ts +29 -0
- package/dist/src/pieces/node.js +56 -0
- package/dist/src/pieces/paper.d.ts +31 -0
- package/dist/src/pieces/paper.js +72 -0
- package/dist/src/pieces/params.d.ts +84 -0
- package/dist/src/pieces/params.js +158 -0
- package/dist/src/pieces/piece.d.ts +9 -0
- package/dist/src/pieces/piece.js +28 -0
- package/dist/src/pieces/pose.d.ts +16 -0
- package/dist/src/pieces/pose.js +30 -0
- package/dist/src/pieces/question-token.d.ts +9 -0
- package/dist/src/pieces/question-token.js +49 -0
- package/dist/src/pieces/react.d.ts +4 -0
- package/dist/src/pieces/react.js +13 -0
- package/dist/src/pieces/render.d.ts +2 -0
- package/dist/src/pieces/render.js +22 -0
- package/dist/src/pieces/skin.d.ts +22 -0
- package/dist/src/pieces/skin.js +13 -0
- package/dist/src/pieces/stamp.d.ts +11 -0
- package/dist/src/pieces/stamp.js +29 -0
- package/dist/src/pieces/supporting-cast.d.ts +35 -0
- package/dist/src/pieces/supporting-cast.js +168 -0
- package/dist/src/pieces/symbol.d.ts +13 -0
- package/dist/src/pieces/symbol.js +27 -0
- package/dist/src/pieces/ui-icons.d.ts +21 -0
- package/dist/src/pieces/ui-icons.js +35 -0
- package/dist/tokens/generated/tokens.d.ts +299 -0
- package/dist/tokens/generated/tokens.js +299 -0
- package/fonts/OFL.txt +97 -0
- package/fonts/SourceCodePro-Bold.ttf +0 -0
- package/fonts/SourceCodePro-Regular.ttf +0 -0
- package/fonts/SourceSans3-Black.ttf +0 -0
- package/fonts/SourceSans3-Bold.ttf +0 -0
- package/fonts/SourceSans3-Regular.ttf +0 -0
- package/fonts/SourceSerif4-Bold.ttf +0 -0
- package/package.json +88 -4
- package/tokens/generated/tokens.css +215 -0
- package/tokens/generated/tokens.json +298 -0
- package/tokens/generated/tokens.ts +302 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
// Cover specs (spec cover-cli; design §6): validation of the JSON a cover is
|
|
2
|
+
// written in, and the frames that draw it from the pieces: the 800x420 cover,
|
|
3
|
+
// the banner, the body diagram and the icon (change designer-formats), and the
|
|
4
|
+
// platform formats (favicon, LinkedIn card, og image, avatar, LinkedIn banner).
|
|
5
|
+
//
|
|
6
|
+
// Why here and not in scripts/: the validation and the frame are pure, so the
|
|
7
|
+
// tests and a future site build can use them without the command line.
|
|
8
|
+
//
|
|
9
|
+
// What can go wrong: an invalid spec returns every problem with its JSON path
|
|
10
|
+
// and draws nothing. A free-form object is limited to drawing tags and safe
|
|
11
|
+
// attributes, because the cover is published as SVG.
|
|
12
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
13
|
+
import { PIECE_NAMES, PIECES, rings } from "./library.js";
|
|
14
|
+
import { EIP_ICON_HEIGHT, EIP_ICON_WIDTH, EIP_ICONS } from "./eip-icons.js";
|
|
15
|
+
import { CATEGORY_ICON_SIZE } from "./category-icon.js";
|
|
16
|
+
import { LINK_ICON_SIZE } from "./link-icons.js";
|
|
17
|
+
import { mira } from "./brand-cast.js";
|
|
18
|
+
import { symbol } from "./symbol.js";
|
|
19
|
+
import { el, g, r2 } from "./node.js";
|
|
20
|
+
import { UI_ICON_SIZE } from "./ui-icons.js";
|
|
21
|
+
import { COLOUR_TOKENS, CURRENT_COLOUR, checkParams, isColourLiteral, MAX_SIZE, PATH_DATA } from "./params.js";
|
|
22
|
+
export const SAFE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
23
|
+
const TOP_LEVEL = ["id", "title", "description", "format", "background", "rings", "pieces", "custom", "customAt", "height", "text", "signature"];
|
|
24
|
+
/** Cover (800x420, the default), banner (1200x420, rounded corners), body diagram (560 laid out, 800 shown),
|
|
25
|
+
* icon, favicon (the symbol, both themes), linkedin-card (1080x1080), avatar (500x500, the symbol only) or
|
|
26
|
+
* linkedin-banner (1584x396, a profile background): spec cover-cli, "Banner output", "Diagram output",
|
|
27
|
+
* "Icon output", "New icon formats", "LinkedIn banner output". */
|
|
28
|
+
export const FORMATS = ["cover", "banner", "diagram", "icon", "favicon", "linkedin-card", "og", "avatar", "linkedin-banner"];
|
|
29
|
+
/** Fixed frame sizes of the platform-shaped formats (not style, so not tokens — like EIP_ICON_WIDTH). */
|
|
30
|
+
export const FAVICON_SIZE = 32;
|
|
31
|
+
export const AVATAR_SIZE = 500;
|
|
32
|
+
export const LINKEDIN_CARD_SIZE = 1080;
|
|
33
|
+
export const OG_WIDTH = 1200;
|
|
34
|
+
export const OG_HEIGHT = 630;
|
|
35
|
+
/** LinkedIn's recommended upload for a personal profile background (4:1). */
|
|
36
|
+
export const LINKEDIN_BANNER_WIDTH = 1584;
|
|
37
|
+
export const LINKEDIN_BANNER_HEIGHT = 396;
|
|
38
|
+
/** Margin added to each profile photo radius for the safe area: the measuring error, the platform's rounding and small drift. */
|
|
39
|
+
export const LINKEDIN_PHOTO_MARGIN = 16;
|
|
40
|
+
const photoZone = (name, cx, cy, r) => Object.freeze({ name, cx, cy, r, safeRadius: r + LINKEDIN_PHOTO_MARGIN });
|
|
41
|
+
/**
|
|
42
|
+
* The circles LinkedIn's profile photo covers on a 1584x396 banner, in banner units, the photo's white ring included
|
|
43
|
+
* (spec cover-cli, "LinkedIn profile photo zones"). Measured by the owner on 2026-11-11 from screenshots of his own
|
|
44
|
+
* profile, about ±2 units: desktop web (the 792 px profile card, the banner at 0.5) and the iOS app (full width, about
|
|
45
|
+
* 0.28 on a 440-pt phone; the centre lies below the image's bottom edge). The Android app and desktop windows narrow
|
|
46
|
+
* enough to change the card's width were not measured. The command does not check a spec against them; the PNG
|
|
47
|
+
* script draws them over a render (`npm run png -- … --zones`).
|
|
48
|
+
*/
|
|
49
|
+
export const LINKEDIN_PHOTO_ZONES = Object.freeze([photoZone("desktop", 207, 362, 160), photoZone("ios", 244, 409, 187)]);
|
|
50
|
+
const CUSTOM_TAGS = ["g", "rect", "circle", "ellipse", "line", "polyline", "polygon", "path", "text"];
|
|
51
|
+
// Attributes a free-form object may use (design §6): geometry, paint, text and transform.
|
|
52
|
+
const CUSTOM_ATTRS = new Set([
|
|
53
|
+
"x", "y", "width", "height", "rx", "ry", "cx", "cy", "r", "x1", "y1", "x2", "y2", "points", "d",
|
|
54
|
+
"fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-dasharray", "opacity", "fill-opacity", "stroke-opacity",
|
|
55
|
+
"font-size", "font-weight", "font-family", "text-anchor", "transform",
|
|
56
|
+
]);
|
|
57
|
+
const COLOUR_ATTRS = new Set(["fill", "stroke"]);
|
|
58
|
+
// Attributes whose value is a grammar, never a bare number.
|
|
59
|
+
const STRING_ONLY_ATTRS = new Set(["transform", "d", "points", "font-family", "text-anchor", "stroke-linecap", "stroke-linejoin"]);
|
|
60
|
+
const TRANSFORM = /^\s*(?:(?:translate|rotate|scale)\(\s*-?[\d.]+(?:[\s,]+-?[\d.]+){0,2}\s*\)\s*)+$/;
|
|
61
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
const describe = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
|
|
63
|
+
export const backgroundNames = () => Object.keys(tokens.coverBackground);
|
|
64
|
+
/** Every string in the spec that looks like a colour literal, by path. */
|
|
65
|
+
const colourLiterals = (value, path, out) => {
|
|
66
|
+
if (typeof value === "string") {
|
|
67
|
+
if (isColourLiteral(value))
|
|
68
|
+
out.push({ path, message: "colour literals are not allowed; use a token path" });
|
|
69
|
+
}
|
|
70
|
+
else if (Array.isArray(value)) {
|
|
71
|
+
value.forEach((item, index) => colourLiterals(item, `${path}[${index}]`, out));
|
|
72
|
+
}
|
|
73
|
+
else if (isPlainObject(value)) {
|
|
74
|
+
for (const [key, child] of Object.entries(value))
|
|
75
|
+
colourLiterals(child, path ? `${path}.${key}` : key, out);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const checkCustom = (node, path, out) => {
|
|
79
|
+
if (!isPlainObject(node))
|
|
80
|
+
return void out.push({ path, message: `expected a node object, found ${describe(node)}` });
|
|
81
|
+
for (const key of Object.keys(node)) {
|
|
82
|
+
if (!["tag", "attrs", "children"].includes(key))
|
|
83
|
+
out.push({ path: `${path}.${key}`, message: "unknown key (expected tag, attrs, children)" });
|
|
84
|
+
}
|
|
85
|
+
if (typeof node.tag !== "string" || !CUSTOM_TAGS.includes(node.tag)) {
|
|
86
|
+
out.push({ path: `${path}.tag`, message: `tag not allowed in a free-form object (allowed: ${CUSTOM_TAGS.join(", ")}), found ${describe(node.tag)}` });
|
|
87
|
+
}
|
|
88
|
+
if (node.attrs !== undefined) {
|
|
89
|
+
if (!isPlainObject(node.attrs))
|
|
90
|
+
out.push({ path: `${path}.attrs`, message: "expected an object" });
|
|
91
|
+
else {
|
|
92
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
93
|
+
const at = `${path}.attrs.${name}`;
|
|
94
|
+
if (!CUSTOM_ATTRS.has(name)) {
|
|
95
|
+
out.push({ path: at, message: "attribute not allowed in a free-form object" });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (typeof value === "number") {
|
|
99
|
+
if (COLOUR_ATTRS.has(name) || STRING_ONLY_ATTRS.has(name))
|
|
100
|
+
out.push({ path: at, message: "expected a string" });
|
|
101
|
+
else if (!Number.isFinite(value))
|
|
102
|
+
out.push({ path: at, message: "expected a finite number" });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (typeof value !== "string") {
|
|
106
|
+
out.push({ path: at, message: `expected a string or a number, found ${describe(value)}` });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (/url\(|\/\//i.test(value)) {
|
|
110
|
+
out.push({ path: at, message: "references are not allowed (url( or //)" });
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (COLOUR_ATTRS.has(name) && value !== "none" && !isColourLiteral(value) && !COLOUR_TOKENS.has(value)) {
|
|
114
|
+
out.push({ path: at, message: `expected none or a colour token path, found ${describe(value)}` });
|
|
115
|
+
}
|
|
116
|
+
else if (name === "transform" && !TRANSFORM.test(value)) {
|
|
117
|
+
out.push({ path: at, message: "only translate, rotate and scale are allowed" });
|
|
118
|
+
}
|
|
119
|
+
else if ((name === "d" || name === "points") && !PATH_DATA.test(value)) {
|
|
120
|
+
out.push({ path: at, message: "expected path characters only (commands, digits, signs, dots, commas, spaces)" });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (node.children !== undefined) {
|
|
126
|
+
if (!Array.isArray(node.children))
|
|
127
|
+
out.push({ path: `${path}.children`, message: "expected an array" });
|
|
128
|
+
else
|
|
129
|
+
node.children.forEach((child, index) => {
|
|
130
|
+
const at = `${path}.children[${index}]`;
|
|
131
|
+
if (typeof child === "string") {
|
|
132
|
+
if (node.tag !== "text")
|
|
133
|
+
out.push({ path: at, message: "text is only allowed inside a text node" });
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
checkCustom(child, at, out);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** Orders strings by Unicode code point (JS `<` compares UTF-16 code units). */
|
|
141
|
+
const compareCodePoints = (a, b) => {
|
|
142
|
+
const left = Array.from(a);
|
|
143
|
+
const right = Array.from(b);
|
|
144
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
145
|
+
const diff = left[i].codePointAt(0) - right[i].codePointAt(0);
|
|
146
|
+
if (diff !== 0)
|
|
147
|
+
return diff;
|
|
148
|
+
}
|
|
149
|
+
return left.length - right.length;
|
|
150
|
+
};
|
|
151
|
+
/** Compares JSON paths: segment by segment, array indexes as numbers, names by code point. */
|
|
152
|
+
export const comparePaths = (a, b) => {
|
|
153
|
+
const split = (path) => path.match(/[^.[\]]+|\[\d+\]/g) ?? [];
|
|
154
|
+
const left = split(a);
|
|
155
|
+
const right = split(b);
|
|
156
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
157
|
+
const x = left[i];
|
|
158
|
+
const y = right[i];
|
|
159
|
+
if (x === y)
|
|
160
|
+
continue;
|
|
161
|
+
const xi = /^\[\d+\]$/.test(x);
|
|
162
|
+
const yi = /^\[\d+\]$/.test(y);
|
|
163
|
+
if (xi && yi)
|
|
164
|
+
return Number(x.slice(1, -1)) - Number(y.slice(1, -1));
|
|
165
|
+
return compareCodePoints(x, y);
|
|
166
|
+
}
|
|
167
|
+
return left.length - right.length;
|
|
168
|
+
};
|
|
169
|
+
// ---------- text tables (spec cover-cli "Text tables", "Text references", "Language choice"; design §3) ----------
|
|
170
|
+
/** A language of a text table and of `--lang`: `pt`, `en`, `pt-br`. */
|
|
171
|
+
export const LANGUAGE = /^[a-z]{2}(-[a-z]{2})?$/;
|
|
172
|
+
const TEXT_KEY = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
173
|
+
const REFERENCE = /^@([A-Za-z][A-Za-z0-9_-]*)$/;
|
|
174
|
+
const isTextValue = (value) => (typeof value === "string" && value !== "") ||
|
|
175
|
+
(Array.isArray(value) && value.length > 0 && Array.from({ length: value.length }, (_, i) => value[i]).every((item) => typeof item === "string" && item !== ""));
|
|
176
|
+
/** The table `lang` picks, or the problems of the tables and of the language choice. */
|
|
177
|
+
const pickTable = (spec, lang) => {
|
|
178
|
+
if (spec.text === undefined)
|
|
179
|
+
return { problems: lang === undefined ? [] : [{ path: "text", message: "--lang needs text tables" }] };
|
|
180
|
+
const text = spec.text;
|
|
181
|
+
if (!isPlainObject(text) || Object.keys(text).length === 0)
|
|
182
|
+
return { problems: [{ path: "text", message: "expected an object of languages (such as en, pt), each a table of text keys" }] };
|
|
183
|
+
const problems = [];
|
|
184
|
+
const tables = new Map();
|
|
185
|
+
for (const [code, table] of Object.entries(text)) {
|
|
186
|
+
if (!LANGUAGE.test(code))
|
|
187
|
+
problems.push({ path: `text.${code}`, message: "expected a language code such as pt or en" });
|
|
188
|
+
else if (!isPlainObject(table))
|
|
189
|
+
problems.push({ path: `text.${code}`, message: "expected an object of text keys" });
|
|
190
|
+
else
|
|
191
|
+
tables.set(code, table);
|
|
192
|
+
}
|
|
193
|
+
const keys = new Set();
|
|
194
|
+
for (const [code, table] of tables) {
|
|
195
|
+
for (const [key, value] of Object.entries(table)) {
|
|
196
|
+
keys.add(key);
|
|
197
|
+
if (!TEXT_KEY.test(key))
|
|
198
|
+
problems.push({ path: `text.${code}.${key}`, message: "expected a text key (a letter, then letters, digits, _ or -)" });
|
|
199
|
+
else if (!isTextValue(value))
|
|
200
|
+
problems.push({ path: `text.${code}.${key}`, message: "expected a non-empty string or a non-empty array of non-empty strings" });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const [code, table] of tables) {
|
|
204
|
+
for (const key of keys)
|
|
205
|
+
if (!Object.hasOwn(table, key))
|
|
206
|
+
problems.push({ path: `text.${code}.${key}`, message: "missing: another language defines it" });
|
|
207
|
+
}
|
|
208
|
+
if (problems.length > 0)
|
|
209
|
+
return { problems };
|
|
210
|
+
const codes = [...tables.keys()].sort().join(", ");
|
|
211
|
+
if (lang === undefined)
|
|
212
|
+
return { problems: [{ path: "text", message: `choose a language with --lang (${codes})` }] };
|
|
213
|
+
if (!tables.has(lang))
|
|
214
|
+
return { problems: [{ path: "text", message: `no table for ${lang} (${codes})` }] };
|
|
215
|
+
return { table: tables.get(lang), problems: [] };
|
|
216
|
+
};
|
|
217
|
+
/** The spec with every `@key` outside `text` replaced once by the table's value; unknown keys by path. */
|
|
218
|
+
const resolveText = (spec, table) => {
|
|
219
|
+
const unknown = [];
|
|
220
|
+
const visit = (value, path) => {
|
|
221
|
+
if (typeof value === "string") {
|
|
222
|
+
const match = REFERENCE.exec(value);
|
|
223
|
+
if (!match)
|
|
224
|
+
return value;
|
|
225
|
+
if (!Object.hasOwn(table, match[1])) {
|
|
226
|
+
unknown.push({ path, message: `unknown text key ${match[1]}` });
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
const found = table[match[1]];
|
|
230
|
+
return Array.isArray(found) ? [...found] : found;
|
|
231
|
+
}
|
|
232
|
+
if (Array.isArray(value))
|
|
233
|
+
return Array.from({ length: value.length }, (_, i) => visit(value[i], `${path}[${i}]`));
|
|
234
|
+
if (isPlainObject(value))
|
|
235
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, visit(child, path ? `${path}.${key}` : key)]));
|
|
236
|
+
return value;
|
|
237
|
+
};
|
|
238
|
+
const { text, ...rest } = spec;
|
|
239
|
+
return { spec: { ...visit(rest, ""), text }, unknown };
|
|
240
|
+
};
|
|
241
|
+
/** The spec the frame draws: resolved for `lang`, with the language in its id (decision 4). */
|
|
242
|
+
const forLanguage = (spec, lang) => {
|
|
243
|
+
if (spec.text === undefined || lang === undefined)
|
|
244
|
+
return spec;
|
|
245
|
+
const resolved = resolveText(spec, spec.text[lang]).spec;
|
|
246
|
+
// The id may be a reference too: the language goes on the resolved id.
|
|
247
|
+
return { ...resolved, id: `${resolved.id}-${lang}` };
|
|
248
|
+
};
|
|
249
|
+
// ---------- validation ----------
|
|
250
|
+
/** Icon pieces and the box each draws in (spec cover-cli, "Icon output"). */
|
|
251
|
+
const ICON_PIECES = ["eipIcon", "uiIcon", "linkIcon", "categoryIcon"];
|
|
252
|
+
const iconBox = (entry) => {
|
|
253
|
+
if (entry.piece === "eipIcon") {
|
|
254
|
+
const scale = entry.scale ?? 1;
|
|
255
|
+
return [EIP_ICON_WIDTH * scale, EIP_ICON_HEIGHT * scale];
|
|
256
|
+
}
|
|
257
|
+
if (entry.piece === "categoryIcon") {
|
|
258
|
+
const side = CATEGORY_ICON_SIZE * (entry.scale ?? 1);
|
|
259
|
+
return [side, side];
|
|
260
|
+
}
|
|
261
|
+
const side = entry.size ?? (entry.piece === "uiIcon" ? UI_ICON_SIZE : LINK_ICON_SIZE);
|
|
262
|
+
return [side, side];
|
|
263
|
+
};
|
|
264
|
+
/** Problems of one `pieces` entry against its piece's parameters (spec cover-cli, "Piece parameters checked"). */
|
|
265
|
+
const checkEntry = (piece, params, at, out) => {
|
|
266
|
+
const definition = PIECES[piece];
|
|
267
|
+
const own = checkParams(definition.schema, params, at);
|
|
268
|
+
// Every output is a standalone image: currentColor (accepted by uiIcon for inline page icons) is refused.
|
|
269
|
+
for (const [name, spec] of Object.entries(definition.schema)) {
|
|
270
|
+
if (spec.kind === "color" && spec.currentColor && params[name] === CURRENT_COLOUR) {
|
|
271
|
+
own.push({ path: `${at}.${name}`, message: "currentColor is for icons inline in a page; a cover uses a token path" });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
out.push(...own);
|
|
275
|
+
// Limits between parameters are reported with the schema's problems, except on a parameter
|
|
276
|
+
// already reported; a relation that cannot read a broken parameter reports nothing.
|
|
277
|
+
let related = [];
|
|
278
|
+
if (definition.relations) {
|
|
279
|
+
try {
|
|
280
|
+
// A relation that reads a broken parameter may return anything: keep only real problems.
|
|
281
|
+
const found = definition.relations(params);
|
|
282
|
+
related = Array.isArray(found) ? found.filter((p) => isPlainObject(p) && typeof p.path === "string" && typeof p.message === "string") : [];
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
related = [];
|
|
286
|
+
}
|
|
287
|
+
const reported = new Set(own.map((problem) => problem.path));
|
|
288
|
+
out.push(...related.map((problem) => ({ path: `${at}.${problem.path}`, message: problem.message })).filter((problem) => !reported.has(problem.path)));
|
|
289
|
+
}
|
|
290
|
+
// A valid entry is drawn once: an overflow is a spec problem at the entry, not a crash.
|
|
291
|
+
if (own.length === 0 && related.length === 0) {
|
|
292
|
+
try {
|
|
293
|
+
PIECES[piece](params);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
if (error instanceof RangeError && error.message.endsWith(": the drawing overflows"))
|
|
297
|
+
out.push({ path: at, message: "the drawing overflows" });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const checkRings = (spec, out) => {
|
|
302
|
+
if (!isPlainObject(spec.rings))
|
|
303
|
+
return void out.push({ path: "rings", message: "missing or not an object (expected cx, cy and an optional radius)" });
|
|
304
|
+
const ringProblems = checkParams(rings.schema, spec.rings, "rings").filter((problem) => problem.path !== "rings.color" && problem.path !== "rings.count");
|
|
305
|
+
out.push(...ringProblems);
|
|
306
|
+
// The piece takes any finite centre; a spec keeps 0.1.0's ±10000, which bounds a banner's and a diagram's ring count.
|
|
307
|
+
for (const axis of ["cx", "cy"]) {
|
|
308
|
+
const value = spec.rings[axis];
|
|
309
|
+
if (ringProblems.some((p) => p.path === `rings.${axis}`) || typeof value !== "number")
|
|
310
|
+
continue;
|
|
311
|
+
if (value < -MAX_SIZE)
|
|
312
|
+
out.push({ path: `rings.${axis}`, message: `expected a number at least -${MAX_SIZE}, found ${value}` });
|
|
313
|
+
else if (value > MAX_SIZE)
|
|
314
|
+
out.push({ path: `rings.${axis}`, message: `expected a number at most ${MAX_SIZE}, found ${value}` });
|
|
315
|
+
}
|
|
316
|
+
if (Object.hasOwn(spec.rings, "color"))
|
|
317
|
+
out.push({ path: "rings.color", message: "unknown parameter: the ring colour comes from the background" });
|
|
318
|
+
if (Object.hasOwn(spec.rings, "count"))
|
|
319
|
+
out.push({ path: "rings.count", message: "unknown parameter: the ring count comes from the format" });
|
|
320
|
+
};
|
|
321
|
+
const NOT_FOR_ICONS = "not used by the icon format";
|
|
322
|
+
const EIP_TEXT = "comes from the EIP icon, with its CC BY 4.0 credit";
|
|
323
|
+
/** Every problem of a resolved spec (no text references left to resolve). */
|
|
324
|
+
const validateResolved = (spec) => {
|
|
325
|
+
const out = [];
|
|
326
|
+
const blocked = [];
|
|
327
|
+
colourLiterals(spec, "", out);
|
|
328
|
+
for (const key of Object.keys(spec)) {
|
|
329
|
+
if (!TOP_LEVEL.includes(key))
|
|
330
|
+
out.push({ path: key, message: `unknown key (expected ${TOP_LEVEL.join(", ")})` });
|
|
331
|
+
}
|
|
332
|
+
if (spec.format !== undefined && (typeof spec.format !== "string" || !FORMATS.includes(spec.format))) {
|
|
333
|
+
out.push({ path: "format", message: `expected one of ${FORMATS.join(", ")}` });
|
|
334
|
+
}
|
|
335
|
+
// An unknown format is checked as a cover, as before this change.
|
|
336
|
+
const format = FORMATS.includes(spec.format) ? spec.format : "cover";
|
|
337
|
+
if (typeof spec.id !== "string" || !SAFE_ID.test(spec.id))
|
|
338
|
+
out.push({ path: "id", message: `expected a safe slug (lowercase letters, digits, single hyphens), found ${describe(spec.id)}` });
|
|
339
|
+
const pieces = spec.pieces;
|
|
340
|
+
const eipIconSpec = format === "icon" && Array.isArray(pieces) && pieces.length === 1 && isPlainObject(pieces[0]) && pieces[0].piece === "eipIcon";
|
|
341
|
+
for (const key of ["title", "description"]) {
|
|
342
|
+
if (eipIconSpec) {
|
|
343
|
+
if (spec[key] !== undefined)
|
|
344
|
+
out.push({ path: key, message: EIP_TEXT });
|
|
345
|
+
}
|
|
346
|
+
else if (typeof spec[key] !== "string" || spec[key].trim() === "")
|
|
347
|
+
out.push({ path: key, message: "expected a non-empty string" });
|
|
348
|
+
}
|
|
349
|
+
if (format === "icon") {
|
|
350
|
+
// signature too since 0.7.0 (0.6.x accepted it and drew nothing).
|
|
351
|
+
for (const key of ["background", "rings", "custom", "customAt", "height", "signature"])
|
|
352
|
+
if (spec[key] !== undefined)
|
|
353
|
+
out.push({ path: key, message: NOT_FOR_ICONS });
|
|
354
|
+
for (const key of ["background", "rings", "custom"])
|
|
355
|
+
if (spec[key] !== undefined)
|
|
356
|
+
blocked.push(key);
|
|
357
|
+
}
|
|
358
|
+
else if (format === "favicon" || format === "avatar") {
|
|
359
|
+
// An avatar takes an optional ground, a coverBackground name (spec cover-cli, "Avatar ground").
|
|
360
|
+
const refused = format === "avatar" ? ["rings", "custom", "customAt", "height", "signature"] : ["background", "rings", "custom", "customAt", "height", "signature"];
|
|
361
|
+
for (const key of refused) {
|
|
362
|
+
if (spec[key] !== undefined)
|
|
363
|
+
out.push({ path: key, message: `not used by the ${format} format` });
|
|
364
|
+
}
|
|
365
|
+
if (format === "avatar" && spec.background !== undefined && (typeof spec.background !== "string" || !backgroundNames().includes(spec.background))) {
|
|
366
|
+
out.push({ path: "background", message: `expected one of ${backgroundNames().join(", ")}, found ${describe(spec.background)}` });
|
|
367
|
+
}
|
|
368
|
+
for (const key of ["background", "rings", "custom"])
|
|
369
|
+
if (spec[key] !== undefined && refused.includes(key))
|
|
370
|
+
blocked.push(key);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
if (format === "diagram") {
|
|
374
|
+
if (spec.background !== undefined)
|
|
375
|
+
out.push({ path: "background", message: "a diagram is drawn on color.panel; background is for covers and banners" });
|
|
376
|
+
if (spec.signature !== undefined)
|
|
377
|
+
out.push({ path: "signature", message: "not used by the diagram format" });
|
|
378
|
+
const height = spec.height;
|
|
379
|
+
if (typeof height !== "number" || !Number.isFinite(height) || height < 1 || height > MAX_SIZE)
|
|
380
|
+
out.push({ path: "height", message: `expected a number from 1 to ${MAX_SIZE}` });
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
if (typeof spec.background !== "string" || !backgroundNames().includes(spec.background)) {
|
|
384
|
+
out.push({ path: "background", message: `expected one of ${backgroundNames().join(", ")}, found ${describe(spec.background)}` });
|
|
385
|
+
}
|
|
386
|
+
if (spec.height !== undefined)
|
|
387
|
+
out.push({ path: "height", message: "only a diagram takes a height" });
|
|
388
|
+
// The photo and the name sign a LinkedIn profile already; a 44-unit lockup would show about 12 pt on a phone.
|
|
389
|
+
if (format === "linkedin-banner" && spec.signature !== undefined)
|
|
390
|
+
out.push({ path: "signature", message: "not used by the linkedin-banner format" });
|
|
391
|
+
else if (spec.signature !== undefined && typeof spec.signature !== "boolean")
|
|
392
|
+
out.push({ path: "signature", message: "expected true or false" });
|
|
393
|
+
}
|
|
394
|
+
checkRings(spec, out);
|
|
395
|
+
if (!isPlainObject(spec.rings) && spec.rings !== undefined)
|
|
396
|
+
blocked.push("rings");
|
|
397
|
+
if (spec.custom !== undefined) {
|
|
398
|
+
if (Array.isArray(spec.custom)) {
|
|
399
|
+
out.push({ path: "custom", message: "one free-form object per cover; a repeated object must be a piece" });
|
|
400
|
+
blocked.push("custom");
|
|
401
|
+
}
|
|
402
|
+
else
|
|
403
|
+
checkCustom(spec.custom, "custom", out);
|
|
404
|
+
}
|
|
405
|
+
if (spec.customAt !== undefined) {
|
|
406
|
+
const at = spec.customAt;
|
|
407
|
+
if (spec.custom === undefined)
|
|
408
|
+
out.push({ path: "customAt", message: "needs custom" });
|
|
409
|
+
else if (Array.isArray(pieces)) {
|
|
410
|
+
if (typeof at !== "number" || !Number.isInteger(at) || at < 0 || at > pieces.length)
|
|
411
|
+
out.push({ path: "customAt", message: `expected an integer from 0 to ${pieces.length}` });
|
|
412
|
+
}
|
|
413
|
+
else if (typeof at !== "number" || !Number.isInteger(at) || at < 0) {
|
|
414
|
+
// Without a pieces array the count is unknown: the type is still checked.
|
|
415
|
+
out.push({ path: "customAt", message: "expected an integer from 0 to the number of pieces" });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (!Array.isArray(pieces)) {
|
|
420
|
+
const piecesOptional = (format === "favicon" || format === "avatar") && pieces === undefined;
|
|
421
|
+
if (!piecesOptional) {
|
|
422
|
+
out.push({ path: "pieces", message: "missing or not an array" });
|
|
423
|
+
if (pieces !== undefined)
|
|
424
|
+
blocked.push("pieces");
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else if (format === "icon") {
|
|
428
|
+
const entry = pieces[0];
|
|
429
|
+
if (pieces.length !== 1 || !isPlainObject(entry) || !ICON_PIECES.includes(entry.piece)) {
|
|
430
|
+
out.push({ path: "pieces", message: "an icon spec holds exactly one piece: eipIcon, uiIcon, linkIcon or categoryIcon" });
|
|
431
|
+
blocked.push("pieces");
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
const { piece, ...params } = entry;
|
|
435
|
+
for (const axis of ["x", "y"])
|
|
436
|
+
if (params[axis] !== undefined && params[axis] !== 0)
|
|
437
|
+
out.push({ path: `pieces[0].${axis}`, message: "an icon is drawn at 0, 0" });
|
|
438
|
+
checkEntry(piece, { ...params, x: 0, y: 0 }, "pieces[0]", out);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
else if (format === "favicon" || format === "avatar") {
|
|
442
|
+
if (pieces.length > 0) {
|
|
443
|
+
out.push({ path: "pieces", message: `not used by the ${format} format` });
|
|
444
|
+
blocked.push("pieces");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
for (let index = 0; index < pieces.length; index++) {
|
|
449
|
+
const entry = pieces[index];
|
|
450
|
+
const at = `pieces[${index}]`;
|
|
451
|
+
if (!isPlainObject(entry)) {
|
|
452
|
+
out.push({ path: at, message: "expected an object with piece and its parameters" });
|
|
453
|
+
blocked.push(at);
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const { piece, ...params } = entry;
|
|
457
|
+
if (typeof piece !== "string" || !PIECE_NAMES.includes(piece)) {
|
|
458
|
+
out.push({ path: `${at}.piece`, message: `unknown piece ${describe(piece)} (expected one of ${PIECE_NAMES.join(", ")})` });
|
|
459
|
+
blocked.push(at);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (piece === "rings") {
|
|
463
|
+
out.push({ path: `${at}.piece`, message: "rings belong to the cover's rings field" });
|
|
464
|
+
blocked.push(at);
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
checkEntry(piece, params, at, out);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return { problems: out, blocked };
|
|
471
|
+
};
|
|
472
|
+
/** Under a path (the path itself included): `a` covers `a`, `a.b` and `a[0]`. */
|
|
473
|
+
const under = (path, base) => path === base || path.startsWith(`${base}.`) || path.startsWith(`${base}[`);
|
|
474
|
+
/** Sorted, one per path and message; a colour literal replaces any other problem at its path. */
|
|
475
|
+
const finish = (out) => {
|
|
476
|
+
const literalPaths = new Set(out.filter((p) => p.message.startsWith("colour literals")).map((p) => p.path));
|
|
477
|
+
const seen = new Set();
|
|
478
|
+
const unique = out.filter((p) => {
|
|
479
|
+
const key = `${p.path}\u0000${p.message}`;
|
|
480
|
+
if (seen.has(key) || (literalPaths.has(p.path) && !p.message.startsWith("colour literals")))
|
|
481
|
+
return false;
|
|
482
|
+
seen.add(key);
|
|
483
|
+
return true;
|
|
484
|
+
});
|
|
485
|
+
return unique.sort((a, b) => comparePaths(a.path, b.path) || compareCodePoints(a.message, b.message));
|
|
486
|
+
};
|
|
487
|
+
/** Every problem of a parsed spec, sorted by path; empty when the spec is valid. `lang` picks a text table. */
|
|
488
|
+
export const validateCoverSpec = (spec, options = {}) => {
|
|
489
|
+
if (!isPlainObject(spec))
|
|
490
|
+
return [{ path: "(root)", message: `a cover spec must be a JSON object, found ${Array.isArray(spec) ? "an array" : describe(spec)}` }];
|
|
491
|
+
// A LinkedIn banner's words are English (STY-8): another table is reported whatever --lang names, and stops the check.
|
|
492
|
+
if (spec.format === "linkedin-banner" && isPlainObject(spec.text)) {
|
|
493
|
+
const other = Object.keys(spec.text).filter((code) => code !== "en");
|
|
494
|
+
if (other.length > 0)
|
|
495
|
+
return finish(other.map((code) => ({ path: `text.${code}`, message: "a LinkedIn banner's words are English" })));
|
|
496
|
+
}
|
|
497
|
+
// Text problems stop the check: references cannot be resolved, so the rest would report false problems.
|
|
498
|
+
const { table, problems: textProblems } = pickTable(spec, options.lang);
|
|
499
|
+
if (textProblems.length > 0)
|
|
500
|
+
return finish(textProblems);
|
|
501
|
+
const { spec: resolved, unknown } = table ? resolveText(spec, table) : { spec, unknown: [] };
|
|
502
|
+
const { problems, blocked } = validateResolved(resolved);
|
|
503
|
+
// A container with the wrong shape is one problem: nothing inside it is reported (its `piece` problem stays).
|
|
504
|
+
// An unknown text key replaces every other problem at its path.
|
|
505
|
+
const insideBlocked = (path) => blocked.some((b) => under(path, b) && path !== b && path !== `${b}.piece`);
|
|
506
|
+
// Unknown references inside a wrong container are not reported either: the container is one problem.
|
|
507
|
+
// A reference in an entry's `piece` names the piece: it is reported even when its container is refused.
|
|
508
|
+
const unknownKept = unknown.filter((u) => !insideBlocked(u.path) || /^pieces\[\d+\]\.piece$/.test(u.path));
|
|
509
|
+
const kept = problems.filter((p) => !insideBlocked(p.path) && !unknownKept.some((u) => under(p.path, u.path)));
|
|
510
|
+
return finish([...kept, ...unknownKept]);
|
|
511
|
+
};
|
|
512
|
+
// ---------- drawing ----------
|
|
513
|
+
const resolveCustom = (node) => {
|
|
514
|
+
const attrs = {};
|
|
515
|
+
for (const [name, value] of Object.entries(node.attrs ?? {})) {
|
|
516
|
+
attrs[name] = typeof value === "string" && COLOUR_ATTRS.has(name) && value !== "none" ? COLOUR_TOKENS.get(value) : value;
|
|
517
|
+
}
|
|
518
|
+
// The outlined group would stroke the letters; free-form words are never outlined.
|
|
519
|
+
if (node.tag === "text")
|
|
520
|
+
attrs.stroke = "none";
|
|
521
|
+
return el(node.tag, attrs, ...(node.children ?? []).map((child) => (typeof child === "string" ? child : resolveCustom(child))));
|
|
522
|
+
};
|
|
523
|
+
/** Rings a banner draws: out to the frame's farthest corner (spec cover-cli, "Banner rings reach the corners").
|
|
524
|
+
* The frame defaults to the banner's (1200x420); a LinkedIn banner passes its 1584x396 ("Ring count takes a frame size"). */
|
|
525
|
+
export const bannerRingCount = (cx, cy, radius = tokens.cover.ringRadius, width = tokens.banner.width, height = tokens.banner.height) => {
|
|
526
|
+
const far = Math.max(...[[0, 0], [width, 0], [0, height], [width, height]].map(([x, y]) => Math.hypot(x - cx, y - cy)));
|
|
527
|
+
return Math.max(1, Math.ceil((far - radius) / tokens.cover.ringStep) + 1);
|
|
528
|
+
};
|
|
529
|
+
/** Layout units per shown pixel of a body diagram (560 / 800). */
|
|
530
|
+
const LAYOUT_SCALE = tokens.bodyDiagram.layoutWidth / tokens.bodyDiagram.width;
|
|
531
|
+
/** Rings of a diagram (spec cover-cli, "Diagram rings at the shown scale"): the cover's step and width at the shown scale. */
|
|
532
|
+
export const diagramRings = (cx, cy, height, radius = tokens.bodyDiagram.ringRadius * LAYOUT_SCALE) => {
|
|
533
|
+
const width = tokens.bodyDiagram.layoutWidth;
|
|
534
|
+
const step = tokens.cover.ringStep * LAYOUT_SCALE;
|
|
535
|
+
const far = Math.max(...[[0, 0], [width, 0], [0, height], [width, height]].map(([x, y]) => Math.hypot(x - cx, y - cy)));
|
|
536
|
+
return { count: Math.max(1, Math.ceil((far - radius) / step) + 1), step, width: tokens.cover.ringWidth * LAYOUT_SCALE, radius };
|
|
537
|
+
};
|
|
538
|
+
const draw = (entry) => {
|
|
539
|
+
const { piece, ...params } = entry;
|
|
540
|
+
return PIECES[piece](params);
|
|
541
|
+
};
|
|
542
|
+
/** The outlined group's children: every body in paint order, `custom` before `pieces[customAt]` (default: last). */
|
|
543
|
+
const bodies = (spec, drawnPieces) => {
|
|
544
|
+
const custom = spec.custom ? resolveCustom(spec.custom) : null;
|
|
545
|
+
const at = spec.customAt ?? drawnPieces.length;
|
|
546
|
+
return [...drawnPieces.slice(0, at).flatMap((d) => d.body), custom, ...drawnPieces.slice(at).flatMap((d) => d.body)];
|
|
547
|
+
};
|
|
548
|
+
const root = (id, width, height, viewBox, ...children) => el("svg", { xmlns: "http://www.w3.org/2000/svg", width, height, viewBox, role: "img", "aria-labelledby": `${id}-title ${id}-desc`, "font-family": tokens.font.sans }, ...children);
|
|
549
|
+
/** An icon (spec cover-cli, "Icon output"): the piece at 0,0 in a box of its own size. */
|
|
550
|
+
const iconTree = (spec) => {
|
|
551
|
+
const entry = spec.pieces[0];
|
|
552
|
+
const [width, height] = iconBox(entry);
|
|
553
|
+
const eip = entry.piece === "eipIcon" ? EIP_ICONS.find((icon) => icon.name === entry.name) : undefined;
|
|
554
|
+
return root(spec.id, width, height, `0 0 ${width} ${height}`, el("title", { id: `${spec.id}-title` }, eip?.title ?? spec.title), el("desc", { id: `${spec.id}-desc` }, eip?.description ?? spec.description), ...draw({ ...entry, x: 0, y: 0 }).body);
|
|
555
|
+
};
|
|
556
|
+
/** A body diagram (spec cover-cli, "Diagram output"): laid out 560 wide, shown 800 wide, on the panel. */
|
|
557
|
+
const diagramTree = (spec) => {
|
|
558
|
+
const width = tokens.bodyDiagram.layoutWidth;
|
|
559
|
+
const height = spec.height;
|
|
560
|
+
const rx = r2(tokens.bodyDiagram.radius * LAYOUT_SCALE);
|
|
561
|
+
const frame = `url(#${spec.id}-frame)`;
|
|
562
|
+
const ring = diagramRings(spec.rings.cx, spec.rings.cy, height, spec.rings.radius);
|
|
563
|
+
const drawnPieces = spec.pieces.map(draw);
|
|
564
|
+
return root(spec.id, tokens.bodyDiagram.width, r2(height / LAYOUT_SCALE), `0 0 ${width} ${height}`, el("title", { id: `${spec.id}-title` }, spec.title), el("desc", { id: `${spec.id}-desc` }, spec.description), el("defs", {}, el("clipPath", { id: `${spec.id}-frame` }, el("rect", { width, height, rx }))), el("rect", { width, height, rx, fill: tokens.color.panel }), g({ "clip-path": frame }, g({ fill: "none", stroke: tokens.color.ring, "stroke-width": r2(ring.width) }, ...Array.from({ length: ring.count }, (_, i) => el("circle", { cx: spec.rings.cx, cy: spec.rings.cy, r: r2(ring.radius + i * ring.step) })))), g({ "clip-path": frame }, g({ stroke: tokens.color.ink, "stroke-width": tokens.map.outline, "stroke-linejoin": "round" }, ...bodies(spec, drawnPieces)), g({ "font-size": tokens.map.labelSize, "font-weight": tokens.cover.labelWeight, fill: tokens.color.ink, "text-anchor": "middle" }, ...drawnPieces.flatMap((d) => d.text))));
|
|
565
|
+
};
|
|
566
|
+
/** Mira (scale 0.25) and the symbol, bottom-right corner, `cover.signatureMargin` from both edges (spec cover-cli, "Signature lockup"). */
|
|
567
|
+
const signatureGroup = (width, height) => {
|
|
568
|
+
const margin = tokens.cover.signatureMargin;
|
|
569
|
+
const miraScale = 0.25;
|
|
570
|
+
// Mira's own viewBox (sheet7.py's VB): 220 wide, 175 tall, ground at the box's bottom.
|
|
571
|
+
const miraWidth = 220 * miraScale;
|
|
572
|
+
const miraHeight = 175 * miraScale;
|
|
573
|
+
const symbolSize = 24;
|
|
574
|
+
const gap = 6;
|
|
575
|
+
const groupWidth = miraWidth + gap + symbolSize;
|
|
576
|
+
const groupHeight = Math.max(miraHeight, symbolSize);
|
|
577
|
+
const left = width - margin - groupWidth;
|
|
578
|
+
const top = height - margin - groupHeight;
|
|
579
|
+
return g({ "data-piece": "signature" }, ...mira({ x: r2(left + miraWidth / 2), y: r2(top + miraHeight), scale: miraScale }).body, ...symbol({ x: r2(left + miraWidth + gap), y: r2(top + (groupHeight - symbolSize) / 2), scale: symbolSize / 32 }).body);
|
|
580
|
+
};
|
|
581
|
+
/** A favicon (spec cover-cli, "New icon formats"): the symbol, both themes, switched by `prefers-color-scheme`. */
|
|
582
|
+
const faviconTree = (spec) => {
|
|
583
|
+
const size = FAVICON_SIZE;
|
|
584
|
+
return root(spec.id, size, size, `0 0 ${size} ${size}`, el("title", { id: `${spec.id}-title` }, spec.title), el("desc", { id: `${spec.id}-desc` }, spec.description), el("style", {}, `.ds-favicon-dark{display:none}@media (prefers-color-scheme:dark){.ds-favicon-light{display:none}.ds-favicon-dark{display:inline}}`), g({ class: "ds-favicon-light" }, ...symbol({ x: 0, y: 0, surface: "light" }).body), g({ class: "ds-favicon-dark" }, ...symbol({ x: 0, y: 0, surface: "dark" }).body));
|
|
585
|
+
};
|
|
586
|
+
/** An avatar (spec cover-cli, "New icon formats", "Avatar ground"): the symbol only, filling the frame, on
|
|
587
|
+
* `brand.light.accentText` or on the `background` pair's fill. Without `background` the tree is 0.9.1's. */
|
|
588
|
+
const avatarTree = (spec) => {
|
|
589
|
+
const size = AVATAR_SIZE;
|
|
590
|
+
const scale = size / 32;
|
|
591
|
+
return root(spec.id, size, size, `0 0 ${size} ${size}`, el("title", { id: `${spec.id}-title` }, spec.title), el("desc", { id: `${spec.id}-desc` }, spec.description), el("rect", { width: size, height: size, fill: spec.background === undefined ? tokens.brand.light.accentText : tokens.coverBackground[spec.background].fill }), g({ transform: `scale(${scale})` }, ...symbol({ x: 0, y: 0, surface: "light" }).body));
|
|
592
|
+
};
|
|
593
|
+
/** The cover's (banner's, diagram's, icon's, favicon's, avatar's) node tree. The spec must be valid for `lang` (validateCoverSpec returned no problem). */
|
|
594
|
+
export const coverTree = (input, options = {}) => {
|
|
595
|
+
const spec = forLanguage(input, options.lang);
|
|
596
|
+
if (spec.format === "icon")
|
|
597
|
+
return iconTree(spec);
|
|
598
|
+
if (spec.format === "diagram")
|
|
599
|
+
return diagramTree(spec);
|
|
600
|
+
if (spec.format === "favicon")
|
|
601
|
+
return faviconTree(spec);
|
|
602
|
+
if (spec.format === "avatar")
|
|
603
|
+
return avatarTree(spec);
|
|
604
|
+
const banner = spec.format === "banner";
|
|
605
|
+
const linkedinCard = spec.format === "linkedin-card";
|
|
606
|
+
const og = spec.format === "og";
|
|
607
|
+
const linkedinBanner = spec.format === "linkedin-banner";
|
|
608
|
+
const { width, height } = linkedinCard
|
|
609
|
+
? { width: LINKEDIN_CARD_SIZE, height: LINKEDIN_CARD_SIZE }
|
|
610
|
+
: linkedinBanner
|
|
611
|
+
? { width: LINKEDIN_BANNER_WIDTH, height: LINKEDIN_BANNER_HEIGHT }
|
|
612
|
+
: og
|
|
613
|
+
? { width: OG_WIDTH, height: OG_HEIGHT }
|
|
614
|
+
: banner
|
|
615
|
+
? tokens.banner
|
|
616
|
+
: tokens.cover;
|
|
617
|
+
// A banner's corners are rounded; a cover, a LinkedIn card, an og image and a LinkedIn banner keep the square frame, attribute for attribute.
|
|
618
|
+
const corner = banner ? { rx: tokens.banner.radius } : {};
|
|
619
|
+
const pair = tokens.coverBackground[spec.background];
|
|
620
|
+
const drawnPieces = spec.pieces.map(draw);
|
|
621
|
+
const ringPath = `coverBackground.${spec.background}.ring`;
|
|
622
|
+
// A banner and a LinkedIn banner draw their rings out to the farthest corner; a cover keeps the default count.
|
|
623
|
+
const ringCount = banner
|
|
624
|
+
? { count: bannerRingCount(spec.rings.cx, spec.rings.cy, spec.rings.radius) }
|
|
625
|
+
: linkedinBanner
|
|
626
|
+
? { count: bannerRingCount(spec.rings.cx, spec.rings.cy, spec.rings.radius, width, height) }
|
|
627
|
+
: {};
|
|
628
|
+
const frame = `url(#${spec.id}-frame)`;
|
|
629
|
+
const signature = spec.format !== "linkedin-banner" && spec.signature ? signatureGroup(width, height) : null;
|
|
630
|
+
const outlined = g({ stroke: tokens.color.ink, "stroke-width": tokens.outline.block, "stroke-linejoin": "round" }, ...bodies(spec, drawnPieces), signature);
|
|
631
|
+
const labels = g({ "font-size": tokens.cover.labelSize, "font-weight": tokens.cover.labelWeight, fill: tokens.color.ink, "text-anchor": "middle" }, ...drawnPieces.flatMap((d) => d.text));
|
|
632
|
+
return root(spec.id, width, height, `0 0 ${width} ${height}`, el("title", { id: `${spec.id}-title` }, spec.title), el("desc", { id: `${spec.id}-desc` }, spec.description), el("defs", {}, el("clipPath", { id: `${spec.id}-frame` }, el("rect", { width, height, ...corner }))), el("rect", { width, height, ...corner, fill: pair.fill }), g({ "clip-path": frame }, ...rings({ ...spec.rings, color: ringPath, ...ringCount }).body),
|
|
633
|
+
// On a banner, pieces and labels are clipped too, so nothing pokes past a rounded corner.
|
|
634
|
+
...(banner ? [g({ "clip-path": frame }, outlined, labels)] : [outlined, labels]));
|
|
635
|
+
};
|