@vectoriox/iox-ui 5.162.0 → 5.163.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/actions-core/index.d.ts +171 -3
- package/assist-core/index.d.ts +3 -2
- package/composite-core/index.d.ts +185 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +243 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +6 -5
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +404 -163
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +56 -5
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +140 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +80 -23
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +383 -10
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +46 -5
- package/harness-core/index.d.ts +132 -2
- package/index.d.ts +105 -3
- package/package.json +1 -1
- package/scene-core/index.d.ts +44 -12
- package/src/actions-core/popup-arrival.ts +328 -0
- package/src/actions-core/public-api.ts +1 -0
- package/src/assist-core/media-generate.ts +6 -5
- package/src/composite-core/popup.ts +285 -0
- package/src/composite-core/public-api.ts +1 -0
- package/src/generation-core/ai-run.ts +65 -2
- package/src/generation-core/pictures.ts +4 -3
- package/src/harness-core/business-types.ts +2 -0
- package/src/harness-core/harness-spec.generated.ts +83 -0
- package/src/harness-core/popup-stance.ts +111 -0
- package/src/harness-core/public-api.ts +1 -0
- package/src/scene-core/scroll-driver.ts +97 -25
- package/styles/iox-design.css +121 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AiEntitlementsView, AiFeature, AiModelEntry, AiRefusal, AiRefusalCode, AiStep, AiTokenPrice, ArtDirection, PICTURE_ASPECTS, PictureReview, WordsArea,
|
|
3
|
-
AI_STEP_FEATURE, aiModelStep, aiRefusalNext, artDirectionPreamble, creditsOfUsd, emptyAreaPhrase, estimateStepCredits, frameWords, modelCanDo, pictureReviewPasses,
|
|
3
|
+
AI_STEP_FEATURE, aiModelStep, aiRefusalNext, artDirectionPreamble, creditsOfUsd, emptyAreaPhrase, estimateStepCredits, frameWords, modelCanDo, pictureReviewPasses, typicalStepTokens,
|
|
4
4
|
} from '@vectoriox/iox-ui/generation-core';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -247,10 +247,11 @@ export interface GenerateEstimate {
|
|
|
247
247
|
/**
|
|
248
248
|
* The cost shown under the box (A-D15: the owner chooses the cost): every candidate is made once and looked at once.
|
|
249
249
|
* Unlike a site build's pictures (`estimatePictures`) there is NO second try in it — a candidate the review says no to
|
|
250
|
-
* is kept and marked, and the owner decides whether to press again.
|
|
250
|
+
* is kept and marked, and the owner decides whether to press again. `model` = the picture model the press runs on: one
|
|
251
|
+
* picture is counted as its maker bills it at most (`pictureTokensFor`, iox-ui#138); absent, as the step's default model.
|
|
251
252
|
*/
|
|
252
|
-
export function estimateGenerate(count: number, prices: { readonly image: AiTokenPrice; readonly review: AiTokenPrice }): GenerateEstimate {
|
|
253
|
-
const picture = estimateStepCredits(GENERATE_STEPS.picture, prices.image);
|
|
253
|
+
export function estimateGenerate(count: number, prices: { readonly image: AiTokenPrice; readonly review: AiTokenPrice }, model?: string | null): GenerateEstimate {
|
|
254
|
+
const picture = estimateStepCredits(GENERATE_STEPS.picture, prices.image, typicalStepTokens(GENERATE_STEPS.picture, undefined, model));
|
|
254
255
|
const review = estimateStepCredits(GENERATE_STEPS.review, prices.review);
|
|
255
256
|
const n = Math.max(0, Math.floor(count));
|
|
256
257
|
return { count: n, picture, review, each: creditsOfUsd((picture + review) / 100), total: creditsOfUsd((n * (picture + review)) / 100) };
|
|
@@ -274,7 +275,7 @@ export function generateModelChoices(models: ReadonlyArray<AiModelEntry>, review
|
|
|
274
275
|
const step = aiModelStep(GENERATE_STEPS.picture); // the vetted list names the step whose model this runs on
|
|
275
276
|
return models
|
|
276
277
|
.filter(m => !m.retired && m.steps.includes(step) && modelCanDo(m, step))
|
|
277
|
-
.map(m => ({ id: m.id, label: m.label, recommended: !!m.recommendedFor?.includes(step), each: m.price ? estimateGenerate(1, { image: m.price, review }).each : null }))
|
|
278
|
+
.map(m => ({ id: m.id, label: m.label, recommended: !!m.recommendedFor?.includes(step), each: m.price ? estimateGenerate(1, { image: m.price, review }, m.id).each : null }))
|
|
278
279
|
.sort((a, b) => Number(b.recommended) - Number(a.recommended));
|
|
279
280
|
}
|
|
280
281
|
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { CompositeNode, CompositeNodeFactory, writeProp } from './composite-node';
|
|
2
|
+
import { COLUMN, recipeLang, recipePart, recipeText, ROW, WORDS, ZERO } from './recipe-parts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* THE POPUP (popups-plan.md, PU1; PU-D1…PU-D18) — the owner's own news, arriving once, as ordinary builder nodes. A popup
|
|
6
|
+
* is a Dialog stamped from this ONE recipe (PU-D1): the builder's palette (PU2) and generation-core's composer (PU3) stamp
|
|
7
|
+
* it with their own node factories, so a generated popup and a hand-placed one are the same tree.
|
|
8
|
+
*
|
|
9
|
+
* Popup Dialog popup (kind · form · arrive · again · dates — the popup traits below)
|
|
10
|
+
* › Container popup.media? Image (the owner's picture) — `art: picture`
|
|
11
|
+
* › Container popup.content
|
|
12
|
+
* Text popup.eyebrow? (only from a date the owner gave)
|
|
13
|
+
* Heading popup.title (h2, worn as the look's h3 — its smallest heading style)
|
|
14
|
+
* Text popup.body (≤ 160 characters)
|
|
15
|
+
* <form> popup.form? (newsletter: the caller's forms-core newsletter preset)
|
|
16
|
+
* Link popup.action? (ONE quiet action — a page link; a form's Send is its own)
|
|
17
|
+
* › the Dialog's own ✕ (44 × 44, named in the site's language by the runtime)
|
|
18
|
+
*
|
|
19
|
+
* Its LOOK is the site's element styles (dialog, h4, small, link) — never a colour. Its words are the OWNER's (title, body,
|
|
20
|
+
* eyebrow, the action's label), passed in; the recipe's own words are mechanism microcopy only ("Close", "Send").
|
|
21
|
+
* Framework-free: no actions-core import (actions-core reads this module, never the other way).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export enum PopupRole {
|
|
25
|
+
Popup = 'popup',
|
|
26
|
+
Media = 'popup.media',
|
|
27
|
+
Content = 'popup.content',
|
|
28
|
+
Eyebrow = 'popup.eyebrow',
|
|
29
|
+
Title = 'popup.title',
|
|
30
|
+
Body = 'popup.body',
|
|
31
|
+
Form = 'popup.form',
|
|
32
|
+
Action = 'popup.action',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const POPUP_ROLES: ReadonlySet<string> = new Set(Object.values(PopupRole));
|
|
36
|
+
|
|
37
|
+
/** PU-D3: what the popup says (contract POPUP `kind`). Seasonal is not a kind — it is dates on any kind. */
|
|
38
|
+
export enum PopupKind {
|
|
39
|
+
Announcement = 'announcement',
|
|
40
|
+
Offer = 'offer',
|
|
41
|
+
Newsletter = 'newsletter',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** §3b: where it sits (contract POPUP `form`). Only `centred` is modal, and only a newsletter's on a laptop. */
|
|
45
|
+
export enum PopupForm {
|
|
46
|
+
Corner = 'corner',
|
|
47
|
+
Bar = 'bar',
|
|
48
|
+
Centred = 'centred',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** PU-D5: what makes it arrive (contract POPUP `arrive`). `leaving` waits for PU2b (drawn as `time`). */
|
|
52
|
+
export enum PopupArrive {
|
|
53
|
+
Scroll = 'scroll',
|
|
54
|
+
Time = 'time',
|
|
55
|
+
ScrollOrTime = 'scrollOrTime',
|
|
56
|
+
Leaving = 'leaving',
|
|
57
|
+
Button = 'button',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** PU-D6: when it may show again after a close (contract POPUP `again`). "Every page view" is refused. */
|
|
61
|
+
export enum PopupAgain {
|
|
62
|
+
Days = 'days',
|
|
63
|
+
Visit = 'visit',
|
|
64
|
+
Once = 'once',
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The contract's `art`. */
|
|
68
|
+
export enum PopupArt {
|
|
69
|
+
None = 'none',
|
|
70
|
+
Picture = 'picture',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The Dialog traits a popup carries (Bindings ▸ Popup, PU2). Like the menu traits (HI2a) they have NO default: a Dialog
|
|
75
|
+
* without `popupKind` is not a popup and renders exactly as before (R-H4). `modal` is the one Dialog trait the popup
|
|
76
|
+
* adds for every Dialog: absent = modal, so every existing Dialog keeps `showModal()`.
|
|
77
|
+
*/
|
|
78
|
+
export enum PopupTrait {
|
|
79
|
+
Kind = 'popupKind',
|
|
80
|
+
Form = 'popupForm',
|
|
81
|
+
Arrive = 'popupArrive',
|
|
82
|
+
/** `scroll`: the share of the FIRST screen scrolled (default 0.5). */
|
|
83
|
+
Screens = 'popupScreens',
|
|
84
|
+
/** `scroll`: the share of the whole PAGE scrolled instead (a newsletter's 40%). */
|
|
85
|
+
PageShare = 'popupPageShare',
|
|
86
|
+
/** `time`: seconds on the page (visible tab), never under 3. */
|
|
87
|
+
Seconds = 'popupSeconds',
|
|
88
|
+
Again = 'popupAgain',
|
|
89
|
+
/** `again: days`: how many (default 30). */
|
|
90
|
+
Days = 'popupDays',
|
|
91
|
+
/** PU-D18: whole days, `YYYY-MM-DD`, on the visitor's clock. */
|
|
92
|
+
ShowFrom = 'popupFrom',
|
|
93
|
+
ShowUntil = 'popupUntil',
|
|
94
|
+
/** "Show it again to everyone" raises it; a remembered close of an older version is forgotten. */
|
|
95
|
+
Version = 'popupVersion',
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A Dialog's own trait: false = non-modal (`showPopover()`, the page stays usable). Absent = modal (as ever). */
|
|
99
|
+
export const DIALOG_MODAL_TRAIT = 'modal';
|
|
100
|
+
|
|
101
|
+
/** The attributes a popup renders on its `<dialog>` — read by the shared CSS (placement, motion) and the popup runtime. */
|
|
102
|
+
export enum PopupAttribute {
|
|
103
|
+
Kind = 'data-iox-popup',
|
|
104
|
+
Form = 'data-iox-popup-form',
|
|
105
|
+
Arrive = 'data-iox-popup-arrive',
|
|
106
|
+
Screens = 'data-iox-popup-screens',
|
|
107
|
+
PageShare = 'data-iox-popup-page',
|
|
108
|
+
Seconds = 'data-iox-popup-seconds',
|
|
109
|
+
Again = 'data-iox-popup-again',
|
|
110
|
+
Days = 'data-iox-popup-days',
|
|
111
|
+
ShowFrom = 'data-iox-popup-from',
|
|
112
|
+
ShowUntil = 'data-iox-popup-until',
|
|
113
|
+
Version = 'data-iox-popup-version',
|
|
114
|
+
/** A non-modal Dialog (a popup's corner / bar, or `modal: false`): opened with `showPopover()`. */
|
|
115
|
+
NonModal = 'data-iox-dialog-nonmodal',
|
|
116
|
+
/** §8 / R-H8: its words never become the page's search snippet. */
|
|
117
|
+
NoSnippet = 'data-nosnippet',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const POPUP_ATTRIBUTES: ReadonlyArray<string> = Object.values(PopupAttribute);
|
|
121
|
+
|
|
122
|
+
const TRAIT_ATTRIBUTE: ReadonlyArray<readonly [PopupTrait, PopupAttribute]> = [
|
|
123
|
+
[PopupTrait.Arrive, PopupAttribute.Arrive], [PopupTrait.Screens, PopupAttribute.Screens], [PopupTrait.PageShare, PopupAttribute.PageShare],
|
|
124
|
+
[PopupTrait.Seconds, PopupAttribute.Seconds], [PopupTrait.Again, PopupAttribute.Again], [PopupTrait.Days, PopupAttribute.Days],
|
|
125
|
+
[PopupTrait.ShowFrom, PopupAttribute.ShowFrom], [PopupTrait.ShowUntil, PopupAttribute.ShowUntil], [PopupTrait.Version, PopupAttribute.Version],
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const inEnum = <E extends Record<string, string>>(e: E, v: unknown): v is E[keyof E] => typeof v === 'string' && (Object.values(e) as string[]).includes(v);
|
|
129
|
+
const isOff = (v: unknown) => v === false || v === 'false';
|
|
130
|
+
const text = (v: unknown): string => (typeof v === 'number' && Number.isFinite(v) ? String(v) : typeof v === 'string' ? v.trim() : '');
|
|
131
|
+
|
|
132
|
+
/** A popup's form, judged: `centred` only for a newsletter (PU-D2) — any other kind asking for it sits in the corner. */
|
|
133
|
+
export function popupFormOf(kind: unknown, form: unknown): PopupForm {
|
|
134
|
+
const f = inEnum(PopupForm, form) ? form : POPUP_KIND_MIX[inEnum(PopupKind, kind) ? kind : PopupKind.Offer].form;
|
|
135
|
+
return f === PopupForm.Centred && kind !== PopupKind.Newsletter ? PopupForm.Corner : f;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** True when a Dialog opens as a modal: a popup only when its form is `centred`; any other Dialog unless `modal: false`. */
|
|
139
|
+
export function dialogIsModal(get: (name: string) => unknown): boolean {
|
|
140
|
+
const kind = get(PopupTrait.Kind);
|
|
141
|
+
if (inEnum(PopupKind, kind)) return popupFormOf(kind, get(PopupTrait.Form)) === PopupForm.Centred;
|
|
142
|
+
return !isOff(get(DIALOG_MODAL_TRAIT));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The attributes a Dialog renders for the popup and the non-modal opening — ONE function, applied by every renderer
|
|
147
|
+
* through `nodeA11yAttributes` (the engine's string path, its component path, the builder canvas). A plain modal Dialog
|
|
148
|
+
* gets `{}` and renders exactly as before.
|
|
149
|
+
*/
|
|
150
|
+
export function popupDialogAttributes(get: (name: string) => unknown): Record<string, string> {
|
|
151
|
+
const out: Record<string, string> = {};
|
|
152
|
+
if (!dialogIsModal(get)) out[PopupAttribute.NonModal] = '';
|
|
153
|
+
const kind = get(PopupTrait.Kind);
|
|
154
|
+
if (!inEnum(PopupKind, kind)) return out;
|
|
155
|
+
out[PopupAttribute.Kind] = kind;
|
|
156
|
+
out[PopupAttribute.Form] = popupFormOf(kind, get(PopupTrait.Form));
|
|
157
|
+
out[PopupAttribute.NoSnippet] = '';
|
|
158
|
+
for (const [trait, attr] of TRAIT_ATTRIBUTE) {
|
|
159
|
+
const v = text(get(trait));
|
|
160
|
+
if (v) out[attr] = v;
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** §3a + PU-D6: each kind's defaults (contract POPUP `named` — generation-core's spec holds them equal). */
|
|
166
|
+
export const POPUP_KIND_MIX: Readonly<Record<PopupKind, { form: PopupForm; arrive: PopupArrive; again: PopupAgain; art: PopupArt }>> = {
|
|
167
|
+
[PopupKind.Announcement]: { form: PopupForm.Bar, arrive: PopupArrive.Scroll, again: PopupAgain.Visit, art: PopupArt.None },
|
|
168
|
+
[PopupKind.Offer]: { form: PopupForm.Corner, arrive: PopupArrive.ScrollOrTime, again: PopupAgain.Days, art: PopupArt.Picture },
|
|
169
|
+
[PopupKind.Newsletter]: { form: PopupForm.Corner, arrive: PopupArrive.ScrollOrTime, again: PopupAgain.Days, art: PopupArt.None },
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** §3a: when each kind arrives by default (contract POPUP `arrival`). */
|
|
173
|
+
export const POPUP_KIND_ARRIVAL: Readonly<Record<PopupKind, { screens?: number; pageShare?: number; seconds?: number }>> = {
|
|
174
|
+
[PopupKind.Announcement]: { screens: 0.5 },
|
|
175
|
+
[PopupKind.Offer]: { screens: 0.5, seconds: 8 },
|
|
176
|
+
[PopupKind.Newsletter]: { pageShare: 0.4, seconds: 25 },
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/** The recipe's OWN words — mechanism microcopy, in the site's language. The rest is the owner's. */
|
|
180
|
+
const POPUP_WORDS = {
|
|
181
|
+
en: { close: 'Close', send: 'Send', label: { [PopupKind.Announcement]: 'Announcement', [PopupKind.Offer]: 'Offer', [PopupKind.Newsletter]: 'Newsletter' } },
|
|
182
|
+
he: { close: 'סגירה', send: 'שליחה', label: { [PopupKind.Announcement]: 'הודעה', [PopupKind.Offer]: 'הצעה', [PopupKind.Newsletter]: 'ניוזלטר' } },
|
|
183
|
+
} as const;
|
|
184
|
+
|
|
185
|
+
export type PopupWords = (typeof POPUP_WORDS)['en'] | (typeof POPUP_WORDS)['he'];
|
|
186
|
+
|
|
187
|
+
/** The popup's mechanism words in `lang` (English for any language it does not speak yet). */
|
|
188
|
+
export function popupWords(lang: string | null | undefined = 'en'): PopupWords {
|
|
189
|
+
return POPUP_WORDS[recipeLang(lang)];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
enum Style {
|
|
193
|
+
Dialog = 'dialog',
|
|
194
|
+
/** The look's smallest heading style (there is no h4 element style): the plan's "h4-sized" title. */
|
|
195
|
+
Title = 'h3',
|
|
196
|
+
Body = 'small',
|
|
197
|
+
Eyebrow = 'eyebrow',
|
|
198
|
+
Link = 'link',
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** §6: a heading of at most this many words; a body of at most this many characters (the gate judges stored ones). */
|
|
202
|
+
export const POPUP_TITLE_MAX_WORDS = 6;
|
|
203
|
+
export const POPUP_BODY_MAX_CHARS = 160;
|
|
204
|
+
|
|
205
|
+
export interface PopupRecipeOptions {
|
|
206
|
+
kind?: PopupKind;
|
|
207
|
+
/** The site's language — the ✕'s name and the Dialog's label fall back to it. */
|
|
208
|
+
lang?: string | null;
|
|
209
|
+
/** The owner's words. Empty words stay empty (the Publishable gate blocks an empty title — never invented). */
|
|
210
|
+
title?: string;
|
|
211
|
+
body?: string;
|
|
212
|
+
/** Only from a date the owner gave ("Until 30 November"). */
|
|
213
|
+
eyebrow?: string;
|
|
214
|
+
/** The ONE action: a link to a page of the site, with its words. No route = no action (an announcement may have none). */
|
|
215
|
+
actionLabel?: string;
|
|
216
|
+
actionRoute?: string | null;
|
|
217
|
+
/** The owner's picture (`art: picture`); '' = the DS3 empty-image box ("Add image"). */
|
|
218
|
+
imageSrc?: string;
|
|
219
|
+
imageAlt?: string;
|
|
220
|
+
/** Overrides of the kind's mix. */
|
|
221
|
+
form?: PopupForm;
|
|
222
|
+
arrive?: PopupArrive;
|
|
223
|
+
again?: PopupAgain;
|
|
224
|
+
art?: PopupArt;
|
|
225
|
+
/** A newsletter's form — the caller's forms-core newsletter preset (with the AW-D15 legal line), stamped by the caller's
|
|
226
|
+
* own factory; it carries its own Send. */
|
|
227
|
+
newsletterForm?: CompositeNode | null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The popup — ONE root. Pure over the factory: the builder and the composer get the same tree. */
|
|
231
|
+
export function buildPopupRecipe(create: CompositeNodeFactory, options: PopupRecipeOptions = {}): CompositeNode {
|
|
232
|
+
const kind = options.kind ?? PopupKind.Offer;
|
|
233
|
+
const mix = POPUP_KIND_MIX[kind];
|
|
234
|
+
const form = popupFormOf(kind, options.form ?? mix.form);
|
|
235
|
+
const art = form === PopupForm.Bar ? PopupArt.None : options.art ?? mix.art;
|
|
236
|
+
const words = popupWords(options.lang);
|
|
237
|
+
const title = options.title?.trim() ?? '';
|
|
238
|
+
const bar = form === PopupForm.Bar;
|
|
239
|
+
|
|
240
|
+
const picture = art === PopupArt.Picture;
|
|
241
|
+
// The dialog style's padding holds, except around a picture: the picture runs to the card's edge, the words keep the pad.
|
|
242
|
+
const { padding: _rowPad, ...row } = ROW;
|
|
243
|
+
const root = recipePart(create, 'popup', 'Dialog', PopupRole.Popup, Style.Dialog, {}, `Popup — ${words.label[kind]}`,
|
|
244
|
+
bar ? { ...row, width: '100%', maxWidth: '100%', gap: '16px' }
|
|
245
|
+
: { ...row, width: picture ? '560px' : '420px', maxWidth: '100%', alignItems: 'stretch', gap: '0px', ...(picture ? { padding: ZERO } : {}) });
|
|
246
|
+
writeProp(root, 'placement', 'center'); // the popup's own form places it (iox-design.css), never the placement
|
|
247
|
+
writeProp(root, 'closeOnBackdrop', true); // centred only: a click on the scrim is a close (remembered)
|
|
248
|
+
writeProp(root, 'showCloseButton', true);
|
|
249
|
+
writeProp(root, 'ariaLabel', title || words.label[kind]);
|
|
250
|
+
writeProp(root, PopupTrait.Kind, kind);
|
|
251
|
+
writeProp(root, PopupTrait.Form, form);
|
|
252
|
+
writeProp(root, PopupTrait.Arrive, options.arrive ?? mix.arrive);
|
|
253
|
+
writeProp(root, PopupTrait.Again, options.again ?? mix.again);
|
|
254
|
+
|
|
255
|
+
const children: CompositeNode[] = [];
|
|
256
|
+
if (picture) {
|
|
257
|
+
const media = recipePart(create, 'popup-media', 'Container', PopupRole.Media, null, {}, 'Picture',
|
|
258
|
+
{ ...COLUMN, width: '40%', flexShrink: '0', overflow: 'hidden' });
|
|
259
|
+
media.children = [recipePart(create, 'popup-image', 'Image', null, null, { src: options.imageSrc ?? '', alt: options.imageAlt ?? '' }, 'Picture',
|
|
260
|
+
{ width: '100%', height: '100%', minHeight: '160px', objectFit: 'cover', margin: ZERO })];
|
|
261
|
+
children.push(media);
|
|
262
|
+
}
|
|
263
|
+
const content = recipePart(create, 'popup-content', 'Container', PopupRole.Content, null, {}, 'Words',
|
|
264
|
+
bar ? { ...ROW, flexGrow: '1', flexWrap: 'wrap', gap: '4px 16px' }
|
|
265
|
+
: { ...COLUMN, flexGrow: '1', width: 'auto', gap: '8px', ...(picture ? { padding: 'var(--iox-dialog-pad)' } : {}) });
|
|
266
|
+
const parts: CompositeNode[] = [];
|
|
267
|
+
if (options.eyebrow?.trim()) parts.push(recipeText(create, 'popup-eyebrow', PopupRole.Eyebrow, Style.Eyebrow, options.eyebrow.trim(), 'Dates'));
|
|
268
|
+
parts.push(recipePart(create, 'popup-title', 'Heading', PopupRole.Title, Style.Title, { content: title, level: 'h2' }, 'Title', WORDS));
|
|
269
|
+
if (options.body?.trim() || !bar) parts.push(recipeText(create, 'popup-body', PopupRole.Body, Style.Body, options.body?.trim() ?? '', 'Words'));
|
|
270
|
+
if (kind === PopupKind.Newsletter && options.newsletterForm) {
|
|
271
|
+
const f = options.newsletterForm;
|
|
272
|
+
f.role = PopupRole.Form;
|
|
273
|
+
parts.push(f);
|
|
274
|
+
} else if (options.actionRoute) {
|
|
275
|
+
// A popup's action is QUIET — never the page's primary button (§6): the look's link (a Link, the consent banner's
|
|
276
|
+
// privacy link's shape), hugging its words — the column would stretch its box (focus ring, hover) to full width.
|
|
277
|
+
parts.push(recipePart(create, 'popup-action', 'Link', PopupRole.Action, Style.Link,
|
|
278
|
+
{ label: options.actionLabel?.trim() ?? '', linkType: 'page', pageRoute: options.actionRoute }, 'Action',
|
|
279
|
+
{ ...WORDS, alignSelf: 'flex-start' }));
|
|
280
|
+
}
|
|
281
|
+
content.children = parts;
|
|
282
|
+
children.push(content);
|
|
283
|
+
root.children = children;
|
|
284
|
+
return root;
|
|
285
|
+
}
|
|
@@ -248,11 +248,74 @@ export function creditsOfUsd(usd: number): number {
|
|
|
248
248
|
return Math.round(usd * CREDITS_PER_USD * CREDIT_PRECISION) / CREDIT_PRECISION;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
/**
|
|
252
|
-
|
|
251
|
+
/**
|
|
252
|
+
* What a typical request of `step` reads and writes — one part's when the step is asked in parts, else the whole step's.
|
|
253
|
+
* A picture step on a named `model` is counted as that model's maker bills one picture (`pictureTokensFor`, iox-ui#138);
|
|
254
|
+
* with no model named it is the step's own count (its default model's maker).
|
|
255
|
+
*/
|
|
256
|
+
export function typicalStepTokens(step: AiStep, part?: PlanPart, model?: string | null): AiTokenCounts {
|
|
257
|
+
if (model && aiModelStep(step) === AiStep.MakePictures) return pictureTokensFor(model);
|
|
253
258
|
return (part && AI_STEP_PART_TOKENS[step]?.[part]) || AI_STEP_TYPICAL_TOKENS[step];
|
|
254
259
|
}
|
|
255
260
|
|
|
261
|
+
// ── One picture's bill, by who draws it (iox-ui#138) ────────────────────────────────────────────────────────────────
|
|
262
|
+
|
|
263
|
+
/** Who draws a picture model's pictures — how many tokens one picture is billed depends on it, not on its price. */
|
|
264
|
+
export enum AiPictureMaker {
|
|
265
|
+
/** Google's image models (Nano Banana): a 1 K picture is 1,120 image tokens and a short text beside it. */
|
|
266
|
+
Gemini = 'gemini',
|
|
267
|
+
/** Google's Pro image model, which thinks before it draws: the same picture, more text written. */
|
|
268
|
+
GeminiThinking = 'geminiThinking',
|
|
269
|
+
/** OpenAI's image models behind GPT-5 Image: a reasoning model writes, gpt-image draws — far more image tokens. */
|
|
270
|
+
OpenAiImage = 'openaiImage',
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface AiPictureMakerRow {
|
|
274
|
+
readonly maker: AiPictureMaker;
|
|
275
|
+
/** The model ids it draws for — the first row that matches wins. */
|
|
276
|
+
readonly ids: RegExp;
|
|
277
|
+
/** The MOST one picture is billed: what a shown estimate is made of, so the cost shown is never below the charge. */
|
|
278
|
+
readonly tokens: AiTokenCounts;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* One row per maker, the most specific first. Each count is an upper bound, held by `ai-run.spec` against a recorded
|
|
283
|
+
* charge where one exists:
|
|
284
|
+
* - Gemini — the M7 count (`PICTURE_TOKENS`); Nano Banana 2.1 was charged 3.6492 credits on 2026-11-24 (133 in, 359 out,
|
|
285
|
+
* 1,120 image) against 3.915 counted.
|
|
286
|
+
* - Gemini thinking — the same picture with 2,000 written for its thoughts and text (not yet measured; counted high).
|
|
287
|
+
* - OpenAI image — gpt-image writes at most 6,240 image tokens for one picture (1024×1536 at high quality, OpenAI's own
|
|
288
|
+
* table; the model chooses the quality) and GPT-5's reasoning and text beside it are counted at 4,000. GPT-5 Image Mini
|
|
289
|
+
* was charged 4.30365 credits on 2026-11-25 where 1.191 had been shown (iox-ui#138); counted now: 5.967.
|
|
290
|
+
*/
|
|
291
|
+
export const AI_PICTURE_MAKERS: ReadonlyArray<AiPictureMakerRow> = [
|
|
292
|
+
{ maker: AiPictureMaker.GeminiThinking, ids: /^google\/gemini-[\w.-]*pro-image/, tokens: { ...PICTURE_TOKENS, output: 2_000 } },
|
|
293
|
+
{ maker: AiPictureMaker.Gemini, ids: /^google\//, tokens: PICTURE_TOKENS },
|
|
294
|
+
{ maker: AiPictureMaker.OpenAiImage, ids: /^openai\//, tokens: { input: 700, output: 4_000, cacheWrite: 0, cacheRead: 0, imageOutput: 6_240 } },
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
/** The maker of a picture model, or null when no row names it. */
|
|
298
|
+
export function pictureMakerOf(model: string): AiPictureMakerRow | null {
|
|
299
|
+
return AI_PICTURE_MAKERS.find(row => row.ids.test(model)) ?? null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const largestOf = (rows: ReadonlyArray<AiTokenCounts>): AiTokenCounts => rows.reduce((a, b) => ({
|
|
303
|
+
input: Math.max(a.input, b.input), output: Math.max(a.output, b.output),
|
|
304
|
+
cacheWrite: Math.max(a.cacheWrite, b.cacheWrite), cacheRead: Math.max(a.cacheRead, b.cacheRead),
|
|
305
|
+
imageOutput: Math.max(a.imageOutput ?? 0, b.imageOutput ?? 0),
|
|
306
|
+
}));
|
|
307
|
+
|
|
308
|
+
/** Every class at the most any maker bills it — what a picture of a model no row names is counted as. */
|
|
309
|
+
export const PICTURE_TOKENS_UNKNOWN_MAKER: AiTokenCounts = largestOf(AI_PICTURE_MAKERS.map(row => row.tokens));
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The most one picture on `model` is billed. A model no row names (an own key's choice) is counted at every maker's
|
|
313
|
+
* largest count — never below what it may be charged; the cost shown may be high, it is never short.
|
|
314
|
+
*/
|
|
315
|
+
export function pictureTokensFor(model: string): AiTokenCounts {
|
|
316
|
+
return pictureMakerOf(model)?.tokens ?? PICTURE_TOKENS_UNKNOWN_MAKER;
|
|
317
|
+
}
|
|
318
|
+
|
|
256
319
|
/** The credits a typical use of `step` costs on a model of `price` — never typed, always computed (§3d). */
|
|
257
320
|
export function estimateStepCredits(step: AiStep, price: AiTokenPrice, tokens: AiTokenCounts = AI_STEP_TYPICAL_TOKENS[step]): number {
|
|
258
321
|
return creditsOfUsd(costUsd(tokens, price));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compositeOver, parseCssColour, relativeLuminance, Rgb, wcagContrastRatio } from '@vectoriox/iox-ui/design-core';
|
|
2
2
|
|
|
3
|
-
import { AiStep, AiTokenPrice, creditsOfUsd, estimateStepCredits } from './ai-run';
|
|
3
|
+
import { AiStep, AiTokenPrice, creditsOfUsd, estimateStepCredits, typicalStepTokens } from './ai-run';
|
|
4
4
|
import { ArtDirection, artDirectionPreamble } from './art-direction';
|
|
5
5
|
import { ComposedSite } from './compose-site';
|
|
6
6
|
import { jsonBoolean, jsonClosedObject, JsonSchema, jsonText } from './json-schema';
|
|
@@ -309,9 +309,10 @@ export interface PicturesEstimate {
|
|
|
309
309
|
* The cost shown before the owner says yes (I-D4): each picture and its review at the vetted list's prices, plus one
|
|
310
310
|
* second try (a picture and its review) for every `PICTURE_REROLL_EVERY` pictures. The run never spends past `total` —
|
|
311
311
|
* a second try that would cross it is not made — so the shown cost is a ceiling met exactly when every try is used.
|
|
312
|
+
* `model` = the picture model: one picture is counted as its maker bills it at most (iox-ui#138); absent, the default's.
|
|
312
313
|
*/
|
|
313
|
-
export function estimatePictures(count: number, prices: { image: AiTokenPrice; review: AiTokenPrice }): PicturesEstimate {
|
|
314
|
-
const picture = estimateStepCredits(AiStep.MakePictures, prices.image);
|
|
314
|
+
export function estimatePictures(count: number, prices: { image: AiTokenPrice; review: AiTokenPrice }, model?: string | null): PicturesEstimate {
|
|
315
|
+
const picture = estimateStepCredits(AiStep.MakePictures, prices.image, typicalStepTokens(AiStep.MakePictures, undefined, model));
|
|
315
316
|
const review = estimateStepCredits(AiStep.CheckPictures, prices.review);
|
|
316
317
|
const rerolls = pictureRerolls(count);
|
|
317
318
|
return { count, rerolls, picture, review, total: creditsOfUsd(((count + rerolls) * (picture + review)) / 100) };
|
|
@@ -157,6 +157,8 @@ export interface BusinessType {
|
|
|
157
157
|
readonly column: BusinessTypeColumn;
|
|
158
158
|
/** Award §0b + §0b.7 (AW-D26…D32): how a film is suggested to this type, and what it may show (`filmIdeaFor`). */
|
|
159
159
|
readonly film: BusinessTypeFilm;
|
|
160
|
+
/** Popups PU0 (popups-plan §10, PU-D11/PU-D12): offer · ifAsked · never — how a popup is suggested (`popupSuggestion`). */
|
|
161
|
+
readonly popup: string;
|
|
160
162
|
readonly imagery: string;
|
|
161
163
|
/** M7: the picture world a site's made pictures start in (generation-core `artDirectionFor`; contract site.pictureWorlds). */
|
|
162
164
|
readonly world: `${PictureWorld}`;
|