@vectoriox/iox-ui 5.181.0 → 5.183.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.
@@ -1,8 +1,9 @@
1
1
  import type { DesignChoices } from '@vectoriox/iox-ui/design-core';
2
+ import { fitSeoText, redirectPath, SEO_DESCRIPTION_MAX, SEO_ROBOTS_NOINDEX, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
2
3
 
3
4
  import {
4
5
  ContentFieldControl, ContentFieldPlan, ContentRole, ContentRoles, ContentTypePlan, DataSourcePlan, FIELD_TYPE_OF_CONTROL, PagePlan, PageSectionPlan,
5
- PlanDataSourceMode, PlanDataSourceType, RelativeOp, roleField, SiteBusiness, SiteLocale, SitePlan, SitePlanSourceKind, SITE_PLAN_VERSION,
6
+ PageSeoPlan, PlanDataSourceMode, PlanDataSourceType, RelativeOp, roleField, SiteBusiness, SiteLocale, SitePlan, SitePlanSourceKind, SITE_PLAN_VERSION,
6
7
  } from './site-plan.model';
7
8
  import { SiteTemplate, STUDIO_TEMPLATE } from './templates';
8
9
 
@@ -14,6 +15,11 @@ import { SiteTemplate, STUDIO_TEMPLATE } from './templates';
14
15
  * `story.long-form` section holding the owner's own words, paragraphs kept. The home page, the contact page and the
15
16
  * header and footer come from the template (the Studio's by default), the look from the owner's pick. Pure: iox-cms
16
17
  * reads its scan into an `ImportReading` and builds the plan here, and so may any screen that shows it.
18
+ *
19
+ * X6: what search knew of each page moves with it — its old title and line become the page's `seo` words (the home
20
+ * page's too), and a page the old site kept out of search moves kept out (`'noindex, follow'`, out of the menu).
21
+ * X7: every moved page and item keeps the old address it was read from, and `importRedirects` lists the redirects from
22
+ * those addresses to the new ones.
17
23
  */
18
24
 
19
25
  /** One item of a list the scan found, in the owner's own words. */
@@ -57,7 +63,17 @@ export interface ImportedPage {
57
63
  readonly title: string;
58
64
  /** Its own text: paragraphs, a blank line between them. A page with none is not moved. */
59
65
  readonly text: string;
60
- /** Its meta description — the line under its name. */
66
+ /** Its meta description — the line under its name in a search result (X6: the page's `seo.description`). */
67
+ readonly description?: string;
68
+ /** X6: its `<title>` — what a search result named it, when the page said (else its name stands). */
69
+ readonly seoTitle?: string;
70
+ /** X6: the old site kept it out of search (`robots: noindex`) — it moves kept out, and out of the menu. */
71
+ readonly noindex?: boolean;
72
+ }
73
+
74
+ /** X6: what search knew of the old home page — the new home page carries its words. */
75
+ export interface ImportedHome {
76
+ readonly seoTitle?: string;
61
77
  readonly description?: string;
62
78
  }
63
79
 
@@ -68,6 +84,8 @@ export interface ImportReading {
68
84
  readonly locale?: `${SiteLocale}`;
69
85
  readonly lists: ReadonlyArray<ImportedList>;
70
86
  readonly pages: ReadonlyArray<ImportedPage>;
87
+ /** X6: the old home page's search words, when it had some. */
88
+ readonly home?: ImportedHome;
71
89
  }
72
90
 
73
91
  export interface ImportPlanInput {
@@ -107,6 +125,66 @@ export function importedPicturesOf(plan: Pick<SitePlan, 'source' | 'contentTypes
107
125
  return [...found];
108
126
  }
109
127
 
128
+ /** X6: a moved page's search words — its old title and line within seo-core's limits, kept out of search when it was. */
129
+ function seoOfImported(title: string | undefined, description: string | undefined, noindex = false): PageSeoPlan | undefined {
130
+ const t = title?.trim() ? fitSeoText(title, SEO_TITLE_MAX) : '';
131
+ const d = description?.trim() ? fitSeoText(description, SEO_DESCRIPTION_MAX) : '';
132
+ const seo: PageSeoPlan = { ...(t ? { title: t } : {}), ...(d ? { description: d } : {}), ...(noindex ? { robots: SEO_ROBOTS_NOINDEX } : {}) };
133
+ return Object.keys(seo).length ? seo : undefined;
134
+ }
135
+
136
+ /** The old address of a list's own page — its items' site and their common path (`https://old.site/blog`), or none. */
137
+ function listAddressOf(list: ImportedList): string | undefined {
138
+ if (!list.path) return undefined;
139
+ try {
140
+ return new URL(list.path, list.items[0].from).href;
141
+ } catch {
142
+ return undefined;
143
+ }
144
+ }
145
+
146
+ /** One redirect an import makes: the old address's path → the page that now holds what it held. */
147
+ export interface ImportRedirect {
148
+ /** The old path (`redirectPath` of the address it was read from). */
149
+ readonly from: string;
150
+ /** The new path — a page's route, or an item's (`/work/blue-bowl`). */
151
+ readonly to: string;
152
+ }
153
+
154
+ /**
155
+ * Bring my site X7: the redirects an import plan makes — every moved page's and real item's old address (its path) to
156
+ * where it now lives, each old path once, in plan order. An address that already IS its new path needs none and is not
157
+ * listed. Whether each may be written (a page that answers there, a chain) is the CMS's question at build time, against
158
+ * the studio as it is (seo-core `redirectRefusal`). A plan read from no site makes none.
159
+ */
160
+ export function importRedirects(plan: Pick<SitePlan, 'source' | 'contentTypes' | 'dataSources' | 'pages'> | null | undefined): ImportRedirect[] {
161
+ if (plan?.source?.kind !== SitePlanSourceKind.Import) return [];
162
+ const out: ImportRedirect[] = [];
163
+ const seen = new Set<string>();
164
+ const add = (address: string | undefined, to: string): void => {
165
+ const from = redirectPath(address);
166
+ const target = redirectPath(to);
167
+ if (!from || !target || from === '/' || from === target || seen.has(from)) return;
168
+ seen.add(from);
169
+ out.push({ from, to: target });
170
+ };
171
+ for (const page of plan.pages ?? []) if (page.importedFrom && !page.routeSource) add(page.importedFrom, page.route);
172
+ for (const type of plan.contentTypes ?? []) {
173
+ const from = type.seed?.importedFrom;
174
+ if (!from?.length) continue;
175
+ const page = (plan.pages ?? []).find(p => p.template === type.name && p.routeSource);
176
+ const source = page && (plan.dataSources ?? []).find(d => d.alias === page.routeSource);
177
+ const lookup = source && 'filterByRouteParam' in source ? source.filterByRouteParam : undefined;
178
+ const values = lookup ? type.seed?.perItem?.[lookup.field] : undefined;
179
+ if (!page || !lookup || !values) continue;
180
+ from.forEach((address, i) => {
181
+ const value = values[i];
182
+ if (typeof value === 'string' && value) add(address, page.route.replace(`:${lookup.routeParam}`, encodeURIComponent(value)));
183
+ });
184
+ }
185
+ return out;
186
+ }
187
+
110
188
  /** The patterns an import places (contract `site.patterns`). */
111
189
  export enum ImportPattern {
112
190
  PageHeader = 'page-header.simple',
@@ -354,8 +432,9 @@ export function planImport(reading: ImportReading, input: ImportPlanInput): Impo
354
432
  const route = routes.claim(base && !routes.has(base) && base !== HOME_ROUTE ? base : `/${importSlug(list.label) || name.toLowerCase()}`);
355
433
  routes.claim(`${route}/:${ITEM_PARAM}`);
356
434
  const key = keys.claim(importSlug(list.label) || name.toLowerCase());
435
+ const listAddress = listAddressOf(list);
357
436
  listPages.push({
358
- key, name: list.label, route, inNav: true, archetype: COLLECTION_ARCHETYPE,
437
+ key, name: list.label, route, inNav: true, archetype: COLLECTION_ARCHETYPE, ...(listAddress ? { importedFrom: listAddress } : {}),
359
438
  sections: [pageHeader(list.label), { pattern: ImportPattern.CardGrid, binding: own.list, without: [...WITHOUT.cardGridHeader] }],
360
439
  });
361
440
  listPages.push({
@@ -378,7 +457,11 @@ export function planImport(reading: ImportReading, input: ImportPlanInput): Impo
378
457
  const body = page.template && typeOfMatched && page.template === typeOfMatched.name && roleField(typeOfMatched, ContentRole.Body)
379
458
  && !sections.some(s => s.pattern === ImportPattern.ItemBody);
380
459
  if (body) sections.splice(Math.max(1, sections.findIndex(s => s.pattern === ImportPattern.ItemHero) + 1), 0, { pattern: ImportPattern.ItemBody });
381
- frame.push({ ...page, sections });
460
+ // X6: the home page carries what search knew of the old one.
461
+ const seo = page.isHome ? seoOfImported(reading.home?.seoTitle, reading.home?.description) : undefined;
462
+ // X7: the template's list page holds the list that took its type's place — its old address redirects here.
463
+ const listAddress = matched && !page.template && templateParts.get(matched.type.name)!.pages.has(page.key) ? listAddressOf(matched.list) : undefined;
464
+ frame.push({ ...page, ...(seo ? { seo } : {}), ...(listAddress ? { importedFrom: listAddress } : {}), sections });
382
465
  }
383
466
 
384
467
  // The owner's pages of words.
@@ -391,9 +474,10 @@ export function planImport(reading: ImportReading, input: ImportPlanInput): Impo
391
474
  if (!base || base === HOME_ROUTE) continue; // the home page is rebuilt from the template
392
475
  if (routes.has(base) && frame.some(p => p.route === base)) continue; // the template's contact page stands for it
393
476
  const route = routes.claim(base);
477
+ const seo = seoOfImported(page.seoTitle || title, page.description, page.noindex);
394
478
  textPages.push({
395
- key: keys.claim(importSlug(base.slice(1)) || importSlug(title) || 'page'), name: title, route, inNav: route.split('/').length === 2,
396
- archetype: ABOUT_ARCHETYPE,
479
+ key: keys.claim(importSlug(base.slice(1)) || importSlug(title) || 'page'), name: title, route, inNav: !page.noindex && route.split('/').length === 2,
480
+ archetype: ABOUT_ARCHETYPE, ...(seo ? { seo } : {}), importedFrom: page.from,
397
481
  sections: [pageHeader(title, page.description?.trim() || undefined), { pattern: ImportPattern.LongForm, slots: { body1: text }, without: [...WITHOUT.longForm] }],
398
482
  });
399
483
  }
@@ -292,6 +292,8 @@ export const PLAN_WIRE_DERIVED: Readonly<Record<string, string>> = {
292
292
  sourceImport: 'the AI never writes an import plan (Bring my site X4 — planImport)',
293
293
  'roles.body': "an imported item's own text (Bring my site X4) — never the model's",
294
294
  'seed.importedFrom': 'the old addresses of real items read from a site (Bring my site X4) — never the model\'s',
295
+ 'page.importedFrom': "the old address a page of the owner's words was read from (Bring my site X7) — never the model's",
296
+ 'pageSeo.robots': "an old page kept out of search (Bring my site X6) — never the model's",
295
297
  design: "the owner's pick (the context)",
296
298
  'plan.film': "the owner's film, set by the build (SC6b)",
297
299
  film: "the owner's film, set by the build (SC6b)",
@@ -6,7 +6,7 @@ import type { LegalContext } from './legal';
6
6
  import { GenerationTier, SitePlan, SitePlanSource } from './site-plan.model';
7
7
  import { SitePlanIssueCode } from './validate-site-plan';
8
8
  import { planSells } from './shop-plan';
9
- import { importedPicturesOf } from './import-plan';
9
+ import { importedPicturesOf, importRedirects } from './import-plan';
10
10
  import type { PictureSupply, TypeLed } from './type-led';
11
11
  import { isPopupNode, POPUP_GLOBAL_ID } from './popup-plan';
12
12
  import { SerializedNode, walkSerialized } from './serialized-node';
@@ -63,6 +63,9 @@ export enum BuildStep {
63
63
  Shop = 'shop',
64
64
  DataSources = 'data-sources',
65
65
  Pages = 'pages',
66
+ /** Bring my site X7: the owner's old addresses answer with a 301 to where each page and item now lives — only in a run
67
+ * whose plan was read from a site and moved something to a new address (`importRedirects`). */
68
+ Redirects = 'redirects',
66
69
  Globals = 'globals',
67
70
  Look = 'look',
68
71
  }
@@ -70,11 +73,14 @@ export enum BuildStep {
70
73
  export const BUILD_STEPS: ReadonlyArray<BuildStep> = Object.values(BuildStep);
71
74
 
72
75
  /** The steps a build of `plan` takes, in order: every one, the shop's only when the plan sells (commerce G1), the imported
73
- * pictures' only when the plan was read from a site that has some (X5). */
76
+ * pictures' only when the plan was read from a site that has some (X5), the redirects' only when it moved an old address
77
+ * (X7). */
74
78
  export function buildStepsOf(plan: unknown): BuildStep[] {
75
79
  const sells = planSells(plan);
76
80
  const pictures = importedPicturesOf(plan as SitePlan).length > 0;
77
- return BUILD_STEPS.filter(step => (step !== BuildStep.Shop || sells) && (step !== BuildStep.ImportPictures || pictures));
81
+ const redirects = importRedirects(plan as SitePlan).length > 0;
82
+ return BUILD_STEPS.filter(step => (step !== BuildStep.Shop || sells) && (step !== BuildStep.ImportPictures || pictures)
83
+ && (step !== BuildStep.Redirects || redirects));
78
84
  }
79
85
 
80
86
  export enum StepState {
@@ -105,6 +111,9 @@ export enum CreatedKind {
105
111
  /** RD3-D3 (a) Replace: a page an earlier Undo kept, moved aside (`/<route>-previous`, a draft) so the plan's page takes
106
112
  * its address — Undo puts it back while it is as the move left it and its address is free (`CreatedRecord.from`). */
107
113
  PageMoved = 'page-moved',
114
+ /** Bring my site X7: a redirect from one of the owner's old addresses (`source: 'import'`) — removed by Undo while it is
115
+ * as the build wrote it. */
116
+ Redirect = 'redirect',
108
117
  Global = 'global',
109
118
  Look = 'look',
110
119
  }
@@ -221,6 +230,10 @@ export enum BuildNoticeCode {
221
230
  * from the owner's news was not written — said once, so the owner knows the news is not on the site and where to
222
231
  * show it (Replace, or the builder). */
223
232
  PopupKept = 'popup-kept',
233
+ /** Bring my site X7: some old addresses were not redirected — a page of the site answers there, or it would chain to
234
+ * another redirect (seo-core `redirectRefusal`); said once with how many, so the owner knows those links land on the
235
+ * page that now stands there (or adds a redirect of their own). */
236
+ RedirectsRefused = 'redirects-refused',
224
237
  }
225
238
 
226
239
  /** RD3-D3 (a): what a build does with a page an earlier Undo kept at an address its plan builds — the header and footer's
@@ -430,6 +443,7 @@ export const buildKeys = {
430
443
  global: (nodeId: string) => `global:${nodeId}`,
431
444
  look: () => 'look',
432
445
  pageMoved: (pageId: string) => `page-moved:${pageId}`,
446
+ redirect: (from: string) => `redirect:${from}`,
433
447
  } as const;
434
448
 
435
449
  /** The id of the page a run made for the plan's home page, or null (not made yet, or no home page). */
@@ -469,6 +483,8 @@ export interface BuildStepFacts {
469
483
  items: number;
470
484
  /** X5: the pictures an import copies from the owner's site (0 = not an import). */
471
485
  pictures: number;
486
+ /** X7: the old addresses an import redirects (0 = not an import, or nothing moved). */
487
+ redirects: number;
472
488
  /** Commerce G1: sample products for the shop (0 = the plan sells nothing) and their categories. */
473
489
  products: number;
474
490
  categories: number;
@@ -492,6 +508,7 @@ export function buildStepFacts(plan: SitePlan, actions: Readonly<Record<string,
492
508
  contentTypeActions,
493
509
  items: plan.contentTypes.reduce((n, t) => n + (t.seed?.count ?? 0), 0),
494
510
  pictures: importedPicturesOf(plan).length,
511
+ redirects: importRedirects(plan).length,
495
512
  products: plan.shop?.products.length ?? 0,
496
513
  categories: plan.shop?.categories.length ?? 0,
497
514
  pages: plan.pages.length,
@@ -266,6 +266,9 @@ export interface PageSectionPlan {
266
266
  export interface PageSeoPlan {
267
267
  readonly title?: string;
268
268
  readonly description?: string;
269
+ /** Bring my site X6: a page the owner's old site kept out of search moves with `'noindex, follow'` (seo-core
270
+ * `SEO_ROBOTS_OPTIONS`). Only on an import plan; never a model's. */
271
+ readonly robots?: string;
269
272
  }
270
273
 
271
274
  /** The kinds of page a plan is made of (contract `site.archetypes`, L0-2). */
@@ -304,6 +307,9 @@ export interface PagePlan {
304
307
  /** The inferred need this page answers (the Plan screen tags it "we added") — a harness-core need id. */
305
308
  readonly need?: SiteNeedId;
306
309
  readonly seo?: PageSeoPlan;
310
+ /** Bring my site X7: the old address (absolute) this page's words were read from — its redirect starts there
311
+ * (`importRedirects`). Only on an import plan; never a model's. */
312
+ readonly importedFrom?: string;
307
313
  /** The page from patterns — a composed page keeps them as its fallback. */
308
314
  readonly sections: ReadonlyArray<PageSectionPlan>;
309
315
  /** M8 gate 2: the page is composed in the layout language (written with the pages; the layout step fills `layout`). */
@@ -182,6 +182,7 @@ export const SPEC_SITE_PLAN_SHAPE = {
182
182
  "template?": "string — the content type a template page renders one item of",
183
183
  "routeSource?": "string — the single source read by the route param (route.* binds it)",
184
184
  "seo?": "pageSeo",
185
+ "importedFrom?": "string — Bring my site X7: the old address (absolute) a page of the owner's words was read from (generation-core planImport) — its redirect starts there. Only on an import plan; never a model's",
185
186
  "sections": "section[] — the page from patterns; a composed page keeps them as its fallback",
186
187
  "compose?": "boolean — the page is composed in the layout language (M8 gate 2): which pages is the generation’s tier (AW-D23/24) — Basic the home page and at most one other, Award every page that is no per-item or legal page; written with the pages, the layout step fills `layout`",
187
188
  "layout?": "layoutPage — the composed page (the layout step's, never the Pages request's): when present the page is stamped from it and `sections` is not",
@@ -219,7 +220,8 @@ export const SPEC_SITE_PLAN_SHAPE = {
219
220
  },
220
221
  "pageSeo": {
221
222
  "title?": "string ≤ 60 — the page title in search results (absent = the page name · the business)",
222
- "description?": "string ≤ 160 — the line under it (absent = the tagline, else the page and the business)"
223
+ "description?": "string ≤ 160 — the line under it (absent = the tagline, else the page and the business)",
224
+ "robots?": "string — seo-core SEO_ROBOTS_OPTIONS: Bring my site X6, a page the owner's old site kept out of search ('noindex, follow'). Only on an import plan; never a model's"
223
225
  },
224
226
  "section": {
225
227
  "pattern": "string — a non-global pattern id",
@@ -1,7 +1,7 @@
1
1
  import { ARRIVE_IDS, flavorPackById, MOVE_IDS, parseHexColor, PRELOADER_IDS, SCRUB_IDS, SPEC_AXES } from '@vectoriox/iox-ui/design-core';
2
2
  import { formPresetById } from '@vectoriox/iox-ui/forms-core';
3
3
  import { filmScreensFor, normalizeFrameSequence } from '@vectoriox/iox-ui/media-core';
4
- import { SEO_DESCRIPTION_MAX, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
4
+ import { SEO_DESCRIPTION_MAX, SEO_ROBOTS_OPTIONS, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
5
5
 
6
6
  import {
7
7
  BindScope, patternById, patternHasForm, patternLinkSlots, patternNeedsBinding, patternOptionalParts, patternRoleNeeds, patternTakesBinding, patternScopes,
@@ -152,6 +152,7 @@ const DESIGN_KEYS = shapeKeys(SHAPE['design']);
152
152
  const CONTENT_TYPE_KEYS = shapeKeys(SHAPE['contentType']);
153
153
  const ROLE_KEYS = shapeKeys(SHAPE['roles']);
154
154
  const PAGE_SEO_KEYS = shapeKeys(SHAPE['pageSeo']);
155
+ const SEO_ROBOTS_KEY = 'robots';
155
156
  const ARRAY_TYPE = 'array';
156
157
  const FIELD_KEYS = shapeKeys(SHAPE['field']);
157
158
  const SLUG_FIELD = 'slug';
@@ -586,6 +587,7 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
586
587
  const archetype = c.string(raw, 'archetype', path, false);
587
588
  if (archetype && !has(PAGE_ARCHETYPES, archetype)) c.add(SitePlanIssueCode.Archetype, `${path}.archetype`, `"${archetype}" is not a page type (${Object.keys(PAGE_ARCHETYPES).join(', ')})`);
588
589
  validatePageSeo(c, raw['seo'], `${path}.seo`);
590
+ c.string(raw, IMPORTED_FROM, path, false);
589
591
  const need = c.string(raw, 'need', path, false);
590
592
  if (need && !(SITE_NEED_IDS as ReadonlyArray<string>).includes(need)) c.add(SitePlanIssueCode.UnknownNeed, `${path}.need`, `"${need}" is not a need (${SITE_NEED_IDS.join(', ')})`);
591
593
 
@@ -753,7 +755,9 @@ function validatePageSeo(c: Collector, seo: unknown, path: string): void {
753
755
  const limits: Readonly<Record<string, number>> = { title: SEO_TITLE_MAX, description: SEO_DESCRIPTION_MAX };
754
756
  for (const key of PAGE_SEO_KEYS) {
755
757
  const value = c.string(seo, key, path, false);
756
- if (value && value.length > limits[key]) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `${value.length} characters — a search result shows ${limits[key]}`);
758
+ if (!value) continue;
759
+ if (key in limits && value.length > limits[key]) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `${value.length} characters — a search result shows ${limits[key]}`);
760
+ if (key === SEO_ROBOTS_KEY && !SEO_ROBOTS_OPTIONS.some(o => o.value === value)) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `"${value}" is not a robots choice`);
757
761
  }
758
762
  }
759
763
 
@@ -1,7 +1,7 @@
1
1
  import { DesignChoices, presetChoices, PRELOADER_LEVELS, SCRUB_LEVELS } from '@vectoriox/iox-ui/design-core';
2
2
 
3
3
  import { motionFor, MotionInput } from './motion';
4
- import { RankInput, rankWithReferences, StyleRead } from './rank';
4
+ import { PresetFit, RankedPreset, RankInput, rankWithReferences, StyleRead } from './rank';
5
5
  import { referenceSeed } from './reference-colour';
6
6
 
7
7
  /**
@@ -43,11 +43,31 @@ export interface StartingDesign {
43
43
  referenceColour: boolean;
44
44
  }
45
45
 
46
- /** The look a business starts from: its best-ranked style (with the references' boost), at its defaults. */
47
- export function startingDesign(input: (RankInput & MotionInput) | string | null, read: StyleRead | null = null): StartingDesign | null {
46
+ /**
47
+ * The look a business starts from: its best-ranked style (with the references' boost), at its defaults.
48
+ *
49
+ * iox-ui#154 (the J10 re-score, award-ingredients-plan §7.18 SJ-D10): two sites of one studio with the same kind of
50
+ * business STARTED from the same look (same preset, same seed). `worn` names the styles the studio's other sites already
51
+ * wear (the fingerprints' `preset`); the start skips them and takes the next-ranked style that still fits (never a Poor
52
+ * fit — one the kind of business or the owner advises against). A style the references' colour re-seeds is a look of its own and is
53
+ * not skipped. When every fitting style is worn, the best-ranked one — the owner may always pick any look.
54
+ */
55
+ export function startingDesign(
56
+ input: (RankInput & MotionInput) | string | null,
57
+ read: StyleRead | null = null,
58
+ worn: ReadonlyArray<string> = [],
59
+ ): StartingDesign | null {
48
60
  const rankInput: RankInput & MotionInput = typeof input === 'object' && input !== null ? input : { businessType: input as string | null };
49
- const top = rankWithReferences(rankInput, read)[0];
61
+ const ranked = rankWithReferences(rankInput, read);
62
+ const top = unwornStart(ranked, worn, read) ?? ranked[0];
50
63
  const design = top ? presetDesign(top.id, rankInput, {}, read) : null;
51
64
  if (!top || !design) return null;
52
65
  return { presetId: top.id, design, referenceColour: !!referenceSeed(read, top.id)?.used };
53
66
  }
67
+
68
+ /** The best-ranked style that fits and that no other site of the studio wears (a re-seeded one is its own look). */
69
+ function unwornStart(ranked: ReadonlyArray<RankedPreset>, worn: ReadonlyArray<string>, read: StyleRead | null): RankedPreset | undefined {
70
+ if (!worn.length) return ranked[0];
71
+ const taken = new Set(worn);
72
+ return ranked.find(r => r.fit !== PresetFit.Poor && (!taken.has(r.id) || !!referenceSeed(read, r.id)?.used));
73
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * When an element ARRIVES on the screen — the moment a viewport entrance (`viewportEnter`) plays and a word with no landing
3
+ * to wait for comes in (`onSceneLand`). ONE rule for every interaction runtime: the builder canvas, the engine and
4
+ * scene-core itself. Framework-free; it asks the host's IntersectionObserver.
5
+ *
6
+ * An element arrives once a tenth of IT shows — or a tenth of the SCREEN shows it, whichever comes first. The second
7
+ * half is what a tall element needs: a list of six cards stacked one under another on a phone is three screens tall, so a
8
+ * tenth of it is more than the space a page header leaves below itself, and an entrance waiting for that tenth never
9
+ * plays on the first screen — the visitor sees an empty band where the cards are (vectoriox/iox-ui#156). An element
10
+ * shorter than the screen arrives exactly as before (a tenth of it shows before a tenth of the screen does).
11
+ */
12
+
13
+ /** The share of an element — or of the screen — that must show before the element arrives. */
14
+ export const ARRIVE_SHARE = 0.1;
15
+
16
+ /** The observer that asks "does a tenth of the element show". */
17
+ export const ARRIVE_ELEMENT_OPTIONS: IntersectionObserverInit = { threshold: ARRIVE_SHARE };
18
+ /** The observer that asks "does the element show in the screen less its last tenth" — its top a tenth of the screen up. */
19
+ export const ARRIVE_SCREEN_OPTIONS: IntersectionObserverInit = { threshold: 0, rootMargin: `0px 0px -${ARRIVE_SHARE * 100}% 0px` };
20
+
21
+ /**
22
+ * Watch `el` arrive and leave: `onChange(true)` as it arrives (either half of the rule), `onChange(false)` as it leaves
23
+ * (neither half holds), each only when the answer changes. Returns the way to let go — or null when the host has no
24
+ * IntersectionObserver (an old browser), so the caller keeps its own stand-in.
25
+ */
26
+ export function watchArrival(el: Element, onChange: (arrived: boolean) => void, host: Window = window): (() => void) | null {
27
+ const Observer = (host as Window & { IntersectionObserver?: typeof IntersectionObserver }).IntersectionObserver;
28
+ if (!Observer) return null;
29
+ const seen = { element: false, screen: false };
30
+ let arrived = false;
31
+ const watch = (half: keyof typeof seen, options: IntersectionObserverInit): IntersectionObserver => {
32
+ const io = new Observer(entries => {
33
+ const entry = entries.filter(e => e.target === el).pop();
34
+ if (!entry) return;
35
+ seen[half] = entry.isIntersecting;
36
+ const now = seen.element || seen.screen;
37
+ if (now === arrived) return;
38
+ arrived = now;
39
+ onChange(now);
40
+ }, options);
41
+ io.observe(el);
42
+ return io;
43
+ };
44
+ const observers = [watch('element', ARRIVE_ELEMENT_OPTIONS), watch('screen', ARRIVE_SCREEN_OPTIONS)];
45
+ return () => observers.forEach(io => io.disconnect());
46
+ }
@@ -4,6 +4,7 @@
4
4
  * composer read the same tracks, frames and recipe; the driver is DOM-only and is the ONE scroll loop.
5
5
  * ⚠️ Consumers wire the usual trio — ng-package raw-ts assets, jest moduleNameMapper, tsconfig paths.
6
6
  */
7
+ export * from './arrival';
7
8
  export * from './scene';
8
9
  export * from './scene-edit';
9
10
  export * from './scene-recipe';
@@ -1,6 +1,7 @@
1
1
  import { SceneRole } from '@vectoriox/iox-ui/composite-core';
2
2
  import { FramePlayer, normalizeFrameSequence, VideoAttribute } from '@vectoriox/iox-ui/media-core';
3
3
 
4
+ import { watchArrival } from './arrival';
4
5
  import { crossesStage, heldProgress, isHoldTrack, trackValueAt, normalizeTracks, SCENE_PHONE_MAX_WIDTH, SceneAttribute, sceneFrame, SceneFrame, scenePlayed, SceneProgress, SceneProp, sceneWordOpacity, sceneWordsLit, SceneTrack } from './scene';
5
6
  import { rangeDistance, rangeProgress, ScrollBox, ScrollRange } from './scroll-range';
6
7
  import { LIGHT_UP_PIECE_CAP, SplitText, splitText } from './split-text';
@@ -133,8 +134,6 @@ export const SCENE_LAND_TRIGGER = 'sceneLand';
133
134
  export const SCENE_LAND_EVENT = 'iox-scene-land';
134
135
  /** Progress short of a landing that still counts as landed: the damping settles onto the scroll, never past it. */
135
136
  const LANDED_SLACK = 1e-4;
136
- /** How much of an element must show before a word with no landing to wait for arrives (the runtimes' viewport entry). */
137
- const ARRIVE_THRESHOLD = 0.1;
138
137
 
139
138
  /**
140
139
  * Where a Scene of steps (each covering the one before once it lands) must stand for step `index` to be in FRONT, or null
@@ -998,14 +997,10 @@ export function onSceneLand(el: HTMLElement, run: () => void, host: Window = win
998
997
  layer.addEventListener(SCENE_LAND_EVENT, heard);
999
998
  offs.push(() => layer.removeEventListener(SCENE_LAND_EVENT, heard));
1000
999
  }
1001
- const Observer = (host as Window & { IntersectionObserver?: typeof IntersectionObserver }).IntersectionObserver;
1002
- if (Observer) {
1003
- const io = new Observer(entries => {
1004
- // Where a driver plays the travel it decides; the viewport only stands in where none does.
1005
- if (entries.some(entry => entry.isIntersecting) && !(layer && landingDriverOf(layer))) go();
1006
- }, { threshold: ARRIVE_THRESHOLD });
1007
- io.observe(el);
1008
- offs.push(() => io.disconnect());
1000
+ // Where a driver plays the travel it decides; the viewport only stands in where none does (`watchArrival`'s rule).
1001
+ const unwatch = watchArrival(el, arrived => { if (arrived && !(layer && landingDriverOf(layer))) go(); }, host);
1002
+ if (unwatch) {
1003
+ offs.push(unwatch);
1009
1004
  } else {
1010
1005
  // No observer to ask (an old browser): it stands in place on the next frame unless a driver will land it.
1011
1006
  const frame = host.requestAnimationFrame?.(() => { if (!(layer && landingDriverOf(layer))) go(); });
@@ -124,3 +124,16 @@ function compact<T extends object>(value: Record<string, unknown>): T | undefine
124
124
  }
125
125
  return (Object.keys(out).length ? out : undefined) as T | undefined;
126
126
  }
127
+
128
+ /**
129
+ * Words cut to `max` characters on a word boundary, with an ellipsis only when something was cut — a search result's
130
+ * title (`SEO_TITLE_MAX`) or line (`SEO_DESCRIPTION_MAX`). White space collapses. Shared by the composer (a composed
131
+ * page's words) and Bring my site (an old page's own title and line, X6).
132
+ */
133
+ export function fitSeoText(text: string, max: number): string {
134
+ const clean = text.replace(/\s+/g, ' ').trim();
135
+ if (clean.length <= max) return clean;
136
+ const cut = clean.slice(0, max - 1);
137
+ const at = cut.lastIndexOf(' ');
138
+ return `${(at > max / 2 ? cut.slice(0, at) : cut).trimEnd()}…`;
139
+ }
@@ -14,3 +14,4 @@ export * from './seo.model';
14
14
  export * from './normalize';
15
15
  export * from './tags';
16
16
  export * from './schema';
17
+ export * from './redirects';
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Redirects — an old address that answers with another (Bring my site X7, site-build plan §3l, decision X-D3).
3
+ *
4
+ * ONE rule for the three places that need it: iox-cms refuses a redirect that would shadow a page or loop when it is
5
+ * written (an import's or the owner's own), the SSR engine answers a request with the redirect that matches it before it
6
+ * renders, and generation-core lists the redirects an import makes. Framework-free and pure.
7
+ *
8
+ * A redirect's `from` is a PATH on the studio's own site — exact (`/portfolio/blue-bowl`) or a pattern whose `:name`
9
+ * segments match one segment each (`/portfolio/:slug`); its `to` is a path that may use the same names
10
+ * (`/work/:slug`). Exact redirects win over patterns; the engine follows ONE hop.
11
+ */
12
+
13
+ /** The status a redirect answers with: moved for good (the import's, and the default) or for now. */
14
+ export enum RedirectCode {
15
+ Permanent = 301,
16
+ Temporary = 302,
17
+ }
18
+
19
+ export const REDIRECT_CODES: ReadonlyArray<number> = [RedirectCode.Permanent, RedirectCode.Temporary];
20
+
21
+ /** One redirect, as the engine reads it (`GET api/site/:orgId/redirects`). */
22
+ export interface SiteRedirect {
23
+ from: string;
24
+ to: string;
25
+ code: number;
26
+ }
27
+
28
+ /** Why a redirect is not written — said to the owner, never a silent skip. */
29
+ export enum RedirectRefusal {
30
+ /** `from` or `to` is not a path of this site (`/…`), or `to`'s `:name` is not one `from` has. */
31
+ NotAPath = 'not-a-path',
32
+ /** It would send an address to itself. */
33
+ Same = 'same',
34
+ /** `from` is the address of a page of the site — the page answers there; a redirect would hide it. (An exact old
35
+ * address under a page PATTERN — `/blog/Old-Post` beside `/blog/:slug` — is not: no item answers there yet.) */
36
+ ShadowsPage = 'shadows-page',
37
+ /** `to` is another redirect's `from`, or `from` another's `to` — a chain, or a loop. */
38
+ Loop = 'loop',
39
+ /** Another redirect already starts at this `from`. */
40
+ Taken = 'taken',
41
+ }
42
+
43
+ const MAX_PATH = 2_048;
44
+ const PARAM = /^:[a-z_][a-z0-9_]*$/i;
45
+
46
+ const segmentsOf = (path: string): string[] => path.split('/').filter(Boolean);
47
+ const isParam = (segment: string): boolean => PARAM.test(segment);
48
+
49
+ /**
50
+ * An address as a redirect path: an absolute address's path, or a path — without its query and fragment, with one leading
51
+ * slash, no repeated or trailing slash (`/about/` and `/about` are one address), each segment percent-encoded one way.
52
+ * Null when it is neither. Letter case is kept: `/About` is not `/about`.
53
+ */
54
+ export function redirectPath(address: string | null | undefined): string | null {
55
+ if (typeof address !== 'string') return null;
56
+ let text = address.trim();
57
+ if (!text || text.length > MAX_PATH) return null;
58
+ if (/^https?:\/\//i.test(text)) {
59
+ try {
60
+ text = new URL(text).pathname;
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+ if (!text.startsWith('/') || text.startsWith('//')) return null;
66
+ text = text.split(/[?#]/, 1)[0];
67
+ if (/\s/.test(text)) return null;
68
+ return `/${segmentsOf(text).map(sameEncoding).join('/')}`;
69
+ }
70
+
71
+ /** One segment as a browser sends it: `%d7%90` (a WordPress link) and `%D7%90` (what Chrome asks for) and `א` are one. */
72
+ function sameEncoding(segment: string): string {
73
+ if (isParam(segment)) return segment;
74
+ try {
75
+ return encodeURIComponent(decodeURIComponent(segment));
76
+ } catch {
77
+ return segment;
78
+ }
79
+ }
80
+
81
+ /** The two shapes overlap: some address answers both (a `:name` segment matches any one segment). */
82
+ function overlaps(a: string, b: string): boolean {
83
+ const x = segmentsOf(a);
84
+ const y = segmentsOf(b);
85
+ return x.length === y.length && x.every((s, i) => s === y[i] || isParam(s) || isParam(y[i]));
86
+ }
87
+
88
+ /** `path` against a pattern: the values of its `:name` segments, or null when it does not match. */
89
+ function bind(pattern: string, path: string): Record<string, string> | null {
90
+ const p = segmentsOf(pattern);
91
+ const s = segmentsOf(path);
92
+ if (p.length !== s.length) return null;
93
+ const values: Record<string, string> = {};
94
+ for (let i = 0; i < p.length; i++) {
95
+ if (isParam(p[i])) values[p[i]] = s[i];
96
+ else if (p[i] !== s[i]) return null;
97
+ }
98
+ return values;
99
+ }
100
+
101
+ /**
102
+ * The redirect a request for `path` follows, or null: an exact `from` first, then the first pattern that matches, its
103
+ * `:name` values put into `to`. ONE hop — what `to` answers is the next request's business.
104
+ */
105
+ export function matchRedirect(redirects: ReadonlyArray<SiteRedirect>, path: string): { to: string; code: number } | null {
106
+ const at = redirectPath(path);
107
+ if (!at) return null;
108
+ const exact = redirects.find(r => !segmentsOf(r.from).some(isParam) && redirectPath(r.from) === at);
109
+ if (exact) return { to: exact.to, code: exact.code };
110
+ for (const r of redirects) {
111
+ if (!segmentsOf(r.from).some(isParam)) continue;
112
+ const values = bind(r.from, at);
113
+ if (!values) continue;
114
+ const to = segmentsOf(r.to).map(s => (isParam(s) ? values[s] ?? s : s)).join('/');
115
+ return { to: `/${to}`, code: r.code };
116
+ }
117
+ return null;
118
+ }
119
+
120
+ /** What a new redirect is judged against: the site's page routes (`/work/:slug` included) and the redirects it has. */
121
+ export interface RedirectContext {
122
+ pageRoutes: ReadonlyArray<string>;
123
+ redirects: ReadonlyArray<Pick<SiteRedirect, 'from' | 'to'>>;
124
+ }
125
+
126
+ /**
127
+ * Why `candidate` may not be written, or null. A `from` must not be where a page answers (it would hide the page); a
128
+ * `to` must not be another redirect's `from` and a `from` not another's `to` (no chains, so no loops — the engine
129
+ * follows one hop); one redirect per `from`.
130
+ */
131
+ export function redirectRefusal(candidate: Pick<SiteRedirect, 'from' | 'to'>, context: RedirectContext): RedirectRefusal | null {
132
+ const from = redirectPath(candidate.from);
133
+ const to = redirectPath(candidate.to);
134
+ if (!from || !to || from === '/') return RedirectRefusal.NotAPath;
135
+ const names = new Set(segmentsOf(from).filter(isParam));
136
+ if (segmentsOf(to).some(s => isParam(s) && !names.has(s))) return RedirectRefusal.NotAPath;
137
+ if (from === to) return RedirectRefusal.Same;
138
+ const pattern = segmentsOf(from).some(isParam);
139
+ if (context.pageRoutes.some(route => (pattern ? overlaps(route, from) : redirectPath(route) === from))) return RedirectRefusal.ShadowsPage;
140
+ const others = context.redirects.map(r => ({ from: redirectPath(r.from), to: redirectPath(r.to) }));
141
+ if (others.some(r => r.from === from)) return RedirectRefusal.Taken;
142
+ if (others.some(r => (r.from && overlaps(r.from, to)) || (r.to && overlaps(r.to, from)))) return RedirectRefusal.Loop;
143
+ return null;
144
+ }
@@ -157,6 +157,10 @@ export const SEO_ROBOTS_OPTIONS: ReadonlyArray<{ label: string; value: string }>
157
157
  { label: 'No Index, No Follow', value: 'noindex, nofollow' },
158
158
  ];
159
159
 
160
+ /** A page kept out of search but its links still followed — what a page the owner's old site kept out of search moves
161
+ * with (Bring my site X6). */
162
+ export const SEO_ROBOTS_NOINDEX = 'noindex, follow';
163
+
160
164
  export const SEO_TWITTER_CARD_OPTIONS: ReadonlyArray<{ label: string; value: string }> = [
161
165
  { label: 'Summary', value: 'summary' },
162
166
  { label: 'Summary Large Image', value: 'summary_large_image' },