@vectoriox/iox-ui 5.155.0 → 5.157.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/fesm2022/vectoriox-iox-ui-generation-core.mjs +2306 -714
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +5348 -4739
- package/package.json +1 -1
- package/src/generation-core/check-free.ts +375 -0
- package/src/generation-core/compose-site.ts +89 -22
- package/src/generation-core/fallback-memory.ts +2 -2
- package/src/generation-core/free-fallback.ts +139 -0
- package/src/generation-core/free-wire.ts +432 -0
- package/src/generation-core/layout-fingerprint.ts +15 -1
- package/src/generation-core/opening-mix.ts +162 -5
- package/src/generation-core/plan-wire.ts +2 -2
- package/src/generation-core/plan-words.ts +50 -3
- package/src/generation-core/prompt-limits.ts +96 -0
- package/src/generation-core/public-api.ts +5 -0
- package/src/generation-core/site-spec.generated.ts +47 -1
- package/src/generation-core/type-led.ts +435 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayoutPage, LayoutSection, LayoutSectionKind } from './layout-language';
|
|
2
|
-
import { FingerprintedPage, fingerprintOf, LAYOUT_READY_MADE_TOKEN, LayoutFingerprint } from './layout-fingerprint';
|
|
2
|
+
import { FingerprintedPage, fingerprintOf, LAYOUT_READY_MADE_TOKEN, LayoutFingerprint, wornOpenings } from './layout-fingerprint';
|
|
3
3
|
import { footerMixOfPlan } from './footer-mix';
|
|
4
4
|
import { wornHeaderOfPlan } from './header-mix';
|
|
5
5
|
import { PatternNode, patternById, patternNeedsBinding, patternNodes, SITE_LIBRARY, SitePattern } from './patterns';
|
|
@@ -129,7 +129,7 @@ export interface DistinctFallback {
|
|
|
129
129
|
export function distinctFallbackSections(sections: ReadonlyArray<PageSectionPlan>, others: ReadonlyArray<FingerprintedPage>): DistinctFallback {
|
|
130
130
|
const all = [...sections];
|
|
131
131
|
const first = all[0];
|
|
132
|
-
const worn =
|
|
132
|
+
const worn = wornOpenings(others);
|
|
133
133
|
if (!first || !worn.has(readyMadeToken(first.pattern))) return { sections: all, kept: FallbackOpeningKept.Free };
|
|
134
134
|
const family = patternById(first.pattern)?.family;
|
|
135
135
|
if (!family) return { sections: all, kept: FallbackOpeningKept.NoneFree };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { checkFree, FreeIssue, FreeIssueCode, FreeJudgeContext } from './check-free';
|
|
2
|
+
import { FreeNode, FreeNodeType, FreePage, walkFree } from './free-wire';
|
|
3
|
+
import { LayoutIssue, LayoutIssueCode, LayoutLayer, LayoutLayerKind, LayoutPage, LayoutSection } from './layout-language';
|
|
4
|
+
import { fallBackBySection, SectionFallback, SectionSwap } from './layout-section-fallback';
|
|
5
|
+
import { followedAfter, PromptLimit, sectionBreaks } from './prompt-limits';
|
|
6
|
+
import { PageSectionPlan } from './site-plan.model';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* THE FREE PAGE'S SILENT FALL BACK (award plan §11.4 gate 6, R-H7): a free section that still breaks a rule after the
|
|
10
|
+
* one repair is given to the plan's ready-made section for its place — through the ONE `fallBackBySection` (never a copy
|
|
11
|
+
* of its rules: the opening and the close always swap, a middle section takes the best fit by list, form and words or is
|
|
12
|
+
* dropped, a ready-made section that repeats a kept one is never a fit, and a page that still fails falls back whole).
|
|
13
|
+
* This file only ADAPTS: a free section is read as the layout language's section (its words as layers, a list slot as
|
|
14
|
+
* its gallery source, a form slot as a form) so the fit is scored the same way, and the judge it hands over re-runs
|
|
15
|
+
* `checkFree` on the free page the swaps leave. Pure.
|
|
16
|
+
*
|
|
17
|
+
* FS-D47 / R-H20: given the owner's limits (`promptLimitsOf` the reading), the ready-made section is chosen against them
|
|
18
|
+
* and the followed line is rewritten when one had to be used anyway.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** A free judge's issue code, in the layout language's codes (the fall back reads only paths and messages). */
|
|
22
|
+
export const FREE_TO_LAYOUT_CODE: Readonly<Record<FreeIssueCode, LayoutIssueCode>> = {
|
|
23
|
+
[FreeIssueCode.Structure]: LayoutIssueCode.Structure,
|
|
24
|
+
[FreeIssueCode.Words]: LayoutIssueCode.Content,
|
|
25
|
+
[FreeIssueCode.Style]: LayoutIssueCode.Look,
|
|
26
|
+
[FreeIssueCode.Token]: LayoutIssueCode.Look,
|
|
27
|
+
[FreeIssueCode.Phone]: LayoutIssueCode.Structure,
|
|
28
|
+
[FreeIssueCode.Motion]: LayoutIssueCode.Motion,
|
|
29
|
+
[FreeIssueCode.Content]: LayoutIssueCode.Content,
|
|
30
|
+
[FreeIssueCode.Contrast]: LayoutIssueCode.Reading,
|
|
31
|
+
[FreeIssueCode.Prompt]: LayoutIssueCode.Content,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const asLayoutIssue = (i: FreeIssue): LayoutIssue => ({ code: FREE_TO_LAYOUT_CODE[i.code], path: i.path, message: i.message });
|
|
35
|
+
|
|
36
|
+
const WORD_LAYER: Readonly<Partial<Record<FreeNodeType, LayoutLayerKind>>> = {
|
|
37
|
+
[FreeNodeType.Heading]: LayoutLayerKind.Heading,
|
|
38
|
+
[FreeNodeType.Text]: LayoutLayerKind.Text,
|
|
39
|
+
[FreeNodeType.Button]: LayoutLayerKind.Button,
|
|
40
|
+
};
|
|
41
|
+
const AT: Pick<LayoutLayer, 'col' | 'row'> = { col: [1, 1], row: [1, 1] };
|
|
42
|
+
|
|
43
|
+
/** One free node as the layer the fall back's fit reads (words, a list's source, a form), or none. */
|
|
44
|
+
function layerOf(node: FreeNode): LayoutLayer | null {
|
|
45
|
+
const word = WORD_LAYER[node.type];
|
|
46
|
+
if (word) return { kind: word, text: node.text ?? '', ...AT };
|
|
47
|
+
if (node.type === FreeNodeType.Image) return { kind: LayoutLayerKind.Photo, photo: { id: node.src ?? '' }, ...AT };
|
|
48
|
+
if (node.type !== FreeNodeType.Slot) return null;
|
|
49
|
+
const [kind, ref] = String(node.slot ?? '').split(':');
|
|
50
|
+
if (kind === 'list') return { kind: LayoutLayerKind.Gallery, gallery: { slides: [], source: ref }, ...AT };
|
|
51
|
+
if (kind === 'form') return { kind: LayoutLayerKind.Form, form: { preset: ref } as LayoutLayer['form'], ...AT };
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A free section read as a layout section (for the fit only — never stamped). */
|
|
56
|
+
export function freeSectionAsLayout(section: FreeNode): LayoutSection {
|
|
57
|
+
const layers = walkFree([section]).map(w => layerOf(w.node)).filter((l): l is LayoutLayer => !!l);
|
|
58
|
+
return { id: section.id, screens: 1, rows: 1, layers, ...(section.readyMade ? { readyMade: section.readyMade } : {}) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface FreeFallback {
|
|
62
|
+
/** The page as it now stands: kept free sections, ready-made places (`readyMade`), dropped ones gone. */
|
|
63
|
+
page: FreePage;
|
|
64
|
+
swaps: SectionSwap[];
|
|
65
|
+
/** What is left: empty — the page composes. */
|
|
66
|
+
left: FreeIssue[];
|
|
67
|
+
/** Set when the page must be made from sections after all (the shipped last resort, counted). */
|
|
68
|
+
lastResort?: SectionFallback['lastResort'];
|
|
69
|
+
/** FS-D47: the owner's limits a ready-made section on the page breaks (said in the followed line), by count. */
|
|
70
|
+
unfollowed?: Partial<Record<PromptLimit, number>>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** What the owner's prompt ruled out, and the site's language for the followed line (FS-D47, R-H20). */
|
|
74
|
+
export interface FreeFallbackPrompt {
|
|
75
|
+
limits: ReadonlyArray<PromptLimit>;
|
|
76
|
+
language?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Give each free section the issues name to the plan's ready-made section, then judge once more. `plan` is the page's
|
|
81
|
+
* ready-made sections (`PagePlan.sections`), in order; `issues` what `checkFree` still finds after the one repair.
|
|
82
|
+
* With the owner's limits (FS-D47), the fall back first chooses only among sections that honour them — a middle place
|
|
83
|
+
* nothing honest fits is dropped where the page's minimums allow; only when that fails is the closest section used, and
|
|
84
|
+
* the followed line then says which of the owner's words the page no longer follows.
|
|
85
|
+
*/
|
|
86
|
+
export function fallBackFree(page: FreePage, plan: ReadonlyArray<PageSectionPlan>, issues: ReadonlyArray<FreeIssue>, ctx: FreeJudgeContext, prompt?: FreeFallbackPrompt): FreeFallback {
|
|
87
|
+
const limits = prompt?.limits ?? [];
|
|
88
|
+
const lastAt = plan.length - 1;
|
|
89
|
+
const honest = plan.map((_, i) => i).filter(i => i === 0 || i === lastAt || !sectionBreaks(plan[i], limits).length);
|
|
90
|
+
const first = limits.length && honest.length < plan.length ? fallBackOn(page, plan, honest, issues, ctx) : null;
|
|
91
|
+
const done = first && !first.lastResort ? first : fallBackOn(page, plan, plan.map((_, i) => i), issues, ctx);
|
|
92
|
+
if (done.lastResort || !limits.length) return done;
|
|
93
|
+
const broken = new Map<PromptLimit, number>();
|
|
94
|
+
for (const s of done.page.sections) {
|
|
95
|
+
if (s.readyMade) for (const l of sectionBreaks(plan[s.readyMade.at], limits)) broken.set(l, (broken.get(l) ?? 0) + 1);
|
|
96
|
+
}
|
|
97
|
+
if (!broken.size) return done;
|
|
98
|
+
return {
|
|
99
|
+
...done,
|
|
100
|
+
page: { ...done.page, read: { ...done.page.read, followed: followedAfter(done.page.read.followed, broken, prompt?.language) } },
|
|
101
|
+
unfollowed: Object.fromEntries(broken),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The ONE fall back over the plan sections `use` (by their index in `plan`); ready-made places name the FULL plan. */
|
|
106
|
+
function fallBackOn(page: FreePage, plan: ReadonlyArray<PageSectionPlan>, use: ReadonlyArray<number>, issues: ReadonlyArray<FreeIssue>, ctx: FreeJudgeContext): FreeFallback {
|
|
107
|
+
const byId = new Map(page.sections.map(s => [s.id, s]));
|
|
108
|
+
const real = (at: number) => use[at] ?? at;
|
|
109
|
+
const toFree = (layout: LayoutPage): FreePage => ({
|
|
110
|
+
...page,
|
|
111
|
+
sections: layout.sections.map(s => {
|
|
112
|
+
const was = byId.get(s.id)!;
|
|
113
|
+
return s.readyMade && !was.readyMade
|
|
114
|
+
? { id: s.id, type: FreeNodeType.Section, styleProps: {}, readyMade: { at: real(s.readyMade.at), pattern: s.readyMade.pattern } }
|
|
115
|
+
: was;
|
|
116
|
+
}),
|
|
117
|
+
});
|
|
118
|
+
// A place already ready-made names the FULL plan; the fall back reads it against the plan it is given.
|
|
119
|
+
const asGiven = (section: FreeNode): LayoutSection => {
|
|
120
|
+
const layout = freeSectionAsLayout(section);
|
|
121
|
+
return layout.readyMade ? { ...layout, readyMade: { ...layout.readyMade, at: use.indexOf(layout.readyMade.at) } } : layout;
|
|
122
|
+
};
|
|
123
|
+
let last: FreeIssue[] = [...issues];
|
|
124
|
+
const judged = fallBackBySection(
|
|
125
|
+
{ dial: 'distinct', sections: page.sections.map(asGiven) },
|
|
126
|
+
use.map(i => plan[i]),
|
|
127
|
+
issues.map(asLayoutIssue),
|
|
128
|
+
layout => {
|
|
129
|
+
last = checkFree(toFree(layout), ctx);
|
|
130
|
+
return { page: layout, issues: last.map(asLayoutIssue) };
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
return {
|
|
134
|
+
page: toFree(judged.page),
|
|
135
|
+
swaps: judged.swaps.map(w => (w.readyMade ? { ...w, readyMade: { ...w.readyMade, at: real(w.readyMade.at) } } : w)),
|
|
136
|
+
left: judged.left.length ? last : [],
|
|
137
|
+
...(judged.lastResort ? { lastResort: judged.lastResort } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { JsonSchema, jsonClosedObject, jsonInteger, jsonListOf, jsonOneOf, jsonText } from './json-schema';
|
|
2
|
+
import { isPlainObject, PlainObject } from './shape-check';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* THE FREE SECTION (award-ingredients plan §11.4, FS3; FS-D15…FS-D18). A free page is ordinary builder-shaped nodes the
|
|
6
|
+
* model writes itself — Section, Container, Heading, Text, Button, Image, Video — each with styles, a phone layer, a hover
|
|
7
|
+
* and ONE move, plus SLOTS where a recipe stands (a list bound to content, a form): the model places a slot and never
|
|
8
|
+
* writes a Repeater or a Form (FS-T1). The look's values stay the look's (tokens only, `checkFree`); layout, overlap,
|
|
9
|
+
* turn, clip and size are free.
|
|
10
|
+
*
|
|
11
|
+
* It is ASKED as the strict FLAT wire (FS-D17): one list of nodes, every key required, no optional key, no union, no
|
|
12
|
+
* recursion, styles as `"<property>:<value>"` strings — 23 properties, held by `strictSchemaComplexity` — so a parse
|
|
13
|
+
* failure cannot happen. `expandFreeWire` turns it into the free tree (`FreePage`) the judge reads; `freeToWire` writes a
|
|
14
|
+
* tree back (fixtures, a repair's starting point); `freeWireIssue` says a judge's tree path in the wire's own words.
|
|
15
|
+
* The page is written in ONE language: the site's. Every enum is generated from THIS request (R-H2): the material ids,
|
|
16
|
+
* the slots, the pages. Pure. The prototype's copy is `prototypes/breaking-limits/code/flat5.mjs` (FS-D48 measured it).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** What a free node is. `Button` is stamped as the builder's ButtonBlock; a `Slot` is a recipe placed by name. */
|
|
20
|
+
export enum FreeNodeType {
|
|
21
|
+
Section = 'Section',
|
|
22
|
+
Container = 'Container',
|
|
23
|
+
Heading = 'Heading',
|
|
24
|
+
Text = 'Text',
|
|
25
|
+
Button = 'Button',
|
|
26
|
+
Image = 'Image',
|
|
27
|
+
Video = 'Video',
|
|
28
|
+
Slot = 'Slot',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The node types that carry words. */
|
|
32
|
+
export const FREE_WORD_TYPES: ReadonlyArray<FreeNodeType> = [FreeNodeType.Heading, FreeNodeType.Text, FreeNodeType.Button];
|
|
33
|
+
/** The node types that hold children. */
|
|
34
|
+
export const FREE_HOLDERS: ReadonlyArray<FreeNodeType> = [FreeNodeType.Section, FreeNodeType.Container];
|
|
35
|
+
|
|
36
|
+
/** What a free section is for — the fall back picks the ready-made section of the same place by it. */
|
|
37
|
+
export enum FreePurpose {
|
|
38
|
+
Opening = 'opening',
|
|
39
|
+
Videos = 'videos',
|
|
40
|
+
Products = 'products',
|
|
41
|
+
Work = 'work',
|
|
42
|
+
About = 'about',
|
|
43
|
+
Offer = 'offer',
|
|
44
|
+
Proof = 'proof',
|
|
45
|
+
Process = 'process',
|
|
46
|
+
Contact = 'contact',
|
|
47
|
+
Closing = 'closing',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The look's element styles a free node may wear, by type — a closed list (the contract has more, e.g. accordion parts,
|
|
52
|
+
* which belong to their recipes). A word node wears one and changes what it needs on top. The spec holds each id to the
|
|
53
|
+
* contract's `appliesTo` (`elementStylesFor`).
|
|
54
|
+
*/
|
|
55
|
+
export const FREE_ELEMENT_STYLES: Readonly<Partial<Record<FreeNodeType, ReadonlyArray<string>>>> = {
|
|
56
|
+
[FreeNodeType.Section]: ['section'],
|
|
57
|
+
[FreeNodeType.Container]: ['box', 'card', 'panel'],
|
|
58
|
+
[FreeNodeType.Heading]: ['display', 'h1', 'h2', 'h3', 'eyebrow'],
|
|
59
|
+
[FreeNodeType.Text]: ['lead', 'body', 'small', 'eyebrow'],
|
|
60
|
+
[FreeNodeType.Button]: ['button-primary', 'button-secondary', 'button-ghost'],
|
|
61
|
+
[FreeNodeType.Image]: ['media'],
|
|
62
|
+
[FreeNodeType.Video]: ['media'],
|
|
63
|
+
};
|
|
64
|
+
/** The builder type each free type is stamped as (and whose element styles it may wear). */
|
|
65
|
+
export const FREE_BUILDER_TYPE: Readonly<Record<FreeNodeType, string>> = {
|
|
66
|
+
[FreeNodeType.Section]: 'Section',
|
|
67
|
+
[FreeNodeType.Container]: 'Container',
|
|
68
|
+
[FreeNodeType.Heading]: 'Heading',
|
|
69
|
+
[FreeNodeType.Text]: 'Text',
|
|
70
|
+
[FreeNodeType.Button]: 'ButtonBlock',
|
|
71
|
+
[FreeNodeType.Image]: 'Image',
|
|
72
|
+
[FreeNodeType.Video]: 'Video',
|
|
73
|
+
[FreeNodeType.Slot]: 'Container',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** The one role a free node may carry: the heading a visitor reads first. */
|
|
77
|
+
export const FREE_LEAD_ROLE = 'lead';
|
|
78
|
+
|
|
79
|
+
/** How a page treats its pictures — ONE word, recorded and shown (R-H8: information, never a gate). */
|
|
80
|
+
export enum FreePictures {
|
|
81
|
+
UniformGrid = 'uniform-grid',
|
|
82
|
+
EqualSquares = 'equal-squares',
|
|
83
|
+
OneFormat = 'one-format',
|
|
84
|
+
SingleLarge = 'single-large',
|
|
85
|
+
FullBleed = 'full-bleed',
|
|
86
|
+
Mixed = 'mixed',
|
|
87
|
+
None = 'none',
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The product's breakpoints a free style layer is written at (`style-compiler/responsive.ts`): the wire asks two. */
|
|
91
|
+
export enum FreeLayer {
|
|
92
|
+
Phone = 'mobile',
|
|
93
|
+
Tablet = 'tablet',
|
|
94
|
+
}
|
|
95
|
+
/** Layers a phone in portrait reaches (a `mobile` layer reaches `small` by the cascade). */
|
|
96
|
+
export const FREE_PHONE_LAYERS: ReadonlyArray<string> = ['mobile', 'small'];
|
|
97
|
+
|
|
98
|
+
/** What triggers a free node's ONE move. */
|
|
99
|
+
export enum FreeTrigger {
|
|
100
|
+
Enter = 'viewportEnter',
|
|
101
|
+
Scroll = 'scrollProgress',
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The moves a free node may make — the product's own action words (actions-core `ELEMENT_ACTION_DESCRIPTORS`), each with
|
|
105
|
+
* the one parameter the wire may set. A hover is a style state, never a move.
|
|
106
|
+
*/
|
|
107
|
+
export const FREE_MOVES: Readonly<Record<FreeTrigger, Readonly<Record<string, Readonly<{ param?: string; values?: ReadonlyArray<string> }>>>>> = {
|
|
108
|
+
[FreeTrigger.Enter]: {
|
|
109
|
+
fadeIn: {},
|
|
110
|
+
moveUp: {},
|
|
111
|
+
blurIn: {},
|
|
112
|
+
zoomOut: {},
|
|
113
|
+
clipReveal: { param: 'from', values: ['start', 'end', 'top', 'bottom', 'centre'] },
|
|
114
|
+
revealText: { param: 'by', values: ['line', 'word'] },
|
|
115
|
+
countUp: {},
|
|
116
|
+
},
|
|
117
|
+
[FreeTrigger.Scroll]: {
|
|
118
|
+
parallax: { param: 'depth', values: ['back', 'front'] },
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** One move, as the free tree holds it. */
|
|
123
|
+
export interface FreeMove {
|
|
124
|
+
trigger: FreeTrigger;
|
|
125
|
+
action: string;
|
|
126
|
+
params?: Record<string, string>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type FreeStyle = Record<string, string>;
|
|
130
|
+
|
|
131
|
+
/** One node of the free tree. */
|
|
132
|
+
export interface FreeNode {
|
|
133
|
+
id: string;
|
|
134
|
+
type: FreeNodeType;
|
|
135
|
+
/** A Section: what it is for. */
|
|
136
|
+
purpose?: FreePurpose;
|
|
137
|
+
elementStyle?: string;
|
|
138
|
+
/** A Heading: 1–4. */
|
|
139
|
+
level?: number;
|
|
140
|
+
role?: typeof FREE_LEAD_ROLE;
|
|
141
|
+
/** The words, in the site's language. */
|
|
142
|
+
text?: string;
|
|
143
|
+
/** An Image / Video: a material id. */
|
|
144
|
+
src?: string;
|
|
145
|
+
/** A Button: a page route of the site, or `#<section id>`. */
|
|
146
|
+
href?: string;
|
|
147
|
+
/** A Slot: what stands here (`list:<alias>`, `form:<preset>`). */
|
|
148
|
+
slot?: string;
|
|
149
|
+
/** A Slot's options (a list's mix words, `arrange:grid`). */
|
|
150
|
+
opts?: string[];
|
|
151
|
+
styleProps: FreeStyle;
|
|
152
|
+
responsive?: Partial<Record<FreeLayer, FreeStyle>>;
|
|
153
|
+
hover?: FreeStyle;
|
|
154
|
+
move?: FreeMove;
|
|
155
|
+
children?: FreeNode[];
|
|
156
|
+
/** Set by the fall back: the plan's ready-made section stands here instead (its index in the page plan, its pattern). */
|
|
157
|
+
readyMade?: { at: number; pattern: string };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What the answer says about itself — `followed` quotes the owner's words (§11.4a, R-H17). */
|
|
161
|
+
export interface FreeRead {
|
|
162
|
+
idea: string;
|
|
163
|
+
why: string;
|
|
164
|
+
followed: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface FreePage {
|
|
168
|
+
read: FreeRead;
|
|
169
|
+
pictures: string;
|
|
170
|
+
sections: FreeNode[];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The wire's node keys, in the order a model writes them. Every one is required. */
|
|
174
|
+
export const FREE_WIRE_NODE_KEYS = [
|
|
175
|
+
'id', 'parent', 'type', 'purpose', 'style', 'level', 'role', 'text', 'src', 'href', 'slot', 'opts', 'base', 'phone', 'tablet', 'hover', 'motion',
|
|
176
|
+
] as const;
|
|
177
|
+
export type FreeWireNode = {
|
|
178
|
+
id: string; parent: string; type: string; purpose: string; style: string; level: number; role: string; text: string; src: string;
|
|
179
|
+
href: string; slot: string; opts: string[]; base: string[]; phone: string[]; tablet: string[]; hover: string[]; motion: string;
|
|
180
|
+
};
|
|
181
|
+
export interface FreeWire {
|
|
182
|
+
read: FreeRead;
|
|
183
|
+
pictures: string;
|
|
184
|
+
nodes: FreeWireNode[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface FreeWireOptions {
|
|
188
|
+
/** The material the page may place, by id (R-H2): the owner's photos and videos. */
|
|
189
|
+
material?: ReadonlyArray<string>;
|
|
190
|
+
/** The slots this page may place (`list:<alias>`, `form:<preset>`) — generated from the plan. */
|
|
191
|
+
slots?: ReadonlyArray<string>;
|
|
192
|
+
/** The site's language, named in the descriptions (`en`, `he`). */
|
|
193
|
+
language?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const SEP = ':';
|
|
197
|
+
const NONE = 'none';
|
|
198
|
+
const ENTER = 'enter';
|
|
199
|
+
const SCROLL = 'scroll';
|
|
200
|
+
const TRIGGER_WORD: Readonly<Record<FreeTrigger, string>> = { [FreeTrigger.Enter]: ENTER, [FreeTrigger.Scroll]: SCROLL };
|
|
201
|
+
|
|
202
|
+
/** Every move word the wire offers: `none`, `enter:<action>[:<value>]`, `scroll:parallax:<depth>`. */
|
|
203
|
+
export function freeMoveWords(): string[] {
|
|
204
|
+
const out = [NONE];
|
|
205
|
+
for (const trigger of Object.values(FreeTrigger)) {
|
|
206
|
+
for (const [action, spec] of Object.entries(FREE_MOVES[trigger])) {
|
|
207
|
+
if (spec.values?.length) for (const v of spec.values) out.push([TRIGGER_WORD[trigger], action, v].join(SEP));
|
|
208
|
+
else out.push([TRIGGER_WORD[trigger], action].join(SEP));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const FREE_STYLE_WORDS: ReadonlyArray<string> = [...new Set(Object.values(FREE_ELEMENT_STYLES).flat() as string[])];
|
|
215
|
+
|
|
216
|
+
const text = (d: string) => ({ ...jsonText(), description: d });
|
|
217
|
+
const oneOf = (values: ReadonlyArray<string>, d: string) => ({ ...jsonOneOf(values), description: d });
|
|
218
|
+
const strings = (d: string) => ({ ...jsonListOf(jsonText()), description: d });
|
|
219
|
+
const closed = (properties: Record<string, JsonSchema>, d?: string) => jsonClosedObject(properties, Object.keys(properties), d);
|
|
220
|
+
|
|
221
|
+
/** The strict format of ONE free page (FS-D17): 23 properties, 0 optional, 0 unions. */
|
|
222
|
+
export function freeWireJsonSchema(options: FreeWireOptions = {}): JsonSchema {
|
|
223
|
+
const lang = options.language ?? 'the site\'s language';
|
|
224
|
+
const node = closed({
|
|
225
|
+
id: text('unique kebab-case id'),
|
|
226
|
+
parent: text("the id of the Section or Container it sits in; '' for a Section (the top of the page). A parent is written before its children; siblings in reading order"),
|
|
227
|
+
type: oneOf(Object.values(FreeNodeType), 'what the node is'),
|
|
228
|
+
purpose: oneOf(['', ...Object.values(FreePurpose)], "a Section: what it is for; '' for every other node"),
|
|
229
|
+
style: oneOf(['', ...FREE_STYLE_WORDS], "the look's element style it wears (a Heading, Text and Button always wear one); '' for none"),
|
|
230
|
+
level: { ...jsonInteger(), description: 'a Heading: 1–4 (exactly one 1 on the page); 0 for other nodes' },
|
|
231
|
+
role: oneOf(['', FREE_LEAD_ROLE], "'lead' on the heading a visitor reads first (in the first section); '' otherwise"),
|
|
232
|
+
text: text(`the words (Heading, Text, Button), in ${lang}; '' for none`),
|
|
233
|
+
src: oneOf(['', ...(options.material ?? [])], "an Image / Video: an id from the material; '' for none"),
|
|
234
|
+
href: text("a Button: a page route of the site or '#<section id>'; '' for none"),
|
|
235
|
+
slot: oneOf(['', ...(options.slots ?? [])], "a Slot: the part that stands here, placed and never built; '' for none"),
|
|
236
|
+
opts: strings("a list Slot: how its items are shown, '<ingredient>:<word>'; [] for none"),
|
|
237
|
+
base: strings("styles at every width, each '<property>:<value>' (camelCase, one plain value; a size relative to the width is cqi, never vw); [] for none"),
|
|
238
|
+
phone: strings("the phone layer (≤ 767px), '<property>:<value>'; [] for none"),
|
|
239
|
+
tablet: strings("the tablet layer (≤ 991px), '<property>:<value>'; [] for none"),
|
|
240
|
+
hover: strings("on hover, '<property>:<value>' — transform, opacity or a colour token only; [] for none"),
|
|
241
|
+
motion: oneOf(freeMoveWords(), 'its ONE entrance or scroll move, or none'),
|
|
242
|
+
});
|
|
243
|
+
return closed({
|
|
244
|
+
read: closed({
|
|
245
|
+
idea: text("one line: the page's idea"),
|
|
246
|
+
why: text('one line: why it suits this owner'),
|
|
247
|
+
followed: text(`ONE line the owner can read, in ${lang}: which of THEIR words this page followed, quoting them as written`),
|
|
248
|
+
}),
|
|
249
|
+
pictures: oneOf(Object.values(FreePictures), 'how the page treats its pictures, one word'),
|
|
250
|
+
nodes: jsonListOf(node),
|
|
251
|
+
}, 'one free page, flat');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A problem found while reading the wire: said in the wire's own words (`nodes[4] ("hero-title")`). */
|
|
255
|
+
export interface FreeWireFault {
|
|
256
|
+
path: string;
|
|
257
|
+
message: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const str = (v: unknown): string => (typeof v === 'string' ? v : '');
|
|
261
|
+
const list = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : []);
|
|
262
|
+
const nodeAt = (i: number, id: string) => `nodes[${i}]${id ? ` ("${id}")` : ''}`;
|
|
263
|
+
|
|
264
|
+
/** `["fontSize:4rem", …]` → a style map, split at each line's FIRST colon; a line with none is a fault. */
|
|
265
|
+
function styleOf(lines: unknown, at: string, faults: FreeWireFault[]): FreeStyle {
|
|
266
|
+
const out: FreeStyle = {};
|
|
267
|
+
list(lines).forEach((line, k) => {
|
|
268
|
+
const i = line.indexOf(SEP);
|
|
269
|
+
if (i <= 0) faults.push({ path: `${at}[${k}]`, message: `"${line}" — write each style as <property>:<value>` });
|
|
270
|
+
else out[line.slice(0, i).trim()] = line.slice(i + 1).trim();
|
|
271
|
+
});
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** `enter:clipReveal:start` → a move; `none`, or a word the format does not hold, → none. */
|
|
276
|
+
export function freeMoveOf(word: string): FreeMove | null {
|
|
277
|
+
const [where, action, value] = String(word ?? '').split(SEP);
|
|
278
|
+
const trigger = (Object.keys(TRIGGER_WORD) as FreeTrigger[]).find(t => TRIGGER_WORD[t] === where);
|
|
279
|
+
const spec = trigger ? FREE_MOVES[trigger][action] : undefined;
|
|
280
|
+
if (!trigger || !spec) return null;
|
|
281
|
+
return { trigger, action, ...(spec.param && value ? { params: { [spec.param]: value } } : {}) };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** A move → its wire word. */
|
|
285
|
+
export function freeMoveWord(move: FreeMove | null | undefined): string {
|
|
286
|
+
if (!move) return NONE;
|
|
287
|
+
const value = Object.values(move.params ?? {})[0];
|
|
288
|
+
return [TRIGGER_WORD[move.trigger], move.action, ...(value ? [value] : [])].join(SEP);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface ExpandedFreeWire {
|
|
292
|
+
page: FreePage;
|
|
293
|
+
/** Each tree path (`sections[0].children[1]`) → the wire node it came from (its index in `nodes`). */
|
|
294
|
+
paths: Record<string, number>;
|
|
295
|
+
faults: FreeWireFault[];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The wire → the free tree. A node whose parent is not written before it, a top node that is not a Section, a child of a
|
|
300
|
+
* node that holds none, a repeated id — each is a FAULT and the node is left out: never guessed, never repaired here.
|
|
301
|
+
*/
|
|
302
|
+
export function expandFreeWire(wire: unknown): ExpandedFreeWire {
|
|
303
|
+
const faults: FreeWireFault[] = [];
|
|
304
|
+
const w: PlainObject = isPlainObject(wire) ? wire : {};
|
|
305
|
+
const read: PlainObject = isPlainObject(w['read']) ? w['read'] : {};
|
|
306
|
+
const sections: FreeNode[] = [];
|
|
307
|
+
const made = new Map<string, FreeNode>();
|
|
308
|
+
const pathOf = new Map<FreeNode, string>();
|
|
309
|
+
const paths: Record<string, number> = {};
|
|
310
|
+
(Array.isArray(w['nodes']) ? w['nodes'] : []).forEach((raw: unknown, i: number) => {
|
|
311
|
+
if (!isPlainObject(raw)) { faults.push({ path: `nodes[${i}]`, message: 'not a node' }); return; }
|
|
312
|
+
const id = str(raw['id']);
|
|
313
|
+
const at = nodeAt(i, id);
|
|
314
|
+
const type = str(raw['type']) as FreeNodeType;
|
|
315
|
+
if (!Object.values(FreeNodeType).includes(type)) { faults.push({ path: at, message: `"${type}" is not a node type — ${Object.values(FreeNodeType).join(', ')}` }); return; }
|
|
316
|
+
if (!id || made.has(id)) { faults.push({ path: at, message: id ? `the id "${id}" is used twice` : 'every node needs its own id' }); return; }
|
|
317
|
+
const node: FreeNode = { id, type, styleProps: styleOf(raw['base'], `${at}.base`, faults) };
|
|
318
|
+
if (type === FreeNodeType.Section) node.purpose = str(raw['purpose']) as FreePurpose;
|
|
319
|
+
if (str(raw['style'])) node.elementStyle = str(raw['style']);
|
|
320
|
+
if (type === FreeNodeType.Heading) node.level = typeof raw['level'] === 'number' ? raw['level'] : 0;
|
|
321
|
+
if (str(raw['role'])) node.role = str(raw['role']) as typeof FREE_LEAD_ROLE;
|
|
322
|
+
if (FREE_WORD_TYPES.includes(type)) node.text = str(raw['text']);
|
|
323
|
+
if (str(raw['src'])) node.src = str(raw['src']);
|
|
324
|
+
if (type === FreeNodeType.Button) node.href = str(raw['href']);
|
|
325
|
+
if (type === FreeNodeType.Slot) {
|
|
326
|
+
node.slot = str(raw['slot']);
|
|
327
|
+
node.opts = list(raw['opts']);
|
|
328
|
+
}
|
|
329
|
+
const responsive: Partial<Record<FreeLayer, FreeStyle>> = {};
|
|
330
|
+
for (const [key, layer] of [['phone', FreeLayer.Phone], ['tablet', FreeLayer.Tablet]] as const) {
|
|
331
|
+
const style = styleOf(raw[key], `${at}.${key}`, faults);
|
|
332
|
+
if (Object.keys(style).length) responsive[layer] = style;
|
|
333
|
+
}
|
|
334
|
+
if (Object.keys(responsive).length) node.responsive = responsive;
|
|
335
|
+
const hover = styleOf(raw['hover'], `${at}.hover`, faults);
|
|
336
|
+
if (Object.keys(hover).length) node.hover = hover;
|
|
337
|
+
const motion = str(raw['motion']);
|
|
338
|
+
const move = freeMoveOf(motion);
|
|
339
|
+
if (move) node.move = move;
|
|
340
|
+
else if (motion && motion !== NONE) faults.push({ path: `${at}.motion`, message: `"${motion}" is not a move — ${freeMoveWords().join(', ')}` });
|
|
341
|
+
|
|
342
|
+
const parentId = str(raw['parent']);
|
|
343
|
+
if (!parentId) {
|
|
344
|
+
if (type !== FreeNodeType.Section) { faults.push({ path: at, message: 'only a Section sits at the top of the page — give it a parent' }); return; }
|
|
345
|
+
pathOf.set(node, `sections[${sections.length}]`);
|
|
346
|
+
sections.push(node);
|
|
347
|
+
} else {
|
|
348
|
+
const parent = made.get(parentId);
|
|
349
|
+
if (!parent) { faults.push({ path: at, message: `its parent "${parentId}" is not written before it` }); return; }
|
|
350
|
+
if (!FREE_HOLDERS.includes(parent.type)) { faults.push({ path: at, message: `a ${parent.type} holds no children` }); return; }
|
|
351
|
+
if (type === FreeNodeType.Section) { faults.push({ path: at, message: 'a Section sits at the top of the page only — use a Container inside' }); return; }
|
|
352
|
+
(parent.children ??= []).push(node);
|
|
353
|
+
pathOf.set(node, `${pathOf.get(parent)}.children[${parent.children.length - 1}]`);
|
|
354
|
+
}
|
|
355
|
+
made.set(id, node);
|
|
356
|
+
paths[pathOf.get(node)!] = i;
|
|
357
|
+
});
|
|
358
|
+
const page: FreePage = {
|
|
359
|
+
read: { idea: str(read['idea']), why: str(read['why']), followed: str(read['followed']) },
|
|
360
|
+
pictures: str(w['pictures']),
|
|
361
|
+
sections,
|
|
362
|
+
};
|
|
363
|
+
return { page, paths, faults };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Every node of a free page with its tree path, its section's index and its ancestors (outermost first). */
|
|
367
|
+
export interface FreeWalked {
|
|
368
|
+
node: FreeNode;
|
|
369
|
+
path: string;
|
|
370
|
+
section: number;
|
|
371
|
+
up: FreeNode[];
|
|
372
|
+
}
|
|
373
|
+
export function walkFree(sections: ReadonlyArray<FreeNode>): FreeWalked[] {
|
|
374
|
+
const out: FreeWalked[] = [];
|
|
375
|
+
const visit = (node: FreeNode, path: string, section: number, up: FreeNode[]) => {
|
|
376
|
+
out.push({ node, path, section, up });
|
|
377
|
+
(node.children ?? []).forEach((c, i) => visit(c, `${path}.children[${i}]`, section, [...up, node]));
|
|
378
|
+
};
|
|
379
|
+
sections.forEach((s, i) => visit(s, `sections[${i}]`, i, []));
|
|
380
|
+
return out;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const lines = (style: FreeStyle | undefined): string[] => Object.entries(style ?? {}).map(([k, v]) => `${k}${SEP}${v}`);
|
|
384
|
+
|
|
385
|
+
/** The free tree → the wire (a ready-made place is left out: it is not the model's). */
|
|
386
|
+
export function freeToWire(page: FreePage): FreeWire {
|
|
387
|
+
const nodes = walkFree(page.sections.filter(s => !s.readyMade)).map(({ node: n, up }): FreeWireNode => ({
|
|
388
|
+
id: n.id, parent: up.length ? up[up.length - 1].id : '', type: n.type, purpose: n.purpose ?? '', style: n.elementStyle ?? '',
|
|
389
|
+
level: n.type === FreeNodeType.Heading ? n.level ?? 0 : 0, role: n.role ?? '', text: n.text ?? '', src: n.src ?? '', href: n.href ?? '',
|
|
390
|
+
slot: n.slot ?? '', opts: [...(n.opts ?? [])], base: lines(n.styleProps), phone: lines(n.responsive?.[FreeLayer.Phone]),
|
|
391
|
+
tablet: lines(n.responsive?.[FreeLayer.Tablet]), hover: lines(n.hover), motion: freeMoveWord(n.move),
|
|
392
|
+
}));
|
|
393
|
+
return { read: { ...page.read }, pictures: page.pictures, nodes };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** A tree key → the wire key it came from. */
|
|
397
|
+
const WIRE_KEY: ReadonlyArray<[string, string]> = [
|
|
398
|
+
[`responsive.${FreeLayer.Phone}`, 'phone'],
|
|
399
|
+
[`responsive.${FreeLayer.Tablet}`, 'tablet'],
|
|
400
|
+
['responsive', 'phone'],
|
|
401
|
+
['styleProps', 'base'],
|
|
402
|
+
['hover', 'hover'],
|
|
403
|
+
['move', 'motion'],
|
|
404
|
+
['elementStyle', 'style'],
|
|
405
|
+
['text', 'text'],
|
|
406
|
+
['opts', 'opts'],
|
|
407
|
+
];
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* A judge's path into the tree (`sections[0].children[1].styleProps.fontSize`) said against the wire
|
|
411
|
+
* (`nodes[2] ("shop-title").base.fontSize`) — a repair names wire paths. A path that names no node stays as written.
|
|
412
|
+
*/
|
|
413
|
+
export function freeWirePath(path: string, paths: Readonly<Record<string, number>>, wire: Pick<FreeWire, 'nodes'>): string {
|
|
414
|
+
const m = /^(sections\[\d+\](?:\.children\[\d+\])*)(?:\.(.*))?$/.exec(path);
|
|
415
|
+
if (!m || paths[m[1]] === undefined) return path;
|
|
416
|
+
const i = paths[m[1]];
|
|
417
|
+
const rest = m[2] ?? '';
|
|
418
|
+
const hit = WIRE_KEY.find(([k]) => rest === k || rest.startsWith(`${k}.`));
|
|
419
|
+
const where = hit ? `.${hit[1]}${rest.length > hit[0].length ? rest.slice(hit[0].length) : ''}` : rest ? `.${rest}` : '';
|
|
420
|
+
return `${nodeAt(i, wire.nodes?.[i]?.id ?? '')}${where}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** A repair's edits remove a node: what sat inside it goes too, so no orphan is left. */
|
|
424
|
+
export function withoutFreeOrphans(wire: FreeWire): FreeWire {
|
|
425
|
+
const ids = new Set<string>();
|
|
426
|
+
const nodes = (wire.nodes ?? []).filter(n => {
|
|
427
|
+
if (n?.parent && !ids.has(n.parent)) return false;
|
|
428
|
+
if (n?.id) ids.add(n.id);
|
|
429
|
+
return true;
|
|
430
|
+
});
|
|
431
|
+
return { ...wire, nodes };
|
|
432
|
+
}
|
|
@@ -210,8 +210,12 @@ export function sequenceShare(a: ReadonlyArray<string>, b: ReadonlyArray<string>
|
|
|
210
210
|
return lcs(a, b) / Math.max(1, a.length, b.length);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
/** #129: an opening mix's token (`opening:<frame>/<media>/<words>`, opening-mix `openingTokenOf`) — a type-led first
|
|
214
|
+
* screen's. Literal here: importing opening-mix from this module reorders the generation-core load (a cycle). */
|
|
215
|
+
const MIX_OPENING = 'opening:';
|
|
213
216
|
const openingWords = (opening: string) =>
|
|
214
|
-
opening.startsWith(
|
|
217
|
+
opening.startsWith(MIX_OPENING) ? `an opening of ${opening.slice(MIX_OPENING.length).split('/').join(' · ')}`
|
|
218
|
+
: opening.startsWith(READY_MADE_OPENING) ? `the ready-made ${opening.slice(READY_MADE_OPENING.length)}` : opening === OPENING_SCREEN_WORD ? 'a screen-size word' : opening === 'photo' || opening === 'gallery' ? `a ${opening}` : `a ${opening.replace('-', ' ')}`;
|
|
215
219
|
/** A list token in words: `list:row/middle-raised/arrows` → "row · middle raised · arrows". */
|
|
216
220
|
export const listWords = (token: string) => token.replace(`${LAYOUT_LIST_TOKEN}:`, '').split('/').map(p => p.replace(/[-+]/g, ' ')).join(' · ');
|
|
217
221
|
const signatureWords = (id: string) => SPEC_SITE_LAYOUT.signatures.find(s => s.id === id)?.label ?? id;
|
|
@@ -246,6 +250,16 @@ export function samenessIssues(me: LayoutFingerprint, others: ReadonlyArray<Fing
|
|
|
246
250
|
return issues;
|
|
247
251
|
}
|
|
248
252
|
|
|
253
|
+
/**
|
|
254
|
+
* The openings the studio's OTHER sites already wear, as the memory holds them (`LayoutFingerprint.opening`). This site's
|
|
255
|
+
* own pages (`sameSite`) and the demos are never a reason: every page of a site may open alike, and a demo is not a site.
|
|
256
|
+
* The ONE reading of the memory for an opening — a fallen page's (`distinctFallbackSections`) and a type-led first
|
|
257
|
+
* screen's (#129, `typeLedRound`).
|
|
258
|
+
*/
|
|
259
|
+
export function wornOpenings(others: ReadonlyArray<FingerprintedPage>): Set<string> {
|
|
260
|
+
return new Set(others.filter(o => !o.sameSite && !o.demo).map(o => o.fingerprint.opening));
|
|
261
|
+
}
|
|
262
|
+
|
|
249
263
|
/** The three proof sites' fingerprints (premium M8): every new page's opening and signature are compared with them, never
|
|
250
264
|
* its order of sections (`demo`). layout-fingerprint.spec holds them equal to `fingerprintOf` of the proof layouts. */
|
|
251
265
|
export const PROOF_FINGERPRINTS: ReadonlyArray<FingerprintedPage> = [
|