@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,158 @@
|
|
|
1
|
+
// Parameter schemas of the pieces: one description per piece, used both when
|
|
2
|
+
// code calls a piece (first problem thrown as a RangeError) and by the cover
|
|
3
|
+
// command (every problem collected, with its JSON path).
|
|
4
|
+
//
|
|
5
|
+
// Why one schema: the cover spec and a scene must accept exactly the same
|
|
6
|
+
// parameters, or a cover that validates could fail to draw.
|
|
7
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
8
|
+
/** A data colour: exactly six hex digits after the sign, nothing else. */
|
|
9
|
+
export const DATA_COLOUR = /^#[0-9A-Fa-f]{6}$/;
|
|
10
|
+
/** The hex value of a data colour parameter: a token path resolved, a data colour as given. */
|
|
11
|
+
export const paint = (value, name = "fill") => (DATA_COLOUR.test(value) ? value : colour(value, name));
|
|
12
|
+
const COLOUR_LITERAL = /^\s*(#[0-9a-fA-F]{3,8}\b|rgba?\(|hsla?\()/;
|
|
13
|
+
/** Every colour token, by its dotted path: any token whose value is #RRGGBB. */
|
|
14
|
+
export const COLOUR_TOKENS = (() => {
|
|
15
|
+
const found = new Map();
|
|
16
|
+
const visit = (prefix, node) => {
|
|
17
|
+
if (typeof node === "string") {
|
|
18
|
+
if (/^#[0-9a-fA-F]{6}$/.test(node))
|
|
19
|
+
found.set(prefix, node);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof node === "object" && node !== null) {
|
|
23
|
+
for (const [name, child] of Object.entries(node))
|
|
24
|
+
visit(prefix ? `${prefix}.${name}` : name, child);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
visit("", tokens);
|
|
28
|
+
return found;
|
|
29
|
+
})();
|
|
30
|
+
export const isColourLiteral = (value) => COLOUR_LITERAL.test(value);
|
|
31
|
+
/** The hex value of a colour token path; throws a RangeError for anything else. */
|
|
32
|
+
export const colour = (path, name = "colour") => {
|
|
33
|
+
const value = COLOUR_TOKENS.get(path);
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
throw new RangeError(`${name}: expected a colour token path such as color.state.healthy, found ${JSON.stringify(path)}`);
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
const describe = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
|
|
39
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
+
const checkValue = (spec, value, path, out) => {
|
|
41
|
+
const report = (message) => {
|
|
42
|
+
out.push({ path, message });
|
|
43
|
+
};
|
|
44
|
+
switch (spec.kind) {
|
|
45
|
+
case "number": {
|
|
46
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
47
|
+
return report(`expected a finite number, found ${describe(value)}`);
|
|
48
|
+
if (spec.integer && !Number.isInteger(value))
|
|
49
|
+
return report(`expected an integer, found ${value}`);
|
|
50
|
+
if (spec.min !== undefined && (spec.exclusiveMin ? value <= spec.min : value < spec.min)) {
|
|
51
|
+
return report(`expected a number ${spec.exclusiveMin ? "greater than" : "at least"} ${spec.min}, found ${value}`);
|
|
52
|
+
}
|
|
53
|
+
if (spec.max !== undefined && value > spec.max)
|
|
54
|
+
return report(`expected a number at most ${spec.max}, found ${value}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
case "color":
|
|
58
|
+
if (spec.currentColor && value === CURRENT_COLOUR)
|
|
59
|
+
return;
|
|
60
|
+
if (typeof value !== "string")
|
|
61
|
+
return report(`expected a colour token path, found ${describe(value)}`);
|
|
62
|
+
if (isColourLiteral(value))
|
|
63
|
+
return report("colour literals are not allowed; use a token path");
|
|
64
|
+
if (!COLOUR_TOKENS.has(value))
|
|
65
|
+
return report(`expected a colour token path such as color.state.healthy, found ${describe(value)}`);
|
|
66
|
+
return;
|
|
67
|
+
case "dataColor":
|
|
68
|
+
if (typeof value !== "string")
|
|
69
|
+
return report(`expected a colour token path or #RRGGBB, found ${describe(value)}`);
|
|
70
|
+
if (DATA_COLOUR.test(value) || COLOUR_TOKENS.has(value))
|
|
71
|
+
return;
|
|
72
|
+
return report(`expected a colour token path or a data colour #RRGGBB, found ${describe(value)}`);
|
|
73
|
+
case "string":
|
|
74
|
+
if (typeof value !== "string")
|
|
75
|
+
return report(`expected a string, found ${describe(value)}`);
|
|
76
|
+
if (spec.nonEmpty && value.trim() === "")
|
|
77
|
+
return report("expected a non-empty string");
|
|
78
|
+
if (spec.pattern && !spec.pattern.test(value))
|
|
79
|
+
return report(`expected ${spec.patternName ?? spec.pattern.source}`);
|
|
80
|
+
return;
|
|
81
|
+
case "enum":
|
|
82
|
+
if (typeof value !== "string" || !spec.values.includes(value)) {
|
|
83
|
+
return report(`expected one of ${spec.values.join(", ")}, found ${describe(value)}`);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
case "boolean":
|
|
87
|
+
if (typeof value !== "boolean")
|
|
88
|
+
return report(`expected true or false, found ${describe(value)}`);
|
|
89
|
+
return;
|
|
90
|
+
case "point":
|
|
91
|
+
// Any finite number: a map position has no maximum (spec illustration-pieces, "Positions of any size").
|
|
92
|
+
// Both indices read directly: every() skips the holes of a sparse array.
|
|
93
|
+
if (!Array.isArray(value) || value.length !== 2 || ![value[0], value[1]].every((n) => typeof n === "number" && Number.isFinite(n))) {
|
|
94
|
+
return report(`expected a point [x, y] of finite numbers, found ${describe(value)}`);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
case "array":
|
|
98
|
+
if (!Array.isArray(value))
|
|
99
|
+
return report(`expected an array, found ${describe(value)}`);
|
|
100
|
+
if (spec.minItems !== undefined && value.length < spec.minItems)
|
|
101
|
+
return report(`expected at least ${spec.minItems} item(s)`);
|
|
102
|
+
if (value.length > (spec.maxItems ?? MAX_ITEMS))
|
|
103
|
+
return report(`expected at most ${spec.maxItems ?? MAX_ITEMS} item(s)`);
|
|
104
|
+
// An index loop, not forEach: a hole in a sparse array is checked as a missing item, not skipped.
|
|
105
|
+
for (let index = 0; index < value.length; index++)
|
|
106
|
+
checkValue(spec.of, value[index], `${path}[${index}]`, out);
|
|
107
|
+
return;
|
|
108
|
+
case "object":
|
|
109
|
+
if (!isPlainObject(value))
|
|
110
|
+
return report(`expected an object, found ${describe(value)}`);
|
|
111
|
+
out.push(...checkParams(spec.fields, value, path));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/** Every problem of `params` against `schema`; paths are `prefix.name`. */
|
|
116
|
+
export const checkParams = (schema, params, prefix = "") => {
|
|
117
|
+
const out = [];
|
|
118
|
+
const at = (name) => (prefix ? `${prefix}.${name}` : name);
|
|
119
|
+
for (const name of Object.keys(params)) {
|
|
120
|
+
if (!Object.hasOwn(schema, name))
|
|
121
|
+
out.push({ path: at(name), message: `unknown parameter (expected ${Object.keys(schema).join(", ")})` });
|
|
122
|
+
}
|
|
123
|
+
for (const [name, spec] of Object.entries(schema)) {
|
|
124
|
+
if (!Object.hasOwn(params, name) || params[name] === undefined) {
|
|
125
|
+
if (spec.required)
|
|
126
|
+
out.push({ path: at(name), message: "missing required parameter" });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
checkValue(spec, params[name], at(name), out);
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
/** Validates params for a call from code; the first problem becomes a RangeError. */
|
|
134
|
+
export const assertParams = (piece, schema, params) => {
|
|
135
|
+
const problems = checkParams(schema, params);
|
|
136
|
+
if (problems.length > 0)
|
|
137
|
+
throw new RangeError(`${piece}: ${problems[0].path}: ${problems[0].message}`);
|
|
138
|
+
};
|
|
139
|
+
// Shorthands for schemas.
|
|
140
|
+
export const num = (extra = {}) => ({ kind: "number", ...extra });
|
|
141
|
+
/** Largest size a piece accepts, far above any banner. Positions and points have no bound. */
|
|
142
|
+
export const MAX_SIZE = 10000;
|
|
143
|
+
/** Most items in any list parameter (rows, lines, nodes, tiles). */
|
|
144
|
+
export const MAX_ITEMS = 50;
|
|
145
|
+
/** A count of repeated parts (units, steps, teeth): an integer from `min` to `max`. */
|
|
146
|
+
export const count = (min, max) => ({ kind: "number", integer: true, min, max });
|
|
147
|
+
/** A size: greater than 0 (or at least `min`, where fixed insets need room), at most MAX_SIZE. */
|
|
148
|
+
export const size = (required = false, min) => min === undefined ? { kind: "number", min: 0, exclusiveMin: true, max: MAX_SIZE, required } : { kind: "number", min, max: MAX_SIZE, required };
|
|
149
|
+
/** A position: any finite number, because a map position has no maximum. */
|
|
150
|
+
export const pos = () => ({ kind: "number", required: true });
|
|
151
|
+
export const col = () => ({ kind: "color" });
|
|
152
|
+
/** The paint keyword that follows the text colour of an inline SVG's element. */
|
|
153
|
+
export const CURRENT_COLOUR = "currentColor";
|
|
154
|
+
/** A token path or `currentColor`: for icons written inline in a page. */
|
|
155
|
+
export const colOrCurrent = () => ({ kind: "color", currentColor: true });
|
|
156
|
+
/** SVG path data: commands, digits, signs, dots, commas and spaces only. */
|
|
157
|
+
export const PATH_DATA = /^[MmLlHhVvCcSsQqTtAaZz0-9eE.,+\-\s]+$/;
|
|
158
|
+
export const label = (required = true) => ({ kind: "string", nonEmpty: true, required });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Drawn } from "./node.ts";
|
|
2
|
+
import { type Problem, type Schema } from "./params.ts";
|
|
3
|
+
export type Relations<P> = (params: P) => Problem[];
|
|
4
|
+
export type Piece<P extends object> = ((params: P) => Drawn) & {
|
|
5
|
+
readonly pieceName: string;
|
|
6
|
+
readonly schema: Schema;
|
|
7
|
+
readonly relations?: Relations<P>;
|
|
8
|
+
};
|
|
9
|
+
export declare const definePiece: <P extends object>(name: string, schema: Schema, draw: (params: P) => Drawn, relations?: Relations<P>) => Piece<P>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { assertParams } from "./params.js";
|
|
2
|
+
// A number the piece computed and would draw: finite, or the drawing overflows
|
|
3
|
+
// (spec illustration-pieces, "Drawing overflow"). Strings are the piece's own
|
|
4
|
+
// path data and transforms; caller path data (road.d, pipe.d) has its own check
|
|
5
|
+
// and only ever holds path characters, never the words Infinity or NaN.
|
|
6
|
+
const NON_FINITE = /Infinity|NaN/;
|
|
7
|
+
const overflows = (node) => {
|
|
8
|
+
if (typeof node === "string")
|
|
9
|
+
return false;
|
|
10
|
+
for (const value of Object.values(node.attrs)) {
|
|
11
|
+
if (typeof value === "number" ? !Number.isFinite(value) : NON_FINITE.test(value))
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return node.children.some(overflows);
|
|
15
|
+
};
|
|
16
|
+
export const definePiece = (name, schema, draw, relations) => {
|
|
17
|
+
const piece = (params) => {
|
|
18
|
+
assertParams(name, schema, params);
|
|
19
|
+
const problems = relations?.(params) ?? [];
|
|
20
|
+
if (problems.length > 0)
|
|
21
|
+
throw new RangeError(`${name}: ${problems[0].path}: ${problems[0].message}`);
|
|
22
|
+
const drawn = draw(params);
|
|
23
|
+
if ([...drawn.body, ...drawn.text].some(overflows))
|
|
24
|
+
throw new RangeError(`${name}: the drawing overflows`);
|
|
25
|
+
return drawn;
|
|
26
|
+
};
|
|
27
|
+
return Object.assign(piece, { pieceName: name, schema, relations });
|
|
28
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SvgNode } from "./node.ts";
|
|
2
|
+
export type Pose = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
/** Degrees, clockwise. */
|
|
6
|
+
tilt?: number;
|
|
7
|
+
/** Vertical stretch; the width shrinks by its square root, so volume reads constant. */
|
|
8
|
+
squash?: number;
|
|
9
|
+
/** Pixels above the base. */
|
|
10
|
+
hop?: number;
|
|
11
|
+
scale?: number;
|
|
12
|
+
/** Horizontal offset in pixels. */
|
|
13
|
+
shake?: number;
|
|
14
|
+
opacity?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const pose: (node: SvgNode, params: Pose) => SvgNode;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Animation by parameter (spec illustration-pieces, "Animation by
|
|
2
|
+
// parameter"): the wrapper of the approved cast motion test. A scene computes
|
|
3
|
+
// the numbers from the frame and wraps the piece; the anchor (x, y) is the
|
|
4
|
+
// piece's base, usually its feet, so squash and tilt keep it on the ground.
|
|
5
|
+
import { g } from "./node.js";
|
|
6
|
+
const finite = (name, value) => {
|
|
7
|
+
if (!Number.isFinite(value))
|
|
8
|
+
throw new RangeError(`pose: ${name} must be a finite number, found ${value}`);
|
|
9
|
+
};
|
|
10
|
+
export const pose = (node, params) => {
|
|
11
|
+
const { x, y, tilt = 0, squash = 1, hop = 0, scale = 1, shake = 0, opacity = 1 } = params;
|
|
12
|
+
// Each parameter is checked completely (finite, then range) before the next, in this order.
|
|
13
|
+
for (const [name, value] of Object.entries({ x, y, tilt, squash, hop, scale, shake, opacity })) {
|
|
14
|
+
finite(name, value);
|
|
15
|
+
if ((name === "squash" || name === "scale") && value <= 0)
|
|
16
|
+
throw new RangeError(`pose: ${name} must be greater than 0, found ${value}`);
|
|
17
|
+
if (name === "opacity" && (value < 0 || value > 1))
|
|
18
|
+
throw new RangeError(`pose: opacity must be within 0 and 1, found ${value}`);
|
|
19
|
+
}
|
|
20
|
+
if (tilt === 0 && squash === 1 && hop === 0 && scale === 1 && shake === 0 && opacity === 1)
|
|
21
|
+
return node;
|
|
22
|
+
// Finite inputs can still overflow once combined (scale 1e308 with squash 4).
|
|
23
|
+
const parts = { "x + shake": x + shake, "y - hop": y - hop, "horizontal scale": scale / Math.sqrt(squash), "vertical scale": scale * squash };
|
|
24
|
+
for (const [name, value] of Object.entries(parts)) {
|
|
25
|
+
if (!Number.isFinite(value))
|
|
26
|
+
throw new RangeError(`pose: ${name} overflows, found ${value}`);
|
|
27
|
+
}
|
|
28
|
+
const transform = `translate(${parts["x + shake"]} ${parts["y - hop"]}) rotate(${tilt}) scale(${parts["horizontal scale"]} ${parts["vertical scale"]}) translate(${-x} ${-y})`;
|
|
29
|
+
return g(opacity < 1 ? { transform, opacity } : { transform }, node);
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type SurfaceName } from "./ink.ts";
|
|
2
|
+
export type QuestionTokenParams = {
|
|
3
|
+
cx: number;
|
|
4
|
+
cy: number;
|
|
5
|
+
scale?: number;
|
|
6
|
+
surface?: SurfaceName;
|
|
7
|
+
};
|
|
8
|
+
/** The open question as an object: a white disc with a `?`, the mark of a sheet's question row. */
|
|
9
|
+
export declare const questionToken: import("./piece.ts").Piece<QuestionTokenParams>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// `questionToken` (spec illustration-pieces, "Question token", "Question token
|
|
2
|
+
// parameters"; change sdd-scene-pieces, design §4): the open question as an
|
|
3
|
+
// object that travels in a scene or sits on a cover, in the v2 grammar of ADR
|
|
4
|
+
// 0009. Its mark is exactly a `sheet` question row's (a white disc of radius 13
|
|
5
|
+
// outlined at `outline.small`, a `?` at size 19 and weight heavy, baseline +7),
|
|
6
|
+
// because in the SDD scene the token travels into a sheet and becomes a row.
|
|
7
|
+
//
|
|
8
|
+
// Why a piece of its own: `countBadge` is a stackledger map sticker (its face is
|
|
9
|
+
// the surface's panel, its size grows from `textSize` with the map tokens), so
|
|
10
|
+
// the gate-0 storyboard's `?` drawn with it read as a dark disc on the dark
|
|
11
|
+
// surface and tied the scene's object to the map's evolution.
|
|
12
|
+
//
|
|
13
|
+
// The disc carries its own stroke, so it draws the same inside the cover
|
|
14
|
+
// command's outlined group as in a scene; the `?` carries its own font, so it
|
|
15
|
+
// reads the same through `toReact` where no labels group exists. `scale` scales
|
|
16
|
+
// the outline with the disc (as `emote`), so a large token keeps the row's
|
|
17
|
+
// proportions.
|
|
18
|
+
//
|
|
19
|
+
// What can go wrong: the schema rejects a missing position, a scale outside
|
|
20
|
+
// (0, 10], an unknown surface, and any colour or text parameter (the token takes
|
|
21
|
+
// none), naming the parameter.
|
|
22
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
23
|
+
import { drawn, el, g } from "./node.js";
|
|
24
|
+
import { inkOf, surfaceParam } from "./ink.js";
|
|
25
|
+
import { pos } from "./params.js";
|
|
26
|
+
import { definePiece } from "./piece.js";
|
|
27
|
+
/** The radius of a sheet question row's disc (`sheet` in paper.ts). */
|
|
28
|
+
const MARK_RADIUS = 13;
|
|
29
|
+
/** The `?` of a sheet question row: its size, and its baseline below the disc's centre. */
|
|
30
|
+
const GLYPH_SIZE = 19;
|
|
31
|
+
const GLYPH_BASELINE = 7;
|
|
32
|
+
const drawQuestionToken = ({ cx, cy, scale = 1, surface = "light" }) => {
|
|
33
|
+
// The ink line of the surface: ink on light, `surface.dark.muted` on dark (ADR 0009's dark rule).
|
|
34
|
+
const { line } = inkOf({ surface });
|
|
35
|
+
const attrs = scale === 1
|
|
36
|
+
? { "data-piece": "questionToken" }
|
|
37
|
+
: { "data-piece": "questionToken", transform: `translate(${cx} ${cy}) scale(${scale}) translate(${-cx} ${-cy})` };
|
|
38
|
+
return drawn([g(attrs, el("circle", { cx, cy, r: MARK_RADIUS, fill: tokens.color.white, stroke: line, "stroke-width": tokens.outline.small }))], [g(attrs, el("text", {
|
|
39
|
+
x: cx,
|
|
40
|
+
y: cy + GLYPH_BASELINE,
|
|
41
|
+
"font-family": tokens.font.sans,
|
|
42
|
+
"font-size": GLYPH_SIZE,
|
|
43
|
+
"font-weight": tokens.font.weightHeavy,
|
|
44
|
+
fill: tokens.color.ink,
|
|
45
|
+
"text-anchor": "middle",
|
|
46
|
+
}, "?"))]);
|
|
47
|
+
};
|
|
48
|
+
/** The open question as an object: a white disc with a `?`, the mark of a sheet's question row. */
|
|
49
|
+
export const questionToken = definePiece("questionToken", { cx: pos(), cy: pos(), scale: { kind: "number", min: 0, exclusiveMin: true, max: 10 }, surface: surfaceParam }, drawQuestionToken);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// React renderer of the node tree (spec illustration-pieces, "React
|
|
2
|
+
// renderer"): the same drawing as toSvg, as React elements for Remotion scenes.
|
|
3
|
+
// Hyphenated SVG attributes take React's camelCase names; aria-* and data-*
|
|
4
|
+
// stay as they are, because React expects them hyphenated.
|
|
5
|
+
import { createElement } from "react";
|
|
6
|
+
export const reactName = (name) => name.startsWith("aria-") || name.startsWith("data-") ? name : name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
7
|
+
export const toReact = (node, key = 0) => {
|
|
8
|
+
const props = { key };
|
|
9
|
+
for (const [name, value] of Object.entries(node.attrs))
|
|
10
|
+
props[reactName(name)] = value;
|
|
11
|
+
const children = node.children.map((child, index) => (typeof child === "string" ? child : toReact(child, index)));
|
|
12
|
+
return createElement(node.tag, props, ...children);
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2
|
+
const attributes = (node) => Object.entries(node.attrs)
|
|
3
|
+
.map(([name, value]) => ` ${name}="${escape(String(value))}"`)
|
|
4
|
+
.join("");
|
|
5
|
+
export const toSvg = (node, depth = 0) => {
|
|
6
|
+
if (typeof node === "string")
|
|
7
|
+
return escape(node);
|
|
8
|
+
const pad = " ".repeat(depth);
|
|
9
|
+
const open = `${pad}<${node.tag}${attributes(node)}`;
|
|
10
|
+
if (node.children.length === 0)
|
|
11
|
+
return `${open}/>`;
|
|
12
|
+
// Text content, alone or mixed with elements, is written inline: added whitespace would change it.
|
|
13
|
+
// A text node is always written inline, so one holding only a tspan keeps its words intact (body-diagram-pieces §4).
|
|
14
|
+
if (node.tag === "text" || node.children.some((child) => typeof child === "string")) {
|
|
15
|
+
return `${open}>${node.children.map((child) => toSvg(child)).join("")}</${node.tag}>`;
|
|
16
|
+
}
|
|
17
|
+
if (node.children.every((child) => typeof child === "string")) {
|
|
18
|
+
return `${open}>${node.children.map((child) => toSvg(child)).join("")}</${node.tag}>`;
|
|
19
|
+
}
|
|
20
|
+
const inner = node.children.map((child) => (typeof child === "string" ? `${pad} ${escape(child)}` : toSvg(child, depth + 1)));
|
|
21
|
+
return `${open}>\n${inner.join("\n")}\n${pad}</${node.tag}>`;
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type SurfaceName } from "./ink.ts";
|
|
2
|
+
export type Skin = {
|
|
3
|
+
readonly body: string;
|
|
4
|
+
readonly outline: string;
|
|
5
|
+
readonly visor: string;
|
|
6
|
+
readonly eye: string;
|
|
7
|
+
readonly accent: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The cast's resolved colours for one surface. The visor is deliberately not
|
|
11
|
+
* the mirror of the outline: the approved sheets keep the screen face
|
|
12
|
+
* near-black in both themes (contrast against the white body), so dark-theme
|
|
13
|
+
* visor reads `brand.dark.bg`, not the light cream `brand.dark.text`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const skin: (surface: SurfaceName) => Skin;
|
|
16
|
+
/** `fill`/`stroke`/`stroke-width`/`stroke-linejoin` for an outlined body shape (the sheets' `ob()`). */
|
|
17
|
+
export declare const outlined: (s: Skin, width?: number) => {
|
|
18
|
+
fill: string;
|
|
19
|
+
stroke: string;
|
|
20
|
+
"stroke-width": number;
|
|
21
|
+
"stroke-linejoin": "round";
|
|
22
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { colour } from "./params.js";
|
|
2
|
+
const c = (path) => colour(path);
|
|
3
|
+
/**
|
|
4
|
+
* The cast's resolved colours for one surface. The visor is deliberately not
|
|
5
|
+
* the mirror of the outline: the approved sheets keep the screen face
|
|
6
|
+
* near-black in both themes (contrast against the white body), so dark-theme
|
|
7
|
+
* visor reads `brand.dark.bg`, not the light cream `brand.dark.text`.
|
|
8
|
+
*/
|
|
9
|
+
export const skin = (surface) => surface === "light"
|
|
10
|
+
? { body: c("color.white"), outline: c("brand.light.text"), visor: c("brand.light.text"), eye: c("cast.eyes"), accent: c("brand.light.accent") }
|
|
11
|
+
: { body: c("color.white"), outline: c("brand.dark.textMuted"), visor: c("brand.dark.bg"), eye: c("cast.eyes"), accent: c("brand.dark.accent") };
|
|
12
|
+
/** `fill`/`stroke`/`stroke-width`/`stroke-linejoin` for an outlined body shape (the sheets' `ob()`). */
|
|
13
|
+
export const outlined = (s, width = 8) => ({ fill: s.body, stroke: s.outline, "stroke-width": width, "stroke-linejoin": "round" });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type StampParams = {
|
|
2
|
+
cx: number;
|
|
3
|
+
cy: number;
|
|
4
|
+
word: string;
|
|
5
|
+
fill?: string;
|
|
6
|
+
r?: number;
|
|
7
|
+
rotate?: number;
|
|
8
|
+
shape?: "round" | "rect";
|
|
9
|
+
};
|
|
10
|
+
/** Rubber stamp, round (dashed inner ring) or rectangular, tilted, with one word. */
|
|
11
|
+
export declare const stamp: import("./piece.ts").Piece<StampParams>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The `stamp` piece (spec illustration-pieces, "Piece catalogue"), moved
|
|
2
|
+
// unchanged from library.ts by change supporting-characters (card 337): Balão
|
|
3
|
+
// holds a stamp (`holdsStamp`, supporting-cast.ts), and supporting-cast.ts
|
|
4
|
+
// cannot import library.ts, which imports it to list Balão in PIECES (the same
|
|
5
|
+
// cycle paper.ts broke for `pill` and `sheet`). library.ts re-exports it and
|
|
6
|
+
// keeps it at its place in PIECES. test/fixtures/stamp-0.12.0.json pins its
|
|
7
|
+
// 0.12.0 drawings ("Stamp calls of 0.12.0 unchanged").
|
|
8
|
+
//
|
|
9
|
+
// What can go wrong: the schema rejects an empty word, a radius under 12 and an
|
|
10
|
+
// unknown shape, naming the parameter. The word is drawn at size 27 whatever
|
|
11
|
+
// the radius, so a long word overhangs a small stamp: fitting it is the caller's job.
|
|
12
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
13
|
+
import { drawn, el, g } from "./node.js";
|
|
14
|
+
import { col, colour, label, pos, size } from "./params.js";
|
|
15
|
+
import { definePiece } from "./piece.js";
|
|
16
|
+
/** Rubber stamp, round (dashed inner ring) or rectangular, tilted, with one word. */
|
|
17
|
+
export const stamp = definePiece("stamp", { cx: pos(), cy: pos(), word: label(), fill: col(), r: size(false, 12), rotate: { kind: "number" }, shape: { kind: "enum", values: ["round", "rect"] } }, ({ cx, cy, word, fill = "color.state.healthy", r = 40, rotate = -12, shape = "round" }) => {
|
|
18
|
+
const turn = `rotate(${rotate} ${cx} ${cy})`;
|
|
19
|
+
const face = shape === "round"
|
|
20
|
+
? [
|
|
21
|
+
el("circle", { cx, cy, r, fill: colour(fill, "fill") }),
|
|
22
|
+
el("circle", { cx, cy, r: r - 10, fill: "none", stroke: tokens.color.white, "stroke-width": tokens.outline.small, "stroke-dasharray": "6 5" }),
|
|
23
|
+
]
|
|
24
|
+
: [
|
|
25
|
+
el("rect", { x: cx - r * 1.6, y: cy - r * 0.7, width: r * 3.2, height: r * 1.4, rx: 8, fill: colour(fill, "fill") }),
|
|
26
|
+
el("rect", { x: cx - r * 1.6 + 8, y: cy - r * 0.7 + 8, width: r * 3.2 - 16, height: r * 1.4 - 16, rx: 4, fill: "none", stroke: tokens.color.white, "stroke-width": tokens.outline.small }),
|
|
27
|
+
];
|
|
28
|
+
return drawn([g({ transform: turn }, ...face)], [el("text", { x: cx, y: cy + 10, "font-size": 27, "font-weight": tokens.font.weightHeavy, transform: turn }, word)]);
|
|
29
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type CastExpression, type CastView, type HeldSheet } from "./brand-cast.ts";
|
|
2
|
+
import { type SurfaceName } from "./ink.ts";
|
|
3
|
+
export declare const CAST_FACINGS: readonly ["right", "left"];
|
|
4
|
+
/** The side a supporting character faces: its signature part and front hand go there. */
|
|
5
|
+
export type CastFacing = (typeof CAST_FACINGS)[number];
|
|
6
|
+
type Shared = {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
surface?: SurfaceName;
|
|
10
|
+
scale?: number;
|
|
11
|
+
expression?: CastExpression;
|
|
12
|
+
view?: CastView;
|
|
13
|
+
facing?: CastFacing;
|
|
14
|
+
};
|
|
15
|
+
export type BalaoParams = Shared & {
|
|
16
|
+
/** The request line on the belly lit in the accent: Balão is asking. */
|
|
17
|
+
speaks?: boolean;
|
|
18
|
+
/** The `stamp` piece in the front hand, with the caller's word (the SDD scene's `GO`); refused with `speaks` or from behind. */
|
|
19
|
+
holdsStamp?: {
|
|
20
|
+
word: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Balão, the requester and approver: a speech balloon whose tail points at the listener. */
|
|
24
|
+
export declare const balao: import("./piece.ts").Piece<BalaoParams>;
|
|
25
|
+
export type ChavesParams = Shared & {
|
|
26
|
+
/** Types at the `keyboard`, held under the front hand; refused with another action or from behind. */
|
|
27
|
+
types?: boolean;
|
|
28
|
+
/** The front hand becomes Visor's pointing hand, reaching up and forward; refused with another action. */
|
|
29
|
+
points?: boolean;
|
|
30
|
+
/** Hands a sheet over, held out in the front hand (Visor's held sheet); refused with another action or from behind. */
|
|
31
|
+
holdsSheet?: HeldSheet;
|
|
32
|
+
};
|
|
33
|
+
/** Chaves, the developer: a `{ }` body with sharp brace points and the cursor in the accent. */
|
|
34
|
+
export declare const chaves: import("./piece.ts").Piece<ChavesParams>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The supporting cast (ADR 0007, amended 2026-11-12; spec illustration-pieces,
|
|
2
|
+
// "Balão", "Chaves" and their parameters; change supporting-characters, design
|
|
3
|
+
// §1 to §5): two characters for the human roles the pillar cast cannot tell,
|
|
4
|
+
// drawn from the approved concept C sheet, "the notation" (identity studio,
|
|
5
|
+
// 2026-11-12; prototype ~/.hermes/cache/scratch/ab337-characters/chars.ts).
|
|
6
|
+
//
|
|
7
|
+
// balao the requester and approver: a speech balloon on Mira's legs whose
|
|
8
|
+
// tail points at the listener; `speaks` lights the request line on
|
|
9
|
+
// its belly, `holdsStamp` holds the `stamp` piece to approve.
|
|
10
|
+
// chaves the developer: a `{ }` body with sharp brace points and a waist (so
|
|
11
|
+
// it reads as a brace at 24 px, not a pillow) and the accent cursor;
|
|
12
|
+
// `types` at the `keyboard`, `points`, `holdsSheet` hands a sheet over.
|
|
13
|
+
//
|
|
14
|
+
// Both wear the shared skin (skin.ts), the screen face and the parent-brand hood
|
|
15
|
+
// tip (brand-cast.ts), take the cast's shared parameters plus `facing`, and do
|
|
16
|
+
// one action at a time, every action off unless set (motion CAST-2 to CAST-5).
|
|
17
|
+
// Coordinates are local units at scale 1 facing right: the ground line is y 0,
|
|
18
|
+
// up is negative, the anchor (x, y) is the centre of the ground line.
|
|
19
|
+
//
|
|
20
|
+
// Why a module of its own: the supporting cast stays apart from the five pinned
|
|
21
|
+
// pillar drawings (design §1, option B). It imports stamp.ts, keyboard.ts,
|
|
22
|
+
// paper.ts and brand-cast.ts, never library.ts, which imports it (the cycle
|
|
23
|
+
// stamp.ts was moved out to break).
|
|
24
|
+
//
|
|
25
|
+
// What can go wrong: the schema rejects a bad parameter, naming it; then each
|
|
26
|
+
// piece returns at most one relation problem (two actions together, or a prop
|
|
27
|
+
// seen from behind), so a cover spec reports one line per piece.
|
|
28
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
29
|
+
import { CAST_EXPRESSIONS, CAST_VIEWS, faceAt, heldSheetSchema, holdSheet, peak, pointingHand } from "./brand-cast.js";
|
|
30
|
+
import { surfaceParam } from "./ink.js";
|
|
31
|
+
import { drawn, el, g } from "./node.js";
|
|
32
|
+
import { label, num, pos } from "./params.js";
|
|
33
|
+
import { definePiece } from "./piece.js";
|
|
34
|
+
import { outlined, skin } from "./skin.js";
|
|
35
|
+
import { keyboard } from "./keyboard.js";
|
|
36
|
+
import { stamp } from "./stamp.js";
|
|
37
|
+
export const CAST_FACINGS = ["right", "left"];
|
|
38
|
+
/** The parameters every supporting character shares with the cast, plus `facing`. */
|
|
39
|
+
const sharedSchema = {
|
|
40
|
+
x: pos(), y: pos(), surface: surfaceParam,
|
|
41
|
+
scale: num({ min: 0.25, max: 4 }),
|
|
42
|
+
expression: { kind: "enum", values: CAST_EXPRESSIONS },
|
|
43
|
+
view: { kind: "enum", values: CAST_VIEWS },
|
|
44
|
+
facing: { kind: "enum", values: CAST_FACINGS },
|
|
45
|
+
};
|
|
46
|
+
/** Mira's legs (two strokes of width 8 and two foot pills) from the hips at (±hip, top) to the feet at (±foot, 0). */
|
|
47
|
+
const legs = (s, top, hip, foot) => [
|
|
48
|
+
el("path", { d: `M${-hip} ${top} L${-foot} 0 M${hip} ${top} L${foot} 0`, stroke: s.outline, "stroke-width": 8, "stroke-linecap": "round" }),
|
|
49
|
+
el("rect", { x: -foot - 10, y: -6, width: 20, height: 7, rx: 3.5, fill: s.outline }),
|
|
50
|
+
el("rect", { x: foot - 10, y: -6, width: 20, height: 7, rx: 3.5, fill: s.outline }),
|
|
51
|
+
];
|
|
52
|
+
/** Visor's hand: a circle of radius 15 with the cast's outline. */
|
|
53
|
+
const hand = (s, cx, cy) => el("circle", { cx, cy, r: 15, ...outlined(s) });
|
|
54
|
+
/** The hood tip seen from behind, a flat lens on the top edge (Visor's back, at the character's top). */
|
|
55
|
+
const tipBack = (s, top) => el("path", { d: `M-28 ${top} Q0 ${top - 8} 28 ${top} Q0 ${top + 8} -28 ${top} Z`, fill: s.accent, stroke: s.outline, "stroke-width": 5, "stroke-linejoin": "round" });
|
|
56
|
+
/** A held prop's group: the prop's shapes with the skin's outline (the cast's root sets `stroke: none`). */
|
|
57
|
+
const heldGroup = (name, s, ...children) => g({ "data-held": name, stroke: s.outline, "stroke-width": tokens.outline.block, "stroke-linejoin": "round" }, ...children);
|
|
58
|
+
/**
|
|
59
|
+
* The character's tree (design §1, Visor's shape): the root group at the anchor
|
|
60
|
+
* and scale with `stroke: none`; the held prop first (outside the mirror, at its
|
|
61
|
+
* mirrored position, so its words and marks read), then the body group, mirrored
|
|
62
|
+
* facing left; the words in one text group with the root's transform.
|
|
63
|
+
*/
|
|
64
|
+
const assemble = (name, p, held, parts) => {
|
|
65
|
+
const transform = `translate(${p.x} ${p.y}) scale(${p.scale ?? 1})`;
|
|
66
|
+
// Facing left mirrors the body only: a uniform -1 scale keeps every stroke width and colour (ADR 0009).
|
|
67
|
+
const body = g((p.facing ?? "right") === "left" ? { transform: "scale(-1,1)" } : {}, ...parts);
|
|
68
|
+
const words = held?.text ?? [];
|
|
69
|
+
const text = words.length > 0
|
|
70
|
+
? [g({ transform, "font-family": tokens.font.sans, "font-size": tokens.cover.labelSize, "font-weight": tokens.cover.labelWeight, fill: tokens.color.ink, "text-anchor": "middle" }, ...words)]
|
|
71
|
+
: [];
|
|
72
|
+
return drawn([g({ "data-piece": name, transform, stroke: "none" }, ...(held?.body ?? []), body)], text);
|
|
73
|
+
};
|
|
74
|
+
/** -1 facing left, 1 facing right: the side of a held prop drawn outside the mirrored body. */
|
|
75
|
+
const side = (p) => ((p.facing ?? "right") === "left" ? -1 : 1);
|
|
76
|
+
/** Balão's body: the rounded balloon with its tail low on the front side, pointing out and down at (94, -76), never between the legs (design §2). */
|
|
77
|
+
const BALAO_BODY = "M-62 -132 Q-62 -162 -32 -162 H32 Q62 -162 62 -132 V-104 L94 -76 L56 -70 Q48 -60 32 -60 H-32 Q-62 -60 -62 -88 Z";
|
|
78
|
+
const BALAO_TOP = -162;
|
|
79
|
+
/** The held stamp's centre and radius, beside the tail (design §2); the front hand sits over its top edge. */
|
|
80
|
+
const BALAO_STAMP = { cx: 132, cy: -70, r: 24 };
|
|
81
|
+
const drawBalao = (p) => {
|
|
82
|
+
const s = skin(p.surface ?? "light");
|
|
83
|
+
const back = (p.view ?? "front") === "back";
|
|
84
|
+
const held = p.holdsStamp === undefined ? null : stamp({ ...BALAO_STAMP, cx: BALAO_STAMP.cx * side(p), word: p.holdsStamp.word });
|
|
85
|
+
const front = back
|
|
86
|
+
? [tipBack(s, BALAO_TOP)]
|
|
87
|
+
: [
|
|
88
|
+
faceAt(-38, -146, 76, 40, s, p.expression ?? "idle"),
|
|
89
|
+
// The request is a bar, not a word: Balão draws no word of its own.
|
|
90
|
+
el("rect", { x: -30, y: -88, width: 60, height: 9, rx: 4.5, fill: p.speaks === true ? s.accent : tokens.illustration.textBar }),
|
|
91
|
+
peak(s, 0, BALAO_TOP, 28, 24),
|
|
92
|
+
];
|
|
93
|
+
const parts = [
|
|
94
|
+
...legs(s, -62, 20, 28),
|
|
95
|
+
el("path", { d: BALAO_BODY, ...outlined(s) }),
|
|
96
|
+
...front,
|
|
97
|
+
hand(s, -86, -100),
|
|
98
|
+
held ? hand(s, BALAO_STAMP.cx, BALAO_STAMP.cy - 30) : hand(s, 92, -132),
|
|
99
|
+
];
|
|
100
|
+
return assemble("balao", p, held && { body: [heldGroup("stamp", s, ...held.body)], text: held.text }, parts);
|
|
101
|
+
};
|
|
102
|
+
/** Balão's relation problem, at most one (design §5): one action at a time, then no stamp from behind. */
|
|
103
|
+
const balaoRelations = (p) => {
|
|
104
|
+
if (p.holdsStamp === undefined)
|
|
105
|
+
return [];
|
|
106
|
+
if (p.speaks === true)
|
|
107
|
+
return [{ path: "holdsStamp", message: "Balão does one action at a time" }];
|
|
108
|
+
if (p.view === "back")
|
|
109
|
+
return [{ path: "holdsStamp", message: "Balão holds a stamp only in the front view" }];
|
|
110
|
+
return [];
|
|
111
|
+
};
|
|
112
|
+
/** Balão, the requester and approver: a speech balloon whose tail points at the listener. */
|
|
113
|
+
export const balao = definePiece("balao", { ...sharedSchema, speaks: { kind: "boolean" }, holdsStamp: { kind: "object", fields: { word: label() } } }, drawBalao, balaoRelations);
|
|
114
|
+
/**
|
|
115
|
+
* Chaves's body, a brace outline that reads at 24 px (design §3, option A): the
|
|
116
|
+
* points reach x ±90 at mid height (y -88), 36 outside the corners (±54) and 46
|
|
117
|
+
* outside the waist (±44), each a corner between two curves.
|
|
118
|
+
*/
|
|
119
|
+
const CHAVES_BODY = "M-30 -150 H30 Q54 -150 54 -128 Q54 -112 44 -108 Q60 -96 90 -88 Q60 -80 44 -68 Q54 -64 54 -48 Q54 -26 30 -26 H-30 Q-54 -26 -54 -48 Q-54 -64 -44 -68 Q-60 -80 -90 -88 Q-60 -96 -44 -108 Q-54 -112 -54 -128 Q-54 -150 -30 -150 Z";
|
|
120
|
+
const CHAVES_TOP = -150;
|
|
121
|
+
/** Where the held props sit (design §3): the keyboard's top-left corner, and the held page's near edge and bottom. */
|
|
122
|
+
const CHAVES_KEYBOARD = { x: 98, y: -74, width: 150 };
|
|
123
|
+
const CHAVES_SHEET_EDGE = 118;
|
|
124
|
+
const CHAVES_SHEET_BOTTOM = -40;
|
|
125
|
+
const drawChaves = (p) => {
|
|
126
|
+
const s = skin(p.surface ?? "light");
|
|
127
|
+
const back = (p.view ?? "front") === "back";
|
|
128
|
+
const turn = side(p);
|
|
129
|
+
let held = null;
|
|
130
|
+
let frontHand = hand(s, 100, -50);
|
|
131
|
+
if (p.types === true) {
|
|
132
|
+
// The keyboard's own shapes (its slab carries its stroke, its keys sit in a `stroke: none` group), without its
|
|
133
|
+
// `data-piece` root, so a selector of `[data-piece]` counts one piece per character.
|
|
134
|
+
const board = keyboard({ ...CHAVES_KEYBOARD, x: turn > 0 ? CHAVES_KEYBOARD.x : -CHAVES_KEYBOARD.x - CHAVES_KEYBOARD.width, surface: p.surface });
|
|
135
|
+
held = { body: [g({ "data-held": "keyboard" }, ...board.body[0].children.filter((child) => typeof child !== "string"))], text: [] };
|
|
136
|
+
frontHand = hand(s, 120, -80);
|
|
137
|
+
}
|
|
138
|
+
else if (p.holdsSheet !== undefined) {
|
|
139
|
+
const page = p.holdsSheet;
|
|
140
|
+
held = holdSheet(page, s, turn > 0 ? CHAVES_SHEET_EDGE : -CHAVES_SHEET_EDGE - page.width, CHAVES_SHEET_BOTTOM - page.height);
|
|
141
|
+
frontHand = hand(s, 112, -92);
|
|
142
|
+
}
|
|
143
|
+
else if (p.points === true) {
|
|
144
|
+
frontHand = pointingHand(s, 104, -128, 55);
|
|
145
|
+
}
|
|
146
|
+
const front = back
|
|
147
|
+
? [tipBack(s, CHAVES_TOP)]
|
|
148
|
+
: [
|
|
149
|
+
faceAt(-34, -132, 68, 38, s, p.expression ?? "idle"),
|
|
150
|
+
el("rect", { x: -9, y: -76, width: 18, height: 8, rx: 2, fill: s.accent }),
|
|
151
|
+
peak(s, 0, CHAVES_TOP, 28, 24),
|
|
152
|
+
];
|
|
153
|
+
const parts = [...legs(s, -30, 16, 26), el("path", { d: CHAVES_BODY, ...outlined(s) }), ...front, hand(s, -100, -50), frontHand];
|
|
154
|
+
return assemble("chaves", p, held, parts);
|
|
155
|
+
};
|
|
156
|
+
/** Chaves's relation problem, at most one (design §5): one action at a time (naming the second on), then no prop from behind. */
|
|
157
|
+
const chavesRelations = (p) => {
|
|
158
|
+
const on = [["types", p.types === true], ["points", p.points === true], ["holdsSheet", p.holdsSheet !== undefined]].filter(([, isOn]) => isOn).map(([name]) => name);
|
|
159
|
+
if (on.length > 1)
|
|
160
|
+
return [{ path: on[1], message: "Chaves does one action at a time" }];
|
|
161
|
+
if (p.view === "back" && on[0] === "types")
|
|
162
|
+
return [{ path: "types", message: "Chaves types only in the front view" }];
|
|
163
|
+
if (p.view === "back" && on[0] === "holdsSheet")
|
|
164
|
+
return [{ path: "holdsSheet", message: "Chaves holds a sheet only in the front view" }];
|
|
165
|
+
return [];
|
|
166
|
+
};
|
|
167
|
+
/** Chaves, the developer: a `{ }` body with sharp brace points and the cursor in the accent. */
|
|
168
|
+
export const chaves = definePiece("chaves", { ...sharedSchema, types: { kind: "boolean" }, points: { kind: "boolean" }, holdsSheet: { kind: "object", fields: heldSheetSchema } }, drawChaves, chavesRelations);
|