@aglyn/plugins-ai 1.11.0 → 1.13.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 (74) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-media-create.component.js +1 -1
  3. package/src/lib/components/ai-media-create.component.js.map +1 -1
  4. package/src/lib/components/ai-upsell-dialog.component.js +1 -1
  5. package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
  6. package/src/lib/jobs/ai-job-import-step.d.ts +1 -1
  7. package/src/lib/jobs/ai-job-import-step.js +37 -8
  8. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  9. package/src/lib/jobs/ai-job-privacy-step.js +2 -2
  10. package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
  11. package/src/lib/jobs/ai-site-import-compile.js +27 -37
  12. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  13. package/src/lib/jobs/ai-site-import-look.d.ts +19 -4
  14. package/src/lib/jobs/ai-site-import-look.js +162 -46
  15. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  16. package/src/lib/jobs/ai-theme-brand-inputs.d.ts +12 -0
  17. package/src/lib/jobs/ai-theme-brand-inputs.js +1 -1
  18. package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -1
  19. package/src/lib/layout-language/ai-layout-compiler.js +7 -1
  20. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  21. package/src/lib/model/ai-credit-estimate.d.ts +15 -0
  22. package/src/lib/model/ai-credit-estimate.js +13 -0
  23. package/src/lib/model/ai-credit-estimate.js.map +1 -1
  24. package/src/lib/model/ai-site-import-fidelity.d.ts +46 -3
  25. package/src/lib/model/ai-site-import-fidelity.js +254 -62
  26. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  27. package/src/lib/model/ai-site-import-report.d.ts +7 -0
  28. package/src/lib/model/ai-site-import-report.js +17 -5
  29. package/src/lib/model/ai-site-import-report.js.map +1 -1
  30. package/src/lib/model/ai-site-import.d.ts +75 -4
  31. package/src/lib/model/ai-site-import.js +34 -11
  32. package/src/lib/model/ai-site-import.js.map +1 -1
  33. package/src/lib/model/ai-site-look.d.ts +16 -0
  34. package/src/lib/model/ai-site-look.js +76 -14
  35. package/src/lib/model/ai-site-look.js.map +1 -1
  36. package/src/lib/model/ai-upsell-copy.js +1 -1
  37. package/src/lib/model/ai-upsell-copy.js.map +1 -1
  38. package/src/lib/site-import/fixtures/aglyn-com-recordings.d.ts +2 -1
  39. package/src/lib/site-import/fixtures/aglyn-com-recordings.js +3 -2
  40. package/src/lib/site-import/fixtures/aglyn-com-recordings.js.map +1 -1
  41. package/src/lib/site-import/fixtures/site-import-crawl-recordings.d.ts +5 -0
  42. package/src/lib/site-import/fixtures/site-import-crawl-recordings.js +116 -3
  43. package/src/lib/site-import/fixtures/site-import-crawl-recordings.js.map +1 -1
  44. package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +7 -0
  45. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +15 -0
  46. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  47. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +32 -0
  48. package/src/lib/site-import/fixtures/site-layout-recordings.js +59 -3
  49. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  50. package/src/lib/site-import/fixtures/site-look-slate.d.ts +2 -1
  51. package/src/lib/site-import/fixtures/site-look-slate.js +2 -1
  52. package/src/lib/site-import/fixtures/site-look-slate.js.map +1 -1
  53. package/src/lib/site-import/site-import-crawl.d.ts +9 -1
  54. package/src/lib/site-import/site-import-crawl.js +128 -23
  55. package/src/lib/site-import/site-import-crawl.js.map +1 -1
  56. package/src/lib/site-import/site-import-css.d.ts +89 -1
  57. package/src/lib/site-import/site-import-css.js +468 -28
  58. package/src/lib/site-import/site-import-css.js.map +1 -1
  59. package/src/lib/site-import/site-import-data-forms.d.ts +32 -0
  60. package/src/lib/site-import/site-import-data-forms.js +531 -0
  61. package/src/lib/site-import/site-import-data-forms.js.map +1 -0
  62. package/src/lib/site-import/site-import-html.d.ts +10 -1
  63. package/src/lib/site-import/site-import-html.js +21 -5
  64. package/src/lib/site-import/site-import-html.js.map +1 -1
  65. package/src/lib/site-import/site-import-layout.d.ts +9 -2
  66. package/src/lib/site-import/site-import-layout.js +383 -62
  67. package/src/lib/site-import/site-import-layout.js.map +1 -1
  68. package/src/lib/site-import/site-import-nav.js +17 -3
  69. package/src/lib/site-import/site-import-nav.js.map +1 -1
  70. package/src/lib/site-import/site-import-page.js +5 -0
  71. package/src/lib/site-import/site-import-page.js.map +1 -1
  72. package/src/lib/site-import/site-import-same-page.d.ts +41 -0
  73. package/src/lib/site-import/site-import-same-page.js +108 -0
  74. package/src/lib/site-import/site-import-same-page.js.map +1 -0
