best-email-builder 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/ai-server.js +3 -3
  3. package/dist/ai.js +11 -11
  4. package/dist/ai.js.map +1 -1
  5. package/dist/builder.js +8 -8
  6. package/dist/{chunk-LKD6QZMD.js → chunk-4662C22G.js} +3 -3
  7. package/dist/{chunk-2M44NIFG.js → chunk-BMCXSP4Q.js} +2 -2
  8. package/dist/{chunk-L7NSAYYX.js → chunk-CYTZO2MW.js} +9 -5
  9. package/dist/chunk-CYTZO2MW.js.map +1 -0
  10. package/dist/{chunk-37PEEEBB.js → chunk-GUF6MIXZ.js} +2 -2
  11. package/dist/{chunk-BER25JS7.js → chunk-HWNNYG45.js} +20 -3
  12. package/dist/{chunk-BER25JS7.js.map → chunk-HWNNYG45.js.map} +1 -1
  13. package/dist/{chunk-D46HKFV5.js → chunk-K43QP3TX.js} +14 -13
  14. package/dist/chunk-K43QP3TX.js.map +1 -0
  15. package/dist/{chunk-POUAC5TN.js → chunk-LJXCMXYI.js} +2 -2
  16. package/dist/{chunk-2B3N6CH4.js → chunk-MW3ZGK34.js} +13 -1
  17. package/dist/chunk-MW3ZGK34.js.map +1 -0
  18. package/dist/{chunk-F3566ZQB.js → chunk-NSNODUL6.js} +3 -3
  19. package/dist/{chunk-JLQDVA4B.js → chunk-UR3UTVC5.js} +4 -4
  20. package/dist/{chunk-W4UKDEB4.js → chunk-WYYATB37.js} +511 -372
  21. package/dist/chunk-WYYATB37.js.map +1 -0
  22. package/dist/index.js +10 -10
  23. package/dist/library.js +5 -5
  24. package/dist/server.js +5 -5
  25. package/dist/styles.css +1 -1
  26. package/dist/types/blocks/shared.d.ts +1 -1
  27. package/dist/types/core/EmailEditor.d.ts +8 -4
  28. package/dist/types/core/constants.d.ts +1 -1
  29. package/dist/types/engine/NativeAdapter.d.ts +1 -1
  30. package/dist/types/engine/canvasMjml.d.ts +7 -0
  31. package/dist/types/features/variables/VariableInsertButton.d.ts +7 -3
  32. package/dist/types/ui/TextRibbon.d.ts +26 -1
  33. package/dist/types/ui/fields.d.ts +13 -0
  34. package/dist/types/ui/primitives/color-picker.d.ts +4 -2
  35. package/dist/types/ui/primitives/fields.d.ts +4 -3
  36. package/dist/types/ui/primitives/overlays.d.ts +3 -3
  37. package/package.json +1 -1
  38. package/dist/chunk-2B3N6CH4.js.map +0 -1
  39. package/dist/chunk-D46HKFV5.js.map +0 -1
  40. package/dist/chunk-L7NSAYYX.js.map +0 -1
  41. package/dist/chunk-W4UKDEB4.js.map +0 -1
  42. /package/dist/{chunk-LKD6QZMD.js.map → chunk-4662C22G.js.map} +0 -0
  43. /package/dist/{chunk-2M44NIFG.js.map → chunk-BMCXSP4Q.js.map} +0 -0
  44. /package/dist/{chunk-37PEEEBB.js.map → chunk-GUF6MIXZ.js.map} +0 -0
  45. /package/dist/{chunk-POUAC5TN.js.map → chunk-LJXCMXYI.js.map} +0 -0
  46. /package/dist/{chunk-F3566ZQB.js.map → chunk-NSNODUL6.js.map} +0 -0
  47. /package/dist/{chunk-JLQDVA4B.js.map → chunk-UR3UTVC5.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/renderer/prepareMjml.js","../src/core/mjmlAttributes.js","../src/core/mjmlDefaults.js","../src/features/brand/extract.js","../src/features/brand/messages.js","../src/renderer/columnAlignment.js","../src/renderer/compileEditorMjml.js"],"sourcesContent":["// @ts-check\n/**\n * Prepares MJML before compilation — shared by the server preview, the test\n * send and saving.\n *\n * The subject and the preview text (preheader) are METADATA of the template,\n * typed outside the canvas: they do not live in the engine project. They are\n * written here, into `<mj-head>`, at compile time:\n *\n * `<mj-title>` document title (browser tab, some webmails);\n * `<mj-preview>` the grey text that follows the subject in the inbox.\n *\n * `lang` is set when missing: otherwise screen readers read the message with\n * the voice of the system language.\n *\n * An image with no picture yet (`src` empty or missing — the canvas shows a\n * grey frame, AI drafts leave them for the user) is left out: sent, it would\n * be a broken image in every inbox (a red cross in Outlook). A preview keeps\n * it (`emptyImages: 'keep'`) to draw the frame that is still to fill.\n */\n\n/** An `<mj-image>` element, self-closing or not; its attributes in group 1. */\nconst MJ_IMAGE = /<mj-image\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)\\s*(?:\\/>|>\\s*<\\/mj-image\\s*>)/gi;\nconst HAS_SRC = /\\ssrc\\s*=\\s*(?:\"\\s*[^\"\\s][^\"]*\"|'\\s*[^'\\s][^']*')/i;\n\n/**\n * How many images have no picture yet.\n * @param {string} mjml\n */\nexport function countImagesWithoutPicture(mjml) {\n return [...String(mjml || '').matchAll(MJ_IMAGE)].filter(([, attrs]) => !HAS_SRC.test(attrs)).length;\n}\n\nfunction escapeXml(text) {\n return String(text ?? '')\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\n/**\n * @param {string} mjml\n * @param {{title?: string|null, preheader?: string|null, lang?: string, emptyImages?: 'drop'|'keep'}} [meta]\n * @returns {string}\n */\nexport function prepareMjml(mjml, { title = null, preheader = null, lang = 'en', emptyImages = 'drop' } = {}) {\n let out = String(mjml || '')\n .replace(/<mj-title(?:\\s[^>]*)?>[\\s\\S]*?<\\/mj-title>/gi, '')\n .replace(/<mj-preview(?:\\s[^>]*)?>[\\s\\S]*?<\\/mj-preview>/gi, '');\n if (emptyImages !== 'keep') out = out.replace(MJ_IMAGE, (element, attrs) => (HAS_SRC.test(attrs) ? element : ''));\n\n out = out.replace(/<mjml(\\s[^>]*)?>/i, (tag, attrs = '') =>\n /\\slang\\s*=/.test(attrs) ? tag : `<mjml lang=\"${escapeXml(lang)}\"${attrs}>`\n );\n\n const head = [\n title && String(title).trim() ? `<mj-title>${escapeXml(String(title).trim())}</mj-title>` : '',\n preheader && String(preheader).trim() ? `<mj-preview>${escapeXml(String(preheader).trim())}</mj-preview>` : '',\n ].join('');\n if (!head) return out;\n\n if (/<mj-head(\\s[^>]*)?>/i.test(out)) {\n return out.replace(/<mj-head(\\s[^>]*)?>/i, (tag) => `${tag}${head}`);\n }\n return out.replace(/<mjml(\\s[^>]*)?>/i, (tag) => `${tag}<mj-head>${head}</mj-head>`);\n}\n","// @ts-check\n/**\n * MJML attributes — reading and writing properties panel values.\n *\n * This is knowledge of the LANGUAGE (MJML), not of the engine: it lives in\n * the core, and every adapter benefits from it.\n *\n * ── PADDING IS WRITTEN IN LONGHAND ─────────────────────────────────────────\n * An MJML element carries both `padding` and `padding-top/-right/-bottom/\n * -left`, and the longhand wins. The canvas, starting from the defaults\n * (`padding-top=\"10px\"`…), ignored a `padding=\"40px 60px\"` that the sent\n * email did apply: the screen lied. So `padding` is always written as four\n * attributes, and read back the same way.\n *\n * `inner-padding` (button) has no longhand in MJML: it stays as is.\n *\n * ── A BORDER IS ONE VALUE IN THE PANEL ──────────────────────────────────────\n * The panel edits a border as one value: one to four widths, a line style, a\n * color (\"2px 0px dashed #cccccc\"). Written, it becomes `border` when the four\n * sides are the same, `border-top`… otherwise; read, both come back as one.\n *\n * ── NO QUOTES IN A VALUE ───────────────────────────────────────────────────\n * The engine export writes attributes unescaped: a `\"` in a value would break\n * the MJML. Double quotes, angle brackets and line breaks are stripped on\n * write.\n */\n\n/** Spacing attributes that have a longhand form in MJML. */\nexport const LONGHAND_SPACING = new Set(['padding']);\n\nexport const SIDES = /** @type {const} */ (['top', 'right', 'bottom', 'left']);\n\n/** Border attributes edited as one value: `border` and its four sides. */\nexport const LONGHAND_BORDER = new Set(['border']);\n\n/** The line styles offered: CSS's, which the email clients draw (a dot-dash line is not one of them). */\nexport const BORDER_STYLES = /** @type {const} */ (['solid', 'dashed', 'dotted', 'double', 'groove', 'ridge']);\n\n/** The widest border written, in pixels. */\nexport const MAX_BORDER = 20;\n\n/** Every CSS line style, to read what an email already has. */\nconst LINE_STYLES = new Set([...BORDER_STYLES, 'inset', 'outset', 'none', 'hidden']);\n/** CSS's width keywords, in pixels as browsers draw them. */\nconst WIDTH_KEYWORDS = { thin: 1, medium: 3, thick: 5 };\n\n/**\n * @typedef {{widths: [number, number, number, number], style: string, color: string}} Border\n * `widths`: in pixels, top, right, bottom, left; `color`: '' for the text's.\n */\n\n/**\n * A CSS border (\"2px dashed #cccccc\", in any order) or the panel's form, with\n * up to four widths (\"2px 0px dashed #cccccc\"). No border (`none`, `0`, no\n * style, nothing): null. Without a width, CSS's `medium` (3 px).\n * @param {string|null|undefined} value\n * @returns {Border|null}\n */\nexport function parseBorder(value) {\n const tokens = String(value || '').trim().match(/[^\\s(]+\\([^)]*\\)|\\S+/g) || [];\n /** @type {number[]} */\n const widths = [];\n let style = '';\n const color = [];\n for (const token of tokens) {\n const word = token.toLowerCase();\n if (/^(\\d+\\.?\\d*|\\.\\d+)(px)?$/.test(word)) widths.push(Number.parseFloat(word));\n else if (word in WIDTH_KEYWORDS) widths.push(WIDTH_KEYWORDS[/** @type {keyof typeof WIDTH_KEYWORDS} */ (word)]);\n else if (LINE_STYLES.has(word)) style = word;\n else color.push(token);\n }\n if (!style || style === 'none' || style === 'hidden') return null;\n const [t = 3, r = t, b = t, l = r] = widths.slice(0, 4).map((width) => Math.max(0, Math.min(MAX_BORDER, Math.round(width))));\n if (!t && !r && !b && !l) return null;\n return { widths: [t, r, b, l], style, color: color.join(' ') };\n}\n\n/**\n * The panel's form of a border: its widths in their shortest form, its style,\n * its color. No border: ''.\n * @param {Border|null} border\n */\nexport function formatBorder(border) {\n if (!border || border.widths.every((width) => !width)) return '';\n return [formatSpacing(border.widths.map((width) => `${width}px`)), border.style, border.color].filter(Boolean).join(' ');\n}\n\n/** One side's (or the four sides') CSS border. @param {Border} border @param {number} width */\nconst borderLine = (border, width) => [`${width}px`, border.style, border.color].filter(Boolean).join(' ');\n\n/**\n * \"10px 25px\" → ['10px', '25px', '10px', '25px'] (CSS 1-to-4 value rule).\n * @param {string|null|undefined} value\n * @returns {[string, string, string, string]}\n */\nexport function parseSpacing(value) {\n const parts = String(value || '')\n .trim()\n .split(/\\s+/)\n .filter(Boolean);\n const [a = '0px', b = a, c = a, d = b] = parts;\n return [a, b, c, d];\n}\n\n/**\n * Shortest form of a four-sided spacing.\n * @param {string[]} sides\n */\nexport function formatSpacing(sides) {\n const [t, r, b, l] = sides.map((s) => String(s || '0px'));\n if (t === b && r === l) return t === r ? t : `${t} ${r}`;\n if (r === l) return `${t} ${r} ${b}`;\n return `${t} ${r} ${b} ${l}`;\n}\n\n/** Attribute value safe for an unescaped export. @param {unknown} value */\nexport function cleanAttributeValue(value) {\n return String(value ?? '')\n .replace(/[\"<>\\r\\n]/g, '')\n .trim();\n}\n\n/**\n * Entered values → MJML attributes to set (`null` = attribute to remove).\n *\n * @param {Record<string, string|null|undefined>} values\n * @returns {Record<string, string|null>}\n */\nexport function toAttributes(values) {\n /** @type {Record<string, string|null>} */\n const out = {};\n for (const [key, raw] of Object.entries(values || {})) {\n const value = raw === null || raw === undefined ? '' : cleanAttributeValue(raw);\n if (LONGHAND_SPACING.has(key)) {\n const sides = value ? parseSpacing(value) : null;\n SIDES.forEach((side, i) => {\n out[`${key}-${side}`] = sides ? sides[i] : null;\n });\n out[key] = null;\n } else if (LONGHAND_BORDER.has(key)) {\n const border = parseBorder(value);\n const same = border && border.widths.every((width) => width === border.widths[0]);\n out[key] = border && same ? borderLine(border, border.widths[0]) : null;\n SIDES.forEach((side, i) => {\n out[`${key}-${side}`] = border && !same && border.widths[i] ? borderLine(border, border.widths[i]) : null;\n });\n } else {\n out[key] = value || null;\n }\n }\n return out;\n}\n\n/**\n * Element attributes → a block's property values.\n *\n * @param {Record<string, unknown>} attributes\n * @param {{key: string}[]} properties\n * @returns {Record<string, string>}\n */\nexport function toValues(attributes, properties) {\n /** @type {Record<string, string>} */\n const values = {};\n for (const { key } of properties) {\n if (LONGHAND_SPACING.has(key)) {\n const base = parseSpacing(String(attributes[key] ?? ''));\n const sides = SIDES.map((side, i) => {\n const v = attributes[`${key}-${side}`];\n return v === undefined || v === null || v === '' ? base[i] : String(v);\n });\n const hasAny = attributes[key] || SIDES.some((side) => attributes[`${key}-${side}`]);\n values[key] = hasAny ? formatSpacing(sides) : '';\n } else if (LONGHAND_BORDER.has(key)) {\n const base = parseBorder(String(attributes[key] ?? ''));\n // A side written on its own wins over `border` (`none` included).\n const sides = SIDES.map((side) => {\n const v = attributes[`${key}-${side}`];\n return v === undefined || v === null || v === '' ? undefined : parseBorder(String(v));\n });\n const line = base || sides.find(Boolean);\n const widths = /** @type {Border['widths']} */ (SIDES.map((_, i) => (sides[i] === undefined ? base?.widths[i] ?? 0 : sides[i]?.widths[0] ?? 0)));\n values[key] = line ? formatBorder({ ...line, widths }) : '';\n } else {\n const v = attributes[key];\n values[key] = v === undefined || v === null ? '' : String(v);\n }\n }\n return values;\n}\n","// @ts-check\n/**\n * MJML DEFAULTS — what MJML 5 renders when an attribute is not written.\n *\n * The properties panel shows them, greyed, in empty fields: an empty\n * \"Padding\" of a section is not \"0\" — MJML gives it 20 px above and below,\n * and the panel must say so (and start from there when one side is edited).\n *\n * Copied from the `defaultAttributes` of the mjml 5 components (the same\n * version the server and the canvas compile with); the unit tests check them\n * against the installed components.\n */\n\n/** @type {Record<string, Record<string, string>>} */\nexport const MJML_DEFAULTS = {\n 'mj-body': { width: '600px' },\n 'mj-section': {\n 'background-repeat': 'repeat',\n 'background-size': 'auto',\n 'background-position': 'top center',\n padding: '20px 0',\n 'text-align': 'center',\n },\n 'mj-wrapper': { 'background-repeat': 'repeat', 'background-size': 'auto', 'background-position': 'top center', padding: '20px 0' },\n 'mj-column': { 'vertical-align': 'top' },\n 'mj-text': {\n align: 'left',\n color: '#000000',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'line-height': '1',\n padding: '10px 25px',\n },\n 'mj-image': { align: 'center', height: 'auto', padding: '10px 25px' },\n 'mj-button': {\n align: 'center',\n 'background-color': '#414141',\n 'border-radius': '3px',\n color: '#ffffff',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'font-weight': 'normal',\n 'inner-padding': '10px 25px',\n 'line-height': '120%',\n padding: '10px 25px',\n },\n 'mj-divider': { 'border-color': '#000000', 'border-style': 'solid', 'border-width': '4px', padding: '10px 25px', width: '100%', align: 'center' },\n 'mj-spacer': { height: '20px' },\n 'mj-social': {\n align: 'center',\n 'border-radius': '3px',\n 'icon-size': '20px',\n mode: 'horizontal',\n padding: '10px 25px',\n },\n 'mj-social-element': { 'border-radius': '3px', padding: '4px' },\n 'mj-navbar': { align: 'center' },\n 'mj-navbar-link': {\n color: '#000000',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'font-weight': 'normal',\n 'line-height': '22px',\n padding: '15px 10px',\n 'text-transform': 'uppercase',\n },\n 'mj-hero': { 'background-color': '#ffffff', padding: '0px' },\n};\n","// @ts-check\n/**\n * BRAND FROM A WEBSITE — what a company's home page says about its look:\n * its name, where its logo is, its main color, the color of its headings\n * and its font.\n *\n * Pure text work on what the server downloaded (src/server/brandImport.js\n * does the downloading, with its safety rules): no network, no DOM, so it\n * runs anywhere and is tested on fixtures.\n *\n * name og:site_name → JSON-LD Organization → application-name → the\n * part of <title> that matches the domain → the domain;\n * logo JSON-LD Organization logo → an <img> called \"logo\" (header\n * first) → apple-touch-icon; SVG and WebP are skipped later\n * (most email apps do not show them);\n * colors counted in the CSS, weighted by where they are used (buttons,\n * links, custom properties named primary/brand/accent, the\n * theme-color meta); grays, alert and social colors set aside;\n * font the body's, mapped to the nearest web-safe stack.\n */\n\nimport { FONT_OPTIONS, PALETTE } from '../../blocks/shared.js';\nimport { contrastRatio, parseColor, toHex, toHsl } from './brand.js';\n\n/**\n * @typedef {{\n * name: string,\n * logos: {url: string, from: 'schema'|'img'|'icon'}[],\n * stylesheets: string[],\n * css: string,\n * themeColor: string,\n * }} PageReading\n */\n\n/* ── HTML ───────────────────────────────────────────────────────────────── */\n\n/** @param {string} text */\nfunction decodeEntities(text) {\n return String(text ?? '')\n .replace(/&#x([0-9a-f]+);/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))\n .replace(/&#(\\d+);/g, (_, dec) => String.fromCodePoint(Number(dec)))\n .replace(/&quot;/g, '\"')\n .replace(/&#39;|&apos;/g, \"'\")\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&nbsp;/g, ' ')\n .replace(/&amp;/g, '&');\n}\n\n/**\n * The attributes of one start tag, names in lower case.\n * @param {string} tag `<img src=\"…\" class=logo>`\n * @returns {Record<string, string>}\n */\nexport function tagAttributes(tag) {\n /** @type {Record<string, string>} */\n const attributes = {};\n const inner = tag.replace(/^<[^\\s>/]+/, '').replace(/\\/?>$/, '');\n const pattern = /([^\\s\"'=<>/]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n let match;\n while ((match = pattern.exec(inner))) {\n const name = match[1].toLowerCase();\n if (!(name in attributes)) attributes[name] = decodeEntities(match[2] ?? match[3] ?? match[4] ?? '');\n }\n return attributes;\n}\n\n/** @param {string} html @param {string} name */\nconst startTags = (html, name) => html.match(new RegExp(`<${name}\\\\b[^>]*>`, 'gi')) || [];\n\n/** An http(s) address, resolved against the page; '' otherwise. @param {string|undefined} href @param {string} base */\nfunction resolve(href, base) {\n const value = String(href ?? '').trim();\n if (!value || /^(data|javascript|blob):/i.test(value)) return '';\n try {\n const url = new URL(value, base);\n return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : '';\n } catch {\n return '';\n }\n}\n\n/** The largest image of a srcset (\"a.png 1x, a@2x.png 2x\"). @param {string} srcset */\nfunction largestOf(srcset) {\n let best = { url: '', size: 0 };\n for (const part of srcset.split(/,\\s+/)) {\n const [url, descriptor = '1x'] = part.trim().split(/\\s+/);\n const size = parseFloat(descriptor) * (descriptor.endsWith('w') ? 1 : 1000);\n if (url && size > best.size) best = { url, size };\n }\n return best.url;\n}\n\n/** Objects of a JSON-LD script, flattened (@graph, arrays). @param {unknown} value @returns {any[]} */\nfunction jsonLdNodes(value) {\n if (Array.isArray(value)) return value.flatMap(jsonLdNodes);\n if (!value || typeof value !== 'object') return [];\n const node = /** @type {any} */ (value);\n return [node, ...jsonLdNodes(node['@graph']), ...jsonLdNodes(node.publisher), ...jsonLdNodes(node.brand)];\n}\n\nconst ORGANIZATION = /organization|corporation|business|brand|store|restaurant|company|ngo|school|airline|bank|agency/i;\n\n/** The words of a host name that name the company: \"www.acme-corp.co.uk\" → \"acme corp\". @param {string} host */\nfunction hostWords(host) {\n const labels = host.toLowerCase().replace(/^www\\d?\\./, '').split('.');\n const main = labels.length > 2 && labels[labels.length - 2].length <= 3 ? labels[labels.length - 3] : labels[0];\n return main.replace(/[-_]+/g, ' ');\n}\n\n/** @param {string} text */\nconst squash = (text) => text.toLowerCase().replace(/[^a-z0-9À-￿]+/g, '');\n\n/** @param {unknown} value */\nconst cleanName = (value) =>\n decodeEntities(String(value ?? ''))\n .replace(/\\s+/g, ' ')\n .trim()\n .slice(0, 80);\n\n/**\n * What a home page says about its brand.\n * @param {string} html\n * @param {string} pageUrl the address it was read from (after redirects)\n * @returns {PageReading}\n */\nexport function readPage(html, pageUrl) {\n const source = String(html ?? '');\n const head = source.slice(0, 400_000);\n const baseTag = startTags(head, 'base').map(tagAttributes).find((a) => a.href);\n const base = resolve(baseTag?.href, pageUrl) || pageUrl;\n const host = (() => {\n try {\n return new URL(pageUrl).hostname;\n } catch {\n return '';\n }\n })();\n\n /** @type {Record<string, string>} */\n const meta = {};\n for (const attributes of startTags(head, 'meta').map(tagAttributes)) {\n const key = (attributes.property || attributes.name || '').toLowerCase();\n if (key && attributes.content && !(key in meta)) meta[key] = attributes.content;\n }\n\n // JSON-LD: the organization's own name and logo, when the site states them.\n let schemaName = '';\n let schemaLogo = '';\n for (const [, body] of source.matchAll(/<script\\b[^>]*type\\s*=\\s*[\"']?application\\/ld\\+json[^>]*>([\\s\\S]*?)<\\/script>/gi)) {\n let data;\n try {\n data = JSON.parse(body.trim());\n } catch {\n continue;\n }\n for (const node of jsonLdNodes(data)) {\n const types = [].concat(node['@type'] || []).join(' ');\n if (!ORGANIZATION.test(types)) continue;\n if (!schemaName && typeof node.name === 'string') schemaName = node.name;\n const logo = typeof node.logo === 'string' ? node.logo : node.logo?.url || node.logo?.contentUrl || '';\n if (!schemaLogo && typeof logo === 'string') schemaLogo = resolve(logo, base);\n }\n }\n\n /* Name */\n const title = cleanName(head.match(/<title\\b[^>]*>([\\s\\S]*?)<\\/title>/i)?.[1] || '');\n const words = hostWords(host);\n const fromTitle =\n title\n .split(/\\s+[|–—:·•»-]\\s+/)\n .map((part) => part.trim())\n .find((part) => part && squash(part).length <= 40 && (squash(part).includes(squash(words)) || squash(words).includes(squash(part)))) || '';\n const fromHost = words.replace(/\\b\\p{L}/gu, (letter) => letter.toUpperCase());\n const name = cleanName(meta['og:site_name'] || schemaName || meta['application-name'] || fromTitle || fromHost);\n\n /* Logo candidates, best first */\n /** @type {PageReading['logos']} */\n const logos = [];\n const add = (/** @type {string} */ url, /** @type {PageReading['logos'][number]['from']} */ from) => {\n if (url && !logos.some((logo) => logo.url === url)) logos.push({ url, from });\n };\n add(schemaLogo, 'schema');\n /** @type {{url: string, score: number}[]} */\n const images = [];\n const headerEnd = (() => {\n const at = source.search(/<\\/header>/i);\n return at > 0 ? at : Math.min(source.length, 20_000);\n })();\n for (const match of source.matchAll(/<img\\b[^>]*>/gi)) {\n const attributes = tagAttributes(match[0]);\n const own = [attributes.class, attributes.id, attributes.alt, attributes.src, attributes['data-src']].join(' ').toLowerCase();\n const before = source.slice(Math.max(0, (match.index ?? 0) - 400), match.index).toLowerCase();\n const parent = /<(a|div|span|figure|picture)\\b[^>]*(class|id)\\s*=\\s*[\"'][^\"']*logo[^\"']*[\"'][^>]*>[^<]*(<source\\b[^>]*>\\s*)*$/i.test(before);\n if (!own.includes('logo') && !parent) continue;\n // Partner, client and payment logos are someone else's.\n if (/partner|client|customer|sponsor|award|payment|badge|trust|press|app-?store|google-?play/.test(own)) continue;\n const url = resolve(attributes.srcset ? largestOf(attributes.srcset) : attributes.src || attributes['data-src'] || '', base);\n if (!url) continue;\n let score = own.includes('logo') ? 3 : 2;\n if ((match.index ?? 0) < headerEnd) score += 3;\n if (name && squash(attributes.alt || '').includes(squash(name))) score += 2;\n if (/footer/.test(own)) score -= 2;\n images.push({ url, score: score - images.length * 0.01 });\n }\n images.sort((a, b) => b.score - a.score).forEach((image) => add(image.url, 'img'));\n /** @type {{url: string, size: number}[]} */\n const icons = [];\n for (const attributes of startTags(head, 'link').map(tagAttributes)) {\n const rel = (attributes.rel || '').toLowerCase();\n if (!/apple-touch-icon|icon/.test(rel)) continue;\n const size = parseInt(attributes.sizes || (rel.includes('apple') ? '180' : '0'), 10) || 0;\n if (size >= 96) icons.push({ url: resolve(attributes.href, base), size });\n }\n icons.sort((a, b) => b.size - a.size).forEach((icon) => add(icon.url, 'icon'));\n\n /* Styles */\n const stylesheets = startTags(head, 'link')\n .map(tagAttributes)\n .filter((a) => /(^|\\s)stylesheet(\\s|$)/i.test(a.rel || '') && !/^print$/i.test((a.media || '').trim()))\n .map((a) => resolve(a.href, base))\n .filter(Boolean)\n // Fonts and third-party widgets say nothing about the brand's colors.\n .filter((href) => !/fonts\\.googleapis|use\\.typekit|fontawesome|cookie|consent|onetrust/i.test(href));\n const css = [\n ...[...source.matchAll(/<style\\b[^>]*>([\\s\\S]*?)<\\/style>/gi)].map((m) => m[1]),\n // Inline styles of buttons and links count too: `<a class=\"btn\" style=\"…\">`.\n ...[...source.matchAll(/<(a|button)\\b[^>]*>/gi)]\n .map((m) => tagAttributes(m[0]))\n .filter((a) => a.style)\n .map((a) => `${/btn|button|cta/i.test(a.class || '') ? '.btn' : 'a'}{${a.style}}`),\n ].join('\\n');\n\n return {\n name,\n logos,\n stylesheets: [...new Set(stylesheets)],\n css,\n themeColor: meta['theme-color'] || meta['msapplication-tilecolor'] || '',\n };\n}\n\n/* ── CSS ────────────────────────────────────────────────────────────────── */\n\nconst PRIMARY_NAME = /primary|brand|accent|main|theme|highlight|cta/i;\nconst NOT_A_BRAND_NAME = /text|foreground|fg|border|muted|gr[ae]y|neutral|surface|shadow|overlay|success|error|danger|warning|info|disabled|placeholder/i;\nconst NOISE = /error|danger|success|warning|alert|invalid|valid\\b|notice|toast|badge|disabled|facebook|twitter|linkedin|instagram|youtube|whatsapp|pinterest|tiktok|social|cookie|consent|onetrust|ot-|cmp|gdpr|wp-block|has-[\\w-]+-(background-)?color|syntax|hljs|code/i;\nconst COLOR_IN_VALUE = /#[0-9a-f]{3,8}\\b|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)/gi;\nconst COLOR_PROPERTY = /^(color|background|background-color|border|border-color|border-(top|bottom|left|right)(-color)?|fill|stroke|outline(-color)?|text-decoration-color|accent-color|caret-color)$/;\n\n/** @param {string} css */\nconst stripComments = (css) => css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n\n/** Rules as [selector, declarations], @media flattened. @param {string} css */\nfunction rulesOf(css) {\n /** @type {[string, [string, string][]][]} */\n const rules = [];\n for (const [, selector, body] of stripComments(css).matchAll(/([^{}]+)\\{([^{}]*)\\}/g)) {\n const declarations = body\n .split(';')\n .map((part) => {\n const colon = part.indexOf(':');\n return /** @type {[string, string]} */ ([part.slice(0, colon).trim().toLowerCase(), part.slice(colon + 1).trim()]);\n })\n .filter(([property, value]) => property && value);\n if (declarations.length) rules.push([selector.trim(), declarations]);\n }\n return rules;\n}\n\n/**\n * A custom property's value as a color: `#2977bc`, `rgb(…)`, and the bare\n * channels design systems keep there (`41 119 188`, `210 64% 45%`).\n * @param {string} value\n */\nfunction customColor(value) {\n const direct = parseColor(value.replace(/\\s*!important$/, ''));\n if (direct) return direct;\n if (/^\\d{1,3}(\\.\\d+)?\\s+\\d{1,3}(\\.\\d+)?\\s+\\d{1,3}(\\.\\d+)?$/.test(value)) return parseColor(`rgb(${value})`);\n if (/^\\d{1,3}(\\.\\d+)?(deg)?\\s+\\d{1,3}(\\.\\d+)?%\\s+\\d{1,3}(\\.\\d+)?%$/.test(value)) return parseColor(`hsl(${value.replace('deg', '')})`);\n return null;\n}\n\n/**\n * `var(--x, fallback)` replaced by what --x holds, a few levels deep.\n * @param {string} value @param {Map<string, string>} custom\n */\nfunction resolveVars(value, custom) {\n let out = value;\n for (let depth = 0; depth < 4 && out.includes('var('); depth += 1) {\n out = out.replace(/var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*([^()]*(?:\\([^()]*\\))?[^()]*))?\\)/g, (_, name, fallback) => custom.get(name) ?? fallback ?? '');\n }\n return out;\n}\n\n/** @param {{r: number, g: number, b: number}} a @param {{r: number, g: number, b: number}} b */\nconst distance = (a, b) => Math.hypot(a.r - b.r, a.g - b.g, a.b - b.b);\n\n/** Colors of one value, as found (not resolved through var()). @param {string} value */\nconst colorsIn = (value) => (value.match(COLOR_IN_VALUE) || []).map((text) => parseColor(text)).filter((c) => c && c.a >= 0.6);\n\n/**\n * The web-safe stack nearest to a CSS font-family.\n * @param {string} family\n * @returns {string|undefined}\n */\nexport function nearestFont(family) {\n const stack = String(family ?? '')\n .toLowerCase()\n .replace(/[\"']/g, '');\n if (!stack.trim() || /^(inherit|initial|unset|revert)$/.test(stack.trim())) return undefined;\n const first = stack.split(',')[0].trim();\n const known = FONT_OPTIONS.find((option) => first.startsWith(option.label.toLowerCase()));\n if (known) return known.value;\n if (/^helvetica/.test(first)) return FONT_OPTIONS[0].value;\n if (/^times/.test(first)) return FONT_OPTIONS.find((o) => o.label === 'Times')?.value;\n if (/monospace|mono\\b|courier|consolas/.test(stack)) return FONT_OPTIONS.find((o) => o.label === 'Courier')?.value;\n // Web fonts: their family decides (serif, else sans-serif).\n if (/(^|,)\\s*serif\\s*(,|$)|garamond|playfair|merriweather|lora|baskerville|caslon|didot|bodoni|crimson|libre baskerville|source serif|noto serif|pt serif/.test(stack)) {\n return FONT_OPTIONS.find((o) => o.label === 'Georgia')?.value;\n }\n return FONT_OPTIONS[0].value;\n}\n\n/**\n * Main color, headings color and font of a site, from its CSS.\n * @param {{css: string, themeColor?: string}} input\n * @returns {{primary?: string, heading?: string, font?: string}}\n */\nexport function brandFromCss({ css, themeColor = '' }) {\n const rules = rulesOf(String(css ?? ''));\n\n /** @type {Map<string, string>} */\n const custom = new Map();\n for (const [selector, declarations] of rules) {\n // :root first: a theme's dark variant must not replace it.\n const root = /^(:root|html|body|\\*)(\\s*,|$)/i.test(selector);\n for (const [property, value] of declarations) {\n if (property.startsWith('--') && (root || !custom.has(property))) custom.set(property, value.replace(/\\s*!important$/, ''));\n }\n }\n\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const found = [];\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const darkText = [];\n /** @type {{font: string, weight: number}[]} */\n const fonts = [];\n const count = (/** @type {{r: number, g: number, b: number}} */ color, /** @type {number} */ weight) => found.push({ color, weight });\n\n for (const [selector, declarations] of rules) {\n if (selector.startsWith('@')) continue;\n const noise = NOISE.test(selector);\n const emphasis = /btn|button|cta|primary|brand|accent|hero|highlight/i.test(selector) ? 4 : /(^|[\\s,>+~])a([:.[\\s,]|$)|link/i.test(selector) ? 2 : 1;\n const isHeading = /(^|[\\s,>])h[1-3]\\b|title|heading|headline/i.test(selector);\n const isBody = /^(html|body|:root)(\\s*,|$)|(^|,)\\s*(html|body)\\s*(,|$)/i.test(selector);\n for (const [property, raw] of declarations) {\n if (property.startsWith('--')) {\n const color = customColor(resolveVars(raw, custom));\n if (color && color.a >= 0.6 && PRIMARY_NAME.test(property) && !NOT_A_BRAND_NAME.test(property)) count(color, 10);\n continue;\n }\n const value = resolveVars(raw, custom);\n if (property === 'font-family' || property === 'font') {\n const family = property === 'font' ? value.replace(/^.*?\\d[\\w%.]*(\\/[\\w%.]+)?\\s+/, '') : value;\n if (isBody || isHeading) fonts.push({ font: family, weight: isBody ? 2 : 1 });\n continue;\n }\n if (!COLOR_PROPERTY.test(property) || noise) continue;\n for (const color of colorsIn(value)) {\n if (!color) continue;\n count(color, emphasis * (property.startsWith('background') ? 1.5 : 1));\n if (property === 'color' && (isHeading || isBody)) darkText.push({ color, weight: isHeading ? 2 : 1 });\n }\n }\n }\n const theme = parseColor(themeColor);\n if (theme && theme.a >= 0.6) count(theme, 15);\n\n // Near colors are one color (hover shades, rounding).\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const clusters = [];\n for (const entry of found) {\n const near = clusters.find((cluster) => distance(cluster.color, entry.color) < 24);\n if (near) near.weight += entry.weight;\n else clusters.push({ ...entry });\n }\n clusters.sort((a, b) => b.weight - a.weight);\n const primary = clusters.find(({ color }) => {\n const { s, l } = toHsl(color);\n return s >= 0.25 && l >= 0.15 && l <= 0.85;\n });\n\n /** @type {{primary?: string, heading?: string, font?: string}} */\n const result = {};\n if (primary) result.primary = toHex(primary.color);\n\n const dark = darkText\n .filter(({ color }) => toHsl(color).l < 0.3)\n .reduce((/** @type {Map<string, number>} */ map, { color, weight }) => map.set(toHex(color), (map.get(toHex(color)) || 0) + weight), new Map());\n const heading = [...dark.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];\n if (heading) result.heading = heading;\n else if (result.primary && contrastRatio(result.primary, PALETTE.white) >= 7) result.heading = result.primary;\n else result.heading = PALETTE.ink;\n\n const font = fonts.sort((a, b) => b.weight - a.weight).map(({ font }) => nearestFont(font)).find(Boolean);\n if (font) result.font = font;\n return result;\n}\n\n/* ── Images ─────────────────────────────────────────────────────────────── */\n\n/**\n * Width and height of a PNG, GIF or JPEG, from its header; null otherwise.\n * @param {Uint8Array} bytes\n * @returns {{width: number, height: number}|null}\n */\nexport function imageSize(bytes) {\n if (!bytes || bytes.length < 24) return null;\n const at = (/** @type {number} */ i) => bytes[i];\n // PNG: IHDR right after the signature.\n if (at(0) === 0x89 && at(1) === 0x50 && at(2) === 0x4e && at(3) === 0x47) {\n const read32 = (/** @type {number} */ i) => ((at(i) << 24) | (at(i + 1) << 16) | (at(i + 2) << 8) | at(i + 3)) >>> 0;\n return { width: read32(16), height: read32(20) };\n }\n // GIF: logical screen size.\n if (at(0) === 0x47 && at(1) === 0x49 && at(2) === 0x46) {\n return { width: at(6) | (at(7) << 8), height: at(8) | (at(9) << 8) };\n }\n // JPEG: the first start-of-frame marker.\n if (at(0) === 0xff && at(1) === 0xd8) {\n let i = 2;\n while (i + 9 < bytes.length) {\n if (at(i) !== 0xff) {\n i += 1;\n continue;\n }\n const marker = at(i + 1);\n if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0xff) {\n i += marker === 0xff ? 1 : 2;\n continue;\n }\n const length = (at(i + 2) << 8) | at(i + 3);\n if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {\n return { height: (at(i + 5) << 8) | at(i + 6), width: (at(i + 7) << 8) | at(i + 8) };\n }\n i += 2 + length;\n }\n }\n return null;\n}\n\n/**\n * The width a logo is shown at in an email: a wordmark wider, a square mark\n * smaller; never wider than the image itself (a blurry logo is worse than a\n * small one). Retina images (twice the size shown) are common: halved first.\n * @param {{width: number, height: number}} size\n */\nexport function logoWidthFor({ width, height }) {\n if (!width || !height) return 140;\n const ratio = width / height;\n const shown = width >= 240 ? width / 2 : width;\n const target = ratio >= 2.5 ? 180 : ratio >= 1.3 ? 140 : 72;\n return Math.max(24, Math.round(Math.min(target, shown)));\n}\n","// @ts-check\n/**\n * What the user is told about reading a brand from a website: why it failed\n * (the server's answer) and what it could not find (notes under the field).\n * English source strings, translated where they are shown.\n */\n\n/**\n * Why a website could not be read: [HTTP status, message], by\n * BrandImportError code (src/server/brandImport.js).\n * @type {Record<string, [number, string]>}\n */\nexport const BRAND_IMPORT_ERRORS = {\n BAD_URL: [400, 'Enter the address of a website, like acme.com'],\n PRIVATE_ADDRESS: [400, 'This address is not a public website'],\n UNREACHABLE: [422, 'The website could not be reached. Check the address.'],\n TIMEOUT: [422, 'The website took too long to answer'],\n HTTP_ERROR: [422, 'The website does not let the builder read it. Fill in your brand below.'],\n NOT_HTML: [422, 'This address is not a web page'],\n TOO_MANY_REDIRECTS: [422, 'The website redirects too many times'],\n TOO_LARGE: [422, 'The website sent too much data'],\n};\n\n/** What could not be read, by note code. @type {Record<string, string>} */\nexport const BRAND_NOTES = {\n LOGO_NOT_FOUND: 'No logo was found on the website. Upload it below.',\n LOGO_UNSUPPORTED: 'The logo on the website is an SVG or WebP image, which most email apps do not show. Upload a PNG or JPEG version.',\n LOGO_ICON: 'The website icon is used as the logo. Upload your full logo if you have one.',\n COLORS_NOT_FOUND: 'No main color was found on the website. Pick one below.',\n};\n","// @ts-check\nimport { parseMjml, serializeMjml } from '../engine/mjml.js';\nimport { createNode, findFirst, walk } from '../engine/model.js';\n\n/**\n * MJML uses inline blocks outside Outlook. They have independent heights,\n * and mixed middle/top alignment uses a text baseline instead of the row.\n * Use equal-height table cells for every desktop row with multiple columns.\n * Outlook keeps MJML's native conditional table. Mobile stacking is unchanged.\n * This runs inside the compiler, after validation, so callers cannot supply\n * arbitrary raw HTML or CSS through the document.\n * @param {string} source\n */\nexport function prepareColumnAlignment(source) {\n if ((source.match(/<mj-(?:column|group)\\b/g) || []).length < 2 || source.includes('eb-va-row')) return source;\n const root = parseMjml(source);\n let changed = false;\n const backgrounds = [];\n let count = 0;\n walk(root, (node) => {\n if (!['mj-section', 'mj-group'].includes(node.tag)) return;\n const columns = node.children.filter((child) => child.tag === 'mj-column' || child.tag === 'mj-group');\n if (columns.length < 2) return;\n changed = true;\n for (const column of columns) {\n column.attributes['css-class'] = `${column.attributes['css-class'] || ''} eb-va-col`.trim();\n const color = column.attributes['background-color'] || '';\n if (/^(?:#[\\da-f]{3,8}|[a-z]+|rgba?\\([\\d\\s.,%]+\\)|hsla?\\([\\d\\s.,%]+\\))$/i.test(color) && !column.attributes['css-class'].includes('eb-render-box-')) {\n const marker = `eb-va-bg-${count++}`;\n column.attributes['css-class'] += ` ${marker}`;\n backgrounds.push(`.${marker} {background-color:${color};}`);\n }\n }\n node.children = [\n createNode('mj-raw', { content: '<!--[if !mso]><!--><div class=\"eb-va-row\"><!--<![endif]-->' }),\n ...node.children,\n createNode('mj-raw', { content: '<!--[if !mso]><!--></div><!--<![endif]-->' }),\n ];\n });\n if (!changed) return source;\n let head = findFirst(root, 'mj-head');\n if (!head) {\n head = createNode('mj-head');\n root.children.unshift(head);\n }\n const width = findFirst(head, 'mj-breakpoint')?.attributes.width || '';\n const breakpoint = /^\\d+(?:\\.\\d+)?px$/.test(width) ? width : '480px';\n head.children.push(createNode('mj-style', { content:\n `@media only screen and (min-width:${breakpoint}) {` +\n '.eb-va-row {display:table;width:100%;table-layout:fixed;}' +\n '.eb-va-row > .eb-va-col {display:table-cell!important;}' +\n '}' }));\n if (backgrounds.length) head.children.push(createNode('mj-style', { attributes: { inline: 'inline' }, content: backgrounds.join('') }));\n return serializeMjml(root);\n}\n","// @ts-check\nimport { parseMjml, serializeMjml, encodeAttribute } from '../engine/mjml.js';\nimport { boxKeys } from '../core/blockBox.js';\nimport { walk } from '../engine/model.js';\nimport { toValues, parseBorder, parseSpacing } from '../core/mjmlAttributes.js';\nimport { MJML_DEFAULTS } from '../core/mjmlDefaults.js';\nimport { prepareColumnAlignment } from './columnAlignment.js';\n\n/** Only lengths may become outside or inside spacing. @param {string} value */\nconst spacing = (value) => parseSpacing(value || '0px').map((part) => {\n const number = Number.parseFloat(part);\n return Number.isFinite(number) && number >= 0 ? `${number}${part.endsWith('%') ? '%' : 'px'}` : '0px';\n}).join(' ');\n\n/** @param {string} value */\nfunction borderStyle(value) {\n const border = parseBorder(value);\n if (!border) return 'border:0;';\n // A border color cannot add declarations, external resources or markup.\n const color = /^(?:#[\\da-f]{3,8}|[a-z]+|rgba?\\([\\d\\s.,%]+\\)|hsla?\\([\\d\\s.,%]+\\))$/i.test(border.color) ? border.color : '#cbd5e1';\n return `border-width:${border.widths.map((width) => `${width}px`).join(' ')};border-style:${border.style};border-color:${color};`;\n}\n\n/** Prepare model-only box controls without sending unsupported attributes to MJML. @param {string} source */\nfunction prepareBoxes(source) {\n /** @type {{marker: string, margin: string, padding: string, border: string, gutter: boolean}[]} */\n const boxes = [];\n if (!/(?:eb-box-[a-f0-9]+|\\bbox-(?:padding|border)\\s*=|\\bmargin\\s*=)/.test(source)) return { mjml: source, boxes };\n const root = parseMjml(source);\n walk(root, (node) => {\n if (node.tag === 'mj-section' || !Object.keys(node.attributes).some((key) => key === 'margin' || key.startsWith('box-'))) return;\n const keys = boxKeys(node.tag);\n const properties = Object.values(keys).map((key) => ({ key }));\n const values = toValues({ ...MJML_DEFAULTS[node.tag], ...node.attributes }, properties);\n const marker = `eb-render-box-${boxes.length}`;\n const margin = spacing(values[keys.margin]);\n const padding = spacing(values[keys.padding]);\n const widths = parseBorder(values[keys.border])?.widths || [0, 0, 0, 0];\n const contextPadding = parseSpacing(margin).map((side, index) => Number.parseFloat(side) + Number.parseFloat(parseSpacing(padding)[index]) + widths[index]);\n boxes.push({ marker, margin, padding, border: borderStyle(values[keys.border]), gutter: node.tag === 'mj-column' && contextPadding.some(Boolean) });\n for (const key of Object.values(keys)) {\n delete node.attributes[key];\n for (const side of ['top', 'right', 'bottom', 'left']) delete node.attributes[`${key}-${side}`];\n }\n // Suppress MJML's default padding: the email table below now supplies it.\n node.attributes.padding = '0px';\n // MJML also uses padding to calculate fixed image widths for Outlook.\n // Reserve the actual box width during compilation, then replace its\n // gutter with the independent layers below.\n if (node.tag === 'mj-image' || node.tag === 'mj-column') node.attributes.padding = contextPadding.map((side) => `${side}px`).join(' ');\n node.attributes['css-class'] = `${node.attributes['css-class'] || ''} ${marker}`.trim();\n });\n return { mjml: boxes.length ? serializeMjml(root) : source, boxes };\n}\n\n/** Find the complete marked element without counting Outlook's conditional HTML as DOM. @param {string} html @param {string} marker */\nfunction markedElement(html, marker) {\n const tokens = /<!--[\\s\\S]*?-->|<\\/?([a-z][\\w:-]*)\\b(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/gi;\n let start = -1;\n let tag = '';\n let opening = '';\n let depth = 0;\n for (const token of html.matchAll(tokens)) {\n if (!token[1]) continue;\n const closing = token[0].startsWith('</');\n if (start < 0) {\n const classes = /\\bclass=\"([^\"]*)\"/.exec(token[0])?.[1].split(/\\s+/) || [];\n if (closing || !classes.includes(marker)) continue;\n start = token.index;\n tag = token[1].toLowerCase();\n opening = token[0];\n depth = 1;\n } else if (token[1].toLowerCase() === tag) {\n depth += closing ? -1 : 1;\n if (!depth) return { start, end: token.index + token[0].length, opening, tag, inner: html.slice(start + opening.length, token.index), closing: token[0] };\n }\n }\n return null;\n}\n\nconst table = (inner) => `<table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"width:100%;border-collapse:separate;\"><tbody><tr>${inner}</tr></tbody></table>`;\n\n/** @param {string} opening @param {string} style */\nfunction styled(opening, style) {\n const safe = encodeAttribute(style);\n return /\\bstyle=\"/.test(opening) ? opening.replace(/\\bstyle=\"([^\"]*)\"/, (_, previous) => `style=\"${previous};${safe}\"`) : opening.replace(/>$/, ` style=\"${safe}\">`);\n}\n\n/** Compile both native MJML and the editor's independent box controls. @param {string} source @param {(source: string, options: any) => any} compile @param {any} [options] */\nexport async function compileEditorMjml(source, compile, options = {}) {\n const prepared = prepareBoxes(source);\n const result = await compile(prepareColumnAlignment(prepared.mjml), options);\n let html = String(result.html || '');\n // Children first: outer wrappers retain every nested canvas marker.\n for (const box of prepared.boxes.reverse()) {\n const element = markedElement(html, box.marker);\n if (!element) continue;\n const inside = `padding:${box.padding};${box.border}`;\n let replacement;\n if (element.tag === 'td') {\n const original = styled(element.opening, inside) + element.inner + element.closing;\n replacement = `<td style=\"padding:${box.margin};font-size:0;\">${table(original)}</td>`;\n } else if (element.tag === 'a') {\n replacement = `<span style=\"display:inline-block;padding:${box.margin};\"><span style=\"display:inline-block;${inside}\">${element.opening}${element.inner}${element.closing}</span></span>`;\n } else {\n const inner = box.gutter ? element.inner.replace(/<td\\b(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/i, (opening) => styled(opening, 'padding:0;')) : element.inner;\n replacement = element.opening + table(`<td style=\"padding:${box.margin};\">${table(`<td style=\"${inside}\">${inner}</td>`)}</td>`) + element.closing;\n }\n html = html.slice(0, element.start) + replacement + html.slice(element.end);\n }\n return { ...result, html };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsBA,IAAM,WAAW;AACjB,IAAM,UAAU;AAMT,SAAS,0BAA0B,MAAM;AAC9C,SAAO,CAAC,GAAG,OAAO,QAAQ,EAAE,EAAE,SAAS,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,EAAE;AAChG;AAEA,SAAS,UAAU,MAAM;AACvB,SAAO,OAAO,QAAQ,EAAE,EACrB,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ;AAC3B;AAOO,SAAS,YAAY,MAAM,EAAE,QAAQ,MAAM,YAAY,MAAM,OAAO,MAAM,cAAc,OAAO,IAAI,CAAC,GAAG;AAC5G,MAAI,MAAM,OAAO,QAAQ,EAAE,EACxB,QAAQ,gDAAgD,EAAE,EAC1D,QAAQ,oDAAoD,EAAE;AACjE,MAAI,gBAAgB,OAAQ,OAAM,IAAI,QAAQ,UAAU,CAAC,SAAS,UAAW,QAAQ,KAAK,KAAK,IAAI,UAAU,EAAG;AAEhH,QAAM,IAAI;AAAA,IAAQ;AAAA,IAAqB,CAAC,KAAK,QAAQ,OACnD,aAAa,KAAK,KAAK,IAAI,MAAM,eAAe,UAAU,IAAI,CAAC,IAAI,KAAK;AAAA,EAC1E;AAEA,QAAM,OAAO;AAAA,IACX,SAAS,OAAO,KAAK,EAAE,KAAK,IAAI,aAAa,UAAU,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,gBAAgB;AAAA,IAC5F,aAAa,O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K,KAAK,OAAO,CAAC,OAAO,IAAI,QAAQ;AAAA,IAC7I;AACA,WAAO,KAAK,MAAM,GAAG,QAAQ,KAAK,IAAI,cAAc,KAAK,MAAM,QAAQ,GAAG;AAAA,EAC5E;AACA,SAAO,EAAE,GAAG,QAAQ,KAAK;AAC3B;","names":["font"]}
1
+ {"version":3,"sources":["../src/renderer/prepareMjml.js","../src/core/mjmlAttributes.js","../src/core/mjmlDefaults.js","../src/features/brand/extract.js","../src/features/brand/messages.js","../src/renderer/columnAlignment.js","../src/renderer/compileEditorMjml.js"],"sourcesContent":["// @ts-check\n/**\n * Prepares MJML before compilation — shared by the server preview, the test\n * send and saving.\n *\n * The subject and the preview text (preheader) are METADATA of the template,\n * typed outside the canvas: they do not live in the engine project. They are\n * written here, into `<mj-head>`, at compile time:\n *\n * `<mj-title>` document title (browser tab, some webmails);\n * `<mj-preview>` the grey text that follows the subject in the inbox.\n *\n * `lang` is set when missing: otherwise screen readers read the message with\n * the voice of the system language.\n *\n * An image with no picture yet (`src` empty or missing — the canvas shows a\n * grey frame, AI drafts leave them for the user) is left out: sent, it would\n * be a broken image in every inbox (a red cross in Outlook). A preview keeps\n * it (`emptyImages: 'keep'`) to draw the frame that is still to fill.\n */\n\n/** An `<mj-image>` element, self-closing or not; its attributes in group 1. */\nconst MJ_IMAGE = /<mj-image\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)\\s*(?:\\/>|>\\s*<\\/mj-image\\s*>)/gi;\nconst HAS_SRC = /\\ssrc\\s*=\\s*(?:\"\\s*[^\"\\s][^\"]*\"|'\\s*[^'\\s][^']*')/i;\n\n/**\n * How many images have no picture yet.\n * @param {string} mjml\n */\nexport function countImagesWithoutPicture(mjml) {\n return [...String(mjml || '').matchAll(MJ_IMAGE)].filter(([, attrs]) => !HAS_SRC.test(attrs)).length;\n}\n\nfunction escapeXml(text) {\n return String(text ?? '')\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\n/**\n * @param {string} mjml\n * @param {{title?: string|null, preheader?: string|null, lang?: string, emptyImages?: 'drop'|'keep'}} [meta]\n * @returns {string}\n */\nexport function prepareMjml(mjml, { title = null, preheader = null, lang = 'en', emptyImages = 'drop' } = {}) {\n let out = String(mjml || '')\n .replace(/<mj-title(?:\\s[^>]*)?>[\\s\\S]*?<\\/mj-title>/gi, '')\n .replace(/<mj-preview(?:\\s[^>]*)?>[\\s\\S]*?<\\/mj-preview>/gi, '');\n if (emptyImages !== 'keep') out = out.replace(MJ_IMAGE, (element, attrs) => (HAS_SRC.test(attrs) ? element : ''));\n\n out = out.replace(/<mjml(\\s[^>]*)?>/i, (tag, attrs = '') =>\n /\\slang\\s*=/.test(attrs) ? tag : `<mjml lang=\"${escapeXml(lang)}\"${attrs}>`\n );\n\n const head = [\n title && String(title).trim() ? `<mj-title>${escapeXml(String(title).trim())}</mj-title>` : '',\n preheader && String(preheader).trim() ? `<mj-preview>${escapeXml(String(preheader).trim())}</mj-preview>` : '',\n ].join('');\n if (!head) return out;\n\n if (/<mj-head(\\s[^>]*)?>/i.test(out)) {\n return out.replace(/<mj-head(\\s[^>]*)?>/i, (tag) => `${tag}${head}`);\n }\n return out.replace(/<mjml(\\s[^>]*)?>/i, (tag) => `${tag}<mj-head>${head}</mj-head>`);\n}\n","// @ts-check\n/**\n * MJML attributes — reading and writing properties panel values.\n *\n * This is knowledge of the LANGUAGE (MJML), not of the engine: it lives in\n * the core, and every adapter benefits from it.\n *\n * ── PADDING IS WRITTEN IN LONGHAND ─────────────────────────────────────────\n * An MJML element carries both `padding` and `padding-top/-right/-bottom/\n * -left`, and the longhand wins. The canvas, starting from the defaults\n * (`padding-top=\"10px\"`…), ignored a `padding=\"40px 60px\"` that the sent\n * email did apply: the screen lied. So `padding` is always written as four\n * attributes, and read back the same way.\n *\n * `inner-padding` (button) has no longhand in MJML: it stays as is.\n *\n * ── A BORDER IS ONE VALUE IN THE PANEL ──────────────────────────────────────\n * The panel edits a border as one value: one to four widths, a line style, a\n * color (\"2px 0px dashed #cccccc\"). Written, it becomes `border` when the four\n * sides are the same, `border-top`… otherwise; read, both come back as one.\n *\n * ── NO QUOTES IN A VALUE ───────────────────────────────────────────────────\n * The engine export writes attributes unescaped: a `\"` in a value would break\n * the MJML. Double quotes, angle brackets and line breaks are stripped on\n * write.\n */\n\n/** Spacing attributes that have a longhand form in MJML. */\nexport const LONGHAND_SPACING = new Set(['padding']);\n\nexport const SIDES = /** @type {const} */ (['top', 'right', 'bottom', 'left']);\n\n/** Border attributes edited as one value: `border` and its four sides. */\nexport const LONGHAND_BORDER = new Set(['border']);\n\n/** The line styles offered: CSS's, which the email clients draw (a dot-dash line is not one of them). */\nexport const BORDER_STYLES = /** @type {const} */ (['solid', 'dashed', 'dotted', 'double', 'groove', 'ridge']);\n\n/** The widest border written, in pixels. */\nexport const MAX_BORDER = 20;\n\n/** Every CSS line style, to read what an email already has. */\nconst LINE_STYLES = new Set([...BORDER_STYLES, 'inset', 'outset', 'none', 'hidden']);\n/** CSS's width keywords, in pixels as browsers draw them. */\nconst WIDTH_KEYWORDS = { thin: 1, medium: 3, thick: 5 };\n\n/**\n * @typedef {{widths: [number, number, number, number], style: string, color: string}} Border\n * `widths`: in pixels, top, right, bottom, left; `color`: '' for the text's.\n */\n\n/**\n * A CSS border (\"2px dashed #cccccc\", in any order) or the panel's form, with\n * up to four widths (\"2px 0px dashed #cccccc\"). No border (`none`, `0`, no\n * style, nothing): null. Without a width, CSS's `medium` (3 px).\n * @param {string|null|undefined} value\n * @returns {Border|null}\n */\nexport function parseBorder(value) {\n const tokens = String(value || '').trim().match(/[^\\s(]+\\([^)]*\\)|\\S+/g) || [];\n /** @type {number[]} */\n const widths = [];\n let style = '';\n const color = [];\n for (const token of tokens) {\n const word = token.toLowerCase();\n if (/^(\\d+\\.?\\d*|\\.\\d+)(px)?$/.test(word)) widths.push(Number.parseFloat(word));\n else if (word in WIDTH_KEYWORDS) widths.push(WIDTH_KEYWORDS[/** @type {keyof typeof WIDTH_KEYWORDS} */ (word)]);\n else if (LINE_STYLES.has(word)) style = word;\n else color.push(token);\n }\n if (!style || style === 'none' || style === 'hidden') return null;\n const [t = 3, r = t, b = t, l = r] = widths.slice(0, 4).map((width) => Math.max(0, Math.min(MAX_BORDER, Math.round(width))));\n if (!t && !r && !b && !l) return null;\n return { widths: [t, r, b, l], style, color: color.join(' ') };\n}\n\n/**\n * The panel's form of a border: its widths in their shortest form, its style,\n * its color. No border: ''.\n * @param {Border|null} border\n */\nexport function formatBorder(border) {\n if (!border || border.widths.every((width) => !width)) return '';\n return [formatSpacing(border.widths.map((width) => `${width}px`)), border.style, border.color].filter(Boolean).join(' ');\n}\n\n/** One side's (or the four sides') CSS border. @param {Border} border @param {number} width */\nconst borderLine = (border, width) => [`${width}px`, border.style, border.color].filter(Boolean).join(' ');\n\n/**\n * \"10px 25px\" → ['10px', '25px', '10px', '25px'] (CSS 1-to-4 value rule).\n * @param {string|null|undefined} value\n * @returns {[string, string, string, string]}\n */\nexport function parseSpacing(value) {\n const parts = String(value || '')\n .trim()\n .split(/\\s+/)\n .filter(Boolean);\n const [a = '0px', b = a, c = a, d = b] = parts;\n return [a, b, c, d];\n}\n\n/**\n * Shortest form of a four-sided spacing.\n * @param {string[]} sides\n */\nexport function formatSpacing(sides) {\n const [t, r, b, l] = sides.map((s) => String(s || '0px'));\n if (t === b && r === l) return t === r ? t : `${t} ${r}`;\n if (r === l) return `${t} ${r} ${b}`;\n return `${t} ${r} ${b} ${l}`;\n}\n\n/** Attribute value safe for an unescaped export. @param {unknown} value */\nexport function cleanAttributeValue(value) {\n return String(value ?? '')\n .replace(/[\"<>\\r\\n]/g, '')\n .trim();\n}\n\n/**\n * Entered values → MJML attributes to set (`null` = attribute to remove).\n *\n * @param {Record<string, string|null|undefined>} values\n * @returns {Record<string, string|null>}\n */\nexport function toAttributes(values) {\n /** @type {Record<string, string|null>} */\n const out = {};\n for (const [key, raw] of Object.entries(values || {})) {\n const value = raw === null || raw === undefined ? '' : cleanAttributeValue(raw);\n if (LONGHAND_SPACING.has(key)) {\n const sides = value ? parseSpacing(value) : null;\n SIDES.forEach((side, i) => {\n out[`${key}-${side}`] = sides ? sides[i] : null;\n });\n out[key] = null;\n } else if (LONGHAND_BORDER.has(key)) {\n const border = parseBorder(value);\n const same = border && border.widths.every((width) => width === border.widths[0]);\n out[key] = border && same ? borderLine(border, border.widths[0]) : null;\n SIDES.forEach((side, i) => {\n out[`${key}-${side}`] = border && !same && border.widths[i] ? borderLine(border, border.widths[i]) : null;\n });\n } else {\n out[key] = value || null;\n }\n }\n return out;\n}\n\n/**\n * Element attributes → a block's property values.\n *\n * @param {Record<string, unknown>} attributes\n * @param {{key: string}[]} properties\n * @returns {Record<string, string>}\n */\nexport function toValues(attributes, properties) {\n /** @type {Record<string, string>} */\n const values = {};\n for (const { key } of properties) {\n if (LONGHAND_SPACING.has(key)) {\n const base = parseSpacing(String(attributes[key] ?? ''));\n const sides = SIDES.map((side, i) => {\n const v = attributes[`${key}-${side}`];\n return v === undefined || v === null || v === '' ? base[i] : String(v);\n });\n const hasAny = attributes[key] || SIDES.some((side) => attributes[`${key}-${side}`]);\n values[key] = hasAny ? formatSpacing(sides) : '';\n } else if (LONGHAND_BORDER.has(key)) {\n const base = parseBorder(String(attributes[key] ?? ''));\n // A side written on its own wins over `border` (`none` included).\n const sides = SIDES.map((side) => {\n const v = attributes[`${key}-${side}`];\n return v === undefined || v === null || v === '' ? undefined : parseBorder(String(v));\n });\n const line = base || sides.find(Boolean);\n const widths = /** @type {Border['widths']} */ (SIDES.map((_, i) => (sides[i] === undefined ? base?.widths[i] ?? 0 : sides[i]?.widths[0] ?? 0)));\n values[key] = line ? formatBorder({ ...line, widths }) : '';\n } else {\n const v = attributes[key];\n values[key] = v === undefined || v === null ? '' : String(v);\n }\n }\n return values;\n}\n","// @ts-check\n/**\n * MJML DEFAULTS — what MJML 5 renders when an attribute is not written.\n *\n * The properties panel shows them, greyed, in empty fields: an empty\n * \"Padding\" of a section is not \"0\" — MJML gives it 20 px above and below,\n * and the panel must say so (and start from there when one side is edited).\n *\n * Copied from the `defaultAttributes` of the mjml 5 components (the same\n * version the server and the canvas compile with); the unit tests check them\n * against the installed components.\n */\n\n/** @type {Record<string, Record<string, string>>} */\nexport const MJML_DEFAULTS = {\n 'mj-body': { width: '600px' },\n 'mj-section': {\n 'background-repeat': 'repeat',\n 'background-size': 'auto',\n 'background-position': 'top center',\n padding: '20px 0',\n 'text-align': 'center',\n },\n 'mj-wrapper': { 'background-repeat': 'repeat', 'background-size': 'auto', 'background-position': 'top center', padding: '20px 0' },\n 'mj-column': { 'vertical-align': 'top' },\n 'mj-text': {\n align: 'left',\n color: '#000000',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'line-height': '1',\n padding: '10px 25px',\n },\n 'mj-image': { align: 'center', height: 'auto', padding: '10px 25px' },\n 'mj-button': {\n align: 'center',\n 'background-color': '#414141',\n 'border-radius': '3px',\n color: '#ffffff',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'font-weight': 'normal',\n 'inner-padding': '10px 25px',\n 'line-height': '120%',\n padding: '10px 25px',\n },\n 'mj-divider': { 'border-color': '#000000', 'border-style': 'solid', 'border-width': '4px', padding: '10px 25px', width: '100%', align: 'center' },\n 'mj-spacer': { height: '20px' },\n 'mj-social': {\n align: 'center',\n 'border-radius': '3px',\n 'icon-size': '20px',\n mode: 'horizontal',\n padding: '10px 25px',\n },\n 'mj-social-element': { 'border-radius': '3px', padding: '4px' },\n 'mj-navbar': { align: 'center' },\n 'mj-navbar-link': {\n color: '#000000',\n 'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',\n 'font-size': '13px',\n 'font-weight': 'normal',\n 'line-height': '22px',\n padding: '15px 10px',\n 'text-transform': 'uppercase',\n },\n 'mj-hero': { 'background-color': '#ffffff', padding: '0px' },\n};\n","// @ts-check\n/**\n * BRAND FROM A WEBSITE — what a company's home page says about its look:\n * its name, where its logo is, its main color, the color of its headings\n * and its font.\n *\n * Pure text work on what the server downloaded (src/server/brandImport.js\n * does the downloading, with its safety rules): no network, no DOM, so it\n * runs anywhere and is tested on fixtures.\n *\n * name og:site_name → JSON-LD Organization → application-name → the\n * part of <title> that matches the domain → the domain;\n * logo JSON-LD Organization logo → an <img> called \"logo\" (header\n * first) → apple-touch-icon; SVG and WebP are skipped later\n * (most email apps do not show them);\n * colors counted in the CSS, weighted by where they are used (buttons,\n * links, custom properties named primary/brand/accent, the\n * theme-color meta); grays, alert and social colors set aside;\n * font the body's, mapped to the nearest web-safe stack.\n */\n\nimport { FONT_OPTIONS, PALETTE } from '../../blocks/shared.js';\nimport { contrastRatio, parseColor, toHex, toHsl } from './brand.js';\n\n/**\n * @typedef {{\n * name: string,\n * logos: {url: string, from: 'schema'|'img'|'icon'}[],\n * stylesheets: string[],\n * css: string,\n * themeColor: string,\n * }} PageReading\n */\n\n/* ── HTML ───────────────────────────────────────────────────────────────── */\n\n/** @param {string} text */\nfunction decodeEntities(text) {\n return String(text ?? '')\n .replace(/&#x([0-9a-f]+);/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))\n .replace(/&#(\\d+);/g, (_, dec) => String.fromCodePoint(Number(dec)))\n .replace(/&quot;/g, '\"')\n .replace(/&#39;|&apos;/g, \"'\")\n .replace(/&lt;/g, '<')\n .replace(/&gt;/g, '>')\n .replace(/&nbsp;/g, ' ')\n .replace(/&amp;/g, '&');\n}\n\n/**\n * The attributes of one start tag, names in lower case.\n * @param {string} tag `<img src=\"…\" class=logo>`\n * @returns {Record<string, string>}\n */\nexport function tagAttributes(tag) {\n /** @type {Record<string, string>} */\n const attributes = {};\n const inner = tag.replace(/^<[^\\s>/]+/, '').replace(/\\/?>$/, '');\n const pattern = /([^\\s\"'=<>/]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n let match;\n while ((match = pattern.exec(inner))) {\n const name = match[1].toLowerCase();\n if (!(name in attributes)) attributes[name] = decodeEntities(match[2] ?? match[3] ?? match[4] ?? '');\n }\n return attributes;\n}\n\n/** @param {string} html @param {string} name */\nconst startTags = (html, name) => html.match(new RegExp(`<${name}\\\\b[^>]*>`, 'gi')) || [];\n\n/** An http(s) address, resolved against the page; '' otherwise. @param {string|undefined} href @param {string} base */\nfunction resolve(href, base) {\n const value = String(href ?? '').trim();\n if (!value || /^(data|javascript|blob):/i.test(value)) return '';\n try {\n const url = new URL(value, base);\n return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : '';\n } catch {\n return '';\n }\n}\n\n/** The largest image of a srcset (\"a.png 1x, a@2x.png 2x\"). @param {string} srcset */\nfunction largestOf(srcset) {\n let best = { url: '', size: 0 };\n for (const part of srcset.split(/,\\s+/)) {\n const [url, descriptor = '1x'] = part.trim().split(/\\s+/);\n const size = parseFloat(descriptor) * (descriptor.endsWith('w') ? 1 : 1000);\n if (url && size > best.size) best = { url, size };\n }\n return best.url;\n}\n\n/** Objects of a JSON-LD script, flattened (@graph, arrays). @param {unknown} value @returns {any[]} */\nfunction jsonLdNodes(value) {\n if (Array.isArray(value)) return value.flatMap(jsonLdNodes);\n if (!value || typeof value !== 'object') return [];\n const node = /** @type {any} */ (value);\n return [node, ...jsonLdNodes(node['@graph']), ...jsonLdNodes(node.publisher), ...jsonLdNodes(node.brand)];\n}\n\nconst ORGANIZATION = /organization|corporation|business|brand|store|restaurant|company|ngo|school|airline|bank|agency/i;\n\n/** The words of a host name that name the company: \"www.acme-corp.co.uk\" → \"acme corp\". @param {string} host */\nfunction hostWords(host) {\n const labels = host.toLowerCase().replace(/^www\\d?\\./, '').split('.');\n const main = labels.length > 2 && labels[labels.length - 2].length <= 3 ? labels[labels.length - 3] : labels[0];\n return main.replace(/[-_]+/g, ' ');\n}\n\n/** @param {string} text */\nconst squash = (text) => text.toLowerCase().replace(/[^a-z0-9À-￿]+/g, '');\n\n/** @param {unknown} value */\nconst cleanName = (value) =>\n decodeEntities(String(value ?? ''))\n .replace(/\\s+/g, ' ')\n .trim()\n .slice(0, 80);\n\n/**\n * What a home page says about its brand.\n * @param {string} html\n * @param {string} pageUrl the address it was read from (after redirects)\n * @returns {PageReading}\n */\nexport function readPage(html, pageUrl) {\n const source = String(html ?? '');\n const head = source.slice(0, 400_000);\n const baseTag = startTags(head, 'base').map(tagAttributes).find((a) => a.href);\n const base = resolve(baseTag?.href, pageUrl) || pageUrl;\n const host = (() => {\n try {\n return new URL(pageUrl).hostname;\n } catch {\n return '';\n }\n })();\n\n /** @type {Record<string, string>} */\n const meta = {};\n for (const attributes of startTags(head, 'meta').map(tagAttributes)) {\n const key = (attributes.property || attributes.name || '').toLowerCase();\n if (key && attributes.content && !(key in meta)) meta[key] = attributes.content;\n }\n\n // JSON-LD: the organization's own name and logo, when the site states them.\n let schemaName = '';\n let schemaLogo = '';\n for (const [, body] of source.matchAll(/<script\\b[^>]*type\\s*=\\s*[\"']?application\\/ld\\+json[^>]*>([\\s\\S]*?)<\\/script>/gi)) {\n let data;\n try {\n data = JSON.parse(body.trim());\n } catch {\n continue;\n }\n for (const node of jsonLdNodes(data)) {\n const types = [].concat(node['@type'] || []).join(' ');\n if (!ORGANIZATION.test(types)) continue;\n if (!schemaName && typeof node.name === 'string') schemaName = node.name;\n const logo = typeof node.logo === 'string' ? node.logo : node.logo?.url || node.logo?.contentUrl || '';\n if (!schemaLogo && typeof logo === 'string') schemaLogo = resolve(logo, base);\n }\n }\n\n /* Name */\n const title = cleanName(head.match(/<title\\b[^>]*>([\\s\\S]*?)<\\/title>/i)?.[1] || '');\n const words = hostWords(host);\n const fromTitle =\n title\n .split(/\\s+[|–—:·•»-]\\s+/)\n .map((part) => part.trim())\n .find((part) => part && squash(part).length <= 40 && (squash(part).includes(squash(words)) || squash(words).includes(squash(part)))) || '';\n const fromHost = words.replace(/\\b\\p{L}/gu, (letter) => letter.toUpperCase());\n const name = cleanName(meta['og:site_name'] || schemaName || meta['application-name'] || fromTitle || fromHost);\n\n /* Logo candidates, best first */\n /** @type {PageReading['logos']} */\n const logos = [];\n const add = (/** @type {string} */ url, /** @type {PageReading['logos'][number]['from']} */ from) => {\n if (url && !logos.some((logo) => logo.url === url)) logos.push({ url, from });\n };\n add(schemaLogo, 'schema');\n /** @type {{url: string, score: number}[]} */\n const images = [];\n const headerEnd = (() => {\n const at = source.search(/<\\/header>/i);\n return at > 0 ? at : Math.min(source.length, 20_000);\n })();\n for (const match of source.matchAll(/<img\\b[^>]*>/gi)) {\n const attributes = tagAttributes(match[0]);\n const own = [attributes.class, attributes.id, attributes.alt, attributes.src, attributes['data-src']].join(' ').toLowerCase();\n const before = source.slice(Math.max(0, (match.index ?? 0) - 400), match.index).toLowerCase();\n const parent = /<(a|div|span|figure|picture)\\b[^>]*(class|id)\\s*=\\s*[\"'][^\"']*logo[^\"']*[\"'][^>]*>[^<]*(<source\\b[^>]*>\\s*)*$/i.test(before);\n if (!own.includes('logo') && !parent) continue;\n // Partner, client and payment logos are someone else's.\n if (/partner|client|customer|sponsor|award|payment|badge|trust|press|app-?store|google-?play/.test(own)) continue;\n const url = resolve(attributes.srcset ? largestOf(attributes.srcset) : attributes.src || attributes['data-src'] || '', base);\n if (!url) continue;\n let score = own.includes('logo') ? 3 : 2;\n if ((match.index ?? 0) < headerEnd) score += 3;\n if (name && squash(attributes.alt || '').includes(squash(name))) score += 2;\n if (/footer/.test(own)) score -= 2;\n images.push({ url, score: score - images.length * 0.01 });\n }\n images.sort((a, b) => b.score - a.score).forEach((image) => add(image.url, 'img'));\n /** @type {{url: string, size: number}[]} */\n const icons = [];\n for (const attributes of startTags(head, 'link').map(tagAttributes)) {\n const rel = (attributes.rel || '').toLowerCase();\n if (!/apple-touch-icon|icon/.test(rel)) continue;\n const size = parseInt(attributes.sizes || (rel.includes('apple') ? '180' : '0'), 10) || 0;\n if (size >= 96) icons.push({ url: resolve(attributes.href, base), size });\n }\n icons.sort((a, b) => b.size - a.size).forEach((icon) => add(icon.url, 'icon'));\n\n /* Styles */\n const stylesheets = startTags(head, 'link')\n .map(tagAttributes)\n .filter((a) => /(^|\\s)stylesheet(\\s|$)/i.test(a.rel || '') && !/^print$/i.test((a.media || '').trim()))\n .map((a) => resolve(a.href, base))\n .filter(Boolean)\n // Fonts and third-party widgets say nothing about the brand's colors.\n .filter((href) => !/fonts\\.googleapis|use\\.typekit|fontawesome|cookie|consent|onetrust/i.test(href));\n const css = [\n ...[...source.matchAll(/<style\\b[^>]*>([\\s\\S]*?)<\\/style>/gi)].map((m) => m[1]),\n // Inline styles of buttons and links count too: `<a class=\"btn\" style=\"…\">`.\n ...[...source.matchAll(/<(a|button)\\b[^>]*>/gi)]\n .map((m) => tagAttributes(m[0]))\n .filter((a) => a.style)\n .map((a) => `${/btn|button|cta/i.test(a.class || '') ? '.btn' : 'a'}{${a.style}}`),\n ].join('\\n');\n\n return {\n name,\n logos,\n stylesheets: [...new Set(stylesheets)],\n css,\n themeColor: meta['theme-color'] || meta['msapplication-tilecolor'] || '',\n };\n}\n\n/* ── CSS ────────────────────────────────────────────────────────────────── */\n\nconst PRIMARY_NAME = /primary|brand|accent|main|theme|highlight|cta/i;\nconst NOT_A_BRAND_NAME = /text|foreground|fg|border|muted|gr[ae]y|neutral|surface|shadow|overlay|success|error|danger|warning|info|disabled|placeholder/i;\nconst NOISE = /error|danger|success|warning|alert|invalid|valid\\b|notice|toast|badge|disabled|facebook|twitter|linkedin|instagram|youtube|whatsapp|pinterest|tiktok|social|cookie|consent|onetrust|ot-|cmp|gdpr|wp-block|has-[\\w-]+-(background-)?color|syntax|hljs|code/i;\nconst COLOR_IN_VALUE = /#[0-9a-f]{3,8}\\b|rgba?\\([^)]*\\)|hsla?\\([^)]*\\)/gi;\nconst COLOR_PROPERTY = /^(color|background|background-color|border|border-color|border-(top|bottom|left|right)(-color)?|fill|stroke|outline(-color)?|text-decoration-color|accent-color|caret-color)$/;\n\n/** @param {string} css */\nconst stripComments = (css) => css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n\n/** Rules as [selector, declarations], @media flattened. @param {string} css */\nfunction rulesOf(css) {\n /** @type {[string, [string, string][]][]} */\n const rules = [];\n for (const [, selector, body] of stripComments(css).matchAll(/([^{}]+)\\{([^{}]*)\\}/g)) {\n const declarations = body\n .split(';')\n .map((part) => {\n const colon = part.indexOf(':');\n return /** @type {[string, string]} */ ([part.slice(0, colon).trim().toLowerCase(), part.slice(colon + 1).trim()]);\n })\n .filter(([property, value]) => property && value);\n if (declarations.length) rules.push([selector.trim(), declarations]);\n }\n return rules;\n}\n\n/**\n * A custom property's value as a color: `#2977bc`, `rgb(…)`, and the bare\n * channels design systems keep there (`41 119 188`, `210 64% 45%`).\n * @param {string} value\n */\nfunction customColor(value) {\n const direct = parseColor(value.replace(/\\s*!important$/, ''));\n if (direct) return direct;\n if (/^\\d{1,3}(\\.\\d+)?\\s+\\d{1,3}(\\.\\d+)?\\s+\\d{1,3}(\\.\\d+)?$/.test(value)) return parseColor(`rgb(${value})`);\n if (/^\\d{1,3}(\\.\\d+)?(deg)?\\s+\\d{1,3}(\\.\\d+)?%\\s+\\d{1,3}(\\.\\d+)?%$/.test(value)) return parseColor(`hsl(${value.replace('deg', '')})`);\n return null;\n}\n\n/**\n * `var(--x, fallback)` replaced by what --x holds, a few levels deep.\n * @param {string} value @param {Map<string, string>} custom\n */\nfunction resolveVars(value, custom) {\n let out = value;\n for (let depth = 0; depth < 4 && out.includes('var('); depth += 1) {\n out = out.replace(/var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*([^()]*(?:\\([^()]*\\))?[^()]*))?\\)/g, (_, name, fallback) => custom.get(name) ?? fallback ?? '');\n }\n return out;\n}\n\n/** @param {{r: number, g: number, b: number}} a @param {{r: number, g: number, b: number}} b */\nconst distance = (a, b) => Math.hypot(a.r - b.r, a.g - b.g, a.b - b.b);\n\n/** Colors of one value, as found (not resolved through var()). @param {string} value */\nconst colorsIn = (value) => (value.match(COLOR_IN_VALUE) || []).map((text) => parseColor(text)).filter((c) => c && c.a >= 0.6);\n\n/**\n * The web-safe stack nearest to a CSS font-family.\n * @param {string} family\n * @returns {string|undefined}\n */\nexport function nearestFont(family) {\n const stack = String(family ?? '')\n .toLowerCase()\n .replace(/[\"']/g, '');\n if (!stack.trim() || /^(inherit|initial|unset|revert)$/.test(stack.trim())) return undefined;\n const first = stack.split(',')[0].trim();\n const known = FONT_OPTIONS.find((option) => first.startsWith(option.label.toLowerCase()));\n if (known) return known.value;\n if (/^helvetica/.test(first)) return FONT_OPTIONS[0].value;\n if (/^times/.test(first)) return FONT_OPTIONS.find((o) => o.label === 'Times')?.value;\n if (/monospace|mono\\b|courier|consolas/.test(stack)) return FONT_OPTIONS.find((o) => o.label === 'Courier')?.value;\n // Web fonts: their family decides (serif, else sans-serif).\n if (/(^|,)\\s*serif\\s*(,|$)|garamond|playfair|merriweather|lora|baskerville|caslon|didot|bodoni|crimson|libre baskerville|source serif|noto serif|pt serif/.test(stack)) {\n return FONT_OPTIONS.find((o) => o.label === 'Georgia')?.value;\n }\n return FONT_OPTIONS[0].value;\n}\n\n/**\n * Main color, headings color and font of a site, from its CSS.\n * @param {{css: string, themeColor?: string}} input\n * @returns {{primary?: string, heading?: string, font?: string}}\n */\nexport function brandFromCss({ css, themeColor = '' }) {\n const rules = rulesOf(String(css ?? ''));\n\n /** @type {Map<string, string>} */\n const custom = new Map();\n for (const [selector, declarations] of rules) {\n // :root first: a theme's dark variant must not replace it.\n const root = /^(:root|html|body|\\*)(\\s*,|$)/i.test(selector);\n for (const [property, value] of declarations) {\n if (property.startsWith('--') && (root || !custom.has(property))) custom.set(property, value.replace(/\\s*!important$/, ''));\n }\n }\n\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const found = [];\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const darkText = [];\n /** @type {{font: string, weight: number}[]} */\n const fonts = [];\n const count = (/** @type {{r: number, g: number, b: number}} */ color, /** @type {number} */ weight) => found.push({ color, weight });\n\n for (const [selector, declarations] of rules) {\n if (selector.startsWith('@')) continue;\n const noise = NOISE.test(selector);\n const emphasis = /btn|button|cta|primary|brand|accent|hero|highlight/i.test(selector) ? 4 : /(^|[\\s,>+~])a([:.[\\s,]|$)|link/i.test(selector) ? 2 : 1;\n const isHeading = /(^|[\\s,>])h[1-3]\\b|title|heading|headline/i.test(selector);\n const isBody = /^(html|body|:root)(\\s*,|$)|(^|,)\\s*(html|body)\\s*(,|$)/i.test(selector);\n for (const [property, raw] of declarations) {\n if (property.startsWith('--')) {\n const color = customColor(resolveVars(raw, custom));\n if (color && color.a >= 0.6 && PRIMARY_NAME.test(property) && !NOT_A_BRAND_NAME.test(property)) count(color, 10);\n continue;\n }\n const value = resolveVars(raw, custom);\n if (property === 'font-family' || property === 'font') {\n const family = property === 'font' ? value.replace(/^.*?\\d[\\w%.]*(\\/[\\w%.]+)?\\s+/, '') : value;\n if (isBody || isHeading) fonts.push({ font: family, weight: isBody ? 2 : 1 });\n continue;\n }\n if (!COLOR_PROPERTY.test(property) || noise) continue;\n for (const color of colorsIn(value)) {\n if (!color) continue;\n count(color, emphasis * (property.startsWith('background') ? 1.5 : 1));\n if (property === 'color' && (isHeading || isBody)) darkText.push({ color, weight: isHeading ? 2 : 1 });\n }\n }\n }\n const theme = parseColor(themeColor);\n if (theme && theme.a >= 0.6) count(theme, 15);\n\n // Near colors are one color (hover shades, rounding).\n /** @type {{color: {r: number, g: number, b: number}, weight: number}[]} */\n const clusters = [];\n for (const entry of found) {\n const near = clusters.find((cluster) => distance(cluster.color, entry.color) < 24);\n if (near) near.weight += entry.weight;\n else clusters.push({ ...entry });\n }\n clusters.sort((a, b) => b.weight - a.weight);\n const primary = clusters.find(({ color }) => {\n const { s, l } = toHsl(color);\n return s >= 0.25 && l >= 0.15 && l <= 0.85;\n });\n\n /** @type {{primary?: string, heading?: string, font?: string}} */\n const result = {};\n if (primary) result.primary = toHex(primary.color);\n\n const dark = darkText\n .filter(({ color }) => toHsl(color).l < 0.3)\n .reduce((/** @type {Map<string, number>} */ map, { color, weight }) => map.set(toHex(color), (map.get(toHex(color)) || 0) + weight), new Map());\n const heading = [...dark.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];\n if (heading) result.heading = heading;\n else if (result.primary && contrastRatio(result.primary, PALETTE.white) >= 7) result.heading = result.primary;\n else result.heading = PALETTE.ink;\n\n const font = fonts.sort((a, b) => b.weight - a.weight).map(({ font }) => nearestFont(font)).find(Boolean);\n if (font) result.font = font;\n return result;\n}\n\n/* ── Images ─────────────────────────────────────────────────────────────── */\n\n/**\n * Width and height of a PNG, GIF or JPEG, from its header; null otherwise.\n * @param {Uint8Array} bytes\n * @returns {{width: number, height: number}|null}\n */\nexport function imageSize(bytes) {\n if (!bytes || bytes.length < 24) return null;\n const at = (/** @type {number} */ i) => bytes[i];\n // PNG: IHDR right after the signature.\n if (at(0) === 0x89 && at(1) === 0x50 && at(2) === 0x4e && at(3) === 0x47) {\n const read32 = (/** @type {number} */ i) => ((at(i) << 24) | (at(i + 1) << 16) | (at(i + 2) << 8) | at(i + 3)) >>> 0;\n return { width: read32(16), height: read32(20) };\n }\n // GIF: logical screen size.\n if (at(0) === 0x47 && at(1) === 0x49 && at(2) === 0x46) {\n return { width: at(6) | (at(7) << 8), height: at(8) | (at(9) << 8) };\n }\n // JPEG: the first start-of-frame marker.\n if (at(0) === 0xff && at(1) === 0xd8) {\n let i = 2;\n while (i + 9 < bytes.length) {\n if (at(i) !== 0xff) {\n i += 1;\n continue;\n }\n const marker = at(i + 1);\n if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0xff) {\n i += marker === 0xff ? 1 : 2;\n continue;\n }\n const length = (at(i + 2) << 8) | at(i + 3);\n if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {\n return { height: (at(i + 5) << 8) | at(i + 6), width: (at(i + 7) << 8) | at(i + 8) };\n }\n i += 2 + length;\n }\n }\n return null;\n}\n\n/**\n * The width a logo is shown at in an email: a wordmark wider, a square mark\n * smaller; never wider than the image itself (a blurry logo is worse than a\n * small one). Retina images (twice the size shown) are common: halved first.\n * @param {{width: number, height: number}} size\n */\nexport function logoWidthFor({ width, height }) {\n if (!width || !height) return 140;\n const ratio = width / height;\n const shown = width >= 240 ? width / 2 : width;\n const target = ratio >= 2.5 ? 180 : ratio >= 1.3 ? 140 : 72;\n return Math.max(24, Math.round(Math.min(target, shown)));\n}\n","// @ts-check\n/**\n * What the user is told about reading a brand from a website: why it failed\n * (the server's answer) and what it could not find (notes under the field).\n * English source strings, translated where they are shown.\n */\n\n/**\n * Why a website could not be read: [HTTP status, message], by\n * BrandImportError code (src/server/brandImport.js).\n * @type {Record<string, [number, string]>}\n */\nexport const BRAND_IMPORT_ERRORS = {\n BAD_URL: [400, 'Enter the address of a website, like acme.com'],\n PRIVATE_ADDRESS: [400, 'This address is not a public website'],\n UNREACHABLE: [422, 'The website could not be reached. Check the address.'],\n TIMEOUT: [422, 'The website took too long to answer'],\n HTTP_ERROR: [422, 'The website does not let the builder read it. Fill in your brand below.'],\n NOT_HTML: [422, 'This address is not a web page'],\n TOO_MANY_REDIRECTS: [422, 'The website redirects too many times'],\n TOO_LARGE: [422, 'The website sent too much data'],\n};\n\n/** What could not be read, by note code. @type {Record<string, string>} */\nexport const BRAND_NOTES = {\n LOGO_NOT_FOUND: 'No logo was found on the website. Upload it below.',\n LOGO_UNSUPPORTED: 'The logo on the website is an SVG or WebP image, which most email apps do not show. Upload a PNG or JPEG version.',\n LOGO_ICON: 'The website icon is used as the logo. Upload your full logo if you have one.',\n COLORS_NOT_FOUND: 'No main color was found on the website. Pick one below.',\n};\n","// @ts-check\nimport { parseMjml, serializeMjml } from '../engine/mjml.js';\nimport { createNode, findFirst, walk } from '../engine/model.js';\n\n/**\n * MJML uses inline blocks outside Outlook. They have independent heights,\n * and mixed middle/top alignment uses a text baseline instead of the row.\n * Use equal-height table cells for every desktop row with multiple columns.\n * Outlook keeps MJML's native conditional table. Mobile stacking is unchanged.\n * This runs inside the compiler, after validation, so callers cannot supply\n * arbitrary raw HTML or CSS through the document.\n * @param {string} source\n */\nexport function prepareColumnAlignment(source) {\n if ((source.match(/<mj-(?:column|group)\\b/g) || []).length < 2 || source.includes('eb-va-row')) return source;\n const root = parseMjml(source);\n let changed = false;\n const backgrounds = [];\n let count = 0;\n walk(root, (node) => {\n if (!['mj-section', 'mj-group'].includes(node.tag)) return;\n const columns = node.children.filter((child) => child.tag === 'mj-column' || child.tag === 'mj-group');\n if (columns.length < 2) return;\n changed = true;\n for (const column of columns) {\n column.attributes['css-class'] = `${column.attributes['css-class'] || ''} eb-va-col`.trim();\n const color = column.attributes['background-color'] || '';\n if (/^(?:#[\\da-f]{3,8}|[a-z]+|rgba?\\([\\d\\s.,%]+\\)|hsla?\\([\\d\\s.,%]+\\))$/i.test(color) && !column.attributes['css-class'].includes('eb-render-box-')) {\n const marker = `eb-va-bg-${count++}`;\n column.attributes['css-class'] += ` ${marker}`;\n backgrounds.push(`.${marker} {background-color:${color};}`);\n }\n }\n node.children = [\n createNode('mj-raw', { content: '<!--[if !mso]><!--><div class=\"eb-va-row\"><!--<![endif]-->' }),\n ...node.children,\n createNode('mj-raw', { content: '<!--[if !mso]><!--></div><!--<![endif]-->' }),\n ];\n });\n if (!changed) return source;\n let head = findFirst(root, 'mj-head');\n if (!head) {\n head = createNode('mj-head');\n root.children.unshift(head);\n }\n const width = findFirst(head, 'mj-breakpoint')?.attributes.width || '';\n const breakpoint = /^\\d+(?:\\.\\d+)?px$/.test(width) ? width : '480px';\n head.children.push(createNode('mj-style', { content:\n `@media only screen and (min-width:${breakpoint}) {` +\n '.eb-va-row {display:table;width:100%;table-layout:fixed;}' +\n '.eb-va-row > .eb-va-col {display:table-cell!important;}' +\n '}' }));\n if (backgrounds.length) head.children.push(createNode('mj-style', { attributes: { inline: 'inline' }, content: backgrounds.join('') }));\n return serializeMjml(root);\n}\n","// @ts-check\nimport { parseMjml, serializeMjml, encodeAttribute } from '../engine/mjml.js';\nimport { boxKeys } from '../core/blockBox.js';\nimport { createNode, findFirst, walk } from '../engine/model.js';\nimport { toValues, parseBorder, parseSpacing } from '../core/mjmlAttributes.js';\nimport { MJML_DEFAULTS } from '../core/mjmlDefaults.js';\nimport { prepareColumnAlignment } from './columnAlignment.js';\n\n/** Only lengths may become outside or inside spacing. @param {string} value */\nconst spacing = (value) => parseSpacing(value || '0px').map((part) => {\n const number = Number.parseFloat(part);\n return Number.isFinite(number) && number >= 0 ? `${number}${part.endsWith('%') ? '%' : 'px'}` : '0px';\n}).join(' ');\n\n/** @param {string} value */\nfunction borderStyle(value) {\n const border = parseBorder(value);\n if (!border) return 'border:0;';\n // A border color cannot add declarations, external resources or markup.\n const color = /^(?:#[\\da-f]{3,8}|[a-z]+|rgba?\\([\\d\\s.,%]+\\)|hsla?\\([\\d\\s.,%]+\\))$/i.test(border.color) ? border.color : '#cbd5e1';\n return `border-width:${border.widths.map((width) => `${width}px`).join(' ')};border-style:${border.style};border-color:${color};`;\n}\n\n/** Prepare model-only box controls without sending unsupported attributes to MJML. @param {string} source */\nfunction prepareBoxes(source) {\n /** @type {{marker: string, margin: string, padding: string, border: string, gutter: boolean}[]} */\n const boxes = [];\n if (!/(?:eb-box-[a-f0-9]+|\\bbox-(?:padding|border)\\s*=|\\bmargin\\s*=)/.test(source)) return { mjml: source, boxes };\n const root = parseMjml(source);\n walk(root, (node) => {\n if (node.tag === 'mj-section' || !Object.keys(node.attributes).some((key) => key === 'margin' || key.startsWith('box-'))) return;\n const keys = boxKeys(node.tag);\n const properties = Object.values(keys).map((key) => ({ key }));\n const values = toValues({ ...MJML_DEFAULTS[node.tag], ...node.attributes }, properties);\n const marker = `eb-render-box-${boxes.length}`;\n const margin = spacing(values[keys.margin]);\n const padding = spacing(values[keys.padding]);\n const widths = parseBorder(values[keys.border])?.widths || [0, 0, 0, 0];\n const contextPadding = parseSpacing(margin).map((side, index) => Number.parseFloat(side) + Number.parseFloat(parseSpacing(padding)[index]) + widths[index]);\n boxes.push({ marker, margin, padding, border: borderStyle(values[keys.border]), gutter: node.tag === 'mj-column' && contextPadding.some(Boolean) });\n for (const key of Object.values(keys)) {\n delete node.attributes[key];\n for (const side of ['top', 'right', 'bottom', 'left']) delete node.attributes[`${key}-${side}`];\n }\n // Suppress MJML's default padding: the email table below now supplies it.\n node.attributes.padding = '0px';\n // MJML also uses padding to calculate fixed image widths for Outlook.\n // Reserve the actual box width during compilation, then replace its\n // gutter with the independent layers below.\n if (node.tag === 'mj-image' || node.tag === 'mj-column') node.attributes.padding = contextPadding.map((side) => `${side}px`).join(' ');\n node.attributes['css-class'] = `${node.attributes['css-class'] || ''} ${marker}`.trim();\n });\n return { mjml: boxes.length ? serializeMjml(root) : source, boxes };\n}\n\n/** Find the complete marked element without counting Outlook's conditional HTML as DOM. @param {string} html @param {string} marker */\nfunction markedElement(html, marker) {\n const tokens = /<!--[\\s\\S]*?-->|<\\/?([a-z][\\w:-]*)\\b(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/gi;\n let start = -1;\n let tag = '';\n let opening = '';\n let depth = 0;\n for (const token of html.matchAll(tokens)) {\n if (!token[1]) continue;\n const closing = token[0].startsWith('</');\n if (start < 0) {\n const classes = /\\bclass=\"([^\"]*)\"/.exec(token[0])?.[1].split(/\\s+/) || [];\n if (closing || !classes.includes(marker)) continue;\n start = token.index;\n tag = token[1].toLowerCase();\n opening = token[0];\n depth = 1;\n } else if (token[1].toLowerCase() === tag) {\n depth += closing ? -1 : 1;\n if (!depth) return { start, end: token.index + token[0].length, opening, tag, inner: html.slice(start + opening.length, token.index), closing: token[0] };\n }\n }\n return null;\n}\n\nconst table = (inner) => `<table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"width:100%;border-collapse:separate;\"><tbody><tr>${inner}</tr></tbody></table>`;\n\n/** @param {string} opening @param {string} style */\nfunction styled(opening, style) {\n const safe = encodeAttribute(style);\n return /\\bstyle=\"/.test(opening) ? opening.replace(/\\bstyle=\"([^\"]*)\"/, (_, previous) => `style=\"${previous};${safe}\"`) : opening.replace(/>$/, ` style=\"${safe}\">`);\n}\n\n/**\n * An image given a height (those side by side, fitted to the first) is\n * cropped to it, not stretched; on a phone, where the columns stack, it keeps\n * its own proportions. Outlook on Windows has no `object-fit`: it stretches.\n * @param {string} source\n */\nfunction prepareImageHeights(source) {\n if (!/<mj-image\\b[^>]*\\sheight=\"\\d/.test(source)) return source;\n const root = parseMjml(source);\n walk(root, (node) => {\n if (node.tag === 'mj-image' && /^\\d+(?:\\.\\d+)?px$/.test(node.attributes.height || '')) {\n node.attributes['css-class'] = `${node.attributes['css-class'] || ''} eb-fill`.trim();\n }\n });\n let head = findFirst(root, 'mj-head');\n if (!head) {\n head = createNode('mj-head');\n root.children.unshift(head);\n }\n const width = Number.parseFloat(findFirst(head, 'mj-breakpoint')?.attributes.width || '') || 480;\n head.children.push(createNode('mj-style', { content:\n '.eb-fill img {object-fit:cover;}' +\n `@media only screen and (max-width:${width - 1}px) {.eb-fill img {height:auto!important;}}` }));\n return serializeMjml(root);\n}\n\n/** Compile both native MJML and the editor's independent box controls. @param {string} source @param {(source: string, options: any) => any} compile @param {any} [options] */\nexport async function compileEditorMjml(source, compile, options = {}) {\n const prepared = prepareBoxes(source);\n const result = await compile(prepareColumnAlignment(prepareImageHeights(prepared.mjml)), options);\n let html = String(result.html || '');\n // Children first: outer wrappers retain every nested canvas marker.\n for (const box of prepared.boxes.reverse()) {\n const element = markedElement(html, box.marker);\n if (!element) continue;\n const inside = `padding:${box.padding};${box.border}`;\n let replacement;\n if (element.tag === 'td') {\n const original = styled(element.opening, inside) + element.inner + element.closing;\n replacement = `<td style=\"padding:${box.margin};font-size:0;\">${table(original)}</td>`;\n } else if (element.tag === 'a') {\n replacement = `<span style=\"display:inline-block;padding:${box.margin};\"><span style=\"display:inline-block;${inside}\">${element.opening}${element.inner}${element.closing}</span></span>`;\n } else {\n const inner = box.gutter ? element.inner.replace(/<td\\b(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/i, (opening) => styled(opening, 'padding:0;')) : element.inner;\n replacement = element.opening + table(`<td style=\"padding:${box.margin};\">${table(`<td style=\"${inside}\">${inner}</td>`)}</td>`) + element.closing;\n }\n html = html.slice(0, element.start) + replacement + html.slice(element.end);\n }\n return { ...result, html };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsBA,IAAM,WAAW;AACjB,IAAM,UAAU;AAMT,SAAS,0BAA0B,MAAM;AAC9C,SAAO,CAAC,GAAG,OAAO,QAAQ,EAAE,EAAE,SAAS,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,EAAE;AAChG;AAEA,SAAS,UAAU,MAAM;AACvB,SAAO,OAAO,QAAQ,EAAE,EACrB,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ;AAC3B;AAOO,SAAS,YAAY,MAAM,EAAE,QAAQ,MAAM,YAAY,MAAM,OAAO,MAAM,cAAc,OAAO,IAAI,CAAC,GAAG;AAC5G,MAAI,MAAM,OAAO,QAAQ,EAAE,EACxB,QAAQ,gDAAgD,EAAE,EAC1D,QAAQ,oDAAoD,EAAE;AACjE,MAAI,gBAAgB,OAAQ,OAAM,IAAI,QAAQ,UAAU,CAAC,SAAS,UAAW,QAAQ,KAAK,KAAK,IAAI,UAAU,EAAG;AAEhH,QAAM,IAAI;AAAA,IAAQ;AAAA,IAAqB,CAAC,KAAK,QAAQ,OACnD,aAAa,KAAK,KAAK,IAAI,MAAM,eAAe,UAAU,IAAI,CAAC,IAAI,KAAK;AAAA,EAC1E;AAEA,QAAM,OAAO;AAAA,IACX,SAAS,OAAO,KAAK,EAAE,KAAK,IAAI,aAAa,UAAU,OAAO,KAAK,EAAE,KAAK,CAAC,CAAC,gBAAg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,OAAO,SAAS,MAAM,QAAQ,GAAG;AAC1C,UAAM,UAAU,cAAc,MAAM,IAAI,MAAM;AAC9C,QAAI,CAAC,QAAS;AACd,UAAM,SAAS,WAAW,IAAI,OAAO,IAAI,IAAI,MAAM;AACnD,QAAI;AACJ,QAAI,QAAQ,QAAQ,MAAM;AACxB,YAAM,WAAW,OAAO,QAAQ,SAAS,MAAM,IAAI,QAAQ,QAAQ,QAAQ;AAC3E,oBAAc,sBAAsB,IAAI,MAAM,kBAAkB,MAAM,QAAQ,CAAC;AAAA,IACjF,WAAW,QAAQ,QAAQ,KAAK;AAC9B,oBAAc,6CAA6C,IAAI,MAAM,wCAAwC,MAAM,KAAK,QAAQ,OAAO,GAAG,QAAQ,KAAK,GAAG,QAAQ,OAAO;AAAA,IAC3K,OAAO;AACL,YAAM,QAAQ,IAAI,SAAS,QAAQ,MAAM,QAAQ,sCAAsC,CAAC,YAAY,OAAO,SAAS,YAAY,CAAC,IAAI,QAAQ;AAC7I,oBAAc,QAAQ,UAAU,MAAM,sBAAsB,IAAI,MAAM,MAAM,MAAM,cAAc,MAAM,KAAK,KAAK,OAAO,CAAC,OAAO,IAAI,QAAQ;AAAA,IAC7I;AACA,WAAO,KAAK,MAAM,GAAG,QAAQ,KAAK,IAAI,cAAc,KAAK,MAAM,QAAQ,GAAG;AAAA,EAC5E;AACA,SAAO,EAAE,GAAG,QAAQ,KAAK;AAC3B;","names":["font"]}
@@ -7,7 +7,7 @@ import {
7
7
  readDocument,
8
8
  sortTags,
9
9
  validateTag
10
- } from "./chunk-L7NSAYYX.js";
10
+ } from "./chunk-CYTZO2MW.js";
11
11
  import {
12
12
  DEFAULT_ASSETS_PATH,
13
13
  DEFAULT_VARIABLES,
@@ -16,7 +16,7 @@ import {
16
16
  translatorFor,
17
17
  validateCustomVariable,
18
18
  validateVariableEdit
19
- } from "./chunk-2B3N6CH4.js";
19
+ } from "./chunk-MW3ZGK34.js";
20
20
 
21
21
  // src/ui/context.jsx
22
22
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
@@ -44,9 +44,9 @@ function cn(...inputs) {
44
44
  import { forwardRef } from "react";
45
45
  import { Label as LabelPrimitive } from "radix-ui";
46
46
  import { jsx } from "react/jsx-runtime";
47
- var DENSE_FIELD = "eb:h-6.5 eb:px-2.5 eb:text-[12.5px]";
47
+ var FIELD = "eb:rounded-lg2 eb:border eb:border-border eb:bg-background eb:px-2.5 eb:text-[12px] eb:text-foreground eb:shadow-xs";
48
48
  var NO_SPINNER = "eb:[appearance:textfield] eb:[&::-webkit-inner-spin-button]:appearance-none eb:[&::-webkit-outer-spin-button]:appearance-none";
49
- var Input = forwardRef(function Input2({ className, type, dense = false, ...props }, ref) {
49
+ var Input = forwardRef(function Input2({ className, type, dense: _dense, ...props }, ref) {
50
50
  return /* @__PURE__ */ jsx(
51
51
  "input",
52
52
  {
@@ -54,10 +54,10 @@ var Input = forwardRef(function Input2({ className, type, dense = false, ...prop
54
54
  type,
55
55
  "data-slot": "input",
56
56
  className: cn(
57
- "eb:h-8 eb:w-full eb:min-w-0 eb:rounded-lg2 eb:border eb:border-border-strong eb:bg-surface-75 eb:px-3 eb:py-1 eb:text-[13px] eb:text-foreground eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:placeholder:text-foreground-muted eb:selection:bg-primary eb:selection:text-primary-foreground eb:disabled:pointer-events-none eb:disabled:cursor-not-allowed eb:disabled:opacity-50",
57
+ FIELD,
58
+ "eb:h-7 eb:w-full eb:min-w-0 eb:py-1 eb:transition-[color,box-shadow] eb:outline-none eb:placeholder:text-foreground-muted eb:selection:bg-primary eb:selection:text-primary-foreground eb:disabled:pointer-events-none eb:disabled:cursor-not-allowed eb:disabled:opacity-50",
58
59
  "eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50",
59
60
  "eb:aria-invalid:border-destructive eb:aria-invalid:ring-destructive/20",
60
- dense && DENSE_FIELD,
61
61
  type === "number" && NO_SPINNER,
62
62
  className
63
63
  ),
@@ -72,8 +72,9 @@ var Textarea = forwardRef(function Textarea2({ className, dense = false, ...prop
72
72
  ref,
73
73
  "data-slot": "textarea",
74
74
  className: cn(
75
- "eb:flex eb:field-sizing-content eb:min-h-16 eb:w-full eb:resize-y eb:rounded-lg2 eb:border eb:border-border-strong eb:bg-surface-75 eb:px-3 eb:py-2 eb:text-[13px] eb:text-foreground eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:aria-invalid:border-destructive eb:aria-invalid:ring-destructive/20 eb:disabled:cursor-not-allowed eb:disabled:opacity-50",
76
- dense && "eb:min-h-12 eb:px-2.5 eb:py-1 eb:text-[12.5px] eb:leading-[18px]",
75
+ FIELD,
76
+ "eb:flex eb:field-sizing-content eb:min-h-16 eb:w-full eb:resize-y eb:py-1.5 eb:transition-[color,box-shadow] eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:aria-invalid:border-destructive eb:aria-invalid:ring-destructive/20 eb:disabled:cursor-not-allowed eb:disabled:opacity-50",
77
+ dense && "eb:min-h-12 eb:py-1 eb:leading-[18px]",
77
78
  className
78
79
  ),
79
80
  ...props
@@ -229,14 +230,14 @@ function Select(props) {
229
230
  function SelectValue(props) {
230
231
  return /* @__PURE__ */ jsx2(SelectPrimitive.Value, { "data-slot": "select-value", ...props });
231
232
  }
232
- function SelectTrigger({ className, children, dense = false, ...props }) {
233
+ function SelectTrigger({ className, children, dense: _dense, ...props }) {
233
234
  return /* @__PURE__ */ jsxs(
234
235
  SelectPrimitive.Trigger,
235
236
  {
236
237
  "data-slot": "select-trigger",
237
238
  className: cn(
238
- "eb:flex eb:h-8 eb:w-full eb:items-center eb:justify-between eb:gap-2 eb:rounded-lg2 eb:border eb:border-border-strong eb:bg-surface-75 eb:px-3 eb:py-1 eb:text-[13px] eb:whitespace-nowrap eb:text-foreground eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:cursor-not-allowed eb:disabled:opacity-50 eb:data-[placeholder]:text-foreground-muted eb:*:data-[slot=select-value]:line-clamp-1 eb:*:data-[slot=select-value]:flex eb:*:data-[slot=select-value]:items-center eb:*:data-[slot=select-value]:gap-2 eb:[&_svg]:pointer-events-none eb:[&_svg]:shrink-0 eb:[&_svg:not([class*='size-'])]:size-4",
239
- dense && DENSE_FIELD,
239
+ FIELD,
240
+ "eb:flex eb:h-7 eb:w-full eb:items-center eb:justify-between eb:gap-2 eb:py-1 eb:whitespace-nowrap eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:cursor-not-allowed eb:disabled:opacity-50 eb:data-[placeholder]:text-foreground-muted eb:*:data-[slot=select-value]:line-clamp-1 eb:*:data-[slot=select-value]:flex eb:*:data-[slot=select-value]:items-center eb:*:data-[slot=select-value]:gap-2 eb:[&_svg]:pointer-events-none eb:[&_svg]:shrink-0 eb:[&_svg:not([class*='size-'])]:size-4",
240
241
  className
241
242
  ),
242
243
  ...props,
@@ -319,7 +320,7 @@ var buttonVariants = cva(
319
320
  "icon-sm-compact": "eb:size-7 eb:[&_svg:not([class*='size-'])]:size-3",
320
321
  "icon-sm": "eb:size-8",
321
322
  // Beside a `dense` field.
322
- "icon-dense": "eb:size-6.5 eb:rounded-lg2 eb:[&_svg:not([class*='size-'])]:size-3.5"
323
+ "icon-dense": "eb:size-7 eb:rounded-lg2 eb:[&_svg:not([class*='size-'])]:size-3.5"
323
324
  }
324
325
  },
325
326
  defaultVariants: { variant: "default", size: "default" }
@@ -1011,4 +1012,4 @@ export {
1011
1012
  createHttpStorage,
1012
1013
  createMemoryStorage
1013
1014
  };
1014
- //# sourceMappingURL=chunk-D46HKFV5.js.map
1015
+ //# sourceMappingURL=chunk-K43QP3TX.js.map