@aglyn/plugins-ai 1.13.0 → 1.14.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/jobs/ai-site-import-compile.js +23 -3
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.js +90 -8
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +8 -2
- package/src/lib/layout-language/ai-layout-language.js +4 -2
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +9 -0
- package/src/lib/model/ai-site-import-fidelity.js +64 -6
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +7 -0
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/runtime/site-inventory.js +2 -3
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/server/assist-view-context.js +3 -3
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +12 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +19 -9
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/site-import-concealed.d.ts +30 -0
- package/src/lib/site-import/site-import-concealed.js +231 -0
- package/src/lib/site-import/site-import-concealed.js.map +1 -0
- package/src/lib/site-import/site-import-crawl.d.ts +3 -1
- package/src/lib/site-import/site-import-crawl.js +8 -1
- package/src/lib/site-import/site-import-crawl.js.map +1 -1
- package/src/lib/site-import/site-import-css.js +13 -2
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-html.d.ts +28 -0
- package/src/lib/site-import/site-import-html.js +246 -49
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.js +211 -12
- package/src/lib/site-import/site-import-layout.js.map +1 -1
- package/src/lib/site-import/site-import-page.js +2 -0
- package/src/lib/site-import/site-import-page.js.map +1 -1
- package/src/lib/testing/stand-in-dataset-index.js +6 -2
- package/src/lib/testing/stand-in-dataset-index.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/site-import/site-import-css.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 * HOW A PAGE IS STYLED, AS A WIDE SCREEN SHOWS IT (AGL-4106).\n *\n * Bring my site reads a page's layout, not only its lines, and most of a\n * layout lives in the stylesheet: which band is grey and which is dark, which\n * container lays its children out in three columns, which link is drawn as a\n * filled button. This is a small cascade, enough for that and no more:\n *\n * - **The sheets.** The page's own `<style>` sheets and the ones it links,\n * every one to a byte budget (`siteImportReadStylesheets`, AGL-4152), read\n * in order. `@media` rules apply as a 1280-pixel screen in light mode\n * sees them, so a grid's desktop columns win over its phone ones;\n * `@layer`, `@supports` and `@container` are read through; keyframes, font\n * faces (their families noted) and page rules are skipped.\n * - **Selectors.** Tags, classes (escaped ones too, as utility frameworks\n * write them), ids and attributes, joined by any combinator, and `:is()`\n * and `:where()` spelled out (AGL-4152). A rule that\n * only applies on hover, focus or to a generated part (`::before`) is a\n * state the page is not in and is not read.\n * - **The cascade.** Specificity, then order, `!important` over both, and the\n * element's own `style` over every rule; color, font and alignment inherit,\n * and so do custom properties, which `var()` reads.\n *\n * Only the properties the layout reader asks about are kept. Nothing here\n * runs anything a page wrote: values are text compared to text.\n *=========================================*/\n\nimport type { SiteImportElement, SiteImportStructure } from './site-import-html'\n\n/** The width a page is read at: a laptop's, where a desktop layout shows. */\nexport const SITE_IMPORT_CSS_VIEWPORT = { width: 1280, height: 800 } as const\n\n/**\n * The width a page's column is read at (AGL-4083). A container caps itself\n * only on screens wider than its cap (`@media (min-width:1536px)` around a\n * `max-width:1536px`), so on a laptop it runs the whole page: read there, it\n * would look as if it had no cap at all.\n */\nexport const SITE_IMPORT_CSS_WIDE_WIDTH = 1920\n\n/** The properties the layout reader reads; every other declaration is dropped as the sheet is parsed. */\nconst KEPT_PROPERTIES = new Set([\n 'background',\n 'background-color',\n 'background-image',\n 'color',\n 'border',\n 'border-width',\n 'border-style',\n 'border-color',\n 'border-top',\n 'border-right',\n 'border-bottom',\n 'border-left',\n 'border-top-width',\n 'border-bottom-width',\n 'border-left-width',\n 'border-right-width',\n 'border-top-style',\n 'border-bottom-style',\n 'border-top-color',\n 'border-bottom-color',\n 'border-radius',\n 'box-shadow',\n 'display',\n 'grid-template-columns',\n 'grid-column',\n // Where a grid places its children, and the order a row shows them in (AGL-4152).\n 'grid-template-rows',\n 'grid-template-areas',\n 'grid-auto-flow',\n 'grid-area',\n 'grid-row',\n 'grid-row-start',\n 'grid-row-end',\n 'grid-column-start',\n 'grid-column-end',\n 'order',\n 'flex',\n 'flex-direction',\n 'flex-wrap',\n 'flex-grow',\n 'flex-basis',\n 'width',\n 'max-width',\n // The shape a picture is framed at (AGL-4138): a box's own, or a height it is cropped to.\n 'aspect-ratio',\n 'height',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'text-transform',\n 'letter-spacing',\n 'text-align',\n 'position',\n 'visibility',\n 'padding',\n 'padding-top',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'object-fit',\n 'justify-content',\n 'align-items',\n])\n\n/** What a rule says of a child's place in its grid, which a breakpoint nested in the rule may say again (AGL-4152). */\nconst GRID_PLACEMENT = /^(?:grid-area|grid-row|grid-row-start|grid-row-end|grid-column|grid-column-start|grid-column-end|order)$/\n\n/** What an element takes from its parent when it says nothing itself. */\nconst INHERITED = new Set(['color', 'font-family', 'font-size', 'font-weight', 'text-transform', 'letter-spacing', 'text-align', 'visibility'])\n\ninterface Compound {\n tag: string | null\n id: string | null\n classes: string[]\n attrs: Array<{ name: string; op: string | null; value: string }>\n /** `:root`: only the document's root element. */\n root: boolean\n}\n\ninterface ComplexSelector {\n /** Rightmost last. */\n compounds: Compound[]\n /** `combinators[i]` joins `compounds[i]` and `compounds[i + 1]`: a space, a child, an adjacent or a sibling combinator. */\n combinators: string[]\n specificity: number\n}\n\ninterface CssRule {\n selector: ComplexSelector\n order: number\n decls: Array<[property: string, value: string, important: boolean]>\n}\n\n/** The page's sheets, parsed for one width. */\nexport interface SiteImportCss {\n rules: CssRule[]\n /** Rules by their rightmost compound's id (`#x`), first class (`.x`), tag, or `*`. */\n index: Map<string, CssRule[]>\n /** Families its `@font-face` rules name, in order. */\n fontFaces: string[]\n /** Read for its dark scheme (AGL-4152): the rules that scheme alone selects, by a media query or a class on the page. */\n darkRules: number\n /** How many declarations read each custom property (AGL-4152): what its palette uses most. */\n variableUses: Map<string, number>\n}\n\n/** Which of a page's color schemes a read of its stylesheets answers for. */\nexport interface SiteImportCssOptions {\n /** Absent is `light`, as a page is first read. */\n scheme?: 'light' | 'dark'\n}\n\n/*------------------------------------------\n * Parsing\n *-----------------------------------------*/\n\nfunction unescapeIdent(text: string): string {\n return text.replace(/\\\\([0-9a-fA-F]{1,6}\\s?|.)/g, (_, escaped: string) => {\n if (/^[0-9a-fA-F]{1,6}\\s?$/.test(escaped)) {\n const code = parseInt(escaped.trim(), 16)\n return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : ''\n }\n return escaped\n })\n}\n\nconst IDENT = String.raw`(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\.|[\\w-]|[^\\x00-\\x7f])+`\nconst SIMPLE = new RegExp(\n String.raw`^(?:(\\*|${IDENT})|#(${IDENT})|\\.(${IDENT})|\\[\\s*([\\w-]+)\\s*(?:([~|^$*]?=)\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\]\\s]+))\\s*(?:[is]\\s*)?)?\\]|(::?)(${IDENT})(\\((?:[^()]|\\([^()]*\\))*\\))?)`,\n)\n\n/** The pseudo-classes a page at rest matches as if they were not there. */\nconst AT_REST = new Set(['link', 'any-link'])\n\n/** One compound selector, or `null` when it depends on a state or a generated part. */\nfunction parseCompound(text: string): Compound | null {\n const compound: Compound = { tag: null, id: null, classes: [], attrs: [], root: false }\n let rest = text\n while (rest) {\n const match = SIMPLE.exec(rest)\n if (!match || !match[0]) return null\n rest = rest.slice(match[0].length)\n if (match[1]) compound.tag = match[1] === '*' ? null : unescapeIdent(match[1]).toLowerCase()\n else if (match[2]) compound.id = unescapeIdent(match[2])\n else if (match[3]) compound.classes.push(unescapeIdent(match[3]))\n else if (match[4]) compound.attrs.push({ name: match[4].toLowerCase(), op: match[5] ?? null, value: match[6] ?? match[7] ?? match[8] ?? '' })\n else if (match[9]) {\n const name = unescapeIdent(match[10] ?? '').toLowerCase()\n if (match[9] === '::') return null\n if (name === 'root') compound.root = true\n else if (!AT_REST.has(name)) return null\n }\n }\n return compound\n}\n\n/** A complex selector, or `null` when any part of it cannot be read at rest. */\nfunction parseSelector(text: string): ComplexSelector | null {\n const compounds: Compound[] = []\n const combinators: string[] = []\n const parts = text.trim().replace(/\\s*([>+~])\\s*/g, ' $1 ').split(/\\s+/)\n let pending: string | null = null\n for (const part of parts) {\n if (!part) continue\n if (part === '>' || part === '+' || part === '~') {\n pending = part\n continue\n }\n const compound = parseCompound(part)\n if (!compound) return null\n if (compounds.length) combinators.push(pending ?? ' ')\n pending = null\n compounds.push(compound)\n }\n if (!compounds.length || pending) return null\n let ids = 0\n let classes = 0\n let tags = 0\n for (const compound of compounds) {\n if (compound.id) ids += 1\n classes += compound.classes.length + compound.attrs.length + (compound.root ? 1 : 0)\n if (compound.tag) tags += 1\n }\n return { compounds, combinators, specificity: ids * 1_000_000 + classes * 1_000 + tags }\n}\n\n/** The most selectors one written with `:is()` or `:where()` is spelled out into. */\nconst SELECTOR_VARIANTS = 24\n\n/**\n * A selector with its `:is()` and `:where()` spelled out (AGL-4152), each with\n * the weight to take off for a `:where()`, which counts for nothing. A variant\n * two compounds cannot be joined into (`.x:is(div)`, `.x:is(.a .b)`) is left out.\n */\nfunction spelledOut(text: string): Array<{ text: string; discount: number }> {\n const match = /:(?:is|where)\\(/i.exec(text)\n if (!match) return [{ text, discount: 0 }]\n const inner = match.index + match[0].length\n let depth = 1\n let end = inner\n while (end < text.length && depth > 0) {\n if (text[end] === '(') depth += 1\n else if (text[end] === ')') depth -= 1\n end += 1\n }\n if (depth) return [{ text, discount: 0 }]\n const head = text.slice(0, match.index)\n const tail = text.slice(end)\n const zeroed = /where/i.test(match[0])\n const joined = !head || /[\\s>+~]$/.test(head)\n const out: Array<{ text: string; discount: number }> = []\n for (const option of splitList(text.slice(inner, end - 1))) {\n if (!joined && (/\\s/.test(option) || /^[\\w*]/.test(option))) continue\n const discount = zeroed ? (parseSelector(option.replace(/:(?:is|where)\\([^()]*\\)/gi, ''))?.specificity ?? 0) : 0\n for (const variant of spelledOut(`${head}${option}${tail}`)) {\n if (out.length >= SELECTOR_VARIANTS) return out\n out.push({ text: variant.text, discount: discount + variant.discount })\n }\n }\n return out\n}\n\n/** Splits at top-level commas: none inside brackets or parentheses. */\nfunction splitList(text: string): string[] {\n const out: string[] = []\n let depth = 0\n let start = 0\n for (let at = 0; at < text.length; at += 1) {\n const char = text[at]\n if (char === '(' || char === '[') depth += 1\n else if (char === ')' || char === ']') depth = Math.max(0, depth - 1)\n else if (char === ',' && depth === 0) {\n out.push(text.slice(start, at))\n start = at + 1\n }\n }\n out.push(text.slice(start))\n return out.map((part) => part.trim()).filter(Boolean)\n}\n\n/** A length in px at the read width; `em`/`rem` at 16. */\nexport function siteImportLengthPx(value: string): number | null {\n const match = /^(-?\\d*\\.?\\d+)\\s*(px|em|rem)?$/i.exec(value.trim())\n if (!match) return null\n const amount = Number(match[1])\n return match[2] && match[2].toLowerCase() !== 'px' ? amount * 16 : amount\n}\n\n/** Whether one media query holds for a screen of this width in this color scheme. */\nfunction mediaQueryHolds(query: string, viewport: number, scheme: 'light' | 'dark'): boolean {\n let text = query.trim().toLowerCase()\n let negate = false\n if (text.startsWith('not ')) {\n negate = true\n text = text.slice(4)\n }\n text = text.replace(/^only\\s+/, '')\n let holds = true\n for (const part of text.split(/\\s+and\\s+/)) {\n const term = part.trim()\n if (!term) continue\n if (!term.startsWith('(')) {\n if (!/^(?:all|screen)$/.test(term)) holds = false\n continue\n }\n const inner = term.replace(/^\\(|\\)$/g, '').trim()\n const feature = /^([\\w-]+)\\s*:\\s*(.+)$/.exec(inner)\n const { height } = SITE_IMPORT_CSS_VIEWPORT\n const width = viewport\n if (feature) {\n const [, name, value] = feature\n const px = siteImportLengthPx(value)\n if (name === 'min-width') holds &&= px !== null && width >= px\n else if (name === 'max-width') holds &&= px !== null && width <= px\n else if (name === 'min-height') holds &&= px !== null && height >= px\n else if (name === 'max-height') holds &&= px !== null && height <= px\n else if (name === 'prefers-color-scheme') holds &&= value.trim() === scheme\n else if (name === 'prefers-reduced-motion') holds &&= value.trim() === 'no-preference'\n else if (name === 'orientation') holds &&= value.trim() === 'landscape'\n else if (name === 'hover' || name === 'any-hover') holds &&= value.trim() === 'hover'\n else if (name === 'pointer' || name === 'any-pointer') holds &&= value.trim() === 'fine'\n else if (name === 'prefers-contrast' || name === 'forced-colors') holds &&= /^(?:no-preference|none)$/.test(value.trim())\n continue\n }\n // Range syntax: (width >= 900px), (600px <= width < 1200px).\n const range = /^(?:(-?[\\d.]+\\w*)\\s*(<=|<|>=|>)\\s*)?(width|height)\\s*(?:(<=|<|>=|>)\\s*(-?[\\d.]+\\w*))?$/.exec(inner)\n if (range) {\n const size = range[3] === 'width' ? width : height\n const test = (a: number, op: string, b: number) => (op === '<' ? a < b : op === '<=' ? a <= b : op === '>' ? a > b : a >= b)\n if (range[1] && range[2]) {\n const px = siteImportLengthPx(range[1])\n holds &&= px !== null && test(px, range[2], size)\n }\n if (range[4] && range[5]) {\n const px = siteImportLengthPx(range[5])\n holds &&= px !== null && test(size, range[4], px)\n }\n }\n }\n return negate ? !holds : holds\n}\n\nfunction mediaHolds(prelude: string, viewport: number, scheme: 'light' | 'dark'): boolean {\n const list = splitList(prelude.replace(/^@media\\s*/i, ''))\n return !list.length || list.some((query) => mediaQueryHolds(query, viewport, scheme))\n}\n\n/**\n * A selector's leading mark of the dark scheme (AGL-4152): `.dark`, `.dark-mode`\n * or a `data-theme` that says dark, on the page's root or body. Nothing a read\n * sees carries it, so a dark read lifts it off and the rest applies as written.\n */\nconst DARK_SCOPE = /^(?:(html|body|:root))?(?:\\.dark(?:-mode|-theme)?|\\[\\s*data-(?:theme|mode|color-scheme|color-mode|bs-theme|mui-color-scheme)\\s*[*~|^]?=\\s*[\"']?[^\"'\\]]*dark[^\"'\\]]*[\"']?\\s*(?:i\\s*)?\\])(?=$|[\\s>+~.:#[])/i\n\n/** What a selector asks of a page in its dark scheme, its mark lifted off: what remains, else the element that held the mark. `null` for a selector with no such mark. */\nfunction withoutDarkScope(text: string): string | null {\n const match = DARK_SCOPE.exec(text.trim())\n if (!match) return null\n const rest = text.trim().slice(match[0].length).replace(/^[\\s>+~]+/, '')\n return rest || match[1] || ':root'\n}\n\nfunction declarationsOf(body: string): CssRule['decls'] {\n const decls: CssRule['decls'] = []\n // Values may hold semicolons only inside strings or url(), which the kept properties never need.\n for (const part of body.split(';')) {\n const colon = part.indexOf(':')\n if (colon <= 0) continue\n const written = part.slice(0, colon).trim()\n // A custom property's name is case-sensitive, as `var()` reads it.\n const property = written.startsWith('--') ? written : written.toLowerCase()\n if (!property.startsWith('--') && !KEPT_PROPERTIES.has(property)) continue\n let value = part.slice(colon + 1).trim()\n const important = /!\\s*important\\s*$/i.test(value)\n if (important) value = value.replace(/!\\s*important\\s*$/i, '').trim()\n if (value) decls.push([property, value.slice(0, 2_000), important])\n }\n return decls\n}\n\n/** The index key of a selector: its rightmost compound's id, first class, tag, else `*`. */\nfunction keyOf(selector: ComplexSelector): string {\n const last = selector.compounds[selector.compounds.length - 1] as Compound\n if (last.id) return `#${last.id}`\n if (last.classes.length) return `.${last.classes[0]}`\n if (last.root) return ':root'\n if (last.tag) return last.tag\n return '*'\n}\n\n/**\n * The page's sheets parsed for a wide screen. Malformed CSS is read as far as\n * it makes sense, as a browser would; nothing throws.\n */\nexport function siteImportCssOf(sheets: readonly string[], viewport: number = SITE_IMPORT_CSS_VIEWPORT.width, options: SiteImportCssOptions = {}): SiteImportCss {\n const css: SiteImportCss = { rules: [], index: new Map(), fontFaces: [], darkRules: 0, variableUses: new Map() }\n const scheme = options.scheme ?? 'light'\n let order = 0\n /** For each open group: whether only a dark scheme's media query opens it. */\n const darkGroups: boolean[] = []\n const addRule = (prelude: string, body: string) => {\n const decls = declarationsOf(body)\n if (!decls.length) return\n for (const [, value] of decls) {\n if (!value.includes('var(')) continue\n for (const use of value.matchAll(/var\\(\\s*(--[\\w-]+)/g)) css.variableUses.set(use[1] as string, (css.variableUses.get(use[1] as string) ?? 0) + 1)\n }\n for (const text of splitList(prelude)) {\n const lifted = scheme === 'dark' ? withoutDarkScope(text) : null\n for (const variant of spelledOut(lifted ?? text)) {\n const selector = parseSelector(variant.text)\n if (!selector) continue\n selector.specificity = Math.max(0, selector.specificity - variant.discount)\n if (scheme === 'dark' && (lifted !== null || darkGroups.includes(true))) css.darkRules += 1\n // The mark it lost still counts: a dark rule outranks the same rule of the light scheme.\n if (lifted !== null) selector.specificity += 1_000\n const rule: CssRule = { selector, order: order++, decls }\n css.rules.push(rule)\n const key = keyOf(selector)\n const list = css.index.get(key)\n if (list) list.push(rule)\n else css.index.set(key, [rule])\n }\n }\n }\n for (const sheet of sheets) {\n const text = String(sheet ?? '').replace(/\\/\\*[\\s\\S]*?\\*\\//g, ' ')\n /** For each open group: whether its rules apply. */\n const groups: boolean[] = []\n let at = 0\n let start = 0\n while (at < text.length) {\n const char = text[at]\n if (char === '\"' || char === \"'\") {\n const end = text.indexOf(char, at + 1)\n at = end < 0 ? text.length : end + 1\n continue\n }\n if (char === ';') {\n // A statement at-rule (@import, @charset) or stray text.\n start = at + 1\n at += 1\n continue\n }\n if (char === '}') {\n groups.pop()\n darkGroups.pop()\n start = at + 1\n at += 1\n continue\n }\n if (char !== '{') {\n at += 1\n continue\n }\n const prelude = text.slice(start, at).trim()\n const applies = groups.every(Boolean)\n if (/^@(?:media)\\b/i.test(prelude)) {\n groups.push(applies && mediaHolds(prelude, viewport, scheme))\n darkGroups.push(/prefers-color-scheme\\s*:\\s*dark/i.test(prelude))\n start = at = at + 1\n continue\n }\n if (/^@(?:supports|layer|container|document|scope|starting-style)\\b/i.test(prelude)) {\n groups.push(applies && !/^@starting-style/i.test(prelude))\n darkGroups.push(false)\n start = at = at + 1\n continue\n }\n // A block to read whole: a style rule, a font face, or an at-rule to skip.\n let depth = 1\n let end = at + 1\n while (end < text.length && depth > 0) {\n if (text[end] === '{') depth += 1\n else if (text[end] === '}') depth -= 1\n end += 1\n }\n const body = text.slice(at + 1, Math.max(at + 1, end - 1))\n if (/^@font-face\\b/i.test(prelude)) {\n const family = /font-family\\s*:\\s*([\"']?)([^;\"']+)\\1/i.exec(body)?.[2]?.trim()\n if (family && !css.fontFaces.includes(family)) css.fontFaces.push(family)\n } else if (!prelude.startsWith('@') && applies && prelude) {\n // A rule nested inside a rule (`&:hover`) is a state: only the outer declarations are read.\n // A breakpoint nested inside one that holds at this width places its child as a top-level one does.\n const placed = [...body.matchAll(/@media([^{};]*)\\{([^{}]*)\\}/g)]\n .filter((match) => mediaHolds(match[1] as string, viewport, scheme))\n .flatMap((match) => (match[2] as string).split(';').filter((part) => GRID_PLACEMENT.test(part.slice(0, part.indexOf(':')).trim().toLowerCase())))\n addRule(prelude, [body.replace(/[^;{}]*\\{[^{}]*\\}/g, ''), ...placed].join(';'))\n }\n start = at = end\n }\n }\n return css\n}\n\n/*------------------------------------------\n * Matching and the cascade\n *-----------------------------------------*/\n\nfunction classesOf(element: SiteImportElement): string[] {\n return (element.attrs.class ?? '').split(/\\s+/).filter(Boolean)\n}\n\nfunction attributeOf(element: SiteImportElement, name: string): string | undefined {\n switch (name) {\n case 'class':\n return element.attrs.class\n case 'id':\n return element.attrs.id\n case 'role':\n return element.attrs.role\n case 'aria-label':\n return element.attrs.label\n case 'href':\n return element.attrs.href\n case 'type':\n return element.attrs.type\n case 'style':\n return element.attrs.style\n case 'hidden':\n case 'aria-hidden':\n return element.attrs.hidden ? 'true' : undefined\n case 'data-section-theme':\n case 'data-theme':\n return element.attrs.theme\n default:\n return undefined\n }\n}\n\nfunction compoundMatches(compound: Compound, element: SiteImportElement, rootId: number): boolean {\n if (compound.root && element.id !== rootId) return false\n if (compound.tag && compound.tag !== element.tag) return false\n if (compound.id && compound.id !== element.attrs.id) return false\n if (compound.classes.length) {\n const own = classesOf(element)\n if (!compound.classes.every((name) => own.includes(name))) return false\n }\n for (const attr of compound.attrs) {\n const value = attributeOf(element, attr.name)\n if (value === undefined) return false\n if (!attr.op) continue\n const wanted = attr.value\n const ok =\n attr.op === '='\n ? value === wanted\n : attr.op === '~='\n ? value.split(/\\s+/).includes(wanted)\n : attr.op === '^='\n ? value.startsWith(wanted)\n : attr.op === '$='\n ? value.endsWith(wanted)\n : attr.op === '*='\n ? value.includes(wanted)\n : value === wanted || value.startsWith(`${wanted}-`)\n if (!ok) return false\n }\n return true\n}\n\n/** Whether a selector matches an element, its combinators walked from the right. */\nfunction selectorMatches(\n selector: ComplexSelector,\n element: SiteImportElement,\n elements: readonly SiteImportElement[],\n root: SiteImportElement | null,\n): boolean {\n const rootId = root?.id ?? -2\n /** The element above `at`: its parent, or the document's root above the body. */\n const above = (at: SiteImportElement) => (at.parent >= 0 ? elements[at.parent] : at === root ? undefined : (root ?? undefined))\n const walk = (index: number, at: SiteImportElement): boolean => {\n if (!compoundMatches(selector.compounds[index] as Compound, at, rootId)) return false\n if (index === 0) return true\n const combinator = selector.combinators[index - 1]\n if (combinator === '>') {\n const parent = above(at)\n return !!parent && walk(index - 1, parent)\n }\n if (combinator === '+' || combinator === '~') {\n const siblings = elements[at.parent]?.children ?? []\n const position = siblings.indexOf(at.id)\n for (let before = position - 1; before >= 0; before -= 1) {\n const sibling = elements[siblings[before] as number]\n if (!sibling) continue\n if (walk(index - 1, sibling)) return true\n if (combinator === '+') return false\n }\n return false\n }\n for (let parent = above(at); parent; parent = above(parent)) {\n if (walk(index - 1, parent)) return true\n }\n return false\n }\n return walk(selector.compounds.length - 1, element)\n}\n\n/** One element's resolved style: the kept properties, `var()` read, lowercased. */\nexport type SiteImportComputedStyle = ReadonlyMap<string, string>\n\n/** Reads elements' styles over a page's structure, each once. */\nexport interface SiteImportStyles {\n of(element: number): SiteImportComputedStyle\n /** The root's (`<html>`) element id, which `:root` matches; -1 for none. */\n readonly root: number\n /** The custom properties the root declares (AGL-4152), each read through to what it holds. */\n rootVariables(): ReadonlyMap<string, string>\n}\n\nconst EMPTY_STYLE: SiteImportComputedStyle = new Map()\n\n/** How far a variable that names a variable is followed: a site builder's palette goes several deep. */\nconst VARIABLE_DEPTH = 8\n\n/** Replaces each `var(--x, fallback)` with what the custom properties hold, to a few levels. */\nfunction withVariables(value: string, custom: ReadonlyMap<string, string>): string {\n let out = value\n for (let pass = 0; pass < VARIABLE_DEPTH && out.includes('var('); pass += 1) {\n out = out.replace(/var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*((?:[^()]|\\([^()]*\\))*))?\\)/g, (_, name: string, fallback?: string) => custom.get(name) ?? fallback?.trim() ?? '')\n }\n return out\n}\n\n/** The kept declarations an inline `style` attribute writes. */\nfunction inlineDeclarations(style: string | undefined): CssRule['decls'] {\n return style ? declarationsOf(style) : []\n}\n\n/**\n * Elements' styles over a page's structure and its sheets. Styles are\n * resolved on demand, parent first, each element once.\n */\nexport function siteImportStylesOf(structure: Pick<SiteImportStructure, 'elements' | 'root'>, css: SiteImportCss): SiteImportStyles {\n const { elements } = structure\n const resolved = new Map<number, { style: Map<string, string>; custom: Map<string, string> }>()\n // The page's root is above the body: `:root` and `html` rules are its.\n const rootStyle = (() => {\n const style = new Map<string, string>()\n const custom = new Map<string, string>()\n const fake: SiteImportElement = { id: -2, tag: 'html', parent: -1, children: [], region: 'main', nav: false, attrs: structure.root ?? {}, blocks: [] }\n const candidates = [...(css.index.get(':root') ?? []), ...(css.index.get('html') ?? []), ...(css.index.get('*') ?? [])]\n for (const name of classesOf(fake)) candidates.push(...(css.index.get(`.${name}`) ?? []))\n if (fake.attrs.id) candidates.push(...(css.index.get(`#${fake.attrs.id}`) ?? []))\n apply(candidates.filter((rule) => selectorMatches(rule.selector, fake, [], fake)), inlineDeclarations(fake.attrs.style), style, custom)\n return { style, custom, element: fake }\n })()\n\n function apply(rules: CssRule[], inline: CssRule['decls'], style: Map<string, string>, custom: Map<string, string>) {\n const unique = [...new Set(rules)].sort((a, b) => a.selector.specificity - b.selector.specificity || a.order - b.order)\n const important: Array<[string, string]> = []\n const put = (property: string, value: string) => {\n if (property.startsWith('--')) custom.set(property, value)\n else style.set(property, value)\n }\n for (const rule of unique) {\n for (const [property, value, flag] of rule.decls) {\n if (flag) important.push([property, value])\n else put(property, value)\n }\n }\n for (const [property, value, flag] of inline) {\n if (flag) important.push([property, value])\n else put(property, value)\n }\n for (const [property, value] of important) put(property, value)\n }\n\n function resolve(id: number): { style: Map<string, string>; custom: Map<string, string> } {\n const held = resolved.get(id)\n if (held) return held\n const element = elements[id]\n if (!element) return rootStyle\n const parent = element.parent >= 0 ? resolve(element.parent) : rootStyle\n const candidates: CssRule[] = [...(css.index.get(element.tag) ?? []), ...(css.index.get('*') ?? [])]\n for (const name of classesOf(element)) candidates.push(...(css.index.get(`.${name}`) ?? []))\n if (element.attrs.id) candidates.push(...(css.index.get(`#${element.attrs.id}`) ?? []))\n const matched = candidates.filter((rule) => selectorMatches(rule.selector, element, elements, rootStyle.element))\n const own = new Map<string, string>()\n const inline = inlineDeclarations(element.attrs.style)\n // A palette can be thousands of properties: only an element that declares one takes a copy of them.\n const declares = inline.some(([property]) => property.startsWith('--')) || matched.some((rule) => rule.decls.some(([property]) => property.startsWith('--')))\n const custom = declares ? new Map(parent.custom) : parent.custom\n apply(matched, inline, own, custom)\n const style = new Map<string, string>()\n for (const property of INHERITED) {\n const value = parent.style.get(property)\n if (value !== undefined) style.set(property, value)\n }\n for (const [property, value] of own) {\n const lowered = value.trim().toLowerCase()\n if (lowered === 'inherit') {\n const inherited = parent.style.get(property)\n if (inherited !== undefined) style.set(property, inherited)\n continue\n }\n if (lowered === 'initial' || lowered === 'unset' || lowered === 'revert') {\n if (!INHERITED.has(property) || lowered === 'initial') style.delete(property)\n continue\n }\n style.set(property, property === 'font-family' ? withVariables(value, custom) : withVariables(value, custom).toLowerCase())\n }\n const entry = { style, custom }\n resolved.set(id, entry)\n return entry\n }\n\n // The root's own inherited values reach the body through `rootStyle`.\n for (const [property, value] of rootStyle.style) {\n rootStyle.style.set(property, property === 'font-family' ? withVariables(value, rootStyle.custom) : withVariables(value, rootStyle.custom).toLowerCase())\n }\n return {\n root: -2,\n of(element: number): SiteImportComputedStyle {\n if (element === -2) return rootStyle.style\n return elements[element] ? resolve(element).style : EMPTY_STYLE\n },\n rootVariables() {\n return new Map([...rootStyle.custom].map(([name, value]) => [name, withVariables(value, rootStyle.custom)]))\n },\n }\n}\n\n/*------------------------------------------\n * Values\n *-----------------------------------------*/\n\nexport interface SiteImportRgba {\n r: number\n g: number\n b: number\n a: number\n}\n\nconst NAMED_COLORS: Record<string, string> = {\n white: '#ffffff',\n black: '#000000',\n red: '#ff0000',\n green: '#008000',\n blue: '#0000ff',\n gray: '#808080',\n grey: '#808080',\n silver: '#c0c0c0',\n whitesmoke: '#f5f5f5',\n ghostwhite: '#f8f8ff',\n snow: '#fffafa',\n ivory: '#fffff0',\n beige: '#f5f5dc',\n linen: '#faf0e6',\n navy: '#000080',\n teal: '#008080',\n orange: '#ffa500',\n gold: '#ffd700',\n purple: '#800080',\n crimson: '#dc143c',\n tomato: '#ff6347',\n coral: '#ff7f50',\n aliceblue: '#f0f8ff',\n lightgray: '#d3d3d3',\n lightgrey: '#d3d3d3',\n gainsboro: '#dcdcdc',\n darkslategray: '#2f4f4f',\n dimgray: '#696969',\n}\n\n/** The first color a value names, or `null`; `transparent` is a color of no strength. */\nexport function siteImportColorOf(value: string | undefined): SiteImportRgba | null {\n if (!value) return null\n const text = value.toLowerCase()\n const hex = /#([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})\\b/.exec(text)\n const rgb = /rgba?\\(\\s*(-?[\\d.]+%?)\\s*[,\\s]\\s*(-?[\\d.]+%?)\\s*[,\\s]\\s*(-?[\\d.]+%?)\\s*(?:[,/]\\s*(-?[\\d.]+%?)\\s*)?\\)/.exec(text)\n const hsl = /hsla?\\(\\s*(-?[\\d.]+)(?:deg)?\\s*[,\\s]\\s*([\\d.]+)%?\\s*[,\\s]\\s*([\\d.]+)%?\\s*(?:[,/]\\s*([\\d.]+%?)\\s*)?\\)/.exec(text)\n const named = /\\b(transparent|[a-z]+)\\b/.exec(text.replace(/[a-z-]+\\(/g, ' ('))\n const first = [hex, rgb, hsl].filter((match): match is RegExpExecArray => !!match).sort((a, b) => a.index - b.index)[0]\n const alphaOf = (raw: string | undefined) => (raw === undefined ? 1 : raw.endsWith('%') ? Number(raw.slice(0, -1)) / 100 : Number(raw))\n if (first === hex && hex) {\n const digits = hex[1]\n const full = digits.length <= 4 ? digits.split('').map((d) => d + d).join('') : digits\n return {\n r: parseInt(full.slice(0, 2), 16),\n g: parseInt(full.slice(2, 4), 16),\n b: parseInt(full.slice(4, 6), 16),\n a: full.length === 8 ? parseInt(full.slice(6, 8), 16) / 255 : 1,\n }\n }\n if (first === rgb && rgb) {\n const channel = (raw: string) => Math.max(0, Math.min(255, raw.endsWith('%') ? (Number(raw.slice(0, -1)) / 100) * 255 : Number(raw)))\n return { r: channel(rgb[1]), g: channel(rgb[2]), b: channel(rgb[3]), a: alphaOf(rgb[4]) }\n }\n if (first === hsl && hsl) {\n const h = (((Number(hsl[1]) % 360) + 360) % 360) / 360\n const s = Number(hsl[2]) / 100\n const l = Number(hsl[3]) / 100\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const tone = (t: number) => {\n const x = t < 0 ? t + 1 : t > 1 ? t - 1 : t\n if (x < 1 / 6) return p + (q - p) * 6 * x\n if (x < 1 / 2) return q\n if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6\n return p\n }\n return { r: tone(h + 1 / 3) * 255, g: tone(h) * 255, b: tone(h - 1 / 3) * 255, a: alphaOf(hsl[4]) }\n }\n if (named) {\n if (named[1] === 'transparent') return { r: 0, g: 0, b: 0, a: 0 }\n const known = NAMED_COLORS[named[1]]\n if (known) return siteImportColorOf(known)\n }\n return null\n}\n\n/** A variable's name that says it holds a brand's color. */\nconst BRAND_VARIABLE = /primary|secondary|brand|accent|highlight/i\n\n/** A custom property's whole value as a color: a color function, or the triple a color function reads through `var()`. */\nfunction colorOfVariable(value: string): SiteImportRgba | null {\n const text = value.trim()\n if (/^(?:#[0-9a-f]{3,8}|(?:rgb|hsl)a?\\([^()]*\\))$/i.test(text)) return siteImportColorOf(text)\n if (/^-?[\\d.]+(?:deg)?[\\s,]+[\\d.]+%[\\s,]+[\\d.]+%$/.test(text)) return siteImportColorOf(`hsl(${text})`)\n if (/^\\d{1,3}[\\s,]+\\d{1,3}[\\s,]+\\d{1,3}$/.test(text)) return siteImportColorOf(`rgb(${text})`)\n return null\n}\n\n/** The most colors of a palette kept. */\nconst PALETTE_COLORS = 6\n\n/**\n * The brand colors a page's root declares (AGL-4152): the custom properties\n * named for a brand that hold a color, a triple included, none too pale, dark\n * or grey to carry one, the most read first. What the page says its brand is,\n * even where nothing on this page happens to draw it.\n */\nexport function siteImportPaletteOf(styles: Pick<SiteImportStyles, 'rootVariables'>, uses: ReadonlyMap<string, number>): string[] {\n const tally = new Map<string, number>()\n for (const [name, value] of styles.rootVariables()) {\n if (!BRAND_VARIABLE.test(name)) continue\n const color = colorOfVariable(value)\n if (!color || color.a < 0.5 || siteImportSaturation(color) < 0.2) continue\n const light = siteImportLuminance(color)\n if (light < 0.01 || light > 0.9) continue\n const hex = siteImportHex(color)\n tally.set(hex, (tally.get(hex) ?? 0) + (uses.get(name) ?? 0))\n }\n return [...tally.entries()].sort((a, b) => b[1] - a[1]).slice(0, PALETTE_COLORS).map(([hex]) => hex)\n}\n\n/** `#rrggbb` of a color, its strength ignored. */\nexport function siteImportHex(color: SiteImportRgba): string {\n return `#${[color.r, color.g, color.b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\n/** Relative luminance, 0 (black) to 1 (white). */\nexport function siteImportLuminance(color: SiteImportRgba): number {\n const linear = (channel: number) => {\n const c = channel / 255\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n }\n return 0.2126 * linear(color.r) + 0.7152 * linear(color.g) + 0.0722 * linear(color.b)\n}\n\n/** How colorful a color is, 0 (grey) to 1. */\nexport function siteImportSaturation(color: SiteImportRgba): number {\n const max = Math.max(color.r, color.g, color.b) / 255\n const min = Math.min(color.r, color.g, color.b) / 255\n if (max === min) return 0\n const l = (max + min) / 2\n return (max - min) / (1 - Math.abs(2 * l - 1))\n}\n\n/** What an element draws behind itself: a color, a gradient and its colors, or a picture. */\nexport interface SiteImportBackground {\n color: SiteImportRgba | null\n gradient: SiteImportRgba[] | null\n /** A picture's address, as written. */\n image: string | null\n}\n\n/** An element's own background, from the shorthand or its parts. */\nexport function siteImportBackgroundOf(style: SiteImportComputedStyle): SiteImportBackground {\n const shorthand = style.get('background') ?? ''\n const imageValue = style.get('background-image') ?? (/(?:url|gradient)\\(/.test(shorthand) ? shorthand : '')\n const colorValue = style.get('background-color') ?? (shorthand && !/(?:url|gradient)\\(/.test(shorthand) ? shorthand : shorthand.replace(/[a-z-]*gradient\\((?:[^()]|\\([^()]*\\))*\\)|url\\([^)]*\\)/g, ' '))\n const color = siteImportColorOf(colorValue)\n let gradient: SiteImportRgba[] | null = null\n let image: string | null = null\n const gradientMatch = /gradient\\(((?:[^()]|\\([^()]*\\))*)\\)/.exec(imageValue)\n if (gradientMatch) {\n const stops: SiteImportRgba[] = []\n for (const match of gradientMatch[1].matchAll(/#[0-9a-f]{3,8}\\b|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)|\\b(?:white|black|transparent)\\b/gi)) {\n const stop = siteImportColorOf(match[0])\n if (stop) stops.push(stop)\n }\n if (stops.length) gradient = stops\n }\n const url = /url\\(\\s*([\"']?)([^\"')]+)\\1\\s*\\)/.exec(imageValue)\n if (url) image = url[2].trim()\n return { color: color && color.a > 0.02 ? color : null, gradient, image }\n}\n\n/** Whether an element draws a border on any side. */\nexport function siteImportHasBorder(style: SiteImportComputedStyle): boolean {\n const sides = ['border', 'border-top', 'border-bottom', 'border-left', 'border-right']\n for (const side of sides) {\n const value = style.get(side)\n if (!value) continue\n if (/\\bnone\\b|\\bhidden\\b/.test(value) || /^0(?:px)?$/.test(value.trim())) continue\n const color = siteImportColorOf(value) ?? siteImportColorOf(style.get('border-color'))\n if (color && color.a < 0.05) continue\n if (/\\d/.test(value) || /\\b(?:solid|dashed|dotted|double)\\b/.test(value)) {\n const width = /(-?[\\d.]+)px/.exec(value)\n if (!width || Number(width[1]) > 0) return true\n }\n }\n const width = style.get('border-width')\n const kind = style.get('border-style')\n if (kind && /\\b(?:solid|dashed|dotted|double)\\b/.test(kind) && (!width || !/^0(?:px)?$/.test(width.trim()))) return true\n return false\n}\n\n/** A side of an element's box. */\nexport type SiteImportSide = 'top' | 'right' | 'bottom' | 'left'\n\nconst SIDES: readonly SiteImportSide[] = ['top', 'right', 'bottom', 'left']\n\n/** One side's border, where it draws one: its width in px and its color as written. */\nexport interface SiteImportBorderSide {\n width: number\n color: SiteImportRgba | null\n}\n\n/**\n * The sides an element draws a border on (AGL-4138), each with its width and\n * color: a box is bordered on every side, a rule on one. The shorthand draws\n * all four; a side's own declaration, or `border-width` and `border-style`\n * by side, draw only theirs.\n */\nexport function siteImportBorderSides(style: SiteImportComputedStyle): Partial<Record<SiteImportSide, SiteImportBorderSide>> {\n const out: Partial<Record<SiteImportSide, SiteImportBorderSide>> = {}\n const shared = siteImportColorOf(style.get('border-color'))\n const drawn = (value: string | undefined): SiteImportBorderSide | null => {\n if (!value || /\\bnone\\b|\\bhidden\\b/.test(value) || /^0(?:px)?$/.test(value.trim())) return null\n const color = siteImportColorOf(value) ?? shared\n if (color && color.a < 0.05) return null\n if (!/\\d/.test(value) && !/\\b(?:solid|dashed|dotted|double)\\b/.test(value)) return null\n const width = /(-?[\\d.]+)(?:px)?(?:\\s|$)/.exec(value.replace(/#[0-9a-f]+|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)/gi, ' '))\n const px = width ? Number(width[1]) : /\\bthick\\b/.test(value) ? 5 : /\\bthin\\b/.test(value) ? 1 : 3\n return px > 0 ? { width: px, color } : null\n }\n const all = drawn(style.get('border'))\n for (const side of SIDES) {\n const own = style.get(`border-${side}`)\n const found = own !== undefined ? drawn(own) : all\n if (found) out[side] = found\n }\n // `border-width` and `border-style` by side, where no shorthand drew a side.\n const kind = style.get('border-style')\n if (!Object.keys(out).length && kind && /\\b(?:solid|dashed|dotted|double)\\b/.test(kind)) {\n const widths = (style.get('border-width') ?? '3px').trim().split(/\\s+/)\n const by = [widths[0], widths[1] ?? widths[0], widths[2] ?? widths[0], widths[3] ?? widths[1] ?? widths[0]]\n SIDES.forEach((side, at) => {\n const px = siteImportLengthPx(by[at] ?? '')\n if (px !== null && px > 0) out[side] = { width: px, color: shared }\n })\n }\n return out\n}\n\n/** A picture box's `aspect-ratio`, width over height: `16 / 9`, `1.5`, `auto 4 / 3`; `null` where it sets none. */\nexport function siteImportAspectRatio(value: string | undefined): number | null {\n const match = /(\\d*\\.?\\d+)\\s*(?:\\/\\s*(\\d*\\.?\\d+))?/.exec((value ?? '').replace(/\\bauto\\b/g, ' '))\n if (!match) return null\n const width = Number(match[1])\n const height = match[2] === undefined ? 1 : Number(match[2])\n return width > 0 && height > 0 ? width / height : null\n}\n\n/** A color as it shows over the ground it sits on, its strength blended in: `rgba(0,0,0,.6)` over white is `#666666`. */\nexport function siteImportOpaque(color: SiteImportRgba, under: SiteImportRgba | null = null): SiteImportRgba {\n const ground = under ?? { r: 255, g: 255, b: 255, a: 1 }\n const a = Math.max(0, Math.min(1, color.a))\n return { r: color.r * a + ground.r * (1 - a), g: color.g * a + ground.g * (1 - a), b: color.b * a + ground.b * (1 - a), a: 1 }\n}\n\n/** How far apart two colors look, in OKLab (0 the same, about 1 black from white). */\nexport function siteImportColorDistance(a: SiteImportRgba, b: SiteImportRgba): number {\n const lab = (color: SiteImportRgba) => {\n const linear = (channel: number) => {\n const c = channel / 255\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n }\n const [r, g, bl] = [linear(color.r), linear(color.g), linear(color.b)]\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * bl)\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * bl)\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * bl)\n return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s]\n }\n const [x, y] = [lab(a), lab(b)]\n return Math.hypot((x[0] as number) - (y[0] as number), (x[1] as number) - (y[1] as number), (x[2] as number) - (y[2] as number))\n}\n\n/** Whether an element draws a shadow. */\nexport function siteImportHasShadow(style: SiteImportComputedStyle): boolean {\n const value = style.get('box-shadow')\n return !!value && !/^(?:none|0|initial|unset)$/.test(value.trim()) && !/^0(?:px)?\\s+0(?:px)?\\s+0(?:px)?(?:\\s+0(?:px)?)?\\s+(?:transparent|rgba\\([^)]*,\\s*0\\))/.test(value.trim())\n}\n\n/** An element's corner radius in px, or `null`. */\nexport function siteImportRadiusPx(style: SiteImportComputedStyle): number | null {\n const value = style.get('border-radius')\n if (!value) return null\n const first = value.trim().split(/[\\s/]+/)[0] ?? ''\n if (first.endsWith('%')) return Number(first.slice(0, -1)) >= 50 ? 999 : Number(first.slice(0, -1))\n return siteImportLengthPx(first)\n}\n\n/** A font size in px, or `null`. */\nexport function siteImportFontSizePx(style: SiteImportComputedStyle): number | null {\n const value = style.get('font-size')\n if (!value) return null\n const clamp = /clamp\\(([^,]+),([^,]+),([^)]+)\\)/.exec(value)\n // A fluid size at the read width: its maximum, as a wide screen shows it.\n const text = clamp ? clamp[3] : value\n return siteImportLengthPx(text.trim())\n}\n\n/** The relative widths a grid template draws its columns at, or `null` for none. */\nexport function siteImportGridColumns(template: string | undefined): number[] | null {\n if (!template || /^(?:none|subgrid|masonry)$/.test(template.trim())) return null\n let text = template.trim()\n // repeat(3, 1fr) / repeat(auto-fill, minmax(240px, 1fr)): the count, or three of them.\n text = text.replace(/repeat\\(\\s*([\\w-]+)\\s*,\\s*((?:[^()]|\\([^()]*\\))*)\\)/g, (_, count: string, track: string) => {\n const times = /^\\d+$/.test(count) ? Math.min(12, Number(count)) : 3\n return Array.from({ length: times }, () => track.trim()).join(' ')\n })\n const tracks: string[] = []\n let depth = 0\n let token = ''\n for (const char of text) {\n if (char === '(') depth += 1\n if (char === ')') depth -= 1\n if (/\\s/.test(char) && depth === 0) {\n if (token) tracks.push(token)\n token = ''\n } else token += char\n }\n if (token) tracks.push(token)\n const weights = tracks\n .filter((track) => !/^\\[.*\\]$/.test(track))\n .map((track) => {\n const fr = /(-?[\\d.]+)fr\\)?$/.exec(track)\n if (fr) return Number(fr[1]) || 1\n const px = /(-?[\\d.]+)px/.exec(track)\n if (px) return Number(px[1]) / 100\n const percent = /(-?[\\d.]+)%/.exec(track)\n if (percent) return Number(percent[1]) / 10\n return 1\n })\n return weights.length ? weights : null\n}\n\n/** A template's top-level words: a track, a `repeat()` or a `[line name]`. */\nfunction gridTemplateWords(template: string): string[] {\n const words: string[] = []\n let depth = 0\n let word = ''\n for (const char of template) {\n if (char === '(' || char === '[') depth += 1\n if (char === ')' || char === ']') depth -= 1\n if (/\\s/.test(char) && depth === 0) {\n if (word) words.push(word)\n word = ''\n } else word += char\n }\n if (word) words.push(word)\n return words\n}\n\n/**\n * How many tracks a grid template draws (AGL-4152), each `repeat()` opened at\n * its whole count; `null` for none, or where the screen decides (`auto-fill`).\n */\nexport function siteImportGridTrackCount(template: string | undefined): number | null {\n const text = template?.trim() ?? ''\n if (!text || /^(?:none|subgrid|masonry|inherit|initial|unset)$/.test(text)) return null\n let count = 0\n for (const word of gridTemplateWords(text)) {\n if (word.startsWith('[')) continue\n const repeat = /^repeat\\(([\\s\\S]*)\\)$/.exec(word)\n if (!repeat) {\n count += 1\n continue\n }\n const [times, ...tracks] = splitList(repeat[1] as string)\n const inner = siteImportGridTrackCount(tracks.join(','))\n if (!/^\\d+$/.test(times ?? '') || inner === null) return null\n count += Number(times) * inner\n }\n return count || null\n}\n\n/** The cells a child of a grid covers, by grid line: `rowEnd` and `columnEnd` are the lines after its last row and column. */\nexport interface SiteImportGridBox {\n rowStart: number\n rowEnd: number\n columnStart: number\n columnEnd: number\n}\n\n/** A child's place along one axis: the line it starts at, `null` where the grid's flow decides, and how many tracks it covers. */\ninterface GridAxis {\n start: number | null\n span: number\n}\n\n/** One written line of a placement: a line number, a span, or nothing a reader can place (`auto`, a named line). */\nfunction gridLineOf(value: string | undefined, tracks: number | null): { line?: number; span?: number } {\n const text = value?.trim() ?? ''\n const span = /^span\\s+(\\d+)$/.exec(text)\n if (span) return { span: Math.max(1, Number(span[1])) }\n if (!/^-?\\d+$/.test(text)) return {}\n const line = Number(text)\n if (line > 0) return { line }\n // A line counted from the end: the last there is, where the template does not say how many.\n if (line < 0) return { line: tracks === null ? Number.POSITIVE_INFINITY : Math.max(1, tracks + 2 + line) }\n return {}\n}\n\nfunction gridAxisOf(startValue: string | undefined, endValue: string | undefined, tracks: number | null): GridAxis {\n const start = gridLineOf(startValue, tracks)\n const end = gridLineOf(endValue, tracks)\n if (start.line === Number.POSITIVE_INFINITY) return { start: null, span: 1 }\n if (start.line !== undefined && end.line !== undefined) {\n const from = Math.min(start.line, end.line)\n return { start: from, span: Math.max(1, Math.max(start.line, end.line) - from) }\n }\n if (start.line !== undefined) return { start: start.line, span: end.span ?? 1 }\n if (end.line !== undefined && end.line !== Number.POSITIVE_INFINITY) {\n const span = start.span ?? 1\n return { start: Math.max(1, end.line - span), span }\n }\n return { start: null, span: start.span ?? end.span ?? 1 }\n}\n\n/** The boxes a `grid-template-areas` names, by name. */\nfunction gridAreasOf(template: string | undefined): Map<string, SiteImportGridBox> {\n const areas = new Map<string, SiteImportGridBox>()\n const rows = [...(template ?? '').matchAll(/\"([^\"]*)\"|'([^']*)'/g)].map((match) => (match[1] ?? match[2] ?? '').trim().split(/\\s+/))\n rows.forEach((names, row) => {\n names.forEach((name, column) => {\n if (!name || /^\\.+$/.test(name)) return\n const held = areas.get(name)\n if (!held) areas.set(name, { rowStart: row + 1, rowEnd: row + 2, columnStart: column + 1, columnEnd: column + 2 })\n else {\n held.rowEnd = Math.max(held.rowEnd, row + 2)\n held.columnEnd = Math.max(held.columnEnd, column + 2)\n }\n })\n })\n return areas\n}\n\n/** A flex or grid child's `order`, 0 where it sets none. */\nexport function siteImportOrderOf(style: SiteImportComputedStyle): number {\n const order = Number.parseInt(style.get('order') ?? '', 10)\n return Number.isNaN(order) ? 0 : order\n}\n\n/**\n * Where a grid places its children (AGL-4152), each child's cells by grid\n * line, as a browser lays them out: the lines each child names (by\n * `grid-area`, a named area, `grid-row` or `grid-column`, a longhand over the\n * shorthand; lines from the end read from the template), then the children it\n * leaves to the grid's flow, in `order`, each in the first cells free.\n *\n * `null` where it cannot say, or there is nothing to say: no child names a\n * place (a `span` says how wide, and `1 / -1` the whole row, not where), the\n * rest of the children flow by columns, or through tracks the screen decides.\n */\nexport function siteImportGridBoxes(container: SiteImportComputedStyle, items: readonly SiteImportComputedStyle[]): SiteImportGridBox[] | null {\n const areas = gridAreasOf(container.get('grid-template-areas'))\n const named = [...areas.values()]\n const columns = siteImportGridTrackCount(container.get('grid-template-columns')) ?? (named.length ? Math.max(...named.map((area) => area.columnEnd)) - 1 : null)\n const rows = siteImportGridTrackCount(container.get('grid-template-rows')) ?? (named.length ? Math.max(...named.map((area) => area.rowEnd)) - 1 : null)\n const places = items.map((item) => {\n const [rowStart, columnStart, rowEnd, columnEnd] = (item.get('grid-area') ?? '').split('/').map((part) => part.trim())\n const area = rowStart && columnStart === undefined ? areas.get(rowStart) : undefined\n const row = item.get('grid-row')?.split('/') ?? [rowStart, rowEnd]\n const column = item.get('grid-column')?.split('/') ?? [columnStart, columnEnd]\n return {\n row: area ? { start: area.rowStart, span: area.rowEnd - area.rowStart } : gridAxisOf(item.get('grid-row-start') ?? row[0], item.get('grid-row-end') ?? row[1], rows),\n column: area ? { start: area.columnStart, span: area.columnEnd - area.columnStart } : gridAxisOf(item.get('grid-column-start') ?? column[0], item.get('grid-column-end') ?? column[1], columns),\n }\n })\n const wholeRow = (axis: GridAxis) => axis.start === 1 && (axis.span === Number.POSITIVE_INFINITY || (columns !== null && axis.span >= columns))\n if (!places.some((place) => place.row.start !== null || (place.column.start !== null && !wholeRow(place.column)))) return null\n const flows = places.some((place) => place.row.start === null || place.column.start === null)\n if (flows && (columns === null || /\\bcolumn\\b/.test(container.get('grid-auto-flow') ?? ''))) return null\n\n const finite = (value: number) => (Number.isFinite(value) ? value : 0)\n const lastRow = Math.max(rows === null ? 1 : rows + 1, ...places.map((place) => (place.row.start ?? 0) + finite(place.row.span)))\n const lastColumn = columns === null ? Math.max(...places.map((place) => (place.column.start ?? 0) + finite(place.column.span))) : columns + 1\n const boxes: Array<SiteImportGridBox | null> = places.map(() => null)\n const free = (row: number, column: number, height: number, width: number) =>\n boxes.every((box) => !box || box.rowEnd <= row || box.rowStart >= row + height || box.columnEnd <= column || box.columnStart >= column + width)\n const put = (at: number, row: number, column: number, height: number, width: number) => {\n boxes[at] = { rowStart: row, rowEnd: row + height, columnStart: column, columnEnd: column + width }\n }\n const heightOf = (axis: GridAxis, row: number) => (Number.isFinite(axis.span) ? axis.span : Math.max(1, lastRow - row))\n const widthOf = (axis: GridAxis, column: number) => Math.max(1, Math.min(axis.span, lastColumn - column))\n const inOrder = places.map((_, at) => at).sort((a, b) => siteImportOrderOf(items[a] as SiteImportComputedStyle) - siteImportOrderOf(items[b] as SiteImportComputedStyle) || a - b)\n // Rows and columns both named first, whatever their order: nothing flows into them.\n for (const at of inOrder) {\n const { row, column } = places[at] as (typeof places)[number]\n if (row.start !== null && column.start !== null) put(at, row.start, column.start, heightOf(row, row.start), widthOf(column, column.start))\n }\n // A row named and its column not: the first cells free in that row.\n for (const at of inOrder) {\n const { row, column } = places[at] as (typeof places)[number]\n if (row.start === null || column.start !== null) continue\n const height = heightOf(row, row.start)\n const width = widthOf(column, 1)\n let left = 1\n while (left + width < lastColumn && !free(row.start, left, height, width)) left += 1\n put(at, row.start, left, height, width)\n }\n // The rest, in the order they flow: a cursor down the grid, never back.\n let cursorRow = 1\n let cursorColumn = 1\n for (const at of inOrder) {\n if (boxes[at]) continue\n const { row, column } = places[at] as (typeof places)[number]\n const height = heightOf(row, 1)\n if (column.start !== null) {\n const width = widthOf(column, column.start)\n if (column.start < cursorColumn) cursorRow += 1\n cursorColumn = column.start\n while (!free(cursorRow, cursorColumn, height, width)) cursorRow += 1\n put(at, cursorRow, cursorColumn, height, width)\n continue\n }\n const width = widthOf(column, 1)\n while (cursorColumn + width > lastColumn || !free(cursorRow, cursorColumn, height, width)) {\n cursorColumn += 1\n if (cursorColumn + width > lastColumn) {\n cursorColumn = 1\n cursorRow += 1\n }\n }\n put(at, cursorRow, cursorColumn, height, width)\n }\n return boxes as SiteImportGridBox[]\n}\n\n/** Weights scaled to twelfths, each at least 1: `[420, 788]` is `[4, 8]`. */\nexport function siteImportTwelfths(weights: readonly number[]): number[] {\n const total = weights.reduce((sum, weight) => sum + Math.max(0, weight), 0)\n if (!total) return weights.map(() => 1)\n const scaled = weights.map((weight) => Math.max(1, Math.round((Math.max(0, weight) / total) * 12)))\n // Two equal tracks stay equal, three stay thirds.\n const unique = new Set(weights.map((weight) => Math.round(weight * 1000)))\n if (unique.size === 1) return weights.map(() => 1)\n return scaled\n}\n\n/** The families a `font-family` value names, quotes dropped, generic ones left out. */\nexport function siteImportFontFamilies(value: string | undefined): string[] {\n if (!value) return []\n return splitList(value)\n .map((family) => family.replace(/^[\"']|[\"']$/g, '').trim())\n .filter((family) => family && !/^(?:serif|sans-serif|monospace|cursive|fantasy|system-ui|ui-[\\w-]+|-apple-system|blinkmacsystemfont|inherit|initial|emoji|math|var\\(.*)$/i.test(family))\n}\n\n/*------------------------------------------\n * Reading a page's stylesheets\n *-----------------------------------------*/\n\n/**\n * How much of a page's stylesheets is read (AGL-4152). A site builder's own\n * sheet can be its fifth link and 1.3 MB, with half a megabyte more behind it,\n * and every color and font of the site is in it. So:\n *\n * - `firstLookBytes`: every link is first read this far. Most sheets end\n * inside it, and those are done; a larger one shows here whether it declares\n * `:root` custom properties, which they do at their top.\n * - `budgetBytes`: what all the page's sheets may hold together, first looks\n * included. Three times the sheet that set it, with room for what comes with\n * it. What does not fit is cut, and a cut sheet is read as far as it goes.\n * - `atOnce`: first looks asked together, so twenty links are not twenty\n * connections to one host.\n *\n * So one page's read costs at most its links' first looks and the budget:\n * 3.8 MB at the most links a page lists, however large its sheets are.\n */\nexport const SITE_IMPORT_SHEET_LIMITS = {\n firstLookBytes: 32 * 1024,\n budgetBytes: 3 * 1024 * 1024,\n atOnce: 6,\n} as const\n\n/** What a read of a stylesheet gives back. */\nexport interface SiteImportSheetAnswer {\n ok: boolean\n text: string\n /** Bytes read. */\n bytes: number\n /** Whether the sheet goes on past `maxBytes`. */\n truncated: boolean\n}\n\n/** Reads a stylesheet to a number of bytes; `null` where it cannot. */\nexport type SiteImportSheetRead = (url: string, maxBytes: number) => Promise<SiteImportSheetAnswer | null>\n\n/** Whether a sheet declares custom properties on the page's root: its theme, not a widget's. */\nconst ROOT_VARIABLES = /(?:^|[},;\\s])(?::root|html)\\b[^{}]*\\{[^{}]*--[\\w-]+\\s*:/\n\n/**\n * Every stylesheet a page links, to a byte budget (AGL-4152), in link order,\n * as the cascade needs them. Each is read a first look; then the ones that go\n * on are read whole, the ones declaring `:root` custom properties first, then\n * the rest in link order, each to what is left of the budget. A read that fails\n * leaves its sheet out, and never the page.\n */\nexport async function siteImportReadStylesheets(\n urls: readonly string[],\n read: SiteImportSheetRead,\n options: { budgetBytes?: number; outOfTime?: () => boolean } = {},\n): Promise<string[]> {\n const budget = options.budgetBytes ?? SITE_IMPORT_SHEET_LIMITS.budgetBytes\n const outOfTime = options.outOfTime ?? (() => false)\n const unique = [...new Set(urls)]\n const looks: Array<SiteImportSheetAnswer | null> = unique.map(() => null)\n const ask = (url: string, maxBytes: number) => read(url, maxBytes).then((answer) => (answer?.ok ? answer : null), () => null)\n let next = 0\n await Promise.all(\n Array.from({ length: Math.min(SITE_IMPORT_SHEET_LIMITS.atOnce, unique.length) }, async () => {\n while (next < unique.length && !outOfTime()) {\n const at = next\n next += 1\n looks[at] = await ask(unique[at] as string, SITE_IMPORT_SHEET_LIMITS.firstLookBytes)\n }\n }),\n )\n let room = budget - looks.reduce((sum, look) => sum + (look?.bytes ?? 0), 0)\n const rest = unique.map((_, at) => at).filter((at) => looks[at]?.truncated)\n const theme = (at: number) => (ROOT_VARIABLES.test((looks[at] as SiteImportSheetAnswer).text) ? 0 : 1)\n rest.sort((a, b) => theme(a) - theme(b) || a - b)\n for (const at of rest) {\n if (room <= 0 || outOfTime()) break\n const look = looks[at] as SiteImportSheetAnswer\n const whole = await ask(unique[at] as string, look.bytes + room)\n if (!whole) continue\n room -= whole.bytes - look.bytes\n looks[at] = whole\n }\n return looks.flatMap((look) => (look ? [look.text] : []))\n}\n"],"names":["SITE_IMPORT_CSS_VIEWPORT","width","height","SITE_IMPORT_CSS_WIDE_WIDTH","KEPT_PROPERTIES","Set","GRID_PLACEMENT","INHERITED","unescapeIdent","text","replace","_","escaped","test","code","parseInt","trim","String","fromCodePoint","IDENT","raw","SIMPLE","RegExp","AT_REST","parseCompound","compound","tag","id","classes","attrs","root","rest","match","exec","slice","length","toLowerCase","push","name","op","value","has","parseSelector","compounds","combinators","parts","split","pending","part","ids","tags","specificity","SELECTOR_VARIANTS","spelledOut","discount","inner","index","depth","end","head","tail","zeroed","joined","out","option","splitList","variant","start","at","char","Math","max","map","filter","Boolean","siteImportLengthPx","amount","Number","mediaQueryHolds","query","viewport","scheme","negate","startsWith","holds","term","feature","px","range","size","a","b","mediaHolds","prelude","list","some","DARK_SCOPE","withoutDarkScope","declarationsOf","body","decls","colon","indexOf","written","property","important","keyOf","selector","last","siteImportCssOf","sheets","options","css","rules","Map","fontFaces","darkRules","variableUses","order","darkGroups","addRule","includes","use","matchAll","set","get","lifted","rule","key","sheet","groups","pop","applies","every","family","placed","flatMap","join","classesOf","element","class","attributeOf","role","label","href","type","style","hidden","undefined","theme","compoundMatches","rootId","own","attr","wanted","ok","endsWith","selectorMatches","elements","above","parent","walk","combinator","siblings","children","position","before","sibling","EMPTY_STYLE","VARIABLE_DEPTH","withVariables","custom","pass","fallback","inlineDeclarations","siteImportStylesOf","structure","resolved","rootStyle","fake","region","nav","blocks","candidates","apply","inline","unique","sort","put","flag","resolve","held","matched","declares","lowered","inherited","delete","entry","of","rootVariables","NAMED_COLORS","white","black","red","green","blue","gray","grey","silver","whitesmoke","ghostwhite","snow","ivory","beige","linen","navy","teal","orange","gold","purple","crimson","tomato","coral","aliceblue","lightgray","lightgrey","gainsboro","darkslategray","dimgray","siteImportColorOf","hex","rgb","hsl","named","first","alphaOf","digits","full","d","r","g","channel","min","h","s","l","q","p","tone","t","x","known","BRAND_VARIABLE","colorOfVariable","PALETTE_COLORS","siteImportPaletteOf","styles","uses","tally","color","siteImportSaturation","light","siteImportLuminance","siteImportHex","entries","round","toString","padStart","linear","c","abs","siteImportBackgroundOf","shorthand","imageValue","colorValue","gradient","image","gradientMatch","stops","stop","url","siteImportHasBorder","sides","side","kind","SIDES","siteImportBorderSides","shared","drawn","all","found","Object","keys","widths","by","forEach","siteImportAspectRatio","siteImportOpaque","under","ground","siteImportColorDistance","lab","bl","cbrt","m","y","hypot","siteImportHasShadow","siteImportRadiusPx","siteImportFontSizePx","clamp","siteImportGridColumns","template","count","track","times","Array","from","tracks","token","weights","fr","percent","gridTemplateWords","words","word","siteImportGridTrackCount","repeat","gridLineOf","span","line","POSITIVE_INFINITY","gridAxisOf","startValue","endValue","gridAreasOf","areas","rows","names","row","column","rowStart","rowEnd","columnStart","columnEnd","siteImportOrderOf","isNaN","siteImportGridBoxes","container","items","values","columns","area","places","item","wholeRow","axis","place","flows","finite","isFinite","lastRow","lastColumn","boxes","free","box","heightOf","widthOf","inOrder","left","cursorRow","cursorColumn","siteImportTwelfths","total","reduce","sum","weight","scaled","siteImportFontFamilies","SITE_IMPORT_SHEET_LIMITS","firstLookBytes","budgetBytes","atOnce","ROOT_VARIABLES","siteImportReadStylesheets","urls","read","budget","outOfTime","looks","ask","maxBytes","then","answer","next","Promise","room","look","bytes","truncated","whole"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;2CAyB2C,GAI3C,2EAA2E,GAC3E,OAAO,MAAMA,2BAA2B;IAAEC,OAAO;IAAMC,QAAQ;AAAI,EAAU;AAE7E;;;;;CAKC,GACD,OAAO,MAAMC,6BAA6B,KAAI;AAE9C,uGAAuG,GACvG,MAAMC,kBAAkB,IAAIC,IAAI;IAC9B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kFAAkF;IAClF;IACA;IACA;IACA;IACA;IACA;IACA;IAC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AAG,GAAG,MAAMkU,IAAI5M,MAAM,CAACtH,GAAG,EAAYuT,yBAAyBC,cAAc;QACrF;IACF;IAEF,IAAIgB,OAAOT,SAASE,MAAMf,MAAM,CAAC,CAACC,KAAKsB;;eAAStB,eAAOsB,wBAAAA,KAAMC,KAAK,mBAAI;OAAI;IAC1E,MAAM/W,OAAO2J,OAAOlH,GAAG,CAAC,CAAC7D,GAAGyD,KAAOA,IAAIK,MAAM,CAAC,CAACL;YAAOiU;gBAAAA,YAAAA,KAAK,CAACjU,GAAG,qBAATiU,UAAWU,SAAS;;IAC1E,MAAM1P,QAAQ,CAACjF,KAAgB2T,eAAelX,IAAI,CAAC,AAACwX,KAAK,CAACjU,GAAG,CAA2B3D,IAAI,IAAI,IAAI;IACpGsB,KAAK4J,IAAI,CAAC,CAACjG,GAAGC,IAAM0D,MAAM3D,KAAK2D,MAAM1D,MAAMD,IAAIC;IAC/C,KAAK,MAAMvB,MAAMrC,KAAM;QACrB,IAAI6W,QAAQ,KAAKR,aAAa;QAC9B,MAAMS,OAAOR,KAAK,CAACjU,GAAG;QACtB,MAAM4U,QAAQ,MAAMV,IAAI5M,MAAM,CAACtH,GAAG,EAAYyU,KAAKC,KAAK,GAAGF;QAC3D,IAAI,CAACI,OAAO;QACZJ,QAAQI,MAAMF,KAAK,GAAGD,KAAKC,KAAK;QAChCT,KAAK,CAACjU,GAAG,GAAG4U;IACd;IACA,OAAOX,MAAM7P,OAAO,CAAC,CAACqQ,OAAUA,OAAO;YAACA,KAAKpY,IAAI;SAAC,GAAG,EAAE;AACzD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/site-import/site-import-css.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 * HOW A PAGE IS STYLED, AS A WIDE SCREEN SHOWS IT (AGL-4106).\n *\n * Bring my site reads a page's layout, not only its lines, and most of a\n * layout lives in the stylesheet: which band is grey and which is dark, which\n * container lays its children out in three columns, which link is drawn as a\n * filled button. This is a small cascade, enough for that and no more:\n *\n * - **The sheets.** The page's own `<style>` sheets and the ones it links,\n * every one to a byte budget (`siteImportReadStylesheets`, AGL-4152), read\n * in order. `@media` rules apply as a 1280-pixel screen in light mode\n * sees them, so a grid's desktop columns win over its phone ones;\n * `@layer`, `@supports` and `@container` are read through; keyframes, font\n * faces (their families noted) and page rules are skipped.\n * - **Selectors.** Tags, classes (escaped ones too, as utility frameworks\n * write them), ids and attributes, joined by any combinator, and `:is()`\n * and `:where()` spelled out (AGL-4152). A rule that\n * only applies on hover, focus or to a generated part (`::before`) is a\n * state the page is not in and is not read.\n * - **The cascade.** Specificity, then order, `!important` over both, and the\n * element's own `style` over every rule; color, font and alignment inherit,\n * and so do custom properties, which `var()` reads.\n *\n * Only the properties the layout reader asks about are kept. Nothing here\n * runs anything a page wrote: values are text compared to text.\n *=========================================*/\n\nimport type { SiteImportElement, SiteImportStructure } from './site-import-html'\n\n/** The width a page is read at: a laptop's, where a desktop layout shows. */\nexport const SITE_IMPORT_CSS_VIEWPORT = { width: 1280, height: 800 } as const\n\n/**\n * The width a page's column is read at (AGL-4083). A container caps itself\n * only on screens wider than its cap (`@media (min-width:1536px)` around a\n * `max-width:1536px`), so on a laptop it runs the whole page: read there, it\n * would look as if it had no cap at all.\n */\nexport const SITE_IMPORT_CSS_WIDE_WIDTH = 1920\n\n/** The properties the layout reader reads; every other declaration is dropped as the sheet is parsed. */\nconst KEPT_PROPERTIES = new Set([\n 'background',\n 'background-color',\n 'background-image',\n 'color',\n 'border',\n 'border-width',\n 'border-style',\n 'border-color',\n 'border-top',\n 'border-right',\n 'border-bottom',\n 'border-left',\n 'border-top-width',\n 'border-bottom-width',\n 'border-left-width',\n 'border-right-width',\n 'border-top-style',\n 'border-bottom-style',\n 'border-top-color',\n 'border-bottom-color',\n 'border-radius',\n 'box-shadow',\n 'display',\n 'grid-template-columns',\n 'grid-column',\n // Where a grid places its children, and the order a row shows them in (AGL-4152).\n 'grid-template-rows',\n 'grid-template-areas',\n 'grid-auto-flow',\n 'grid-area',\n 'grid-row',\n 'grid-row-start',\n 'grid-row-end',\n 'grid-column-start',\n 'grid-column-end',\n 'order',\n 'flex',\n 'flex-direction',\n 'flex-wrap',\n 'flex-grow',\n 'flex-basis',\n 'width',\n 'max-width',\n // The shape a picture is framed at (AGL-4138): a box's own, or a height it is cropped to.\n 'aspect-ratio',\n 'height',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'text-transform',\n 'letter-spacing',\n 'text-align',\n 'position',\n 'visibility',\n 'padding',\n 'padding-top',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'object-fit',\n 'justify-content',\n 'align-items',\n // What says a visitor cannot see an element (AGL-4152): clipped, off-screen, its words pushed away; and how its lines break.\n 'clip',\n 'clip-path',\n 'overflow',\n 'left',\n 'right',\n 'top',\n 'transform',\n 'text-indent',\n 'white-space',\n])\n\n/** What a rule says of a child's place in its grid, which a breakpoint nested in the rule may say again (AGL-4152). */\nconst GRID_PLACEMENT = /^(?:grid-area|grid-row|grid-row-start|grid-row-end|grid-column|grid-column-start|grid-column-end|order)$/\n\n/** What an element takes from its parent when it says nothing itself. */\nconst INHERITED = new Set(['color', 'font-family', 'font-size', 'font-weight', 'text-transform', 'letter-spacing', 'text-align', 'visibility', 'white-space'])\n\ninterface Compound {\n tag: string | null\n id: string | null\n classes: string[]\n attrs: Array<{ name: string; op: string | null; value: string }>\n /** `:root`: only the document's root element. */\n root: boolean\n}\n\ninterface ComplexSelector {\n /** Rightmost last. */\n compounds: Compound[]\n /** `combinators[i]` joins `compounds[i]` and `compounds[i + 1]`: a space, a child, an adjacent or a sibling combinator. */\n combinators: string[]\n specificity: number\n}\n\ninterface CssRule {\n selector: ComplexSelector\n order: number\n decls: Array<[property: string, value: string, important: boolean]>\n}\n\n/** The page's sheets, parsed for one width. */\nexport interface SiteImportCss {\n rules: CssRule[]\n /** Rules by their rightmost compound's id (`#x`), first class (`.x`), tag, or `*`. */\n index: Map<string, CssRule[]>\n /** Families its `@font-face` rules name, in order. */\n fontFaces: string[]\n /** Read for its dark scheme (AGL-4152): the rules that scheme alone selects, by a media query or a class on the page. */\n darkRules: number\n /** How many declarations read each custom property (AGL-4152): what its palette uses most. */\n variableUses: Map<string, number>\n}\n\n/** Which of a page's color schemes a read of its stylesheets answers for. */\nexport interface SiteImportCssOptions {\n /** Absent is `light`, as a page is first read. */\n scheme?: 'light' | 'dark'\n}\n\n/*------------------------------------------\n * Parsing\n *-----------------------------------------*/\n\nfunction unescapeIdent(text: string): string {\n return text.replace(/\\\\([0-9a-fA-F]{1,6}\\s?|.)/g, (_, escaped: string) => {\n if (/^[0-9a-fA-F]{1,6}\\s?$/.test(escaped)) {\n const code = parseInt(escaped.trim(), 16)\n return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : ''\n }\n return escaped\n })\n}\n\nconst IDENT = String.raw`(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\.|[\\w-]|[^\\x00-\\x7f])+`\nconst SIMPLE = new RegExp(\n String.raw`^(?:(\\*|${IDENT})|#(${IDENT})|\\.(${IDENT})|\\[\\s*([\\w-]+)\\s*(?:([~|^$*]?=)\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\]\\s]+))\\s*(?:[is]\\s*)?)?\\]|(::?)(${IDENT})(\\((?:[^()]|\\([^()]*\\))*\\))?)`,\n)\n\n/** The pseudo-classes a page at rest matches as if they were not there. */\nconst AT_REST = new Set(['link', 'any-link'])\n\n/** One compound selector, or `null` when it depends on a state or a generated part. */\nfunction parseCompound(text: string): Compound | null {\n const compound: Compound = { tag: null, id: null, classes: [], attrs: [], root: false }\n let rest = text\n while (rest) {\n const match = SIMPLE.exec(rest)\n if (!match || !match[0]) return null\n rest = rest.slice(match[0].length)\n if (match[1]) compound.tag = match[1] === '*' ? null : unescapeIdent(match[1]).toLowerCase()\n else if (match[2]) compound.id = unescapeIdent(match[2])\n else if (match[3]) compound.classes.push(unescapeIdent(match[3]))\n else if (match[4]) compound.attrs.push({ name: match[4].toLowerCase(), op: match[5] ?? null, value: match[6] ?? match[7] ?? match[8] ?? '' })\n else if (match[9]) {\n const name = unescapeIdent(match[10] ?? '').toLowerCase()\n if (match[9] === '::') return null\n if (name === 'root') compound.root = true\n else if (!AT_REST.has(name)) return null\n }\n }\n return compound\n}\n\n/** A complex selector, or `null` when any part of it cannot be read at rest. */\nfunction parseSelector(text: string): ComplexSelector | null {\n const compounds: Compound[] = []\n const combinators: string[] = []\n const parts = text.trim().replace(/\\s*([>+~])\\s*/g, ' $1 ').split(/\\s+/)\n let pending: string | null = null\n for (const part of parts) {\n if (!part) continue\n if (part === '>' || part === '+' || part === '~') {\n pending = part\n continue\n }\n const compound = parseCompound(part)\n if (!compound) return null\n if (compounds.length) combinators.push(pending ?? ' ')\n pending = null\n compounds.push(compound)\n }\n if (!compounds.length || pending) return null\n let ids = 0\n let classes = 0\n let tags = 0\n for (const compound of compounds) {\n if (compound.id) ids += 1\n classes += compound.classes.length + compound.attrs.length + (compound.root ? 1 : 0)\n if (compound.tag) tags += 1\n }\n return { compounds, combinators, specificity: ids * 1_000_000 + classes * 1_000 + tags }\n}\n\n/** The most selectors one written with `:is()` or `:where()` is spelled out into. */\nconst SELECTOR_VARIANTS = 24\n\n/**\n * A selector with its `:is()` and `:where()` spelled out (AGL-4152), each with\n * the weight to take off for a `:where()`, which counts for nothing. A variant\n * two compounds cannot be joined into (`.x:is(div)`, `.x:is(.a .b)`) is left out.\n */\nfunction spelledOut(text: string): Array<{ text: string; discount: number }> {\n const match = /:(?:is|where)\\(/i.exec(text)\n if (!match) return [{ text, discount: 0 }]\n const inner = match.index + match[0].length\n let depth = 1\n let end = inner\n while (end < text.length && depth > 0) {\n if (text[end] === '(') depth += 1\n else if (text[end] === ')') depth -= 1\n end += 1\n }\n if (depth) return [{ text, discount: 0 }]\n const head = text.slice(0, match.index)\n const tail = text.slice(end)\n const zeroed = /where/i.test(match[0])\n const joined = !head || /[\\s>+~]$/.test(head)\n const out: Array<{ text: string; discount: number }> = []\n for (const option of splitList(text.slice(inner, end - 1))) {\n if (!joined && (/\\s/.test(option) || /^[\\w*]/.test(option))) continue\n const discount = zeroed ? (parseSelector(option.replace(/:(?:is|where)\\([^()]*\\)/gi, ''))?.specificity ?? 0) : 0\n for (const variant of spelledOut(`${head}${option}${tail}`)) {\n if (out.length >= SELECTOR_VARIANTS) return out\n out.push({ text: variant.text, discount: discount + variant.discount })\n }\n }\n return out\n}\n\n/** Splits at top-level commas: none inside brackets or parentheses. */\nfunction splitList(text: string): string[] {\n const out: string[] = []\n let depth = 0\n let start = 0\n for (let at = 0; at < text.length; at += 1) {\n const char = text[at]\n if (char === '(' || char === '[') depth += 1\n else if (char === ')' || char === ']') depth = Math.max(0, depth - 1)\n else if (char === ',' && depth === 0) {\n out.push(text.slice(start, at))\n start = at + 1\n }\n }\n out.push(text.slice(start))\n return out.map((part) => part.trim()).filter(Boolean)\n}\n\n/** A length in px at the read width; `em`/`rem` at 16. */\nexport function siteImportLengthPx(value: string): number | null {\n const match = /^(-?\\d*\\.?\\d+)\\s*(px|em|rem)?$/i.exec(value.trim())\n if (!match) return null\n const amount = Number(match[1])\n return match[2] && match[2].toLowerCase() !== 'px' ? amount * 16 : amount\n}\n\n/** Whether one media query holds for a screen of this width in this color scheme. */\nfunction mediaQueryHolds(query: string, viewport: number, scheme: 'light' | 'dark'): boolean {\n let text = query.trim().toLowerCase()\n let negate = false\n if (text.startsWith('not ')) {\n negate = true\n text = text.slice(4)\n }\n text = text.replace(/^only\\s+/, '')\n let holds = true\n for (const part of text.split(/\\s+and\\s+/)) {\n const term = part.trim()\n if (!term) continue\n if (!term.startsWith('(')) {\n if (!/^(?:all|screen)$/.test(term)) holds = false\n continue\n }\n const inner = term.replace(/^\\(|\\)$/g, '').trim()\n const feature = /^([\\w-]+)\\s*:\\s*(.+)$/.exec(inner)\n const { height } = SITE_IMPORT_CSS_VIEWPORT\n const width = viewport\n if (feature) {\n const [, name, value] = feature\n const px = siteImportLengthPx(value)\n if (name === 'min-width') holds &&= px !== null && width >= px\n else if (name === 'max-width') holds &&= px !== null && width <= px\n else if (name === 'min-height') holds &&= px !== null && height >= px\n else if (name === 'max-height') holds &&= px !== null && height <= px\n else if (name === 'prefers-color-scheme') holds &&= value.trim() === scheme\n else if (name === 'prefers-reduced-motion') holds &&= value.trim() === 'no-preference'\n else if (name === 'orientation') holds &&= value.trim() === 'landscape'\n else if (name === 'hover' || name === 'any-hover') holds &&= value.trim() === 'hover'\n else if (name === 'pointer' || name === 'any-pointer') holds &&= value.trim() === 'fine'\n else if (name === 'prefers-contrast' || name === 'forced-colors') holds &&= /^(?:no-preference|none)$/.test(value.trim())\n continue\n }\n // Range syntax: (width >= 900px), (600px <= width < 1200px).\n const range = /^(?:(-?[\\d.]+\\w*)\\s*(<=|<|>=|>)\\s*)?(width|height)\\s*(?:(<=|<|>=|>)\\s*(-?[\\d.]+\\w*))?$/.exec(inner)\n if (range) {\n const size = range[3] === 'width' ? width : height\n const test = (a: number, op: string, b: number) => (op === '<' ? a < b : op === '<=' ? a <= b : op === '>' ? a > b : a >= b)\n if (range[1] && range[2]) {\n const px = siteImportLengthPx(range[1])\n holds &&= px !== null && test(px, range[2], size)\n }\n if (range[4] && range[5]) {\n const px = siteImportLengthPx(range[5])\n holds &&= px !== null && test(size, range[4], px)\n }\n }\n }\n return negate ? !holds : holds\n}\n\nfunction mediaHolds(prelude: string, viewport: number, scheme: 'light' | 'dark'): boolean {\n const list = splitList(prelude.replace(/^@media\\s*/i, ''))\n return !list.length || list.some((query) => mediaQueryHolds(query, viewport, scheme))\n}\n\n/**\n * A selector's leading mark of the dark scheme (AGL-4152): `.dark`, `.dark-mode`\n * or a `data-theme` that says dark, on the page's root or body. Nothing a read\n * sees carries it, so a dark read lifts it off and the rest applies as written.\n */\nconst DARK_SCOPE = /^(?:(html|body|:root))?(?:\\.dark(?:-mode|-theme)?|\\[\\s*data-(?:theme|mode|color-scheme|color-mode|bs-theme|mui-color-scheme)\\s*[*~|^]?=\\s*[\"']?[^\"'\\]]*dark[^\"'\\]]*[\"']?\\s*(?:i\\s*)?\\])(?=$|[\\s>+~.:#[])/i\n\n/** What a selector asks of a page in its dark scheme, its mark lifted off: what remains, else the element that held the mark. `null` for a selector with no such mark. */\nfunction withoutDarkScope(text: string): string | null {\n const match = DARK_SCOPE.exec(text.trim())\n if (!match) return null\n const rest = text.trim().slice(match[0].length).replace(/^[\\s>+~]+/, '')\n return rest || match[1] || ':root'\n}\n\nfunction declarationsOf(body: string): CssRule['decls'] {\n const decls: CssRule['decls'] = []\n // Values may hold semicolons only inside strings or url(), which the kept properties never need.\n for (const part of body.split(';')) {\n const colon = part.indexOf(':')\n if (colon <= 0) continue\n const written = part.slice(0, colon).trim()\n // A custom property's name is case-sensitive, as `var()` reads it.\n const property = written.startsWith('--') ? written : written.toLowerCase()\n if (!property.startsWith('--') && !KEPT_PROPERTIES.has(property)) continue\n let value = part.slice(colon + 1).trim()\n const important = /!\\s*important\\s*$/i.test(value)\n if (important) value = value.replace(/!\\s*important\\s*$/i, '').trim()\n if (value) decls.push([property, value.slice(0, 2_000), important])\n }\n return decls\n}\n\n/** The index key of a selector: its rightmost compound's id, first class, tag, else `*`. */\nfunction keyOf(selector: ComplexSelector): string {\n const last = selector.compounds[selector.compounds.length - 1] as Compound\n if (last.id) return `#${last.id}`\n if (last.classes.length) return `.${last.classes[0]}`\n if (last.root) return ':root'\n if (last.tag) return last.tag\n return '*'\n}\n\n/**\n * The page's sheets parsed for a wide screen. Malformed CSS is read as far as\n * it makes sense, as a browser would; nothing throws.\n */\nexport function siteImportCssOf(sheets: readonly string[], viewport: number = SITE_IMPORT_CSS_VIEWPORT.width, options: SiteImportCssOptions = {}): SiteImportCss {\n const css: SiteImportCss = { rules: [], index: new Map(), fontFaces: [], darkRules: 0, variableUses: new Map() }\n const scheme = options.scheme ?? 'light'\n let order = 0\n /** For each open group: whether only a dark scheme's media query opens it. */\n const darkGroups: boolean[] = []\n const addRule = (prelude: string, body: string) => {\n const decls = declarationsOf(body)\n if (!decls.length) return\n for (const [, value] of decls) {\n if (!value.includes('var(')) continue\n for (const use of value.matchAll(/var\\(\\s*(--[\\w-]+)/g)) css.variableUses.set(use[1] as string, (css.variableUses.get(use[1] as string) ?? 0) + 1)\n }\n for (const text of splitList(prelude)) {\n const lifted = scheme === 'dark' ? withoutDarkScope(text) : null\n for (const variant of spelledOut(lifted ?? text)) {\n const selector = parseSelector(variant.text)\n if (!selector) continue\n selector.specificity = Math.max(0, selector.specificity - variant.discount)\n if (scheme === 'dark' && (lifted !== null || darkGroups.includes(true))) css.darkRules += 1\n // The mark it lost still counts: a dark rule outranks the same rule of the light scheme.\n if (lifted !== null) selector.specificity += 1_000\n const rule: CssRule = { selector, order: order++, decls }\n css.rules.push(rule)\n const key = keyOf(selector)\n const list = css.index.get(key)\n if (list) list.push(rule)\n else css.index.set(key, [rule])\n }\n }\n }\n for (const sheet of sheets) {\n const text = String(sheet ?? '').replace(/\\/\\*[\\s\\S]*?\\*\\//g, ' ')\n /** For each open group: whether its rules apply. */\n const groups: boolean[] = []\n let at = 0\n let start = 0\n while (at < text.length) {\n const char = text[at]\n if (char === '\"' || char === \"'\") {\n const end = text.indexOf(char, at + 1)\n at = end < 0 ? text.length : end + 1\n continue\n }\n if (char === ';') {\n // A statement at-rule (@import, @charset) or stray text.\n start = at + 1\n at += 1\n continue\n }\n if (char === '}') {\n groups.pop()\n darkGroups.pop()\n start = at + 1\n at += 1\n continue\n }\n if (char !== '{') {\n at += 1\n continue\n }\n const prelude = text.slice(start, at).trim()\n const applies = groups.every(Boolean)\n if (/^@(?:media)\\b/i.test(prelude)) {\n groups.push(applies && mediaHolds(prelude, viewport, scheme))\n darkGroups.push(/prefers-color-scheme\\s*:\\s*dark/i.test(prelude))\n start = at = at + 1\n continue\n }\n if (/^@(?:supports|layer|container|document|scope|starting-style)\\b/i.test(prelude)) {\n groups.push(applies && !/^@starting-style/i.test(prelude))\n darkGroups.push(false)\n start = at = at + 1\n continue\n }\n // A block to read whole: a style rule, a font face, or an at-rule to skip.\n let depth = 1\n let end = at + 1\n while (end < text.length && depth > 0) {\n if (text[end] === '{') depth += 1\n else if (text[end] === '}') depth -= 1\n end += 1\n }\n const body = text.slice(at + 1, Math.max(at + 1, end - 1))\n if (/^@font-face\\b/i.test(prelude)) {\n const family = /font-family\\s*:\\s*([\"']?)([^;\"']+)\\1/i.exec(body)?.[2]?.trim()\n if (family && !css.fontFaces.includes(family)) css.fontFaces.push(family)\n } else if (!prelude.startsWith('@') && applies && prelude) {\n // A rule nested inside a rule (`&:hover`) is a state: only the outer declarations are read.\n // A breakpoint nested inside one that holds at this width places its child as a top-level one does.\n const placed = [...body.matchAll(/@media([^{};]*)\\{([^{}]*)\\}/g)]\n .filter((match) => mediaHolds(match[1] as string, viewport, scheme))\n .flatMap((match) => (match[2] as string).split(';').filter((part) => GRID_PLACEMENT.test(part.slice(0, part.indexOf(':')).trim().toLowerCase())))\n addRule(prelude, [body.replace(/[^;{}]*\\{[^{}]*\\}/g, ''), ...placed].join(';'))\n }\n start = at = end\n }\n }\n return css\n}\n\n/*------------------------------------------\n * Matching and the cascade\n *-----------------------------------------*/\n\nfunction classesOf(element: SiteImportElement): string[] {\n return (element.attrs.class ?? '').split(/\\s+/).filter(Boolean)\n}\n\nfunction attributeOf(element: SiteImportElement, name: string): string | undefined {\n switch (name) {\n case 'class':\n return element.attrs.class\n case 'id':\n return element.attrs.id\n case 'role':\n return element.attrs.role\n case 'aria-label':\n return element.attrs.label\n case 'href':\n return element.attrs.href\n case 'type':\n return element.attrs.type\n case 'style':\n return element.attrs.style\n case 'hidden':\n case 'aria-hidden':\n return element.attrs.hidden ? 'true' : undefined\n case 'data-section-theme':\n case 'data-theme':\n return element.attrs.theme\n default:\n return undefined\n }\n}\n\nfunction compoundMatches(compound: Compound, element: SiteImportElement, rootId: number): boolean {\n if (compound.root && element.id !== rootId) return false\n if (compound.tag && compound.tag !== element.tag) return false\n if (compound.id && compound.id !== element.attrs.id) return false\n if (compound.classes.length) {\n const own = classesOf(element)\n if (!compound.classes.every((name) => own.includes(name))) return false\n }\n for (const attr of compound.attrs) {\n const value = attributeOf(element, attr.name)\n if (value === undefined) return false\n if (!attr.op) continue\n const wanted = attr.value\n const ok =\n attr.op === '='\n ? value === wanted\n : attr.op === '~='\n ? value.split(/\\s+/).includes(wanted)\n : attr.op === '^='\n ? value.startsWith(wanted)\n : attr.op === '$='\n ? value.endsWith(wanted)\n : attr.op === '*='\n ? value.includes(wanted)\n : value === wanted || value.startsWith(`${wanted}-`)\n if (!ok) return false\n }\n return true\n}\n\n/** Whether a selector matches an element, its combinators walked from the right. */\nfunction selectorMatches(\n selector: ComplexSelector,\n element: SiteImportElement,\n elements: readonly SiteImportElement[],\n root: SiteImportElement | null,\n): boolean {\n const rootId = root?.id ?? -2\n /** The element above `at`: its parent, or the document's root above the body. */\n const above = (at: SiteImportElement) => (at.parent >= 0 ? elements[at.parent] : at === root ? undefined : (root ?? undefined))\n const walk = (index: number, at: SiteImportElement): boolean => {\n if (!compoundMatches(selector.compounds[index] as Compound, at, rootId)) return false\n if (index === 0) return true\n const combinator = selector.combinators[index - 1]\n if (combinator === '>') {\n const parent = above(at)\n return !!parent && walk(index - 1, parent)\n }\n if (combinator === '+' || combinator === '~') {\n const siblings = elements[at.parent]?.children ?? []\n const position = siblings.indexOf(at.id)\n for (let before = position - 1; before >= 0; before -= 1) {\n const sibling = elements[siblings[before] as number]\n if (!sibling) continue\n if (walk(index - 1, sibling)) return true\n if (combinator === '+') return false\n }\n return false\n }\n for (let parent = above(at); parent; parent = above(parent)) {\n if (walk(index - 1, parent)) return true\n }\n return false\n }\n return walk(selector.compounds.length - 1, element)\n}\n\n/** One element's resolved style: the kept properties, `var()` read, lowercased. */\nexport type SiteImportComputedStyle = ReadonlyMap<string, string>\n\n/** Reads elements' styles over a page's structure, each once. */\nexport interface SiteImportStyles {\n of(element: number): SiteImportComputedStyle\n /** The root's (`<html>`) element id, which `:root` matches; -1 for none. */\n readonly root: number\n /** The custom properties the root declares (AGL-4152), each read through to what it holds. */\n rootVariables(): ReadonlyMap<string, string>\n}\n\nconst EMPTY_STYLE: SiteImportComputedStyle = new Map()\n\n/** How far a variable that names a variable is followed: a site builder's palette goes several deep. */\nconst VARIABLE_DEPTH = 8\n\n/** Replaces each `var(--x, fallback)` with what the custom properties hold, to a few levels. */\nfunction withVariables(value: string, custom: ReadonlyMap<string, string>): string {\n let out = value\n for (let pass = 0; pass < VARIABLE_DEPTH && out.includes('var('); pass += 1) {\n out = out.replace(/var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*((?:[^()]|\\([^()]*\\))*))?\\)/g, (_, name: string, fallback?: string) => custom.get(name) ?? fallback?.trim() ?? '')\n }\n return out\n}\n\n/** The kept declarations an inline `style` attribute writes. */\nfunction inlineDeclarations(style: string | undefined): CssRule['decls'] {\n return style ? declarationsOf(style) : []\n}\n\n/**\n * Elements' styles over a page's structure and its sheets. Styles are\n * resolved on demand, parent first, each element once.\n */\nexport function siteImportStylesOf(structure: Pick<SiteImportStructure, 'elements' | 'root'>, css: SiteImportCss): SiteImportStyles {\n const { elements } = structure\n const resolved = new Map<number, { style: Map<string, string>; custom: Map<string, string> }>()\n // The page's root is above the body: `:root` and `html` rules are its.\n const rootStyle = (() => {\n const style = new Map<string, string>()\n const custom = new Map<string, string>()\n const fake: SiteImportElement = { id: -2, tag: 'html', parent: -1, children: [], region: 'main', nav: false, attrs: structure.root ?? {}, blocks: [] }\n const candidates = [...(css.index.get(':root') ?? []), ...(css.index.get('html') ?? []), ...(css.index.get('*') ?? [])]\n for (const name of classesOf(fake)) candidates.push(...(css.index.get(`.${name}`) ?? []))\n if (fake.attrs.id) candidates.push(...(css.index.get(`#${fake.attrs.id}`) ?? []))\n apply(candidates.filter((rule) => selectorMatches(rule.selector, fake, [], fake)), inlineDeclarations(fake.attrs.style), style, custom)\n return { style, custom, element: fake }\n })()\n\n function apply(rules: CssRule[], inline: CssRule['decls'], style: Map<string, string>, custom: Map<string, string>) {\n const unique = [...new Set(rules)].sort((a, b) => a.selector.specificity - b.selector.specificity || a.order - b.order)\n const important: Array<[string, string]> = []\n const put = (property: string, value: string) => {\n if (property.startsWith('--')) custom.set(property, value)\n else style.set(property, value)\n }\n for (const rule of unique) {\n for (const [property, value, flag] of rule.decls) {\n if (flag) important.push([property, value])\n else put(property, value)\n }\n }\n for (const [property, value, flag] of inline) {\n if (flag) important.push([property, value])\n else put(property, value)\n }\n for (const [property, value] of important) put(property, value)\n }\n\n function resolve(id: number): { style: Map<string, string>; custom: Map<string, string> } {\n const held = resolved.get(id)\n if (held) return held\n const element = elements[id]\n if (!element) return rootStyle\n const parent = element.parent >= 0 ? resolve(element.parent) : rootStyle\n const candidates: CssRule[] = [...(css.index.get(element.tag) ?? []), ...(css.index.get('*') ?? [])]\n for (const name of classesOf(element)) candidates.push(...(css.index.get(`.${name}`) ?? []))\n if (element.attrs.id) candidates.push(...(css.index.get(`#${element.attrs.id}`) ?? []))\n const matched = candidates.filter((rule) => selectorMatches(rule.selector, element, elements, rootStyle.element))\n const own = new Map<string, string>()\n const inline = inlineDeclarations(element.attrs.style)\n // A palette can be thousands of properties: only an element that declares one takes a copy of them.\n const declares = inline.some(([property]) => property.startsWith('--')) || matched.some((rule) => rule.decls.some(([property]) => property.startsWith('--')))\n const custom = declares ? new Map(parent.custom) : parent.custom\n apply(matched, inline, own, custom)\n const style = new Map<string, string>()\n for (const property of INHERITED) {\n const value = parent.style.get(property)\n if (value !== undefined) style.set(property, value)\n }\n for (const [property, value] of own) {\n const lowered = value.trim().toLowerCase()\n if (lowered === 'inherit') {\n const inherited = parent.style.get(property)\n if (inherited !== undefined) style.set(property, inherited)\n continue\n }\n if (lowered === 'initial' || lowered === 'unset' || lowered === 'revert') {\n if (!INHERITED.has(property) || lowered === 'initial') style.delete(property)\n continue\n }\n style.set(property, property === 'font-family' ? withVariables(value, custom) : withVariables(value, custom).toLowerCase())\n }\n const entry = { style, custom }\n resolved.set(id, entry)\n return entry\n }\n\n // The root's own inherited values reach the body through `rootStyle`.\n for (const [property, value] of rootStyle.style) {\n rootStyle.style.set(property, property === 'font-family' ? withVariables(value, rootStyle.custom) : withVariables(value, rootStyle.custom).toLowerCase())\n }\n return {\n root: -2,\n of(element: number): SiteImportComputedStyle {\n if (element === -2) return rootStyle.style\n return elements[element] ? resolve(element).style : EMPTY_STYLE\n },\n rootVariables() {\n return new Map([...rootStyle.custom].map(([name, value]) => [name, withVariables(value, rootStyle.custom)]))\n },\n }\n}\n\n/*------------------------------------------\n * Values\n *-----------------------------------------*/\n\nexport interface SiteImportRgba {\n r: number\n g: number\n b: number\n a: number\n}\n\nconst NAMED_COLORS: Record<string, string> = {\n white: '#ffffff',\n black: '#000000',\n red: '#ff0000',\n green: '#008000',\n blue: '#0000ff',\n gray: '#808080',\n grey: '#808080',\n silver: '#c0c0c0',\n whitesmoke: '#f5f5f5',\n ghostwhite: '#f8f8ff',\n snow: '#fffafa',\n ivory: '#fffff0',\n beige: '#f5f5dc',\n linen: '#faf0e6',\n navy: '#000080',\n teal: '#008080',\n orange: '#ffa500',\n gold: '#ffd700',\n purple: '#800080',\n crimson: '#dc143c',\n tomato: '#ff6347',\n coral: '#ff7f50',\n aliceblue: '#f0f8ff',\n lightgray: '#d3d3d3',\n lightgrey: '#d3d3d3',\n gainsboro: '#dcdcdc',\n darkslategray: '#2f4f4f',\n dimgray: '#696969',\n}\n\n/** The first color a value names, or `null`; `transparent` is a color of no strength. */\nexport function siteImportColorOf(value: string | undefined): SiteImportRgba | null {\n if (!value) return null\n const text = value.toLowerCase()\n const hex = /#([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})\\b/.exec(text)\n const rgb = /rgba?\\(\\s*(-?[\\d.]+%?)\\s*[,\\s]\\s*(-?[\\d.]+%?)\\s*[,\\s]\\s*(-?[\\d.]+%?)\\s*(?:[,/]\\s*(-?[\\d.]+%?)\\s*)?\\)/.exec(text)\n const hsl = /hsla?\\(\\s*(-?[\\d.]+)(?:deg)?\\s*[,\\s]\\s*([\\d.]+)%?\\s*[,\\s]\\s*([\\d.]+)%?\\s*(?:[,/]\\s*([\\d.]+%?)\\s*)?\\)/.exec(text)\n const named = /\\b(transparent|[a-z]+)\\b/.exec(text.replace(/[a-z-]+\\(/g, ' ('))\n const first = [hex, rgb, hsl].filter((match): match is RegExpExecArray => !!match).sort((a, b) => a.index - b.index)[0]\n const alphaOf = (raw: string | undefined) => (raw === undefined ? 1 : raw.endsWith('%') ? Number(raw.slice(0, -1)) / 100 : Number(raw))\n if (first === hex && hex) {\n const digits = hex[1]\n const full = digits.length <= 4 ? digits.split('').map((d) => d + d).join('') : digits\n return {\n r: parseInt(full.slice(0, 2), 16),\n g: parseInt(full.slice(2, 4), 16),\n b: parseInt(full.slice(4, 6), 16),\n a: full.length === 8 ? parseInt(full.slice(6, 8), 16) / 255 : 1,\n }\n }\n if (first === rgb && rgb) {\n const channel = (raw: string) => Math.max(0, Math.min(255, raw.endsWith('%') ? (Number(raw.slice(0, -1)) / 100) * 255 : Number(raw)))\n return { r: channel(rgb[1]), g: channel(rgb[2]), b: channel(rgb[3]), a: alphaOf(rgb[4]) }\n }\n if (first === hsl && hsl) {\n const h = (((Number(hsl[1]) % 360) + 360) % 360) / 360\n const s = Number(hsl[2]) / 100\n const l = Number(hsl[3]) / 100\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const tone = (t: number) => {\n const x = t < 0 ? t + 1 : t > 1 ? t - 1 : t\n if (x < 1 / 6) return p + (q - p) * 6 * x\n if (x < 1 / 2) return q\n if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6\n return p\n }\n return { r: tone(h + 1 / 3) * 255, g: tone(h) * 255, b: tone(h - 1 / 3) * 255, a: alphaOf(hsl[4]) }\n }\n if (named) {\n if (named[1] === 'transparent') return { r: 0, g: 0, b: 0, a: 0 }\n const known = NAMED_COLORS[named[1]]\n if (known) return siteImportColorOf(known)\n }\n return null\n}\n\n/** A variable's name that says it holds a brand's color. */\nconst BRAND_VARIABLE = /primary|secondary|brand|accent|highlight/i\n\n/** A custom property's whole value as a color: a color function, or the triple a color function reads through `var()`. */\nfunction colorOfVariable(value: string): SiteImportRgba | null {\n const text = value.trim()\n if (/^(?:#[0-9a-f]{3,8}|(?:rgb|hsl)a?\\([^()]*\\))$/i.test(text)) return siteImportColorOf(text)\n if (/^-?[\\d.]+(?:deg)?[\\s,]+[\\d.]+%[\\s,]+[\\d.]+%$/.test(text)) return siteImportColorOf(`hsl(${text})`)\n if (/^\\d{1,3}[\\s,]+\\d{1,3}[\\s,]+\\d{1,3}$/.test(text)) return siteImportColorOf(`rgb(${text})`)\n return null\n}\n\n/** The most colors of a palette kept. */\nconst PALETTE_COLORS = 6\n\n/**\n * The brand colors a page's root declares (AGL-4152): the custom properties\n * named for a brand that hold a color, a triple included, none too pale, dark\n * or grey to carry one, the most read first. What the page says its brand is,\n * even where nothing on this page happens to draw it.\n */\nexport function siteImportPaletteOf(styles: Pick<SiteImportStyles, 'rootVariables'>, uses: ReadonlyMap<string, number>): string[] {\n const tally = new Map<string, number>()\n for (const [name, value] of styles.rootVariables()) {\n if (!BRAND_VARIABLE.test(name)) continue\n const color = colorOfVariable(value)\n if (!color || color.a < 0.5 || siteImportSaturation(color) < 0.2) continue\n const light = siteImportLuminance(color)\n if (light < 0.01 || light > 0.9) continue\n const hex = siteImportHex(color)\n tally.set(hex, (tally.get(hex) ?? 0) + (uses.get(name) ?? 0))\n }\n return [...tally.entries()].sort((a, b) => b[1] - a[1]).slice(0, PALETTE_COLORS).map(([hex]) => hex)\n}\n\n/** `#rrggbb` of a color, its strength ignored. */\nexport function siteImportHex(color: SiteImportRgba): string {\n return `#${[color.r, color.g, color.b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\n/** Relative luminance, 0 (black) to 1 (white). */\nexport function siteImportLuminance(color: SiteImportRgba): number {\n const linear = (channel: number) => {\n const c = channel / 255\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n }\n return 0.2126 * linear(color.r) + 0.7152 * linear(color.g) + 0.0722 * linear(color.b)\n}\n\n/** How colorful a color is, 0 (grey) to 1. */\nexport function siteImportSaturation(color: SiteImportRgba): number {\n const max = Math.max(color.r, color.g, color.b) / 255\n const min = Math.min(color.r, color.g, color.b) / 255\n if (max === min) return 0\n const l = (max + min) / 2\n return (max - min) / (1 - Math.abs(2 * l - 1))\n}\n\n/** What an element draws behind itself: a color, a gradient and its colors, or a picture. */\nexport interface SiteImportBackground {\n color: SiteImportRgba | null\n gradient: SiteImportRgba[] | null\n /** A picture's address, as written. */\n image: string | null\n}\n\n/** An element's own background, from the shorthand or its parts. */\nexport function siteImportBackgroundOf(style: SiteImportComputedStyle): SiteImportBackground {\n const shorthand = style.get('background') ?? ''\n const imageValue = style.get('background-image') ?? (/(?:url|gradient)\\(/.test(shorthand) ? shorthand : '')\n const colorValue = style.get('background-color') ?? (shorthand && !/(?:url|gradient)\\(/.test(shorthand) ? shorthand : shorthand.replace(/[a-z-]*gradient\\((?:[^()]|\\([^()]*\\))*\\)|url\\([^)]*\\)/g, ' '))\n const color = siteImportColorOf(colorValue)\n let gradient: SiteImportRgba[] | null = null\n let image: string | null = null\n const gradientMatch = /gradient\\(((?:[^()]|\\([^()]*\\))*)\\)/.exec(imageValue)\n if (gradientMatch) {\n const stops: SiteImportRgba[] = []\n for (const match of gradientMatch[1].matchAll(/#[0-9a-f]{3,8}\\b|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)|\\b(?:white|black|transparent)\\b/gi)) {\n const stop = siteImportColorOf(match[0])\n if (stop) stops.push(stop)\n }\n if (stops.length) gradient = stops\n }\n const url = /url\\(\\s*([\"']?)([^\"')]+)\\1\\s*\\)/.exec(imageValue)\n if (url) image = url[2].trim()\n return { color: color && color.a > 0.02 ? color : null, gradient, image }\n}\n\n/** Whether an element draws a border on any side. */\nexport function siteImportHasBorder(style: SiteImportComputedStyle): boolean {\n const sides = ['border', 'border-top', 'border-bottom', 'border-left', 'border-right']\n for (const side of sides) {\n const value = style.get(side)\n if (!value) continue\n if (/\\bnone\\b|\\bhidden\\b/.test(value) || /^0(?:px)?$/.test(value.trim())) continue\n const color = siteImportColorOf(value) ?? siteImportColorOf(style.get('border-color'))\n if (color && color.a < 0.05) continue\n if (/\\d/.test(value) || /\\b(?:solid|dashed|dotted|double)\\b/.test(value)) {\n const width = /(-?[\\d.]+)px/.exec(value)\n if (!width || Number(width[1]) > 0) return true\n }\n }\n const width = style.get('border-width')\n const kind = style.get('border-style')\n if (kind && /\\b(?:solid|dashed|dotted|double)\\b/.test(kind) && (!width || !/^0(?:px)?$/.test(width.trim()))) return true\n return false\n}\n\n/** A side of an element's box. */\nexport type SiteImportSide = 'top' | 'right' | 'bottom' | 'left'\n\nconst SIDES: readonly SiteImportSide[] = ['top', 'right', 'bottom', 'left']\n\n/** One side's border, where it draws one: its width in px and its color as written. */\nexport interface SiteImportBorderSide {\n width: number\n color: SiteImportRgba | null\n}\n\n/**\n * The sides an element draws a border on (AGL-4138), each with its width and\n * color: a box is bordered on every side, a rule on one. The shorthand draws\n * all four; a side's own declaration, or `border-width` and `border-style`\n * by side, draw only theirs.\n */\nexport function siteImportBorderSides(style: SiteImportComputedStyle): Partial<Record<SiteImportSide, SiteImportBorderSide>> {\n const out: Partial<Record<SiteImportSide, SiteImportBorderSide>> = {}\n const shared = siteImportColorOf(style.get('border-color'))\n const drawn = (value: string | undefined): SiteImportBorderSide | null => {\n if (!value || /\\bnone\\b|\\bhidden\\b/.test(value) || /^0(?:px)?$/.test(value.trim())) return null\n const color = siteImportColorOf(value) ?? shared\n if (color && color.a < 0.05) return null\n if (!/\\d/.test(value) && !/\\b(?:solid|dashed|dotted|double)\\b/.test(value)) return null\n const width = /(-?[\\d.]+)(?:px)?(?:\\s|$)/.exec(value.replace(/#[0-9a-f]+|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)/gi, ' '))\n const px = width ? Number(width[1]) : /\\bthick\\b/.test(value) ? 5 : /\\bthin\\b/.test(value) ? 1 : 3\n return px > 0 ? { width: px, color } : null\n }\n const all = drawn(style.get('border'))\n for (const side of SIDES) {\n const own = style.get(`border-${side}`)\n const found = own !== undefined ? drawn(own) : all\n if (found) out[side] = found\n }\n // `border-width` and `border-style` by side, where no shorthand drew a side.\n const kind = style.get('border-style')\n if (!Object.keys(out).length && kind && /\\b(?:solid|dashed|dotted|double)\\b/.test(kind)) {\n const widths = (style.get('border-width') ?? '3px').trim().split(/\\s+/)\n const by = [widths[0], widths[1] ?? widths[0], widths[2] ?? widths[0], widths[3] ?? widths[1] ?? widths[0]]\n SIDES.forEach((side, at) => {\n const px = siteImportLengthPx(by[at] ?? '')\n if (px !== null && px > 0) out[side] = { width: px, color: shared }\n })\n }\n return out\n}\n\n/** A picture box's `aspect-ratio`, width over height: `16 / 9`, `1.5`, `auto 4 / 3`; `null` where it sets none. */\nexport function siteImportAspectRatio(value: string | undefined): number | null {\n const match = /(\\d*\\.?\\d+)\\s*(?:\\/\\s*(\\d*\\.?\\d+))?/.exec((value ?? '').replace(/\\bauto\\b/g, ' '))\n if (!match) return null\n const width = Number(match[1])\n const height = match[2] === undefined ? 1 : Number(match[2])\n return width > 0 && height > 0 ? width / height : null\n}\n\n/** A color as it shows over the ground it sits on, its strength blended in: `rgba(0,0,0,.6)` over white is `#666666`. */\nexport function siteImportOpaque(color: SiteImportRgba, under: SiteImportRgba | null = null): SiteImportRgba {\n const ground = under ?? { r: 255, g: 255, b: 255, a: 1 }\n const a = Math.max(0, Math.min(1, color.a))\n return { r: color.r * a + ground.r * (1 - a), g: color.g * a + ground.g * (1 - a), b: color.b * a + ground.b * (1 - a), a: 1 }\n}\n\n/** How far apart two colors look, in OKLab (0 the same, about 1 black from white). */\nexport function siteImportColorDistance(a: SiteImportRgba, b: SiteImportRgba): number {\n const lab = (color: SiteImportRgba) => {\n const linear = (channel: number) => {\n const c = channel / 255\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n }\n const [r, g, bl] = [linear(color.r), linear(color.g), linear(color.b)]\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * bl)\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * bl)\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * bl)\n return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s]\n }\n const [x, y] = [lab(a), lab(b)]\n return Math.hypot((x[0] as number) - (y[0] as number), (x[1] as number) - (y[1] as number), (x[2] as number) - (y[2] as number))\n}\n\n/** Whether an element draws a shadow. */\nexport function siteImportHasShadow(style: SiteImportComputedStyle): boolean {\n const value = style.get('box-shadow')\n return !!value && !/^(?:none|0|initial|unset)$/.test(value.trim()) && !/^0(?:px)?\\s+0(?:px)?\\s+0(?:px)?(?:\\s+0(?:px)?)?\\s+(?:transparent|rgba\\([^)]*,\\s*0\\))/.test(value.trim())\n}\n\n/** An element's corner radius in px, or `null`. */\nexport function siteImportRadiusPx(style: SiteImportComputedStyle): number | null {\n const value = style.get('border-radius')\n if (!value) return null\n const first = value.trim().split(/[\\s/]+/)[0] ?? ''\n if (first.endsWith('%')) return Number(first.slice(0, -1)) >= 50 ? 999 : Number(first.slice(0, -1))\n return siteImportLengthPx(first)\n}\n\n/** A font size in px, or `null`. */\nexport function siteImportFontSizePx(style: SiteImportComputedStyle): number | null {\n const value = style.get('font-size')\n if (!value) return null\n const clamp = /clamp\\(([^,]+),([^,]+),([^)]+)\\)/.exec(value)\n // A fluid size at the read width: its maximum, as a wide screen shows it.\n const text = clamp ? clamp[3] : value\n return siteImportLengthPx(text.trim())\n}\n\n/** The relative widths a grid template draws its columns at, or `null` for none. */\nexport function siteImportGridColumns(template: string | undefined): number[] | null {\n if (!template || /^(?:none|subgrid|masonry)$/.test(template.trim())) return null\n let text = template.trim()\n // repeat(3, 1fr) / repeat(auto-fill, minmax(240px, 1fr)): the count, or three of them.\n text = text.replace(/repeat\\(\\s*([\\w-]+)\\s*,\\s*((?:[^()]|\\([^()]*\\))*)\\)/g, (_, count: string, track: string) => {\n const times = /^\\d+$/.test(count) ? Math.min(12, Number(count)) : 3\n return Array.from({ length: times }, () => track.trim()).join(' ')\n })\n const tracks: string[] = []\n let depth = 0\n let token = ''\n for (const char of text) {\n if (char === '(') depth += 1\n if (char === ')') depth -= 1\n if (/\\s/.test(char) && depth === 0) {\n if (token) tracks.push(token)\n token = ''\n } else token += char\n }\n if (token) tracks.push(token)\n const weights = tracks\n .filter((track) => !/^\\[.*\\]$/.test(track))\n .map((track) => {\n const fr = /(-?[\\d.]+)fr\\)?$/.exec(track)\n if (fr) return Number(fr[1]) || 1\n const px = /(-?[\\d.]+)px/.exec(track)\n if (px) return Number(px[1]) / 100\n const percent = /(-?[\\d.]+)%/.exec(track)\n if (percent) return Number(percent[1]) / 10\n return 1\n })\n return weights.length ? weights : null\n}\n\n/** A template's top-level words: a track, a `repeat()` or a `[line name]`. */\nfunction gridTemplateWords(template: string): string[] {\n const words: string[] = []\n let depth = 0\n let word = ''\n for (const char of template) {\n if (char === '(' || char === '[') depth += 1\n if (char === ')' || char === ']') depth -= 1\n if (/\\s/.test(char) && depth === 0) {\n if (word) words.push(word)\n word = ''\n } else word += char\n }\n if (word) words.push(word)\n return words\n}\n\n/**\n * How many tracks a grid template draws (AGL-4152), each `repeat()` opened at\n * its whole count; `null` for none, or where the screen decides (`auto-fill`).\n */\nexport function siteImportGridTrackCount(template: string | undefined): number | null {\n const text = template?.trim() ?? ''\n if (!text || /^(?:none|subgrid|masonry|inherit|initial|unset)$/.test(text)) return null\n let count = 0\n for (const word of gridTemplateWords(text)) {\n if (word.startsWith('[')) continue\n const repeat = /^repeat\\(([\\s\\S]*)\\)$/.exec(word)\n if (!repeat) {\n count += 1\n continue\n }\n const [times, ...tracks] = splitList(repeat[1] as string)\n const inner = siteImportGridTrackCount(tracks.join(','))\n if (!/^\\d+$/.test(times ?? '') || inner === null) return null\n count += Number(times) * inner\n }\n return count || null\n}\n\n/** The cells a child of a grid covers, by grid line: `rowEnd` and `columnEnd` are the lines after its last row and column. */\nexport interface SiteImportGridBox {\n rowStart: number\n rowEnd: number\n columnStart: number\n columnEnd: number\n}\n\n/** A child's place along one axis: the line it starts at, `null` where the grid's flow decides, and how many tracks it covers. */\ninterface GridAxis {\n start: number | null\n span: number\n}\n\n/** One written line of a placement: a line number, a span, or nothing a reader can place (`auto`, a named line). */\nfunction gridLineOf(value: string | undefined, tracks: number | null): { line?: number; span?: number } {\n const text = value?.trim() ?? ''\n const span = /^span\\s+(\\d+)$/.exec(text)\n if (span) return { span: Math.max(1, Number(span[1])) }\n if (!/^-?\\d+$/.test(text)) return {}\n const line = Number(text)\n if (line > 0) return { line }\n // A line counted from the end: the last there is, where the template does not say how many.\n if (line < 0) return { line: tracks === null ? Number.POSITIVE_INFINITY : Math.max(1, tracks + 2 + line) }\n return {}\n}\n\nfunction gridAxisOf(startValue: string | undefined, endValue: string | undefined, tracks: number | null): GridAxis {\n const start = gridLineOf(startValue, tracks)\n const end = gridLineOf(endValue, tracks)\n if (start.line === Number.POSITIVE_INFINITY) return { start: null, span: 1 }\n if (start.line !== undefined && end.line !== undefined) {\n const from = Math.min(start.line, end.line)\n return { start: from, span: Math.max(1, Math.max(start.line, end.line) - from) }\n }\n if (start.line !== undefined) return { start: start.line, span: end.span ?? 1 }\n if (end.line !== undefined && end.line !== Number.POSITIVE_INFINITY) {\n const span = start.span ?? 1\n return { start: Math.max(1, end.line - span), span }\n }\n return { start: null, span: start.span ?? end.span ?? 1 }\n}\n\n/** The boxes a `grid-template-areas` names, by name. */\nfunction gridAreasOf(template: string | undefined): Map<string, SiteImportGridBox> {\n const areas = new Map<string, SiteImportGridBox>()\n const rows = [...(template ?? '').matchAll(/\"([^\"]*)\"|'([^']*)'/g)].map((match) => (match[1] ?? match[2] ?? '').trim().split(/\\s+/))\n rows.forEach((names, row) => {\n names.forEach((name, column) => {\n if (!name || /^\\.+$/.test(name)) return\n const held = areas.get(name)\n if (!held) areas.set(name, { rowStart: row + 1, rowEnd: row + 2, columnStart: column + 1, columnEnd: column + 2 })\n else {\n held.rowEnd = Math.max(held.rowEnd, row + 2)\n held.columnEnd = Math.max(held.columnEnd, column + 2)\n }\n })\n })\n return areas\n}\n\n/** A flex or grid child's `order`, 0 where it sets none. */\nexport function siteImportOrderOf(style: SiteImportComputedStyle): number {\n const order = Number.parseInt(style.get('order') ?? '', 10)\n return Number.isNaN(order) ? 0 : order\n}\n\n/**\n * Where a grid places its children (AGL-4152), each child's cells by grid\n * line, as a browser lays them out: the lines each child names (by\n * `grid-area`, a named area, `grid-row` or `grid-column`, a longhand over the\n * shorthand; lines from the end read from the template), then the children it\n * leaves to the grid's flow, in `order`, each in the first cells free.\n *\n * `null` where it cannot say, or there is nothing to say: no child names a\n * place (a `span` says how wide, and `1 / -1` the whole row, not where), the\n * rest of the children flow by columns, or through tracks the screen decides.\n */\nexport function siteImportGridBoxes(container: SiteImportComputedStyle, items: readonly SiteImportComputedStyle[]): SiteImportGridBox[] | null {\n const areas = gridAreasOf(container.get('grid-template-areas'))\n const named = [...areas.values()]\n const columns = siteImportGridTrackCount(container.get('grid-template-columns')) ?? (named.length ? Math.max(...named.map((area) => area.columnEnd)) - 1 : null)\n const rows = siteImportGridTrackCount(container.get('grid-template-rows')) ?? (named.length ? Math.max(...named.map((area) => area.rowEnd)) - 1 : null)\n const places = items.map((item) => {\n const [rowStart, columnStart, rowEnd, columnEnd] = (item.get('grid-area') ?? '').split('/').map((part) => part.trim())\n const area = rowStart && columnStart === undefined ? areas.get(rowStart) : undefined\n const row = item.get('grid-row')?.split('/') ?? [rowStart, rowEnd]\n const column = item.get('grid-column')?.split('/') ?? [columnStart, columnEnd]\n return {\n row: area ? { start: area.rowStart, span: area.rowEnd - area.rowStart } : gridAxisOf(item.get('grid-row-start') ?? row[0], item.get('grid-row-end') ?? row[1], rows),\n column: area ? { start: area.columnStart, span: area.columnEnd - area.columnStart } : gridAxisOf(item.get('grid-column-start') ?? column[0], item.get('grid-column-end') ?? column[1], columns),\n }\n })\n const wholeRow = (axis: GridAxis) => axis.start === 1 && (axis.span === Number.POSITIVE_INFINITY || (columns !== null && axis.span >= columns))\n if (!places.some((place) => place.row.start !== null || (place.column.start !== null && !wholeRow(place.column)))) return null\n const flows = places.some((place) => place.row.start === null || place.column.start === null)\n if (flows && (columns === null || /\\bcolumn\\b/.test(container.get('grid-auto-flow') ?? ''))) return null\n\n const finite = (value: number) => (Number.isFinite(value) ? value : 0)\n const lastRow = Math.max(rows === null ? 1 : rows + 1, ...places.map((place) => (place.row.start ?? 0) + finite(place.row.span)))\n const lastColumn = columns === null ? Math.max(...places.map((place) => (place.column.start ?? 0) + finite(place.column.span))) : columns + 1\n const boxes: Array<SiteImportGridBox | null> = places.map(() => null)\n const free = (row: number, column: number, height: number, width: number) =>\n boxes.every((box) => !box || box.rowEnd <= row || box.rowStart >= row + height || box.columnEnd <= column || box.columnStart >= column + width)\n const put = (at: number, row: number, column: number, height: number, width: number) => {\n boxes[at] = { rowStart: row, rowEnd: row + height, columnStart: column, columnEnd: column + width }\n }\n const heightOf = (axis: GridAxis, row: number) => (Number.isFinite(axis.span) ? axis.span : Math.max(1, lastRow - row))\n const widthOf = (axis: GridAxis, column: number) => Math.max(1, Math.min(axis.span, lastColumn - column))\n const inOrder = places.map((_, at) => at).sort((a, b) => siteImportOrderOf(items[a] as SiteImportComputedStyle) - siteImportOrderOf(items[b] as SiteImportComputedStyle) || a - b)\n // Rows and columns both named first, whatever their order: nothing flows into them.\n for (const at of inOrder) {\n const { row, column } = places[at] as (typeof places)[number]\n if (row.start !== null && column.start !== null) put(at, row.start, column.start, heightOf(row, row.start), widthOf(column, column.start))\n }\n // A row named and its column not: the first cells free in that row.\n for (const at of inOrder) {\n const { row, column } = places[at] as (typeof places)[number]\n if (row.start === null || column.start !== null) continue\n const height = heightOf(row, row.start)\n const width = widthOf(column, 1)\n let left = 1\n while (left + width < lastColumn && !free(row.start, left, height, width)) left += 1\n put(at, row.start, left, height, width)\n }\n // The rest, in the order they flow: a cursor down the grid, never back.\n let cursorRow = 1\n let cursorColumn = 1\n for (const at of inOrder) {\n if (boxes[at]) continue\n const { row, column } = places[at] as (typeof places)[number]\n const height = heightOf(row, 1)\n if (column.start !== null) {\n const width = widthOf(column, column.start)\n if (column.start < cursorColumn) cursorRow += 1\n cursorColumn = column.start\n while (!free(cursorRow, cursorColumn, height, width)) cursorRow += 1\n put(at, cursorRow, cursorColumn, height, width)\n continue\n }\n const width = widthOf(column, 1)\n while (cursorColumn + width > lastColumn || !free(cursorRow, cursorColumn, height, width)) {\n cursorColumn += 1\n if (cursorColumn + width > lastColumn) {\n cursorColumn = 1\n cursorRow += 1\n }\n }\n put(at, cursorRow, cursorColumn, height, width)\n }\n return boxes as SiteImportGridBox[]\n}\n\n/** Weights scaled to twelfths, each at least 1: `[420, 788]` is `[4, 8]`. */\nexport function siteImportTwelfths(weights: readonly number[]): number[] {\n const total = weights.reduce((sum, weight) => sum + Math.max(0, weight), 0)\n if (!total) return weights.map(() => 1)\n const scaled = weights.map((weight) => Math.max(1, Math.round((Math.max(0, weight) / total) * 12)))\n // Two equal tracks stay equal, three stay thirds.\n const unique = new Set(weights.map((weight) => Math.round(weight * 1000)))\n if (unique.size === 1) return weights.map(() => 1)\n return scaled\n}\n\n/** The families a `font-family` value names, quotes dropped, generic ones left out. */\nexport function siteImportFontFamilies(value: string | undefined): string[] {\n if (!value) return []\n return splitList(value)\n .map((family) => family.replace(/^[\"']|[\"']$/g, '').trim())\n .filter((family) => family && !/^(?:serif|sans-serif|monospace|cursive|fantasy|system-ui|ui-[\\w-]+|-apple-system|blinkmacsystemfont|inherit|initial|emoji|math|var\\(.*)$/i.test(family))\n}\n\n/*------------------------------------------\n * Reading a page's stylesheets\n *-----------------------------------------*/\n\n/**\n * How much of a page's stylesheets is read (AGL-4152). A site builder's own\n * sheet can be its fifth link and 1.3 MB, with half a megabyte more behind it,\n * and every color and font of the site is in it. So:\n *\n * - `firstLookBytes`: every link is first read this far. Most sheets end\n * inside it, and those are done; a larger one shows here whether it declares\n * `:root` custom properties, which they do at their top.\n * - `budgetBytes`: what all the page's sheets may hold together, first looks\n * included. Three times the sheet that set it, with room for what comes with\n * it. What does not fit is cut, and a cut sheet is read as far as it goes.\n * - `atOnce`: first looks asked together, so twenty links are not twenty\n * connections to one host.\n *\n * So one page's read costs at most its links' first looks and the budget:\n * 3.8 MB at the most links a page lists, however large its sheets are.\n */\nexport const SITE_IMPORT_SHEET_LIMITS = {\n firstLookBytes: 32 * 1024,\n budgetBytes: 3 * 1024 * 1024,\n atOnce: 6,\n} as const\n\n/** What a read of a stylesheet gives back. */\nexport interface SiteImportSheetAnswer {\n ok: boolean\n text: string\n /** Bytes read. */\n bytes: number\n /** Whether the sheet goes on past `maxBytes`. */\n truncated: boolean\n}\n\n/** Reads a stylesheet to a number of bytes; `null` where it cannot. */\nexport type SiteImportSheetRead = (url: string, maxBytes: number) => Promise<SiteImportSheetAnswer | null>\n\n/** Whether a sheet declares custom properties on the page's root: its theme, not a widget's. */\nconst ROOT_VARIABLES = /(?:^|[},;\\s])(?::root|html)\\b[^{}]*\\{[^{}]*--[\\w-]+\\s*:/\n\n/**\n * Every stylesheet a page links, to a byte budget (AGL-4152), in link order,\n * as the cascade needs them. Each is read a first look; then the ones that go\n * on are read whole, the ones declaring `:root` custom properties first, then\n * the rest in link order, each to what is left of the budget. A read that fails\n * leaves its sheet out, and never the page.\n */\nexport async function siteImportReadStylesheets(\n urls: readonly string[],\n read: SiteImportSheetRead,\n options: { budgetBytes?: number; outOfTime?: () => boolean } = {},\n): Promise<string[]> {\n const budget = options.budgetBytes ?? SITE_IMPORT_SHEET_LIMITS.budgetBytes\n const outOfTime = options.outOfTime ?? (() => false)\n const unique = [...new Set(urls)]\n const looks: Array<SiteImportSheetAnswer | null> = unique.map(() => null)\n const ask = (url: string, maxBytes: number) => read(url, maxBytes).then((answer) => (answer?.ok ? answer : null), () => null)\n let next = 0\n await Promise.all(\n Array.from({ length: Math.min(SITE_IMPORT_SHEET_LIMITS.atOnce, unique.length) }, async () => {\n while (next < unique.length && !outOfTime()) {\n const at = next\n next += 1\n looks[at] = await ask(unique[at] as string, SITE_IMPORT_SHEET_LIMITS.firstLookBytes)\n }\n }),\n )\n let room = budget - looks.reduce((sum, look) => sum + (look?.bytes ?? 0), 0)\n const rest = unique.map((_, at) => at).filter((at) => looks[at]?.truncated)\n const theme = (at: number) => (ROOT_VARIABLES.test((looks[at] as SiteImportSheetAnswer).text) ? 0 : 1)\n rest.sort((a, b) => theme(a) - theme(b) || a - b)\n for (const at of rest) {\n if (room <= 0 || outOfTime()) break\n const look = looks[at] as SiteImportSheetAnswer\n const whole = await ask(unique[at] as string, look.bytes + room)\n if (!whole) continue\n room -= whole.bytes - look.bytes\n looks[at] = whole\n }\n return looks.flatMap((look) => (look ? [look.text] : []))\n}\n"],"names":["SITE_IMPORT_CSS_VIEWPORT","width","height","SITE_IMPORT_CSS_WIDE_WIDTH","KEPT_PROPERTIES","Set","GRID_PLACEMENT","INHERITED","unescapeIdent","text","replace","_","escaped","test","code","parseInt","trim","String","fromCodePoint","IDENT","raw","SIMPLE","RegExp","AT_REST","parseCompound","compound","tag","id","classes","attrs","root","rest","match","exec","slice","length","toLowerCase","push","name","op","value","has","parseSelector","compounds","combinators","parts","split","pending","part","ids","tags","specificity","SELECTOR_VARIANTS","spelledOut","discount","inner","index","depth","end","head","tail","zeroed","joined","out","option","splitList","variant","start","at","char","Math","max","map","filter","Boolean","siteImportLengthPx","amount","Number","mediaQueryHolds","query","viewport","scheme","negate","startsWith","holds","term","feature","px","range","size","a","b","mediaHolds","prelude","list","some","DARK_SCOPE","withoutDarkScope","declarationsOf","body","decls","colon","indexOf","written","property","important","keyOf","selector","last","siteImportCssOf","sheets","options","css","rules","Map","fontFaces","darkRules","variableUses","order","darkGroups","addRule","includes","use","matchAll","set","get","lifted","rule","key","sheet","groups","pop","applies","every","family","placed","flatMap","join","classesOf","element","class","attributeOf","role","label","href","type","style","hidden","undefined","theme","compoundMatches","rootId","own","attr","wanted","ok","endsWith","selectorMatches","elements","above","parent","walk","combinator","siblings","children","position","before","sibling","EMPTY_STYLE","VARIABLE_DEPTH","withVariables","custom","pass","fallback","inlineDeclarations","siteImportStylesOf","structure","resolved","rootStyle","fake","region","nav","blocks","candidates","apply","inline","unique","sort","put","flag","resolve","held","matched","declares","lowered","inherited","delete","entry","of","rootVariables","NAMED_COLORS","white","black","red","green","blue","gray","grey","silver","whitesmoke","ghostwhite","snow","ivory","beige","linen","navy","teal","orange","gold","purple","crimson","tomato","coral","aliceblue","lightgray","lightgrey","gainsboro","darkslategray","dimgray","siteImportColorOf","hex","rgb","hsl","named","first","alphaOf","digits","full","d","r","g","channel","min","h","s","l","q","p","tone","t","x","known","BRAND_VARIABLE","colorOfVariable","PALETTE_COLORS","siteImportPaletteOf","styles","uses","tally","color","siteImportSaturation","light","siteImportLuminance","siteImportHex","entries","round","toString","padStart","linear","c","abs","siteImportBackgroundOf","shorthand","imageValue","colorValue","gradient","image","gradientMatch","stops","stop","url","siteImportHasBorder","sides","side","kind","SIDES","siteImportBorderSides","shared","drawn","all","found","Object","keys","widths","by","forEach","siteImportAspectRatio","siteImportOpaque","under","ground","siteImportColorDistance","lab","bl","cbrt","m","y","hypot","siteImportHasShadow","siteImportRadiusPx","siteImportFontSizePx","clamp","siteImportGridColumns","template","count","track","times","Array","from","tracks","token","weights","fr","percent","gridTemplateWords","words","word","siteImportGridTrackCount","repeat","gridLineOf","span","line","POSITIVE_INFINITY","gridAxisOf","startValue","endValue","gridAreasOf","areas","rows","names","row","column","rowStart","rowEnd","columnStart","columnEnd","siteImportOrderOf","isNaN","siteImportGridBoxes","container","items","values","columns","area","places","item","wholeRow","axis","place","flows","finite","isFinite","lastRow","lastColumn","boxes","free","box","heightOf","widthOf","inOrder","left","cursorRow","cursorColumn","siteImportTwelfths","total","reduce","sum","weight","scaled","siteImportFontFamilies","SITE_IMPORT_SHEET_LIMITS","firstLookBytes","budgetBytes","atOnce","ROOT_VARIABLES","siteImportReadStylesheets","urls","read","budget","outOfTime","looks","ask","maxBytes","then","answer","next","Promise","room","look","bytes","truncated","whole"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;2CAyB2C,GAI3C,2EAA2E,GAC3E,OAAO,MAAMA,2BAA2B;IAAEC,OAAO;IAAMC,QAAQ;AAAI,EAAU;AAE7E;;;;;CAKC,GACD,OAAO,MAAMC,6BAA6B,KAAI;AAE9C,uGAAuG,GACvG,MAAMC,kBAAkB,IAAIC,IAAI;IAC9B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kFAAkF;IAClF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,0FAA0F;IAC1F;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,6HAA6H;IAC7H;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,qHAAqH,GACrH,MAAMC,iBAAiB;AAEvB,uEAAuE,GACvE,MAAMC,YAAY,IAAIF,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