@vectoriox/iox-ui 5.158.0 → 5.159.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/design-core/index.d.ts +18 -2
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +41 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +2900 -2297
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +5 -33
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +528 -411
- package/package.json +1 -1
- package/src/design-core/css-functions.ts +48 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/generation-core/check-free.ts +31 -5
- package/src/generation-core/compose-free.ts +205 -0
- package/src/generation-core/compose-layout.ts +3 -1
- package/src/generation-core/compose-site.ts +74 -9
- package/src/generation-core/free-fallback.ts +11 -3
- package/src/generation-core/free-slots.ts +125 -0
- package/src/generation-core/free-wire.ts +5 -0
- package/src/generation-core/layout-section-fallback.ts +38 -1
- package/src/generation-core/plan-wire.ts +5 -0
- package/src/generation-core/public-api.ts +2 -0
- package/src/generation-core/site-plan.model.ts +12 -0
- package/src/generation-core/site-spec.generated.ts +34 -2
- package/src/generation-core/validate-site-plan.ts +124 -0
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The style controls that compose ONE multi-function CSS value (Effects ▸ Filter, Effects ▸ Backdrop): each control's
|
|
3
|
+
* trait, the CSS function it writes and its resting value — framework-free, so the main entry's style compiler
|
|
4
|
+
* (`composeVirtualTraits`) and generation-core's free stamp (`free-slots.ts`, which reads a model's whole `filter` into
|
|
5
|
+
* these controls) read ONE table. `decomposeCssFunctions` is the inverse: a whole value → the controls.
|
|
6
|
+
*/
|
|
7
|
+
export type CssFunctionControl = readonly [trait: string, fn: string, rest: string];
|
|
8
|
+
|
|
9
|
+
export const FILTER_FUNCTIONS: ReadonlyArray<CssFunctionControl> = [
|
|
10
|
+
['filterBlur', 'blur', '0px'],
|
|
11
|
+
['filterBrightness', 'brightness', '1'],
|
|
12
|
+
['filterContrast', 'contrast', '1'],
|
|
13
|
+
['filterGrayscale', 'grayscale', '0'],
|
|
14
|
+
['filterSaturate', 'saturate', '1'],
|
|
15
|
+
['filterHueRotate', 'hue-rotate', '0deg'],
|
|
16
|
+
['filterSepia', 'sepia', '0'],
|
|
17
|
+
['filterInvert', 'invert', '0'],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const BACKDROP_FUNCTIONS: ReadonlyArray<CssFunctionControl> = [
|
|
21
|
+
['backdropBlur', 'blur', '0px'],
|
|
22
|
+
['backdropBrightness', 'brightness', '1'],
|
|
23
|
+
['backdropContrast', 'contrast', '1'],
|
|
24
|
+
['backdropSaturate', 'saturate', '1'],
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/** The functions whose argument is a length or an angle; the rest are 0–3 factors (`140%` reads as `1.4`). */
|
|
28
|
+
const VERBATIM: ReadonlyArray<string> = ['blur', 'hue-rotate'];
|
|
29
|
+
const ONE_FUNCTION = /^([a-z-]+)\(([^()]*)\)$/;
|
|
30
|
+
const asFactor = (arg: string): string => (arg.endsWith('%') ? String(Math.round(parseFloat(arg) * 100) / 10000) : arg);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A whole value (`blur(16px) saturate(1.4)`) → every control of the group (its resting value when absent). `none` /
|
|
34
|
+
* empty → all resting. A function the group has no control for, or a `var()`, → null: the caller keeps it whole rather
|
|
35
|
+
* than silently dropping part of the look.
|
|
36
|
+
*/
|
|
37
|
+
export function decomposeCssFunctions(controls: ReadonlyArray<CssFunctionControl>, value: string | null | undefined): Record<string, string> | null {
|
|
38
|
+
const out: Record<string, string> = Object.fromEntries(controls.map(([trait, , rest]) => [trait, rest]));
|
|
39
|
+
const text = (value ?? '').trim();
|
|
40
|
+
if (text === '' || text === 'none') return out;
|
|
41
|
+
for (const part of text.split(/\s+(?![^(]*\))/)) {
|
|
42
|
+
const m = ONE_FUNCTION.exec(part);
|
|
43
|
+
const control = m && controls.find(([, fn]) => fn === m[1]);
|
|
44
|
+
if (!m || !control || m[2].trim() === '' || m[2].includes('var(')) return null;
|
|
45
|
+
out[control[0]] = VERBATIM.includes(control[1]) ? m[2].trim() : asFactor(m[2].trim());
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { factIssues, PlanWordContext, WrittenText } from './plan-words';
|
|
9
9
|
import { PageSectionPlan } from './site-plan.model';
|
|
10
10
|
import { PathIssue } from './shape-check';
|
|
11
|
+
import { freeStyleWithoutSlot } from './free-slots';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* THE FREE PAGE'S JUDGE (award plan §11.4 gates 1 + 2, FS3): every reason a free page may not be stamped, path first,
|
|
@@ -80,7 +81,7 @@ const LARGE_STYLES: ReadonlyArray<string> = ['display', 'h1', 'h2'];
|
|
|
80
81
|
|
|
81
82
|
/** The style properties whose value is the LOOK's: a token of this type, or one of the listed plain words. */
|
|
82
83
|
export const FREE_TOKEN_PROPS: Readonly<Record<string, string>> = {
|
|
83
|
-
color: 'color', backgroundColor: 'color', borderColor: 'color',
|
|
84
|
+
color: 'color', backgroundColor: 'color', borderColor: 'color',
|
|
84
85
|
fontFamily: 'font', borderRadius: 'radius', boxShadow: 'shadow', transitionDuration: 'duration', transitionTimingFunction: 'easing',
|
|
85
86
|
};
|
|
86
87
|
const TOKEN_PLAIN: Readonly<Record<string, ReadonlyArray<string>>> = {
|
|
@@ -88,7 +89,9 @@ const TOKEN_PLAIN: Readonly<Record<string, ReadonlyArray<string>>> = {
|
|
|
88
89
|
};
|
|
89
90
|
/** A colour token may be either of these token types. */
|
|
90
91
|
const COLOUR_TYPES: ReadonlyArray<string> = ['color', 'paint'];
|
|
91
|
-
/** The free properties: geometry, arrangement, type scale and rhythm, clipping, blending
|
|
92
|
+
/** The free properties: geometry, arrangement, type scale and rhythm, clipping, blending — each one a builder control
|
|
93
|
+
* holds (`free-slots.ts` folds the start / end sides, the axes, `place*`, `flex` and `filter` into them; a node's TYPE may
|
|
94
|
+
* still lack one, which `freeSlotIssues` says). */
|
|
92
95
|
export const FREE_STYLE_PROPS: ReadonlyArray<string> = [
|
|
93
96
|
'display', 'position', 'top', 'bottom', 'insetInlineStart', 'insetInlineEnd', 'zIndex', 'order',
|
|
94
97
|
'width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight', 'aspectRatio', 'overflow',
|
|
@@ -96,9 +99,9 @@ export const FREE_STYLE_PROPS: ReadonlyArray<string> = [
|
|
|
96
99
|
'padding', 'paddingTop', 'paddingBottom', 'paddingInlineStart', 'paddingInlineEnd', 'paddingInline', 'paddingBlock',
|
|
97
100
|
'gridTemplateColumns', 'gridTemplateRows', 'gridColumn', 'gridRow', 'gap', 'rowGap', 'columnGap',
|
|
98
101
|
'flexDirection', 'flexWrap', 'flex', 'alignItems', 'alignContent', 'justifyContent', 'alignSelf', 'justifySelf', 'placeItems', 'placeSelf',
|
|
99
|
-
'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textTransform', 'textAlign', 'fontStyle',
|
|
102
|
+
'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textTransform', 'textAlign', 'fontStyle',
|
|
100
103
|
'translateX', 'translateY', 'rotate', 'scaleX', 'scaleY', 'transformOrigin',
|
|
101
|
-
'clipPath', 'opacity', 'mixBlendMode', 'objectFit', '
|
|
104
|
+
'clipPath', 'opacity', 'mixBlendMode', 'objectFit', 'borderWidth', 'borderStyle', 'filter', 'backdropFilter',
|
|
102
105
|
];
|
|
103
106
|
/** A hover changes position, scale, turn, opacity or a colour token — never layout (Emil: transform / opacity only). */
|
|
104
107
|
export const FREE_HOVER_PROPS: ReadonlyArray<string> = ['translateX', 'translateY', 'scaleX', 'scaleY', 'rotate', 'opacity', 'color', 'backgroundColor', 'borderColor', 'boxShadow'];
|
|
@@ -164,6 +167,26 @@ export function freeStyleIssues(style: FreeStyle | undefined, path: string, ctx:
|
|
|
164
167
|
return out;
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
/**
|
|
171
|
+
* The style a node's TYPE has no builder control for (FS3 stamp, `free-slots.ts`): kept past the first save it could not
|
|
172
|
+
* be, so it is refused here, at the property the answer wrote — every layer, hover included.
|
|
173
|
+
*/
|
|
174
|
+
export function freeSlotIssues(node: FreeNode, path: string): FreeIssue[] {
|
|
175
|
+
if (!Object.values(FreeNodeType).includes(node?.type)) return [];
|
|
176
|
+
const layers: Array<[string, FreeStyle | undefined]> = [
|
|
177
|
+
['styleProps', node.styleProps], ...Object.entries(node.responsive ?? {}).map(([bp, s]) => [`responsive.${bp}`, s] as [string, FreeStyle]), ['hover', node.hover],
|
|
178
|
+
];
|
|
179
|
+
const out: FreeIssue[] = [];
|
|
180
|
+
for (const [layer, style] of layers) {
|
|
181
|
+
for (const [prop, control] of freeStyleWithoutSlot(node.type, style)) {
|
|
182
|
+
if (!FREE_TOKEN_PROPS[prop] && !FREE_STYLE_PROPS.includes(prop)) continue; // said once, by freeStyleIssues
|
|
183
|
+
const inside = node.type === FreeNodeType.Video || node.type === FreeNodeType.Image ? ' — put it on a Container around it' : '';
|
|
184
|
+
out.push({ code: FreeIssueCode.Style, path: `${path}.${layer}.${prop}`, message: `a ${node.type} has no ${control === prop ? `"${prop}"` : `"${control}" (what "${prop}" becomes)`}${inside}` });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
167
190
|
/** Every reason a free page may not be stamped (gate 1), contrast included (gate 2's tree half). */
|
|
168
191
|
export function checkFree(page: FreePage, ctx: FreeJudgeContext): FreeIssue[] {
|
|
169
192
|
return judgeFree(page, ctx, false);
|
|
@@ -197,7 +220,9 @@ function judgeFree(page: FreePage, ctx: FreeJudgeContext, signature: boolean): F
|
|
|
197
220
|
const issues: FreeIssue[] = [];
|
|
198
221
|
const say = (code: FreeIssueCode, path: string, message: string) => issues.push({ code, path, message });
|
|
199
222
|
const sections = Array.isArray(page?.sections) ? page.sections : [];
|
|
200
|
-
|
|
223
|
+
// A section the fall back dropped still counts toward the minimum (iox-ui#134); the maximum is the page as it stands.
|
|
224
|
+
const counted = sections.length + Math.max(0, Number(page?.givenAway) || 0);
|
|
225
|
+
if (!signature && (counted < FREE_SECTIONS.min || sections.length > FREE_SECTIONS.max)) say(FreeIssueCode.Structure, 'sections', `a page is ${FREE_SECTIONS.min} to ${FREE_SECTIONS.max} sections (this one has ${sections.length})`);
|
|
201
226
|
const ready = (i: number) => !!sections[i]?.readyMade;
|
|
202
227
|
const walked = walkFree(sections).filter(w => !ready(w.section));
|
|
203
228
|
const ids = new Set(walkFree(sections).map(w => w.node.id));
|
|
@@ -246,6 +271,7 @@ function judgeFree(page: FreePage, ctx: FreeJudgeContext, signature: boolean): F
|
|
|
246
271
|
}
|
|
247
272
|
for (const prop of Object.keys(node.hover ?? {})) if (!FREE_HOVER_PROPS.includes(prop)) say(FreeIssueCode.Style, `${path}.hover.${prop}`, `a hover changes position, scale, turn, opacity or a colour token only (${FREE_HOVER_PROPS.join(', ')}) — never layout`);
|
|
248
273
|
issues.push(...freeStyleIssues(Object.fromEntries(Object.entries(node.hover ?? {}).filter(([p]) => FREE_HOVER_PROPS.includes(p))), `${path}.hover`, ctx));
|
|
274
|
+
issues.push(...freeSlotIssues(node, path));
|
|
249
275
|
|
|
250
276
|
// the one move
|
|
251
277
|
if (node.move) {
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { NO_ELEMENT_STYLE } from '@vectoriox/iox-ui/composite-core';
|
|
2
|
+
import { LinkType } from '@vectoriox/iox-ui/design-core';
|
|
3
|
+
import { VideoMode, VideoSource } from '@vectoriox/iox-ui/media-core';
|
|
4
|
+
|
|
5
|
+
import { composeListFrame, LayoutListBinding } from './compose-layout';
|
|
6
|
+
import { composePresetForm } from './compose-site';
|
|
7
|
+
import { freeStyleToSlots } from './free-slots';
|
|
8
|
+
import { FREE_BUILDER_TYPE, FreeLayer, FreeNode, FreeNodeType, FreePage, FreeStyle, FreeTrigger } from './free-wire';
|
|
9
|
+
import { LAYOUT_BEAT_DELAY, LAYOUT_DEPTH_ON_PHONE, LAYOUT_EASING, LAYOUT_PACE, LAYOUT_RISE, LayoutEase, LayoutPace, LayoutRole, LayoutSite } from './layout-language';
|
|
10
|
+
import { listMixFromWords } from './layout-wire';
|
|
11
|
+
import { ComposeError, createSerializedNode, SerializedNode, setStyleProps } from './serialized-node';
|
|
12
|
+
import { stampSection } from './section-stamp';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* THE FREE STAMP (award-ingredients plan §11.4, FS3, R-H3): a free page — or one free signature section — that passed
|
|
16
|
+
* `checkFree` in, ordinary builder nodes out. Each free node is made by `createSerializedNode` (the builder's own
|
|
17
|
+
* creation: its type, its element style) and given the answer's look through the builder's CONTROLS (`free-slots.ts`),
|
|
18
|
+
* so the builder reloads the page and saves it unchanged and the engine renders it with nothing new to learn. A Slot is
|
|
19
|
+
* the product's recipe, never the model's nodes: a list through `composeListFrame` (the one list composer), a form
|
|
20
|
+
* through the forms-core preset (`composePresetForm`); a section the fall back gave the plan back is the plan's
|
|
21
|
+
* ready-made section, composed by the caller (`readyMade`). The header and the footer are the site's globals. Pure and
|
|
22
|
+
* deterministic; what the stamp cannot keep is a `ComposeError` (the judge refused it first).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const COMPOSED = { releaseLayoutDefaults: true } as const;
|
|
26
|
+
const SECTION_LINK = '#';
|
|
27
|
+
const ROUTE_MARK = '/';
|
|
28
|
+
const LIST_SLOT = 'list:';
|
|
29
|
+
const FORM_SLOT = 'form:';
|
|
30
|
+
/** A list slot's mix when the answer names no option: cards of the list's parts, in a grid. */
|
|
31
|
+
const LIST_SLOT_WORDS: ReadonlyArray<string> = ['item:card', 'arrange:grid'];
|
|
32
|
+
|
|
33
|
+
export interface ComposeFreeOptions {
|
|
34
|
+
/** The page key: every node's id is `<owner>-<the answer's id>`, unique on the site. */
|
|
35
|
+
owner: string;
|
|
36
|
+
/** The site's language: a right-to-left one puts the start side on the right. */
|
|
37
|
+
locale?: string;
|
|
38
|
+
rtl?: boolean;
|
|
39
|
+
/** The look's pace and easing (`layoutMotionOf`): how long an entrance takes. Default normal, ease-out. */
|
|
40
|
+
motion?: LayoutSite['motion'];
|
|
41
|
+
/** A material id as the address and the words of its picture (`ComposeContext.photoSrc` / `photoAlt`). */
|
|
42
|
+
photoSrc: (id: string) => string;
|
|
43
|
+
photoAlt: (id: string) => string;
|
|
44
|
+
/** How a list slot's items are read (`layoutListBinding`); null for an alias that is no list. */
|
|
45
|
+
listOf: (alias: string) => LayoutListBinding | null;
|
|
46
|
+
/** The plan's ready-made section at plan index `at`, composed under `id` (a section the fall back gave back). */
|
|
47
|
+
readyMade?: (at: number, id: string) => SerializedNode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface Ctx {
|
|
51
|
+
o: ComposeFreeOptions;
|
|
52
|
+
rtl: boolean;
|
|
53
|
+
pace: { lead: number; support: number; decoration: number; gap: number };
|
|
54
|
+
ease: string;
|
|
55
|
+
/** Every Button that goes to a section of this page, by the answer's id (resolved once every node is made). */
|
|
56
|
+
links: Array<{ node: SerializedNode; to: string }>;
|
|
57
|
+
ids: Set<string>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const idOf = (ctx: Ctx, id: string) => `${ctx.o.owner}-${id}`;
|
|
61
|
+
|
|
62
|
+
/** A free page's sections, one stamped root each (a ready-made place stamped with its pattern, the rest as model-laid). */
|
|
63
|
+
export function composeFreePage(page: FreePage, options: ComposeFreeOptions): SerializedNode[] {
|
|
64
|
+
const ctx = contextOf(options, page.sections);
|
|
65
|
+
const roots = page.sections.map(section => (section.readyMade ? readyMadeSection(section, ctx) : composeNode(section, ctx, 0)));
|
|
66
|
+
// The links are written once every node is made; the stamp's fingerprint is taken after them.
|
|
67
|
+
wireLinks(ctx);
|
|
68
|
+
return roots.map((root, i) => {
|
|
69
|
+
const pattern = page.sections[i].readyMade?.pattern;
|
|
70
|
+
return stampSection(root, pattern ? { pattern } : { layout: page.sections[i].id });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** ONE free signature section (FS-D19 Basic) as a section root under `id` — the page's other sections are the plan's. */
|
|
75
|
+
export function composeFreeSection(section: FreeNode, id: string, options: ComposeFreeOptions): SerializedNode {
|
|
76
|
+
if (section.type !== FreeNodeType.Section) throw new ComposeError(`${id}: a free section is a Section, not a ${section.type}`);
|
|
77
|
+
// Its nodes are named under the section's own id, so they never meet the ids of the patterns beside it.
|
|
78
|
+
const ctx = contextOf({ ...options, owner: id }, [section]);
|
|
79
|
+
const root = composeNode(section, ctx, 0);
|
|
80
|
+
root.id = id;
|
|
81
|
+
wireLinks(ctx, { [section.id]: id });
|
|
82
|
+
return stampSection(root, { layout: section.id });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function contextOf(options: ComposeFreeOptions, sections: ReadonlyArray<FreeNode>): Ctx {
|
|
86
|
+
const pace = LAYOUT_PACE[(options.motion?.pace ?? LayoutPace.Normal) as LayoutPace] ?? LAYOUT_PACE[LayoutPace.Normal];
|
|
87
|
+
const ids = new Set<string>();
|
|
88
|
+
const walk = (n: FreeNode) => { ids.add(n.id); (n.children ?? []).forEach(walk); };
|
|
89
|
+
sections.forEach(walk);
|
|
90
|
+
return {
|
|
91
|
+
o: options, rtl: !!options.rtl, pace, ids, links: [],
|
|
92
|
+
ease: LAYOUT_EASING[(options.motion?.ease ?? LayoutEase.Out) as LayoutEase] ?? LAYOUT_EASING[LayoutEase.Out],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function readyMadeSection(section: FreeNode, ctx: Ctx): SerializedNode {
|
|
97
|
+
if (!ctx.o.readyMade) throw new ComposeError(`${section.id}: a ready-made place, and no plan section to compose it from`);
|
|
98
|
+
return ctx.o.readyMade(section.readyMade!.at, idOf(ctx, section.id));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** One free node and its children, as the builder makes them. `beat` is its place among its moving siblings. */
|
|
102
|
+
function composeNode(n: FreeNode, ctx: Ctx, beat: number): SerializedNode {
|
|
103
|
+
const id = idOf(ctx, n.id);
|
|
104
|
+
const type = FREE_BUILDER_TYPE[n.type];
|
|
105
|
+
if (!type) throw new ComposeError(`${n.id}: "${n.type}" is not a free node type`);
|
|
106
|
+
const node = createSerializedNode(id, type, propsOf(n, ctx), n.elementStyle || NO_ELEMENT_STYLE, COMPOSED);
|
|
107
|
+
node.label = n.purpose ?? n.id;
|
|
108
|
+
if (n.type === FreeNodeType.Button) {
|
|
109
|
+
const label = createSerializedNode(`${id}-label`, 'Text', { content: n.text ?? '', tag: 'span' }, 'button-label', COMPOSED);
|
|
110
|
+
node.children = [label];
|
|
111
|
+
if (n.href?.startsWith(SECTION_LINK)) ctx.links.push({ node, to: n.href.slice(1) });
|
|
112
|
+
}
|
|
113
|
+
styleInto(node, n, ctx);
|
|
114
|
+
const move = moveOf(n, id, ctx, beat);
|
|
115
|
+
if (move) node.interactions = [...node.interactions, move];
|
|
116
|
+
if (n.type === FreeNodeType.Slot) node.children = [slotOf(n, id, ctx)];
|
|
117
|
+
else if (n.children?.length) {
|
|
118
|
+
let moving = 0;
|
|
119
|
+
node.children = [...(node.children ?? []), ...n.children.map(c => composeNode(c, ctx, c.move ? moving++ : 0))];
|
|
120
|
+
}
|
|
121
|
+
return node;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What a node says and shows: its words, its level, its link, its picture. */
|
|
125
|
+
function propsOf(n: FreeNode, ctx: Ctx): Record<string, unknown> {
|
|
126
|
+
switch (n.type) {
|
|
127
|
+
case FreeNodeType.Heading: return { content: n.text ?? '', level: `h${n.level ?? 2}` };
|
|
128
|
+
case FreeNodeType.Text: return { content: n.text ?? '', tag: 'p' };
|
|
129
|
+
case FreeNodeType.Button:
|
|
130
|
+
return n.href?.startsWith(ROUTE_MARK) ? { tag: 'a', linkType: LinkType.Page, pageRoute: n.href } : { tag: 'button', type: 'button' };
|
|
131
|
+
case FreeNodeType.Image: return { src: ctx.o.photoSrc(n.src ?? ''), alt: ctx.o.photoAlt(n.src ?? '') };
|
|
132
|
+
case FreeNodeType.Video:
|
|
133
|
+
return { videoSource: VideoSource.File, src: ctx.o.photoSrc(n.src ?? ''), title: ctx.o.photoAlt(n.src ?? ''), mode: VideoMode.Inline };
|
|
134
|
+
default: return {};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The answer's style, every layer, through the builder's controls: base on the element style, each width on the one
|
|
139
|
+
* wider (tablet on the base, the phone on the tablet), the hover as the node's hover state. */
|
|
140
|
+
function styleInto(node: SerializedNode, n: FreeNode, ctx: Ctx): void {
|
|
141
|
+
const base = freeStyleToSlots(n.styleProps, { rtl: ctx.rtl, held: node.styleProps });
|
|
142
|
+
setStyleProps(node, base);
|
|
143
|
+
let held: Record<string, unknown> = { ...node.styleProps };
|
|
144
|
+
for (const layer of [FreeLayer.Tablet, FreeLayer.Phone]) {
|
|
145
|
+
const style = n.responsive?.[layer];
|
|
146
|
+
if (!style || !Object.keys(style).length) continue;
|
|
147
|
+
const values = freeStyleToSlots(style, { rtl: ctx.rtl, held });
|
|
148
|
+
assertLayer(node, values);
|
|
149
|
+
node.responsive = { ...(node.responsive ?? {}), [layer]: { styleProps: values } };
|
|
150
|
+
held = { ...held, ...values };
|
|
151
|
+
}
|
|
152
|
+
if (n.hover && Object.keys(n.hover).length) {
|
|
153
|
+
const values = freeStyleToSlots(n.hover as FreeStyle, { rtl: ctx.rtl, held: node.styleProps });
|
|
154
|
+
assertLayer(node, values);
|
|
155
|
+
node.stateStyles = { ...(node.stateStyles ?? {}), hover: { ...(node.stateStyles?.['hover'] ?? {}), ...values } };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A layer's controls must be the node's own, as the base's are (`setStyleProps`). */
|
|
160
|
+
function assertLayer(node: SerializedNode, values: Record<string, unknown>): void {
|
|
161
|
+
const probe = { ...node, styleProps: {} };
|
|
162
|
+
setStyleProps(probe, values);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The node's ONE move as the product's interaction: a time entrance (`viewportEnter`) or a depth played by the scroll. */
|
|
166
|
+
function moveOf(n: FreeNode, id: string, ctx: Ctx, beat: number): unknown | null {
|
|
167
|
+
const m = n.move;
|
|
168
|
+
if (!m) return null;
|
|
169
|
+
if (m.trigger === FreeTrigger.Scroll) {
|
|
170
|
+
return { id: `${id}-depth`, trigger: 'scrollProgress', range: 'cover', actions: [{ type: m.action, target: 'self', duration: 1000, delay: 0, easing: 'linear', params: { ...(m.params ?? {}), phone: LAYOUT_DEPTH_ON_PHONE } }] };
|
|
171
|
+
}
|
|
172
|
+
const lead = n.role === 'lead';
|
|
173
|
+
const params: Record<string, unknown> = { ...(m.params ?? {}) };
|
|
174
|
+
if (m.action === 'moveUp') params['distance'] = LAYOUT_RISE[lead ? LayoutRole.Lead : LayoutRole.Support];
|
|
175
|
+
const delay = Math.round(LAYOUT_BEAT_DELAY[Math.min(beat, LAYOUT_BEAT_DELAY.length - 1)] * ctx.pace.gap);
|
|
176
|
+
return {
|
|
177
|
+
id: `${id}-enter`, trigger: 'viewportEnter',
|
|
178
|
+
actions: [{ type: m.action, target: 'self', duration: lead ? ctx.pace.lead : ctx.pace.support, delay, easing: ctx.ease, once: true, ...(Object.keys(params).length ? { params } : {}) }],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** The recipe a Slot places: the list composer's frame, or the preset form. */
|
|
183
|
+
function slotOf(n: FreeNode, id: string, ctx: Ctx): SerializedNode {
|
|
184
|
+
const slot = n.slot ?? '';
|
|
185
|
+
if (slot.startsWith(LIST_SLOT)) {
|
|
186
|
+
const alias = slot.slice(LIST_SLOT.length);
|
|
187
|
+
const list = ctx.o.listOf(alias);
|
|
188
|
+
if (!list) throw new ComposeError(`${n.id}: "${alias}" is no list of the plan`);
|
|
189
|
+
const asked = (n.opts ?? []).filter(Boolean);
|
|
190
|
+
const words = [...LIST_SLOT_WORDS.filter(w => !asked.some(a => a.split(':')[0] === w.split(':')[0])), ...asked];
|
|
191
|
+
const mix = listMixFromWords(words, Object.keys(list.roles))!;
|
|
192
|
+
return composeListFrame({ id: `${id}-list`, mix, source: alias, list, locale: ctx.o.locale, label: n.purpose ?? alias, path: n.id, ...(ctx.o.motion ? { motion: ctx.o.motion } : {}) }).frame;
|
|
193
|
+
}
|
|
194
|
+
if (slot.startsWith(FORM_SLOT)) return composePresetForm(`${id}-form`, slot.slice(FORM_SLOT.length), ctx.o.owner, ctx.o.locale);
|
|
195
|
+
throw new ComposeError(`${n.id}: "${slot}" is not a part a free page may place`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** A Button to a section of this page scrolls to it (the product's `scrollTo`: M8-G7, no shareable `#id`). */
|
|
199
|
+
function wireLinks(ctx: Ctx, renamed: Readonly<Record<string, string>> = {}): void {
|
|
200
|
+
for (const { node, to } of ctx.links) {
|
|
201
|
+
if (!ctx.ids.has(to)) throw new ComposeError(`${node.id}: goes to "#${to}", which this page does not have`);
|
|
202
|
+
const target = renamed[to] ?? idOf(ctx, to);
|
|
203
|
+
node.interactions = [...node.interactions, { id: `${node.id}-to`, trigger: 'click', actions: [{ type: 'scrollTo', target, duration: 0, delay: 0, easing: 'ease' }] }];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -1096,6 +1096,8 @@ export interface ListFrameInput {
|
|
|
1096
1096
|
/** vectoriox/iox-ui#122: the mix the frame on the page wears now (the panel's), so the composer can tell the owner's
|
|
1097
1097
|
* edits inside the card from its own drawing. Absent: read from the frame (`listMixOfFrame`). */
|
|
1098
1098
|
readonly was?: LayoutListMix | null;
|
|
1099
|
+
/** The id a NEW frame is made under (a free page's slot, FS3); default `list`. A recompose keeps `previous`'s. */
|
|
1100
|
+
readonly id?: string;
|
|
1099
1101
|
}
|
|
1100
1102
|
|
|
1101
1103
|
/** A recomposed list frame, and what the composer said while composing it (a word drawn as its stand-in…). */
|
|
@@ -1121,7 +1123,7 @@ const LIST_FRAME_PROPS: ReadonlyArray<string> = [LIST_MIX_PROP, 'colorScheme'];
|
|
|
1121
1123
|
* arrangement, role, room and classes. Pure.
|
|
1122
1124
|
*/
|
|
1123
1125
|
export function composeListFrame(input: ListFrameInput, previous?: SerializedNode | null): ListFrame {
|
|
1124
|
-
const composed = composeListOnly(input, previous?.id ?? 'list');
|
|
1126
|
+
const composed = composeListOnly(input, previous?.id ?? input.id ?? 'list');
|
|
1125
1127
|
if (!previous) return { frame: composed.frame, gaps: composed.gaps, edits: [] };
|
|
1126
1128
|
// What the composer draws for the mix the frame wears now: anything else on the page is the owner's (#122).
|
|
1127
1129
|
const was = input.was ?? listMixOfFrame(previous, input.list);
|
|
@@ -50,6 +50,8 @@ import { MenuSide, NavRole, NavShape, planNavShape } from './nav-shape';
|
|
|
50
50
|
import { composeLayout, LayoutColourMode, layoutBandScheme, LayoutListBinding } from './compose-layout';
|
|
51
51
|
import { LayoutGalleryList, LayoutListShape, LayoutPage, LayoutPhotoShape, LayoutPhotoSource, LayoutSite, parseLayoutPhotoId } from './layout-language';
|
|
52
52
|
import { layoutMotionOf, layoutPresetOf } from './layout-look';
|
|
53
|
+
import { ComposeFreeOptions, composeFreePage, composeFreeSection } from './compose-free';
|
|
54
|
+
import { FreePage } from './free-wire';
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
57
|
* THE composer — a Site Plan in, ordinary IOX data out (design-system plan §6b, W1). Deterministic and
|
|
@@ -1690,16 +1692,62 @@ function composeLayoutPage(
|
|
|
1690
1692
|
const image = type && pictureless.has(type.name) ? undefined : roleField(type, 'image');
|
|
1691
1693
|
return image ? { image, ...(roleField(type, 'title') ? { title: roleField(type, 'title')! } : {}) } : null;
|
|
1692
1694
|
},
|
|
1693
|
-
listOf: alias =>
|
|
1694
|
-
const binding = layoutListBinding(alias, plan);
|
|
1695
|
-
const type = contentTypeOfSource(alias, plan);
|
|
1696
|
-
// #129: a list whose items have no picture is read as a list without one (its cards draw no picture part).
|
|
1697
|
-
if (!binding || !type || !pictureless.has(type.name) || !binding.roles[ContentRole.Image]) return binding;
|
|
1698
|
-
const { [ContentRole.Image]: _none, ...roles } = binding.roles;
|
|
1699
|
-
return { ...binding, roles };
|
|
1700
|
-
},
|
|
1695
|
+
listOf: alias => pageListOf(alias, plan, pictureless),
|
|
1701
1696
|
...(context.carry?.[page.key] ? { carry: context.carry[page.key] } : {}),
|
|
1702
1697
|
});
|
|
1698
|
+
fillPageFacts(nodes, page, plan, placeholders);
|
|
1699
|
+
return nodes;
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
/** How a model-laid page reads one list (`layoutListBinding`) — #129: a list whose items have no picture is read as a list
|
|
1703
|
+
* without one (its cards draw no picture part). */
|
|
1704
|
+
function pageListOf(alias: string, plan: SitePlan, pictureless: ReadonlySet<string>): LayoutListBinding | null {
|
|
1705
|
+
const binding = layoutListBinding(alias, plan);
|
|
1706
|
+
const type = contentTypeOfSource(alias, plan);
|
|
1707
|
+
if (!binding || !type || !pictureless.has(type.name) || !binding.roles[ContentRole.Image]) return binding;
|
|
1708
|
+
const { [ContentRole.Image]: _none, ...roles } = binding.roles;
|
|
1709
|
+
return { ...binding, roles };
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
/**
|
|
1713
|
+
* FS3: a free page — the model's own nodes, stamped by `composeFreePage` in the look's pace — with the site's facts
|
|
1714
|
+
* written in as on a composed page; a section the fall back gave back is the plan's ready-made one.
|
|
1715
|
+
*/
|
|
1716
|
+
function composeFreePlanPage(
|
|
1717
|
+
page: PagePlan, free: FreePage, plan: SitePlan, context: ComposeContext, placeholders: ComposedPlaceholder[], pictureless: ReadonlySet<string>,
|
|
1718
|
+
readyMade: (section: PageSectionPlan, id: string, at: number) => SerializedNode,
|
|
1719
|
+
): SerializedNode[] {
|
|
1720
|
+
const nodes = composeFreePage(free, freeOptionsOf(page, plan, context, pictureless, readyMade));
|
|
1721
|
+
fillPageFacts(nodes, page, plan, placeholders);
|
|
1722
|
+
return nodes;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
/** What the free stamp reads of the site: its language, the look's pace, the owner's pictures, the plan's lists. */
|
|
1726
|
+
function freeOptionsOf(
|
|
1727
|
+
page: PagePlan, plan: SitePlan, context: ComposeContext, pictureless: ReadonlySet<string>,
|
|
1728
|
+
readyMade?: (section: PageSectionPlan, id: string, at: number) => SerializedNode,
|
|
1729
|
+
): ComposeFreeOptions {
|
|
1730
|
+
const locale = plan.locale ?? DEFAULT_SITE_LOCALE;
|
|
1731
|
+
return {
|
|
1732
|
+
owner: page.key, locale, rtl: isRtlLocale(locale), motion: layoutMotionOf(layoutPresetOf(plan.design).id),
|
|
1733
|
+
photoSrc: id => context.photoSrc?.(id) ?? '', photoAlt: id => context.photoAlt?.(id) ?? '',
|
|
1734
|
+
listOf: alias => pageListOf(alias, plan, pictureless),
|
|
1735
|
+
...(readyMade ? {
|
|
1736
|
+
readyMade: (at: number, id: string) => {
|
|
1737
|
+
const section = page.sections[at];
|
|
1738
|
+
if (!section) throw new ComposeError(`${page.key}: a ready-made place names plan section ${at}, which the page does not have`);
|
|
1739
|
+
return readyMade(section, id, at);
|
|
1740
|
+
},
|
|
1741
|
+
} : {}),
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* A model-laid page's facts (M8 gate 2; a free page's too, FS3): a `{fact:<key>}` the owner gave becomes their words, one
|
|
1747
|
+
* they did not becomes the fact's label and a contact placeholder (never invented); a photo with no address is the empty
|
|
1748
|
+
* image box, a placeholder like a pattern's.
|
|
1749
|
+
*/
|
|
1750
|
+
function fillPageFacts(nodes: SerializedNode[], page: PagePlan, plan: SitePlan, placeholders: ComposedPlaceholder[]): void {
|
|
1703
1751
|
const facts = plan.business.facts ?? {};
|
|
1704
1752
|
walkSerialized(nodes, node => {
|
|
1705
1753
|
for (const prop of LAYOUT_TEXT_PROPS) {
|
|
@@ -1716,7 +1764,6 @@ function composeLayoutPage(
|
|
|
1716
1764
|
}
|
|
1717
1765
|
if (node.type === IMAGE && !node.props['src'] && !node.bindings.length) placeholders.push({ nodeId: node.id, owner: page.key, kind: PlaceholderKind.Image, text: '' });
|
|
1718
1766
|
});
|
|
1719
|
-
return nodes;
|
|
1720
1767
|
}
|
|
1721
1768
|
|
|
1722
1769
|
/** M2-1: each section root of a model-laid page says where it came from — a ready-made place its plan section's library
|
|
@@ -1788,6 +1835,18 @@ function composeSiteOnce(plan: SitePlan, context: ComposeContext, pictureless: R
|
|
|
1788
1835
|
const body = bodyChecked?.mix ?? null;
|
|
1789
1836
|
const pages: ComposedPage[] = plan.pages.map(page => {
|
|
1790
1837
|
const nextAlias = page.routeSource ? nextSourceOf(relatives, page.routeSource) : null;
|
|
1838
|
+
if (page.free) {
|
|
1839
|
+
// FS3: the model's own page. Its opening is its own (the plan's opening is never worn over it).
|
|
1840
|
+
const nodes = composeFreePlanPage(page, page.free, plan, context, placeholders, pictureless, (section, id, at) =>
|
|
1841
|
+
composePattern(patternById(section.pattern) as SitePattern, id, { ...base, owner: page.key, page, section, nextAlias },
|
|
1842
|
+
{ level: section.enter ?? design.animate ?? null, rtl, move: design.headings ?? null, scrub: design.scrub ?? null, opening: at === 0 }));
|
|
1843
|
+
const opening = schemeOfFirst(nodes);
|
|
1844
|
+
return {
|
|
1845
|
+
key: page.key, name: page.name, route: { path: page.route }, isHome: page.isHome === true, status: STATUS_DRAFT, locale,
|
|
1846
|
+
pageSettings: { designSystem: true, layoutSource: { pageKey: page.key }, ...(opening ? { opening } : {}) }, seo: composePageSeo(page, plan),
|
|
1847
|
+
layout: wearBodyMix(nodes, body),
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1791
1850
|
if (page.layout) {
|
|
1792
1851
|
// vectoriox/iox-ui#99: a composed page that is where the site lists the shop lists it (a stored layout too).
|
|
1793
1852
|
const layout = withShownList(page.layout, layoutListsContext(page, plan)) ?? page.layout;
|
|
@@ -1810,6 +1869,12 @@ function composeSiteOnce(plan: SitePlan, context: ComposeContext, pictureless: R
|
|
|
1810
1869
|
const layout = wearPlanOpening(page, page.sections.map((section, i) => {
|
|
1811
1870
|
const pattern = patternById(section.pattern) as SitePattern;
|
|
1812
1871
|
const motion: SectionMotion = { level: section.enter ?? design.animate ?? null, rtl, move: design.headings ?? null, scrub: design.scrub ?? null, opening: i === 0 };
|
|
1872
|
+
// FS-D19: a free signature section stands in its place; its fall back is this pattern.
|
|
1873
|
+
if (section.free) {
|
|
1874
|
+
const root = composeFreeSection(section.free, `${page.key}-${i}`, freeOptionsOf(page, plan, context, pictureless));
|
|
1875
|
+
fillPageFacts([root], page, plan, placeholders);
|
|
1876
|
+
return root;
|
|
1877
|
+
}
|
|
1813
1878
|
return stampSection(composePattern(pattern, `${page.key}-${i}`, { ...base, owner: page.key, page, section, nextAlias }, motion), { pattern: section.pattern });
|
|
1814
1879
|
}), plan, context, design, placeholders, issues, false, page.sections[0]);
|
|
1815
1880
|
const opening = schemeOfFirst(layout);
|
|
@@ -87,8 +87,10 @@ export function fallBackFree(page: FreePage, plan: ReadonlyArray<PageSectionPlan
|
|
|
87
87
|
const limits = prompt?.limits ?? [];
|
|
88
88
|
const lastAt = plan.length - 1;
|
|
89
89
|
const honest = plan.map((_, i) => i).filter(i => i === 0 || i === lastAt || !sectionBreaks(plan[i], limits).length);
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
// The honest pass holds the page's minimum (FS-D47: a place is dropped only where the minimums allow); the last pass,
|
|
91
|
+
// over the whole plan, forgives a place nothing at all is left for (iox-ui#134: never the whole page for its count).
|
|
92
|
+
const first = limits.length && honest.length < plan.length ? fallBackOn(page, plan, honest, issues, ctx, false) : null;
|
|
93
|
+
const done = first && !first.lastResort ? first : fallBackOn(page, plan, plan.map((_, i) => i), issues, ctx, true);
|
|
92
94
|
if (done.lastResort || !limits.length) return done;
|
|
93
95
|
const broken = new Map<PromptLimit, number>();
|
|
94
96
|
for (const s of done.page.sections) {
|
|
@@ -103,11 +105,15 @@ export function fallBackFree(page: FreePage, plan: ReadonlyArray<PageSectionPlan
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
/** The ONE fall back over the plan sections `use` (by their index in `plan`); ready-made places name the FULL plan. */
|
|
106
|
-
function fallBackOn(
|
|
108
|
+
function fallBackOn(
|
|
109
|
+
page: FreePage, plan: ReadonlyArray<PageSectionPlan>, use: ReadonlyArray<number>, issues: ReadonlyArray<FreeIssue>, ctx: FreeJudgeContext, forgive: boolean,
|
|
110
|
+
): FreeFallback {
|
|
107
111
|
const byId = new Map(page.sections.map(s => [s.id, s]));
|
|
108
112
|
const real = (at: number) => use[at] ?? at;
|
|
113
|
+
// iox-ui#134: on the last pass, what the fall back dropped is given away — the page's minimum forgives it (as #67).
|
|
109
114
|
const toFree = (layout: LayoutPage): FreePage => ({
|
|
110
115
|
...page,
|
|
116
|
+
...(forgive && layout.sections.length < page.sections.length ? { givenAway: (page.givenAway ?? 0) + page.sections.length - layout.sections.length } : {}),
|
|
111
117
|
sections: layout.sections.map(s => {
|
|
112
118
|
const was = byId.get(s.id)!;
|
|
113
119
|
return s.readyMade && !was.readyMade
|
|
@@ -129,6 +135,8 @@ function fallBackOn(page: FreePage, plan: ReadonlyArray<PageSectionPlan>, use: R
|
|
|
129
135
|
last = checkFree(toFree(layout), ctx);
|
|
130
136
|
return { page: layout, issues: last.map(asLayoutIssue) };
|
|
131
137
|
},
|
|
138
|
+
// iox-ui#134: a free page keeps its places — a middle section nothing fits by its words takes the nearest unused one.
|
|
139
|
+
{ keepPlace: true },
|
|
132
140
|
);
|
|
133
141
|
return {
|
|
134
142
|
page: toFree(judged.page),
|