@@ -29,7 +29,8 @@ export declare const AI_SITE_IMPORT_LOGO_HEIGHT = 192;
29
29
  export declare const AI_SITE_IMPORT_LOGO_MAX_BYTES: number;
30
30
  type Fetch = (url: string, options: PublicFetchOptions) => Promise<PublicFetchResult>;
31
31
  /**
32
- * The home page and its first stylesheets, read as AglynBot (AGL-4084).
32
+ * The home page and its stylesheets, every one to the crawl's byte budget
33
+ * (AGL-4152), read as AglynBot (AGL-4084).
33
34
  * `headersFor` is asked for every request and every redirect hop, as the
34
35
  * crawl asks it (`aiSiteImportLookHeaders`: the edge header only to the
35
36
  * site's own origins). `null` when the page cannot be read.
@@ -56,7 +57,7 @@ export declare function aiSiteImportBrandColors(page: Pick<AiReferencePage, 'htm
56
57
  * (`aiSiteColors`): aglyn.com's light blue buttons, under white words at
57
58
  * 2.4:1, come out at the deeper blue of its own links.
58
59
  */
59
- export declare function aiSiteImportBrandOf(facts: Pick<SiteImportLookFacts, 'buttonFill' | 'link'> | null | undefined): {
60
+ export declare function aiSiteImportBrandOf(facts: (Pick<SiteImportLookFacts, 'buttonFill' | 'link'> & Pick<Partial<SiteImportLookFacts>, 'palette'>) | null | undefined): {
60
61
  brand: string;
61
62
  accent: string | null;
62
63
  } | null;
@@ -66,8 +67,11 @@ export declare function aiSiteImportBrandOf(facts: Pick<SiteImportLookFacts, 'bu
66
67
  * strongest color as the brand. What the reader found of its look
67
68
  * (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its
68
69
  * links' color as the accent, its eyebrows' own color as the third, and its
69
- * own fonts where the catalog has them (`fonts`). `null` where the source
70
- * showed no color to carry a brand, so the site keeps the theme it has.
70
+ * own fonts where the catalog has them (`fonts`). Its pictures' colors
71
+ * (`pictures`, AGL-4152) stand in for a brand where its facts show none. `null`
72
+ * where nothing showed a color to carry a brand, unless asked to draw the look
73
+ * from the seed alone (`draw`), which the pass does rather than leave the site
74
+ * in the stock theme.
71
75
  *
72
76
  * How the owner asked the site to be finished (AGL-4152) says what else:
73
77
  * - **Keep my site** (`keep`, and an import that names none) pins the rest
@@ -85,6 +89,8 @@ export declare function aiSiteImportStyle(site: AiSiteInspirationSite | null, in
85
89
  facts?: SiteImportLookFacts | null;
86
90
  fonts?: AiSiteStyle['sourceFonts'];
87
91
  finish?: AiSiteImportFinish | null;
92
+ pictures?: readonly string[];
93
+ draw?: boolean;
88
94
  }): AiSiteStyle | null;
89
95
  /** A family's facts, as the theme font catalog answers them. */
90
96
  export type AiSiteImportFontFacts = (family: string) => Promise<ThemeFontFacts | undefined>;
@@ -122,7 +128,16 @@ export interface AiSiteImportLookDeps {
122
128
  writeHost?: (firestore: FirebaseFirestore.Firestore, hostId: string, updates: Record<string, unknown>) => Promise<void>;
123
129
  /** Re-fans the rows every site list reads a site's icon from (AGL-3972), after the look sets one. */
124
130
  syncMemberships?: (orgId: string, hostId: string) => Promise<void>;
131
+ /** A picture in the library's dominant colors (AGL-4152); `null` where it cannot be read. */
132
+ pictureColors?: AiSiteImportPictureColors;
125
133
  }
134
+ /** A picture in the site's library's dominant colors (`dominantColorsFromPixels`). */
135
+ export type AiSiteImportPictureColors = (photo: AiSiteImportPhoto, input: {
136
+ firestore: FirebaseFirestore.Firestore;
137
+ hostId: string;
138
+ orgId: string;
139
+ signal?: AbortSignal;
140
+ }) => Promise<readonly string[] | null>;
126
141
  /** The most pictures the home page's menus bring into the library (AGL-4139). */
127
142
  export declare const AI_SITE_IMPORT_MENU_PICTURES = 4;
128
143
  /** The pictures the home page's menus show (AGL-4139), each once, the first few: a featured card's. */
@@ -43,9 +43,15 @@
43
43
  * listing it was created with: an owner's own words are never written
44
44
  * over.
45
45
  *
46
- * Nothing here fails a wave: a source whose look cannot be read keeps the
47
- * site's theme, and a logo that cannot be brought in leaves the header its
48
- * name.
46
+ * A bare read never leaves the stock theme (AGL-4152). A source with no color
47
+ * of its own to read (no colorful button, link or declared palette) takes its brand from its logo's dominant colorful hue, then its hero photo's,
48
+ * read from the library's copy. With no picture to read either, what its
49
+ * stylesheets use most decides, and with none of that the site still gets the
50
+ * seed's own look for its kind of site, as a guided start with no answer does,
51
+ * and the look says so (`from`). An owner's chosen theme is still kept.
52
+ *
53
+ * Nothing here fails a wave: a logo that cannot be brought in leaves the header
54
+ * its name.
49
55
  *=========================================*/ import { _ as _extends } from "@swc/helpers/_/_extends";
50
56
  import { themeFontFacts } from "@aglyn/aglyn/plugin-manager/plugin-theme-font-catalog";
51
57
  import { syncHostProjectionForMembers } from "@aglyn/tenant-data-admin/server/host-memberships";
@@ -54,17 +60,21 @@ import { aiSiteKindFor } from "../model/ai-site-kinds.js";
54
60
  import { aiHexOklch, aiSiteSeed, aiSiteStyleFor } from "../model/ai-site-look.js";
55
61
  import { aiSiteIsStarterSrc } from "../model/ai-site-photos.js";
56
62
  import { AGLYN_BOT_USER_AGENT, siteImportOrigins } from "../site-import/site-import-crawl.js";
63
+ import { siteImportReadStylesheets } from "../site-import/site-import-css.js";
57
64
  import { NO_SITE_IMPORT_HEADERS, siteImportEdgeHeadersFor } from "../site-import/site-import-edge.js";
65
+ import { siteImportStylesheetLinks } from "../site-import/site-import-html.js";
58
66
  import { bringInSiteImportPhotos, siteImportImageKey, siteImportLogoUrl } from "../site-import/site-import-images.js";
59
67
  import { aiSaveSiteTheme, aiWorkspaceSiteStyles } from "./ai-job-site-look.js";
60
68
  import { aiSiteInspirationLookPins } from "./ai-site-inspiration.js";
61
69
  import { aiSiteInspirationSignals } from "./ai-site-inspiration-signals.js";
62
- import { AI_THEME_BRAND_COLORS_PER_SOURCE, AI_THEME_REFERENCE_MAX_BYTES, AI_THEME_REFERENCE_STYLESHEETS, AI_THEME_STYLESHEET_MAX_BYTES, AI_THEME_THEME_COLOR_WEIGHT, fetchPublicTextDetailed, rankBrandColors, stylesheetUrlsOf } from "./ai-theme-brand-inputs.js";
70
+ import { AI_THEME_BRAND_COLORS_PER_SOURCE, AI_THEME_REFERENCE_MAX_BYTES, AI_THEME_THEME_COLOR_WEIGHT, fetchPublicTextDetailed, logoMediaLocation, rankBrandColors, readLogoColors } from "./ai-theme-brand-inputs.js";
63
71
  /** The height an SVG logo is drawn at as a picture: crisp at twice the header's 40. */ export const AI_SITE_IMPORT_LOGO_HEIGHT = 192;
64
72
  /** The largest logo file read. */ export const AI_SITE_IMPORT_LOGO_MAX_BYTES = 1024 * 1024;
65
73
  /** One read's own clock in the look pass. */ const LOOK_READ_MS = 8000;
74
+ /** The clock on starting the home page's stylesheets' reads: however many it links, a pass waits no longer than this and one read's own. */ const LOOK_SHEETS_MS = 12000;
66
75
  /**
67
- * The home page and its first stylesheets, read as AglynBot (AGL-4084).
76
+ * The home page and its stylesheets, every one to the crawl's byte budget
77
+ * (AGL-4152), read as AglynBot (AGL-4084).
68
78
  * `headersFor` is asked for every request and every redirect hop, as the
69
79
  * crawl asks it (`aiSiteImportLookHeaders`: the edge header only to the
70
80
  * site's own origins). `null` when the page cannot be read.
@@ -84,11 +94,10 @@ import { AI_THEME_BRAND_COLORS_PER_SOURCE, AI_THEME_REFERENCE_MAX_BYTES, AI_THEM
84
94
  } : {})).catch(()=>null);
85
95
  const page = await read(url, AI_THEME_REFERENCE_MAX_BYTES, /text\/html|application\/xhtml\+xml/i);
86
96
  if (!(page == null ? void 0 : page.ok)) return null;
87
- const stylesheets = [];
88
- for (const sheet of stylesheetUrlsOf(page.text, page.url).slice(0, AI_THEME_REFERENCE_STYLESHEETS)){
89
- const css = await read(sheet, AI_THEME_STYLESHEET_MAX_BYTES, /text\/css/i);
90
- if (css == null ? void 0 : css.ok) stylesheets.push(css.text);
91
- }
97
+ const startedAt = Date.now();
98
+ const stylesheets = await siteImportReadStylesheets(siteImportStylesheetLinks(page.text, page.url), (sheet, maxBytes)=>read(sheet, maxBytes, /text\/css|text\/plain/i), {
99
+ outOfTime: ()=>Date.now() - startedAt >= LOOK_SHEETS_MS
100
+ });
92
101
  return {
93
102
  url: page.url,
94
103
  html: page.text,
@@ -147,13 +156,16 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
147
156
  * (`aiSiteColors`): aglyn.com's light blue buttons, under white words at
148
157
  * 2.4:1, come out at the deeper blue of its own links.
149
158
  */ export function aiSiteImportBrandOf(facts) {
159
+ var _ref, _ref1, _ref2;
150
160
  const fill = colorful(facts == null ? void 0 : facts.buttonFill) ? (facts == null ? void 0 : facts.buttonFill).toLowerCase() : null;
151
161
  const link = colorful(facts == null ? void 0 : facts.link) ? (facts == null ? void 0 : facts.link).toLowerCase() : null;
152
- const brand = fill != null ? fill : link;
162
+ // What its root declares its brand to be (AGL-4152), where nothing on its home page draws it.
163
+ const palette = ((_ref = facts == null ? void 0 : facts.palette) != null ? _ref : []).filter(colorful).map((hex)=>hex.toLowerCase());
164
+ const brand = (_ref1 = fill != null ? fill : link) != null ? _ref1 : palette[0];
153
165
  if (!brand) return null;
154
166
  return {
155
167
  brand,
156
- accent: link && link !== brand ? link : null
168
+ accent: (_ref2 = link && link !== brand ? link : palette.find((hex)=>hex !== brand)) != null ? _ref2 : null
157
169
  };
158
170
  }
159
171
  const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : null;
@@ -163,8 +175,11 @@ const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLower
163
175
  * strongest color as the brand. What the reader found of its look
164
176
  * (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its
165
177
  * links' color as the accent, its eyebrows' own color as the third, and its
166
- * own fonts where the catalog has them (`fonts`). `null` where the source
167
- * showed no color to carry a brand, so the site keeps the theme it has.
178
+ * own fonts where the catalog has them (`fonts`). Its pictures' colors
179
+ * (`pictures`, AGL-4152) stand in for a brand where its facts show none. `null`
180
+ * where nothing showed a color to carry a brand, unless asked to draw the look
181
+ * from the seed alone (`draw`), which the pass does rather than leave the site
182
+ * in the stock theme.
168
183
  *
169
184
  * How the owner asked the site to be finished (AGL-4152) says what else:
170
185
  * - **Keep my site** (`keep`, and an import that names none) pins the rest
@@ -175,11 +190,16 @@ const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLower
175
190
  * and the fonts, so the base that suits the kind of site shows with its own
176
191
  * corners, buttons, grounds and eyebrows.
177
192
  */ export function aiSiteImportStyle(site, input) {
178
- var _input_facts, _input_avoid;
193
+ var _input_facts, _ref, _aiSiteImportBrandOf, _input_avoid;
194
+ var _input_pictures, _input_pictures_;
179
195
  const facts = (_input_facts = input.facts) != null ? _input_facts : null;
180
196
  const finish = input.finish === 'improve' ? 'improve' : 'keep';
181
- const own = aiSiteImportBrandOf(facts);
182
- if (!site && !own) return null;
197
+ const pictured = ((_input_pictures = input.pictures) == null ? void 0 : _input_pictures[0]) ? {
198
+ brand: input.pictures[0].toLowerCase(),
199
+ accent: (_ref = (_input_pictures_ = input.pictures[1]) == null ? void 0 : _input_pictures_.toLowerCase()) != null ? _ref : null
200
+ } : null;
201
+ const own = (_aiSiteImportBrandOf = aiSiteImportBrandOf(facts)) != null ? _aiSiteImportBrandOf : pictured;
202
+ if (!site && !own && !input.draw) return null;
183
203
  const kind = aiSiteKindFor(input.description);
184
204
  const signals = site ? aiSiteInspirationLookPins({
185
205
  v: 1,
@@ -218,7 +238,7 @@ const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLower
218
238
  // it — and their own color, where it is one, as the theme's third.
219
239
  if (facts && finish === 'keep') pins.eyebrow = 'caps';
220
240
  if (colorful(facts == null ? void 0 : facts.eyebrow)) pins.tertiary = (facts == null ? void 0 : facts.eyebrow).toLowerCase();
221
- if (!pins.brand) return null;
241
+ if (!pins.brand && !input.draw) return null;
222
242
  const style = aiSiteStyleFor({
223
243
  kind,
224
244
  answer: {},
@@ -238,15 +258,34 @@ const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLower
238
258
  const darkPage = solidHex(facts == null ? void 0 : facts.darkBackground);
239
259
  const buttonFill = solidHex(facts == null ? void 0 : facts.buttonFill);
240
260
  const buttonText = buttonFill ? solidHex(facts == null ? void 0 : facts.buttonText) : null;
241
- const buttonCase = (facts == null ? void 0 : facts.buttonCase) === 'upper' || (facts == null ? void 0 : facts.buttonCase) === 'none' ? facts.buttonCase : null;
261
+ const caseOf = (value)=>value === 'upper' || value === 'none' ? value : null;
262
+ const buttonCase = caseOf(facts == null ? void 0 : facts.buttonCase);
263
+ const outlinedCase = caseOf(facts == null ? void 0 : facts.outlinedCase);
264
+ const textCase = caseOf(facts == null ? void 0 : facts.textCase);
265
+ const paper = solidHex(facts == null ? void 0 : facts.paperBackground);
266
+ const darkPaper = solidHex(facts == null ? void 0 : facts.darkPaper);
267
+ const outlinedFill = solidHex(facts == null ? void 0 : facts.outlinedFill);
268
+ const buttonOutline = solidHex(facts == null ? void 0 : facts.buttonOutline);
242
269
  return _extends({}, style, {
243
270
  finish
244
271
  }, page ? {
245
272
  page
246
273
  } : {}, darkPage ? {
247
274
  darkPage
275
+ } : {}, paper ? {
276
+ paper
277
+ } : {}, darkPaper ? {
278
+ darkPaper
248
279
  } : {}, buttonCase ? {
249
280
  buttonCase
281
+ } : {}, outlinedCase ? {
282
+ outlinedCase
283
+ } : {}, textCase ? {
284
+ textCase
285
+ } : {}, outlinedFill ? {
286
+ outlinedFill
287
+ } : {}, buttonOutline ? {
288
+ buttonOutline
250
289
  } : {}, buttonFill ? {
251
290
  buttonFill
252
291
  } : {}, buttonText ? {
@@ -307,6 +346,26 @@ const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLower
307
346
  if (image === undefined || image === null) return true;
308
347
  return typeof image === 'string' && (!image.trim() || aiSiteIsStarterSrc(image));
309
348
  }
349
+ /** The library's copy of a picture, decoded where `sharp` is shipped (`readLogoColors`, AGL-4048). */ const pictureColorsOf = async (photo, { firestore, hostId, orgId, signal })=>{
350
+ const location = logoMediaLocation(photo.src, hostId, orgId);
351
+ if (!location) return null;
352
+ return readLogoColors(firestore, location, hostId, AbortSignal.any([
353
+ AbortSignal.timeout(LOOK_READ_MS),
354
+ ...signal ? [
355
+ signal
356
+ ] : []
357
+ ]));
358
+ };
359
+ /** A read of a picture's colorful colors: none where it has none, or cannot be read. */ async function colorfulColorsOf(photo, read, input) {
360
+ const colors = await read(photo, input).catch((error)=>{
361
+ console.warn('[site-import] a picture’s colors could not be read', {
362
+ hostId: input.hostId,
363
+ error
364
+ });
365
+ return null;
366
+ });
367
+ return (colors != null ? colors : []).filter(colorful).map((hex)=>hex.toLowerCase());
368
+ }
310
369
  /** The most pictures the home page's menus bring into the library (AGL-4139). */ export const AI_SITE_IMPORT_MENU_PICTURES = 4;
311
370
  /** The pictures the home page's menus show (AGL-4139), each once, the first few: a featured card's. */ export function aiSiteImportMenuPictures(home) {
312
371
  var _ref;
@@ -430,7 +489,7 @@ async function writeHostDoc(firestore, hostId, updates) {
430
489
  }
431
490
  }
432
491
  /** The look pass (AGL-4084): the theme, the logo and the listing, from the owner's own home page. No model. */ export async function aiRunSiteImportLook(input, deps = {}) {
433
- var _deps_others, _home_look, _input_finish, _deps_ingest, _deps_readHost, _ref;
492
+ var _deps_others, _home_look, _deps_ingest, _input_finish, _deps_save, _deps_readHost, _facts_palette, _ref;
434
493
  const { firestore, hostId, home } = input;
435
494
  const headersFor = await aiSiteImportLookHeaders(input.domain, deps);
436
495
  const seed = aiSiteSeed(input.jobId);
@@ -453,25 +512,6 @@ async function writeHostDoc(firestore, hostId, updates) {
453
512
  // What the reader found of its look, its buttons, ground and fonts (AGL-4108).
454
513
  const facts = (_home_look = home.look) != null ? _home_look : null;
455
514
  const fonts = await aiSiteImportSourceFonts(facts, deps.fontFacts);
456
- const style = aiSiteImportStyle(site, {
457
- seed,
458
- description: `${home.siteName} ${home.description}`,
459
- avoid,
460
- facts,
461
- fonts,
462
- finish: (_input_finish = input.finish) != null ? _input_finish : null
463
- });
464
- let theme = 'unread';
465
- if (style) {
466
- var _deps_save;
467
- const saved = await ((_deps_save = deps.save) != null ? _deps_save : aiSaveSiteTheme)(firestore, {
468
- hostId,
469
- jobId: input.jobId,
470
- style
471
- });
472
- if (saved.write === 'missing') throw new Error(`site ${hostId} vanished while its look was brought in`);
473
- theme = saved.write === 'kept' ? 'kept' : 'applied';
474
- }
475
515
  const ingest = (_deps_ingest = deps.ingest) != null ? _deps_ingest : null;
476
516
  const logo = home.brand.logo ? await aiSiteImportLogo(_extends({
477
517
  hostId,
@@ -489,9 +529,82 @@ async function writeHostDoc(firestore, hostId, updates) {
489
529
  } : {}, deps.rasterize ? {
490
530
  rasterize: deps.rasterize
491
531
  } : {})) : null;
532
+ // No color of its own (AGL-4152): its logo's colorful colors, else its hero photo's, else its share picture's.
533
+ let pictures = [];
534
+ let from = 'source';
535
+ if (!aiSiteImportBrandOf(facts)) {
536
+ var _deps_pictureColors;
537
+ const read = (_deps_pictureColors = deps.pictureColors) != null ? _deps_pictureColors : pictureColorsOf;
538
+ const asked = _extends({
539
+ firestore,
540
+ hostId,
541
+ orgId: input.orgId
542
+ }, input.signal ? {
543
+ signal: input.signal
544
+ } : {});
545
+ const ofLogo = logo ? await colorfulColorsOf(logo, read, asked) : [];
546
+ if (ofLogo.length) {
547
+ pictures = ofLogo.slice(0, 2);
548
+ from = 'logo';
549
+ } else {
550
+ for (const image of [
551
+ home.hero,
552
+ home.ogImage ? {
553
+ url: home.ogImage,
554
+ alt: ''
555
+ } : null
556
+ ]){
557
+ if (!image) continue;
558
+ const { assets } = await bringInSiteImportPhotos(_extends({
559
+ hostId,
560
+ uid: input.uid,
561
+ domain: input.domain,
562
+ images: [
563
+ image
564
+ ],
565
+ deadlineAt: Date.now() + LOOK_READ_MS
566
+ }, input.signal ? {
567
+ signal: input.signal
568
+ } : {}), _extends({
569
+ ingest
570
+ }, deps.fetch ? {
571
+ fetch: deps.fetch
572
+ } : {}));
573
+ const ofPhoto = assets[0] ? await colorfulColorsOf(assets[0], read, asked) : [];
574
+ if (!ofPhoto.length) continue;
575
+ pictures = ofPhoto.slice(0, 1);
576
+ from = 'photo';
577
+ break;
578
+ }
579
+ }
580
+ }
581
+ const described = {
582
+ seed,
583
+ description: `${home.siteName} ${home.description}`,
584
+ avoid,
585
+ facts,
586
+ fonts,
587
+ finish: (_input_finish = input.finish) != null ? _input_finish : null,
588
+ pictures
589
+ };
590
+ let style = aiSiteImportStyle(site, described);
591
+ // Nothing anywhere to read a color from: the seed's look for its kind, never the stock theme.
592
+ if (!style) {
593
+ style = aiSiteImportStyle(site, _extends({}, described, {
594
+ draw: true
595
+ }));
596
+ from = 'seed';
597
+ }
598
+ const saved = await ((_deps_save = deps.save) != null ? _deps_save : aiSaveSiteTheme)(firestore, {
599
+ hostId,
600
+ jobId: input.jobId,
601
+ style
602
+ });
603
+ if (saved.write === 'missing') throw new Error(`site ${hostId} vanished while its look was brought in`);
604
+ const theme = saved.write === 'kept' ? 'kept' : 'applied';
492
605
  // The pictures its menus show, in the library like its pages' photos (AGL-4139), for the header's panels.
493
606
  const menuImages = aiSiteImportMenuPictures(home);
494
- const pictures = menuImages.length ? (await bringInSiteImportPhotos(_extends({
607
+ const menuPictures = menuImages.length ? (await bringInSiteImportPhotos(_extends({
495
608
  hostId,
496
609
  uid: input.uid,
497
610
  domain: input.domain,
@@ -574,33 +687,36 @@ async function writeHostDoc(firestore, hostId, updates) {
574
687
  }
575
688
  }
576
689
  }
577
- const drawn = style ? _extends({}, typeof style.headerAlign === 'string' ? {
690
+ const drawn = _extends({}, typeof style.headerAlign === 'string' ? {
578
691
  headerAlign: style.headerAlign
579
692
  } : {}, typeof style.rhythm === 'string' ? {
580
693
  rhythm: style.rhythm
581
694
  } : {}, typeof style.motion === 'string' ? {
582
695
  motion: style.motion
583
- } : {}) : null;
696
+ } : {});
584
697
  const colors = [
585
698
  ...new Set([
586
699
  ...facts ? [
587
700
  facts.buttonFill,
588
701
  facts.link,
589
- facts.eyebrow
702
+ facts.eyebrow,
703
+ ...(_facts_palette = facts.palette) != null ? _facts_palette : []
590
704
  ].filter(colorful).map((hex)=>hex.toLowerCase()) : [],
705
+ ...pictures,
591
706
  ...(_ref = site == null ? void 0 : site.colors) != null ? _ref : []
592
707
  ])
593
708
  ];
594
709
  return _extends({
595
710
  at: input.at,
596
711
  theme,
712
+ from,
597
713
  colors,
598
714
  logo
599
- }, pictures.length ? {
600
- pictures
715
+ }, menuPictures.length ? {
716
+ pictures: menuPictures
601
717
  } : {}, {
602
718
  seo,
603
- seed: style ? style.seed : seed,
719
+ seed: style.seed,
604
720
  style: drawn
605
721
  });
606
722
  }