@vectoriox/iox-ui 5.205.0 → 5.206.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.
Files changed (48) hide show
  1. package/data-core/index.d.ts +13 -4
  2. package/design-core/index.d.ts +269 -6
  3. package/fesm2022/vectoriox-iox-ui-data-core.mjs +23 -4
  4. package/fesm2022/vectoriox-iox-ui-data-core.mjs.map +1 -1
  5. package/fesm2022/vectoriox-iox-ui-design-core.mjs +3064 -2682
  6. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  7. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1159 -172
  8. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  9. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +71 -19
  10. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  11. package/fesm2022/vectoriox-iox-ui-scene-core.mjs +32 -4
  12. package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
  13. package/generation-core/index.d.ts +411 -34
  14. package/harness-core/index.d.ts +52 -12
  15. package/package.json +1 -1
  16. package/scene-core/index.d.ts +16 -2
  17. package/src/data-core/placeholder-rows.ts +24 -3
  18. package/src/design-core/colour-eval.ts +22 -0
  19. package/src/design-core/contrast-audit.ts +96 -2
  20. package/src/design-core/design-token.model.ts +2 -0
  21. package/src/design-core/flavor-spec.generated.ts +184 -0
  22. package/src/design-core/font-metrics.ts +14 -1
  23. package/src/design-core/font-vertical.ts +80 -0
  24. package/src/design-core/public-api.ts +1 -0
  25. package/src/design-core/style-presets.ts +20 -1
  26. package/src/design-core/token-css.ts +3 -1
  27. package/src/generation-core/audit-site.ts +5 -3
  28. package/src/generation-core/compose-free.ts +1 -1
  29. package/src/generation-core/compose-layout.ts +172 -22
  30. package/src/generation-core/critic-calibration.ts +26 -9
  31. package/src/generation-core/critic-numbers.ts +259 -0
  32. package/src/generation-core/critic-prompt.ts +53 -6
  33. package/src/generation-core/critic-rubric.generated.ts +6 -6
  34. package/src/generation-core/critic-sheet.ts +112 -1
  35. package/src/generation-core/layout-render-check.ts +35 -2
  36. package/src/generation-core/nav-shape.ts +67 -8
  37. package/src/generation-core/opening-mix.ts +61 -17
  38. package/src/generation-core/public-api.ts +2 -0
  39. package/src/generation-core/social-links.ts +47 -8
  40. package/src/generation-core/stock-photos.ts +149 -14
  41. package/src/generation-core/stock-search.ts +108 -19
  42. package/src/generation-core/stock-subjects.ts +204 -0
  43. package/src/harness-core/business-types.ts +3 -0
  44. package/src/harness-core/harness-spec.generated.ts +54 -15
  45. package/src/harness-core/intake.ts +18 -5
  46. package/src/scene-core/scene.ts +34 -3
  47. package/styles/iox-design.css +41 -2
  48. package/styles/iox-forms.css +7 -6
@@ -8,6 +8,7 @@ import {
8
8
  stockWords,
9
9
  } from './stock-match';
10
10
  import { isPeopleContentType, StockFit, stockMayFill, stockPhotoFits } from './stock-search';
11
+ import { stockNearWords } from './stock-subjects';
11
12
 
12
13
  /**
13
14
  * Stock photos in a built site (AI plan §3g / §3m, I2 + I2.1): a FREE picture from the platform's curated library, copied
@@ -16,9 +17,9 @@ import { isPeopleContentType, StockFit, stockMayFill, stockPhotoFits } from './s
16
17
  * never a person (testimonials, the team — nor a sample item of a type that lists people, iox-ui#172: `stockMayFill`),
17
18
  * never anywhere when the business type says `stock: false` — and, since I2.1
18
19
  * (Doron, 2026-10-28), in the picture of a MARKED sample item (a product, a service, a dish) of a type that may show
19
- * stock. Which photo goes where is chosen by what the slot is about (`stock-match.ts`). Its alt text is
20
- * the provider's description of what it shows (never a claim), and the credit line its licence requires — when it
21
- * requires one — is placed in the footer. Pure: the build step does the copying.
20
+ * stock. Which photo goes where is chosen by what the slot is about (`stock-match.ts`, `stockRelevance`). Its alt text is
21
+ * the place's own words (`stockPhotoAlt`, iox-cms#130 — never the provider's tags), and the credit line its licence
22
+ * requires — when it requires one — is placed in the footer. Pure: the build step does the copying.
22
23
  */
23
24
 
24
25
  /** Where a stock photo comes from (the library's provider). */
