@vectoriox/iox-ui 5.136.0 → 5.138.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/assist-core/index.d.ts +22 -4
- package/composite-core/index.d.ts +10 -2
- package/design-core/index.d.ts +257 -21
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +12 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +29 -5
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +18 -2
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +431 -61
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +999 -259
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +5 -4
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +197 -28
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +538 -11
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +1118 -732
- package/harness-core/index.d.ts +2 -2
- package/index.d.ts +150 -4
- package/package.json +1 -1
- package/scene-core/index.d.ts +69 -13
- package/src/actions-core/element-actions.ts +14 -4
- package/src/assist-core/assist-turn.ts +3 -1
- package/src/assist-core/route-schema.ts +20 -5
- package/src/assist-core/surfaces.ts +12 -0
- package/src/composite-core/header.ts +18 -1
- package/src/design-core/design-settings.ts +14 -3
- package/src/design-core/design-token.model.ts +3 -0
- package/src/design-core/flavor-spec.generated.ts +64 -25
- package/src/design-core/graphemes.ts +16 -0
- package/src/design-core/header-behaviour.ts +20 -2
- package/src/design-core/motion-language.ts +11 -7
- package/src/design-core/node-classes.ts +10 -4
- package/src/design-core/preloader-of.ts +26 -0
- package/src/design-core/preloader.ts +49 -5
- package/src/design-core/public-api.ts +4 -0
- package/src/design-core/scrub.ts +37 -0
- package/src/design-core/section-edge.ts +223 -0
- package/src/design-core/style-presets.ts +2 -0
- package/src/generation-core/body-mix.ts +443 -0
- package/src/generation-core/check-layout.ts +42 -4
- package/src/generation-core/compose-layout.ts +28 -6
- package/src/generation-core/compose-site.ts +26 -8
- package/src/generation-core/header-mix.ts +4 -0
- package/src/generation-core/layout-fingerprint.ts +19 -1
- package/src/generation-core/layout-language.ts +21 -1
- package/src/generation-core/layout-wire.ts +27 -2
- package/src/generation-core/node-baselines.generated.ts +7 -2
- package/src/generation-core/opening-mix.ts +32 -0
- package/src/generation-core/plan-wire.ts +1 -0
- package/src/generation-core/public-api.ts +2 -0
- package/src/generation-core/redesign-run.ts +69 -2
- package/src/generation-core/site-build-run.ts +29 -7
- package/src/generation-core/site-plan.model.ts +2 -0
- package/src/generation-core/site-spec.generated.ts +120 -86
- package/src/generation-core/text-scroll.ts +179 -0
- package/src/generation-core/validate-site-plan.ts +4 -2
- package/src/harness-core/starting-design.ts +6 -5
- package/src/scene-core/scroll-range.ts +4 -0
- package/src/scene-core/split-text.ts +216 -28
- package/styles/iox-design.css +87 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { colorSchemeClass } from './node-classes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A section's EDGE into the section above it, and its SHAPE (award-ingredients plan §7.1d, AW6 — board award-body,
|
|
5
|
+
* AW6-D1…D11). Two content traits on a Section, edited in Bindings ▸ Section edge and stamped by the composer, and ONE
|
|
6
|
+
* answer every renderer applies: the classes below, through design-core's node-class helper (`nodeDesignClasses`), which
|
|
7
|
+
* the shared CSS (`iox-design.css`) paints.
|
|
8
|
+
*
|
|
9
|
+
* - The edge belongs to the LOWER section (AW6-D2): its `::before` — filled with its own ground — rises into the one
|
|
10
|
+
* above by the seam's depth (contract `BODY.seams`, laptop · phone). Nothing moves: the shape is painted, never laid
|
|
11
|
+
* out (`rules.seamPaintsOnly`, R-H16). Two neighbours on the same ground paint nothing visible (AW6-D3).
|
|
12
|
+
* - `rounded` paints the upper section's lower corners away in this section's ground (AW6-D4: the upper looks laid
|
|
13
|
+
* over this one, radius from the table, depth 0).
|
|
14
|
+
* - Drip and torn are asymmetric: a right-to-left section draws them mirrored (AW6-D5, R-H18) — decided HERE from the
|
|
15
|
+
* section's own Text Direction (`iox-seam-mirrored`), never by `:dir(rtl)`: a composed Hebrew page carries its
|
|
16
|
+
* direction as the CSS `direction` of each section (which `:dir()` cannot see), and the builder canvas sits inside the
|
|
17
|
+
* ADMIN's `<html dir>` — a Hebrew admin would mirror an English site's seams.
|
|
18
|
+
* - The shape `card` insets the section from the window with the look's gutter and card radius (AW6-D11); a card takes
|
|
19
|
+
* only Straight or Rounded, and its rounding is its own corners — so a card wears no seam class at all.
|
|
20
|
+
*
|
|
21
|
+
* Framework-free: the composer (generation-core), the builder's panels and both renderers read it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** The seams — the contract's `BODY.ingredients.seam` (generation-core `BodySeam` is this vocabulary). */
|
|
25
|
+
export enum SectionEdge {
|
|
26
|
+
Straight = 'straight',
|
|
27
|
+
Wave = 'wave',
|
|
28
|
+
Drip = 'drip',
|
|
29
|
+
Torn = 'torn',
|
|
30
|
+
Rounded = 'rounded',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A section's shape: edge to edge, or a rounded card on the page's ground (contract `sections.inset-card`). */
|
|
34
|
+
export enum SectionShape {
|
|
35
|
+
Full = 'full',
|
|
36
|
+
Card = 'card',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The content traits (stored in `props`, like `colorScheme`). No default is saved: a section without them is straight and full. */
|
|
40
|
+
export const SECTION_EDGE_TRAIT = 'seam';
|
|
41
|
+
export const SECTION_SHAPE_TRAIT = 'sectionShape';
|
|
42
|
+
|
|
43
|
+
/** The node types that offer an edge and a shape (a Container only as a page's direct child — the panel decides). */
|
|
44
|
+
export const SECTION_EDGE_TYPES: ReadonlyArray<string> = ['Section', 'Container'];
|
|
45
|
+
|
|
46
|
+
/** Every edge in contract order. */
|
|
47
|
+
export const SECTION_EDGES: ReadonlyArray<SectionEdge> = Object.values(SectionEdge);
|
|
48
|
+
|
|
49
|
+
/** The edges a CARD may take (AW6-D11). */
|
|
50
|
+
export const CARD_EDGES: ReadonlyArray<SectionEdge> = [SectionEdge.Straight, SectionEdge.Rounded];
|
|
51
|
+
|
|
52
|
+
/** The asymmetric edges — the ones a right-to-left section draws mirrored (the contract's `mirrors`). */
|
|
53
|
+
export const MIRRORED_EDGES: ReadonlyArray<SectionEdge> = [SectionEdge.Drip, SectionEdge.Torn];
|
|
54
|
+
|
|
55
|
+
export const SEAM_CLASS_PREFIX = 'iox-seam-';
|
|
56
|
+
/** Beside an asymmetric edge's class on a right-to-left section (AW6-D5). */
|
|
57
|
+
export const SEAM_MIRRORED_CLASS = 'iox-seam-mirrored';
|
|
58
|
+
export const SECTION_CARD_CLASS = 'iox-section-card';
|
|
59
|
+
|
|
60
|
+
const EDGE_IDS = new Set<string>(SECTION_EDGES);
|
|
61
|
+
const SHAPE_IDS = new Set<string>(Object.values(SectionShape));
|
|
62
|
+
|
|
63
|
+
/** The node shapes this module reads: a serialized node (`props`) or a builder node (`traits[]`). */
|
|
64
|
+
export interface SectionEdgeSource {
|
|
65
|
+
props?: Readonly<Record<string, unknown>> | null;
|
|
66
|
+
traits?: ReadonlyArray<{ name?: string; default?: unknown }> | null;
|
|
67
|
+
/** A saved node's styles (its Text Direction decides a mirrored seam). */
|
|
68
|
+
styleProps?: Readonly<Record<string, unknown>> | null;
|
|
69
|
+
/** A builder node's styles. */
|
|
70
|
+
styleTraits?: ReadonlyArray<{ traits?: ReadonlyArray<{ name?: string; default?: unknown }> | null }> | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function traitOf(node: SectionEdgeSource | null | undefined, name: string): unknown {
|
|
74
|
+
if (!node) return undefined;
|
|
75
|
+
if (node.props && name in node.props) return node.props[name];
|
|
76
|
+
return node.traits?.find(t => t?.name === name)?.default;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A node's stored edge — Straight for none or anything unknown. */
|
|
80
|
+
export function sectionEdgeOf(node: SectionEdgeSource | null | undefined): SectionEdge {
|
|
81
|
+
const v = traitOf(node, SECTION_EDGE_TRAIT);
|
|
82
|
+
return typeof v === 'string' && EDGE_IDS.has(v) ? v as SectionEdge : SectionEdge.Straight;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A node's stored shape — Full for none or anything unknown. */
|
|
86
|
+
export function sectionShapeOf(node: SectionEdgeSource | null | undefined): SectionShape {
|
|
87
|
+
const v = traitOf(node, SECTION_SHAPE_TRAIT);
|
|
88
|
+
return typeof v === 'string' && SHAPE_IDS.has(v) ? v as SectionShape : SectionShape.Full;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** True when an edge is one a section of `shape` can wear (a card: Straight or Rounded). */
|
|
92
|
+
export function edgeFitsShape(edge: string, shape: string): boolean {
|
|
93
|
+
return shape !== SectionShape.Card || (CARD_EDGES as ReadonlyArray<string>).includes(edge);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `iox-seam-<edge>` for a known, non-straight edge — else null (an unknown word never reaches a class attribute). */
|
|
97
|
+
export function sectionEdgeClass(edge: unknown): string | null {
|
|
98
|
+
return typeof edge === 'string' && edge !== SectionEdge.Straight && EDGE_IDS.has(edge) ? `${SEAM_CLASS_PREFIX}${edge}` : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const RTL = 'rtl';
|
|
102
|
+
/** The Text Direction trait and where it used to live (style-compiler `TEXT_DIRECTION_KEY` / `LEGACY_DIRECTION_KEY`). */
|
|
103
|
+
const DIRECTION_KEYS = ['textDirection', 'direction'];
|
|
104
|
+
|
|
105
|
+
/** True when the section's OWN Text Direction is right-to-left (a saved node's styleProps, a builder node's style
|
|
106
|
+
* traits). A section with no direction of its own reads left-to-right. */
|
|
107
|
+
export function sectionIsRtl(node: SectionEdgeSource | null | undefined): boolean {
|
|
108
|
+
if (!node) return false;
|
|
109
|
+
for (const key of DIRECTION_KEYS) {
|
|
110
|
+
if (node.styleProps && key in node.styleProps) return node.styleProps[key] === RTL;
|
|
111
|
+
}
|
|
112
|
+
for (const group of node.styleTraits ?? []) {
|
|
113
|
+
const t = group?.traits?.find(x => x?.name === DIRECTION_KEYS[0]);
|
|
114
|
+
if (t) return t.default === RTL;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The classes a section renders for its edge and shape: `iox-seam-wave`, `iox-seam-drip iox-seam-mirrored` (a
|
|
121
|
+
* right-to-left section), `iox-section-card`, or `''`. A card wears no seam (its rounding is its own corners); an edge
|
|
122
|
+
* stored on a card that cannot take it is kept and drawn as nothing.
|
|
123
|
+
*/
|
|
124
|
+
export function sectionDesignClasses(node: SectionEdgeSource | null | undefined): string {
|
|
125
|
+
if (sectionShapeOf(node) === SectionShape.Card) return SECTION_CARD_CLASS;
|
|
126
|
+
const edge = sectionEdgeOf(node);
|
|
127
|
+
const cls = sectionEdgeClass(edge);
|
|
128
|
+
if (!cls) return '';
|
|
129
|
+
return MIRRORED_EDGES.includes(edge) && sectionIsRtl(node) ? `${cls} ${SEAM_MIRRORED_CLASS}` : cls;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** True for a class this module writes (so a re-sync removes a stale one). */
|
|
133
|
+
export function isSectionDesignClass(c: string): boolean {
|
|
134
|
+
return c === SECTION_CARD_CLASS || c.startsWith(SEAM_CLASS_PREFIX);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type WritableNode = { props?: Record<string, unknown> | null; traits?: Array<{ name?: string; default?: unknown }> | null };
|
|
138
|
+
|
|
139
|
+
function writeTrait(node: WritableNode | null | undefined, name: string, value: string): boolean {
|
|
140
|
+
if (!node) return false;
|
|
141
|
+
if (Array.isArray(node.traits)) {
|
|
142
|
+
const trait = node.traits.find(t => t?.name === name);
|
|
143
|
+
if (!trait) return false;
|
|
144
|
+
if (trait.default === value) return false;
|
|
145
|
+
trait.default = value;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (node.props?.[name] === value) return false;
|
|
149
|
+
node.props = { ...(node.props ?? {}), [name]: value };
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Write a section's edge — THE one writer (Bindings ▸ Section edge, "every section", the composer). False when
|
|
154
|
+
* nothing changed: an unknown edge, the edge it holds, or a builder node with no such trait. */
|
|
155
|
+
export function setSectionEdge(node: WritableNode | null | undefined, edge: string): boolean {
|
|
156
|
+
if (!EDGE_IDS.has(edge)) return false;
|
|
157
|
+
return writeTrait(node, SECTION_EDGE_TRAIT, edge);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The style props a card shape writes (the look's gutter either side, the card's radius — token references, so a
|
|
161
|
+
* re-theme reaches it), and what Full width puts back. */
|
|
162
|
+
export const SECTION_CARD_STYLES: Readonly<Record<string, string>> = {
|
|
163
|
+
margin: '0px var(--iox-space-gutter) 0px var(--iox-space-gutter)',
|
|
164
|
+
borderRadius: 'var(--iox-card-radius)',
|
|
165
|
+
};
|
|
166
|
+
export const SECTION_FULL_STYLES: Readonly<Record<string, string>> = {
|
|
167
|
+
margin: '0px 0px 0px 0px',
|
|
168
|
+
borderRadius: '0px',
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* What choosing a shape writes, judged against what the section wears now: the trait, and the style props — Card
|
|
173
|
+
* writes {@link SECTION_CARD_STYLES}; Full width puts {@link SECTION_FULL_STYLES} back only where the section still
|
|
174
|
+
* holds the card's own value (an author's margin or radius is theirs and stays). `styles` is `{}` when nothing changes.
|
|
175
|
+
*/
|
|
176
|
+
export function planSectionShape(shape: string, current: Readonly<Record<string, unknown>> = {}): { shape: SectionShape; styles: Record<string, string> } | null {
|
|
177
|
+
if (!SHAPE_IDS.has(shape)) return null;
|
|
178
|
+
const styles: Record<string, string> = {};
|
|
179
|
+
if (shape === SectionShape.Card) {
|
|
180
|
+
for (const [k, v] of Object.entries(SECTION_CARD_STYLES)) if (current[k] !== v) styles[k] = v;
|
|
181
|
+
} else {
|
|
182
|
+
for (const [k, v] of Object.entries(SECTION_FULL_STYLES)) if (current[k] === SECTION_CARD_STYLES[k]) styles[k] = v;
|
|
183
|
+
}
|
|
184
|
+
return { shape: shape as SectionShape, styles };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Write a section's shape trait (the style props are the caller's, from {@link planSectionShape}). */
|
|
188
|
+
export function setSectionShape(node: WritableNode | null | undefined, shape: string): boolean {
|
|
189
|
+
if (!SHAPE_IDS.has(shape)) return false;
|
|
190
|
+
return writeTrait(node, SECTION_SHAPE_TRAIT, shape);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ── The ground under the header (AW6-D10, ink.follows) ──────────────────────────────────────────────────────────────
|
|
194
|
+
|
|
195
|
+
/** A band of the page as the header sees it: its box in the viewport, and the scheme it wears (null = the page's own). */
|
|
196
|
+
export interface GroundBand {
|
|
197
|
+
top: number;
|
|
198
|
+
bottom: number;
|
|
199
|
+
scheme: string | null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The non-default scheme of the band under the header's bottom edge — the 1px line just above `barBottom` — or null
|
|
204
|
+
* (a default band, or nothing there). Pure: the boxes come from the renderer (the window's scroll on the site, the
|
|
205
|
+
* canvas's own driver in the builder). The first band that holds the line wins (bands are the page's sections, in order).
|
|
206
|
+
*/
|
|
207
|
+
export function schemeUnderBar(bands: ReadonlyArray<GroundBand>, barBottom: number): string | null {
|
|
208
|
+
if (!Number.isFinite(barBottom)) return null;
|
|
209
|
+
const line = barBottom - 0.5;
|
|
210
|
+
const hit = bands.find(b => b.top <= line && line < b.bottom);
|
|
211
|
+
return hit && colorSchemeClass(hit.scheme) ? hit.scheme : null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const SCHEME_CLASS = /^iox-scheme-([a-z][a-z0-9-]*)$/;
|
|
215
|
+
|
|
216
|
+
/** The scheme an element wears, read back from its `iox-scheme-<id>` class — null for none. */
|
|
217
|
+
export function schemeOfClasses(classes: Iterable<string> | null | undefined): string | null {
|
|
218
|
+
for (const c of classes ?? []) {
|
|
219
|
+
const m = SCHEME_CLASS.exec(c);
|
|
220
|
+
if (m && colorSchemeClass(m[1])) return m[1];
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
@@ -75,6 +75,8 @@ export function presetChoices(id: string, mode?: DesignMode): DesignChoices | nu
|
|
|
75
75
|
// preloader (PL-D1 — the exit is the preset's, never stored).
|
|
76
76
|
feel: presetMotionLanguage(preset.id)?.arrive, headings: presetMotionLanguage(preset.id)?.move,
|
|
77
77
|
preloader: presetMotionLanguage(preset.id)?.preloader,
|
|
78
|
+
// AW10: its By the scroll (never reads absent).
|
|
79
|
+
scrub: presetMotionLanguage(preset.id)?.scrub,
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { GenerationTier } from './site-plan.model';
|
|
2
|
+
import { LayoutIssue, LayoutIssueCode, LayoutLayer, LayoutLayerKind, LayoutSection, LayoutSectionKind } from './layout-language';
|
|
3
|
+
import { SPEC_SITE_LAYOUT } from './site-spec.generated';
|
|
4
|
+
import { colorSchemeOf, planSectionShape, SECTION_EDGE_TYPES, sectionShapeOf, sectionEdgeClass, SectionShape, setSectionEdge, setSectionShape } from '@vectoriox/iox-ui/design-core';
|
|
5
|
+
import { SerializedNode, walkSerialized } from './serialized-node';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* THE BODY (award-ingredients-plan §3.4, AW6; board award-body): how a site's sections meet (the seam), how their grounds
|
|
9
|
+
* follow one another (the rhythm), the texture laid on a ground (AW7) and the extra kinds of section a site may hold. Every
|
|
10
|
+
* word, its meaning in both languages, whether the product draws it, its tier, each seam's geometry and each rhythm's rule
|
|
11
|
+
* live in ONE table, the contract's `site.layout.body` (layout.mjs `BODY`). This module reads it, mends a mix the site
|
|
12
|
+
* cannot carry (`checkBody`) and judges a composed page's grounds against its rhythm (`rhythmIssues`, run by
|
|
13
|
+
* `checkLayout`). Pure.
|
|
14
|
+
*
|
|
15
|
+
* A seam is PAINTED, never laid out (`rules.seamPaintsOnly`): the LOWER section's ground rises into the one above it as a
|
|
16
|
+
* shape `depth` px tall, under the words; the upper section keeps its words clear of it (`rules.seamKeepsClear`). `rounded`
|
|
17
|
+
* instead lays the upper section over the next with its lower corners at `radius`. A Hebrew page mirrors an asymmetric
|
|
18
|
+
* shape (`mirrors`).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const B = SPEC_SITE_LAYOUT.body as unknown as BodyTable;
|
|
22
|
+
|
|
23
|
+
interface BodySeamGeometry {
|
|
24
|
+
/** px the shape rises — laptop · phone. */
|
|
25
|
+
depth: readonly [number, number];
|
|
26
|
+
/** px of the upper section's lower corners (rounded) — laptop · phone. */
|
|
27
|
+
radius?: readonly [number, number];
|
|
28
|
+
/** An asymmetric shape: a right-to-left page draws it mirrored. */
|
|
29
|
+
mirrors: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface BodyTable {
|
|
33
|
+
ingredients: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
34
|
+
many: ReadonlyArray<string>;
|
|
35
|
+
meanings: Readonly<Record<string, string>>;
|
|
36
|
+
meaningsHe?: Readonly<Record<string, string>>;
|
|
37
|
+
seams: Readonly<Record<string, BodySeamGeometry>>;
|
|
38
|
+
rhythms: {
|
|
39
|
+
free: Record<string, never>;
|
|
40
|
+
alternate: { neighbours: 'differ' };
|
|
41
|
+
'loud-quiet': { pairs: number; quietCols: number };
|
|
42
|
+
chapters: { changesAt: ReadonlyArray<string> };
|
|
43
|
+
tail: { last: number };
|
|
44
|
+
};
|
|
45
|
+
waits: Readonly<Record<string, { phase: string; drawnAs: string | null }>>;
|
|
46
|
+
defaults: Readonly<Record<string, string | ReadonlyArray<string>>>;
|
|
47
|
+
fingerprint: ReadonlyArray<string>;
|
|
48
|
+
rules: Readonly<Record<string, boolean>>;
|
|
49
|
+
tiers: Readonly<Record<string, 'all' | 'pro'>>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The ingredients, by the contract's keys (held equal to it by body-mix.spec). */
|
|
53
|
+
export enum BodyIngredient {
|
|
54
|
+
Seam = 'seam',
|
|
55
|
+
Rhythm = 'rhythm',
|
|
56
|
+
Texture = 'texture',
|
|
57
|
+
Sections = 'sections',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export enum BodySeam { Straight = 'straight', Wave = 'wave', Drip = 'drip', Torn = 'torn', Rounded = 'rounded' }
|
|
61
|
+
export enum BodyRhythm { Free = 'free', Alternate = 'alternate', LoudQuiet = 'loud-quiet', Chapters = 'chapters', Tail = 'tail' }
|
|
62
|
+
export enum BodyTexture { None = 'none', Pattern = 'pattern', Light = 'light', Material = 'material', Grain = 'grain', Lanes = 'lanes' }
|
|
63
|
+
export enum BodySectionWord {
|
|
64
|
+
InsetCard = 'inset-card',
|
|
65
|
+
StickyTitle = 'sticky-title',
|
|
66
|
+
TabsNav = 'tabs-nav',
|
|
67
|
+
Promises = 'promises',
|
|
68
|
+
Table = 'table',
|
|
69
|
+
Timeline = 'timeline',
|
|
70
|
+
Hotspots = 'hotspots',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One word for each of seam, rhythm and texture; a list (in the table's order) of the extra kinds of section. */
|
|
74
|
+
export interface BodyMix {
|
|
75
|
+
seam: string;
|
|
76
|
+
rhythm: string;
|
|
77
|
+
texture: string;
|
|
78
|
+
sections: string[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export class BodyMixError extends Error {}
|
|
82
|
+
|
|
83
|
+
const HEBREW = 'he';
|
|
84
|
+
const INGREDIENTS = B.ingredients;
|
|
85
|
+
const MANY: ReadonlySet<string> = new Set(B.many);
|
|
86
|
+
const WAITS = B.waits;
|
|
87
|
+
const ORDER: ReadonlyArray<BodyIngredient> = Object.values(BodyIngredient);
|
|
88
|
+
|
|
89
|
+
const isMany = (k: string): k is BodyIngredient.Sections => MANY.has(k);
|
|
90
|
+
const listOf = (v: string | ReadonlyArray<string> | undefined): string[] => (v === undefined ? [] : Array.isArray(v) ? [...v] : [v as string]);
|
|
91
|
+
const ordered = (k: string, words: ReadonlyArray<string>): string[] => bodyWords(k as BodyIngredient).filter(w => words.includes(w));
|
|
92
|
+
|
|
93
|
+
/** The words an ingredient may take, in the table's order. */
|
|
94
|
+
export function bodyWords(ingredient: `${BodyIngredient}`): ReadonlyArray<string> {
|
|
95
|
+
return INGREDIENTS[ingredient] ?? [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What a word means — in Hebrew when the builder speaks it. */
|
|
99
|
+
export function bodyMeaning(ingredient: `${BodyIngredient}`, word: string, locale?: string | null): string {
|
|
100
|
+
const key = `${ingredient}.${word}`;
|
|
101
|
+
return (locale === HEBREW ? B.meaningsHe?.[key] : undefined) ?? B.meanings[key] ?? word;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Whether the product draws a word today (a waiting word is listed with its phase, drawn as its stand-in). */
|
|
105
|
+
export function bodyWordDrawn(ingredient: `${BodyIngredient}`, word: string): boolean {
|
|
106
|
+
return bodyWords(ingredient).includes(word) && !WAITS[`${ingredient}.${word}`];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The phase a waiting word waits for, or null. */
|
|
110
|
+
export function bodyWordWaits(ingredient: `${BodyIngredient}`, word: string): string | null {
|
|
111
|
+
return WAITS[`${ingredient}.${word}`]?.phase ?? null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** AW-D23: a word every plan wears (`all`) or one the award tier alone is offered (`pro`). */
|
|
115
|
+
export function bodyWordTier(ingredient: `${BodyIngredient}`, word: string): 'all' | 'pro' {
|
|
116
|
+
return B.tiers[`${ingredient}.${word}`] === 'pro' ? 'pro' : 'all';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** May a build at `tier` wear this word? */
|
|
120
|
+
export function bodyWordOffered(ingredient: `${BodyIngredient}`, word: string, tier: `${GenerationTier}`): boolean {
|
|
121
|
+
return bodyWordTier(ingredient, word) === 'all' || tier === GenerationTier.Award;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A whole mix from part of one: what is not named is the default (straight, free, no texture). Refuses a word the table
|
|
125
|
+
* lacks. */
|
|
126
|
+
export function bodyMix(partial: Partial<Record<string, string | ReadonlyArray<string>>> = {}): BodyMix {
|
|
127
|
+
const mix: BodyMix = {
|
|
128
|
+
seam: B.defaults['seam'] as string, rhythm: B.defaults['rhythm'] as string, texture: B.defaults['texture'] as string,
|
|
129
|
+
sections: listOf(B.defaults['sections']),
|
|
130
|
+
};
|
|
131
|
+
for (const [k, v] of Object.entries(partial)) {
|
|
132
|
+
if (v === undefined) continue;
|
|
133
|
+
if (!INGREDIENTS[k]) throw new BodyMixError(`no body ingredient "${k}"`);
|
|
134
|
+
const words = listOf(v);
|
|
135
|
+
for (const w of words) if (!INGREDIENTS[k].includes(w)) throw new BodyMixError(`a body's ${k} cannot be "${w}" (${INGREDIENTS[k].join(' · ')})`);
|
|
136
|
+
if (isMany(k)) mix[k] = ordered(k, words);
|
|
137
|
+
else if (words.length !== 1) throw new BodyMixError(`a body has one ${k}`);
|
|
138
|
+
else (mix as unknown as Record<string, string>)[k] = words[0];
|
|
139
|
+
}
|
|
140
|
+
return mix;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A mix on the wire: one `<ingredient>:<word>` per word, in the table's order. */
|
|
144
|
+
export function bodyMixWords(mix: BodyMix): string[] {
|
|
145
|
+
return ORDER.flatMap(k => listOf((mix as unknown as Record<string, string | string[]>)[k]).map(w => `${k}:${w}`));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The words back into a mix. Refuses an unknown word and two words for a one-word ingredient. */
|
|
149
|
+
export function bodyMixFromWords(words: ReadonlyArray<string>): BodyMix {
|
|
150
|
+
const partial: Record<string, string[]> = {};
|
|
151
|
+
for (const pair of words) {
|
|
152
|
+
const [k, w] = String(pair).split(':');
|
|
153
|
+
if (!INGREDIENTS[k] || !w) throw new BodyMixError(`"${pair}" is no body word (<ingredient>:<word>)`);
|
|
154
|
+
const got = (partial[k] ??= []);
|
|
155
|
+
if (!isMany(k) && got.length && got[0] !== w) throw new BodyMixError(`a body has one ${k} ("${got[0]}" and "${w}")`);
|
|
156
|
+
if (!got.includes(w)) got.push(w);
|
|
157
|
+
}
|
|
158
|
+
return bodyMix(Object.fromEntries(Object.entries(partial).map(([k, v]) => [k, isMany(k) ? v : v[0]])));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A site plan's body (AW6): its `mixes.body` as a mix, or null — absent or empty, straight seams and free grounds. */
|
|
162
|
+
export function bodyMixOfPlan(plan: { readonly mixes?: { readonly body?: ReadonlyArray<string> } }): BodyMix | null {
|
|
163
|
+
const words = plan.mixes?.body;
|
|
164
|
+
return words?.length ? bodyMixFromWords(words) : null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface BodyGap {
|
|
168
|
+
ingredient: `${BodyIngredient}`;
|
|
169
|
+
word: string;
|
|
170
|
+
phase: string;
|
|
171
|
+
drawnAs: string | null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The mix the product DRAWS today: a waiting word becomes its stand-in (a waiting kind of section is left out), each said. */
|
|
175
|
+
export function drawnBodyMix(mix: BodyMix): { drawn: BodyMix; gaps: BodyGap[] } {
|
|
176
|
+
const drawn: BodyMix = { ...mix, sections: [...mix.sections] };
|
|
177
|
+
const gaps: BodyGap[] = [];
|
|
178
|
+
for (const k of ORDER) {
|
|
179
|
+
if (isMany(k)) {
|
|
180
|
+
drawn[k] = mix[k].filter(w => {
|
|
181
|
+
const wait = WAITS[`${k}.${w}`];
|
|
182
|
+
if (wait) gaps.push({ ingredient: k, word: w, phase: wait.phase, drawnAs: wait.drawnAs });
|
|
183
|
+
return !wait;
|
|
184
|
+
});
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const word = (mix as unknown as Record<string, string>)[k];
|
|
188
|
+
const wait = WAITS[`${k}.${word}`];
|
|
189
|
+
if (!wait) continue;
|
|
190
|
+
gaps.push({ ingredient: k, word, phase: wait.phase, drawnAs: wait.drawnAs });
|
|
191
|
+
(drawn as unknown as Record<string, string>)[k] = wait.drawnAs ?? (B.defaults[k] as string);
|
|
192
|
+
}
|
|
193
|
+
return { drawn, gaps };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The fingerprint's prefix for a body. */
|
|
197
|
+
export const BODY_TOKEN = 'body';
|
|
198
|
+
|
|
199
|
+
/** A body as the fingerprint sees it: `body:<seam>/<rhythm>/<texture>`. */
|
|
200
|
+
export function bodyTokenOf(mix: BodyMix): string {
|
|
201
|
+
return `${BODY_TOKEN}:${B.fingerprint.map(k => (mix as unknown as Record<string, string>)[k]).join('/')}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Every `<ingredient>:<word>` the generator's wire may carry at `tier`: drawn words only, the award tier's only there. */
|
|
205
|
+
export function bodyWireWords(tier: `${GenerationTier}` = GenerationTier.Basic): string[] {
|
|
206
|
+
return ORDER.flatMap(k => bodyWords(k).filter(w => bodyWordDrawn(k, w) && bodyWordOffered(k, w, tier)).map(w => `${k}:${w}`));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── The seam: its geometry, from the table ────────────────────────────────────────────────────────────────────────────
|
|
210
|
+
|
|
211
|
+
export interface BodySeamShape {
|
|
212
|
+
/** px the lower ground rises into the section above. */
|
|
213
|
+
depth: number;
|
|
214
|
+
/** px of the upper section's lower corners (0 = square). */
|
|
215
|
+
radius: number;
|
|
216
|
+
/** Draw it mirrored (an asymmetric shape on a right-to-left page). */
|
|
217
|
+
mirrored: boolean;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** How a seam is drawn at a width and in a direction. An unknown word is the straight seam. */
|
|
221
|
+
export function bodySeamShape(word: string, opts: { phone?: boolean; rtl?: boolean } = {}): BodySeamShape {
|
|
222
|
+
const g = B.seams[word] ?? B.seams[BodySeam.Straight];
|
|
223
|
+
const at = opts.phone ? 1 : 0;
|
|
224
|
+
return { depth: g.depth[at], radius: g.radius?.[at] ?? 0, mirrored: !!opts.rtl && g.mirrors };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The class a section wears for its seam (`iox-seam-<word>`); the straight seam wears none. design-core's
|
|
228
|
+
* `sectionEdgeClass` is the one writer (the renderers' node-class helper); this reads the table's words through it. */
|
|
229
|
+
export function bodySeamClass(word: string | null | undefined): string | null {
|
|
230
|
+
return word && B.seams[word] ? sectionEdgeClass(word) : null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ── The body worn by a composed page (H4: the composer stamps what the palette's Section edge writes) ─────────────────
|
|
234
|
+
|
|
235
|
+
const SCENE_ROLE = 'scene';
|
|
236
|
+
|
|
237
|
+
function holdsScene(node: SerializedNode): boolean {
|
|
238
|
+
let found = false;
|
|
239
|
+
walkSerialized([node], n => { if (n.role === SCENE_ROLE) found = true; });
|
|
240
|
+
return found;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Split a CSS shorthand at its top-level spaces (a `calc()` / `var()` stays whole). */
|
|
244
|
+
function shorthandParts(value: string): string[] {
|
|
245
|
+
const out: string[] = [];
|
|
246
|
+
let depth = 0;
|
|
247
|
+
let cur = '';
|
|
248
|
+
for (const ch of value.trim()) {
|
|
249
|
+
if (ch === '(') depth++;
|
|
250
|
+
if (ch === ')') depth--;
|
|
251
|
+
if (/\s/.test(ch) && depth === 0) { if (cur) out.push(cur); cur = ''; continue; }
|
|
252
|
+
cur += ch;
|
|
253
|
+
}
|
|
254
|
+
if (cur) out.push(cur);
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The padding with its bottom at least `px` (`rules.seamKeepsClear`): `a b max(c, 48px) d`, a px value raised in place. */
|
|
259
|
+
export function paddingKeepingClear(padding: unknown, px: number): string {
|
|
260
|
+
const parts = shorthandParts(typeof padding === 'string' && padding.trim() ? padding : '0px');
|
|
261
|
+
const [top, right = top, bottom = top, left = right] = parts;
|
|
262
|
+
const m = /^(-?\d*\.?\d+)px$/.exec(bottom);
|
|
263
|
+
const kept = m ? (Number(m[1]) >= px ? bottom : `${px}px`) : (bottom.startsWith('max(') && bottom.endsWith(`, ${px}px)`) ? bottom : `max(${bottom}, ${px}px)`);
|
|
264
|
+
return `${top} ${right} ${kept} ${left}`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A composed page wearing the body mix (AW6, H4): the plan's seam on every Section whose ground differs from the one
|
|
269
|
+
* above it (never the first, a Scene or a section holding one — AW6-D11; two equal grounds would draw nothing), the
|
|
270
|
+
* upper's bottom space raised to the seam's depth so its words stay clear (R-H17); `inset-card` makes every later
|
|
271
|
+
* section that wears a scheme a rounded card on the page's ground. A mix with nothing drawn returns the layout as it was
|
|
272
|
+
* (the same array — byte-identical, R-H4). Pure: touched nodes are copied.
|
|
273
|
+
*/
|
|
274
|
+
export function wearBodyMix(layout: ReadonlyArray<SerializedNode>, mix: BodyMix | null | undefined): SerializedNode[] {
|
|
275
|
+
if (!mix) return layout as SerializedNode[];
|
|
276
|
+
const drawn = drawnBodyMix(mix).drawn;
|
|
277
|
+
const cards = drawn.sections.includes(BodySectionWord.InsetCard);
|
|
278
|
+
const seam = drawn.seam;
|
|
279
|
+
if (seam === BodySeam.Straight && !cards) return layout as SerializedNode[];
|
|
280
|
+
const out = layout.map(n => n);
|
|
281
|
+
const depth = bodySeamShape(seam).depth;
|
|
282
|
+
for (let i = 1; i < out.length; i++) {
|
|
283
|
+
const node = out[i];
|
|
284
|
+
if (!SECTION_EDGE_TYPES.includes(node.type) || holdsScene(node)) continue;
|
|
285
|
+
const scheme = colorSchemeOf(node) ?? 'default';
|
|
286
|
+
const above = colorSchemeOf(out[i - 1]) ?? 'default';
|
|
287
|
+
const copy: SerializedNode = { ...node, props: { ...(node.props ?? {}) }, styleProps: { ...(node.styleProps ?? {}) } };
|
|
288
|
+
if (cards && scheme !== 'default') {
|
|
289
|
+
const plan = planSectionShape(SectionShape.Card, copy.styleProps);
|
|
290
|
+
setSectionShape(copy, SectionShape.Card);
|
|
291
|
+
Object.assign(copy.styleProps, plan?.styles ?? {});
|
|
292
|
+
out[i] = copy;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
// A card stands inset on the page's ground: the section under it meets that ground, never the card (D11).
|
|
296
|
+
if (seam === BodySeam.Straight || scheme === above || holdsScene(out[i - 1]) || sectionShapeOf(out[i - 1]) === SectionShape.Card) continue;
|
|
297
|
+
setSectionEdge(copy, seam);
|
|
298
|
+
out[i] = copy;
|
|
299
|
+
if (depth > 0) {
|
|
300
|
+
const upper = out[i - 1];
|
|
301
|
+
out[i - 1] = { ...upper, styleProps: { ...(upper.styleProps ?? {}), padding: paddingKeepingClear(upper.styleProps?.['padding'], depth) } };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ── The check: a mix judged against the site, mended where the site cannot carry it, each mend said ──────────────────
|
|
308
|
+
|
|
309
|
+
export enum BodyRepairCode {
|
|
310
|
+
/** A word the award tier alone wears, on a site built below it. */
|
|
311
|
+
ProOnly = 'pro-only',
|
|
312
|
+
/** A trust or care business (harness `MOTION_CEILINGS.subtle`) never wears a torn or dripping edge: a soft hill. */
|
|
313
|
+
CalmSeam = 'calm-seam',
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The seams a calm business never wears (award plan H1), and the one it wears instead. */
|
|
317
|
+
const LOUD_SEAMS: ReadonlySet<string> = new Set([BodySeam.Torn, BodySeam.Drip]);
|
|
318
|
+
const CALM_SEAM = BodySeam.Wave;
|
|
319
|
+
|
|
320
|
+
export interface BodyRepair {
|
|
321
|
+
code: BodyRepairCode;
|
|
322
|
+
said: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface BodyContext {
|
|
326
|
+
/** AW-D23: the tier the site is built at; absent: the award words are the owner's to choose (the builder). */
|
|
327
|
+
readonly tier?: `${GenerationTier}`;
|
|
328
|
+
/** A trust or care business — the harness's calm motion ceiling (`MOTION_CEILINGS.subtle`). */
|
|
329
|
+
readonly calm?: boolean;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The ONE judge of a body mix against the site. Judges the mix as DRAWN (`drawnBodyMix` first). Never throws. Pure. */
|
|
333
|
+
export function checkBody(mix: BodyMix, ctx: BodyContext = {}): { mix: BodyMix; repairs: BodyRepair[] } {
|
|
334
|
+
const m: BodyMix = { ...mix, sections: [...mix.sections] };
|
|
335
|
+
const repairs: BodyRepair[] = [];
|
|
336
|
+
if (ctx.tier && ctx.tier !== GenerationTier.Award) {
|
|
337
|
+
for (const k of ORDER) {
|
|
338
|
+
if (isMany(k)) {
|
|
339
|
+
const kept = m[k].filter(w => bodyWordTier(k, w) === 'all');
|
|
340
|
+
for (const w of m[k].filter(x => !kept.includes(x))) repairs.push({ code: BodyRepairCode.ProOnly, said: `"${bodyMeaning(k, w)}" comes with the award plan: left out` });
|
|
341
|
+
m[k] = kept;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const word = (m as unknown as Record<string, string>)[k];
|
|
345
|
+
if (bodyWordTier(k, word) === 'all') continue;
|
|
346
|
+
const standIn = B.defaults[k] as string;
|
|
347
|
+
(m as unknown as Record<string, string>)[k] = standIn;
|
|
348
|
+
repairs.push({ code: BodyRepairCode.ProOnly, said: `"${bodyMeaning(k, word)}" comes with the award plan: ${bodyMeaning(k, standIn)} instead` });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (ctx.calm && LOUD_SEAMS.has(m.seam)) {
|
|
352
|
+
repairs.push({ code: BodyRepairCode.CalmSeam, said: `a calm business never wears "${bodyMeaning(BodyIngredient.Seam, m.seam)}": ${bodyMeaning(BodyIngredient.Seam, CALM_SEAM)} instead` });
|
|
353
|
+
m.seam = CALM_SEAM;
|
|
354
|
+
}
|
|
355
|
+
return { mix: m, repairs };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ── The rhythm: a composed page's grounds against the body's rhythm ──────────────────────────────────────────────────
|
|
359
|
+
|
|
360
|
+
/** How a section's ground reads: dark or light (by its colour's luminance), or a photo (free in every rhythm). */
|
|
361
|
+
export enum GroundTone {
|
|
362
|
+
Dark = 'dark',
|
|
363
|
+
Light = 'light',
|
|
364
|
+
Photo = 'photo',
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The luminance where black and white words read equally on a ground (≈ 0.179): above it the ground is light. */
|
|
368
|
+
const TONE_SPLIT = Math.sqrt(1.05 * 0.05) - 0.05;
|
|
369
|
+
|
|
370
|
+
/** A ground's tone from its relative luminance. */
|
|
371
|
+
export function groundToneOf(luminance: number): GroundTone.Dark | GroundTone.Light {
|
|
372
|
+
return luminance > TONE_SPLIT ? GroundTone.Light : GroundTone.Dark;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface RhythmContext {
|
|
376
|
+
/** Each section's ground, as it reads. */
|
|
377
|
+
toneOf: (section: LayoutSection) => GroundTone;
|
|
378
|
+
/** The footer's ground, as it reads; absent: the tail is not judged (the footer's scheme is not known). */
|
|
379
|
+
footerTone?: GroundTone | null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const PICTURED: ReadonlySet<string> = new Set([LayoutLayerKind.Photo, LayoutLayerKind.Gallery, LayoutLayerKind.List, LayoutLayerKind.Marquee]);
|
|
383
|
+
const span = (l: LayoutLayer) => (Array.isArray(l.col) ? l.col[1] - l.col[0] : 0);
|
|
384
|
+
const pictured = (s: LayoutSection) => String(s.ground ?? '').startsWith('photo:') || (s.layers ?? []).some(l => PICTURED.has(l.kind));
|
|
385
|
+
/** A quiet section: words only, centred, every layer within `cols` of the twelve. */
|
|
386
|
+
const quiet = (s: LayoutSection, cols: number) =>
|
|
387
|
+
!pictured(s) && !!(s.layers ?? []).length && (s.layers ?? []).every(l => l.kind === LayoutLayerKind.Shape || (span(l) <= cols && (l.align ?? 'start') === 'center'));
|
|
388
|
+
const startsChapter = (s: LayoutSection, at: ReadonlyArray<string>) =>
|
|
389
|
+
(at.includes('inhale') && s.kind === LayoutSectionKind.Inhale) || (at.includes('signature') && !!s.signature);
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* A composed page's grounds judged against the body's rhythm (`BODY.rhythms`): each issue a `Structure` issue on the page,
|
|
393
|
+
* so the layout request is asked again with it. `free` (and an unknown word) asks nothing. A photo ground is free in
|
|
394
|
+
* `alternate`, `chapters` and `tail`. Pure.
|
|
395
|
+
*/
|
|
396
|
+
export function rhythmIssues(sections: ReadonlyArray<LayoutSection>, rhythm: string | null | undefined, ctx: RhythmContext): LayoutIssue[] {
|
|
397
|
+
const issues: LayoutIssue[] = [];
|
|
398
|
+
const add = (path: string, message: string) => issues.push({ code: LayoutIssueCode.Structure, path, message });
|
|
399
|
+
const tones = sections.map(s => ctx.toneOf(s));
|
|
400
|
+
const R = B.rhythms;
|
|
401
|
+
switch (rhythm) {
|
|
402
|
+
case BodyRhythm.Alternate:
|
|
403
|
+
for (let i = 1; i < sections.length; i++) {
|
|
404
|
+
if (tones[i] !== GroundTone.Photo && tones[i] === tones[i - 1]) {
|
|
405
|
+
add(`sections[${i}].ground`, `grounds alternate dark and light — "${sections[i].id}" is ${tones[i]} like the section before it`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
case BodyRhythm.LoudQuiet: {
|
|
410
|
+
const { pairs, quietCols } = R['loud-quiet'];
|
|
411
|
+
let found = 0;
|
|
412
|
+
for (let i = 1; i < sections.length; i++) if (pictured(sections[i - 1]) && quiet(sections[i], quietCols)) found++;
|
|
413
|
+
if (found < pairs) {
|
|
414
|
+
add('sections', `${found} picture section(s) followed by a quiet one — the loud-quiet rhythm asks at least ${pairs}: a picture section, then words only, centred, within ${quietCols} of the 12 columns`);
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case BodyRhythm.Chapters: {
|
|
419
|
+
const at = R.chapters.changesAt;
|
|
420
|
+
let last: GroundTone | null = null;
|
|
421
|
+
sections.forEach((s, i) => {
|
|
422
|
+
const tone = tones[i];
|
|
423
|
+
if (tone === GroundTone.Photo) return;
|
|
424
|
+
if (last !== null && tone !== last && !startsChapter(s, at)) {
|
|
425
|
+
add(`sections[${i}].ground`, `the ground changes only where a chapter starts (an inhale or the signature) — "${s.id}" changes it`);
|
|
426
|
+
}
|
|
427
|
+
last = tone;
|
|
428
|
+
});
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
case BodyRhythm.Tail: {
|
|
432
|
+
if (!ctx.footerTone || ctx.footerTone === GroundTone.Photo) break;
|
|
433
|
+
const from = Math.max(0, sections.length - R.tail.last);
|
|
434
|
+
for (let i = from; i < sections.length; i++) {
|
|
435
|
+
if (tones[i] !== GroundTone.Photo && tones[i] !== ctx.footerTone) {
|
|
436
|
+
add(`sections[${i}].ground`, `the last ${R.tail.last} sections wear the footer's ${ctx.footerTone} ground — "${sections[i].id}" is ${tones[i]}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return issues;
|
|
443
|
+
}
|