@vectoriox/iox-ui 5.90.2 → 5.91.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 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +38 -3
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +439 -50
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +40 -23
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +139 -19
- package/index.d.ts +18 -1
- package/package.json +1 -1
- package/src/design-core/node-classes.ts +25 -0
- package/src/design-core/token-css.ts +18 -3
- package/src/generation-core/check-layout.ts +84 -25
- package/src/generation-core/compose-layout.ts +7 -0
- package/src/generation-core/compose-site.ts +9 -5
- package/src/generation-core/layout-language.ts +19 -1
- package/src/generation-core/layout-space.ts +260 -0
- package/src/generation-core/pictures.ts +3 -3
- package/src/generation-core/public-api.ts +1 -0
- package/src/generation-core/site-spec.generated.ts +2 -0
- package/src/generation-core/stock-photos.ts +77 -13
|
@@ -118,6 +118,8 @@ export interface StockItemSlot extends StockNeed {
|
|
|
118
118
|
index: number;
|
|
119
119
|
/** The field playing the type's `image` role. */
|
|
120
120
|
field: string;
|
|
121
|
+
/** The item's own name, as words (its `title`): an owner's photo stands under it only when it shows that. */
|
|
122
|
+
subject?: string[];
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
export type StockTarget = StockSlot | StockItemSlot;
|
|
@@ -125,40 +127,102 @@ export type StockTarget = StockSlot | StockItemSlot;
|
|
|
125
127
|
/** Where the owner's photo goes: a slot of a composed section or the image field of a sample item. */
|
|
126
128
|
export type OwnPhotoPlacement = (Pick<StockSlot, 'nodeId' | 'owner'> | { item: Pick<StockItemSlot, 'contentType' | 'index' | 'field'> }) & { url: string };
|
|
127
129
|
|
|
128
|
-
/**
|
|
129
|
-
export
|
|
130
|
-
|
|
130
|
+
/** One of the owner's photos: its address, and what it shows in words (the owner's description or the picture review's). */
|
|
131
|
+
export interface OwnPhoto {
|
|
132
|
+
url: string;
|
|
133
|
+
words?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const ownPhotoOf = (photo: string | OwnPhoto): OwnPhoto => (typeof photo === 'string' ? { url: photo } : photo);
|
|
137
|
+
|
|
138
|
+
/** A title word counts this much more than any other word the item and the photo share. */
|
|
139
|
+
const OWN_NAMED_POINTS = 10;
|
|
140
|
+
/** Without its name, this many of the item's words must be in the photo's. */
|
|
141
|
+
const OWN_SHARED_MIN = 2;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* How well an owner's photo stands under a sample item (M8 demo: the bar's room photos stood under "Martini" and
|
|
145
|
+
* "Negroni"): its words name the item, or share at least two of the item's words. 0 — it does not; a photo with no words
|
|
146
|
+
* never does.
|
|
147
|
+
*/
|
|
148
|
+
export function ownPhotoFit(photo: OwnPhoto, subject: ReadonlyArray<string>, words: ReadonlyArray<string>): number {
|
|
149
|
+
const has = new Set(stockWords(photo.words));
|
|
150
|
+
if (!has.size) return 0;
|
|
151
|
+
const named = subject.filter(w => has.has(w)).length;
|
|
152
|
+
const shared = words.filter(w => has.has(w)).length;
|
|
153
|
+
return named ? OWN_NAMED_POINTS * named + shared : shared >= OWN_SHARED_MIN ? shared : 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The owner's photos that fit an item, best first (their order breaks a tie). */
|
|
157
|
+
function ownPhotosFor(photos: ReadonlyArray<OwnPhoto>, subject: ReadonlyArray<string>, words: ReadonlyArray<string>): OwnPhoto[] {
|
|
158
|
+
return photos.map((photo, i) => ({ photo, i, fit: ownPhotoFit(photo, subject, words) }))
|
|
159
|
+
.filter(f => f.fit > 0)
|
|
160
|
+
.sort((a, b) => b.fit - a.fit || a.i - b.i)
|
|
161
|
+
.map(f => f.photo);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The owner's photos come before any stock or sample picture. A composed section's empty picture takes them in order and
|
|
166
|
+
* never repeats one. A sample item takes only one that shows it (`ownPhotoFit`), never twice in one type's samples; an
|
|
167
|
+
* item none fits keeps its sample picture or goes on to the library (`rest`) — never an unrelated photo under its name.
|
|
168
|
+
*/
|
|
169
|
+
export function planOwnPhotos(slots: ReadonlyArray<StockTarget>, photos: ReadonlyArray<string | OwnPhoto>): { placements: OwnPhotoPlacement[]; rest: StockTarget[] } {
|
|
170
|
+
const own = photos.map(ownPhotoOf).filter(p => !!p.url);
|
|
171
|
+
if (!own.length) return { placements: [], rest: [...slots] };
|
|
131
172
|
const placements: OwnPhotoPlacement[] = [];
|
|
132
173
|
const rest: StockTarget[] = [];
|
|
174
|
+
const shown = new Map<string, Set<string>>();
|
|
133
175
|
let next = 0;
|
|
134
176
|
for (const slot of slots) {
|
|
135
177
|
if (slot.kind === StockSlotKind.Section) {
|
|
136
|
-
if (next <
|
|
178
|
+
if (next < own.length) placements.push({ nodeId: slot.nodeId, owner: slot.owner, url: own[next++].url });
|
|
137
179
|
else rest.push(slot);
|
|
138
|
-
|
|
139
|
-
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const group = shown.get(slot.contentType) ?? new Set<string>();
|
|
183
|
+
const best = ownPhotosFor(own.filter(p => !group.has(p.url)), slot.subject ?? [], slot.words)[0];
|
|
184
|
+
if (!best) {
|
|
185
|
+
rest.push(slot);
|
|
186
|
+
continue;
|
|
140
187
|
}
|
|
188
|
+
group.add(best.url);
|
|
189
|
+
shown.set(slot.contentType, group);
|
|
190
|
+
placements.push({ item: { contentType: slot.contentType, index: slot.index, field: slot.field }, url: best.url });
|
|
141
191
|
}
|
|
142
192
|
return { placements, rest };
|
|
143
193
|
}
|
|
144
194
|
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Each marked sample's gallery shows the owner's photos that fit the item (`ownPhotoFit`) instead of bundled samples; an
|
|
197
|
+
* item none fits keeps its samples.
|
|
198
|
+
*/
|
|
199
|
+
export function applyOwnPhotoGalleries(plan: Pick<SitePlan, 'contentTypes'>, items: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>, photos: ReadonlyArray<string | OwnPhoto>): number {
|
|
200
|
+
const own = photos.map(ownPhotoOf).filter(p => !!p.url);
|
|
201
|
+
if (!own.length) return 0;
|
|
148
202
|
let changed = 0;
|
|
149
203
|
for (const type of plan.contentTypes) {
|
|
150
204
|
const field = roleField(type, ContentRole.Gallery);
|
|
151
205
|
if (!field) continue;
|
|
152
|
-
(items[type.name] ?? []).forEach(
|
|
206
|
+
(items[type.name] ?? []).forEach(item => {
|
|
153
207
|
const list = item[field];
|
|
154
208
|
if (!item['isSample'] || !Array.isArray(list)) return;
|
|
155
|
-
|
|
209
|
+
const { subject, words } = itemWords(type, item);
|
|
210
|
+
const fitting = ownPhotosFor(own, subject, words);
|
|
211
|
+
if (!fitting.length) return;
|
|
212
|
+
let next = 0;
|
|
213
|
+
item[field] = list.map(value => (parseSampleImageRef(value) === null ? value : fitting[next++ % fitting.length].url));
|
|
156
214
|
changed++;
|
|
157
215
|
});
|
|
158
216
|
}
|
|
159
217
|
return changed;
|
|
160
218
|
}
|
|
161
219
|
|
|
220
|
+
/** A sample item's words: its name (`title`) and everything that says what it is (the type's label and name, its summary). */
|
|
221
|
+
function itemWords(type: SitePlan['contentTypes'][number], item: Record<string, unknown>): { subject: string[]; words: string[] } {
|
|
222
|
+
const title = item[roleField(type, ContentRole.Title) ?? ''];
|
|
223
|
+
return { subject: stockWords(title), words: stockWords(type.label, type.name, title, item[roleField(type, ContentRole.Summary) ?? '']) };
|
|
224
|
+
}
|
|
225
|
+
|
|
162
226
|
/** Where a photo may not appear twice: one page; one content type's samples (a list shows them together). */
|
|
163
227
|
export function stockGroupOf(target: StockTarget): string {
|
|
164
228
|
return target.kind === StockSlotKind.Section ? `page:${target.owner}` : `items:${target.contentType}`;
|
|
@@ -216,10 +280,10 @@ export function stockItemSlots(plan: Pick<SitePlan, 'contentTypes'>, composed: P
|
|
|
216
280
|
for (const type of plan.contentTypes) {
|
|
217
281
|
const field = roleField(type, ContentRole.Image);
|
|
218
282
|
if (!field) continue;
|
|
219
|
-
const words = (item: Record<string, unknown>) => [type.label, type.name, ...[ContentRole.Title, ContentRole.Summary].map(r => item[roleField(type, r) ?? ''])];
|
|
220
283
|
(composed.items[type.name] ?? []).forEach((item, index) => {
|
|
221
284
|
if (!item.isSample || parseSampleImageRef(item[field]) === null) return;
|
|
222
|
-
|
|
285
|
+
const { subject, words } = itemWords(type, item);
|
|
286
|
+
out.push({ kind: StockSlotKind.Item, contentType: type.name, index, field, intent: StockIntent.Product, aspect: STOCK_ITEM_ASPECT, words, subject });
|
|
223
287
|
});
|
|
224
288
|
}
|
|
225
289
|
return out;
|