@@ -85,7 +86,10 @@ export interface StockPhoto extends StockPhotoTraits {
85
86
  key: string;
86
87
  /** Where the operator's run wrote it (kept for older readers; a build resolves `key` against the library's address). */
87
88
  url: string;
88
- /** What it shows, in the provider's words — the alt text. Never a claim. */
89
+ /**
90
+ * What it shows, in the provider's words, as the library or the search holds it. A PLACED photo (`planStockPhotos`)
91
+ * carries its place's alt instead (`stockPhotoAlt`, iox-cms#130); the provider's words stay on `credit.title`.
92
+ */
89
93
  alt: string;
90
94
  credit: StockCredit;
91
95
  }
@@ -121,6 +125,10 @@ export interface StockSlot extends StockNeed {
121
125
  layout?: string;
122
126
  /** What the section says — its plan section's slots, or a laid section's own words — cut to a prompt's length. */
123
127
  about?: string;
128
+ /** iox-cms#130: the words of the text beside it (its row), in order — what the picture itself is about (`stockNearWords`). */
129
+ near?: string[];
130
+ /** iox-cms#130: the words beside it as written (the row's heading, else its first text) — the photo's alt (`stockPhotoAlt`). */
131
+ caption?: string;
124
132
  }
125
133
 
126
134
  /** The image field of a sample item (a product, a service, a dish) a stock photo may fill. */
