@iksnerd/blazon 0.4.0 → 0.5.1
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/CHANGELOG.md +375 -0
- package/dist/chunks/{site-builder-BOQjoDbM.js → site-builder-C8g2sfUv.js} +3519 -3712
- package/dist/cli/commands/approvals.d.ts +1 -1
- package/dist/cli/commands/approvals.d.ts.map +1 -1
- package/dist/cli/commands/mcp-check.d.ts +7 -4
- package/dist/cli/commands/mcp-check.d.ts.map +1 -1
- package/dist/cli/errors.d.ts +3 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/folder-first.d.ts +7 -0
- package/dist/cli/folder-first.d.ts.map +1 -0
- package/dist/cli/index.js +1098 -965
- package/dist/cli/operations.d.ts.map +1 -1
- package/dist/cli/where.d.ts +2 -0
- package/dist/cli/where.d.ts.map +1 -1
- package/dist/core/assets/representations.d.ts +44 -0
- package/dist/core/assets/representations.d.ts.map +1 -0
- package/dist/core/assets/scanner.d.ts.map +1 -1
- package/dist/core/assets/sidecar.d.ts.map +1 -1
- package/dist/core/brand/export.d.ts +13 -5
- package/dist/core/brand/export.d.ts.map +1 -1
- package/dist/core/brand/schema.d.ts +68 -0
- package/dist/core/brand/schema.d.ts.map +1 -1
- package/dist/core/checker/approvals.d.ts +5 -0
- package/dist/core/checker/approvals.d.ts.map +1 -1
- package/dist/core/checker/catalogue.d.ts +31 -7
- package/dist/core/checker/catalogue.d.ts.map +1 -1
- package/dist/core/checker/font-meta.d.ts.map +1 -1
- package/dist/core/checker/review.d.ts +19 -1
- package/dist/core/checker/review.d.ts.map +1 -1
- package/dist/core/docs/directives.d.ts +10 -0
- package/dist/core/docs/directives.d.ts.map +1 -1
- package/dist/core/docs/parser.d.ts.map +1 -1
- package/dist/core/font-roles.d.ts +11 -0
- package/dist/core/font-roles.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/init/from-site/fonts.d.ts.map +1 -1
- package/dist/core/logo/colorways.d.ts +29 -0
- package/dist/core/logo/colorways.d.ts.map +1 -0
- package/dist/core/logo/misuse.d.ts +18 -0
- package/dist/core/logo/misuse.d.ts.map +1 -0
- package/dist/core/mcp-config.d.ts +7 -0
- package/dist/core/mcp-config.d.ts.map +1 -1
- package/dist/core/read/can.d.ts +2 -1
- package/dist/core/read/can.d.ts.map +1 -1
- package/dist/core/read/fonts.d.ts +2 -6
- package/dist/core/read/fonts.d.ts.map +1 -1
- package/dist/core/read/logo.d.ts +3 -3
- package/dist/core/read/logo.d.ts.map +1 -1
- package/dist/core/read/lookup.d.ts +2 -2
- package/dist/core/read/lookup.d.ts.map +1 -1
- package/dist/core/read/theme.d.ts +1 -1
- package/dist/core/read/theme.d.ts.map +1 -1
- package/dist/core/tokens/alias.d.ts +5 -3
- package/dist/core/tokens/alias.d.ts.map +1 -1
- package/dist/core/tokens/contexts.d.ts +11 -3
- package/dist/core/tokens/contexts.d.ts.map +1 -1
- package/dist/core/tokens/formatters/json.d.ts +4 -1
- package/dist/core/tokens/formatters/json.d.ts.map +1 -1
- package/dist/core/tokens/key-lines.d.ts.map +1 -1
- package/dist/core/tokens/merge.d.ts.map +1 -1
- package/dist/core/tokens/resolver/compile.d.ts.map +1 -1
- package/dist/core/tokens/resolver/parse.d.ts.map +1 -1
- package/dist/core/tokens/resolver/sources.d.ts.map +1 -1
- package/dist/core/tokens/walk.d.ts.map +1 -1
- package/dist/index.js +34 -34
- package/dist/plugins/host/call.d.ts.map +1 -1
- package/dist/plugins/roles/roles.d.ts.map +1 -1
- package/dist/server/plugin.d.ts.map +1 -1
- package/dist/types/assets.d.ts +19 -1
- package/dist/types/assets.d.ts.map +1 -1
- package/dist/types/parsed.d.ts +8 -0
- package/dist/types/parsed.d.ts.map +1 -1
- package/dist/types/tokens.d.ts +12 -0
- package/dist/types/tokens.d.ts.map +1 -1
- package/dist/ui/assets/index-b4HhGGrn.js +82 -0
- package/dist/ui/assets/index-pE1ku5gt.css +2 -0
- package/dist/ui/index.html +2 -2
- package/mcp/dist/index.js +4 -4
- package/package.json +3 -2
- package/plugins/blazon.brand-deck/README.md +1 -1
- package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +106 -13
- package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +120 -12
- package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +45 -1
- package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +45 -1
- package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +66 -3
- package/plugins/blazon.platform-tokens/README.md +1 -1
- package/plugins/blazon.press-kit/README.md +17 -9
- package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +621 -101
- package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +59 -3
- package/plugins/shipped.lock +8 -8
- package/dist/ui/assets/index-Biy1hkeq.css +0 -2
- package/dist/ui/assets/index-dkJG6W9p.js +0 -82
|
@@ -19,10 +19,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
let node_fs = require("node:fs");
|
|
23
|
-
node_fs = __toESM(node_fs, 1);
|
|
24
22
|
let node_path = require("node:path");
|
|
25
23
|
node_path = __toESM(node_path, 1);
|
|
24
|
+
let node_fs = require("node:fs");
|
|
25
|
+
node_fs = __toESM(node_fs, 1);
|
|
26
26
|
let pdf_lib = require("pdf-lib");
|
|
27
27
|
let playwright_core = require("playwright-core");
|
|
28
28
|
/** What the findings may take on the wire, in bytes. The limit is 65,536; the rest is the envelope, the summary finding and a newline, with room to spare. */
|
|
@@ -156,6 +156,77 @@ async function runPlugin(argv, manifest, build, failure, name) {
|
|
|
156
156
|
return 2;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
/** Replaces `dir` with a folder holding exactly `entries`: what `dir` held before, such as a file of an earlier run, is gone. */
|
|
160
|
+
function replaceFolder(dir, entries) {
|
|
161
|
+
const staged = `${dir}.part`;
|
|
162
|
+
const old = `${dir}.old`;
|
|
163
|
+
node_fs.default.rmSync(staged, {
|
|
164
|
+
recursive: true,
|
|
165
|
+
force: true
|
|
166
|
+
});
|
|
167
|
+
node_fs.default.rmSync(old, {
|
|
168
|
+
recursive: true,
|
|
169
|
+
force: true
|
|
170
|
+
});
|
|
171
|
+
try {
|
|
172
|
+
stage(staged, entries);
|
|
173
|
+
const had = node_fs.default.lstatSync(dir, { throwIfNoEntry: false }) !== void 0;
|
|
174
|
+
if (had) node_fs.default.renameSync(dir, old);
|
|
175
|
+
try {
|
|
176
|
+
node_fs.default.renameSync(staged, dir);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (had) node_fs.default.renameSync(old, dir);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
} finally {
|
|
182
|
+
node_fs.default.rmSync(staged, {
|
|
183
|
+
recursive: true,
|
|
184
|
+
force: true
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
node_fs.default.rmSync(old, {
|
|
188
|
+
recursive: true,
|
|
189
|
+
force: true
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Writes `entries` into `dir`, leaving the other files in it. A file is never seen half written. Used where `dir` is the host's own
|
|
194
|
+
* out_dir, which a plugin may not replace, so the set is staged in a folder inside it and moved up once it is all made.
|
|
195
|
+
*/
|
|
196
|
+
function writeFolder(dir, entries) {
|
|
197
|
+
const staged = node_path.default.join(dir, ".part");
|
|
198
|
+
node_fs.default.rmSync(staged, {
|
|
199
|
+
recursive: true,
|
|
200
|
+
force: true
|
|
201
|
+
});
|
|
202
|
+
try {
|
|
203
|
+
stage(staged, entries);
|
|
204
|
+
for (const file of walk(staged)) {
|
|
205
|
+
const target = node_path.default.join(dir, file);
|
|
206
|
+
node_fs.default.mkdirSync(node_path.default.dirname(target), { recursive: true });
|
|
207
|
+
node_fs.default.renameSync(node_path.default.join(staged, file), target);
|
|
208
|
+
}
|
|
209
|
+
} finally {
|
|
210
|
+
node_fs.default.rmSync(staged, {
|
|
211
|
+
recursive: true,
|
|
212
|
+
force: true
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function stage(folder, entries) {
|
|
217
|
+
node_fs.default.mkdirSync(folder, { recursive: true });
|
|
218
|
+
for (const [file, content] of entries) {
|
|
219
|
+
const target = node_path.default.join(folder, file);
|
|
220
|
+
node_fs.default.mkdirSync(node_path.default.dirname(target), { recursive: true });
|
|
221
|
+
node_fs.default.writeFileSync(target, content);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function walk(root, sub = "") {
|
|
225
|
+
return node_fs.default.readdirSync(node_path.default.join(root, sub), { withFileTypes: true }).flatMap((item) => {
|
|
226
|
+
const rel = node_path.default.join(sub, item.name);
|
|
227
|
+
return item.isDirectory() ? walk(root, rel) : [rel];
|
|
228
|
+
});
|
|
229
|
+
}
|
|
159
230
|
var CRC_TABLE = Uint32Array.from({ length: 256 }, (_, n) => {
|
|
160
231
|
let c = n;
|
|
161
232
|
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
@@ -210,6 +281,73 @@ function zipOf(entries) {
|
|
|
210
281
|
end
|
|
211
282
|
]);
|
|
212
283
|
}
|
|
284
|
+
/** The roles a font token can state, closed: a brand's type page names a role for each typeface and a fallback with its reason */
|
|
285
|
+
var FONT_ROLES = [
|
|
286
|
+
"primary",
|
|
287
|
+
"secondary",
|
|
288
|
+
"display",
|
|
289
|
+
"monospace",
|
|
290
|
+
"fallback"
|
|
291
|
+
];
|
|
292
|
+
/** Text on one line, not blank, up to `max` characters: what a font's `reason` and `fallbackFor` must be */
|
|
293
|
+
var isOneLine = (value, max) => typeof value === "string" && value.trim() !== "" && !/[\r\n]/.test(value) && value.length <= max;
|
|
294
|
+
/**
|
|
295
|
+
* The `role`, `reason` and `fallbackFor` of a font's meta that are valid, and nothing else: a value `blazon check` warns about is left out
|
|
296
|
+
* of what is printed. `fallbackFor` counts only on a role of `fallback`.
|
|
297
|
+
*/
|
|
298
|
+
function fontRoleFields(meta) {
|
|
299
|
+
const font = typeof meta === "object" && meta !== null ? meta : {};
|
|
300
|
+
const role = FONT_ROLES.find((name) => name === font.role);
|
|
301
|
+
return {
|
|
302
|
+
...role && { role },
|
|
303
|
+
...isOneLine(font.reason, 160) && { reason: font.reason },
|
|
304
|
+
...role === "fallback" && isOneLine(font.fallbackFor, 80) && { fallbackFor: font.fallbackFor }
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Compares two strings by UTF-16 code unit. It gives the same answer on every host, which a locale-aware compare does not. */
|
|
308
|
+
function compareText(a, b) {
|
|
309
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
310
|
+
}
|
|
311
|
+
/** The order a reader follows when it has no preference of its own: vector first, then the rasters, then any other format by name. */
|
|
312
|
+
var DEFAULT_FORMAT_ORDER = [
|
|
313
|
+
"svg",
|
|
314
|
+
"png",
|
|
315
|
+
"webp",
|
|
316
|
+
"jpg",
|
|
317
|
+
"gif"
|
|
318
|
+
];
|
|
319
|
+
var pathOf = (record) => record.filePath ?? record.file ?? "";
|
|
320
|
+
/** The file name of a representation, the last segment of its path. */
|
|
321
|
+
function fileNameOf(record) {
|
|
322
|
+
const path = pathOf(record);
|
|
323
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
324
|
+
}
|
|
325
|
+
var defaultRank = (format) => {
|
|
326
|
+
const at = DEFAULT_FORMAT_ORDER.indexOf(format === "jpeg" ? "jpg" : format);
|
|
327
|
+
return at === -1 ? DEFAULT_FORMAT_ORDER.length : at;
|
|
328
|
+
};
|
|
329
|
+
/** The order of two representations of one id: the caller's formats first, then the default order, then the file name. */
|
|
330
|
+
function compareRepresentations(a, b, options = {}) {
|
|
331
|
+
const preferred = options.formats;
|
|
332
|
+
if (preferred) {
|
|
333
|
+
const rank = (r) => {
|
|
334
|
+
const at = preferred.indexOf(r.format);
|
|
335
|
+
return at === -1 ? preferred.length : at;
|
|
336
|
+
};
|
|
337
|
+
const byWish = rank(a) - rank(b);
|
|
338
|
+
if (byWish !== 0) return byWish;
|
|
339
|
+
}
|
|
340
|
+
return defaultRank(a.format) - defaultRank(b.format) || compareText(a.format, b.format) || compareText(fileNameOf(a), fileNameOf(b)) || compareText(pathOf(a), pathOf(b));
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* For a reader that keys a map by id while it reads the records: puts `record` in the map unless the map already holds a better
|
|
344
|
+
* representation of that id. A record in a format the caller does not list is kept only when the id has no other, so the caller
|
|
345
|
+
* can say what is wrong with it. The map ends the same whatever order the records come in.
|
|
346
|
+
*/
|
|
347
|
+
function keepRepresentation(map, record, options = {}) {
|
|
348
|
+
const held = map.get(record.id);
|
|
349
|
+
if (!held || compareRepresentations(record, held, options) < 0) map.set(record.id, record);
|
|
350
|
+
}
|
|
213
351
|
/** A non-empty string (not only whitespace), or undefined. */
|
|
214
352
|
var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
215
353
|
/** An asset's id, file, format and category (the first segment of the id when the entry has none); undefined when the entry lacks one of the first three. */
|
|
@@ -284,14 +422,15 @@ function readBrand(brand) {
|
|
|
284
422
|
stack,
|
|
285
423
|
...license && { license },
|
|
286
424
|
...text(font.licenseUrl) && { licenseUrl: font.licenseUrl },
|
|
287
|
-
...text(font.source) && { source: font.source }
|
|
425
|
+
...text(font.source) && { source: font.source },
|
|
426
|
+
...fontRoleFields(font)
|
|
288
427
|
});
|
|
289
428
|
}
|
|
290
429
|
}
|
|
291
430
|
const assets = /* @__PURE__ */ new Map();
|
|
292
431
|
for (const raw of Array.isArray(root.assets) ? root.assets : []) {
|
|
293
432
|
const base = readBaseAsset(raw);
|
|
294
|
-
if (base && isObject(raw)) assets
|
|
433
|
+
if (base && isObject(raw)) keepRepresentation(assets, {
|
|
295
434
|
...base,
|
|
296
435
|
meta: readMeta(raw)
|
|
297
436
|
});
|
|
@@ -352,6 +491,11 @@ function luminance([r, g, b]) {
|
|
|
352
491
|
});
|
|
353
492
|
return .2126 * lr + .7152 * lg + .0722 * lb;
|
|
354
493
|
}
|
|
494
|
+
/** WCAG contrast ratio, 1 to 21 */
|
|
495
|
+
function contrast(a, b) {
|
|
496
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
497
|
+
return (hi + .05) / (lo + .05);
|
|
498
|
+
}
|
|
355
499
|
/** The plugin's name, which blazon's config names it by, and the prefix of its finding codes */
|
|
356
500
|
var NAME = "blazon.press-kit";
|
|
357
501
|
var MANIFEST = {
|
|
@@ -378,7 +522,13 @@ var LIMITS = {
|
|
|
378
522
|
facts: 20,
|
|
379
523
|
label: 60,
|
|
380
524
|
value: 300,
|
|
381
|
-
note: 280
|
|
525
|
+
note: 280,
|
|
526
|
+
contactName: 80,
|
|
527
|
+
contactRole: 80,
|
|
528
|
+
contactPhone: 40,
|
|
529
|
+
contactEmail: 120,
|
|
530
|
+
url: 300,
|
|
531
|
+
terms: 1e3
|
|
382
532
|
};
|
|
383
533
|
var KEYS = [
|
|
384
534
|
"name",
|
|
@@ -386,13 +536,23 @@ var KEYS = [
|
|
|
386
536
|
"unreviewed",
|
|
387
537
|
"logos",
|
|
388
538
|
"company",
|
|
389
|
-
"note"
|
|
539
|
+
"note",
|
|
540
|
+
"terms"
|
|
390
541
|
];
|
|
391
542
|
var COMPANY_KEYS = [
|
|
392
543
|
"description",
|
|
393
544
|
"boilerplate",
|
|
394
|
-
"facts"
|
|
545
|
+
"facts",
|
|
546
|
+
"contact"
|
|
547
|
+
];
|
|
548
|
+
var CONTACT_KEYS = [
|
|
549
|
+
"name",
|
|
550
|
+
"role",
|
|
551
|
+
"email",
|
|
552
|
+
"phone",
|
|
553
|
+
"url"
|
|
395
554
|
];
|
|
555
|
+
var TERMS_KEYS = ["text", "url"];
|
|
396
556
|
var FACT_KEYS = ["label", "value"];
|
|
397
557
|
var finding = findingFor(NAME);
|
|
398
558
|
var invalid = (message, at = "options") => finding("option-invalid", "error", at, message);
|
|
@@ -403,6 +563,24 @@ function textProblem(value, max, oneLine) {
|
|
|
403
563
|
if (value.length > max) return `must be at most ${max} characters, not ${value.length}`;
|
|
404
564
|
if (oneLine && /[\r\n]/.test(value)) return "must be on one line";
|
|
405
565
|
}
|
|
566
|
+
/** An http or https address on one line, up to the cap, or the reason it is not */
|
|
567
|
+
function urlProblem(value, max) {
|
|
568
|
+
const problem = textProblem(value, max, true);
|
|
569
|
+
if (problem) return problem;
|
|
570
|
+
const text = value.trim();
|
|
571
|
+
if (/\s/.test(text)) return "must not contain spaces";
|
|
572
|
+
try {
|
|
573
|
+
if (!["http:", "https:"].includes(new URL(text).protocol)) return "must be an http or https address";
|
|
574
|
+
} catch {
|
|
575
|
+
return "must be an http or https address";
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/** An address of one `@` with something on each side and no spaces, on one line */
|
|
579
|
+
function emailProblem(value, max) {
|
|
580
|
+
const problem = textProblem(value, max, true);
|
|
581
|
+
if (problem) return problem;
|
|
582
|
+
return /^[^\s@]+@[^\s@]+$/.test(value.trim()) ? void 0 : "must be an email address of one @ and no spaces";
|
|
583
|
+
}
|
|
406
584
|
/** A text as a file name: letters, digits, dots, hyphens and underscores, so it is plain ASCII and cannot leave the folder. */
|
|
407
585
|
var fileName = (text) => text.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^[-.]+/, "") || "file";
|
|
408
586
|
/**
|
|
@@ -449,6 +627,7 @@ function parseOptions(raw, logoIds) {
|
|
|
449
627
|
if (problem) findings.push(invalid(`note ${problem}`, "options.note"));
|
|
450
628
|
else options.note = raw.note.trim();
|
|
451
629
|
}
|
|
630
|
+
if (raw.terms !== void 0) readTerms(raw.terms, options, findings);
|
|
452
631
|
return {
|
|
453
632
|
options,
|
|
454
633
|
findings
|
|
@@ -489,8 +668,56 @@ function readCompany(raw, options, findings) {
|
|
|
489
668
|
if (facts.length > 0) company.facts = facts;
|
|
490
669
|
}
|
|
491
670
|
}
|
|
671
|
+
if (raw.contact !== void 0) {
|
|
672
|
+
const contact = readContact(raw.contact, findings);
|
|
673
|
+
if (contact) company.contact = contact;
|
|
674
|
+
}
|
|
492
675
|
if (Object.keys(company).length > 0) options.company = company;
|
|
493
676
|
}
|
|
677
|
+
/** company.contact: each value checked on its own; the contact is set when at least one key is good */
|
|
678
|
+
function readContact(raw, findings) {
|
|
679
|
+
const at = "options.company.contact";
|
|
680
|
+
if (!isObject(raw) || Array.isArray(raw) || Object.keys(raw).length === 0) {
|
|
681
|
+
findings.push(invalid(`company.contact must be an object with at least one of ${CONTACT_KEYS.join(", ")}`, at));
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
for (const key of Object.keys(raw)) if (!CONTACT_KEYS.includes(key)) findings.push(invalid(`unknown key "company.contact.${key}"; contact takes ${CONTACT_KEYS.join(", ")}`, at));
|
|
685
|
+
const checks = {
|
|
686
|
+
name: (value) => textProblem(value, LIMITS.contactName, true),
|
|
687
|
+
role: (value) => textProblem(value, LIMITS.contactRole, true),
|
|
688
|
+
email: (value) => emailProblem(value, LIMITS.contactEmail),
|
|
689
|
+
phone: (value) => textProblem(value, LIMITS.contactPhone, true),
|
|
690
|
+
url: (value) => urlProblem(value, LIMITS.url)
|
|
691
|
+
};
|
|
692
|
+
const contact = {};
|
|
693
|
+
for (const key of CONTACT_KEYS) {
|
|
694
|
+
if (raw[key] === void 0) continue;
|
|
695
|
+
const problem = checks[key](raw[key]);
|
|
696
|
+
if (problem) findings.push(invalid(`company.contact.${key} ${problem}`, `${at}.${key}`));
|
|
697
|
+
else contact[key] = raw[key].trim();
|
|
698
|
+
}
|
|
699
|
+
return Object.keys(contact).length > 0 ? contact : void 0;
|
|
700
|
+
}
|
|
701
|
+
/** The terms option: a text, an address, or both */
|
|
702
|
+
function readTerms(raw, options, findings) {
|
|
703
|
+
if (!isObject(raw) || Array.isArray(raw) || Object.keys(raw).length === 0) {
|
|
704
|
+
findings.push(invalid("terms must be an object with at least one of text, url", "options.terms"));
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
for (const key of Object.keys(raw)) if (!TERMS_KEYS.includes(key)) findings.push(invalid(`unknown key "terms.${key}"; terms takes ${TERMS_KEYS.join(", ")}`, "options.terms"));
|
|
708
|
+
const terms = {};
|
|
709
|
+
if (raw.text !== void 0) {
|
|
710
|
+
const problem = textProblem(raw.text, LIMITS.terms, false);
|
|
711
|
+
if (problem) findings.push(invalid(`terms.text ${problem}`, "options.terms.text"));
|
|
712
|
+
else terms.text = raw.text.trim();
|
|
713
|
+
}
|
|
714
|
+
if (raw.url !== void 0) {
|
|
715
|
+
const problem = urlProblem(raw.url, LIMITS.url);
|
|
716
|
+
if (problem) findings.push(invalid(`terms.url ${problem}`, "options.terms.url"));
|
|
717
|
+
else terms.url = raw.url.trim();
|
|
718
|
+
}
|
|
719
|
+
if (Object.keys(terms).length > 0) options.terms = terms;
|
|
720
|
+
}
|
|
494
721
|
var PLAIN = /^(#([0-9a-f]{3}|[0-9a-f]{6})|rgb\(\s*[\d.]+%?[\s,]+[\d.]+%?[\s,]+[\d.]+%?\s*\))$/i;
|
|
495
722
|
var cssName = (path) => `--${path.replace(/[^A-Za-z0-9_-]+/g, "-").toLowerCase()}`;
|
|
496
723
|
function planColors(brand, options = {}) {
|
|
@@ -630,6 +857,72 @@ function families(stack) {
|
|
|
630
857
|
/** The first family of the stack that names a font: not a generic, not a var(). */
|
|
631
858
|
var fontOf = (stack) => stack ? families(stack).find((name) => !GENERIC.has(name.toLowerCase()) && !/[()]/.test(name)) : void 0;
|
|
632
859
|
var NOT_STATED = "not stated";
|
|
860
|
+
/** What to say about one font, in order: the one list both fonts.txt and the page are written from */
|
|
861
|
+
function fontRows(font) {
|
|
862
|
+
const rows = [];
|
|
863
|
+
if (font.usedFor.length > 0) rows.push({
|
|
864
|
+
label: "Used for",
|
|
865
|
+
value: font.usedFor.join(", ")
|
|
866
|
+
});
|
|
867
|
+
if (font.role) rows.push({
|
|
868
|
+
label: "Role",
|
|
869
|
+
value: font.role
|
|
870
|
+
});
|
|
871
|
+
if (font.reason) rows.push({
|
|
872
|
+
label: "Why",
|
|
873
|
+
value: font.reason
|
|
874
|
+
});
|
|
875
|
+
if (font.standsInFor) rows.push({
|
|
876
|
+
label: "Stands in for",
|
|
877
|
+
value: font.standsInFor
|
|
878
|
+
});
|
|
879
|
+
if (font.source !== void 0 || font.license.kind !== "none") rows.push({
|
|
880
|
+
label: "Source",
|
|
881
|
+
value: font.source ?? NOT_STATED
|
|
882
|
+
});
|
|
883
|
+
const license = font.license;
|
|
884
|
+
if (license.kind === "text") {
|
|
885
|
+
rows.push({
|
|
886
|
+
label: "License",
|
|
887
|
+
value: license.text,
|
|
888
|
+
block: true
|
|
889
|
+
});
|
|
890
|
+
if (license.url) rows.push({
|
|
891
|
+
label: "License text",
|
|
892
|
+
value: license.url
|
|
893
|
+
});
|
|
894
|
+
} else if (license.kind === "url") rows.push({
|
|
895
|
+
label: "License",
|
|
896
|
+
value: `see ${license.url}`
|
|
897
|
+
});
|
|
898
|
+
else if (license.kind === "file") rows.push({
|
|
899
|
+
label: "License",
|
|
900
|
+
value: license.headline ?? `see ${license.file}`
|
|
901
|
+
}, {
|
|
902
|
+
label: "License file",
|
|
903
|
+
value: `${license.file} (in the brand project, not in this kit)`
|
|
904
|
+
});
|
|
905
|
+
else if (license.kind === "unstated") rows.push({
|
|
906
|
+
label: "License",
|
|
907
|
+
value: NOT_STATED
|
|
908
|
+
});
|
|
909
|
+
return rows;
|
|
910
|
+
}
|
|
911
|
+
/** The one line that lists the fallbacks, or undefined when there are none */
|
|
912
|
+
var fallbackLine = (fonts) => fonts.fallbacks.length > 0 ? `Fallback fonts, not shipped: ${fonts.fallbacks.join(", ")}` : void 0;
|
|
913
|
+
/** fonts.txt */
|
|
914
|
+
function fontsText(fonts) {
|
|
915
|
+
const lines = ["Fonts", ""];
|
|
916
|
+
for (const font of fonts.families) {
|
|
917
|
+
lines.push(font.name);
|
|
918
|
+
for (const row of fontRows(font)) if (row.block) lines.push(` ${row.label}:`, ...row.value.split("\n").map((line) => ` ${line}`.trimEnd()));
|
|
919
|
+
else lines.push(` ${row.label}: ${row.value}`);
|
|
920
|
+
lines.push("");
|
|
921
|
+
}
|
|
922
|
+
const fallback = fallbackLine(fonts);
|
|
923
|
+
if (fallback) lines.push(fallback);
|
|
924
|
+
return `${lines.join("\n").trimEnd()}\n`;
|
|
925
|
+
}
|
|
633
926
|
var ROLES = [["fontDisplay", "headings (the fontDisplay role)"], ["fontBody", "running text (the fontBody role)"]];
|
|
634
927
|
/** The families a stylesheet loads and where it is from: Google Fonts names them in the URL; a data: stylesheet in its @font-face rules */
|
|
635
928
|
function stylesheetFamilies(sheet) {
|
|
@@ -678,6 +971,9 @@ function planFonts(brand) {
|
|
|
678
971
|
family.license ??= stated?.license;
|
|
679
972
|
family.licenseUrl ??= stated?.licenseUrl;
|
|
680
973
|
family.source ??= stated?.source;
|
|
974
|
+
family.role ??= stated?.role;
|
|
975
|
+
family.reason ??= stated?.reason;
|
|
976
|
+
family.fallbackFor ??= stated?.fallbackFor;
|
|
681
977
|
families$1.set(name.toLowerCase(), family);
|
|
682
978
|
};
|
|
683
979
|
const sheetNames = /* @__PURE__ */ new Set();
|
|
@@ -689,7 +985,7 @@ function planFonts(brand) {
|
|
|
689
985
|
/** The front family of a stack is a brand font unless it is a system one nothing loads and nothing states a source or license for; the rest of the stack is fallback */
|
|
690
986
|
const take = (stack, usedFor, stated) => {
|
|
691
987
|
const name = fontOf(stack);
|
|
692
|
-
for (const family of stack ? families(stack) : []) if (family === name && (!SYSTEM_FAMILIES.has(family.toLowerCase()) || sheetNames.has(family.toLowerCase()) || !!(stated?.license || stated?.licenseUrl || stated?.source))) add(family, usedFor, stated);
|
|
988
|
+
for (const family of stack ? families(stack) : []) if (family === name && (!SYSTEM_FAMILIES.has(family.toLowerCase()) || sheetNames.has(family.toLowerCase()) || !!(stated?.license || stated?.licenseUrl || stated?.source || stated?.role))) add(family, usedFor, stated);
|
|
693
989
|
else fallback(family);
|
|
694
990
|
};
|
|
695
991
|
for (const [role, label] of ROLES) take(brand.roles[role], label);
|
|
@@ -715,30 +1011,42 @@ function planFonts(brand) {
|
|
|
715
1011
|
findings.push(finding("font-none", "warning", "theme.roles", "the brand names no font it ships or loads (system fonts and generic families are fallbacks, not brand fonts), so the kit has no fonts.txt"));
|
|
716
1012
|
return { findings };
|
|
717
1013
|
}
|
|
718
|
-
const lines = ["Fonts", ""];
|
|
719
1014
|
const unlicensed = [];
|
|
1015
|
+
const stackFront = new Map(brand.fontTokens.map((token) => [token.path, fontOf(token.stack)]));
|
|
1016
|
+
const kit = [];
|
|
720
1017
|
for (const family of families$1.values()) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1018
|
+
const license = family.license ? {
|
|
1019
|
+
kind: "text",
|
|
1020
|
+
text: family.license,
|
|
1021
|
+
...family.licenseUrl && { url: family.licenseUrl }
|
|
1022
|
+
} : family.licenseUrl ? {
|
|
1023
|
+
kind: "url",
|
|
1024
|
+
url: family.licenseUrl
|
|
1025
|
+
} : family.fileLicense ? {
|
|
1026
|
+
kind: "file",
|
|
1027
|
+
...family.fileLicense.headline && { headline: family.fileLicense.headline },
|
|
1028
|
+
file: family.fileLicense.file
|
|
1029
|
+
} : family.role === "fallback" ? { kind: "none" } : { kind: "unstated" };
|
|
1030
|
+
if (license.kind === "unstated") unlicensed.push(family.name);
|
|
1031
|
+
const source = family.source ?? sources.get(family.name.toLowerCase());
|
|
1032
|
+
kit.push({
|
|
1033
|
+
name: family.name,
|
|
1034
|
+
usedFor: family.usedFor,
|
|
1035
|
+
...family.role && { role: family.role },
|
|
1036
|
+
...family.reason && { reason: family.reason },
|
|
1037
|
+
...family.fallbackFor && { standsInFor: stackFront.get(family.fallbackFor) ?? family.fallbackFor },
|
|
1038
|
+
...source && { source },
|
|
1039
|
+
license
|
|
1040
|
+
});
|
|
736
1041
|
}
|
|
737
|
-
const
|
|
738
|
-
|
|
1042
|
+
const model = {
|
|
1043
|
+
families: kit,
|
|
1044
|
+
fallbacks: [...fallbacks].filter(([key]) => !families$1.has(key)).map(([, name]) => name)
|
|
1045
|
+
};
|
|
739
1046
|
if (unlicensed.length > 0) findings.push(finding("font-license-unstated", "warning", "fonts", `${unlicensed.length} ${unlicensed.length === 1 ? "font has" : "fonts have"} no license stated: ${unlicensed.join(", ")}; fonts.txt says "license not stated" for each`));
|
|
740
1047
|
return {
|
|
741
|
-
text:
|
|
1048
|
+
text: fontsText(model),
|
|
1049
|
+
model,
|
|
742
1050
|
findings
|
|
743
1051
|
};
|
|
744
1052
|
}
|
|
@@ -846,6 +1154,264 @@ function logosText(chosen) {
|
|
|
846
1154
|
}
|
|
847
1155
|
return `${lines.join("\n").trimEnd()}\n`;
|
|
848
1156
|
}
|
|
1157
|
+
/**
|
|
1158
|
+
* about.txt: the name, then the description to quote: the company's when the `company` option gives one, else the brand's. After it come the
|
|
1159
|
+
* company's boilerplate, its facts as `Label: value` lines in the order given, and the note. Without any description it says so in one
|
|
1160
|
+
* line, and a brand with no name has no file.
|
|
1161
|
+
*/
|
|
1162
|
+
function aboutText(brand, extras = {}) {
|
|
1163
|
+
if (!brand.named) return { findings: [] };
|
|
1164
|
+
const { company, terms, note } = extras;
|
|
1165
|
+
const description = company?.description ?? brand.description;
|
|
1166
|
+
const findings = [];
|
|
1167
|
+
const blocks = [brand.title, description ?? "No description is set in blazon.json."];
|
|
1168
|
+
if (!description) findings.push(finding("about-no-description", "warning", "brand.description", "the brand has no description, so about.txt says none is set"));
|
|
1169
|
+
if (company?.boilerplate) blocks.push(company.boilerplate);
|
|
1170
|
+
if (company?.facts) blocks.push(company.facts.map((fact) => `${fact.label}: ${fact.value}`).join("\n"));
|
|
1171
|
+
if (company?.contact) blocks.push(contactText(company.contact));
|
|
1172
|
+
if (terms) blocks.push(termsText(terms));
|
|
1173
|
+
if (note) blocks.push(`Note: ${note}`);
|
|
1174
|
+
return {
|
|
1175
|
+
text: `${blocks.join("\n\n")}\n`,
|
|
1176
|
+
findings
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
var CONTACT_LABELS = [
|
|
1180
|
+
["name", "Name"],
|
|
1181
|
+
["role", "Role"],
|
|
1182
|
+
["email", "Email"],
|
|
1183
|
+
["phone", "Phone"],
|
|
1184
|
+
["url", "Web"]
|
|
1185
|
+
];
|
|
1186
|
+
/** The contact's keys that are set, in a fixed order, as labelled lines: the page, the PDF and about.txt all print these */
|
|
1187
|
+
var contactLines = (contact) => CONTACT_LABELS.flatMap(([key, label]) => contact[key] ? [{
|
|
1188
|
+
label,
|
|
1189
|
+
value: contact[key]
|
|
1190
|
+
}] : []);
|
|
1191
|
+
var contactText = (contact) => ["Contact:", ...contactLines(contact).map(({ label, value }) => ` ${label}: ${value}`)].join("\n");
|
|
1192
|
+
var termsText = (terms) => [
|
|
1193
|
+
"Terms of use:",
|
|
1194
|
+
...terms.text ? [terms.text] : [],
|
|
1195
|
+
...terms.url ? [`Full terms: ${terms.url}`] : []
|
|
1196
|
+
].join("\n");
|
|
1197
|
+
/** What each part of the kit is for, in the order the README lists them; a part is listed when a file of the kit starts or ends as `match` says */
|
|
1198
|
+
var PARTS = [
|
|
1199
|
+
{
|
|
1200
|
+
match: (path) => path === "index.html",
|
|
1201
|
+
says: "The kit as one web page: open it in a browser."
|
|
1202
|
+
},
|
|
1203
|
+
{
|
|
1204
|
+
match: (path) => path.startsWith("logos/"),
|
|
1205
|
+
says: "The logo files as they are. Use the ones in on-light-backgrounds/ on a light background and the ones in on-dark-backgrounds/ on a dark one. logos.txt says what the brand states about each."
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
match: (path) => path.startsWith("colors/"),
|
|
1209
|
+
says: "The brand colors: colors.txt to read, colors.css for a web page, colors.json for a program."
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
match: (path) => path === "fonts.txt",
|
|
1213
|
+
says: "The fonts the brand uses, where each comes from, and under what license, where the brand states one."
|
|
1214
|
+
},
|
|
1215
|
+
{
|
|
1216
|
+
match: (path) => path === "about.txt",
|
|
1217
|
+
says: "The brand name and a short description, to quote."
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
match: (path) => path.endsWith(".pdf"),
|
|
1221
|
+
says: "One page with the name, the description, up to ten colors (whole color groups, in the order of the brand's groups, each labelled with its group and step) and a logo."
|
|
1222
|
+
}
|
|
1223
|
+
];
|
|
1224
|
+
/** README.txt: what is in the kit, in plain words. It names only the parts that are there, and holds no date. */
|
|
1225
|
+
function readmeText(title, paths, name, note, hasTerms = false) {
|
|
1226
|
+
const lines = [`${title}: press kit`, ""];
|
|
1227
|
+
if (note) lines.push(`Note: ${note}`, "");
|
|
1228
|
+
if (hasTerms) lines.push("Terms of use: see about.txt", "");
|
|
1229
|
+
lines.push("What is in this folder", "");
|
|
1230
|
+
const listed = PARTS.flatMap(({ match, says }) => {
|
|
1231
|
+
const hit = paths.find(match);
|
|
1232
|
+
return hit ? [{
|
|
1233
|
+
shown: hit.startsWith("logos/") || hit.startsWith("colors/") ? `${hit.split("/")[0]}/` : hit,
|
|
1234
|
+
says
|
|
1235
|
+
}] : [];
|
|
1236
|
+
});
|
|
1237
|
+
const width = Math.max(16, ...listed.map(({ shown }) => shown.length + 2));
|
|
1238
|
+
for (const { shown, says } of listed) lines.push(` ${shown.padEnd(width)}${says}`);
|
|
1239
|
+
lines.push("", `${name}.zip holds the same files.`, "", "The logos are the brand's own files, not redrawn.");
|
|
1240
|
+
return `${lines.join("\n")}\n`;
|
|
1241
|
+
}
|
|
1242
|
+
/** Text for an HTML text or a double-quoted attribute; each character that could end either is a numeric reference */
|
|
1243
|
+
var esc = (text) => text.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
|
|
1244
|
+
var paragraphs = (text) => text.split(/\n\s*\n/).map((part) => `<p>${esc(part.trim())}</p>`).join("");
|
|
1245
|
+
var isWeb = (value) => /^https?:\/\/[^\s"'<>]+$/i.test(value);
|
|
1246
|
+
var isEmail = (value) => /^[^\s@<>"']+@[^\s@<>"']+$/.test(value);
|
|
1247
|
+
var link = (value) => isWeb(value) ? `<a href="${esc(value)}">${esc(value)}</a>` : esc(value);
|
|
1248
|
+
var dl = (rows, className = "") => `<dl${className ? ` class="${className}"` : ""}>${rows.map(({ label, html }) => `<dt>${esc(label)}</dt><dd>${html}</dd>`).join("")}</dl>`;
|
|
1249
|
+
var section = (title, body) => `<section><h2>${esc(title)}</h2>${body}</section>`;
|
|
1250
|
+
var BLACK = "#000000";
|
|
1251
|
+
var WHITE = "#ffffff";
|
|
1252
|
+
/** The label color for a swatch: the one of black and white that contrasts more, which is always at least 4.58:1 */
|
|
1253
|
+
function labelInk(hex) {
|
|
1254
|
+
const rgb = parseColor(hex);
|
|
1255
|
+
if (!rgb) return BLACK;
|
|
1256
|
+
return contrast(rgb, parseColor(BLACK)) >= contrast(rgb, parseColor(WHITE)) ? BLACK : WHITE;
|
|
1257
|
+
}
|
|
1258
|
+
var SURFACES = [
|
|
1259
|
+
["light", "For light backgrounds"],
|
|
1260
|
+
["dark", "For dark backgrounds"],
|
|
1261
|
+
["unstated", "Background not stated"]
|
|
1262
|
+
];
|
|
1263
|
+
function logoBlock({ asset, surface, kitPath }) {
|
|
1264
|
+
const { meta } = asset;
|
|
1265
|
+
const file = kitPath.split("/").pop();
|
|
1266
|
+
const alt = meta.description || meta.title || asset.id.split("/").pop() || file;
|
|
1267
|
+
const rules = [
|
|
1268
|
+
meta.lockup && {
|
|
1269
|
+
label: "Lockup",
|
|
1270
|
+
html: esc(meta.lockup)
|
|
1271
|
+
},
|
|
1272
|
+
meta.clearSpace && {
|
|
1273
|
+
label: "Clear space on every side",
|
|
1274
|
+
html: esc(measureText(meta.clearSpace, meta))
|
|
1275
|
+
},
|
|
1276
|
+
meta.minSize && {
|
|
1277
|
+
label: "Smallest size",
|
|
1278
|
+
html: esc(dimensionsText(meta.minSize))
|
|
1279
|
+
},
|
|
1280
|
+
meta.maxSize && {
|
|
1281
|
+
label: "Largest size",
|
|
1282
|
+
html: esc(dimensionsText(meta.maxSize))
|
|
1283
|
+
},
|
|
1284
|
+
meta.ink && {
|
|
1285
|
+
label: "Main color",
|
|
1286
|
+
html: esc(meta.ink)
|
|
1287
|
+
}
|
|
1288
|
+
].filter((row) => Boolean(row));
|
|
1289
|
+
const list = (title, items) => items && items.length > 0 ? `<h4>${title}</h4><ul>${items.map((item) => `<li>${esc(item)}</li>`).join("")}</ul>` : "";
|
|
1290
|
+
return `<article class="logo"><div class="plate ${surface === "dark" ? "plate-dark" : ""}"><img src="${esc(kitPath)}" alt="${esc(alt)}"></div><p class="file"><strong>${esc(file)}</strong> <a href="${esc(kitPath)}" download aria-label="Download ${esc(file)}">Download</a></p>${meta.description ? `<p>${esc(meta.description)}</p>` : ""}${rules.length > 0 ? dl(rules, "rules") : ""}${list("Do", meta.do)}${list("Do not", meta.dont)}</article>`;
|
|
1291
|
+
}
|
|
1292
|
+
function colorBlock(color) {
|
|
1293
|
+
const name = color.description && color.description.length <= 60 ? `${color.description} (${color.path})` : color.path;
|
|
1294
|
+
const rows = [
|
|
1295
|
+
color.hex && {
|
|
1296
|
+
label: "HEX",
|
|
1297
|
+
html: esc(color.hex)
|
|
1298
|
+
},
|
|
1299
|
+
color.rgb && {
|
|
1300
|
+
label: "RGB",
|
|
1301
|
+
html: esc(color.rgb.join(", "))
|
|
1302
|
+
},
|
|
1303
|
+
!color.hex && {
|
|
1304
|
+
label: "As written",
|
|
1305
|
+
html: esc(color.value)
|
|
1306
|
+
},
|
|
1307
|
+
color.print?.cmyk && {
|
|
1308
|
+
label: "CMYK",
|
|
1309
|
+
html: esc(color.print.cmyk.join(", "))
|
|
1310
|
+
},
|
|
1311
|
+
color.print?.pms && {
|
|
1312
|
+
label: "Pantone",
|
|
1313
|
+
html: esc(color.print.pms)
|
|
1314
|
+
},
|
|
1315
|
+
color.print?.ral && {
|
|
1316
|
+
label: "RAL",
|
|
1317
|
+
html: esc(color.print.ral)
|
|
1318
|
+
},
|
|
1319
|
+
color.usedAs.length > 0 && {
|
|
1320
|
+
label: "Also named",
|
|
1321
|
+
html: esc(color.usedAs.join(", "))
|
|
1322
|
+
}
|
|
1323
|
+
].filter((row) => Boolean(row));
|
|
1324
|
+
return `<li class="color">${color.hex ? `<div class="swatch" style="background:${esc(color.hex)};color:${labelInk(color.hex)}">${esc(color.hex)}</div>` : ""}<p class="name"><strong>${esc(name)}</strong>${color.review ? " (unreviewed)" : ""}</p>${dl(rows)}</li>`;
|
|
1325
|
+
}
|
|
1326
|
+
var STYLE = `*{box-sizing:border-box}
|
|
1327
|
+
html{-webkit-text-size-adjust:100%}
|
|
1328
|
+
body{margin:0;background:#ffffff;color:#1a1a1a;font:16px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif}
|
|
1329
|
+
main{max-width:60rem;margin:0 auto;padding:2rem 1rem 4rem}
|
|
1330
|
+
h1{margin:0 0 .5rem;font-size:2.25rem;line-height:1.15}
|
|
1331
|
+
h2{margin:2.5rem 0 1rem;padding-top:1rem;border-top:1px solid #d0d0d0;font-size:1.4rem}
|
|
1332
|
+
h3{margin:1.5rem 0 .75rem;font-size:1.1rem}
|
|
1333
|
+
h4{margin:.75rem 0 .25rem;font-size:.95rem}
|
|
1334
|
+
p{margin:0 0 .75rem;overflow-wrap:anywhere}
|
|
1335
|
+
a{color:#0b4f9c}
|
|
1336
|
+
.lead{font-size:1.15rem;max-width:42rem}
|
|
1337
|
+
dt{color:#595959}
|
|
1338
|
+
dl{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:.25rem 1rem;margin:0 0 .75rem}
|
|
1339
|
+
dd{margin:0;overflow-wrap:anywhere;white-space:pre-line}
|
|
1340
|
+
ul{margin:0 0 .75rem;padding-left:1.25rem}
|
|
1341
|
+
.terms p,.note{white-space:pre-line}
|
|
1342
|
+
.note{padding:.5rem .75rem;border-left:3px solid #8a8a8a;background:#f4f4f2}
|
|
1343
|
+
.logos,.colors{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,16rem),1fr));gap:1.5rem}
|
|
1344
|
+
.logo{min-width:0}
|
|
1345
|
+
.plate{display:flex;align-items:center;justify-content:center;height:9rem;padding:1.5rem;margin-bottom:.5rem;border:1px solid #d0d0d0;background:#f4f4f2}
|
|
1346
|
+
.plate-dark{background:#161616}
|
|
1347
|
+
.plate img{display:block;max-width:100%;max-height:7rem;height:auto}
|
|
1348
|
+
.rules{font-size:.9rem}
|
|
1349
|
+
.swatch{display:flex;align-items:flex-end;height:5rem;padding:.5rem .75rem;border:1px solid #d0d0d0;font:600 .9rem/1.2 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
1350
|
+
.color{min-width:0}
|
|
1351
|
+
.color .name{margin:.5rem 0 .25rem}
|
|
1352
|
+
.color dl{font-size:.9rem}
|
|
1353
|
+
.fonts{margin:0 0 1rem}`;
|
|
1354
|
+
/** The page, as one string */
|
|
1355
|
+
function kitPage(kit) {
|
|
1356
|
+
const { brand, company, terms, note } = kit;
|
|
1357
|
+
const description = company?.description ?? brand.description;
|
|
1358
|
+
const parts = [];
|
|
1359
|
+
if (company?.boilerplate) parts.push(section("About", paragraphs(company.boilerplate)));
|
|
1360
|
+
if (company?.facts) parts.push(section("Facts", dl(company.facts.map((fact) => ({
|
|
1361
|
+
label: fact.label,
|
|
1362
|
+
html: esc(fact.value)
|
|
1363
|
+
})))));
|
|
1364
|
+
if (company?.contact) {
|
|
1365
|
+
const rows = contactLines(company.contact).map(({ label, value }) => ({
|
|
1366
|
+
label,
|
|
1367
|
+
html: label === "Email" && isEmail(value) ? `<a href="mailto:${esc(value)}">${esc(value)}</a>` : label === "Web" ? link(value) : esc(value)
|
|
1368
|
+
}));
|
|
1369
|
+
parts.push(section("Contact", dl(rows)));
|
|
1370
|
+
}
|
|
1371
|
+
if (kit.logos.length > 0) {
|
|
1372
|
+
const groups = SURFACES.flatMap(([surface, title]) => {
|
|
1373
|
+
const items = kit.logos.filter((item) => item.surface === surface);
|
|
1374
|
+
return items.length > 0 ? [`<h3>${title}</h3><div class="logos">${items.map(logoBlock).join("")}</div>`] : [];
|
|
1375
|
+
});
|
|
1376
|
+
parts.push(section("Logos", groups.join("")));
|
|
1377
|
+
}
|
|
1378
|
+
if (kit.colors.length > 0) {
|
|
1379
|
+
const files = ["colors/colors.css", "colors/colors.json"].filter((file) => kit.paths.includes(file));
|
|
1380
|
+
parts.push(section("Colors", `<ul class="colors">${kit.colors.map(colorBlock).join("")}</ul>${files.length > 0 ? `<p>${files.map((file) => `<a href="${esc(file)}" download>${esc(file)}</a>`).join(" ")}</p>` : ""}`));
|
|
1381
|
+
}
|
|
1382
|
+
if (kit.fonts) {
|
|
1383
|
+
const body = kit.fonts.families.map((font) => {
|
|
1384
|
+
const rows = fontRows(font).map((row) => ({
|
|
1385
|
+
label: row.label,
|
|
1386
|
+
html: esc(row.block ? row.value.split("\n").map((line) => line.trim()).filter(Boolean).join("\n") : row.value)
|
|
1387
|
+
}));
|
|
1388
|
+
return `<div class="fonts"><h3>${esc(font.name)}</h3>${dl(rows)}</div>`;
|
|
1389
|
+
});
|
|
1390
|
+
const fallback = fallbackLine(kit.fonts);
|
|
1391
|
+
if (fallback) body.push(`<p>${esc(fallback)}</p>`);
|
|
1392
|
+
if (body.length > 0) parts.push(section("Fonts", body.join("")));
|
|
1393
|
+
}
|
|
1394
|
+
if (terms) parts.push(section("Terms of use", `<div class="terms">${terms.text ? paragraphs(terms.text) : ""}${terms.url ? `<p>Full terms: ${link(terms.url)}</p>` : ""}</div>`));
|
|
1395
|
+
if (note) parts.push(section("Note", `<p class="note">${esc(note)}</p>`));
|
|
1396
|
+
return `<!doctype html>
|
|
1397
|
+
<html lang="en">
|
|
1398
|
+
<head>
|
|
1399
|
+
<meta charset="utf-8">
|
|
1400
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1401
|
+
<title>${esc(brand.title)}: press kit</title>
|
|
1402
|
+
<style>
|
|
1403
|
+
${STYLE}
|
|
1404
|
+
</style>
|
|
1405
|
+
</head>
|
|
1406
|
+
<body>
|
|
1407
|
+
<main>
|
|
1408
|
+
<header><h1>${esc(brand.title)}</h1>${description ? `<p class="lead">${esc(description)}</p>` : ""}</header>
|
|
1409
|
+
${parts.join("\n")}
|
|
1410
|
+
</main>
|
|
1411
|
+
</body>
|
|
1412
|
+
</html>
|
|
1413
|
+
`;
|
|
1414
|
+
}
|
|
849
1415
|
var INSTALL_HINT = "install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program";
|
|
850
1416
|
/**
|
|
851
1417
|
* The browser: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. It never downloads one.
|
|
@@ -918,7 +1484,9 @@ function pickSwatches(colors) {
|
|
|
918
1484
|
more: colors.length - swatches.length
|
|
919
1485
|
};
|
|
920
1486
|
}
|
|
921
|
-
|
|
1487
|
+
/** The most of the terms' text the PDF holds: it is one page, and about.txt has the whole */
|
|
1488
|
+
var TERMS_PDF_CHARS = 300;
|
|
1489
|
+
function pageHtml({ brand, colors, logo, company, note, terms }) {
|
|
922
1490
|
const display = fontOf(brand.roles.fontDisplay);
|
|
923
1491
|
const body = fontOf(brand.roles.fontBody);
|
|
924
1492
|
const stack = (name, generic) => [name && quoted(name), generic].filter(Boolean).join(", ");
|
|
@@ -934,7 +1502,9 @@ function pageHtml({ brand, colors, logo, company, note }) {
|
|
|
934
1502
|
const about = [
|
|
935
1503
|
description ? `<p>${escape(description)}</p>` : "",
|
|
936
1504
|
company?.boilerplate ? `<p class="boiler">${escape(company.boilerplate)}</p>` : "",
|
|
937
|
-
company?.facts ? `<dl class="facts">${company.facts.map((fact) => `<dt>${escape(fact.label)}</dt><dd>${escape(fact.value)}</dd>`).join("")}</dl>` : ""
|
|
1505
|
+
company?.facts ? `<dl class="facts">${company.facts.map((fact) => `<dt>${escape(fact.label)}</dt><dd>${escape(fact.value)}</dd>`).join("")}</dl>` : "",
|
|
1506
|
+
company?.contact ? `<p class="contact">${contactLines(company.contact).map(({ label, value }) => `<span>${escape(label)}: ${escape(value)}</span>`).join("")}</p>` : "",
|
|
1507
|
+
terms ? termsBlock(terms) : ""
|
|
938
1508
|
].join("");
|
|
939
1509
|
return `<!doctype html><meta charset="utf-8"><title>${escape(brand.title)}</title>${sheets.join("")}<style>
|
|
940
1510
|
@page{size:${PAGE.width}px ${PAGE.height}px;margin:0}
|
|
@@ -951,9 +1521,15 @@ li b{font-weight:600}
|
|
|
951
1521
|
small{display:block;margin-top:12px;color:#666;font-size:13px}
|
|
952
1522
|
p+p{margin-top:12px}.boiler{font-size:14px}
|
|
953
1523
|
.facts{margin:16px 0 0;display:grid;grid-template-columns:max-content 1fr;gap:4px 16px;font-size:13px;line-height:1.4}.facts dt{color:#666}.facts dd{margin:0}
|
|
1524
|
+
.contact{margin:16px 0 0;display:flex;flex-wrap:wrap;gap:2px 16px;font-size:13px;line-height:1.4}.terms{margin:12px 0 0;font-size:12px;line-height:1.4;color:#444}.terms b{color:#161616}
|
|
954
1525
|
.note{margin-top:16px;padding:8px 12px;border-left:3px solid #999;background:#f4f4f2;font-size:13px}
|
|
955
1526
|
</style><body><section class="logo">${image}</section><main><div><h1>${escape(brand.title)}</h1>${about}</div><div><ul>${chips.join("")}</ul>${more > 0 ? `<small>${more} more in colors/colors.txt</small>` : ""}${note ? `<p class="note">${escape(note)}</p>` : ""}</div></main>`;
|
|
956
1527
|
}
|
|
1528
|
+
/** The terms as one short block: the start of the text and the address, with a pointer to about.txt when the text is cut */
|
|
1529
|
+
function termsBlock(terms) {
|
|
1530
|
+
const text = terms.text && terms.text.length > TERMS_PDF_CHARS ? `${terms.text.slice(0, TERMS_PDF_CHARS).replace(/\s+\S*$/, "")}... (all of it in about.txt)` : terms.text;
|
|
1531
|
+
return `<p class="terms"><b>Terms of use</b> ${text ? escape(text.replace(/\s+/g, " ")) : ""}${terms.url ? ` ${escape(terms.url)}` : ""}</p>`;
|
|
1532
|
+
}
|
|
957
1533
|
/** The page as a PDF, with the dates and the producer fixed so the same brand gives the same bytes */
|
|
958
1534
|
async function drawPdf(input, env) {
|
|
959
1535
|
const browser = await launchChrome(env, "draw the PDF with");
|
|
@@ -990,66 +1566,6 @@ function siteFile(siteDir, file) {
|
|
|
990
1566
|
const real = node_fs.default.realpathSync(full);
|
|
991
1567
|
return real.startsWith(root + node_path.default.sep) ? node_fs.default.readFileSync(real) : void 0;
|
|
992
1568
|
}
|
|
993
|
-
/**
|
|
994
|
-
* about.txt: the name, then the description to quote: the company's when the `company` option gives one, else the brand's. After it come the
|
|
995
|
-
* company's boilerplate, its facts as `Label: value` lines in the order given, and the note. Without any description it says so in one
|
|
996
|
-
* line, and a brand with no name has no file.
|
|
997
|
-
*/
|
|
998
|
-
function aboutText(brand, extras = {}) {
|
|
999
|
-
if (!brand.named) return { findings: [] };
|
|
1000
|
-
const { company, note } = extras;
|
|
1001
|
-
const description = company?.description ?? brand.description;
|
|
1002
|
-
const findings = [];
|
|
1003
|
-
const blocks = [brand.title, description ?? "No description is set in blazon.json."];
|
|
1004
|
-
if (!description) findings.push(finding("about-no-description", "warning", "brand.description", "the brand has no description, so about.txt says none is set"));
|
|
1005
|
-
if (company?.boilerplate) blocks.push(company.boilerplate);
|
|
1006
|
-
if (company?.facts) blocks.push(company.facts.map((fact) => `${fact.label}: ${fact.value}`).join("\n"));
|
|
1007
|
-
if (note) blocks.push(`Note: ${note}`);
|
|
1008
|
-
return {
|
|
1009
|
-
text: `${blocks.join("\n\n")}\n`,
|
|
1010
|
-
findings
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
/** What each part of the kit is for, in the order the README lists them; a part is listed when a file of the kit starts or ends as `match` says */
|
|
1014
|
-
var PARTS = [
|
|
1015
|
-
{
|
|
1016
|
-
match: (path) => path.startsWith("logos/"),
|
|
1017
|
-
says: "The logo files as they are. Use the ones in on-light-backgrounds/ on a light background and the ones in on-dark-backgrounds/ on a dark one. logos.txt says what the brand states about each."
|
|
1018
|
-
},
|
|
1019
|
-
{
|
|
1020
|
-
match: (path) => path.startsWith("colors/"),
|
|
1021
|
-
says: "The brand colors: colors.txt to read, colors.css for a web page, colors.json for a program."
|
|
1022
|
-
},
|
|
1023
|
-
{
|
|
1024
|
-
match: (path) => path === "fonts.txt",
|
|
1025
|
-
says: "The fonts the brand uses, where each comes from, and under what license, where the brand states one."
|
|
1026
|
-
},
|
|
1027
|
-
{
|
|
1028
|
-
match: (path) => path === "about.txt",
|
|
1029
|
-
says: "The brand name and a short description, to quote."
|
|
1030
|
-
},
|
|
1031
|
-
{
|
|
1032
|
-
match: (path) => path.endsWith(".pdf"),
|
|
1033
|
-
says: "One page with the name, the description, up to ten colors (whole color groups, in the order of the brand's groups, each labelled with its group and step) and a logo."
|
|
1034
|
-
}
|
|
1035
|
-
];
|
|
1036
|
-
/** README.txt: what is in the kit, in plain words. It names only the parts that are there, and holds no date. */
|
|
1037
|
-
function readmeText(title, paths, name, note) {
|
|
1038
|
-
const lines = [`${title}: press kit`, ""];
|
|
1039
|
-
if (note) lines.push(`Note: ${note}`, "");
|
|
1040
|
-
lines.push("What is in this folder", "");
|
|
1041
|
-
const listed = PARTS.flatMap(({ match, says }) => {
|
|
1042
|
-
const hit = paths.find(match);
|
|
1043
|
-
return hit ? [{
|
|
1044
|
-
shown: hit.startsWith("logos/") || hit.startsWith("colors/") ? `${hit.split("/")[0]}/` : hit,
|
|
1045
|
-
says
|
|
1046
|
-
}] : [];
|
|
1047
|
-
});
|
|
1048
|
-
const width = Math.max(16, ...listed.map(({ shown }) => shown.length + 2));
|
|
1049
|
-
for (const { shown, says } of listed) lines.push(` ${shown.padEnd(width)}${says}`);
|
|
1050
|
-
lines.push("", `${name}.zip holds the same files.`, "", "The logos are the brand's own files, not redrawn.");
|
|
1051
|
-
return `${lines.join("\n")}\n`;
|
|
1052
|
-
}
|
|
1053
1569
|
async function build(text) {
|
|
1054
1570
|
const job = jobFor(text);
|
|
1055
1571
|
const brand = readBrand(job.brand);
|
|
@@ -1079,6 +1595,7 @@ async function build(text) {
|
|
|
1079
1595
|
if (fonts.text) files.set("fonts.txt", fonts.text);
|
|
1080
1596
|
const about = aboutText(brand, {
|
|
1081
1597
|
company: options.company,
|
|
1598
|
+
terms: options.terms,
|
|
1082
1599
|
note: options.note
|
|
1083
1600
|
});
|
|
1084
1601
|
findings.push(...about.findings);
|
|
@@ -1095,7 +1612,8 @@ async function build(text) {
|
|
|
1095
1612
|
surface: shown.surface
|
|
1096
1613
|
},
|
|
1097
1614
|
company: options.company,
|
|
1098
|
-
note: options.note
|
|
1615
|
+
note: options.note,
|
|
1616
|
+
terms: options.terms
|
|
1099
1617
|
}, process.env);
|
|
1100
1618
|
files.set(`${options.name}.pdf`, pdf);
|
|
1101
1619
|
const fallen = pdfFallbacks(brand);
|
|
@@ -1105,18 +1623,20 @@ async function build(text) {
|
|
|
1105
1623
|
findings.push(finding("pdf-skipped", "warning", "options.pdf", `${options.name}.pdf is not in the kit: ${reason}`));
|
|
1106
1624
|
}
|
|
1107
1625
|
}
|
|
1108
|
-
files.set("
|
|
1626
|
+
files.set("index.html", kitPage({
|
|
1627
|
+
brand,
|
|
1628
|
+
company: options.company,
|
|
1629
|
+
terms: options.terms,
|
|
1630
|
+
note: options.note,
|
|
1631
|
+
logos: present,
|
|
1632
|
+
colors: colors.colors,
|
|
1633
|
+
fonts: fonts.model,
|
|
1634
|
+
paths: [...files.keys()]
|
|
1635
|
+
}));
|
|
1636
|
+
files.set("README.txt", readmeText(brand.title, [...files.keys()], options.name, options.note, options.terms !== void 0));
|
|
1109
1637
|
const entries = [...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
recursive: true,
|
|
1113
|
-
force: true
|
|
1114
|
-
});
|
|
1115
|
-
for (const [file, content] of entries) {
|
|
1116
|
-
node_fs.default.mkdirSync(node_path.default.dirname(node_path.default.join(folder, file)), { recursive: true });
|
|
1117
|
-
node_fs.default.writeFileSync(node_path.default.join(folder, file), content);
|
|
1118
|
-
}
|
|
1119
|
-
node_fs.default.writeFileSync(node_path.default.join(job.outDir, `${options.name}.zip`), zipOf(entries.map(([file, content]) => [`${options.name}/${file}`, content])));
|
|
1638
|
+
replaceFolder(node_path.default.join(job.outDir, options.name), entries);
|
|
1639
|
+
writeFolder(job.outDir, [[`${options.name}.zip`, zipOf(entries.map(([file, content]) => [`${options.name}/${file}`, content]))]]);
|
|
1120
1640
|
return { findings };
|
|
1121
1641
|
}
|
|
1122
1642
|
runPlugin(process.argv.slice(2), MANIFEST, build, "the press kit could not be written", NAME).then((code) => {
|