@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.
Files changed (76) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +15 -0
  3. package/README.md +567 -2
  4. package/dist/scripts/cover.d.ts +29 -0
  5. package/dist/scripts/cover.js +186 -0
  6. package/dist/src/fonts/embed.d.ts +7 -0
  7. package/dist/src/fonts/embed.js +221 -0
  8. package/dist/src/pieces/bank-objects.d.ts +12 -0
  9. package/dist/src/pieces/bank-objects.js +52 -0
  10. package/dist/src/pieces/brand-cast.d.ts +105 -0
  11. package/dist/src/pieces/brand-cast.js +221 -0
  12. package/dist/src/pieces/brand-notation-icons.d.ts +12 -0
  13. package/dist/src/pieces/brand-notation-icons.js +79 -0
  14. package/dist/src/pieces/category-icon.d.ts +12 -0
  15. package/dist/src/pieces/category-icon.js +55 -0
  16. package/dist/src/pieces/cover.d.ts +138 -0
  17. package/dist/src/pieces/cover.js +635 -0
  18. package/dist/src/pieces/diagram.d.ts +141 -0
  19. package/dist/src/pieces/diagram.js +201 -0
  20. package/dist/src/pieces/eip-icons.d.ts +12 -0
  21. package/dist/src/pieces/eip-icons.js +468 -0
  22. package/dist/src/pieces/emote.d.ts +13 -0
  23. package/dist/src/pieces/emote.js +88 -0
  24. package/dist/src/pieces/headline.d.ts +11 -0
  25. package/dist/src/pieces/headline.js +37 -0
  26. package/dist/src/pieces/index.d.ts +17 -0
  27. package/dist/src/pieces/index.js +20 -0
  28. package/dist/src/pieces/ink.d.ts +71 -0
  29. package/dist/src/pieces/ink.js +57 -0
  30. package/dist/src/pieces/keyboard.d.ts +9 -0
  31. package/dist/src/pieces/keyboard.js +33 -0
  32. package/dist/src/pieces/library.d.ts +320 -0
  33. package/dist/src/pieces/library.js +355 -0
  34. package/dist/src/pieces/link-icons.d.ts +23 -0
  35. package/dist/src/pieces/link-icons.js +101 -0
  36. package/dist/src/pieces/metro.d.ts +137 -0
  37. package/dist/src/pieces/metro.js +288 -0
  38. package/dist/src/pieces/node.d.ts +29 -0
  39. package/dist/src/pieces/node.js +56 -0
  40. package/dist/src/pieces/paper.d.ts +31 -0
  41. package/dist/src/pieces/paper.js +72 -0
  42. package/dist/src/pieces/params.d.ts +84 -0
  43. package/dist/src/pieces/params.js +158 -0
  44. package/dist/src/pieces/piece.d.ts +9 -0
  45. package/dist/src/pieces/piece.js +28 -0
  46. package/dist/src/pieces/pose.d.ts +16 -0
  47. package/dist/src/pieces/pose.js +30 -0
  48. package/dist/src/pieces/question-token.d.ts +9 -0
  49. package/dist/src/pieces/question-token.js +49 -0
  50. package/dist/src/pieces/react.d.ts +4 -0
  51. package/dist/src/pieces/react.js +13 -0
  52. package/dist/src/pieces/render.d.ts +2 -0
  53. package/dist/src/pieces/render.js +22 -0
  54. package/dist/src/pieces/skin.d.ts +22 -0
  55. package/dist/src/pieces/skin.js +13 -0
  56. package/dist/src/pieces/stamp.d.ts +11 -0
  57. package/dist/src/pieces/stamp.js +29 -0
  58. package/dist/src/pieces/supporting-cast.d.ts +35 -0
  59. package/dist/src/pieces/supporting-cast.js +168 -0
  60. package/dist/src/pieces/symbol.d.ts +13 -0
  61. package/dist/src/pieces/symbol.js +27 -0
  62. package/dist/src/pieces/ui-icons.d.ts +21 -0
  63. package/dist/src/pieces/ui-icons.js +35 -0
  64. package/dist/tokens/generated/tokens.d.ts +299 -0
  65. package/dist/tokens/generated/tokens.js +299 -0
  66. package/fonts/OFL.txt +97 -0
  67. package/fonts/SourceCodePro-Bold.ttf +0 -0
  68. package/fonts/SourceCodePro-Regular.ttf +0 -0
  69. package/fonts/SourceSans3-Black.ttf +0 -0
  70. package/fonts/SourceSans3-Bold.ttf +0 -0
  71. package/fonts/SourceSans3-Regular.ttf +0 -0
  72. package/fonts/SourceSerif4-Bold.ttf +0 -0
  73. package/package.json +88 -4
  74. package/tokens/generated/tokens.css +215 -0
  75. package/tokens/generated/tokens.json +298 -0
  76. package/tokens/generated/tokens.ts +302 -0
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ export declare const COVER_USAGE = "usage: npm run cover -- <spec.json> --out <file.svg> [--lang <code>]";
3
+ export type CoverIo = {
4
+ cwd: string;
5
+ log: (line: string) => void;
6
+ error: (line: string) => void;
7
+ };
8
+ /** The first invocation problem, in the order of the spec, or the two paths. */
9
+ export declare const parseCoverArgs: (args: string[], cwd: string) => {
10
+ ok: true;
11
+ spec: string;
12
+ out: string;
13
+ lang?: string;
14
+ } | {
15
+ ok: false;
16
+ problem: string;
17
+ };
18
+ /**
19
+ * Builds the cover text for a spec file's contents, its fonts embedded, or the
20
+ * problem lines. Rejects when embedding fails (a font file, or harfbuzzjs).
21
+ */
22
+ export declare const buildCover: (text: string, label: string, lang?: string) => Promise<{
23
+ ok: true;
24
+ svg: string;
25
+ } | {
26
+ ok: false;
27
+ lines: string[];
28
+ }>;
29
+ export declare const runCover: (args: string[], io: CoverIo) => Promise<number>;
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ // `npm run cover -- <spec.json> --out <file.svg> [--lang <code>]`, installed as the bin
3
+ // `signwright-cover` (spec cover-cli; design §6):
4
+ // builds one blog cover from a cover spec kept with its article in the vault.
5
+ //
6
+ // Why: covers were drawn by hand and drifted; a spec plus the shared pieces
7
+ // makes every cover reproducible, and only the pieces live in this public
8
+ // repository.
9
+ //
10
+ // Every written image embeds, as subsets, the Source faces its text uses
11
+ // (`embedFonts`, ADR 0008), so a reader sees Source inside an `<img>`.
12
+ //
13
+ // What can go wrong: a bad invocation reports its first problem with the
14
+ // usage; an invalid spec reports every problem by JSON path; a font file that
15
+ // cannot be read or a WebAssembly subsetter that does not load prints the
16
+ // error's one line (naming the file or harfbuzzjs). In each case the command
17
+ // exits 1 and writes nothing. An existing output file is replaced.
18
+ import { closeSync, existsSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
19
+ import { randomUUID } from "node:crypto";
20
+ import { dirname, resolve } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ import { embedFonts } from "../src/fonts/embed.js";
23
+ import { coverTree, LANGUAGE, validateCoverSpec } from "../src/pieces/cover.js";
24
+ import { toSvg } from "../src/pieces/render.js";
25
+ export const COVER_USAGE = "usage: npm run cover -- <spec.json> --out <file.svg> [--lang <code>]";
26
+ /** The first invocation problem, in the order of the spec, or the two paths. */
27
+ export const parseCoverArgs = (args, cwd) => {
28
+ const specs = [];
29
+ const outs = [];
30
+ const langs = [];
31
+ let unknown;
32
+ let outWithoutValue = false;
33
+ let langWithoutValue = false;
34
+ for (let i = 0; i < args.length; i++) {
35
+ const arg = args[i];
36
+ if (arg === "--out" || arg === "--lang") {
37
+ const value = args[i + 1];
38
+ if (value === undefined || value.startsWith("--")) {
39
+ if (arg === "--out")
40
+ outWithoutValue = true;
41
+ else
42
+ langWithoutValue = true;
43
+ }
44
+ else {
45
+ (arg === "--out" ? outs : langs).push(value);
46
+ i++;
47
+ }
48
+ }
49
+ else if (arg.startsWith("-"))
50
+ unknown ??= arg;
51
+ else
52
+ specs.push(arg);
53
+ }
54
+ if (unknown !== undefined)
55
+ return { ok: false, problem: `unknown option ${unknown}` };
56
+ if (outWithoutValue)
57
+ return { ok: false, problem: "--out needs a value: <file.svg>" };
58
+ if (outs.length === 0)
59
+ return { ok: false, problem: "--out <file.svg> is required" };
60
+ if (outs.length > 1)
61
+ return { ok: false, problem: "--out given more than once" };
62
+ const out = outs[0];
63
+ if (!out.endsWith(".svg"))
64
+ return { ok: false, problem: `the output must be an .svg file, found ${out}` };
65
+ const folder = dirname(resolve(cwd, out));
66
+ if (!existsSync(folder) || !statSync(folder).isDirectory())
67
+ return { ok: false, problem: `the output folder does not exist: ${dirname(out)}` };
68
+ const target = resolve(cwd, out);
69
+ if (existsSync(target) && statSync(target).isDirectory())
70
+ return { ok: false, problem: `the output is a folder: ${out}` };
71
+ if (langWithoutValue)
72
+ return { ok: false, problem: "--lang needs a value: <code>" };
73
+ if (langs.length > 1)
74
+ return { ok: false, problem: "--lang given more than once" };
75
+ if (langs.length === 1 && !LANGUAGE.test(langs[0]))
76
+ return { ok: false, problem: `--lang expects a language code such as pt or en, found ${langs[0]}` };
77
+ if (specs.length === 0)
78
+ return { ok: false, problem: "missing the cover spec: <spec.json>" };
79
+ if (specs.length > 1)
80
+ return { ok: false, problem: `one cover spec at a time, found ${specs.length}` };
81
+ return { ok: true, spec: specs[0], out, ...(langs.length === 1 ? { lang: langs[0] } : {}) };
82
+ };
83
+ /** Parses the spec text; a syntax error names the line and column. */
84
+ const parseJson = (text, label) => {
85
+ try {
86
+ return { value: JSON.parse(text) };
87
+ }
88
+ catch (error) {
89
+ const message = error instanceof Error ? error.message : String(error);
90
+ const lineColumn = /line (\d+) column (\d+)/.exec(message);
91
+ const position = /position (\d+)/.exec(message);
92
+ let where = "";
93
+ if (lineColumn)
94
+ where = ` at line ${lineColumn[1]}, column ${lineColumn[2]}`;
95
+ else if (position) {
96
+ const before = text.slice(0, Number(position[1])).split("\n");
97
+ where = ` at line ${before.length}, column ${before[before.length - 1].length + 1}`;
98
+ }
99
+ return { problem: `${label}: invalid JSON${where} (${message})` };
100
+ }
101
+ };
102
+ /**
103
+ * Builds the cover text for a spec file's contents, its fonts embedded, or the
104
+ * problem lines. Rejects when embedding fails (a font file, or harfbuzzjs).
105
+ */
106
+ export const buildCover = async (text, label, lang) => {
107
+ const parsed = parseJson(text, label);
108
+ if ("problem" in parsed)
109
+ return { ok: false, lines: [parsed.problem] };
110
+ const problems = validateCoverSpec(parsed.value, { lang });
111
+ if (problems.length > 0)
112
+ return { ok: false, lines: problems.map((p) => `${p.path}: ${p.message}`) };
113
+ return { ok: true, svg: `${toSvg(await embedFonts(coverTree(parsed.value, { lang })))}\n` };
114
+ };
115
+ export const runCover = async (args, io) => {
116
+ const invocation = parseCoverArgs(args, io.cwd);
117
+ if (!invocation.ok) {
118
+ io.error(invocation.problem);
119
+ io.error(COVER_USAGE);
120
+ return 1;
121
+ }
122
+ const specPath = resolve(io.cwd, invocation.spec);
123
+ let text;
124
+ try {
125
+ text = readFileSync(specPath, "utf8");
126
+ }
127
+ catch (error) {
128
+ io.error(`cannot read ${invocation.spec}: ${error instanceof Error ? error.message : String(error)}`);
129
+ io.error(COVER_USAGE);
130
+ return 1;
131
+ }
132
+ let result;
133
+ try {
134
+ result = await buildCover(text, invocation.spec, invocation.lang);
135
+ }
136
+ catch (error) {
137
+ // The embedding failed: no image ships without its faces.
138
+ io.error(error instanceof Error ? error.message : String(error));
139
+ return 1;
140
+ }
141
+ if (!result.ok) {
142
+ for (const line of result.lines)
143
+ io.error(line);
144
+ io.error(`cover: ${result.lines.length} problem(s) in ${invocation.spec}; no file written`);
145
+ return 1;
146
+ }
147
+ // Write beside the target and rename, so a failed write never leaves half a cover.
148
+ const target = resolve(io.cwd, invocation.out);
149
+ // Unpredictable name, created exclusively ("wx"): never follows or reuses an existing path.
150
+ const temporary = `${target}.${randomUUID()}.tmp`;
151
+ let created = false;
152
+ try {
153
+ const fd = openSync(temporary, "wx");
154
+ created = true; // ours from here on: remove it on any later failure
155
+ try {
156
+ // writeFileSync on a descriptor loops until every byte is written (writeSync may write fewer).
157
+ writeFileSync(fd, result.svg);
158
+ }
159
+ finally {
160
+ closeSync(fd);
161
+ }
162
+ renameSync(temporary, target);
163
+ }
164
+ catch (error) {
165
+ if (created)
166
+ rmSync(temporary, { force: true });
167
+ io.error(`cannot write ${invocation.out}: ${error instanceof Error ? error.message : String(error)}`);
168
+ return 1;
169
+ }
170
+ io.log(`wrote ${invocation.out}`);
171
+ return 0;
172
+ };
173
+ // Real paths on both sides: an installed bin is a symlink in node_modules/.bin.
174
+ const isMain = (() => {
175
+ if (process.argv[1] === undefined)
176
+ return false;
177
+ try {
178
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1]);
179
+ }
180
+ catch {
181
+ return false;
182
+ }
183
+ })();
184
+ if (isMain) {
185
+ process.exitCode = await runCover(process.argv.slice(2), { cwd: process.env.INIT_CWD ?? process.cwd(), log: console.log, error: console.error });
186
+ }
@@ -0,0 +1,7 @@
1
+ import type { SvgNode } from "../pieces/node.ts";
2
+ /**
3
+ * The tree with the Source faces its drawn text uses embedded as subsets, in
4
+ * one `style` right after the root's `desc` (or as its first child). A tree
5
+ * with no face to embed resolves to the input; the input is never modified.
6
+ */
7
+ export declare const embedFonts: (tree: SvgNode) => Promise<SvgNode>;
@@ -0,0 +1,221 @@
1
+ // Source faces embedded in an SVG tree (spec illustration-pieces, "Fonts
2
+ // embedded in an SVG tree"; design.md Decision 1, ADR 0008), exported from the
3
+ // subpath `@brunosouzas/signwright/fonts`.
4
+ //
5
+ // Why: the site shows covers and diagrams through `<img>`, which never loads a
6
+ // page's web fonts, and Source is not installed on most readers' machines. So
7
+ // every written image carries, as a TrueType subset in a `<style>`, only the
8
+ // characters it draws in each Source face; the reader sees Source, at 2-10 KB
9
+ // gzip per image.
10
+ //
11
+ // How: `await embedFonts(tree)` returns a new tree with one `style` after the
12
+ // root's `desc` (or first), one `@font-face` per face its drawn text uses. The
13
+ // cover command and `npm run pieces:sheet` call it before writing.
14
+ //
15
+ // What can go wrong: an unreadable font file or a WebAssembly module that does
16
+ // not load rejects with an Error naming the file or `harfbuzzjs`; a failed load
17
+ // is not cached, so the next call retries. A character no shipped face has is
18
+ // left out of the subset (the browser takes it from the next family of the
19
+ // stack). This module reads files, so it lives outside src/pieces/, whose
20
+ // modules stay pure (the root entry must import in a browser bundle).
21
+ import { existsSync, readFileSync } from "node:fs";
22
+ import { readFile } from "node:fs/promises";
23
+ import { createRequire } from "node:module";
24
+ import { dirname, join } from "node:path";
25
+ import { fileURLToPath } from "node:url";
26
+ const PACKAGE_NAME = "@brunosouzas/signwright";
27
+ const FACES = [
28
+ { family: "Source Code Pro", weight: 400, upTo: 549, range: "100 549", file: "SourceCodePro-Regular.ttf" },
29
+ { family: "Source Code Pro", weight: 700, upTo: Infinity, range: "550 900", file: "SourceCodePro-Bold.ttf" },
30
+ { family: "Source Sans 3", weight: 400, upTo: 549, range: "100 549", file: "SourceSans3-Regular.ttf" },
31
+ { family: "Source Sans 3", weight: 700, upTo: 799, range: "550 799", file: "SourceSans3-Bold.ttf" },
32
+ { family: "Source Sans 3", weight: 900, upTo: Infinity, range: "800 900", file: "SourceSans3-Black.ttf" },
33
+ // One serif face, the bold the `headline` piece draws (change headline-piece): every weight takes it.
34
+ { family: "Source Serif 4", weight: 700, upTo: Infinity, range: "100 900", file: "SourceSerif4-Bold.ttf" },
35
+ ];
36
+ // FACES is already in the order of the rules: family name by code point, then weight.
37
+ /** Subtrees whose strings are never drawn. */
38
+ const NOT_DRAWN = new Set(["title", "desc", "style"]);
39
+ /** First family of a `font-family` list, trimmed and unquoted. */
40
+ const firstFamily = (value) => value.split(",")[0].trim().replace(/^(["'])(.*)\1$/, "$2");
41
+ /** CSS weight of a `font-weight` value: keywords other than `bold`, and anything non-numeric, are 400. */
42
+ const weightOf = (value) => {
43
+ if (typeof value === "number")
44
+ return value;
45
+ if (value === undefined)
46
+ return 400;
47
+ const trimmed = value.trim();
48
+ if (trimmed === "bold")
49
+ return 700;
50
+ return /^\d+(\.\d+)?$/.test(trimmed) ? Number(trimmed) : 400;
51
+ };
52
+ /** The shipped face a text is drawn in, or undefined (another family, or none). Italic and oblique take the upright face. */
53
+ const faceOf = (inherited) => {
54
+ if (inherited.family === undefined)
55
+ return undefined;
56
+ const family = firstFamily(inherited.family);
57
+ const weight = weightOf(inherited.weight);
58
+ const ofFamily = FACES.filter((face) => face.family === family);
59
+ // Snapped to the first face whose declared range reaches the weight (549.5
60
+ // goes to 700 and 799.5 to 900, as in the browser); above 900, the heaviest.
61
+ return ofFamily.find((face) => weight <= face.upTo);
62
+ };
63
+ /** Drawn characters per face: the strings of text and tspan nodes, outside title, desc and style. */
64
+ const drawnText = (node, inherited, out) => {
65
+ if (NOT_DRAWN.has(node.tag))
66
+ return;
67
+ const own = {
68
+ family: node.attrs["font-family"] === undefined ? inherited.family : String(node.attrs["font-family"]),
69
+ weight: node.attrs["font-weight"] ?? inherited.weight,
70
+ };
71
+ const isText = node.tag === "text" || node.tag === "tspan";
72
+ for (const child of node.children) {
73
+ if (typeof child !== "string")
74
+ drawnText(child, own, out);
75
+ else if (isText) {
76
+ const face = faceOf(own);
77
+ if (face === undefined)
78
+ continue;
79
+ const characters = out.get(face) ?? new Set();
80
+ for (const character of child)
81
+ characters.add(character);
82
+ out.set(face, characters);
83
+ }
84
+ }
85
+ };
86
+ // ---------- loading (lazy, once per process, failures not cached) ----------
87
+ let fontsFolder;
88
+ /** `fonts/` of this package: the nearest package.json above this module named PACKAGE_NAME (works from src/ and dist/). */
89
+ const fontsDir = () => {
90
+ if (fontsFolder !== undefined)
91
+ return fontsFolder;
92
+ const start = dirname(fileURLToPath(import.meta.url));
93
+ for (let dir = start;; dir = dirname(dir)) {
94
+ const manifest = join(dir, "package.json");
95
+ if (existsSync(manifest) && JSON.parse(readFileSync(manifest, "utf8")).name === PACKAGE_NAME) {
96
+ fontsFolder = join(dir, "fonts");
97
+ return fontsFolder;
98
+ }
99
+ if (dirname(dir) === dir)
100
+ throw new Error(`cannot find the fonts/ folder of ${PACKAGE_NAME} above ${start}`);
101
+ }
102
+ };
103
+ const message = (error) => (error instanceof Error ? error.message : String(error));
104
+ const fontFiles = new Map();
105
+ const fontFile = (file) => {
106
+ const path = join(fontsDir(), file);
107
+ let loading = fontFiles.get(path);
108
+ if (loading === undefined) {
109
+ loading = readFile(path).then((bytes) => new Uint8Array(bytes), (error) => {
110
+ fontFiles.delete(path); // not cached: the next call reads it again
111
+ throw new Error(`cannot read the font file ${path}: ${message(error)}`);
112
+ });
113
+ fontFiles.set(path, loading);
114
+ }
115
+ return loading;
116
+ };
117
+ let harfBuzz;
118
+ const subsetter = () => {
119
+ if (harfBuzz !== undefined)
120
+ return harfBuzz;
121
+ const loading = (async () => {
122
+ try {
123
+ const wasm = createRequire(import.meta.url).resolve("harfbuzzjs/dist/harfbuzz-subset.wasm");
124
+ const { instance } = await WebAssembly.instantiate(await readFile(wasm));
125
+ const hb = instance.exports;
126
+ hb._initialize();
127
+ return hb;
128
+ }
129
+ catch (error) {
130
+ throw new Error(`harfbuzzjs: cannot load the WebAssembly subsetter: ${message(error)}`);
131
+ }
132
+ })();
133
+ // Cached only once assigned, and cleared on rejection, so a failure thrown
134
+ // before the first await (the module cannot be resolved) is not cached either.
135
+ harfBuzz = loading;
136
+ loading.catch(() => {
137
+ if (harfBuzz === loading)
138
+ harfBuzz = undefined; // not cached: the next call loads it again
139
+ });
140
+ return loading;
141
+ };
142
+ // ---------- subsetting ----------
143
+ // The mode of the spike that proved the routine (card 300): HarfBuzz may use the copy in place; it is freed after.
144
+ const HB_MEMORY_MODE_WRITABLE = 2;
145
+ const HB_SUBSET_SETS_UNICODE = 1;
146
+ const HB_SUBSET_SETS_LAYOUT_FEATURE_TAG = 6;
147
+ const HB_SUBSET_FLAGS_NO_HINTING = 0x1;
148
+ // Kerning and the ligatures the text may use; every other layout feature is dropped.
149
+ const LAYOUT_FEATURES = ["kern", "liga", "calt"];
150
+ const tag = (name) => [...name].reduce((value, character) => ((value << 8) | character.charCodeAt(0)) >>> 0, 0);
151
+ /** A TrueType subset of `font` holding the glyphs of `characters` (deterministic: same input, same bytes). */
152
+ const subset = (hb, font, characters, file) => {
153
+ const input = hb.hb_subset_input_create_or_fail();
154
+ if (input === 0)
155
+ throw new Error(`harfbuzzjs: cannot create a subset input for ${file}`);
156
+ const data = hb.malloc(font.byteLength);
157
+ new Uint8Array(hb.memory.buffer).set(font, data);
158
+ const blob = hb.hb_blob_create(data, font.byteLength, HB_MEMORY_MODE_WRITABLE, 0, 0);
159
+ const face = hb.hb_face_create(blob, 0);
160
+ hb.hb_blob_destroy(blob);
161
+ try {
162
+ const unicodes = hb.hb_subset_input_set(input, HB_SUBSET_SETS_UNICODE);
163
+ for (const character of characters)
164
+ hb.hb_set_add(unicodes, character.codePointAt(0));
165
+ const features = hb.hb_subset_input_set(input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
166
+ hb.hb_set_clear(features);
167
+ for (const feature of LAYOUT_FEATURES)
168
+ hb.hb_set_add(features, tag(feature));
169
+ hb.hb_subset_input_set_flags(input, hb.hb_subset_input_get_flags(input) | HB_SUBSET_FLAGS_NO_HINTING);
170
+ const result = hb.hb_subset_or_fail(face, input);
171
+ if (result === 0)
172
+ throw new Error(`harfbuzzjs: subsetting ${file} failed`);
173
+ const out = hb.hb_face_reference_blob(result);
174
+ const offset = hb.hb_blob_get_data(out, 0);
175
+ const bytes = new Uint8Array(hb.memory.buffer).slice(offset, offset + hb.hb_blob_get_length(out));
176
+ hb.hb_blob_destroy(out);
177
+ hb.hb_face_destroy(result);
178
+ return bytes;
179
+ }
180
+ finally {
181
+ hb.hb_subset_input_destroy(input);
182
+ hb.hb_face_destroy(face);
183
+ hb.free(data);
184
+ }
185
+ };
186
+ /** Glyph count of a TrueType font (its `maxp` table); a subset with only `.notdef` draws none of its characters. */
187
+ const glyphCount = (font) => {
188
+ const view = new DataView(font.buffer, font.byteOffset, font.byteLength);
189
+ const tables = view.getUint16(4);
190
+ for (let i = 0; i < tables; i++) {
191
+ const record = 12 + i * 16;
192
+ if (view.getUint32(record) === tag("maxp"))
193
+ return view.getUint16(view.getUint32(record + 8) + 4);
194
+ }
195
+ return 0;
196
+ };
197
+ const fontFace = (face, font) => `@font-face{font-family:'${face.family}';font-weight:${face.range};font-style:normal;src:url(data:font/ttf;base64,${Buffer.from(font).toString("base64")}) format('truetype')}`;
198
+ /**
199
+ * The tree with the Source faces its drawn text uses embedded as subsets, in
200
+ * one `style` right after the root's `desc` (or as its first child). A tree
201
+ * with no face to embed resolves to the input; the input is never modified.
202
+ */
203
+ export const embedFonts = async (tree) => {
204
+ const used = new Map();
205
+ drawnText(tree, {}, used);
206
+ const faces = FACES.filter((face) => used.has(face));
207
+ if (faces.length === 0)
208
+ return tree;
209
+ const hb = await subsetter();
210
+ const rules = [];
211
+ for (const face of faces) {
212
+ const font = subset(hb, await fontFile(face.file), used.get(face), face.file);
213
+ if (glyphCount(font) > 1)
214
+ rules.push(fontFace(face, font));
215
+ }
216
+ if (rules.length === 0)
217
+ return tree;
218
+ const style = { tag: "style", attrs: {}, children: [rules.join("\n")] };
219
+ const at = tree.children.findIndex((child) => typeof child !== "string" && child.tag === "desc") + 1;
220
+ return { ...tree, children: [...tree.children.slice(0, at), style, ...tree.children.slice(at)] };
221
+ };
@@ -0,0 +1,12 @@
1
+ import { type SurfaceName } from "./ink.ts";
2
+ export declare const BANK_OBJECT_NAMES: readonly ["courier", "lume", "carga", "anel", "modulo", "hub"];
3
+ export type BankObjectName = (typeof BANK_OBJECT_NAMES)[number];
4
+ export type BankObjectParams = {
5
+ name: BankObjectName;
6
+ x: number;
7
+ y: number;
8
+ surface?: SurfaceName;
9
+ scale?: number;
10
+ };
11
+ /** One of the six prop-bank objects for covers (I10): Correio, Lume, Carga, Anel, Módulo, Hub, with idle eyes on the screen. */
12
+ export declare const bankObject: import("./piece.ts").Piece<BankObjectParams>;
@@ -0,0 +1,52 @@
1
+ // The bank of objects for covers (identity studio I10, amended in 0.7.0): six
2
+ // objects that appear on track covers instead of a cast character with a role.
3
+ // Geometry ported from the approved phase-3 source
4
+ // (`~/.hermes/cache/scratch/ab267/casting3.py`: `courier`/`lume`/`carga`/`anel`/`modulo`/`hub`);
5
+ // in 0.7.0 every screen shows the cast's idle eyes and `modulo` loses the two
6
+ // inner strokes between its legs (the card 301 preview the owner approved).
7
+ //
8
+ // Why idle eyes and nothing more: an object with a face-like screen and no eyes
9
+ // reads as dead, so the screen is on; but a bank object is scenery, not a
10
+ // character with a story role (Mira, Visor, Drone, Kiu, Sinal), so it takes no
11
+ // expression. If a future piece needs the same object with expressions or a
12
+ // role in two or more places, it becomes a character with its own sheet (E8),
13
+ // not a change to this file.
14
+ import { drawn, el, g, r2 } from "./node.js";
15
+ import { surfaceParam } from "./ink.js";
16
+ import { pos, num } from "./params.js";
17
+ import { definePiece } from "./piece.js";
18
+ import { outlined, skin } from "./skin.js";
19
+ export const BANK_OBJECT_NAMES = ["courier", "lume", "carga", "anel", "modulo", "hub"];
20
+ /** The screen: the visor-coloured panel with the cast's idle eyes centred on it, and no other expression. */
21
+ const screen = (x, y, w, h, s, rx) => {
22
+ // Two upright pills a fifth of the screen's width either side of its centre, 0.42 of its height.
23
+ const cx = x + w / 2, cy = y + h / 2, dx = w * 0.2, ew = Math.max(5, w * 0.11), eh = h * 0.42;
24
+ return g({}, el("rect", { x, y, width: w, height: h, rx: rx ?? h / 2.4, fill: s.visor }), ...[-dx, dx].map((sx) => el("rect", { x: r2(cx + sx - ew / 2), y: r2(cy - eh / 2), width: r2(ew), height: r2(eh), rx: r2(ew / 2), fill: s.eye, stroke: "none" })));
25
+ };
26
+ const courier = (s) => g({}, el("path", { d: "M-42 -100 L-60 -126 H-34 L-18 -100 Z", fill: s.outline }), el("path", { d: "M-42 -40 L-60 -14 H-34 L-18 -40 Z", fill: s.outline }), el("rect", { x: -72, y: -84, width: 14, height: 28, rx: 4, fill: s.outline }), el("path", { d: "M-50 -102 H18 C58 -102 80 -84 80 -70 C80 -56 58 -38 18 -38 H-50 A32 32 0 0 1 -50 -102 Z", ...outlined(s) }), el("rect", { x: -40, y: -82, width: 24, height: 24, rx: 5, fill: s.accent }), screen(-2, -90, 56, 38, s));
27
+ const lume = (s) => {
28
+ const rays = [0, 1, 2].map((i) => el("path", { d: `M${50 + i * 4} ${-104 + i * 22} L${78 + i * 8} ${-112 + i * 26}`, stroke: s.accent, "stroke-width": 7, "stroke-linecap": "round" }));
29
+ return g({}, el("path", { d: "M-20 -138 A20 20 0 0 1 20 -138", stroke: s.outline, "stroke-width": 6, fill: "none" }), el("path", { d: "M-30 -138 H30 L38 -124 H-38 Z", fill: s.outline }), el("rect", { x: -36, y: -126, width: 72, height: 80, rx: 14, ...outlined(s) }), screen(-25, -114, 50, 44, s), el("path", { d: "M-38 -46 H38 L30 -34 H-30 Z", fill: s.outline }), el("path", { d: "M-10 -34 H10 L0 -20 Z", fill: s.outline }), ...rays);
30
+ };
31
+ const carga = (s) => g({}, el("rect", { x: -44, y: -152, width: 60, height: 28, rx: 4, fill: s.accent }), el("path", { d: "M-30 -152 V-124 M-14 -152 V-124 M2 -152 V-124", stroke: s.body, "stroke-width": 3 }), el("path", { d: "M-24 -60 L-38 -32 L-24 -6 M24 -60 L12 -32 L26 -6", stroke: s.outline, "stroke-width": 10, "stroke-linecap": "round", "stroke-linejoin": "round", fill: "none" }), el("rect", { x: -40, y: -8, width: 30, height: 9, rx: 4.5, fill: s.outline }), el("rect", { x: 12, y: -8, width: 30, height: 9, rx: 4.5, fill: s.outline }), el("rect", { x: -50, y: -126, width: 100, height: 70, rx: 16, ...outlined(s) }), screen(-30, -114, 62, 36, s), el("path", { d: "M50 -96 H66 V-74", stroke: s.outline, "stroke-width": 7, "stroke-linecap": "round", fill: "none" }), el("path", { d: "M58 -74 H74", stroke: s.outline, "stroke-width": 7, "stroke-linecap": "round" }));
32
+ const anel = (s) => g({}, el("path", { d: "M-82 -78 A84 20 -12 0 1 82 -98", stroke: s.accent, "stroke-width": 9, fill: "none", "stroke-linecap": "round" }), el("circle", { cx: 0, cy: -88, r: 46, ...outlined(s) }), screen(-31, -112, 62, 32, s), el("path", { d: "M82 -98 A84 20 -12 0 1 -82 -78", stroke: s.accent, "stroke-width": 9, fill: "none", "stroke-linecap": "round" }), el("rect", { x: -66, y: -74, width: 14, height: 14, rx: 3, fill: s.outline }), el("rect", { x: 58, y: -92, width: 14, height: 14, rx: 3, fill: s.outline }));
33
+ const modulo = (s) => g({}, el("path", { d: "M-44 -50 L-74 -2 M44 -50 L74 -2", stroke: s.outline, "stroke-width": 7, "stroke-linecap": "round" }), el("rect", { x: -88, y: -6, width: 28, height: 7, rx: 3.5, fill: s.outline }), el("rect", { x: 60, y: -6, width: 28, height: 7, rx: 3.5, fill: s.outline }), el("rect", { x: -46, y: -62, width: 92, height: 24, rx: 5, fill: s.accent }), el("path", { d: "M22 -134 L34 -154", stroke: s.outline, "stroke-width": 5, "stroke-linecap": "round" }), el("path", { d: "M26 -160 A10 10 0 0 0 44 -150 Z", fill: s.outline }), el("path", { d: "M-36 -136 H36 L52 -114 V-80 L36 -62 H-36 L-52 -80 V-114 Z", ...outlined(s) }), screen(-34, -122, 68, 42, s));
34
+ const hub = (s) => {
35
+ const arms = [];
36
+ const spokes = [
37
+ [-30, -70, -70, -60, -84, -14], [-14, -64, -30, -30, -40, 0], [14, -64, 30, -30, 40, 0], [30, -70, 70, -60, 84, -14],
38
+ ];
39
+ for (const [x1, y1, cx, cy, x2, y2] of spokes) {
40
+ arms.push(el("path", { d: `M${x1} ${y1} Q${cx} ${cy} ${x2} ${y2}`, stroke: s.outline, "stroke-width": 7, fill: "none", "stroke-linecap": "round" }));
41
+ arms.push(el("rect", { x: x2 - 8, y: y2 - 4, width: 16, height: 12, rx: 3, fill: s.accent }));
42
+ }
43
+ return g({}, ...arms, el("path", { d: "M-50 -76 V-104 A50 50 0 0 1 50 -104 V-76 Q0 -60 -50 -76 Z", ...outlined(s) }), screen(-36, -130, 72, 40, s));
44
+ };
45
+ const DRAW = { courier, lume, carga, anel, modulo, hub };
46
+ const drawBankObject = (p) => {
47
+ const s = skin(p.surface ?? "light");
48
+ const body = DRAW[p.name](s);
49
+ return drawn([g({ "data-piece": `bank-${p.name}`, transform: `translate(${p.x} ${p.y}) scale(${p.scale ?? 1})`, stroke: "none" }, body)]);
50
+ };
51
+ /** One of the six prop-bank objects for covers (I10): Correio, Lume, Carga, Anel, Módulo, Hub, with idle eyes on the screen. */
52
+ export const bankObject = definePiece("bankObject", { name: { kind: "enum", required: true, values: BANK_OBJECT_NAMES }, x: pos(), y: pos(), surface: surfaceParam, scale: num({ min: 0.25, max: 4 }) }, drawBankObject);
@@ -0,0 +1,105 @@
1
+ import { type Drawn, type SvgNode } from "./node.ts";
2
+ import { type SurfaceName } from "./ink.ts";
3
+ import { type SheetRow } from "./paper.ts";
4
+ import { type Schema } from "./params.ts";
5
+ import { type Skin } from "./skin.ts";
6
+ export declare const CAST_EXPRESSIONS: readonly ["idle", "done", "waiting", "failed"];
7
+ export type CastExpression = (typeof CAST_EXPRESSIONS)[number];
8
+ export declare const CAST_VIEWS: readonly ["front", "back"];
9
+ export type CastView = (typeof CAST_VIEWS)[number];
10
+ /**
11
+ * The screen face, the message state (identity studio I2: 4 expressions = parked, done, waiting, failed).
12
+ * Ported from `casting3.py`'s `face(x, y, w, h, S, mode)`.
13
+ */
14
+ export declare const faceAt: (x: number, y: number, w: number, h: number, s: Skin, expression: CastExpression) => SvgNode;
15
+ /** The hood tip, dipping over the forehead: the parent-brand family device (ADR 0007, I4). Absent on Sinal. */
16
+ export declare const peak: (s: Skin, cx: number, top: number, w?: number, dip?: number) => SvgNode;
17
+ /** The hood tip drawn as a cap sitting astride a circle's rim (Visor, Drone, Kiu use this form; `final.py`'s `tipcap`). */
18
+ export declare const tipCap: (s: Skin, cx: number, cy: number, r: number, depth: number) => SvgNode;
19
+ export type MiraParams = {
20
+ x: number;
21
+ y: number;
22
+ surface?: SurfaceName;
23
+ scale?: number;
24
+ expression?: CastExpression;
25
+ view?: CastView;
26
+ /** The needle's angle in degrees (the sheets' `a`); the needle acts first (motion principle, identity sheet). */
27
+ needleAngle?: number;
28
+ /** A message riding the needle's tip. */
29
+ carries?: boolean;
30
+ /** A walking stride offset on the legs. */
31
+ stride?: number;
32
+ };
33
+ /** Mira, the protagonist: an astrolabe whose needle points the route each message takes. */
34
+ export declare const mira: import("./piece.ts").Piece<MiraParams>;
35
+ export declare const VISOR_FACINGS: readonly ["right", "left"];
36
+ export type VisorFacing = (typeof VISOR_FACINGS)[number];
37
+ /** A held sheet (Visor's, and Chaves's since change supporting-characters): the `sheet` piece's page parameters, plus the file name pill. */
38
+ export type HeldSheet = {
39
+ width: number;
40
+ height: number;
41
+ rows: SheetRow[];
42
+ top?: number;
43
+ step?: number;
44
+ label?: string;
45
+ };
46
+ /** The name of 0.12.0, kept as an alias of `HeldSheet`. */
47
+ export type VisorHeldSheet = HeldSheet;
48
+ export type VisorParams = {
49
+ x: number;
50
+ y: number;
51
+ surface?: SurfaceName;
52
+ scale?: number;
53
+ expression?: CastExpression;
54
+ view?: CastView;
55
+ /** The small accent card in the left hand. */
56
+ holds?: boolean;
57
+ /** A sheet in the left hand instead of the card; refused with `holds: true` or `view: "back"`. */
58
+ holdsSheet?: HeldSheet;
59
+ points?: boolean;
60
+ /** `right` (the default, the drawing of 0.11.0) or `left`, the mirror image; the held sheet and words stay unmirrored. */
61
+ facing?: VisorFacing;
62
+ };
63
+ /**
64
+ * A held sheet with its page's top-left corner at (x, y), in the holder's
65
+ * units: the `sheet` and `pill` pieces' own drawings in one group that gives
66
+ * them the cast's outline (cast pieces set `stroke: none` on their root), so
67
+ * it draws the same in a cover and in a scene. The marks sit on the white page,
68
+ * so they stay ink on the dark surface too (ADR 0009). Its words go to the
69
+ * holder's text. Shared by Visor and Chaves (change supporting-characters, design §1).
70
+ */
71
+ export declare const holdSheet: (held: HeldSheet, s: Skin, x: number, y: number) => Drawn;
72
+ /** Visor's pointing hand, a finger pill above the palm, turned `angle` degrees about the palm at (x, y). Shared with Chaves (change supporting-characters, design §1). */
73
+ export declare const pointingHand: (s: Skin, x: number, y: number, angle: number) => SvgNode;
74
+ /** The held sheet's schema (Visor's and Chaves's `holdsSheet`). */
75
+ export declare const heldSheetSchema: Schema;
76
+ export declare const visor: import("./piece.ts").Piece<VisorParams>;
77
+ export type DroneParams = {
78
+ x: number;
79
+ y: number;
80
+ surface?: SurfaceName;
81
+ scale?: number;
82
+ expression?: CastExpression;
83
+ view?: CastView;
84
+ carries?: boolean;
85
+ };
86
+ export declare const drone: import("./piece.ts").Piece<DroneParams>;
87
+ export type KiuParams = {
88
+ x: number;
89
+ y: number;
90
+ surface?: SurfaceName;
91
+ scale?: number;
92
+ expression?: CastExpression;
93
+ view?: CastView;
94
+ steps?: number;
95
+ };
96
+ export declare const kiu: import("./piece.ts").Piece<KiuParams>;
97
+ export type SinalParams = {
98
+ x: number;
99
+ y: number;
100
+ surface?: SurfaceName;
101
+ scale?: number;
102
+ expression?: CastExpression;
103
+ view?: CastView;
104
+ };
105
+ export declare const sinal: import("./piece.ts").Piece<SinalParams>;