@@ -133,6 +141,10 @@ export interface StockItemSlot extends StockNeed {
133
141
  field: string;
134
142
  /** The item's own name, as words (its `title`): an owner's photo stands under it only when it shows that. */
135
143
  subject?: string[];
144
+ /** iox-cms#130: its name's words and (Hebrew) the subjects it names (`stockNearWords`) — the part of the business it shows. */
145
+ near?: string[];
146
+ /** iox-cms#130: its name as written — the photo's alt (`stockPhotoAlt`). */
147
+ caption?: string;
136
148
  /**
137
149
  * iox-ui#172: the item is a PERSON (its type lists people — `isPeopleContentType`): only the owner's photo of them may
138
150
  * stand here, never stock (`stockMayFill`) — a stranger under a team member's name is a made-up fact.
@@ -183,13 +195,17 @@ function ownPhotosFor(photos: ReadonlyArray<OwnPhoto>, subject: ReadonlyArray<st
183
195
  * The owner's photos come before any stock or sample picture. A composed section's empty picture takes them in order and
184
196
  * never repeats one. A sample item takes only one that shows it (`ownPhotoFit`), never twice in one type's samples; an
185
197
  * item none fits keeps its sample picture or goes on to the library (`rest`) — never an unrelated photo under its name.
198
+ *
199
+ * iox-cms#133 (Pro ceramics, 2026-11-29: "Handled Cup" kept the placeholder art between two real photos): a type's samples
200
+ * share its photos by ONE assignment (`matchOwnPhotos`) — the most samples that a photo fits get one, then the best fits —
201
+ * never first come, first served, where an early sample took the only photo a later one could wear.
186
202
  */
187
203
  export function planOwnPhotos(slots: ReadonlyArray<StockTarget>, photos: ReadonlyArray<string | OwnPhoto>): { placements: OwnPhotoPlacement[]; rest: StockTarget[] } {
188
204
  const own = photos.map(ownPhotoOf).filter(p => !!p.url);
189
205
  if (!own.length) return { placements: [], rest: [...slots] };
190
206
  const placements: OwnPhotoPlacement[] = [];
191
207
  const rest: StockTarget[] = [];
192
- const shown = new Map<string, Set<string>>();
208
+ const matched = matchOwnPhotos(slots.filter((s): s is StockItemSlot => s.kind === StockSlotKind.Item), own);
193
209
  let next = 0;
194
210
  for (const slot of slots) {
195
211
  if (slot.kind === StockSlotKind.Section) {
@@ -197,19 +213,90 @@ export function planOwnPhotos(slots: ReadonlyArray<StockTarget>, photos: Readonl
197
213
  else rest.push(slot);
198
214
  continue;
199
215
  }
200
- const group = shown.get(slot.contentType) ?? new Set<string>();
201
- const best = ownPhotosFor(own.filter(p => !group.has(p.url)), slot.subject ?? [], slot.words)[0];
202
- if (!best) {
216
+ const photo = matched.get(slot);
217
+ if (!photo) {
203
218
  rest.push(slot);
204
219
  continue;
205
220
  }
206
- group.add(best.url);
207
- shown.set(slot.contentType, group);
208
- placements.push({ item: { contentType: slot.contentType, index: slot.index, field: slot.field }, url: best.url });
221
+ placements.push({ item: { contentType: slot.contentType, index: slot.index, field: slot.field }, url: photo.url });
209
222
  }
210
223
  return { placements, rest };
211
224
  }
212
225
 
226
+ /** Per content type (a list shows its samples together, so a photo stands under one of them only): which of the owner's
227
+ * photos each sample wears — the assignment that dresses the most samples, then fits them best (`bestAssignment`). */
228
+ function matchOwnPhotos(slots: ReadonlyArray<StockItemSlot>, own: ReadonlyArray<OwnPhoto>): Map<StockItemSlot, OwnPhoto> {
229
+ const byType = new Map<string, StockItemSlot[]>();
230
+ for (const slot of slots) byType.set(slot.contentType, [...(byType.get(slot.contentType) ?? []), slot]);
231
+ const out = new Map<StockItemSlot, OwnPhoto>();
232
+ for (const group of byType.values()) {
233
+ const fits = group.map(slot => own.map(photo => ownPhotoFit(photo, slot.subject ?? [], slot.words)));
234
+ bestAssignment(fits).forEach((column, row) => { if (column >= 0) out.set(group[row], own[column]); });
235
+ }
236
+ return out;
237
+ }
238
+
239
+ /** Above any total fit: a sample dressed always outweighs a better fit elsewhere. */
240
+ const ASSIGN_FILLED = 1e6;
241
+ /** Tie-breaks far below a fit point (fits are whole numbers): the earlier sample, then the owner's earlier photo. */
242
+ const ASSIGN_ROW_TIE = 1e-3;
243
+ const ASSIGN_COLUMN_TIE = 1e-6;
244
+
245
+ /**
246
+ * Rows (samples) to distinct columns (photos) by their scores (`ownPhotoFit`; 0 = does not fit): the most rows on a column
247
+ * that fits, then the highest total score; a tie goes to the earlier row, then the earlier column. The row's column, or -1.
248
+ * Kuhn–Munkres (the Hungarian method) on a square matrix padded with "takes nothing" columns, O(n²·m) — a type holds a
249
+ * handful of samples and the owner a handful of photos. Exported for its spec.
250
+ */
251
+ export function bestAssignment(scores: ReadonlyArray<ReadonlyArray<number>>): number[] {
252
+ const n = scores.length;
253
+ if (!n) return [];
254
+ const columns = Math.max(0, ...scores.map(r => r.length));
255
+ const m = columns + n;
256
+ const weight = (i: number, j: number): number => {
257
+ const fit = j < columns ? scores[i][j] ?? 0 : 0;
258
+ return fit > 0 ? ASSIGN_FILLED + fit - ASSIGN_ROW_TIE * i - ASSIGN_COLUMN_TIE * j : 0;
259
+ };
260
+ // Minimum cost = maximum weight; 1-based potentials as in the classic formulation (row 0 / column 0 are the sentinels).
261
+ const u = new Array<number>(n + 1).fill(0);
262
+ const v = new Array<number>(m + 1).fill(0);
263
+ const p = new Array<number>(m + 1).fill(0);
264
+ const way = new Array<number>(m + 1).fill(0);
265
+ for (let i = 1; i <= n; i++) {
266
+ p[0] = i;
267
+ let j0 = 0;
268
+ const minv = new Array<number>(m + 1).fill(Infinity);
269
+ const used = new Array<boolean>(m + 1).fill(false);
270
+ do {
271
+ used[j0] = true;
272
+ const i0 = p[j0];
273
+ let delta = Infinity;
274
+ let j1 = 0;
275
+ for (let j = 1; j <= m; j++) {
276
+ if (used[j]) continue;
277
+ const cur = -weight(i0 - 1, j - 1) - u[i0] - v[j];
278
+ if (cur < minv[j]) { minv[j] = cur; way[j] = j0; }
279
+ if (minv[j] < delta) { delta = minv[j]; j1 = j; }
280
+ }
281
+ for (let j = 0; j <= m; j++) {
282
+ if (used[j]) { u[p[j]] += delta; v[j] -= delta; } else minv[j] -= delta;
283
+ }
284
+ j0 = j1;
285
+ } while (p[j0] !== 0);
286
+ do {
287
+ const j1 = way[j0];
288
+ p[j0] = p[j1];
289
+ j0 = j1;
290
+ } while (j0);
291
+ }
292
+ const out = new Array<number>(n).fill(-1);
293
+ for (let j = 1; j <= columns; j++) {
294
+ const row = p[j] - 1;
295
+ if (row >= 0 && (scores[row][j - 1] ?? 0) > 0) out[row] = j - 1;
296
+ }
297
+ return out;
298
+ }
299
+
213
300
  /**
214
301
  * Each marked sample's gallery shows the owner's photos that fit the item (`ownPhotoFit`) instead of bundled samples; an
215
302
  * item none fits keeps its samples.
@@ -241,12 +328,53 @@ function itemWords(type: SitePlan['contentTypes'][number], item: Record<string,
241
328
  return { subject: stockWords(title), words: stockWords(type.label, type.name, title, item[roleField(type, ContentRole.Summary) ?? '']) };
242
329
  }
243
330
 
331
+ /** The longest alt a stock photo is given (a screen reader's sentence, not a paragraph). */
332
+ export const STOCK_ALT_MAX = 125;
333
+
334
+ /** Text as an alt carries it: markup gone, one line, cut at a word to `STOCK_ALT_MAX`. */
335
+ function altText(value: unknown): string {
336
+ if (typeof value !== 'string') return '';
337
+ const text = value.replace(/<[^>]*>/g, ' ').replace(/&nbsp;/g, ' ').replace(/\s+/g, ' ').trim();
338
+ if (text.length <= STOCK_ALT_MAX) return text;
339
+ const cut = text.slice(0, STOCK_ALT_MAX + 1);
340
+ const space = cut.lastIndexOf(' ');
341
+ return (space > STOCK_ALT_MAX / 2 ? cut.slice(0, space) : cut.slice(0, STOCK_ALT_MAX)).replace(/[\s,;:–—-]+$/u, '');
342
+ }
343
+
344
+ /** A place's words as written, for its alt: an item's name; a section picture's heading beside it (`caption`). */
345
+ function captionOf(row: SerializedNode | undefined, skip: string): string {
346
+ if (!row) return '';
347
+ let heading = '';
348
+ let text = '';
349
+ walkSerialized([row], n => {
350
+ if (n.id === skip || typeof n.props['content'] !== 'string') return;
351
+ if (n.type === HEADING && !heading) heading = altText(n.props['content']);
352
+ else if (n.type === TEXT && !text) text = altText(n.props['content']);
353
+ });
354
+ return heading || text;
355
+ }
356
+
357
+ /**
358
+ * The alt of a stock photo in a place (iox-cms#130): the place's OWN words, in the site's language — a sample item's name,
359
+ * the heading (else the text) beside a section's picture, else the first thing its section says. Never the provider's tags
360
+ * (a tag list read aloud is noise, and an English one on a Hebrew site). Nothing written there: '' (a picture that only
361
+ * sets the mood, which a screen reader passes).
362
+ */
363
+ export function stockPhotoAlt(target: Pick<StockSlot, 'caption' | 'about'> | Pick<StockItemSlot, 'caption'>): string {
364
+ const caption = altText(target.caption);
365
+ if (caption) return caption;
366
+ const about = 'about' in target ? target.about ?? '' : '';
367
+ return altText(about.split(' — ')[0].replace(/…$/, ''));
368
+ }
369
+
244
370
  /** Where a photo may not appear twice: one page; one content type's samples (a list shows them together). */
245
371
  export function stockGroupOf(target: StockTarget): string {
246
372
  return target.kind === StockSlotKind.Section ? `page:${target.owner}` : `items:${target.contentType}`;
247
373
  }
248
374
 
249
375
  const TEXT_PROPS: ReadonlyArray<string> = ['content', 'label'];
376
+ const HEADING = 'Heading';
377
+ const TEXT = 'Text';
250
378
 
251
379
  /** The words of a subtree's text (Headings, Text, Links), the given node left out. */
252
380
  function textOf(nodes: ReadonlyArray<SerializedNode>, skip: string): string[] {
@@ -332,10 +460,13 @@ export function stockSlots(plan: SitePlan, composed: Pick<ComposedSite, 'pages'
332
460
  walkSerialized([root], (n, ancestors) => {
333
461
  if (n.type !== 'Image' || !empty.has(n.id) || n.bindings.length) return;
334
462
  const row = ancestors[ancestors.length - 1];
463
+ const beside = row ? textOf([row], n.id) : [];
464
+ const caption = captionOf(row, n.id);
335
465
  out.push({
336
466
  kind: StockSlotKind.Section, nodeId: n.id, owner: page.key, ...read, intent, about,
337
467
  aspect: aspectRatioOf(n.styleProps['aspectRatio']),
338
- words: stockWords(...(row ? textOf([row], n.id) : []), ...sectionWords),
468
+ words: stockWords(...beside, ...sectionWords),
469
+ near: stockNearWords(...beside), ...(caption ? { caption } : {}),
339
470
  });
340
471
  });
341
472
  });
@@ -360,6 +491,7 @@ export function stockItemSlots(plan: Pick<SitePlan, 'contentTypes'>, composed: P
360
491
  out.push({
361
492
  kind: StockSlotKind.Item, contentType: ShopResource.Products, index, field: SHOP_IMAGE_FIELD, intent: StockIntent.Product, aspect: STOCK_ITEM_ASPECT,
362
493
  words: stockWords(product.title, product.category, product.description), subject: stockWords(product.title),
494
+ near: stockNearWords(product.title), ...(altText(product.title) ? { caption: altText(product.title) } : {}),
363
495
  });
364
496
  });
365
497
  for (const type of plan.contentTypes) {
@@ -369,8 +501,10 @@ export function stockItemSlots(plan: Pick<SitePlan, 'contentTypes'>, composed: P
369
501
  (composed.items[type.name] ?? []).forEach((item, index) => {
370
502
  if (!item.isSample || parseSampleImageRef(item[field]) === null) return;
371
503
  const { subject, words } = itemWords(type, item);
504
+ const title = item[roleField(type, ContentRole.Title) ?? ''];
372
505
  out.push({
373
506
  kind: StockSlotKind.Item, contentType: type.name, index, field, intent: StockIntent.Product, aspect: STOCK_ITEM_ASPECT, words, subject,
507
+ near: stockNearWords(title), ...(altText(title) ? { caption: altText(title) } : {}),
374
508
  ...(person ? { person: true } : {}),
375
509
  });
376
510
  });
@@ -459,7 +593,8 @@ export function planStockPhotos<T extends StockTarget>(slots: ReadonlyArray<T>,
459
593
  used.add(best.key);
460
594
  here.add(best.key);
461
595
  shownIn.set(group, here);
462
- placed.set(i, { ...slot, photo: best });
596
+ // iox-cms#130: the photo as placed HERE carries this place's alt — the provider's words stay on `credit.title`.
597
+ placed.set(i, { ...slot, photo: { ...best, alt: stockPhotoAlt(slot) } });
463
598
  }
464
599
  return slots.map((_, i) => placed.get(i)).filter((p): p is StockPlacement<T> => !!p);
465
600
  }
@@ -469,7 +604,7 @@ export function stockCopyKey(photo: Pick<StockPhoto, 'key'>): string {
469
604
  return `media/stock/${photo.key.replace(/[^a-zA-Z0-9._-]+/g, '-')}`;
470
605
  }
471
606
 
472
- /** Put the studio's copy of each photo into its slot (src + the provider's alt). Returns the nodes changed. */
607
+ /** Put the studio's copy of each photo into its slot (src + its alt: the place's words, `stockPhotoAlt`). Returns the nodes changed. */
473
608
  export function applyStockPhotos(trees: ReadonlyArray<SerializedNode>, placed: ReadonlyArray<{ nodeId: string; url: string; alt: string }>): number {
474
609
  const byId = new Map(placed.map(p => [p.nodeId, p]));
475
610
  let changed = 0;
@@ -4,6 +4,9 @@ import {
4
4
  stockWord, stockWords,
5
5
  } from './stock-match';
6
6
  import type { StockTarget } from './stock-photos';
7
+ import {
8
+ STOCK_FACET_VOCABULARY, STOCK_GENERIC_WORDS, STOCK_UNRELATED_WORDS, stockFacetsOf, stockPlaceNamesIn, stockTagPhrases,
9
+ } from './stock-subjects';
7
10
 
8
11
  /**
9
12
  * What a build may ask a stock provider, and what it may take from the answer (AI plan §3g-live; iox-cms#123,
@@ -94,17 +97,17 @@ export const STOCK_TRADE_WORDS: Readonly<Record<string, ReadonlyArray<string>>>
94
97
  vet: ['cat', 'puppy', 'kitten', 'veterinarian', 'paw', 'animal'],
95
98
  restaurant: ['dining', 'dinner', 'dish', 'meal', 'plate', 'cuisine', 'cooking', 'gourmet', 'table'],
96
99
  'cafe-bakery': ['espresso', 'cappuccino', 'latte', 'barista', 'croissant', 'pastry', 'cake', 'bread', 'muffin', 'dessert', 'breakfast', 'brunch', 'cookie'],
97
- 'bar-winery': ['beer', 'whiskey', 'whisky', 'vineyard', 'grape', 'barrel', 'pub', 'bartender', 'glass'],
100
+ 'bar-winery': ['beer', 'whiskey', 'whisky', 'vineyard', 'grape', 'barrel', 'pub', 'bartender', 'glass', 'tap', 'draft'],
98
101
  boutique: ['dress', 'apparel', 'garment', 'outfit', 'shoe', 'handbag', 'textile', 'wardrobe'],
99
102
  florist: ['rose', 'tulip', 'blossom', 'floral', 'peony', 'orchid', 'succulent', 'greenery', 'vase'],
100
103
  'home-goods': ['sofa', 'chair', 'table', 'lamp', 'interior', 'cushion', 'armchair', 'shelf', 'vase'],
101
- consultant: ['meeting', 'business', 'planning', 'presentation', 'chart', 'office', 'desk', 'teamwork'],
102
- coach: ['meeting', 'conversation', 'notebook', 'goal', 'growth', 'motivation'],
104
+ consultant: ['meeting', 'business', 'planning', 'presentation', 'chart', 'office', 'desk', 'teamwork', 'laptop', 'computer'],
105
+ coach: ['meeting', 'conversation', 'notebook', 'goal', 'growth', 'motivation', 'laptop'],
103
106
  'law-accounting': ['justice', 'court', 'judge', 'gavel', 'contract', 'notary', 'tax', 'finance', 'paperwork', 'document', 'signature', 'desk', 'agreement'],
104
107
  nonprofit: ['donation', 'solidarity', 'fundraising', 'charity'],
105
108
  'venue-events': ['banquet', 'ballroom', 'celebration', 'reception', 'ceremony', 'catering', 'party'],
106
109
  'hotel-bnb': ['bedroom', 'bed', 'suite', 'resort', 'hospitality', 'lobby', 'pillow', 'accommodation', 'villa', 'inn', 'hostel'],
107
- classes: ['classroom', 'education', 'learning', 'student', 'study', 'piano', 'guitar', 'blackboard'],
110
+ classes: ['classroom', 'education', 'learning', 'student', 'study', 'piano', 'guitar', 'blackboard', 'laptop', 'computer'],
108
111
  };
109
112
 
110
113
  /**
@@ -194,20 +197,34 @@ export function stockSearchTerm(type: Pick<StockSearchType, 'label' | 'match'>):
194
197
  const SUBJECT_VOCABULARY: ReadonlyMap<StockSubject, ReadonlyMap<string, string>> = new Map(
195
198
  (Object.values(StockSubject) as StockSubject[]).map(subject => [subject, new Map(STOCK_SUBJECT_WORDS[subject].map(w => [stockWord(w), w]))]),
196
199
  );
200
+ /** Every subject word, as compared → as asked. */
201
+ const ALL_SUBJECT_VOCABULARY: ReadonlyMap<string, string> = new Map([...SUBJECT_VOCABULARY.values()].flatMap(m => [...m]));
202
+
203
+ /** The words a place's OWN text says: a section's text beside the picture (`near`), an item's name (`near`, else `subject`). */
204
+ export function stockPlaceNear(slot: Pick<StockFitPlace, 'near' | 'subject'>): ReadonlyArray<string> {
205
+ return slot.near?.length ? slot.near : slot.subject ?? [];
206
+ }
197
207
 
198
208
  /**
199
- * The one subject word a place adds to its query: among the words that say what it is about — a sample item's own name
200
- * first, then the words around the place, then the type's imagery line — the first that names a subject its intent takes,
201
- * its best subject first. None: the base query.
209
+ * The one subject word a place adds to its query (iox-cms#130: the place's own subject, never scenery). First, the place's
210
+ * OWN words in the order written (the heading beside it, an item's name — "Breakfast on the roof, the bay below" asks
211
+ * `breakfast`): the first that is a closed subject word (`STOCK_SUBJECT_WORDS`, a part of a business `STOCK_FACETS`, the
212
+ * type's imagery). Else, among the words around the place and the type's imagery line, the first that names a subject its
213
+ * intent takes, its best subject first. Never a scenery word (`STOCK_GENERIC_WORDS` — "hotel view" is answered with resort
214
+ * towers), never another trade's place, never the type's own word. None: the base query.
202
215
  */
203
216
  export function stockSearchFocus(slot: StockTarget, type: StockSearchType | Pick<StockSearchType, 'imagery'>, term: string): string | null {
204
217
  // iox-ui#175: another trade's place word is never the subject ("Boutique law firm" → never "law boutique").
205
218
  const vocabulary = 'label' in type ? stockFitFor(type).vocabulary : new Set<string>();
206
- const words = [...(slot.kind === 'item' ? slot.subject ?? [] : []), ...slot.words, ...stockWords(type.imagery)].filter(w => !foreignTrade(w, vocabulary));
207
219
  const asked = new Set(term.split(' ').map(stockWord));
220
+ const open = (w: string) => !asked.has(w) && !STOCK_GENERIC_WORDS.has(w) && !foreignTrade(w, vocabulary);
221
+ const imagery = stockWords(type.imagery).filter(w => !IMAGERY_NOISE.has(w));
222
+ const own = stockPlaceNear(slot).find(w => open(w) && (ALL_SUBJECT_VOCABULARY.has(w) || STOCK_FACET_VOCABULARY.has(w) || imagery.includes(w)));
223
+ if (own) return ALL_SUBJECT_VOCABULARY.get(own) ?? STOCK_FACET_VOCABULARY.get(own) ?? own;
224
+ const words = [...(slot.kind === 'item' ? slot.subject ?? [] : []), ...slot.words, ...stockWords(type.imagery)].filter(open);
208
225
  for (const subject of STOCK_INTENT_SUBJECTS[slot.intent as StockIntent] ?? []) {
209
226
  const vocabulary = SUBJECT_VOCABULARY.get(subject)!;
210
- const hit = words.find(w => vocabulary.has(w) && !asked.has(w));
227
+ const hit = words.find(w => vocabulary.has(w));
211
228
  if (hit) return vocabulary.get(hit)!;
212
229
  }
213
230
  return null;
@@ -265,22 +282,94 @@ export interface StockFitPlace {
265
282
  readonly intent: string;
266
283
  /** A sample item's own name (`StockItemSlot.subject`): a photo that names it shows the item. */
267
284
  readonly subject?: ReadonlyArray<string>;
285
+ /** iox-cms#130: every word around the place (`StockNeed.words`) — a word a photo carries that they name is never off-subject. */
286
+ readonly words?: ReadonlyArray<string>;
287
+ /** iox-cms#130: the place's OWN words (`stockNearWords`: the text beside it, an item's name) — the part of the business it shows. */
288
+ readonly near?: ReadonlyArray<string>;
289
+ }
290
+
291
+ /** Why a photo may not stand in a place (`stockRelevance`). */
292
+ export enum StockOffSubject {
293
+ /** A never-word or phrase: crime, ruin, a joke, the trade's fears. */
294
+ Never = 'never',
295
+ /** It shows somewhere else on the map ("china, sanya" for a hotel in Haifa). */
296
+ Elsewhere = 'elsewhere',
297
+ /** It shows something no word of the place or the business names: a laptop, a cruise ship, a drain. */
298
+ Unrelated = 'unrelated',
299
+ /** It shows another part of the business than the place names: a manicure under "straightening". */
300
+ OtherPart = 'other-part',
301
+ /** It does not name the business (twice in an opening). */
302
+ NotTheBusiness = 'not-the-business',
303
+ }
304
+
305
+ /** A photo read against a place (`stockRelevance`). */
306
+ export interface StockRelevance {
307
+ /** Why it may not stand here, or null when it may. */
308
+ readonly off: `${StockOffSubject}` | null;
309
+ /** The photo's words (or place names) that said so. */
310
+ readonly offWords: ReadonlyArray<string>;
311
+ /** Distinct words of the photo that name the business (`StockFit.vocabulary`; outside an opening an item's name too). */
312
+ readonly business: number;
313
+ /** Distinct words of the photo the place's own words name (`near`) — how closely it shows THIS place. */
314
+ readonly near: number;
268
315
  }
269
316
 
270
317
  /**
271
- * Whether a photo may stand in a place on a site held to `fit`: none of its words is a never-word or phrase, and a photo no
272
- * operator approved SHOWS THE BUSINESS — it names the type's vocabulary `STOCK_OPENING_TYPE_WORDS` times in an opening and
273
- * `STOCK_PLACE_TYPE_WORDS` times anywhere else (iox-ui#175); an item's own name counts as the business's there (a
274
- * "Bridal makeup" service, a makeup photo). Another trade's place word never counts. An approved library photo was seen for
275
- * its type and needs no word. No type known (`STOCK_FIT_ANY`): the never-words only.
318
+ * THE relevance of a stock photo to a place (iox-cms#130; iox-cms#123, iox-ui#175) — pure and deterministic, no model.
319
+ * In order, a photo is off-subject when:
320
+ * 1. any word is a never-word or phrase of the site (`fit.never`, `STOCK_NEVER_PHRASES`);
321
+ * 2. (unreviewed, type known) it names a place on the map (`STOCK_PLACE_NAMES`) and the place's words name none of them;
322
+ * 3. (unreviewed, type known) it carries a word that shows something else (`STOCK_UNRELATED_WORDS`) that neither the place's
323
+ * words nor the business's vocabulary name;
324
+ * 4. the place's own words name a part of the business (`STOCK_FACETS`: hair, nails, a meal, a bed…) and the photo names
325
+ * other parts but none of those — an approved library photo too: it was seen for its type, never for this place;
326
+ * 5. (unreviewed, type known) it does not name the business `STOCK_OPENING_TYPE_WORDS` times in an opening,
327
+ * `STOCK_PLACE_TYPE_WORDS` times elsewhere (iox-ui#175).
328
+ * No type known (`STOCK_FIT_ANY`): the never-words only. The counts are reported for reading a choice; the ranking among the
329
+ * photos that fit stays `scoreStockPhoto` (which already counts the place's words).
276
330
  */
277
- export function stockPhotoFits(photo: Pick<StockPhotoTraits, 'alt' | 'tags' | 'review'>, slot: StockFitPlace, fit: StockFit = STOCK_FIT_ANY): boolean {
331
+ export function stockRelevance(photo: Pick<StockPhotoTraits, 'alt' | 'tags' | 'review'>, place: StockFitPlace, fit: StockFit = STOCK_FIT_ANY): StockRelevance {
278
332
  const words = stockPhotoWords(photo);
279
- if (words.some(w => fit.never.has(w))) return false;
333
+ const near = new Set(stockPlaceNear(place));
334
+ const counts = { business: businessWordsOf(words, place, fit), near: words.filter(w => near.has(w)).length };
335
+ const off = (why: StockOffSubject, offWords: ReadonlyArray<string>): StockRelevance => ({ off: why, offWords, ...counts });
336
+ const never = words.filter(w => fit.never.has(w));
337
+ if (never.length) return off(StockOffSubject.Never, never);
280
338
  const phrases = photoPhrases(photo);
281
- if (STOCK_NEVER_PHRASES.some(phrase => phrases.some(p => p.includes(` ${phrase} `)))) return false;
282
- if (photo.review?.verdict === StockReviewVerdict.Approved || !fit.vocabulary.size) return true;
283
- return businessWordsOf(words, slot, fit) >= (OPENING_INTENTS.has(slot.intent) ? STOCK_OPENING_TYPE_WORDS : STOCK_PLACE_TYPE_WORDS);
339
+ const neverPhrases = STOCK_NEVER_PHRASES.filter(phrase => phrases.some(p => p.includes(` ${phrase} `)));
340
+ if (neverPhrases.length) return off(StockOffSubject.Never, neverPhrases);
341
+ if (!fit.vocabulary.size) return { off: null, offWords: [], ...counts };
342
+ const reviewed = photo.review?.verdict === StockReviewVerdict.Approved;
343
+ const said = new Set([...(place.words ?? []), ...near, ...(place.subject ?? [])]);
344
+ if (!reviewed) {
345
+ const places = stockPlaceNamesIn(stockTagPhrases(photo.tags?.length ? photo.tags : String(photo.alt ?? '').split(',')));
346
+ if (places.length && !places.some(name => namedBy(name, said))) return off(StockOffSubject.Elsewhere, places);
347
+ const unrelated = words.filter(w => STOCK_UNRELATED_WORDS.has(w) && !said.has(w) && !fit.vocabulary.has(w));
348
+ if (unrelated.length) return off(StockOffSubject.Unrelated, unrelated);
349
+ }
350
+ const parts = stockFacetsOf([...near]);
351
+ const shown = parts.length ? stockFacetsOf(words) : [];
352
+ if (shown.length && !shown.some(f => parts.includes(f))) return off(StockOffSubject.OtherPart, shown);
353
+ if (!reviewed && counts.business < (OPENING_INTENTS.has(place.intent) ? STOCK_OPENING_TYPE_WORDS : STOCK_PLACE_TYPE_WORDS)) {
354
+ return off(StockOffSubject.NotTheBusiness, []);
355
+ }
356
+ return { off: null, offWords: [], ...counts };
357
+ }
358
+
359
+ /**
360
+ * Whether a photo may stand in a place on a site held to `fit` — `stockRelevance` finds nothing off-subject: no never-word
361
+ * or phrase; an unreviewed photo shows the business (its vocabulary twice in an opening, once elsewhere — an item's own
362
+ * name counts there, iox-ui#175), no other place on the map and nothing unrelated (iox-cms#130); and no photo shows another
363
+ * part of the business than the place names. No type known (`STOCK_FIT_ANY`): the never-words only.
364
+ */
365
+ export function stockPhotoFits(photo: Pick<StockPhotoTraits, 'alt' | 'tags' | 'review'>, slot: StockFitPlace, fit: StockFit = STOCK_FIT_ANY): boolean {
366
+ return stockRelevance(photo, slot, fit).off === null;
367
+ }
368
+
369
+ /** A place on the map the place's words name (every word of it; a name too short to compare — `uk` — never). */
370
+ function namedBy(name: string, said: ReadonlySet<string>): boolean {
371
+ const words = stockWords(name);
372
+ return words.length > 0 && words.every(w => said.has(w));
284
373
  }
285
374
 
286
375
  /** How many distinct words of a photo name the business (the opening: its vocabulary; elsewhere an item's name too). */