@aglyn/plugins-ai 1.9.0 → 1.10.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/package.json +17 -17
- package/src/lib/components/ai-job-requests.d.ts +5 -0
- package/src/lib/components/ai-job-requests.js +4 -0
- package/src/lib/components/ai-job-requests.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +10 -3
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-finish.component.d.ts +40 -0
- package/src/lib/components/ai-site-import-finish.component.js +174 -0
- package/src/lib/components/ai-site-import-finish.component.js.map +1 -0
- package/src/lib/components/ai-site-import-job.component.d.ts +11 -3
- package/src/lib/components/ai-site-import-job.component.js +220 -135
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/components/ai-site-import-start.component.d.ts +11 -2
- package/src/lib/components/ai-site-import-start.component.js +27 -5
- package/src/lib/components/ai-site-import-start.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.js +1 -1
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.js +2 -2
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +2 -0
- package/src/lib/jobs/ai-job-import-step.js +31 -8
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +40 -2
- package/src/lib/jobs/ai-job-page-language.js +188 -9
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +2 -0
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +5 -0
- package/src/lib/jobs/ai-job-privacy-step.js +9 -4
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +7 -1
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.d.ts +13 -2
- package/src/lib/jobs/ai-site-import-compile.js +115 -21
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +5 -1
- package/src/lib/jobs/ai-site-import-document.js +5 -1
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-look.d.ts +16 -4
- package/src/lib/jobs/ai-site-import-look.js +54 -13
- package/src/lib/jobs/ai-site-import-look.js.map +1 -1
- package/src/lib/jobs/ai-site-import-wording.d.ts +187 -0
- package/src/lib/jobs/ai-site-import-wording.js +747 -0
- package/src/lib/jobs/ai-site-import-wording.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +12 -1
- package/src/lib/layout-language/ai-layout-compiler.js +29 -30
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +12 -0
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +211 -2
- package/src/lib/model/ai-site-import-fidelity.js +1011 -14
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +52 -1
- package/src/lib/model/ai-site-import-report.js +102 -5
- package/src/lib/model/ai-site-import-report.js.map +1 -1
- package/src/lib/model/ai-site-import-view.d.ts +62 -2
- package/src/lib/model/ai-site-import-view.js +83 -4
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +122 -6
- package/src/lib/model/ai-site-import.js +202 -9
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +51 -0
- package/src/lib/model/ai-site-look.js +205 -29
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +19 -0
- package/src/lib/runtime/ai-doctrine-validators.js +25 -0
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.js +4 -1
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/server/ai-allotments.js +4 -2
- package/src/lib/server/ai-allotments.js.map +1 -1
- package/src/lib/server/ai-jobs-resume.js +32 -5
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +36 -10
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +48 -4
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/fixtures/site-look-slate.d.ts +27 -0
- package/src/lib/site-import/fixtures/site-look-slate.js +29 -0
- package/src/lib/site-import/fixtures/site-look-slate.js.map +1 -0
- package/src/lib/site-import/site-import-layout.d.ts +19 -5
- package/src/lib/site-import/site-import-layout.js +137 -16
- package/src/lib/site-import/site-import-layout.js.map +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { type AiSiteImportBuild, type AiSiteImportPhoto, type SiteImportLayout } from '../model/ai-site-import';
|
|
17
|
+
import { type AiSiteImportBuild, type AiSiteImportFinish, type AiSiteImportPhoto, type AiSiteImportWords, type SiteImportLayout } from '../model/ai-site-import';
|
|
18
18
|
import type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html';
|
|
19
19
|
/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */
|
|
20
20
|
export declare const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = "importedSections";
|
|
@@ -41,6 +41,10 @@ export interface AiSiteImportDocument {
|
|
|
41
41
|
* absent on a read made before the reader, or one past its budget.
|
|
42
42
|
*/
|
|
43
43
|
layout?: SiteImportLayout | null;
|
|
44
|
+
/** How the page's wave finishes it (AGL-4152); absent is `keep`. */
|
|
45
|
+
finish?: AiSiteImportFinish | null;
|
|
46
|
+
/** Whether its words are improved (AGL-4152); absent is kept as written. */
|
|
47
|
+
wording?: AiSiteImportWords | null;
|
|
44
48
|
/** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */
|
|
45
49
|
forms?: Array<{
|
|
46
50
|
index: number;
|
|
@@ -200,7 +200,11 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
200
200
|
] : [];
|
|
201
201
|
}),
|
|
202
202
|
origins: strings(value['origins'])
|
|
203
|
-
},
|
|
203
|
+
}, value['finish'] === 'keep' || value['finish'] === 'improve' ? {
|
|
204
|
+
finish: value['finish']
|
|
205
|
+
} : {}, value['wording'] === 'kept' || value['wording'] === 'improved' ? {
|
|
206
|
+
wording: value['wording']
|
|
207
|
+
} : {}, isLayout(value['layout']) ? {
|
|
204
208
|
layout: value['layout']
|
|
205
209
|
} : {}, Array.isArray(value['videos']) ? {
|
|
206
210
|
videos: value['videos'].map(videoOf)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE BROUGHT IN WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportPhoto,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: (Array.isArray(value['photos']) ? value['photos'] : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n },\n ]\n : []\n }),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photos","photo","mediaId","src","width","height","from","links","link","path","id","origins","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA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AACkE,KAAKhG,IAAI;QAC7B;QACA2F,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACA7E;IACA,OAAO0E;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE BROUGHT IN WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportFinish,\n type AiSiteImportPhoto,\n type AiSiteImportWords,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** How the page's wave finishes it (AGL-4152); absent is `keep`. */\n finish?: AiSiteImportFinish | null\n /** Whether its words are improved (AGL-4152); absent is kept as written. */\n wording?: AiSiteImportWords | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: (Array.isArray(value['photos']) ? value['photos'] : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n },\n ]\n : []\n }),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n // How the page's wave finishes it and whether its words are improved (AGL-4152); anything else is absent: kept.\n ...(value['finish'] === 'keep' || value['finish'] === 'improve' ? { finish: value['finish'] } : {}),\n ...(value['wording'] === 'kept' || value['wording'] === 'improved' ? { wording: value['wording'] } : {}),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photos","photo","mediaId","src","width","height","from","links","link","path","id","origins","finish","wording","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA,8BAA8B,EAC9BC,2BAA2B,QAMtB,6BAAyB;AAEhC,SAASC,eAAe,QAAQ,qCAAiC;AACjE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,2GAA2G,GAC3G,OAAO,MAAMC,oCAAoC,mBAAkB;A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+E,KAAKjE,KAAK,CAAC,GAAGoE,KAAKlG,IAAI;YAClC+F,OAAOA,KAAKjE,KAAK,CAACoE,KAAKlG,IAAI;QAC7B;QACA6F,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACA/E;IACA,OAAO4E;AACT"}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest';
|
|
18
18
|
import { type ThemeFontFacts } from '@aglyn/aglyn/plugin-manager/plugin-theme-font-catalog';
|
|
19
|
-
import type { AiSiteImportHome, AiSiteImportLook, AiSiteImportPhoto, SiteImportLookFacts } from '../model/ai-site-import';
|
|
19
|
+
import type { AiSiteImportFinish, AiSiteImportHome, AiSiteImportLook, AiSiteImportPhoto, SiteImportLookFacts } from '../model/ai-site-import';
|
|
20
20
|
import { type AiSiteStyle } from '../model/ai-site-look';
|
|
21
21
|
import { type SiteImportCrawlSeams } from '../site-import/site-import-crawl';
|
|
22
22
|
import { siteImportEdgeHeadersFor, type SiteImportHeadersFor } from '../site-import/site-import-edge';
|
|
@@ -65,9 +65,18 @@ export declare function aiSiteImportBrandOf(facts: Pick<SiteImportLookFacts, 'bu
|
|
|
65
65
|
* is: the kind of site its own description says, the import's seed, its
|
|
66
66
|
* strongest color as the brand. What the reader found of its look
|
|
67
67
|
* (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its
|
|
68
|
-
* links' color as the accent, its
|
|
69
|
-
* catalog has them (`fonts`). `null` where the source
|
|
70
|
-
* carry a brand, so the site keeps the theme it has.
|
|
68
|
+
* 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.
|
|
71
|
+
*
|
|
72
|
+
* How the owner asked the site to be finished (AGL-4152) says what else:
|
|
73
|
+
* - **Keep my site** (`keep`, and an import that names none) pins the rest
|
|
74
|
+
* of its look as it draws it: its page's ground and its dark bands', its
|
|
75
|
+
* buttons' corners and case and their own fill and words, every inspiration
|
|
76
|
+
* signal, and its eyebrows set as spaced capitals.
|
|
77
|
+
* - **Improve it** (`improve`) pins only the brand, accent and third colors
|
|
78
|
+
* and the fonts, so the base that suits the kind of site shows with its own
|
|
79
|
+
* corners, buttons, grounds and eyebrows.
|
|
71
80
|
*/
|
|
72
81
|
export declare function aiSiteImportStyle(site: AiSiteInspirationSite | null, input: {
|
|
73
82
|
seed: number;
|
|
@@ -75,6 +84,7 @@ export declare function aiSiteImportStyle(site: AiSiteInspirationSite | null, in
|
|
|
75
84
|
avoid?: readonly AiSiteStyle[];
|
|
76
85
|
facts?: SiteImportLookFacts | null;
|
|
77
86
|
fonts?: AiSiteStyle['sourceFonts'];
|
|
87
|
+
finish?: AiSiteImportFinish | null;
|
|
78
88
|
}): AiSiteStyle | null;
|
|
79
89
|
/** A family's facts, as the theme font catalog answers them. */
|
|
80
90
|
export type AiSiteImportFontFacts = (family: string) => Promise<ThemeFontFacts | undefined>;
|
|
@@ -132,6 +142,8 @@ export interface AiSiteImportLookInput {
|
|
|
132
142
|
home: AiSiteImportHome;
|
|
133
143
|
at: string;
|
|
134
144
|
signal?: AbortSignal;
|
|
145
|
+
/** How the site is finished (AGL-4152): Keep my site keeps more of the source's look. Absent is `keep`. */
|
|
146
|
+
finish?: AiSiteImportFinish | null;
|
|
135
147
|
}
|
|
136
148
|
/**
|
|
137
149
|
* The source header's logo in the site's library (AGL-4084), once: the copy
|
|
@@ -156,21 +156,32 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
|
|
|
156
156
|
accent: link && link !== brand ? link : null
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
+
const solidHex = (value)=>value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : null;
|
|
159
160
|
/**
|
|
160
161
|
* The look a source's signals pin (AGL-4084), drawn the way a guided start's
|
|
161
162
|
* is: the kind of site its own description says, the import's seed, its
|
|
162
163
|
* strongest color as the brand. What the reader found of its look
|
|
163
164
|
* (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its
|
|
164
|
-
* links' color as the accent, its
|
|
165
|
-
* catalog has them (`fonts`). `null` where the source
|
|
166
|
-
* carry a brand, so the site keeps the theme it has.
|
|
165
|
+
* 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.
|
|
168
|
+
*
|
|
169
|
+
* How the owner asked the site to be finished (AGL-4152) says what else:
|
|
170
|
+
* - **Keep my site** (`keep`, and an import that names none) pins the rest
|
|
171
|
+
* of its look as it draws it: its page's ground and its dark bands', its
|
|
172
|
+
* buttons' corners and case and their own fill and words, every inspiration
|
|
173
|
+
* signal, and its eyebrows set as spaced capitals.
|
|
174
|
+
* - **Improve it** (`improve`) pins only the brand, accent and third colors
|
|
175
|
+
* and the fonts, so the base that suits the kind of site shows with its own
|
|
176
|
+
* corners, buttons, grounds and eyebrows.
|
|
167
177
|
*/ export function aiSiteImportStyle(site, input) {
|
|
168
178
|
var _input_facts, _input_avoid;
|
|
169
179
|
const facts = (_input_facts = input.facts) != null ? _input_facts : null;
|
|
180
|
+
const finish = input.finish === 'improve' ? 'improve' : 'keep';
|
|
170
181
|
const own = aiSiteImportBrandOf(facts);
|
|
171
182
|
if (!site && !own) return null;
|
|
172
183
|
const kind = aiSiteKindFor(input.description);
|
|
173
|
-
const
|
|
184
|
+
const signals = site ? aiSiteInspirationLookPins({
|
|
174
185
|
v: 1,
|
|
175
186
|
sites: [
|
|
176
187
|
site
|
|
@@ -180,6 +191,16 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
|
|
|
180
191
|
kind,
|
|
181
192
|
seed: input.seed
|
|
182
193
|
}) : {};
|
|
194
|
+
// Improve keeps the brand's colors and its type, and nothing else its source draws.
|
|
195
|
+
const pins = finish === 'improve' ? _extends({}, signals.brand ? {
|
|
196
|
+
brand: signals.brand
|
|
197
|
+
} : {}, signals.hue !== undefined ? {
|
|
198
|
+
hue: signals.hue
|
|
199
|
+
} : {}, signals.accent !== undefined ? {
|
|
200
|
+
accent: signals.accent
|
|
201
|
+
} : {}, signals.fonts ? {
|
|
202
|
+
fonts: signals.fonts
|
|
203
|
+
} : {}) : signals;
|
|
183
204
|
if (own) {
|
|
184
205
|
pins.brand = own.brand;
|
|
185
206
|
pins.hue = Math.round(aiHexOklch(own.brand).h) % 360;
|
|
@@ -187,7 +208,7 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
|
|
|
187
208
|
}
|
|
188
209
|
// Its buttons' corners round the theme's shape where its stylesheets did not say (AGL-4108).
|
|
189
210
|
const radius = facts == null ? void 0 : facts.buttonRadius;
|
|
190
|
-
if (typeof radius === 'number' && Number.isFinite(radius) && radius >= 0) {
|
|
211
|
+
if (finish === 'keep' && typeof radius === 'number' && Number.isFinite(radius) && radius >= 0) {
|
|
191
212
|
var _pins, _buttons, _pins1, _corners;
|
|
192
213
|
(_buttons = (_pins = pins).buttons) != null ? _buttons : _pins.buttons = radius >= 24 ? 'pill' : radius <= 2 ? 'square' : 'rounded';
|
|
193
214
|
(_corners = (_pins1 = pins).corners) != null ? _corners : _pins1.corners = radius <= 2 ? 'sharp' : radius <= 10 ? 'soft' : radius <= 20 ? 'round' : 'pill';
|
|
@@ -195,7 +216,7 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
|
|
|
195
216
|
// Its eyebrows as it sets them (AGL-4138): spaced capitals with no line before them — the
|
|
196
217
|
// reader takes an eyebrow only in capitals, and no mark a page draws before one is a word of
|
|
197
218
|
// it — and their own color, where it is one, as the theme's third.
|
|
198
|
-
if (facts) pins.eyebrow = 'caps';
|
|
219
|
+
if (facts && finish === 'keep') pins.eyebrow = 'caps';
|
|
199
220
|
if (colorful(facts == null ? void 0 : facts.eyebrow)) pins.tertiary = (facts == null ? void 0 : facts.eyebrow).toLowerCase();
|
|
200
221
|
if (!pins.brand) return null;
|
|
201
222
|
const style = aiSiteStyleFor({
|
|
@@ -206,12 +227,31 @@ const colorful = (hex)=>!!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).
|
|
|
206
227
|
avoid: (_input_avoid = input.avoid) != null ? _input_avoid : [],
|
|
207
228
|
pins
|
|
208
229
|
});
|
|
209
|
-
const
|
|
210
|
-
return _extends({}, style, page ? {
|
|
211
|
-
page
|
|
212
|
-
} : {}, input.fonts ? {
|
|
230
|
+
const fonts = input.fonts ? {
|
|
213
231
|
sourceFonts: input.fonts
|
|
214
|
-
} : {}
|
|
232
|
+
} : {};
|
|
233
|
+
if (finish === 'improve') return _extends({}, style, {
|
|
234
|
+
finish
|
|
235
|
+
}, fonts);
|
|
236
|
+
// Keep my site (AGL-4152): its grounds, its buttons' case, and its filled buttons as it draws them.
|
|
237
|
+
const page = solidHex(facts == null ? void 0 : facts.background);
|
|
238
|
+
const darkPage = solidHex(facts == null ? void 0 : facts.darkBackground);
|
|
239
|
+
const buttonFill = solidHex(facts == null ? void 0 : facts.buttonFill);
|
|
240
|
+
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;
|
|
242
|
+
return _extends({}, style, {
|
|
243
|
+
finish
|
|
244
|
+
}, page ? {
|
|
245
|
+
page
|
|
246
|
+
} : {}, darkPage ? {
|
|
247
|
+
darkPage
|
|
248
|
+
} : {}, buttonCase ? {
|
|
249
|
+
buttonCase
|
|
250
|
+
} : {}, buttonFill ? {
|
|
251
|
+
buttonFill
|
|
252
|
+
} : {}, buttonText ? {
|
|
253
|
+
buttonText
|
|
254
|
+
} : {}, fonts);
|
|
215
255
|
}
|
|
216
256
|
/**
|
|
217
257
|
* The source's own fonts (AGL-4108), each where the theme font catalog has
|
|
@@ -390,7 +430,7 @@ async function writeHostDoc(firestore, hostId, updates) {
|
|
|
390
430
|
}
|
|
391
431
|
}
|
|
392
432
|
/** 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 = {}) {
|
|
393
|
-
var _deps_others, _home_look, _deps_ingest, _deps_readHost, _ref;
|
|
433
|
+
var _deps_others, _home_look, _input_finish, _deps_ingest, _deps_readHost, _ref;
|
|
394
434
|
const { firestore, hostId, home } = input;
|
|
395
435
|
const headersFor = await aiSiteImportLookHeaders(input.domain, deps);
|
|
396
436
|
const seed = aiSiteSeed(input.jobId);
|
|
@@ -418,7 +458,8 @@ async function writeHostDoc(firestore, hostId, updates) {
|
|
|
418
458
|
description: `${home.siteName} ${home.description}`,
|
|
419
459
|
avoid,
|
|
420
460
|
facts,
|
|
421
|
-
fonts
|
|
461
|
+
fonts,
|
|
462
|
+
finish: (_input_finish = input.finish) != null ? _input_finish : null
|
|
422
463
|
});
|
|
423
464
|
let theme = 'unread';
|
|
424
465
|
if (style) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-look.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * THE SITE BROUGHT IN KEEPS ITS OWN LOOK (AGL-4084).\n *\n * The first wave's look pass, before the header and footer, with no model:\n *\n * - **The theme.** The owner's own home page is read once more as AglynBot,\n * with the edge headers a site this platform serves gets whether or not a\n * caller hands them in (AGL-4108: production handed none, our own edge\n * challenged the read, and the 10/29 site kept the starter's indigo), and\n * the signals a guided start reads off the sites a person likes\n * (AGL-3975: colors, ground, type mood, corners, buttons, cards, header,\n * density, motion) pin the look. What the reader found of the source's\n * look (AGL-4106) pins it closer (AGL-4108): its buttons' fill is the\n * brand and its links' color the accent, its page's ground is the site's,\n * its eyebrows' own color the theme's third and its eyebrows spaced\n * capitals with no line before them (AGL-4138), and its own font family\n * is the site's wherever the theme font catalog has it, else a pairing of\n * its type mood. The look is drawn and saved\n * exactly as a guided start's (`aiSiteStyleFor`, `aiSaveSiteTheme`): a\n * built-in base plus the brand colors and fonts, every color held to the\n * theme's reading checks. A site whose owner already chose a theme keeps\n * it.\n * - **The logo.** The source header's logo, as the source draws it, into the\n * site's media library once: an SVG is turned into a PNG 192 pixels tall\n * (the library takes pictures, not drawings), a picture is kept as it is.\n * - **The listing.** The home page's own title, description and share\n * picture become the site's listing, only while the site still has the\n * listing it was created with: an owner's own words are never written\n * over.\n *\n * Nothing here fails a wave: a source whose look cannot be read keeps the\n * site's theme, and a logo that cannot be brought in leaves the header its\n * name.\n *=========================================*/\n\nimport type { PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { themeFontFacts, type ThemeFontFacts } from '@aglyn/aglyn/plugin-manager/plugin-theme-font-catalog'\nimport { syncHostProjectionForMembers } from '@aglyn/tenant-data-admin/server/host-memberships'\nimport { aiSiteListingSeeded } from '../model/ai-site-entity'\nimport type { AiSiteImportHome, AiSiteImportLook, AiSiteImportPhoto, SiteImportLookFacts } from '../model/ai-site-import'\nimport { aiSiteKindFor } from '../model/ai-site-kinds'\nimport { aiHexOklch, aiSiteSeed, aiSiteStyleFor, type AiSiteSourceFont, type AiSiteStyle } from '../model/ai-site-look'\nimport { aiSiteIsStarterSrc } from '../model/ai-site-photos'\nimport { AGLYN_BOT_USER_AGENT, siteImportOrigins, type SiteImportCrawlSeams } from '../site-import/site-import-crawl'\nimport { NO_SITE_IMPORT_HEADERS, siteImportEdgeHeadersFor, type SiteImportHeadersFor } from '../site-import/site-import-edge'\nimport { bringInSiteImportPhotos, siteImportImageKey, siteImportLogoUrl } from '../site-import/site-import-images'\nimport { aiSaveSiteTheme, aiWorkspaceSiteStyles } from './ai-job-site-look'\nimport { aiSiteInspirationLookPins } from './ai-site-inspiration'\nimport { aiSiteInspirationSignals, type AiSiteInspirationSite } from './ai-site-inspiration-signals'\nimport {\n AI_THEME_BRAND_COLORS_PER_SOURCE,\n AI_THEME_REFERENCE_MAX_BYTES,\n AI_THEME_REFERENCE_STYLESHEETS,\n AI_THEME_STYLESHEET_MAX_BYTES,\n AI_THEME_THEME_COLOR_WEIGHT,\n fetchPublicTextDetailed,\n rankBrandColors,\n stylesheetUrlsOf,\n type AiReferencePage,\n type PublicFetchOptions,\n type PublicFetchResult,\n} from './ai-theme-brand-inputs'\n\n/** The height an SVG logo is drawn at as a picture: crisp at twice the header's 40. */\nexport const AI_SITE_IMPORT_LOGO_HEIGHT = 192\n\n/** The largest logo file read. */\nexport const AI_SITE_IMPORT_LOGO_MAX_BYTES = 1024 * 1024\n\n/** One read's own clock in the look pass. */\nconst LOOK_READ_MS = 8_000\n\ntype Fetch = (url: string, options: PublicFetchOptions) => Promise<PublicFetchResult>\n\n/**\n * The home page and its first stylesheets, read as AglynBot (AGL-4084).\n * `headersFor` is asked for every request and every redirect hop, as the\n * crawl asks it (`aiSiteImportLookHeaders`: the edge header only to the\n * site's own origins). `null` when the page cannot be read.\n */\nexport async function readSiteImportLookPage(\n url: string,\n input: { fetch?: Fetch; headersFor?: SiteImportHeadersFor | null; signal?: AbortSignal },\n): Promise<AiReferencePage | null> {\n const fetchText = input.fetch ?? fetchPublicTextDetailed\n const headersFor = input.headersFor ?? null\n const read = (address: string, maxBytes: number, accept: RegExp) =>\n fetchText(address, {\n maxBytes,\n accept,\n userAgent: AGLYN_BOT_USER_AGENT,\n timeoutMs: LOOK_READ_MS,\n ...(input.signal ? { signal: input.signal } : {}),\n ...(headersFor ? { headersFor } : {}),\n }).catch(() => null)\n const page = await read(url, AI_THEME_REFERENCE_MAX_BYTES, /text\\/html|application\\/xhtml\\+xml/i)\n if (!page?.ok) return null\n const stylesheets: string[] = []\n for (const sheet of stylesheetUrlsOf(page.text, page.url).slice(0, AI_THEME_REFERENCE_STYLESHEETS)) {\n const css = await read(sheet, AI_THEME_STYLESHEET_MAX_BYTES, /text\\/css/i)\n if (css?.ok) stylesheets.push(css.text)\n }\n return { url: page.url, html: page.text, stylesheets }\n}\n\nconst SOLID_HEX = /(?<!&)#(?:[0-9a-f]{6}|[0-9a-f]{3})(?![0-9a-z])/gi\nconst SOLID_RGB = /rgba?\\(\\s*(\\d{1,3})\\s*[,\\s]\\s*(\\d{1,3})\\s*[,\\s]\\s*(\\d{1,3})\\s*(?:[,/]\\s*([\\d.]+%?)\\s*)?\\)/gi\nconst THEME_COLOR = /<meta\\b[^>]*\\bname\\s*=\\s*[\"']?theme-color\\b[^>]*\\bcontent\\s*=\\s*[\"']?\\s*(#[0-9a-f]{3,6})/gi\n\nconst hexOf = (value: string): string | null => {\n const raw = value.trim().toLowerCase()\n if (/^#[0-9a-f]{6}$/.test(raw)) return raw\n if (/^#[0-9a-f]{3}$/.test(raw)) return `#${raw[1]}${raw[1]}${raw[2]}${raw[2]}${raw[3]}${raw[3]}`\n return null\n}\n\n/**\n * A source's brand colors as it DRAWS them (AGL-4084): the colors its markup\n * and stylesheets use solid, most used first, the colorful before the greys.\n * A translucent color is a tint of one (a hover, a focus ring), never a use\n * of it, so it is not counted: aglyn.com's focus rings, a light blue at a\n * quarter strength, outnumbered the deep blue its buttons and links are\n * drawn in, which the theme reader would otherwise take as its brand.\n */\nexport function aiSiteImportBrandColors(page: Pick<AiReferencePage, 'html' | 'stylesheets'>): string[] {\n const weights = new Map<string, number>()\n const add = (hex: string | null, weight = 1) => {\n if (hex) weights.set(hex, (weights.get(hex) ?? 0) + weight)\n }\n for (const match of page.html.matchAll(THEME_COLOR)) add(hexOf(match[1] ?? ''), AI_THEME_THEME_COLOR_WEIGHT)\n for (const text of [page.html, ...page.stylesheets]) {\n for (const match of text.matchAll(SOLID_HEX)) add(hexOf(match[0]))\n for (const match of text.matchAll(SOLID_RGB)) {\n const alpha = match[4]\n if (alpha !== undefined && (alpha.endsWith('%') ? Number(alpha.slice(0, -1)) < 100 : Number(alpha) < 1)) continue\n const channels = [match[1], match[2], match[3]].map((value) => Math.min(255, Number(value)))\n add(`#${channels.map((value) => value.toString(16).padStart(2, '0')).join('')}`)\n }\n }\n return rankBrandColors(weights, AI_THEME_BRAND_COLORS_PER_SOURCE)\n}\n\n/** How colorful a color must be to carry a brand: the inspiration reader's own floor. */\nconst COLORFUL_CHROMA = 0.04\n\nconst colorful = (hex: string | null | undefined): hex is string => !!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).C >= COLORFUL_CHROMA\n\n/**\n * The brand and accent a source's look facts give (AGL-4108): the fill of\n * its filled buttons as the brand, the color of its links as the accent\n * where it is a color of its own, and the reverse where its buttons are not\n * colorful. The theme draws the brand at the nearest shade of it that reads\n * (`aiSiteColors`): aglyn.com's light blue buttons, under white words at\n * 2.4:1, come out at the deeper blue of its own links.\n */\nexport function aiSiteImportBrandOf(facts: Pick<SiteImportLookFacts, 'buttonFill' | 'link'> | null | undefined): { brand: string; accent: string | null } | null {\n const fill = colorful(facts?.buttonFill) ? (facts?.buttonFill as string).toLowerCase() : null\n const link = colorful(facts?.link) ? (facts?.link as string).toLowerCase() : null\n const brand = fill ?? link\n if (!brand) return null\n return { brand, accent: link && link !== brand ? link : null }\n}\n\n/**\n * The look a source's signals pin (AGL-4084), drawn the way a guided start's\n * is: the kind of site its own description says, the import's seed, its\n * strongest color as the brand. What the reader found of its look\n * (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its\n * links' color as the accent, its page's ground, and its own fonts where the\n * catalog has them (`fonts`). `null` where the source showed no color to\n * carry a brand, so the site keeps the theme it has.\n */\nexport function aiSiteImportStyle(\n site: AiSiteInspirationSite | null,\n input: {\n seed: number\n description: string\n avoid?: readonly AiSiteStyle[]\n facts?: SiteImportLookFacts | null\n fonts?: AiSiteStyle['sourceFonts']\n },\n): AiSiteStyle | null {\n const facts = input.facts ?? null\n const own = aiSiteImportBrandOf(facts)\n if (!site && !own) return null\n const kind = aiSiteKindFor(input.description)\n const pins = site ? aiSiteInspirationLookPins({ v: 1, sites: [site], unread: 0 }, { kind, seed: input.seed }) : {}\n if (own) {\n pins.brand = own.brand\n pins.hue = Math.round(aiHexOklch(own.brand).h) % 360\n if (own.accent) pins.accent = Math.round(aiHexOklch(own.accent).h) % 360\n }\n // Its buttons' corners round the theme's shape where its stylesheets did not say (AGL-4108).\n const radius = facts?.buttonRadius\n if (typeof radius === 'number' && Number.isFinite(radius) && radius >= 0) {\n pins.buttons ??= radius >= 24 ? 'pill' : radius <= 2 ? 'square' : 'rounded'\n pins.corners ??= radius <= 2 ? 'sharp' : radius <= 10 ? 'soft' : radius <= 20 ? 'round' : 'pill'\n }\n // Its eyebrows as it sets them (AGL-4138): spaced capitals with no line before them — the\n // reader takes an eyebrow only in capitals, and no mark a page draws before one is a word of\n // it — and their own color, where it is one, as the theme's third.\n if (facts) pins.eyebrow = 'caps'\n if (colorful(facts?.eyebrow)) pins.tertiary = (facts?.eyebrow as string).toLowerCase()\n if (!pins.brand) return null\n const style = aiSiteStyleFor({ kind, answer: {}, seed: input.seed, brand: pins.brand, avoid: input.avoid ?? [], pins })\n const page = facts?.background && /^#[0-9a-f]{6}$/i.test(facts.background) ? facts.background.toLowerCase() : null\n return {\n ...style,\n ...(page ? { page } : {}),\n ...(input.fonts ? { sourceFonts: input.fonts } : {}),\n }\n}\n\n/** A family's facts, as the theme font catalog answers them. */\nexport type AiSiteImportFontFacts = (family: string) => Promise<ThemeFontFacts | undefined>\n\n/**\n * The source's own fonts (AGL-4108), each where the theme font catalog has\n * the family (Google Fonts', as the fonts plugin registers it), or the\n * source loads it from Google Fonts itself: its body's and its headings'.\n * `null` where its body's family is neither, and the pairing of the source's\n * type mood sets the site instead.\n */\nexport async function aiSiteImportSourceFonts(\n facts: Pick<SiteImportLookFacts, 'fonts'> | null | undefined,\n lookup: AiSiteImportFontFacts = themeFontFacts,\n): Promise<AiSiteStyle['sourceFonts']> {\n const fonts = facts?.fonts\n if (!fonts?.body) return null\n const loaded = new Set(fonts.google.map((family) => family.toLowerCase()))\n const resolve = async (family: string | null): Promise<AiSiteSourceFont | null> => {\n if (!family) return null\n const known = await lookup(family).catch(() => undefined)\n if (known) return { family: known.family, category: known.category, weights: [...known.weights] }\n return loaded.has(family.toLowerCase()) ? { family, category: 'sans-serif', weights: [] } : null\n }\n const body = await resolve(fonts.body)\n if (!body) return null\n const heading = fonts.headings && fonts.headings.toLowerCase() !== body.family.toLowerCase() ? await resolve(fonts.headings) : null\n return { body, heading }\n}\n\n/**\n * The site's listing in the home page's own words (AGL-4084), as field\n * paths: its title and description each only where the site still has the\n * one it was created with, so an owner's own listing is never written over.\n * `{}` with nothing to write.\n */\nexport function aiSiteImportListingUpdates(seo: unknown, displayName: unknown, home: Pick<AiSiteImportHome, 'title' | 'description'>): Record<string, string> {\n const seeded = aiSiteListingSeeded(seo, displayName)\n const current = (seo && typeof seo === 'object' ? seo : {}) as Record<string, unknown>\n const updates: Record<string, string> = {}\n const title = home.title.replace(/\\s+/g, ' ').trim()\n const description = home.description.replace(/\\s+/g, ' ').trim()\n if (title && seeded.title && title !== current['title']) updates['seo.title'] = title\n if (description && seeded.description && description !== current['description']) updates['seo.description'] = description\n return updates\n}\n\n/** Whether the site's share picture is still open: none, or the starter's (AGL-3988). */\nfunction shareOpen(seo: unknown): boolean {\n const image = (seo as { image?: unknown } | null | undefined)?.image\n if (image === undefined || image === null) return true\n return typeof image === 'string' && (!image.trim() || aiSiteIsStarterSrc(image))\n}\n\n/** Turns an SVG drawing into a PNG of a height; `null` where it cannot. */\nexport type AiSiteImportRasterize = (svg: Uint8Array, height: number) => Promise<Uint8Array | null>\n\nexport interface AiSiteImportLookDeps {\n fetch?: Fetch\n /** The edge headers for the source, asked with its domain; absent, the edge is asked as the crawl asks it (AGL-4108). */\n headersFor?: SiteImportCrawlSeams['headersFor']\n /** The edge's own answer, per address (`siteImportEdgeHeadersFor`), where no `headersFor` is given. */\n edgeHeadersFor?: typeof siteImportEdgeHeadersFor\n /** A family's facts in the theme font catalog (`themeFontFacts`). */\n fontFacts?: AiSiteImportFontFacts\n save?: typeof aiSaveSiteTheme\n others?: typeof aiWorkspaceSiteStyles\n ingest?: PluginMediaIngest | null\n rasterize?: AiSiteImportRasterize\n /** The site's document, as the listing reads it. */\n readHost?: (firestore: FirebaseFirestore.Firestore, hostId: string) => Promise<Record<string, unknown> | null>\n writeHost?: (firestore: FirebaseFirestore.Firestore, hostId: string, updates: Record<string, unknown>) => Promise<void>\n /** Re-fans the rows every site list reads a site's icon from (AGL-3972), after the look sets one. */\n syncMemberships?: (orgId: string, hostId: string) => Promise<void>\n}\n\n/** The most pictures the home page's menus bring into the library (AGL-4139). */\nexport const AI_SITE_IMPORT_MENU_PICTURES = 4\n\n/** The pictures the home page's menus show (AGL-4139), each once, the first few: a featured card's. */\nexport function aiSiteImportMenuPictures(home: Pick<AiSiteImportHome, 'nav'>): Array<{ url: string; alt: string }> {\n const seen = new Set<string>()\n const out: Array<{ url: string; alt: string }> = []\n for (const group of home.nav?.items ?? []) {\n for (const column of group.columns ?? []) {\n if (!column.image || seen.has(column.image.url) || out.length >= AI_SITE_IMPORT_MENU_PICTURES) continue\n seen.add(column.image.url)\n out.push({ url: column.image.url, alt: column.image.alt })\n }\n }\n return out\n}\n\n/** Whether the site still has no icon of its own (AGL-4139): an owner's is never written over. */\nfunction faviconOpen(seo: unknown): boolean {\n const favicon = (seo as { favicon?: unknown } | null | undefined)?.favicon\n return favicon === undefined || favicon === null || (typeof favicon === 'string' && !favicon.trim())\n}\n\n\nexport interface AiSiteImportLookInput {\n firestore: FirebaseFirestore.Firestore\n hostId: string\n orgId: string\n /** The member the logo and the share picture are stored as. */\n uid: string\n /** The import job's id, which the look's seed is drawn from. */\n jobId: string\n domain: string\n home: AiSiteImportHome\n at: string\n signal?: AbortSignal\n}\n\nasync function readHostDoc(firestore: FirebaseFirestore.Firestore, hostId: string): Promise<Record<string, unknown> | null> {\n const snapshot = await firestore.collection('hosts').doc(hostId).get()\n return snapshot.exists ? ((snapshot.data() ?? {}) as Record<string, unknown>) : null\n}\n\nasync function writeHostDoc(firestore: FirebaseFirestore.Firestore, hostId: string, updates: Record<string, unknown>): Promise<void> {\n await firestore.collection('hosts').doc(hostId).update(updates)\n}\n\n/** Turns an SVG into a PNG in this process, where `sharp` is shipped; `null` where it is not. */\nasync function rasterizeHere(svg: Uint8Array, height: number): Promise<Uint8Array | null> {\n const images = await import('./ai-image-reads')\n const origin = images.aiImageReadsOrigin()\n if (origin) return images.requestAiLogoRaster(origin, svg, height)\n return images.rasterizeAiLogoSvg(svg, height)\n}\n\n/**\n * The source header's logo in the site's library (AGL-4084), once: the copy\n * a page already brought in is reused by its key. An SVG becomes a PNG.\n * `null` where it cannot be brought in, and the header then prints the name.\n */\nexport async function aiSiteImportLogo(\n input: { hostId: string; uid: string; domain: string; logo: NonNullable<AiSiteImportHome['brand']['logo']>; alt: string; headersFor?: SiteImportHeadersFor | null; signal?: AbortSignal },\n deps: { fetch?: Fetch; ingest: PluginMediaIngest | null; rasterize?: AiSiteImportRasterize },\n): Promise<AiSiteImportPhoto | null> {\n const ingest = deps.ingest\n const url = siteImportLogoUrl(input.logo.url)\n if (!ingest?.findImportedPhoto || !url) return null\n const sourceKey = siteImportImageKey(url)\n try {\n const held = await ingest.findImportedPhoto({ hostId: input.hostId, sourceKey })\n if (held) return { mediaId: held.mediaId, src: held.src, alt: input.alt, from: url, ...(held.width ? { width: held.width } : {}), ...(held.height ? { height: held.height } : {}) }\n const fetched = await (deps.fetch ?? fetchPublicTextDetailed)(url, {\n maxBytes: AI_SITE_IMPORT_LOGO_MAX_BYTES,\n accept: /^image\\//i,\n acceptHeader: 'image/svg+xml,image/png,image/webp,image/jpeg;q=0.9',\n userAgent: AGLYN_BOT_USER_AGENT,\n timeoutMs: LOOK_READ_MS,\n refuseOver: true,\n binary: true,\n ...(input.signal ? { signal: input.signal } : {}),\n ...(input.headersFor ? { headersFor: input.headersFor } : {}),\n })\n if (!fetched.ok || !fetched.data?.byteLength) return null\n const type = fetched.contentType.split(';')[0].trim().toLowerCase()\n let bytes: Uint8Array | null = fetched.data\n let contentType = type\n if (type === 'image/svg+xml' || input.logo.type === 'svg') {\n bytes = await (deps.rasterize ?? rasterizeHere)(fetched.data, AI_SITE_IMPORT_LOGO_HEIGHT).catch(() => null)\n contentType = 'image/png'\n } else if (!/^image\\/(?:png|jpeg|webp|gif)$/.test(type)) {\n return null\n }\n if (!bytes?.byteLength) return null\n const stored = await ingest.ingest({\n hostId: input.hostId,\n uid: input.uid,\n fileName: `logo.${contentType === 'image/jpeg' ? 'jpg' : contentType.split('/')[1]}`,\n contentType,\n bytes,\n ...(input.alt ? { alt: input.alt.slice(0, 250) } : {}),\n importedFrom: { key: sourceKey, url, domain: input.domain },\n })\n if (!stored.ok) return null\n return { mediaId: stored.mediaId, src: stored.src, alt: input.alt, from: url, ...(stored.width ? { width: stored.width } : {}), ...(stored.height ? { height: stored.height } : {}) }\n } catch (error) {\n console.warn('[site-import] the logo could not be brought in', { hostId: input.hostId, error })\n return null\n }\n}\n\n/** The look pass (AGL-4084): the theme, the logo and the listing, from the owner's own home page. No model. */\nexport async function aiRunSiteImportLook(input: AiSiteImportLookInput, deps: AiSiteImportLookDeps = {}): Promise<AiSiteImportLook> {\n const { firestore, hostId, home } = input\n const headersFor = await aiSiteImportLookHeaders(input.domain, deps)\n const seed = aiSiteSeed(input.jobId)\n const page = await readSiteImportLookPage(home.url, { ...(deps.fetch ? { fetch: deps.fetch } : {}), headersFor, ...(input.signal ? { signal: input.signal } : {}) })\n // The source's own signals, its brand colors as it draws them solid.\n const signals = page ? aiSiteInspirationSignals(page) : null\n const site = signals && page ? { ...signals, colors: aiSiteImportBrandColors(page) } : signals\n const avoid = await (deps.others ?? aiWorkspaceSiteStyles)(firestore, { orgId: input.orgId, hostId })\n // What the reader found of its look, its buttons, ground and fonts (AGL-4108).\n const facts = home.look ?? null\n const fonts = await aiSiteImportSourceFonts(facts, deps.fontFacts)\n const style = aiSiteImportStyle(site, { seed, description: `${home.siteName} ${home.description}`, avoid, facts, fonts })\n let theme: AiSiteImportLook['theme'] = 'unread'\n if (style) {\n const saved = await (deps.save ?? aiSaveSiteTheme)(firestore, { hostId, jobId: input.jobId, style })\n if (saved.write === 'missing') throw new Error(`site ${hostId} vanished while its look was brought in`)\n theme = saved.write === 'kept' ? 'kept' : 'applied'\n }\n const ingest = deps.ingest ?? null\n const logo = home.brand.logo\n ? await aiSiteImportLogo(\n { hostId, uid: input.uid, domain: input.domain, logo: home.brand.logo, alt: home.siteName || home.brand.text, headersFor, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}), ...(deps.rasterize ? { rasterize: deps.rasterize } : {}) },\n )\n : null\n // The pictures its menus show, in the library like its pages' photos (AGL-4139), for the header's panels.\n const menuImages = aiSiteImportMenuPictures(home)\n const pictures = menuImages.length\n ? (\n await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: menuImages, deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n ).assets\n : []\n // The site's listing in its own words, only over the one it was created with.\n let seo = false\n const host = await (deps.readHost ?? readHostDoc)(firestore, hostId)\n if (host) {\n const updates: Record<string, unknown> = aiSiteImportListingUpdates(host['seo'], host['displayName'], home)\n // The site's icon from the one its head names, where the site has none (AGL-4139).\n if (home.favicon && faviconOpen(host['seo'])) {\n const icon = await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: [{ url: home.favicon, alt: '' }], deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n const photo = icon.assets[0]\n if (photo) updates['seo.favicon'] = photo.src\n }\n if (home.ogImage && shareOpen(host['seo'])) {\n const share = await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: [{ url: home.ogImage, alt: '' }], deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n const photo = share.assets[0]\n if (photo) {\n updates['seo.image'] = photo.src\n if (photo.width) updates['seo.imageWidth'] = photo.width\n if (photo.height) updates['seo.imageHeight'] = photo.height\n }\n }\n if (Object.keys(updates).length) {\n await (deps.writeHost ?? writeHostDoc)(firestore, hostId, updates)\n seo = true\n // Every site list reads the icon the members' rows carry (AGL-3972).\n if (updates['seo.favicon']) {\n await (deps.syncMemberships ?? syncHostProjectionForMembers)(input.orgId, hostId).catch((error: unknown) => {\n console.warn('[site-import] the site lists were not told of the new icon', { hostId, error })\n })\n }\n }\n }\n const drawn = style\n ? {\n ...(typeof style.headerAlign === 'string' ? { headerAlign: style.headerAlign } : {}),\n ...(typeof style.rhythm === 'string' ? { rhythm: style.rhythm } : {}),\n ...(typeof style.motion === 'string' ? { motion: style.motion } : {}),\n }\n : null\n const colors = [...new Set([...(facts ? [facts.buttonFill, facts.link, facts.eyebrow].filter(colorful).map((hex) => hex.toLowerCase()) : []), ...(site?.colors ?? [])])]\n return { at: input.at, theme, colors, logo, ...(pictures.length ? { pictures } : {}), seo, seed: style ? style.seed : seed, style: drawn }\n}\n\n/**\n * The headers the look's reads of the source go with, per address (AGL-4108),\n * exactly as the crawl's (`siteRequestHeaders`): the caller's where it hands\n * them in, else the edge's own, so a site this platform serves is read past\n * its challenge however the step was registered; and nothing for any address\n * off the site's two origins, a redirect hop's included. Never throws.\n *\n * The 10/29 look read went without the header twice over: no caller handed\n * one in, and the read passed headers the fetch does not take, which is why\n * this is a function the fetch asks for every hop (`headersFor`).\n */\nexport async function aiSiteImportLookHeaders(\n domain: string,\n deps: Pick<AiSiteImportLookDeps, 'headersFor' | 'edgeHeadersFor'>,\n): Promise<SiteImportHeadersFor> {\n const origins = siteImportOrigins(domain)\n let inner: SiteImportHeadersFor = NO_SITE_IMPORT_HEADERS\n try {\n if (deps.headersFor) {\n const headers = await deps.headersFor(domain)\n if (headers && Object.keys(headers).length) inner = () => headers\n } else {\n inner = await (deps.edgeHeadersFor ?? siteImportEdgeHeadersFor)(origins)\n }\n } catch (error) {\n console.warn('[site-import] the edge headers could not be read; reading the look without them', { domain, error })\n }\n return (url: URL) => (origins.includes(url.origin) ? inner(url) : {})\n}\n"],"names":["themeFontFacts","syncHostProjectionForMembers","aiSiteListingSeeded","aiSiteKindFor","aiHexOklch","aiSiteSeed","aiSiteStyleFor","aiSiteIsStarterSrc","AGLYN_BOT_USER_AGENT","siteImportOrigins","NO_SITE_IMPORT_HEADERS","siteImportEdgeHeadersFor","bringInSiteImportPhotos","siteImportImageKey","siteImportLogoUrl","aiSaveSiteTheme","aiWorkspaceSiteStyles","aiSiteInspirationLookPins","aiSiteInspirationSignals","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","AI_SITE_IMPORT_LOGO_HEIGHT","AI_SITE_IMPORT_LOGO_MAX_BYTES","LOOK_READ_MS","readSiteImportLookPage","url","input","fetchText","fetch","headersFor","read","address","maxBytes","accept","userAgent","timeoutMs","signal","catch","page","ok","stylesheets","sheet","text","slice","css","push","html","SOLID_HEX","SOLID_RGB","THEME_COLOR","hexOf","value","raw","trim","toLowerCase","test","aiSiteImportBrandColors","match","weights","Map","add","hex","weight","set","get","matchAll","alpha","undefined","endsWith","Number","channels","map","Math","min","toString","padStart","join","COLORFUL_CHROMA","colorful","C","aiSiteImportBrandOf","facts","fill","buttonFill","link","brand","accent","aiSiteImportStyle","site","own","kind","description","pins","v","sites","unread","seed","hue","round","h","radius","buttonRadius","isFinite","buttons","corners","eyebrow","tertiary","style","answer","avoid","background","fonts","sourceFonts","aiSiteImportSourceFonts","lookup","body","loaded","Set","google","family","resolve","known","category","has","heading","headings","aiSiteImportListingUpdates","seo","displayName","home","seeded","current","updates","title","replace","shareOpen","image","AI_SITE_IMPORT_MENU_PICTURES","aiSiteImportMenuPictures","seen","out","group","nav","items","column","columns","length","alt","faviconOpen","favicon","readHostDoc","firestore","hostId","snapshot","collection","doc","exists","data","writeHostDoc","update","rasterizeHere","svg","height","images","origin","aiImageReadsOrigin","requestAiLogoRaster","rasterizeAiLogoSvg","aiSiteImportLogo","deps","ingest","logo","findImportedPhoto","sourceKey","fetched","held","mediaId","src","from","width","acceptHeader","refuseOver","binary","byteLength","type","contentType","split","bytes","rasterize","stored","uid","fileName","importedFrom","key","domain","error","console","warn","aiRunSiteImportLook","aiSiteImportLookHeaders","jobId","signals","colors","others","orgId","look","fontFacts","siteName","theme","saved","save","write","Error","menuImages","pictures","deadlineAt","Date","now","assets","host","readHost","icon","photo","ogImage","share","Object","keys","writeHost","syncMemberships","drawn","headerAlign","rhythm","motion","filter","at","origins","inner","headers","edgeHeadersFor","includes"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAiC2C;AAG3C,SAASA,cAAc,QAA6B,wDAAuD;AAC3G,SAASC,4BAA4B,QAAQ,mDAAkD;AAC/F,SAASC,mBAAmB,QAAQ,6BAAyB;AAE7D,SAASC,aAAa,QAAQ,4BAAwB;AACtD,SAASC,UAAU,EAAEC,UAA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O;aAAC,CAACgI,MAAM,CAAC3J,UAAUP,GAAG,CAAC,CAACV,MAAQA,IAAIP,WAAW,MAAM,EAAE;uBAAOkC,wBAAAA,KAAMkH,MAAM,mBAAI,EAAE;SAAE;KAAE;IACxK,OAAO;QAAEgC,IAAIhN,MAAMgN,EAAE;QAAE1B;QAAON;QAAQ/B;OAAU2C,SAASpE,MAAM,GAAG;QAAEoE;IAAS,IAAI,CAAC;QAAIvF;QAAK/B,MAAMW,QAAQA,MAAMX,IAAI,GAAGA;QAAMW,OAAO0H;;AACrI;AAEA;;;;;;;;;;CAUC,GACD,OAAO,eAAe9B,wBACpBL,MAAc,EACdzB,IAAiE;IAEjE,MAAMkE,UAAUxO,kBAAkB+L;IAClC,IAAI0C,QAA8BxO;IAClC,IAAI;QACF,IAAIqK,KAAK5I,UAAU,EAAE;YACnB,MAAMgN,UAAU,MAAMpE,KAAK5I,UAAU,CAACqK;YACtC,IAAI2C,WAAWZ,OAAOC,IAAI,CAACW,SAAS3F,MAAM,EAAE0F,QAAQ,IAAMC;QAC5D,OAAO;gBACUpE;YAAfmE,QAAQ,MAAM,EAACnE,uBAAAA,KAAKqE,cAAc,YAAnBrE,uBAAuBpK,0BAA0BsO;QAClE;IACF,EAAE,OAAOxC,OAAO;QACdC,QAAQC,IAAI,CAAC,mFAAmF;YAAEH;YAAQC;QAAM;IAClH;IACA,OAAO,CAAC1K,MAAckN,QAAQI,QAAQ,CAACtN,IAAI2I,MAAM,IAAIwE,MAAMnN,OAAO,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-look.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * THE SITE BROUGHT IN KEEPS ITS OWN LOOK (AGL-4084).\n *\n * The first wave's look pass, before the header and footer, with no model:\n *\n * - **The theme.** The owner's own home page is read once more as AglynBot,\n * with the edge headers a site this platform serves gets whether or not a\n * caller hands them in (AGL-4108: production handed none, our own edge\n * challenged the read, and the 10/29 site kept the starter's indigo), and\n * the signals a guided start reads off the sites a person likes\n * (AGL-3975: colors, ground, type mood, corners, buttons, cards, header,\n * density, motion) pin the look. What the reader found of the source's\n * look (AGL-4106) pins it closer (AGL-4108): its buttons' fill is the\n * brand and its links' color the accent, its page's ground is the site's,\n * its eyebrows' own color the theme's third and its eyebrows spaced\n * capitals with no line before them (AGL-4138), and its own font family\n * is the site's wherever the theme font catalog has it, else a pairing of\n * its type mood. The look is drawn and saved\n * exactly as a guided start's (`aiSiteStyleFor`, `aiSaveSiteTheme`): a\n * built-in base plus the brand colors and fonts, every color held to the\n * theme's reading checks. A site whose owner already chose a theme keeps\n * it.\n * - **The logo.** The source header's logo, as the source draws it, into the\n * site's media library once: an SVG is turned into a PNG 192 pixels tall\n * (the library takes pictures, not drawings), a picture is kept as it is.\n * - **The listing.** The home page's own title, description and share\n * picture become the site's listing, only while the site still has the\n * listing it was created with: an owner's own words are never written\n * over.\n *\n * Nothing here fails a wave: a source whose look cannot be read keeps the\n * site's theme, and a logo that cannot be brought in leaves the header its\n * name.\n *=========================================*/\n\nimport type { PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { themeFontFacts, type ThemeFontFacts } from '@aglyn/aglyn/plugin-manager/plugin-theme-font-catalog'\nimport { syncHostProjectionForMembers } from '@aglyn/tenant-data-admin/server/host-memberships'\nimport { aiSiteListingSeeded } from '../model/ai-site-entity'\nimport type { AiSiteImportFinish, AiSiteImportHome, AiSiteImportLook, AiSiteImportPhoto, SiteImportLookFacts } from '../model/ai-site-import'\nimport { aiSiteKindFor } from '../model/ai-site-kinds'\nimport { aiHexOklch, aiSiteSeed, aiSiteStyleFor, type AiSiteLookPins, type AiSiteSourceFont, type AiSiteStyle } from '../model/ai-site-look'\nimport { aiSiteIsStarterSrc } from '../model/ai-site-photos'\nimport { AGLYN_BOT_USER_AGENT, siteImportOrigins, type SiteImportCrawlSeams } from '../site-import/site-import-crawl'\nimport { NO_SITE_IMPORT_HEADERS, siteImportEdgeHeadersFor, type SiteImportHeadersFor } from '../site-import/site-import-edge'\nimport { bringInSiteImportPhotos, siteImportImageKey, siteImportLogoUrl } from '../site-import/site-import-images'\nimport { aiSaveSiteTheme, aiWorkspaceSiteStyles } from './ai-job-site-look'\nimport { aiSiteInspirationLookPins } from './ai-site-inspiration'\nimport { aiSiteInspirationSignals, type AiSiteInspirationSite } from './ai-site-inspiration-signals'\nimport {\n AI_THEME_BRAND_COLORS_PER_SOURCE,\n AI_THEME_REFERENCE_MAX_BYTES,\n AI_THEME_REFERENCE_STYLESHEETS,\n AI_THEME_STYLESHEET_MAX_BYTES,\n AI_THEME_THEME_COLOR_WEIGHT,\n fetchPublicTextDetailed,\n rankBrandColors,\n stylesheetUrlsOf,\n type AiReferencePage,\n type PublicFetchOptions,\n type PublicFetchResult,\n} from './ai-theme-brand-inputs'\n\n/** The height an SVG logo is drawn at as a picture: crisp at twice the header's 40. */\nexport const AI_SITE_IMPORT_LOGO_HEIGHT = 192\n\n/** The largest logo file read. */\nexport const AI_SITE_IMPORT_LOGO_MAX_BYTES = 1024 * 1024\n\n/** One read's own clock in the look pass. */\nconst LOOK_READ_MS = 8_000\n\ntype Fetch = (url: string, options: PublicFetchOptions) => Promise<PublicFetchResult>\n\n/**\n * The home page and its first stylesheets, read as AglynBot (AGL-4084).\n * `headersFor` is asked for every request and every redirect hop, as the\n * crawl asks it (`aiSiteImportLookHeaders`: the edge header only to the\n * site's own origins). `null` when the page cannot be read.\n */\nexport async function readSiteImportLookPage(\n url: string,\n input: { fetch?: Fetch; headersFor?: SiteImportHeadersFor | null; signal?: AbortSignal },\n): Promise<AiReferencePage | null> {\n const fetchText = input.fetch ?? fetchPublicTextDetailed\n const headersFor = input.headersFor ?? null\n const read = (address: string, maxBytes: number, accept: RegExp) =>\n fetchText(address, {\n maxBytes,\n accept,\n userAgent: AGLYN_BOT_USER_AGENT,\n timeoutMs: LOOK_READ_MS,\n ...(input.signal ? { signal: input.signal } : {}),\n ...(headersFor ? { headersFor } : {}),\n }).catch(() => null)\n const page = await read(url, AI_THEME_REFERENCE_MAX_BYTES, /text\\/html|application\\/xhtml\\+xml/i)\n if (!page?.ok) return null\n const stylesheets: string[] = []\n for (const sheet of stylesheetUrlsOf(page.text, page.url).slice(0, AI_THEME_REFERENCE_STYLESHEETS)) {\n const css = await read(sheet, AI_THEME_STYLESHEET_MAX_BYTES, /text\\/css/i)\n if (css?.ok) stylesheets.push(css.text)\n }\n return { url: page.url, html: page.text, stylesheets }\n}\n\nconst SOLID_HEX = /(?<!&)#(?:[0-9a-f]{6}|[0-9a-f]{3})(?![0-9a-z])/gi\nconst SOLID_RGB = /rgba?\\(\\s*(\\d{1,3})\\s*[,\\s]\\s*(\\d{1,3})\\s*[,\\s]\\s*(\\d{1,3})\\s*(?:[,/]\\s*([\\d.]+%?)\\s*)?\\)/gi\nconst THEME_COLOR = /<meta\\b[^>]*\\bname\\s*=\\s*[\"']?theme-color\\b[^>]*\\bcontent\\s*=\\s*[\"']?\\s*(#[0-9a-f]{3,6})/gi\n\nconst hexOf = (value: string): string | null => {\n const raw = value.trim().toLowerCase()\n if (/^#[0-9a-f]{6}$/.test(raw)) return raw\n if (/^#[0-9a-f]{3}$/.test(raw)) return `#${raw[1]}${raw[1]}${raw[2]}${raw[2]}${raw[3]}${raw[3]}`\n return null\n}\n\n/**\n * A source's brand colors as it DRAWS them (AGL-4084): the colors its markup\n * and stylesheets use solid, most used first, the colorful before the greys.\n * A translucent color is a tint of one (a hover, a focus ring), never a use\n * of it, so it is not counted: aglyn.com's focus rings, a light blue at a\n * quarter strength, outnumbered the deep blue its buttons and links are\n * drawn in, which the theme reader would otherwise take as its brand.\n */\nexport function aiSiteImportBrandColors(page: Pick<AiReferencePage, 'html' | 'stylesheets'>): string[] {\n const weights = new Map<string, number>()\n const add = (hex: string | null, weight = 1) => {\n if (hex) weights.set(hex, (weights.get(hex) ?? 0) + weight)\n }\n for (const match of page.html.matchAll(THEME_COLOR)) add(hexOf(match[1] ?? ''), AI_THEME_THEME_COLOR_WEIGHT)\n for (const text of [page.html, ...page.stylesheets]) {\n for (const match of text.matchAll(SOLID_HEX)) add(hexOf(match[0]))\n for (const match of text.matchAll(SOLID_RGB)) {\n const alpha = match[4]\n if (alpha !== undefined && (alpha.endsWith('%') ? Number(alpha.slice(0, -1)) < 100 : Number(alpha) < 1)) continue\n const channels = [match[1], match[2], match[3]].map((value) => Math.min(255, Number(value)))\n add(`#${channels.map((value) => value.toString(16).padStart(2, '0')).join('')}`)\n }\n }\n return rankBrandColors(weights, AI_THEME_BRAND_COLORS_PER_SOURCE)\n}\n\n/** How colorful a color must be to carry a brand: the inspiration reader's own floor. */\nconst COLORFUL_CHROMA = 0.04\n\nconst colorful = (hex: string | null | undefined): hex is string => !!hex && /^#[0-9a-f]{6}$/i.test(hex) && aiHexOklch(hex).C >= COLORFUL_CHROMA\n\n/**\n * The brand and accent a source's look facts give (AGL-4108): the fill of\n * its filled buttons as the brand, the color of its links as the accent\n * where it is a color of its own, and the reverse where its buttons are not\n * colorful. The theme draws the brand at the nearest shade of it that reads\n * (`aiSiteColors`): aglyn.com's light blue buttons, under white words at\n * 2.4:1, come out at the deeper blue of its own links.\n */\nexport function aiSiteImportBrandOf(facts: Pick<SiteImportLookFacts, 'buttonFill' | 'link'> | null | undefined): { brand: string; accent: string | null } | null {\n const fill = colorful(facts?.buttonFill) ? (facts?.buttonFill as string).toLowerCase() : null\n const link = colorful(facts?.link) ? (facts?.link as string).toLowerCase() : null\n const brand = fill ?? link\n if (!brand) return null\n return { brand, accent: link && link !== brand ? link : null }\n}\n\nconst solidHex = (value: string | null | undefined): string | null => (value && /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : null)\n\n/**\n * The look a source's signals pin (AGL-4084), drawn the way a guided start's\n * is: the kind of site its own description says, the import's seed, its\n * strongest color as the brand. What the reader found of its look\n * (`facts`, AGL-4108) pins it closer: its buttons' fill as the brand and its\n * links' color as the accent, its eyebrows' own color as the third, and its\n * own fonts where the catalog has them (`fonts`). `null` where the source\n * showed no color to carry a brand, so the site keeps the theme it has.\n *\n * How the owner asked the site to be finished (AGL-4152) says what else:\n * - **Keep my site** (`keep`, and an import that names none) pins the rest\n * of its look as it draws it: its page's ground and its dark bands', its\n * buttons' corners and case and their own fill and words, every inspiration\n * signal, and its eyebrows set as spaced capitals.\n * - **Improve it** (`improve`) pins only the brand, accent and third colors\n * and the fonts, so the base that suits the kind of site shows with its own\n * corners, buttons, grounds and eyebrows.\n */\nexport function aiSiteImportStyle(\n site: AiSiteInspirationSite | null,\n input: {\n seed: number\n description: string\n avoid?: readonly AiSiteStyle[]\n facts?: SiteImportLookFacts | null\n fonts?: AiSiteStyle['sourceFonts']\n finish?: AiSiteImportFinish | null\n },\n): AiSiteStyle | null {\n const facts = input.facts ?? null\n const finish: AiSiteImportFinish = input.finish === 'improve' ? 'improve' : 'keep'\n const own = aiSiteImportBrandOf(facts)\n if (!site && !own) return null\n const kind = aiSiteKindFor(input.description)\n const signals = site ? aiSiteInspirationLookPins({ v: 1, sites: [site], unread: 0 }, { kind, seed: input.seed }) : {}\n // Improve keeps the brand's colors and its type, and nothing else its source draws.\n const pins: AiSiteLookPins =\n finish === 'improve'\n ? {\n ...(signals.brand ? { brand: signals.brand } : {}),\n ...(signals.hue !== undefined ? { hue: signals.hue } : {}),\n ...(signals.accent !== undefined ? { accent: signals.accent } : {}),\n ...(signals.fonts ? { fonts: signals.fonts } : {}),\n }\n : signals\n if (own) {\n pins.brand = own.brand\n pins.hue = Math.round(aiHexOklch(own.brand).h) % 360\n if (own.accent) pins.accent = Math.round(aiHexOklch(own.accent).h) % 360\n }\n // Its buttons' corners round the theme's shape where its stylesheets did not say (AGL-4108).\n const radius = facts?.buttonRadius\n if (finish === 'keep' && typeof radius === 'number' && Number.isFinite(radius) && radius >= 0) {\n pins.buttons ??= radius >= 24 ? 'pill' : radius <= 2 ? 'square' : 'rounded'\n pins.corners ??= radius <= 2 ? 'sharp' : radius <= 10 ? 'soft' : radius <= 20 ? 'round' : 'pill'\n }\n // Its eyebrows as it sets them (AGL-4138): spaced capitals with no line before them — the\n // reader takes an eyebrow only in capitals, and no mark a page draws before one is a word of\n // it — and their own color, where it is one, as the theme's third.\n if (facts && finish === 'keep') pins.eyebrow = 'caps'\n if (colorful(facts?.eyebrow)) pins.tertiary = (facts?.eyebrow as string).toLowerCase()\n if (!pins.brand) return null\n const style = aiSiteStyleFor({ kind, answer: {}, seed: input.seed, brand: pins.brand, avoid: input.avoid ?? [], pins })\n const fonts = input.fonts ? { sourceFonts: input.fonts } : {}\n if (finish === 'improve') return { ...style, finish, ...fonts }\n // Keep my site (AGL-4152): its grounds, its buttons' case, and its filled buttons as it draws them.\n const page = solidHex(facts?.background)\n const darkPage = solidHex(facts?.darkBackground)\n const buttonFill = solidHex(facts?.buttonFill)\n const buttonText = buttonFill ? solidHex(facts?.buttonText) : null\n const buttonCase = facts?.buttonCase === 'upper' || facts?.buttonCase === 'none' ? facts.buttonCase : null\n return {\n ...style,\n finish,\n ...(page ? { page } : {}),\n ...(darkPage ? { darkPage } : {}),\n ...(buttonCase ? { buttonCase } : {}),\n ...(buttonFill ? { buttonFill } : {}),\n ...(buttonText ? { buttonText } : {}),\n ...fonts,\n }\n}\n\n/** A family's facts, as the theme font catalog answers them. */\nexport type AiSiteImportFontFacts = (family: string) => Promise<ThemeFontFacts | undefined>\n\n/**\n * The source's own fonts (AGL-4108), each where the theme font catalog has\n * the family (Google Fonts', as the fonts plugin registers it), or the\n * source loads it from Google Fonts itself: its body's and its headings'.\n * `null` where its body's family is neither, and the pairing of the source's\n * type mood sets the site instead.\n */\nexport async function aiSiteImportSourceFonts(\n facts: Pick<SiteImportLookFacts, 'fonts'> | null | undefined,\n lookup: AiSiteImportFontFacts = themeFontFacts,\n): Promise<AiSiteStyle['sourceFonts']> {\n const fonts = facts?.fonts\n if (!fonts?.body) return null\n const loaded = new Set(fonts.google.map((family) => family.toLowerCase()))\n const resolve = async (family: string | null): Promise<AiSiteSourceFont | null> => {\n if (!family) return null\n const known = await lookup(family).catch(() => undefined)\n if (known) return { family: known.family, category: known.category, weights: [...known.weights] }\n return loaded.has(family.toLowerCase()) ? { family, category: 'sans-serif', weights: [] } : null\n }\n const body = await resolve(fonts.body)\n if (!body) return null\n const heading = fonts.headings && fonts.headings.toLowerCase() !== body.family.toLowerCase() ? await resolve(fonts.headings) : null\n return { body, heading }\n}\n\n/**\n * The site's listing in the home page's own words (AGL-4084), as field\n * paths: its title and description each only where the site still has the\n * one it was created with, so an owner's own listing is never written over.\n * `{}` with nothing to write.\n */\nexport function aiSiteImportListingUpdates(seo: unknown, displayName: unknown, home: Pick<AiSiteImportHome, 'title' | 'description'>): Record<string, string> {\n const seeded = aiSiteListingSeeded(seo, displayName)\n const current = (seo && typeof seo === 'object' ? seo : {}) as Record<string, unknown>\n const updates: Record<string, string> = {}\n const title = home.title.replace(/\\s+/g, ' ').trim()\n const description = home.description.replace(/\\s+/g, ' ').trim()\n if (title && seeded.title && title !== current['title']) updates['seo.title'] = title\n if (description && seeded.description && description !== current['description']) updates['seo.description'] = description\n return updates\n}\n\n/** Whether the site's share picture is still open: none, or the starter's (AGL-3988). */\nfunction shareOpen(seo: unknown): boolean {\n const image = (seo as { image?: unknown } | null | undefined)?.image\n if (image === undefined || image === null) return true\n return typeof image === 'string' && (!image.trim() || aiSiteIsStarterSrc(image))\n}\n\n/** Turns an SVG drawing into a PNG of a height; `null` where it cannot. */\nexport type AiSiteImportRasterize = (svg: Uint8Array, height: number) => Promise<Uint8Array | null>\n\nexport interface AiSiteImportLookDeps {\n fetch?: Fetch\n /** The edge headers for the source, asked with its domain; absent, the edge is asked as the crawl asks it (AGL-4108). */\n headersFor?: SiteImportCrawlSeams['headersFor']\n /** The edge's own answer, per address (`siteImportEdgeHeadersFor`), where no `headersFor` is given. */\n edgeHeadersFor?: typeof siteImportEdgeHeadersFor\n /** A family's facts in the theme font catalog (`themeFontFacts`). */\n fontFacts?: AiSiteImportFontFacts\n save?: typeof aiSaveSiteTheme\n others?: typeof aiWorkspaceSiteStyles\n ingest?: PluginMediaIngest | null\n rasterize?: AiSiteImportRasterize\n /** The site's document, as the listing reads it. */\n readHost?: (firestore: FirebaseFirestore.Firestore, hostId: string) => Promise<Record<string, unknown> | null>\n writeHost?: (firestore: FirebaseFirestore.Firestore, hostId: string, updates: Record<string, unknown>) => Promise<void>\n /** Re-fans the rows every site list reads a site's icon from (AGL-3972), after the look sets one. */\n syncMemberships?: (orgId: string, hostId: string) => Promise<void>\n}\n\n/** The most pictures the home page's menus bring into the library (AGL-4139). */\nexport const AI_SITE_IMPORT_MENU_PICTURES = 4\n\n/** The pictures the home page's menus show (AGL-4139), each once, the first few: a featured card's. */\nexport function aiSiteImportMenuPictures(home: Pick<AiSiteImportHome, 'nav'>): Array<{ url: string; alt: string }> {\n const seen = new Set<string>()\n const out: Array<{ url: string; alt: string }> = []\n for (const group of home.nav?.items ?? []) {\n for (const column of group.columns ?? []) {\n if (!column.image || seen.has(column.image.url) || out.length >= AI_SITE_IMPORT_MENU_PICTURES) continue\n seen.add(column.image.url)\n out.push({ url: column.image.url, alt: column.image.alt })\n }\n }\n return out\n}\n\n/** Whether the site still has no icon of its own (AGL-4139): an owner's is never written over. */\nfunction faviconOpen(seo: unknown): boolean {\n const favicon = (seo as { favicon?: unknown } | null | undefined)?.favicon\n return favicon === undefined || favicon === null || (typeof favicon === 'string' && !favicon.trim())\n}\n\n\nexport interface AiSiteImportLookInput {\n firestore: FirebaseFirestore.Firestore\n hostId: string\n orgId: string\n /** The member the logo and the share picture are stored as. */\n uid: string\n /** The import job's id, which the look's seed is drawn from. */\n jobId: string\n domain: string\n home: AiSiteImportHome\n at: string\n signal?: AbortSignal\n /** How the site is finished (AGL-4152): Keep my site keeps more of the source's look. Absent is `keep`. */\n finish?: AiSiteImportFinish | null\n}\n\nasync function readHostDoc(firestore: FirebaseFirestore.Firestore, hostId: string): Promise<Record<string, unknown> | null> {\n const snapshot = await firestore.collection('hosts').doc(hostId).get()\n return snapshot.exists ? ((snapshot.data() ?? {}) as Record<string, unknown>) : null\n}\n\nasync function writeHostDoc(firestore: FirebaseFirestore.Firestore, hostId: string, updates: Record<string, unknown>): Promise<void> {\n await firestore.collection('hosts').doc(hostId).update(updates)\n}\n\n/** Turns an SVG into a PNG in this process, where `sharp` is shipped; `null` where it is not. */\nasync function rasterizeHere(svg: Uint8Array, height: number): Promise<Uint8Array | null> {\n const images = await import('./ai-image-reads')\n const origin = images.aiImageReadsOrigin()\n if (origin) return images.requestAiLogoRaster(origin, svg, height)\n return images.rasterizeAiLogoSvg(svg, height)\n}\n\n/**\n * The source header's logo in the site's library (AGL-4084), once: the copy\n * a page already brought in is reused by its key. An SVG becomes a PNG.\n * `null` where it cannot be brought in, and the header then prints the name.\n */\nexport async function aiSiteImportLogo(\n input: { hostId: string; uid: string; domain: string; logo: NonNullable<AiSiteImportHome['brand']['logo']>; alt: string; headersFor?: SiteImportHeadersFor | null; signal?: AbortSignal },\n deps: { fetch?: Fetch; ingest: PluginMediaIngest | null; rasterize?: AiSiteImportRasterize },\n): Promise<AiSiteImportPhoto | null> {\n const ingest = deps.ingest\n const url = siteImportLogoUrl(input.logo.url)\n if (!ingest?.findImportedPhoto || !url) return null\n const sourceKey = siteImportImageKey(url)\n try {\n const held = await ingest.findImportedPhoto({ hostId: input.hostId, sourceKey })\n if (held) return { mediaId: held.mediaId, src: held.src, alt: input.alt, from: url, ...(held.width ? { width: held.width } : {}), ...(held.height ? { height: held.height } : {}) }\n const fetched = await (deps.fetch ?? fetchPublicTextDetailed)(url, {\n maxBytes: AI_SITE_IMPORT_LOGO_MAX_BYTES,\n accept: /^image\\//i,\n acceptHeader: 'image/svg+xml,image/png,image/webp,image/jpeg;q=0.9',\n userAgent: AGLYN_BOT_USER_AGENT,\n timeoutMs: LOOK_READ_MS,\n refuseOver: true,\n binary: true,\n ...(input.signal ? { signal: input.signal } : {}),\n ...(input.headersFor ? { headersFor: input.headersFor } : {}),\n })\n if (!fetched.ok || !fetched.data?.byteLength) return null\n const type = fetched.contentType.split(';')[0].trim().toLowerCase()\n let bytes: Uint8Array | null = fetched.data\n let contentType = type\n if (type === 'image/svg+xml' || input.logo.type === 'svg') {\n bytes = await (deps.rasterize ?? rasterizeHere)(fetched.data, AI_SITE_IMPORT_LOGO_HEIGHT).catch(() => null)\n contentType = 'image/png'\n } else if (!/^image\\/(?:png|jpeg|webp|gif)$/.test(type)) {\n return null\n }\n if (!bytes?.byteLength) return null\n const stored = await ingest.ingest({\n hostId: input.hostId,\n uid: input.uid,\n fileName: `logo.${contentType === 'image/jpeg' ? 'jpg' : contentType.split('/')[1]}`,\n contentType,\n bytes,\n ...(input.alt ? { alt: input.alt.slice(0, 250) } : {}),\n importedFrom: { key: sourceKey, url, domain: input.domain },\n })\n if (!stored.ok) return null\n return { mediaId: stored.mediaId, src: stored.src, alt: input.alt, from: url, ...(stored.width ? { width: stored.width } : {}), ...(stored.height ? { height: stored.height } : {}) }\n } catch (error) {\n console.warn('[site-import] the logo could not be brought in', { hostId: input.hostId, error })\n return null\n }\n}\n\n/** The look pass (AGL-4084): the theme, the logo and the listing, from the owner's own home page. No model. */\nexport async function aiRunSiteImportLook(input: AiSiteImportLookInput, deps: AiSiteImportLookDeps = {}): Promise<AiSiteImportLook> {\n const { firestore, hostId, home } = input\n const headersFor = await aiSiteImportLookHeaders(input.domain, deps)\n const seed = aiSiteSeed(input.jobId)\n const page = await readSiteImportLookPage(home.url, { ...(deps.fetch ? { fetch: deps.fetch } : {}), headersFor, ...(input.signal ? { signal: input.signal } : {}) })\n // The source's own signals, its brand colors as it draws them solid.\n const signals = page ? aiSiteInspirationSignals(page) : null\n const site = signals && page ? { ...signals, colors: aiSiteImportBrandColors(page) } : signals\n const avoid = await (deps.others ?? aiWorkspaceSiteStyles)(firestore, { orgId: input.orgId, hostId })\n // What the reader found of its look, its buttons, ground and fonts (AGL-4108).\n const facts = home.look ?? null\n const fonts = await aiSiteImportSourceFonts(facts, deps.fontFacts)\n const style = aiSiteImportStyle(site, { seed, description: `${home.siteName} ${home.description}`, avoid, facts, fonts, finish: input.finish ?? null })\n let theme: AiSiteImportLook['theme'] = 'unread'\n if (style) {\n const saved = await (deps.save ?? aiSaveSiteTheme)(firestore, { hostId, jobId: input.jobId, style })\n if (saved.write === 'missing') throw new Error(`site ${hostId} vanished while its look was brought in`)\n theme = saved.write === 'kept' ? 'kept' : 'applied'\n }\n const ingest = deps.ingest ?? null\n const logo = home.brand.logo\n ? await aiSiteImportLogo(\n { hostId, uid: input.uid, domain: input.domain, logo: home.brand.logo, alt: home.siteName || home.brand.text, headersFor, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}), ...(deps.rasterize ? { rasterize: deps.rasterize } : {}) },\n )\n : null\n // The pictures its menus show, in the library like its pages' photos (AGL-4139), for the header's panels.\n const menuImages = aiSiteImportMenuPictures(home)\n const pictures = menuImages.length\n ? (\n await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: menuImages, deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n ).assets\n : []\n // The site's listing in its own words, only over the one it was created with.\n let seo = false\n const host = await (deps.readHost ?? readHostDoc)(firestore, hostId)\n if (host) {\n const updates: Record<string, unknown> = aiSiteImportListingUpdates(host['seo'], host['displayName'], home)\n // The site's icon from the one its head names, where the site has none (AGL-4139).\n if (home.favicon && faviconOpen(host['seo'])) {\n const icon = await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: [{ url: home.favicon, alt: '' }], deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n const photo = icon.assets[0]\n if (photo) updates['seo.favicon'] = photo.src\n }\n if (home.ogImage && shareOpen(host['seo'])) {\n const share = await bringInSiteImportPhotos(\n { hostId, uid: input.uid, domain: input.domain, images: [{ url: home.ogImage, alt: '' }], deadlineAt: Date.now() + LOOK_READ_MS, ...(input.signal ? { signal: input.signal } : {}) },\n { ingest, ...(deps.fetch ? { fetch: deps.fetch } : {}) },\n )\n const photo = share.assets[0]\n if (photo) {\n updates['seo.image'] = photo.src\n if (photo.width) updates['seo.imageWidth'] = photo.width\n if (photo.height) updates['seo.imageHeight'] = photo.height\n }\n }\n if (Object.keys(updates).length) {\n await (deps.writeHost ?? writeHostDoc)(firestore, hostId, updates)\n seo = true\n // Every site list reads the icon the members' rows carry (AGL-3972).\n if (updates['seo.favicon']) {\n await (deps.syncMemberships ?? syncHostProjectionForMembers)(input.orgId, hostId).catch((error: unknown) => {\n console.warn('[site-import] the site lists were not told of the new icon', { hostId, error })\n })\n }\n }\n }\n const drawn = style\n ? {\n ...(typeof style.headerAlign === 'string' ? { headerAlign: style.headerAlign } : {}),\n ...(typeof style.rhythm === 'string' ? { rhythm: style.rhythm } : {}),\n ...(typeof style.motion === 'string' ? { motion: style.motion } : {}),\n }\n : null\n const colors = [...new Set([...(facts ? [facts.buttonFill, facts.link, facts.eyebrow].filter(colorful).map((hex) => hex.toLowerCase()) : []), ...(site?.colors ?? [])])]\n return { at: input.at, theme, colors, logo, ...(pictures.length ? { pictures } : {}), seo, seed: style ? style.seed : seed, style: drawn }\n}\n\n/**\n * The headers the look's reads of the source go with, per address (AGL-4108),\n * exactly as the crawl's (`siteRequestHeaders`): the caller's where it hands\n * them in, else the edge's own, so a site this platform serves is read past\n * its challenge however the step was registered; and nothing for any address\n * off the site's two origins, a redirect hop's included. Never throws.\n *\n * The 10/29 look read went without the header twice over: no caller handed\n * one in, and the read passed headers the fetch does not take, which is why\n * this is a function the fetch asks for every hop (`headersFor`).\n */\nexport async function aiSiteImportLookHeaders(\n domain: string,\n deps: Pick<AiSiteImportLookDeps, 'headersFor' | 'edgeHeadersFor'>,\n): Promise<SiteImportHeadersFor> {\n const origins = siteImportOrigins(domain)\n let inner: SiteImportHeadersFor = NO_SITE_IMPORT_HEADERS\n try {\n if (deps.headersFor) {\n const headers = await deps.headersFor(domain)\n if (headers && Object.keys(headers).length) inner = () => headers\n } else {\n inner = await (deps.edgeHeadersFor ?? siteImportEdgeHeadersFor)(origins)\n }\n } catch (error) {\n console.warn('[site-import] the edge headers could not be read; reading the look without them', { domain, error })\n }\n return (url: URL) => (origins.includes(url.origin) ? inner(url) : {})\n}\n"],"names":["themeFontFacts","syncHostProjectionForMembers","aiSiteListingSeeded","aiSiteKindFor","aiHexOklch","aiSiteSeed","aiSiteStyleFor","aiSiteIsStarterSrc","AGLYN_BOT_USER_AGENT","siteImportOrigins","NO_SITE_IMPORT_HEADERS","siteImportEdgeHeadersFor","bringInSiteImportPhotos","siteImportImageKey","siteImportLogoUrl","aiSaveSiteTheme","aiWorkspaceSiteStyles","aiSiteInspirationLookPins","aiSiteInspirationSignals","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","AI_SITE_IMPORT_LOGO_HEIGHT","AI_SITE_IMPORT_LOGO_MAX_BYTES","LOOK_READ_MS","readSiteImportLookPage","url","input","fetchText","fetch","headersFor","read","address","maxBytes","accept","userAgent","timeoutMs","signal","catch","page","ok","stylesheets","sheet","text","slice","css","push","html","SOLID_HEX","SOLID_RGB","THEME_COLOR","hexOf","value","raw","trim","toLowerCase","test","aiSiteImportBrandColors","match","weights","Map","add","hex","weight","set","get","matchAll","alpha","undefined","endsWith","Number","channels","map","Math","min","toString","padStart","join","COLORFUL_CHROMA","colorful","C","aiSiteImportBrandOf","facts","fill","buttonFill","link","brand","accent","solidHex","aiSiteImportStyle","site","finish","own","kind","description","signals","v","sites","unread","seed","pins","hue","fonts","round","h","radius","buttonRadius","isFinite","buttons","corners","eyebrow","tertiary","style","answer","avoid","sourceFonts","background","darkPage","darkBackground","buttonText","buttonCase","aiSiteImportSourceFonts","lookup","body","loaded","Set","google","family","resolve","known","category","has","heading","headings","aiSiteImportListingUpdates","seo","displayName","home","seeded","current","updates","title","replace","shareOpen","image","AI_SITE_IMPORT_MENU_PICTURES","aiSiteImportMenuPictures","seen","out","group","nav","items","column","columns","length","alt","faviconOpen","favicon","readHostDoc","firestore","hostId","snapshot","collection","doc","exists","data","writeHostDoc","update","rasterizeHere","svg","height","images","origin","aiImageReadsOrigin","requestAiLogoRaster","rasterizeAiLogoSvg","aiSiteImportLogo","deps","ingest","logo","findImportedPhoto","sourceKey","fetched","held","mediaId","src","from","width","acceptHeader","refuseOver","binary","byteLength","type","contentType","split","bytes","rasterize","stored","uid","fileName","importedFrom","key","domain","error","console","warn","aiRunSiteImportLook","aiSiteImportLookHeaders","jobId","colors","others","orgId","look","fontFacts","siteName","theme","saved","save","write","Error","menuImages","pictures","deadlineAt","Date","now","assets","host","readHost","icon","photo","ogImage","share","Object","keys","writeHost","syncMemberships","drawn","headerAlign","rhythm","motion","filter","at","origins","inner","headers","edgeHeadersFor","includes"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAiC2C;AAG3C,SAASA,cAAc,QAA6B,wDAAuD;AAC3G,SAASC,4BAA4B,QAAQ,mDAAkD;AAC/F,SAASC,mBAAmB,QAAQ,6BAAyB;AAE7D,SAASC,aAAa,Q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