best-email-builder 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/ai-server.js +3 -3
- package/dist/ai.js +6 -6
- package/dist/builder.js +11 -8
- package/dist/{chunk-C22PQBW4.js → chunk-5ZL3YA33.js} +15 -4
- package/dist/chunk-5ZL3YA33.js.map +1 -0
- package/dist/{chunk-2XSNS7EW.js → chunk-AABKWP7D.js} +3 -3
- package/dist/{chunk-2XSNS7EW.js.map → chunk-AABKWP7D.js.map} +1 -1
- package/dist/{chunk-WWP3FQYO.js → chunk-BGRCQ7FC.js} +4 -4
- package/dist/{chunk-HE2VAOLR.js → chunk-BNCV6YFL.js} +127 -7
- package/dist/chunk-BNCV6YFL.js.map +1 -0
- package/dist/{chunk-IGC3I4XL.js → chunk-DVC7C52B.js} +2 -2
- package/dist/{chunk-XYXN3UBQ.js → chunk-HBFZQGE7.js} +2 -2
- package/dist/{chunk-3FKHX47M.js → chunk-LZYH2DE7.js} +565 -636
- package/dist/chunk-LZYH2DE7.js.map +1 -0
- package/dist/{chunk-OSQ5YGHL.js → chunk-QY67KPCS.js} +2 -2
- package/dist/chunk-SNQ37KCQ.js +768 -0
- package/dist/chunk-SNQ37KCQ.js.map +1 -0
- package/dist/{chunk-4SRNGFAV.js → chunk-YKPRHFMR.js} +3 -3
- package/dist/{chunk-LQ3JCPZ2.js → chunk-ZRMXUM2K.js} +2 -2
- package/dist/index.js +10 -10
- package/dist/library.js +7 -5
- package/dist/server.js +99 -16
- package/dist/server.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/builder.d.ts +1 -0
- package/dist/types/core/constants.d.ts +1 -1
- package/dist/types/engine/NativeAdapter.d.ts +1 -1
- package/dist/types/features/preview/PreviewButton.d.ts +4 -3
- package/dist/types/features/test-email/TestEmailDialog.d.ts +29 -0
- package/dist/types/library.d.ts +1 -0
- package/dist/types/server/handler.d.ts +45 -0
- package/dist/types/server/render.d.ts +6 -2
- package/dist/types/server/sendTest.d.ts +21 -3
- package/dist/types/storage/client.d.ts +39 -5
- package/package.json +1 -1
- package/dist/chunk-3FKHX47M.js.map +0 -1
- package/dist/chunk-7ZI7ZOYQ.js +0 -294
- package/dist/chunk-7ZI7ZOYQ.js.map +0 -1
- package/dist/chunk-C22PQBW4.js.map +0 -1
- package/dist/chunk-HE2VAOLR.js.map +0 -1
- package/dist/types/features/test-email/TestEmailButton.d.ts +0 -3
- /package/dist/{chunk-WWP3FQYO.js.map → chunk-BGRCQ7FC.js.map} +0 -0
- /package/dist/{chunk-IGC3I4XL.js.map → chunk-DVC7C52B.js.map} +0 -0
- /package/dist/{chunk-XYXN3UBQ.js.map → chunk-HBFZQGE7.js.map} +0 -0
- /package/dist/{chunk-OSQ5YGHL.js.map → chunk-QY67KPCS.js.map} +0 -0
- /package/dist/{chunk-4SRNGFAV.js.map → chunk-YKPRHFMR.js.map} +0 -0
- /package/dist/{chunk-LQ3JCPZ2.js.map → chunk-ZRMXUM2K.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/constants.js","../src/core/document.js","../src/engine/model.js","../src/core/blockBox.js","../src/engine/mjml.js","../src/blocks/shared.js","../src/features/brand/brand.js","../src/features/tags/tags.js","../src/validation/images.js"],"sourcesContent":["// @ts-check\n/**\n * Email builder constants.\n *\n * `EMAIL_BUILDER_VERSION` versions THIS package (UI, blocks, rendering);\n * `EMAIL_DOCUMENT_SCHEMA_VERSION` versions the stored JSON envelope (the\n * project JSON). Both are written with every template, so a document read by\n * a newer version knows whether it must be migrated (see `core/document.js`).\n */\n\nexport const EMAIL_BUILDER_VERSION = '0.22.0';\n\nexport const EMAIL_DOCUMENT_SCHEMA_VERSION = 1;\n\n/** @typedef {'desktop'|'mobile'} EmailDevice */\n\n/** @type {EmailDevice[]} */\nexport const EMAIL_DEVICES = ['desktop', 'mobile'];\n\n/** Content column width — the email client standard. */\nexport const EMAIL_CONTENT_WIDTH = 600;\n\n/** Mobile preview frame width (standard iPhone, the common worst case). */\nexport const EMAIL_MOBILE_WIDTH = 375;\n","// @ts-check\n/**\n * DOCUMENT envelope — what gets stored (the project JSON).\n *\n * HTML is only a compilation output; what gets edited is the engine's\n * project. It is not stored bare but wrapped with:\n *\n * schemaVersion the shape of THIS envelope (migrations, see MIGRATIONS);\n * engine the engine that can read `project` back;\n * engineVersion its version at write time;\n * builderVersion the builder version that wrote it;\n * project the engine data, opaque to the rest of the code.\n *\n * A document from another engine, a future schema or a malformed one is\n * REJECTED on read rather than half-loaded: a template silently emptied and\n * then saved again would be lost.\n *\n * Dependency-free module: testable outside the browser.\n */\n\nimport { EMAIL_BUILDER_VERSION, EMAIL_DOCUMENT_SCHEMA_VERSION } from './constants.js';\n\n/**\n * @typedef {{\n * schemaVersion: number,\n * engine: string,\n * engineVersion: string,\n * builderVersion: string,\n * project: Record<string, any>,\n * }} EmailDocument\n */\n\n/**\n * Envelope migrations, from N to N+1. Empty while only one schema exists; the\n * first entry will be `1: (doc) => ({ ...doc, schemaVersion: 2 })`.\n *\n * @type {Record<number, (document: any) => any>}\n */\nconst MIGRATIONS = {};\n\nexport class EmailDocumentError extends Error {\n /** @param {string} message */\n constructor(message) {\n super(message);\n this.name = 'EmailDocumentError';\n this.status = 422;\n }\n}\n\nfunction isPlainObject(value) {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * @param {{engine: string, engineVersion: string, project: object}} parts\n * @returns {EmailDocument}\n */\nexport function createDocument({ engine, engineVersion, project }) {\n if (!engine) throw new EmailDocumentError('Document: missing engine');\n if (!isPlainObject(project)) throw new EmailDocumentError('Document: invalid engine project');\n return {\n schemaVersion: EMAIL_DOCUMENT_SCHEMA_VERSION,\n engine,\n engineVersion: String(engineVersion || ''),\n builderVersion: EMAIL_BUILDER_VERSION,\n project: /** @type {Record<string, any>} */ (project),\n };\n}\n\n/**\n * Reads a document (object or JSON string), migrates it to the current schema\n * and validates it.\n *\n * @param {unknown} raw\n * @returns {EmailDocument}\n * @throws {EmailDocumentError}\n */\nexport function readDocument(raw) {\n let value = raw;\n if (typeof value === 'string') {\n try {\n value = JSON.parse(value);\n } catch {\n throw new EmailDocumentError('Unreadable document: invalid JSON');\n }\n }\n if (!isPlainObject(value)) throw new EmailDocumentError('Unreadable document: object expected');\n\n /** @type {any} */\n let document = { ...(/** @type {object} */ (value)) };\n const version = Number(document.schemaVersion);\n if (!Number.isInteger(version) || version < 1) {\n throw new EmailDocumentError('Unreadable document: missing schema version');\n }\n if (version > EMAIL_DOCUMENT_SCHEMA_VERSION) {\n throw new EmailDocumentError(\n `Document written by a newer version of the builder (schema ${version}) — ` +\n 'reload the page'\n );\n }\n for (let v = version; v < EMAIL_DOCUMENT_SCHEMA_VERSION; v += 1) {\n const migrate = MIGRATIONS[v];\n if (!migrate) throw new EmailDocumentError(`Document: no migration from schema ${v}`);\n document = migrate(document);\n }\n\n if (typeof document.engine !== 'string' || !document.engine) {\n throw new EmailDocumentError('Unreadable document: missing engine');\n }\n if (!isPlainObject(document.project)) {\n throw new EmailDocumentError('Unreadable document: missing engine project');\n }\n\n return {\n schemaVersion: EMAIL_DOCUMENT_SCHEMA_VERSION,\n engine: document.engine,\n engineVersion: String(document.engineVersion || ''),\n builderVersion: String(document.builderVersion || ''),\n project: document.project,\n };\n}\n\n/** @param {EmailDocument} document */\nexport function serializeDocument(document) {\n return JSON.stringify(readDocument(document));\n}\n","// @ts-check\n/**\n * THE EMAIL MODEL — the builder's own document, an MJML tree with ids.\n *\n * { id, tag: 'mj-text', attributes: { color: '#2b3038' }, children: [], content: 'Hello' }\n *\n * One node per MJML element. \"Ending\" elements (`mj-text`, `mj-button`…)\n * keep their inner HTML in `content`; the others hold `children`. Ids are\n * opaque, unique within a tree, made of `[a-z0-9]` so they can live in a CSS\n * class (the canvas finds an element by them, see `canvasMjml.js`).\n *\n * Every operation is PURE: it returns a new tree and never changes the one it\n * got, sharing the untouched branches. The undo history is then just a list\n * of trees.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\n/**\n * @typedef {{\n * id: string,\n * tag: string,\n * attributes: Record<string, string>,\n * children: EmailNode[],\n * content: string|null,\n * }} EmailNode\n */\n\n/** MJML elements whose inner content is HTML (MJML calls them \"ending tags\"). */\nexport const ENDING_TAGS = new Set([\n 'mj-text',\n 'mj-button',\n 'mj-navbar-link',\n 'mj-social-element',\n 'mj-table',\n 'mj-raw',\n 'mj-title',\n 'mj-preview',\n 'mj-style',\n 'mj-accordion-title',\n 'mj-accordion-text',\n]);\n\n/** Elements that hold a whole section's place in the body. */\nexport const SECTION_TAGS = new Set(['mj-section', 'mj-wrapper', 'mj-hero']);\n\n/** Elements that are never removed, moved or duplicated. */\nexport const LOCKED_TAGS = new Set(['mjml', 'mj-head', 'mj-body']);\n\nlet counter = 0;\n\n/** A fresh id: short, unique for the page's lifetime, `[a-z0-9]` only. */\nexport function createId() {\n counter = (counter + 1) % 1679616; // 36^4\n return `n${Date.now().toString(36).slice(-5)}${counter.toString(36).padStart(4, '0')}${Math.floor(Math.random() * 1296)\n .toString(36)\n .padStart(2, '0')}`;\n}\n\n/**\n * @param {string} tag\n * @param {{attributes?: Record<string, string>, children?: EmailNode[], content?: string|null, id?: string}} [parts]\n * @returns {EmailNode}\n */\nexport function createNode(tag, { attributes = {}, children = [], content = null, id = createId() } = {}) {\n return { id, tag, attributes: { ...attributes }, children: [...children], content: ENDING_TAGS.has(tag) ? String(content ?? '') : null };\n}\n\n/**\n * Deep copy with NEW ids everywhere (duplicate, paste, insert a block twice).\n * @param {EmailNode} node\n * @returns {EmailNode}\n */\nexport function cloneWithNewIds(node) {\n return {\n id: createId(),\n tag: node.tag,\n attributes: { ...node.attributes },\n children: node.children.map(cloneWithNewIds),\n content: node.content,\n };\n}\n\n/* ── Reading ─────────────────────────────────────────────────────────────── */\n\n/**\n * The node with this id and its ancestors (root first), or null.\n * @param {EmailNode} root @param {string} id\n * @returns {EmailNode[]|null}\n */\nexport function pathTo(root, id) {\n if (root.id === id) return [root];\n for (const child of root.children) {\n const path = pathTo(child, id);\n if (path) return [root, ...path];\n }\n return null;\n}\n\n/** @param {EmailNode} root @param {string|null|undefined} id */\nexport function findNode(root, id) {\n if (!id) return null;\n const path = pathTo(root, id);\n return path ? path[path.length - 1] : null;\n}\n\n/** @param {EmailNode} root @param {string} id */\nexport function parentOf(root, id) {\n const path = pathTo(root, id);\n return path && path.length > 1 ? path[path.length - 2] : null;\n}\n\n/**\n * Closest node (itself included) whose tag is one of `tags`.\n * @param {EmailNode} root @param {string} id @param {Set<string>|string[]} tags\n */\nexport function closestOfTags(root, id, tags) {\n const set = tags instanceof Set ? tags : new Set(tags);\n const path = pathTo(root, id);\n if (!path) return null;\n for (let i = path.length - 1; i >= 0; i -= 1) if (set.has(path[i].tag)) return path[i];\n return null;\n}\n\n/** First node of a tag, depth first. @param {EmailNode} root @param {string} tag @returns {EmailNode|null} */\nexport function findFirst(root, tag) {\n if (root.tag === tag) return root;\n for (const child of root.children) {\n const found = findFirst(child, tag);\n if (found) return found;\n }\n return null;\n}\n\n/** Every node, depth first. @param {EmailNode} root @param {(node: EmailNode) => void} visit */\nexport function walk(root, visit) {\n visit(root);\n for (const child of root.children) walk(child, visit);\n}\n\n/* ── Writing (pure) ──────────────────────────────────────────────────────── */\n\n/**\n * The tree with the node `id` replaced by `update(node)`.\n * @param {EmailNode} root @param {string} id @param {(node: EmailNode) => EmailNode} update\n * @returns {EmailNode}\n */\nexport function updateNode(root, id, update) {\n if (root.id === id) return update(root);\n let changed = false;\n const children = root.children.map((child) => {\n const next = updateNode(child, id, update);\n if (next !== child) changed = true;\n return next;\n });\n return changed ? { ...root, children } : root;\n}\n\n/**\n * Sets (string) or removes (null, '') attributes.\n * @param {EmailNode} root @param {string} id @param {Record<string, string|null|undefined>} attributes\n */\nexport function setAttributes(root, id, attributes) {\n return updateNode(root, id, (node) => {\n const next = { ...node.attributes };\n for (const [key, value] of Object.entries(attributes)) {\n if (value === null || value === undefined || value === '') delete next[key];\n else next[key] = String(value);\n }\n return { ...node, attributes: next };\n });\n}\n\n/** @param {EmailNode} root @param {string} id @param {string} content */\nexport function setContent(root, id, content) {\n return updateNode(root, id, (node) => (node.content === null ? node : { ...node, content: String(content ?? '') }));\n}\n\n/**\n * Inserts nodes into `parentId` at `index` (clamped).\n * @param {EmailNode} root @param {string} parentId @param {number} index @param {EmailNode[]} nodes\n */\nexport function insertNodes(root, parentId, index, nodes) {\n return updateNode(root, parentId, (parent) => {\n const at = Math.max(0, Math.min(index, parent.children.length));\n const children = [...parent.children];\n children.splice(at, 0, ...nodes);\n return { ...parent, children };\n });\n}\n\n/** @param {EmailNode} root @param {string} id */\nexport function removeNode(root, id) {\n const parent = parentOf(root, id);\n if (!parent) return root;\n return updateNode(root, parent.id, (p) => ({ ...p, children: p.children.filter((c) => c.id !== id) }));\n}\n\n/**\n * Moves a node under `parentId` at `index`, where `index` counts the target's\n * children BEFORE the node leaves its place (what a drop indicator shows).\n * @param {EmailNode} root @param {string} id @param {string} parentId @param {number} index\n */\nexport function moveNode(root, id, parentId, index) {\n const node = findNode(root, id);\n const from = parentOf(root, id);\n if (!node || !from) return root;\n // A node cannot go inside itself.\n if (pathTo(node, parentId)) return root;\n let at = index;\n if (from.id === parentId) {\n const current = from.children.findIndex((c) => c.id === id);\n if (current < at) at -= 1;\n if (current === at) return root;\n }\n return insertNodes(removeNode(root, id), parentId, at, [node]);\n}\n\n/**\n * Index of a node among its siblings, and their count.\n * @param {EmailNode} root @param {string} id\n */\nexport function positionOf(root, id) {\n const parent = parentOf(root, id);\n if (!parent) return { parent: null, index: -1, count: 0 };\n return { parent, index: parent.children.findIndex((c) => c.id === id), count: parent.children.length };\n}\n\n/* ── Snapshot (the stored project) ───────────────────────────────────────── */\n\n/** Shape version of the stored project (`{ format, root }`). */\nexport const PROJECT_FORMAT = 1;\n\n/** @param {EmailNode} root */\nexport function toProject(root) {\n return { format: PROJECT_FORMAT, root: strip(root) };\n}\n\n/** @param {EmailNode} node @returns {any} */\nfunction strip(node) {\n /** @type {any} */\n const out = { id: node.id, tag: node.tag };\n if (Object.keys(node.attributes).length) out.attributes = { ...node.attributes };\n if (node.content !== null) out.content = node.content;\n if (node.children.length) out.children = node.children.map(strip);\n return out;\n}\n\n/**\n * Reads a stored project back into a tree. Ids are kept when they are valid\n * and unique, replaced otherwise. Throws on anything that is not a project of\n * this format.\n * @param {unknown} project\n * @returns {EmailNode}\n */\nexport function fromProject(project) {\n const value = /** @type {any} */ (project);\n if (!value || typeof value !== 'object' || value.format !== PROJECT_FORMAT || !value.root) {\n throw new Error('Not a project of this builder');\n }\n const seen = new Set();\n /** @param {any} raw @returns {EmailNode} */\n const read = (raw) => {\n if (!raw || typeof raw !== 'object' || typeof raw.tag !== 'string' || !/^(mjml|mj-[a-z-]+)$/.test(raw.tag)) {\n throw new Error('Invalid element in the project');\n }\n let id = typeof raw.id === 'string' && /^[a-z0-9]{1,40}$/.test(raw.id) ? raw.id : createId();\n if (seen.has(id)) id = createId();\n seen.add(id);\n /** @type {Record<string, string>} */\n const attributes = {};\n for (const [k, v] of Object.entries(raw.attributes || {})) {\n if (/^[a-z][a-z0-9-]*$/i.test(k) && v !== null && v !== undefined) attributes[k] = String(v);\n }\n return createNode(raw.tag, {\n id,\n attributes,\n content: ENDING_TAGS.has(raw.tag) ? String(raw.content ?? '') : null,\n children: ENDING_TAGS.has(raw.tag) ? [] : (Array.isArray(raw.children) ? raw.children : []).map(read),\n });\n };\n const root = read(value.root);\n if (root.tag !== 'mjml' || !findFirst(root, 'mj-body')) throw new Error('The project has no email body');\n return root;\n}\n","// @ts-check\n/** Editor-only box properties travel through valid MJML as a CSS class. */\nconst PREFIX = 'eb-box-';\nconst KEYS = new Set(['margin', 'box-padding', 'box-border', 'box-border-top', 'box-border-right', 'box-border-bottom', 'box-border-left']);\n\n/** @param {string} tag @param {Record<string, string>} attributes */\nexport function encodeBox(tag, attributes) {\n const custom = Object.fromEntries(Object.entries(attributes).filter(([key]) => KEYS.has(key) && !(tag === 'mj-section' && key === 'margin')));\n if (!Object.keys(custom).length) return attributes;\n const out = { ...attributes };\n for (const key of Object.keys(custom)) delete out[key];\n const code = [...JSON.stringify(custom)].map((c) => c.charCodeAt(0).toString(16).padStart(4, '0')).join('');\n out['css-class'] = `${out['css-class'] || ''} ${PREFIX}${code}`.trim();\n return out;\n}\n\n/** @param {Record<string, string>} attributes */\nexport function decodeBox(attributes) {\n const classes = String(attributes['css-class'] || '').split(/\\s+/);\n const out = { ...attributes };\n const kept = classes.filter((name) => {\n if (!name.startsWith(PREFIX) || !/^(?:[a-f0-9]{4})+$/.test(name.slice(PREFIX.length))) return true;\n try {\n const json = name.slice(PREFIX.length).replace(/.{4}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));\n const values = JSON.parse(json);\n for (const [key, value] of Object.entries(values)) if (KEYS.has(key) && typeof value === 'string') out[key] = value;\n return false;\n } catch { return true; }\n });\n if (kept.filter(Boolean).length) out['css-class'] = kept.filter(Boolean).join(' ');\n else delete out['css-class'];\n return out;\n}\n\n/** The native outer padding of visual blocks already means outside spacing. @param {string} tag */\nexport function boxKeys(tag) {\n const outside = ['mj-image', 'mj-button', 'mj-divider', 'mj-social'].includes(tag);\n return {\n margin: outside ? 'padding' : 'margin',\n border: ['mj-image', 'mj-button', 'mj-column', 'mj-section'].includes(tag) ? 'border' : 'box-border',\n padding: tag === 'mj-button' ? 'inner-padding' : outside || ['mj-spacer', 'mj-navbar', 'mj-social-element'].includes(tag) ? 'box-padding' : 'padding',\n };\n}\n","// @ts-check\n/**\n * MJML ⇄ MODEL — reading MJML into the builder's tree, writing it back.\n *\n * MJML is close enough to XML to be read by a small scanner, and only two\n * kinds of element exist:\n * - containers (`mj-section`, `mj-column`…), made of other MJML elements;\n * - \"ending\" elements (`mj-text`, `mj-button`…), whose inside is HTML kept\n * as is, up to the matching closing tag.\n * Anything else between containers (stray text, comments, HTML outside an\n * ending element) is not MJML and is dropped.\n *\n * Attribute values are DECODED in the model (`&` → `&`) and encoded again\n * on write: the model holds what the attribute means, the MJML how to write\n * it.\n *\n * Two model attributes are written as wrappers in MJML:\n * `margin` on a section becomes the padding of an `eb-section-margin`\n * wrapper, outside the section's border and its own padding.\n * `content-background-color` on\n * `mj-body`, the color painted under the content, at the email's width. A\n * section with rounded corners shows it in its corners instead of the page\n * background. MJML has no such attribute: it is written as an `mj-wrapper`\n * around the sections (`eb-content-layer`), and read back into the body.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\nimport { ENDING_TAGS, createNode, findFirst } from './model.js';\nimport { decodeBox, encodeBox } from '../core/blockBox.js';\n\n/** @typedef {import('./model.js').EmailNode} EmailNode */\n\n/** The color under the content, kept on `mj-body` in the model. */\nexport const CONTENT_BACKGROUND = 'content-background-color';\n/** The class of the `mj-wrapper` it is written as. */\nexport const CONTENT_LAYER_CLASS = 'eb-content-layer';\n/** A section's outside spacing, written as valid MJML rather than a margin attribute. */\nexport const SECTION_MARGIN_CLASS = 'eb-section-margin';\n\n/**\n * Sections the layer goes under. A band across the whole screen cannot be in\n * an `mj-wrapper` (it would shrink to the content's width), nor can another\n * wrapper: they split the layer in two.\n * @param {EmailNode} node\n */\nconst underLayer = (node) =>\n (node.tag === 'mj-section' && !node.attributes.margin && node.attributes['full-width'] !== 'full-width') || node.tag === 'mj-hero';\n\n/** @param {EmailNode} node */\nconst isContentLayer = (node) =>\n node.tag === 'mj-wrapper' && String(node.attributes['css-class'] || '').split(/\\s+/).includes(CONTENT_LAYER_CLASS);\n\nconst NAMED_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '\"', apos: \"'\", nbsp: ' ' };\n\n/** @param {string} value */\nexport function decodeAttribute(value) {\n return value.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (match, entity) => {\n if (entity[0] === '#') {\n const code = entity[1] === 'x' || entity[1] === 'X' ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);\n return Number.isFinite(code) && code > 0 && code < 0x110000 ? String.fromCodePoint(code) : match;\n }\n const named = /** @type {Record<string, string>} */ (NAMED_ENTITIES)[entity.toLowerCase()];\n return named ?? match;\n });\n}\n\n/** @param {string} value */\nexport function encodeAttribute(value) {\n return String(value).replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\n}\n\n/**\n * Reads the attributes of an opening tag, from `start` (just after the name)\n * to its `>`. Quotes may contain `>`.\n * @param {string} source @param {number} start\n * @returns {{attributes: Record<string, string>, end: number, selfClosing: boolean}}\n */\nfunction readAttributes(source, start) {\n /** @type {Record<string, string>} */\n const attributes = {};\n let i = start;\n const n = source.length;\n while (i < n) {\n while (i < n && /\\s/.test(source[i])) i += 1;\n if (source[i] === '>') return { attributes, end: i + 1, selfClosing: false };\n if (source[i] === '/' && source[i + 1] === '>') return { attributes, end: i + 2, selfClosing: true };\n if (i >= n) break;\n const nameMatch = /^[^\\s=/>\"']+/.exec(source.slice(i, i + 200));\n if (!nameMatch) {\n i += 1;\n continue;\n }\n const name = nameMatch[0].toLowerCase();\n i += nameMatch[0].length;\n while (i < n && /\\s/.test(source[i])) i += 1;\n let value = '';\n if (source[i] === '=') {\n i += 1;\n while (i < n && /\\s/.test(source[i])) i += 1;\n const quote = source[i];\n if (quote === '\"' || quote === \"'\") {\n const close = source.indexOf(quote, i + 1);\n const stop = close === -1 ? n : close;\n value = source.slice(i + 1, stop);\n i = stop + 1;\n } else {\n let bare = /^[^\\s>]*/.exec(source.slice(i))?.[0] || '';\n // `width=100/>`: the slash closes the tag, it is not in the value.\n if (bare.endsWith('/') && source[i + bare.length] === '>') bare = bare.slice(0, -1);\n value = bare;\n i += bare.length;\n }\n }\n attributes[name] = decodeAttribute(value);\n }\n return { attributes, end: n, selfClosing: false };\n}\n\n/**\n * MJML elements of a fragment (no `<mjml>` needed): `<mj-section>…</mj-section><mj-section>…`.\n * @param {string} source\n * @returns {EmailNode[]}\n */\nexport function parseMjmlFragment(source) {\n const text = String(source || '').replace(/^\\uFEFF/, '');\n /** @type {EmailNode} */\n const top = createNode('mj-fragment');\n /** @type {EmailNode[]} */\n const stack = [top];\n let i = 0;\n const n = text.length;\n\n while (i < n) {\n const lt = text.indexOf('<', i);\n if (lt === -1) break;\n i = lt;\n if (text.startsWith('<!--', i)) {\n const close = text.indexOf('-->', i + 4);\n i = close === -1 ? n : close + 3;\n continue;\n }\n if (text.startsWith('<?', i) || text.startsWith('<!', i)) {\n const close = text.indexOf('>', i);\n i = close === -1 ? n : close + 1;\n continue;\n }\n const closing = text[i + 1] === '/';\n const nameMatch = /^[a-z][a-z0-9-]*/i.exec(text.slice(i + (closing ? 2 : 1), i + 60));\n if (!nameMatch) {\n i += 1;\n continue;\n }\n const tag = nameMatch[0].toLowerCase();\n const afterName = i + (closing ? 2 : 1) + nameMatch[0].length;\n const isMjml = tag === 'mjml' || tag.startsWith('mj-');\n\n if (closing) {\n const close = text.indexOf('>', afterName);\n i = close === -1 ? n : close + 1;\n if (!isMjml) continue;\n // Close up to the matching element (tolerates a forgotten closing tag).\n for (let depth = stack.length - 1; depth > 0; depth -= 1) {\n if (stack[depth].tag === tag) {\n stack.length = depth;\n break;\n }\n }\n continue;\n }\n\n const { attributes: written, end, selfClosing } = readAttributes(text, afterName);\n const attributes = decodeBox(written);\n i = end;\n if (!isMjml) continue;\n\n const parent = stack[stack.length - 1];\n if (ENDING_TAGS.has(tag)) {\n let content = '';\n if (!selfClosing) {\n const closeRe = new RegExp(`</${tag}\\\\s*>`, 'ig');\n closeRe.lastIndex = i;\n const close = closeRe.exec(text);\n const stop = close ? close.index : n;\n content = text.slice(i, stop).trim();\n i = close ? close.index + close[0].length : n;\n }\n parent.children.push(createNode(tag, { attributes, content }));\n continue;\n }\n const node = createNode(tag, { attributes });\n parent.children.push(node);\n if (!selfClosing) stack.push(node);\n }\n return top.children;\n}\n\n/**\n * A whole email. Always returns an `mjml` root holding an `mj-body`: a bare\n * fragment is wrapped, a missing body is added.\n * @param {string} source\n * @returns {EmailNode}\n */\nexport function parseMjml(source) {\n const nodes = parseMjmlFragment(source);\n let root = nodes.find((node) => node.tag === 'mjml') || null;\n if (!root) {\n const body = nodes.find((node) => node.tag === 'mj-body');\n const head = nodes.find((node) => node.tag === 'mj-head');\n root = createNode('mjml', {\n children: [\n ...(head ? [head] : []),\n body || createNode('mj-body', { children: nodes.filter((node) => node.tag !== 'mj-head') }),\n ],\n });\n }\n const body = findFirst(root, 'mj-body');\n if (!body) root.children.push(createNode('mj-body'));\n else {\n const layer = body.children.find((child) => isContentLayer(child) ||\n (child.tag === 'mj-wrapper' && child.attributes['css-class'] === SECTION_MARGIN_CLASS && child.attributes['background-color']));\n const color = layer?.attributes['background-color'];\n if (color) body.attributes[CONTENT_BACKGROUND] = color;\n body.children = body.children.flatMap((child) => (isContentLayer(child) ? child.children : [child]));\n }\n const restoreMargins = (/** @type {EmailNode} */ parent) => {\n parent.children = parent.children.flatMap((child) => {\n if (child.tag === 'mj-wrapper' && String(child.attributes['css-class'] || '').split(/\\s+/).includes(SECTION_MARGIN_CLASS) &&\n child.children.length === 1 && child.children[0].tag === 'mj-section') {\n const section = child.children[0];\n section.attributes.margin = child.attributes.padding || '0px';\n if (child.attributes['full-width']) section.attributes['full-width'] = child.attributes['full-width'];\n return [section];\n }\n restoreMargins(child);\n return [child];\n });\n };\n restoreMargins(root);\n return root;\n}\n\n/**\n * The MJML of a tree. `pretty`: one element per line, indented (what is\n * stored and downloaded); otherwise on one line.\n * @param {EmailNode} node\n * @param {{pretty?: boolean, attributes?: (node: EmailNode) => Record<string, string>, extraChildren?: (node: EmailNode) => string}} [options]\n * `attributes`: replaces a node's attributes on write (the canvas adds its\n * markers there); `extraChildren`: MJML appended inside a container.\n */\nexport function serializeMjml(node, options = {}) {\n const { pretty = true } = options;\n /** @param {Record<string, string>} attributes */\n const attrsOf = (attributes) =>\n Object.entries(attributes)\n .map(([key, value]) => ` ${key}=\"${encodeAttribute(value)}\"`)\n .join('');\n /** @param {string} tag @param {Record<string, string>} attributes @param {string[]} inner @param {number} depth */\n const element = (tag, attributes, inner, depth) => {\n const indent = pretty ? ' '.repeat(depth) : '';\n const attrs = attrsOf(attributes);\n if (!inner.length) return `${indent}<${tag}${attrs} />`;\n return pretty ? `${indent}<${tag}${attrs}>\\n${inner.join('\\n')}\\n${indent}</${tag}>` : `<${tag}${attrs}>${inner.join('')}</${tag}>`;\n };\n /** The body's children, each run of sections under the layer in its `mj-wrapper`. @param {EmailNode} body @param {number} depth */\n const layered = (body, depth) => {\n const layer = { 'css-class': CONTENT_LAYER_CLASS, 'background-color': body.attributes[CONTENT_BACKGROUND], padding: '0px' };\n /** @type {string[]} */\n const out = [];\n /** @type {EmailNode[]} */\n let run = [];\n const flush = () => {\n if (run.length) out.push(element('mj-wrapper', layer, run.map((child) => write(child, depth + 2)), depth + 1));\n run = [];\n };\n for (const child of body.children) {\n if (underLayer(child)) run.push(child);\n else {\n flush();\n out.push(write(child, depth + 1));\n }\n }\n flush();\n return out;\n };\n /** @param {EmailNode} current @param {number} depth @returns {string} */\n const write = (current, depth) => {\n let attributes = encodeBox(current.tag, options.attributes ? options.attributes(current) : current.attributes);\n const margin = current.tag === 'mj-section' ? attributes.margin : null;\n if (margin) {\n const { margin: _margin, 'full-width': _fullWidth, ...sectionAttributes } = attributes;\n /** @type {Record<string, string>} */\n const wrapperAttributes = { 'css-class': SECTION_MARGIN_CLASS, padding: margin };\n if (attributes['full-width']) wrapperAttributes['full-width'] = attributes['full-width'];\n const background = findFirst(node, 'mj-body')?.attributes[CONTENT_BACKGROUND];\n if (background && !attributes['full-width']) wrapperAttributes['background-color'] = background;\n return element('mj-wrapper', wrapperAttributes, [\n element(current.tag, sectionAttributes, current.children.map((child) => write(child, depth + 2)), depth + 1),\n ], depth);\n }\n if (current.tag === 'mj-body' && CONTENT_BACKGROUND in attributes) {\n const { [CONTENT_BACKGROUND]: _layer, ...mjml } = attributes;\n attributes = mjml;\n }\n if (current.content !== null) {\n return `${pretty ? ' '.repeat(depth) : ''}<${current.tag}${attrsOf(attributes)}>${current.content}</${current.tag}>`;\n }\n const inner =\n current.tag === 'mj-body' && current.attributes[CONTENT_BACKGROUND]\n ? layered(current, depth)\n : current.children.map((child) => write(child, depth + 1));\n const extra = options.extraChildren ? options.extraChildren(current) : '';\n if (extra) inner.push(pretty ? `${' '.repeat(depth + 1)}${extra}` : extra);\n return element(current.tag, attributes, inner, depth);\n };\n return write(node, 0);\n}\n","// @ts-check\n/**\n * Building blocks shared by all blocks: palette, fonts, recurring properties.\n *\n * -- DEFAULT PALETTE ---------------------------------------------------------\n * Plain hex values: email clients load no stylesheet and understand neither\n * `var()` nor modern color functions, so every value ends up inline in a\n * `style=\"\"` attribute.\n *\n * -- EVERY BLOCK SETS ITS OWN TEXT ATTRIBUTES --------------------------------\n * Font, size, line height and color are written on the element itself, never\n * left to MJML defaults (the \"Ubuntu\" font loaded from Google, line height 1):\n * the canvas and the sent email then render the same thing, and Outlook gets\n * explicit values.\n *\n * Fonts: only web-safe stacks, installed everywhere and understood by\n * Outlook - a web font only renders in a minority of email clients.\n */\n\n/** @typedef {import('../core/EmailEditor.js').BlockProperty} BlockProperty */\n\n/** Text for an MJML attribute or element. @param {string} text */\nexport function escapeXml(text) {\n return String(text ?? '')\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n\n/** The default palette. */\nexport const PALETTE = {\n ink: '#2b3038',\n inkSoft: '#41506b',\n navy: '#212e5a',\n brand: '#2977bc',\n border: '#dfe6f0',\n canvas: '#eceff4',\n surface: '#ffffff',\n white: '#ffffff',\n};\n\n/** Default link of a new button. */\nexport const DEFAULT_BUTTON_URL = 'https://example.com';\n\nexport const FONT_STACK = 'Arial, Helvetica, sans-serif';\n\n/** @type {{value: string, label: string}[]} */\nexport const FONT_OPTIONS = [\n { value: 'Arial, Helvetica, sans-serif', label: 'Arial' },\n { value: 'Verdana, Geneva, sans-serif', label: 'Verdana' },\n { value: 'Tahoma, Geneva, sans-serif', label: 'Tahoma' },\n { value: \"'Trebuchet MS', Helvetica, sans-serif\", label: 'Trebuchet' },\n { value: 'Georgia, Times, serif', label: 'Georgia' },\n { value: \"'Times New Roman', Times, serif\", label: 'Times' },\n { value: \"'Courier New', Courier, monospace\", label: 'Courier' },\n];\n\n/** @type {{value: string, label: string}[]} */\nexport const ALIGN_OPTIONS = [\n { value: 'left', label: 'Left' },\n { value: 'center', label: 'Center' },\n { value: 'right', label: 'Right' },\n];\n\n/** Properties panel groups, in display order. */\nexport const GROUPS = {\n content: 'Content',\n link: 'Link',\n typography: 'Typography',\n colors: 'Colors',\n layout: 'Layout',\n spacing: 'Spacing',\n};\n\n/** Recurring properties. */\nexport const prop = {\n /** @returns {BlockProperty} */\n fontFamily: () => ({ key: 'font-family', label: 'Font', type: 'select', group: GROUPS.typography, options: FONT_OPTIONS }),\n /** @returns {BlockProperty} */\n fontSize: (min = 10, max = 48) => ({ key: 'font-size', label: 'Size', type: 'size', group: GROUPS.typography, min, max, unit: 'px' }),\n /** @returns {BlockProperty} */\n lineHeight: () => ({ key: 'line-height', label: 'Line height', type: 'size', group: GROUPS.typography, min: 10, max: 80, unit: 'px' }),\n /** @returns {BlockProperty} */\n color: (label = 'Text') => ({ key: 'color', label, type: 'color', group: GROUPS.colors }),\n /** @returns {BlockProperty} */\n background: (key = 'background-color', label = 'Background') => ({ key, label, type: 'color', group: GROUPS.colors }),\n /** @returns {BlockProperty} */\n align: (options = ALIGN_OPTIONS) => ({ key: 'align', label: 'Alignment', type: 'align', group: GROUPS.layout, options }),\n /** Align the containing column, or every column of a layout. @returns {BlockProperty} */\n verticalAlign: () => ({ key: 'vertical-align', label: 'Vertical alignment', type: 'select', group: GROUPS.layout,\n options: [{ value: 'top', label: 'Top' }, { value: 'middle', label: 'Middle' }, { value: 'bottom', label: 'Bottom' }] }),\n /**\n * `box`: where the box diagram shows it — `margin` when the space is outside\n * what the reader sees as the block (a button, an image), `padding` inside.\n * @param {'margin'|'padding'} [box]\n * @returns {BlockProperty}\n */\n padding: (key = 'padding', label = 'Padding', box = undefined) => ({ key, label, type: 'spacing', group: GROUPS.spacing, ...(box ? { box } : {}) }),\n /** A line around the block: widths, style, color, in one value. @returns {BlockProperty} */\n border: () => ({ key: 'border', label: 'Border', type: 'border', group: GROUPS.spacing, box: 'border' }),\n /** @returns {BlockProperty} */\n href: (label = 'Link URL') => ({ key: 'href', label, type: 'url', group: GROUPS.link, placeholder: 'https://' }),\n /**\n * `%` only where the box is square enough to want it (an image, an icon: 50 % is a circle):\n * on a wide button or section, a percentage of the width and of the height makes an oval.\n * @returns {BlockProperty}\n */\n radius: (units = ['px', '%']) => ({ key: 'border-radius', label: 'Corner radius', type: 'size', group: GROUPS.layout, min: 0, unit: 'px', ...(units.length > 1 ? { units } : {}) }),\n};\n\n/**\n * White one-column section: the wrapper of a content block dropped outside\n * any column (MJML does not accept text directly inside the body).\n *\n * Warning: padding in LONGHAND form, never `padding=\"...\"`. The canvas starts\n * from the longhand defaults (20 px for a section), which override the\n * shorthand, while the export omits them - the screen and the email would\n * diverge (see core/mjmlAttributes).\n *\n * @param {string} inner\n */\nexport function inWhiteSection(inner) {\n return (\n `<mj-section background-color=\"${PALETTE.surface}\" padding-top=\"0px\" padding-bottom=\"0px\">` +\n `<mj-column>${inner}</mj-column></mj-section>`\n );\n}\n","// @ts-check\n/**\n * BRAND — the look of a company's emails: its name, its logo, a main color,\n * a color for headings, a font and a text size. Set once (by hand, or read from the\n * company's website), it is used by every new email, template and block,\n * and can be applied to the email being edited.\n *\n * `applyBrand` repaints an email by ROLE, not by exact color, so it works on\n * any email — a template, an imported one, one the user built:\n *\n * buttons filled with the main color, text in the color that\n * reads on it (white or ink);\n * colored sections (banners) take the main color; their texts and\n * buttons switch to what reads on it;\n * headings (bold, 18 px and more, on white) take the headings\n * color; body text and gray footers keep theirs;\n * colored links take the main color, or the headings color when the\n * main one is too light to read on white;\n * fonts every text, button and menu link;\n * text size paragraphs (not bold, 13 to 18 px, not gray): their\n * line height follows; headings, labels and footers\n * keep theirs;\n * header (optional) the logo — or the name — at the top, and\n * the name in the footer.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\nimport { FONT_OPTIONS, PALETTE, escapeXml } from '../../blocks/shared.js';\nimport { createNode } from '../../engine/model.js';\nimport { parseMjml, parseMjmlFragment, serializeMjml } from '../../engine/mjml.js';\n\n/**\n * @typedef {{\n * name?: string,\n * logoUrl?: string,\n * logoWidth?: number,\n * primary?: string,\n * heading?: string,\n * font?: string,\n * fontSize?: number,\n * website?: string,\n * }} Brand\n * `primary`: buttons, banners, links; `heading`: headings; colors as\n * `#rrggbb`. `font`: one of the builder's web-safe stacks (FONT_OPTIONS).\n * `fontSize`: the paragraphs' size in px (BRAND_FONT_SIZES).\n * `website`: where it was read from, to read it again.\n *\n * @typedef {import('../../engine/model.js').EmailNode} EmailNode\n */\n\nconst HEX = /^#[0-9a-f]{6}$/;\nconst FONTS = new Set(FONT_OPTIONS.map((option) => option.value));\nexport const MAX_LOGO_WIDTH = 240;\n/** The paragraphs' sizes a brand offers, in px; the builder's own is 15. */\nexport const BRAND_FONT_SIZES = [13, 14, 15, 16, 17, 18];\n\n/* ── Colors ─────────────────────────────────────────────────────────────── */\n\n/**\n * A CSS color as RGB(A), or null: #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(),\n * rgba(), hsl(), hsla(), and the keywords white and black.\n * @param {unknown} value\n * @returns {{r: number, g: number, b: number, a: number}|null}\n */\nexport function parseColor(value) {\n const source = String(value ?? '').trim().toLowerCase();\n if (source === 'white') return { r: 255, g: 255, b: 255, a: 1 };\n if (source === 'black') return { r: 0, g: 0, b: 0, a: 1 };\n let match = source.match(/^#([0-9a-f]{3,8})$/);\n if (match) {\n const hex = match[1];\n if (hex.length === 3 || hex.length === 4) {\n const [r, g, b, a = 'ff'] = hex.split('').map((c) => c + c);\n return { r: parseInt(r, 16), g: parseInt(g, 16), b: parseInt(b, 16), a: parseInt(a, 16) / 255 };\n }\n if (hex.length === 6 || hex.length === 8) {\n return {\n r: parseInt(hex.slice(0, 2), 16),\n g: parseInt(hex.slice(2, 4), 16),\n b: parseInt(hex.slice(4, 6), 16),\n a: hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1,\n };\n }\n return null;\n }\n match = source.match(/^(rgba?|hsla?)\\(([^)]*)\\)$/);\n if (!match) return null;\n const parts = match[2].split(/[\\s,/]+/).filter(Boolean);\n if (parts.length < 3) return null;\n const alpha = parts[3] === undefined ? 1 : parts[3].endsWith('%') ? parseFloat(parts[3]) / 100 : parseFloat(parts[3]);\n if (match[1].startsWith('rgb')) {\n const channel = (/** @type {string} */ part) => (part.endsWith('%') ? (parseFloat(part) * 255) / 100 : parseFloat(part));\n const [r, g, b] = parts.slice(0, 3).map(channel);\n if ([r, g, b, alpha].some((n) => Number.isNaN(n))) return null;\n const clamp = (/** @type {number} */ n) => Math.max(0, Math.min(255, Math.round(n)));\n return { r: clamp(r), g: clamp(g), b: clamp(b), a: alpha };\n }\n const h = parseFloat(parts[0]);\n const s = parseFloat(parts[1]) / 100;\n const l = parseFloat(parts[2]) / 100;\n if ([h, s, l, alpha].some((n) => Number.isNaN(n))) return null;\n return { ...fromHsl(((h % 360) + 360) % 360, Math.max(0, Math.min(1, s)), Math.max(0, Math.min(1, l))), a: alpha };\n}\n\n/** @param {number} h @param {number} s @param {number} l */\nfunction fromHsl(h, s, l) {\n const c = (1 - Math.abs(2 * l - 1)) * s;\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1));\n const m = l - c / 2;\n const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];\n return { r: Math.round((r + m) * 255), g: Math.round((g + m) * 255), b: Math.round((b + m) * 255) };\n}\n\n/** @param {{r: number, g: number, b: number}} color */\nexport const toHex = ({ r, g, b }) => `#${[r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('')}`;\n\n/** Hue (0-360), saturation and lightness (0-1). @param {{r: number, g: number, b: number}} color */\nexport function toHsl({ r, g, b }) {\n const [R, G, B] = [r / 255, g / 255, b / 255];\n const max = Math.max(R, G, B);\n const min = Math.min(R, G, B);\n const l = (max + min) / 2;\n if (max === min) return { h: 0, s: 0, l };\n const d = max - min;\n const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n const h = max === R ? ((G - B) / d + (G < B ? 6 : 0)) * 60 : max === G ? ((B - R) / d + 2) * 60 : ((R - G) / d + 4) * 60;\n return { h, s, l };\n}\n\n/** WCAG relative luminance. @param {{r: number, g: number, b: number}} color */\nfunction luminance({ r, g, b }) {\n const linear = (/** @type {number} */ n) => {\n const c = n / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** WCAG contrast ratio of two colors (1 to 21). @param {string} a @param {string} b */\nexport function contrastRatio(a, b) {\n const ca = parseColor(a);\n const cb = parseColor(b);\n if (!ca || !cb) return 1;\n const [hi, lo] = [luminance(ca), luminance(cb)].sort((x, y) => y - x);\n return (hi + 0.05) / (lo + 0.05);\n}\n\n/** The text color that reads on `background`: white or ink. @param {string} background */\nexport function readableOn(background) {\n return contrastRatio(background, PALETTE.white) >= contrastRatio(background, PALETTE.ink) ? PALETTE.white : PALETTE.ink;\n}\n\n/**\n * A color meant to be noticed (a banner, a filled button), as opposed to\n * white, light tints, grays and near-black.\n * @param {unknown} value\n */\nexport function isColored(value) {\n const color = parseColor(value);\n if (!color || color.a < 0.5) return false;\n const { s, l } = toHsl(color);\n return s >= 0.2 && l >= 0.08 && l <= 0.88;\n}\n\n/** Dark enough to carry white text (navy, charcoal…). @param {unknown} value */\nfunction isDark(value) {\n const color = parseColor(value);\n return Boolean(color && color.a >= 0.5 && luminance(color) < 0.12);\n}\n\n/** A light gray (footers, captions): left as it is. @param {unknown} value */\nfunction isMuted(value) {\n const color = parseColor(value);\n if (!color) return false;\n const { s, l } = toHsl(color);\n return s < 0.2 && l > 0.4;\n}\n\n/* ── The brand itself ───────────────────────────────────────────────────── */\n\n/** @param {unknown} value */\nconst cleanColor = (value) => {\n const color = parseColor(value);\n return color && color.a >= 0.5 ? toHex(color) : '';\n};\n\n/**\n * A brand as stored and used: unknown fields dropped, colors as #rrggbb,\n * the font one of the builder's stacks, the logo an https or site-relative\n * image. Whatever is invalid is left out (the builder's default is used).\n * @param {unknown} input\n * @returns {Brand}\n */\nexport function cleanBrand(input) {\n const source = /** @type {Record<string, unknown>} */ (input && typeof input === 'object' ? input : {});\n /** @type {Brand} */\n const brand = {};\n const name = typeof source.name === 'string' ? source.name.replace(/\\s+/g, ' ').trim().slice(0, 80) : '';\n if (name) brand.name = name;\n const logo = typeof source.logoUrl === 'string' ? source.logoUrl.trim() : '';\n if (logo && logo.length <= 2000 && (/^https:\\/\\/[^\\s\"'<>]+$/i.test(logo) || /^\\/(?!\\/)[^\\s\"'<>]*$/.test(logo))) {\n brand.logoUrl = logo;\n const width = Math.round(Number(source.logoWidth));\n if (width >= 24 && width <= MAX_LOGO_WIDTH) brand.logoWidth = width;\n }\n const primary = cleanColor(source.primary);\n if (primary && HEX.test(primary)) brand.primary = primary;\n const heading = cleanColor(source.heading);\n if (heading && HEX.test(heading)) brand.heading = heading;\n if (typeof source.font === 'string' && FONTS.has(source.font)) brand.font = source.font;\n const fontSize = Number(source.fontSize);\n if (BRAND_FONT_SIZES.includes(fontSize)) brand.fontSize = fontSize;\n const website = typeof source.website === 'string' ? source.website.trim() : '';\n if (/^https?:\\/\\/[^\\s\"'<>]+$/i.test(website) && website.length <= 500) brand.website = website;\n return brand;\n}\n\n/** Does the brand change anything? @param {Brand|null|undefined} brand */\nexport const hasBrand = (brand) => Boolean(brand && Object.keys(cleanBrand(brand)).some((key) => key !== 'website'));\n\n/**\n * The sender the templates use: the brand's name and logo over the host's\n * sender (whose postal address stays).\n * @param {import('../templates/starter.js').StarterSender|null|undefined} sender\n * @param {Brand|null|undefined} brand\n */\nexport function brandedSender(sender, brand) {\n const base = { ...(sender || {}) };\n if (!brand) return base;\n if (brand.name) base.name = brand.name;\n if (brand.logoUrl) {\n base.logoUrl = brand.logoUrl;\n base.logoWidth = brand.logoWidth || base.logoWidth;\n }\n return base;\n}\n\n/**\n * The colors applyBrand paints with.\n * @param {Brand} brand\n */\nfunction paletteOf(brand) {\n const primary = brand.primary || null;\n return {\n primary,\n onPrimary: primary ? readableOn(primary) : null,\n heading: brand.heading || null,\n // A link must read on white: a too-light main color gives way.\n link: primary ? (contrastRatio(primary, PALETTE.white) >= 3 ? primary : brand.heading || PALETTE.ink) : null,\n font: brand.font || null,\n fontSize: brand.fontSize || null,\n };\n}\n\n/* ── Painting ───────────────────────────────────────────────────────────── */\n\nconst SECTION_LIKE = new Set(['mj-section', 'mj-wrapper', 'mj-hero', 'mj-column', 'mj-group']);\nconst FONT_TAGS = new Set(['mj-text', 'mj-button', 'mj-navbar-link', 'mj-social-element', 'mj-table']);\n\n/** @param {string|undefined} size */\nconst px = (size) => {\n const n = parseFloat(String(size ?? ''));\n return Number.isNaN(n) ? 0 : n;\n};\n\n/** @param {string|undefined} weight */\nconst isBold = (weight) => /^(bold|bolder|[6-9]00)$/.test(String(weight ?? '').trim());\n\n/**\n * A paragraph's attributes in a new size, its line height in proportion (a\n * text without a size has MJML's 13 px).\n * @param {Record<string, string>} attributes @param {number} size\n */\nfunction resize(attributes, size) {\n const from = px(attributes['font-size']) || 13;\n const lineHeight = String(attributes['line-height'] ?? '').trim();\n attributes['font-size'] = `${size}px`;\n if (/^\\d+(\\.\\d+)?px$/.test(lineHeight)) attributes['line-height'] = `${Math.round((px(lineHeight) * size) / from)}px`;\n}\n\n/**\n * The links of a text in a new color, when theirs is a color (a gray or a\n * black link is a choice, and stays).\n * @param {string} html @param {string} color\n */\nfunction recolorLinks(html, color) {\n return html.replace(/<a\\b[^>]*>/gi, (tag) =>\n tag.replace(/(style\\s*=\\s*\")([^\"]*)(\")/i, (_, open, style, close) =>\n `${open}${style.replace(/(^|;)(\\s*color\\s*:\\s*)([^;]+)/i, (whole, sep, prop, value) =>\n isColored(value) ? `${sep}${prop}${color}` : whole\n )}${close}`\n )\n );\n}\n\n/**\n * One node and what it holds, in the brand's colors.\n * @param {EmailNode} node\n * @param {ReturnType<typeof paletteOf>} palette\n * @param {boolean} onColor the node sits on a colored background\n * @returns {EmailNode}\n */\nfunction paint(node, palette, onColor) {\n const attributes = { ...node.attributes };\n let content = node.content;\n let childrenOnColor = onColor;\n const set = (/** @type {string} */ key, /** @type {string|null} */ value) => {\n if (value) attributes[key] = value;\n };\n\n if (SECTION_LIKE.has(node.tag)) {\n const background = attributes['background-color'];\n if (background && palette.primary && (isColored(background) || (isDark(background) && node.tag !== 'mj-column'))) {\n attributes['background-color'] = palette.primary;\n childrenOnColor = true;\n } else if (background && parseColor(background)) {\n childrenOnColor = false;\n }\n }\n\n if (FONT_TAGS.has(node.tag) && palette.font) set('font-family', palette.font);\n\n if (node.tag === 'mj-text' && content !== null) {\n const size = px(attributes['font-size']) || 13;\n if (palette.fontSize && !isBold(attributes['font-weight']) && size >= 13 && size <= 18 && !isMuted(attributes.color)) {\n resize(attributes, palette.fontSize);\n }\n if (onColor) {\n set('color', palette.onPrimary);\n } else {\n const heading = isBold(attributes['font-weight']) && px(attributes['font-size']) >= 18;\n if (heading && palette.heading && !isMuted(attributes.color)) attributes.color = palette.heading;\n if (palette.link) content = recolorLinks(content, palette.link);\n }\n }\n\n if (node.tag === 'mj-button') {\n const background = attributes['background-color'];\n // MJML's own default is a dark gray: a button without color is filled.\n const filled = !background || isColored(background) || isDark(background);\n if (palette.primary && filled) {\n set('background-color', onColor ? palette.onPrimary : palette.primary);\n set('color', onColor ? palette.primary : palette.onPrimary);\n } else if (palette.primary && onColor) {\n // A light button on a banner: kept light, its text in the main color.\n set('color', readableOn(background) === PALETTE.ink && contrastRatio(palette.primary, background) < 3 ? PALETTE.ink : palette.primary);\n } else if (palette.link && isColored(attributes.color)) {\n // An outlined button on white.\n attributes.color = palette.link;\n if (isColored(attributes['border-color'])) attributes['border-color'] = palette.link;\n }\n }\n\n if (node.tag === 'mj-navbar-link' && isColored(attributes.color)) {\n set('color', onColor ? palette.onPrimary : palette.link);\n }\n\n const children = node.children.map((child) => paint(child, palette, childrenOnColor));\n return { ...node, attributes, content, children };\n}\n\n/** @param {string} html */\nconst plainText = (html) =>\n html\n .replace(/<[^>]*>/g, ' ')\n .replace(/ /g, ' ')\n .replace(/&/g, '&')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/** @param {EmailNode} body */\nconst sectionsOf = (body) =>\n body.children.flatMap((child) => (child.tag === 'mj-wrapper' ? child.children.filter((c) => c.tag === 'mj-section') : [child]));\n\n/**\n * The logo, or the name, at the top; the name in the footer.\n * @param {EmailNode} root\n * @param {Brand} brand\n * @param {{names: string[], logos: string[]}} previous what the email may still show\n * @returns {EmailNode}\n */\nfunction rebrandHeader(root, brand, previous) {\n const body = root.children.find((child) => child.tag === 'mj-body');\n if (!body) return root;\n const names = previous.names.map((name) => String(name || '').trim()).filter((name) => name.length >= 2);\n const known = new Set(names.map((name) => name.toLowerCase()));\n const sections = sectionsOf(body);\n /** @type {Map<string, EmailNode>} */\n const replaced = new Map();\n\n const top = sections[0];\n const column = top?.children.find((child) => child.tag === 'mj-column');\n const first = column?.children[0];\n if (first?.tag === 'mj-image') {\n const small = px(first.attributes.width) > 0 && px(first.attributes.width) <= MAX_LOGO_WIDTH;\n const wasLogo = small || previous.logos.includes(first.attributes.src) || known.has(String(first.attributes.alt || '').toLowerCase());\n if (wasLogo && brand.logoUrl) {\n replaced.set(first.id, {\n ...first,\n attributes: {\n ...first.attributes,\n src: brand.logoUrl,\n alt: brand.name || first.attributes.alt || '',\n width: `${brand.logoWidth || Math.min(px(first.attributes.width) || 140, MAX_LOGO_WIDTH)}px`,\n },\n });\n }\n } else if (first?.tag === 'mj-text' && first.content !== null && known.has(plainText(first.content).toLowerCase())) {\n if (brand.logoUrl) {\n const keep = Object.fromEntries(Object.entries(first.attributes).filter(([key]) => key.startsWith('padding') || key === 'align'));\n replaced.set(\n first.id,\n createNode('mj-image', {\n id: first.id,\n attributes: { src: brand.logoUrl, alt: brand.name || '', width: `${brand.logoWidth || 140}px`, align: 'left', ...keep },\n })\n );\n } else if (brand.name) {\n replaced.set(first.id, { ...first, content: escapeXml(brand.name) });\n }\n }\n\n // The footer: the old name in its line becomes the new one.\n const bottom = sections.length > 1 ? sections[sections.length - 1] : null;\n const newName = brand.name;\n if (bottom && newName) {\n const swap = (/** @type {EmailNode} */ node) => {\n if (node.tag === 'mj-text' && node.content !== null) {\n let html = node.content;\n for (const name of names) {\n if (name !== newName) html = html.split(escapeXml(name)).join(escapeXml(newName));\n }\n if (html !== node.content) replaced.set(node.id, { ...node, content: html });\n }\n node.children.forEach(swap);\n };\n swap(bottom);\n }\n\n if (!replaced.size) return root;\n const rebuild = (/** @type {EmailNode} */ node) => replaced.get(node.id) || { ...node, children: node.children.map(rebuild) };\n return rebuild(root);\n}\n\n/**\n * An email in the brand's look.\n * @param {string} mjml\n * @param {Brand|null|undefined} brand\n * @param {{header?: boolean, previous?: {names?: (string|undefined)[], logos?: (string|undefined)[]}}} [options]\n * `header`: also put the logo (or name) at the top and the name in the\n * footer, replacing what `previous` lists (the names and logos the email\n * may still show: the host's sender, the brand before, \"Your company\").\n * @returns {string}\n */\nexport function applyBrand(mjml, brand, { header = false, previous = {} } = {}) {\n const clean = cleanBrand(brand);\n if (!hasBrand(clean)) return mjml;\n let root = parseMjml(mjml);\n root = paint(root, paletteOf(clean), false);\n if (header) {\n root = rebrandHeader(root, clean, {\n names: /** @type {string[]} */ ((previous.names || []).filter(Boolean)),\n logos: /** @type {string[]} */ ((previous.logos || []).filter(Boolean)),\n });\n }\n return serializeMjml(root);\n}\n\n/**\n * A fragment (a block about to be inserted) in the brand's look.\n * @param {string} mjml @param {Brand|null|undefined} brand\n */\nexport function applyBrandToFragment(mjml, brand) {\n const clean = cleanBrand(brand);\n if (!mjml || !hasBrand(clean)) return mjml;\n const palette = paletteOf(clean);\n return parseMjmlFragment(mjml)\n .map((node) => serializeMjml(paint(node, palette, false), { pretty: false }))\n .join('');\n}\n\n/**\n * A ready-made email (the starter, a gallery template) in the brand's look,\n * its header and footer naming the brand rather than the host's sender or\n * the \"Your company\" placeholder.\n * @param {string} mjml\n * @param {Brand|null|undefined} brand\n * @param {{sender?: import('../templates/starter.js').StarterSender|null, t?: (key: string) => string}} [context]\n */\nexport function brandTemplate(mjml, brand, { sender = null, t = (key) => key } = {}) {\n return applyBrand(mjml, brand, {\n header: true,\n previous: { names: [sender?.name, t('Your company')], logos: [sender?.logoUrl] },\n });\n}\n","// @ts-check\n/**\n * TAGS — colored labels on templates, to sort a library at a glance.\n *\n * The workspace keeps one list of tags, shared by every user like the custom\n * variables; a template carries at most `MAX_TEMPLATE_TAGS` of them, by id.\n * A tag's name is unique (case aside) and its color is one of `TAG_COLORS`,\n * so every tag reads well in the light and the dark theme.\n *\n * The same rules run in the browser (the tags dialog, the memory storage) and\n * on the server (`best-email-builder/server`).\n */\n\nimport { identity } from '../../i18n/index.js';\n\n/** @typedef {{id: string, label: string, color: string}} TemplateTag */\n\nexport const MAX_TEMPLATE_TAGS = 3;\n/** Tags in a workspace. */\nexport const MAX_TAGS = 100;\nexport const TAG_LIMITS = { label: 24 };\nexport const TAG_COLORS = ['gray', 'red', 'orange', 'amber', 'lime', 'green', 'teal', 'cyan', 'blue', 'violet', 'fuchsia', 'pink'];\n\nconst sameName = (a, b) => a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0;\n\n/**\n * @param {any} input `{label, color}`\n * @param {{existing?: TemplateTag[], editing?: string|null, t?: import('../../i18n/index.js').Translate}} [options]\n * `editing`: the id of the tag being edited (its own name is not a duplicate)\n * @returns {{tag: {label: string, color: string}, errors?: undefined} | {tag?: undefined, errors: Record<string, string>}}\n */\nexport function validateTag(input, { existing = [], editing = null, t = identity } = {}) {\n /** @type {Record<string, string>} */\n const errors = {};\n const label = String(input?.label ?? '').replace(/\\s+/g, ' ').trim();\n const color = String(input?.color ?? '');\n if (!label) errors.label = t('Name is required');\n else if (label.length > TAG_LIMITS.label) errors.label = t('{max} characters at most', { max: TAG_LIMITS.label });\n else if (existing.some((tag) => String(tag.id) !== String(editing) && sameName(tag.label, label))) {\n errors.label = t('A tag with this name already exists');\n }\n if (!TAG_COLORS.includes(color)) errors.color = t('Choose a color');\n if (Object.keys(errors).length) return { errors };\n return { tag: { label, color } };\n}\n\n/**\n * The tags a template may carry: known ids, each once, `MAX_TEMPLATE_TAGS`\n * at most, in the list's order.\n *\n * @param {unknown} ids\n * @param {TemplateTag[]} catalog\n * @param {{t?: import('../../i18n/index.js').Translate}} [options]\n * @returns {{ids: string[], error?: undefined} | {ids?: undefined, error: {code: string, message: string}}}\n */\nexport function checkTemplateTags(ids, catalog, { t = identity } = {}) {\n if (!Array.isArray(ids)) return { error: { code: 'INVALID_TAGS', message: t('A list of tags is expected') } };\n const wanted = new Set(ids.map(String));\n if (wanted.size > MAX_TEMPLATE_TAGS) {\n return { error: { code: 'TOO_MANY_TAGS', message: t('{max} tags at most per template', { max: MAX_TEMPLATE_TAGS }) } };\n }\n const known = new Set(catalog.map((tag) => String(tag.id)));\n if ([...wanted].some((id) => !known.has(id))) return { error: { code: 'UNKNOWN_TAG', message: t('Tag not found') } };\n return { ids: catalog.map((tag) => String(tag.id)).filter((id) => wanted.has(id)) };\n}\n\n/** The list's order: by name. @param {TemplateTag[]} tags */\nexport const sortTags = (tags) => [...tags].sort((a, b) => a.label.localeCompare(b.label));\n","// @ts-check\n/**\n * Images UPLOADED in the builder — one rule shared by the browser (immediate\n * rejection, storage/client.js) and the server (storage/server/assetFile.js).\n *\n * PNG, JPEG, GIF: the three formats every email client displays. WebP and SVG\n * do not display in Outlook, and an SVG can carry script.\n * The server reads the type from the file BYTES; the browser, from `file.type`.\n */\n\nimport { identity } from '../i18n/index.js';\n\n/** Maximum image size: beyond it, the email becomes slow to open. */\nexport const MAX_IMAGE_BYTES = 2 * 1024 * 1024;\n\n/** Accepted types → extension of the public key. */\nexport const IMAGE_TYPES = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/gif': 'gif' };\n\n/** Public key: 32 hex characters of the hash + extension. */\nexport const ASSET_KEY_PATTERN = /^[a-f0-9]{32}\\.(png|jpg|gif)$/;\n\nconst SIGNATURES = [\n { type: 'image/png', bytes: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] },\n { type: 'image/jpeg', bytes: [0xff, 0xd8, 0xff] },\n { type: 'image/gif', bytes: [0x47, 0x49, 0x46, 0x38] },\n];\n\n/**\n * Image type detected from the file signature, or `null`.\n * @param {Uint8Array} bytes\n * @returns {{type: string, ext: string}|null}\n */\nexport function detectImage(bytes) {\n if (!bytes || bytes.length < 8) return null;\n const found = SIGNATURES.find((s) => s.bytes.every((b, i) => bytes[i] === b));\n return found ? { type: found.type, ext: IMAGE_TYPES[found.type] } : null;\n}\n\n/**\n * Immediate rejection of a file the server would refuse, or `null`.\n * @param {{type?: string, size?: number}} file\n * @param {{t?: import('../i18n/index.js').Translate}} [options]\n */\nexport function imageUploadError(file, { t = identity } = {}) {\n if (!(String(file?.type || '') in IMAGE_TYPES)) return t('Format rejected: PNG, JPEG or GIF expected');\n if (Number(file?.size || 0) > MAX_IMAGE_BYTES) {\n return t('Image too large: {max} MB maximum', { max: MAX_IMAGE_BYTES / (1024 * 1024) });\n }\n return null;\n}\n"],"mappings":";;;;;AAUO,IAAM,wBAAwB;AAE9B,IAAM,gCAAgC;AAKtC,IAAM,gBAAgB,CAAC,WAAW,QAAQ;AAM1C,IAAM,qBAAqB;;;ACelC,IAAM,aAAa,CAAC;AAEb,IAAM,qBAAN,cAAiC,MAAM;AAAA;AAAA,EAE5C,YAAY,SAAS;AACnB,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;A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IAAI,EAAE,IAAI;AACtE;AAOO,SAAS,iBAAiB,MAAM,EAAE,IAAI,SAAS,IAAI,CAAC,GAAG;AAC5D,MAAI,EAAE,OAAO,MAAM,QAAQ,EAAE,KAAK,aAAc,QAAO,EAAE,4CAA4C;AACrG,MAAI,OAAO,MAAM,QAAQ,CAAC,IAAI,iBAAiB;AAC7C,WAAO,EAAE,qCAAqC,EAAE,KAAK,mBAAmB,OAAO,MAAM,CAAC;AAAA,EACxF;AACA,SAAO;AACT;","names":["body","prop"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/constants.js","../src/core/document.js","../src/engine/model.js","../src/core/blockBox.js","../src/engine/mjml.js","../src/blocks/shared.js","../src/features/brand/brand.js","../src/features/tags/tags.js","../src/validation/images.js"],"sourcesContent":["// @ts-check\n/**\n * Email builder constants.\n *\n * `EMAIL_BUILDER_VERSION` versions THIS package (UI, blocks, rendering);\n * `EMAIL_DOCUMENT_SCHEMA_VERSION` versions the stored JSON envelope (the\n * project JSON). Both are written with every template, so a document read by\n * a newer version knows whether it must be migrated (see `core/document.js`).\n */\n\nexport const EMAIL_BUILDER_VERSION = '0.23.0';\n\nexport const EMAIL_DOCUMENT_SCHEMA_VERSION = 1;\n\n/** @typedef {'desktop'|'mobile'} EmailDevice */\n\n/** @type {EmailDevice[]} */\nexport const EMAIL_DEVICES = ['desktop', 'mobile'];\n\n/** Content column width — the email client standard. */\nexport const EMAIL_CONTENT_WIDTH = 600;\n\n/** Mobile preview frame width (standard iPhone, the common worst case). */\nexport const EMAIL_MOBILE_WIDTH = 375;\n","// @ts-check\n/**\n * DOCUMENT envelope — what gets stored (the project JSON).\n *\n * HTML is only a compilation output; what gets edited is the engine's\n * project. It is not stored bare but wrapped with:\n *\n * schemaVersion the shape of THIS envelope (migrations, see MIGRATIONS);\n * engine the engine that can read `project` back;\n * engineVersion its version at write time;\n * builderVersion the builder version that wrote it;\n * project the engine data, opaque to the rest of the code.\n *\n * A document from another engine, a future schema or a malformed one is\n * REJECTED on read rather than half-loaded: a template silently emptied and\n * then saved again would be lost.\n *\n * Dependency-free module: testable outside the browser.\n */\n\nimport { EMAIL_BUILDER_VERSION, EMAIL_DOCUMENT_SCHEMA_VERSION } from './constants.js';\n\n/**\n * @typedef {{\n * schemaVersion: number,\n * engine: string,\n * engineVersion: string,\n * builderVersion: string,\n * project: Record<string, any>,\n * }} EmailDocument\n */\n\n/**\n * Envelope migrations, from N to N+1. Empty while only one schema exists; the\n * first entry will be `1: (doc) => ({ ...doc, schemaVersion: 2 })`.\n *\n * @type {Record<number, (document: any) => any>}\n */\nconst MIGRATIONS = {};\n\nexport class EmailDocumentError extends Error {\n /** @param {string} message */\n constructor(message) {\n super(message);\n this.name = 'EmailDocumentError';\n this.status = 422;\n }\n}\n\nfunction isPlainObject(value) {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * @param {{engine: string, engineVersion: string, project: object}} parts\n * @returns {EmailDocument}\n */\nexport function createDocument({ engine, engineVersion, project }) {\n if (!engine) throw new EmailDocumentError('Document: missing engine');\n if (!isPlainObject(project)) throw new EmailDocumentError('Document: invalid engine project');\n return {\n schemaVersion: EMAIL_DOCUMENT_SCHEMA_VERSION,\n engine,\n engineVersion: String(engineVersion || ''),\n builderVersion: EMAIL_BUILDER_VERSION,\n project: /** @type {Record<string, any>} */ (project),\n };\n}\n\n/**\n * Reads a document (object or JSON string), migrates it to the current schema\n * and validates it.\n *\n * @param {unknown} raw\n * @returns {EmailDocument}\n * @throws {EmailDocumentError}\n */\nexport function readDocument(raw) {\n let value = raw;\n if (typeof value === 'string') {\n try {\n value = JSON.parse(value);\n } catch {\n throw new EmailDocumentError('Unreadable document: invalid JSON');\n }\n }\n if (!isPlainObject(value)) throw new EmailDocumentError('Unreadable document: object expected');\n\n /** @type {any} */\n let document = { ...(/** @type {object} */ (value)) };\n const version = Number(document.schemaVersion);\n if (!Number.isInteger(version) || version < 1) {\n throw new EmailDocumentError('Unreadable document: missing schema version');\n }\n if (version > EMAIL_DOCUMENT_SCHEMA_VERSION) {\n throw new EmailDocumentError(\n `Document written by a newer version of the builder (schema ${version}) — ` +\n 'reload the page'\n );\n }\n for (let v = version; v < EMAIL_DOCUMENT_SCHEMA_VERSION; v += 1) {\n const migrate = MIGRATIONS[v];\n if (!migrate) throw new EmailDocumentError(`Document: no migration from schema ${v}`);\n document = migrate(document);\n }\n\n if (typeof document.engine !== 'string' || !document.engine) {\n throw new EmailDocumentError('Unreadable document: missing engine');\n }\n if (!isPlainObject(document.project)) {\n throw new EmailDocumentError('Unreadable document: missing engine project');\n }\n\n return {\n schemaVersion: EMAIL_DOCUMENT_SCHEMA_VERSION,\n engine: document.engine,\n engineVersion: String(document.engineVersion || ''),\n builderVersion: String(document.builderVersion || ''),\n project: document.project,\n };\n}\n\n/** @param {EmailDocument} document */\nexport function serializeDocument(document) {\n return JSON.stringify(readDocument(document));\n}\n","// @ts-check\n/**\n * THE EMAIL MODEL — the builder's own document, an MJML tree with ids.\n *\n * { id, tag: 'mj-text', attributes: { color: '#2b3038' }, children: [], content: 'Hello' }\n *\n * One node per MJML element. \"Ending\" elements (`mj-text`, `mj-button`…)\n * keep their inner HTML in `content`; the others hold `children`. Ids are\n * opaque, unique within a tree, made of `[a-z0-9]` so they can live in a CSS\n * class (the canvas finds an element by them, see `canvasMjml.js`).\n *\n * Every operation is PURE: it returns a new tree and never changes the one it\n * got, sharing the untouched branches. The undo history is then just a list\n * of trees.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\n/**\n * @typedef {{\n * id: string,\n * tag: string,\n * attributes: Record<string, string>,\n * children: EmailNode[],\n * content: string|null,\n * }} EmailNode\n */\n\n/** MJML elements whose inner content is HTML (MJML calls them \"ending tags\"). */\nexport const ENDING_TAGS = new Set([\n 'mj-text',\n 'mj-button',\n 'mj-navbar-link',\n 'mj-social-element',\n 'mj-table',\n 'mj-raw',\n 'mj-title',\n 'mj-preview',\n 'mj-style',\n 'mj-accordion-title',\n 'mj-accordion-text',\n]);\n\n/** Elements that hold a whole section's place in the body. */\nexport const SECTION_TAGS = new Set(['mj-section', 'mj-wrapper', 'mj-hero']);\n\n/** Elements that are never removed, moved or duplicated. */\nexport const LOCKED_TAGS = new Set(['mjml', 'mj-head', 'mj-body']);\n\nlet counter = 0;\n\n/** A fresh id: short, unique for the page's lifetime, `[a-z0-9]` only. */\nexport function createId() {\n counter = (counter + 1) % 1679616; // 36^4\n return `n${Date.now().toString(36).slice(-5)}${counter.toString(36).padStart(4, '0')}${Math.floor(Math.random() * 1296)\n .toString(36)\n .padStart(2, '0')}`;\n}\n\n/**\n * @param {string} tag\n * @param {{attributes?: Record<string, string>, children?: EmailNode[], content?: string|null, id?: string}} [parts]\n * @returns {EmailNode}\n */\nexport function createNode(tag, { attributes = {}, children = [], content = null, id = createId() } = {}) {\n return { id, tag, attributes: { ...attributes }, children: [...children], content: ENDING_TAGS.has(tag) ? String(content ?? '') : null };\n}\n\n/**\n * Deep copy with NEW ids everywhere (duplicate, paste, insert a block twice).\n * @param {EmailNode} node\n * @returns {EmailNode}\n */\nexport function cloneWithNewIds(node) {\n return {\n id: createId(),\n tag: node.tag,\n attributes: { ...node.attributes },\n children: node.children.map(cloneWithNewIds),\n content: node.content,\n };\n}\n\n/* ── Reading ─────────────────────────────────────────────────────────────── */\n\n/**\n * The node with this id and its ancestors (root first), or null.\n * @param {EmailNode} root @param {string} id\n * @returns {EmailNode[]|null}\n */\nexport function pathTo(root, id) {\n if (root.id === id) return [root];\n for (const child of root.children) {\n const path = pathTo(child, id);\n if (path) return [root, ...path];\n }\n return null;\n}\n\n/** @param {EmailNode} root @param {string|null|undefined} id */\nexport function findNode(root, id) {\n if (!id) return null;\n const path = pathTo(root, id);\n return path ? path[path.length - 1] : null;\n}\n\n/** @param {EmailNode} root @param {string} id */\nexport function parentOf(root, id) {\n const path = pathTo(root, id);\n return path && path.length > 1 ? path[path.length - 2] : null;\n}\n\n/**\n * Closest node (itself included) whose tag is one of `tags`.\n * @param {EmailNode} root @param {string} id @param {Set<string>|string[]} tags\n */\nexport function closestOfTags(root, id, tags) {\n const set = tags instanceof Set ? tags : new Set(tags);\n const path = pathTo(root, id);\n if (!path) return null;\n for (let i = path.length - 1; i >= 0; i -= 1) if (set.has(path[i].tag)) return path[i];\n return null;\n}\n\n/** First node of a tag, depth first. @param {EmailNode} root @param {string} tag @returns {EmailNode|null} */\nexport function findFirst(root, tag) {\n if (root.tag === tag) return root;\n for (const child of root.children) {\n const found = findFirst(child, tag);\n if (found) return found;\n }\n return null;\n}\n\n/** Every node, depth first. @param {EmailNode} root @param {(node: EmailNode) => void} visit */\nexport function walk(root, visit) {\n visit(root);\n for (const child of root.children) walk(child, visit);\n}\n\n/* ── Writing (pure) ──────────────────────────────────────────────────────── */\n\n/**\n * The tree with the node `id` replaced by `update(node)`.\n * @param {EmailNode} root @param {string} id @param {(node: EmailNode) => EmailNode} update\n * @returns {EmailNode}\n */\nexport function updateNode(root, id, update) {\n if (root.id === id) return update(root);\n let changed = false;\n const children = root.children.map((child) => {\n const next = updateNode(child, id, update);\n if (next !== child) changed = true;\n return next;\n });\n return changed ? { ...root, children } : root;\n}\n\n/**\n * Sets (string) or removes (null, '') attributes.\n * @param {EmailNode} root @param {string} id @param {Record<string, string|null|undefined>} attributes\n */\nexport function setAttributes(root, id, attributes) {\n return updateNode(root, id, (node) => {\n const next = { ...node.attributes };\n for (const [key, value] of Object.entries(attributes)) {\n if (value === null || value === undefined || value === '') delete next[key];\n else next[key] = String(value);\n }\n return { ...node, attributes: next };\n });\n}\n\n/** @param {EmailNode} root @param {string} id @param {string} content */\nexport function setContent(root, id, content) {\n return updateNode(root, id, (node) => (node.content === null ? node : { ...node, content: String(content ?? '') }));\n}\n\n/**\n * Inserts nodes into `parentId` at `index` (clamped).\n * @param {EmailNode} root @param {string} parentId @param {number} index @param {EmailNode[]} nodes\n */\nexport function insertNodes(root, parentId, index, nodes) {\n return updateNode(root, parentId, (parent) => {\n const at = Math.max(0, Math.min(index, parent.children.length));\n const children = [...parent.children];\n children.splice(at, 0, ...nodes);\n return { ...parent, children };\n });\n}\n\n/** @param {EmailNode} root @param {string} id */\nexport function removeNode(root, id) {\n const parent = parentOf(root, id);\n if (!parent) return root;\n return updateNode(root, parent.id, (p) => ({ ...p, children: p.children.filter((c) => c.id !== id) }));\n}\n\n/**\n * Moves a node under `parentId` at `index`, where `index` counts the target's\n * children BEFORE the node leaves its place (what a drop indicator shows).\n * @param {EmailNode} root @param {string} id @param {string} parentId @param {number} index\n */\nexport function moveNode(root, id, parentId, index) {\n const node = findNode(root, id);\n const from = parentOf(root, id);\n if (!node || !from) return root;\n // A node cannot go inside itself.\n if (pathTo(node, parentId)) return root;\n let at = index;\n if (from.id === parentId) {\n const current = from.children.findIndex((c) => c.id === id);\n if (current < at) at -= 1;\n if (current === at) return root;\n }\n return insertNodes(removeNode(root, id), parentId, at, [node]);\n}\n\n/**\n * Index of a node among its siblings, and their count.\n * @param {EmailNode} root @param {string} id\n */\nexport function positionOf(root, id) {\n const parent = parentOf(root, id);\n if (!parent) return { parent: null, index: -1, count: 0 };\n return { parent, index: parent.children.findIndex((c) => c.id === id), count: parent.children.length };\n}\n\n/* ── Snapshot (the stored project) ───────────────────────────────────────── */\n\n/** Shape version of the stored project (`{ format, root }`). */\nexport const PROJECT_FORMAT = 1;\n\n/** @param {EmailNode} root */\nexport function toProject(root) {\n return { format: PROJECT_FORMAT, root: strip(root) };\n}\n\n/** @param {EmailNode} node @returns {any} */\nfunction strip(node) {\n /** @type {any} */\n const out = { id: node.id, tag: node.tag };\n if (Object.keys(node.attributes).length) out.attributes = { ...node.attributes };\n if (node.content !== null) out.content = node.content;\n if (node.children.length) out.children = node.children.map(strip);\n return out;\n}\n\n/**\n * Reads a stored project back into a tree. Ids are kept when they are valid\n * and unique, replaced otherwise. Throws on anything that is not a project of\n * this format.\n * @param {unknown} project\n * @returns {EmailNode}\n */\nexport function fromProject(project) {\n const value = /** @type {any} */ (project);\n if (!value || typeof value !== 'object' || value.format !== PROJECT_FORMAT || !value.root) {\n throw new Error('Not a project of this builder');\n }\n const seen = new Set();\n /** @param {any} raw @returns {EmailNode} */\n const read = (raw) => {\n if (!raw || typeof raw !== 'object' || typeof raw.tag !== 'string' || !/^(mjml|mj-[a-z-]+)$/.test(raw.tag)) {\n throw new Error('Invalid element in the project');\n }\n let id = typeof raw.id === 'string' && /^[a-z0-9]{1,40}$/.test(raw.id) ? raw.id : createId();\n if (seen.has(id)) id = createId();\n seen.add(id);\n /** @type {Record<string, string>} */\n const attributes = {};\n for (const [k, v] of Object.entries(raw.attributes || {})) {\n if (/^[a-z][a-z0-9-]*$/i.test(k) && v !== null && v !== undefined) attributes[k] = String(v);\n }\n return createNode(raw.tag, {\n id,\n attributes,\n content: ENDING_TAGS.has(raw.tag) ? String(raw.content ?? '') : null,\n children: ENDING_TAGS.has(raw.tag) ? [] : (Array.isArray(raw.children) ? raw.children : []).map(read),\n });\n };\n const root = read(value.root);\n if (root.tag !== 'mjml' || !findFirst(root, 'mj-body')) throw new Error('The project has no email body');\n return root;\n}\n","// @ts-check\n/** Editor-only box properties travel through valid MJML as a CSS class. */\nconst PREFIX = 'eb-box-';\nconst KEYS = new Set(['margin', 'box-padding', 'box-border', 'box-border-top', 'box-border-right', 'box-border-bottom', 'box-border-left']);\n\n/** @param {string} tag @param {Record<string, string>} attributes */\nexport function encodeBox(tag, attributes) {\n const custom = Object.fromEntries(Object.entries(attributes).filter(([key]) => KEYS.has(key) && !(tag === 'mj-section' && key === 'margin')));\n if (!Object.keys(custom).length) return attributes;\n const out = { ...attributes };\n for (const key of Object.keys(custom)) delete out[key];\n const code = [...JSON.stringify(custom)].map((c) => c.charCodeAt(0).toString(16).padStart(4, '0')).join('');\n out['css-class'] = `${out['css-class'] || ''} ${PREFIX}${code}`.trim();\n return out;\n}\n\n/** @param {Record<string, string>} attributes */\nexport function decodeBox(attributes) {\n const classes = String(attributes['css-class'] || '').split(/\\s+/);\n const out = { ...attributes };\n const kept = classes.filter((name) => {\n if (!name.startsWith(PREFIX) || !/^(?:[a-f0-9]{4})+$/.test(name.slice(PREFIX.length))) return true;\n try {\n const json = name.slice(PREFIX.length).replace(/.{4}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));\n const values = JSON.parse(json);\n for (const [key, value] of Object.entries(values)) if (KEYS.has(key) && typeof value === 'string') out[key] = value;\n return false;\n } catch { return true; }\n });\n if (kept.filter(Boolean).length) out['css-class'] = kept.filter(Boolean).join(' ');\n else delete out['css-class'];\n return out;\n}\n\n/** The native outer padding of visual blocks already means outside spacing. @param {string} tag */\nexport function boxKeys(tag) {\n const outside = ['mj-image', 'mj-button', 'mj-divider', 'mj-social'].includes(tag);\n return {\n margin: outside ? 'padding' : 'margin',\n border: ['mj-image', 'mj-button', 'mj-column', 'mj-section'].includes(tag) ? 'border' : 'box-border',\n padding: tag === 'mj-button' ? 'inner-padding' : outside || ['mj-spacer', 'mj-navbar', 'mj-social-element'].includes(tag) ? 'box-padding' : 'padding',\n };\n}\n","// @ts-check\n/**\n * MJML ⇄ MODEL — reading MJML into the builder's tree, writing it back.\n *\n * MJML is close enough to XML to be read by a small scanner, and only two\n * kinds of element exist:\n * - containers (`mj-section`, `mj-column`…), made of other MJML elements;\n * - \"ending\" elements (`mj-text`, `mj-button`…), whose inside is HTML kept\n * as is, up to the matching closing tag.\n * Anything else between containers (stray text, comments, HTML outside an\n * ending element) is not MJML and is dropped.\n *\n * Attribute values are DECODED in the model (`&` → `&`) and encoded again\n * on write: the model holds what the attribute means, the MJML how to write\n * it.\n *\n * Two model attributes are written as wrappers in MJML:\n * `margin` on a section becomes the padding of an `eb-section-margin`\n * wrapper, outside the section's border and its own padding.\n * `content-background-color` on\n * `mj-body`, the color painted under the content, at the email's width. A\n * section with rounded corners shows it in its corners instead of the page\n * background. MJML has no such attribute: it is written as an `mj-wrapper`\n * around the sections (`eb-content-layer`), and read back into the body.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\nimport { ENDING_TAGS, createNode, findFirst } from './model.js';\nimport { decodeBox, encodeBox } from '../core/blockBox.js';\n\n/** @typedef {import('./model.js').EmailNode} EmailNode */\n\n/** The color under the content, kept on `mj-body` in the model. */\nexport const CONTENT_BACKGROUND = 'content-background-color';\n/** The class of the `mj-wrapper` it is written as. */\nexport const CONTENT_LAYER_CLASS = 'eb-content-layer';\n/** A section's outside spacing, written as valid MJML rather than a margin attribute. */\nexport const SECTION_MARGIN_CLASS = 'eb-section-margin';\n\n/**\n * Sections the layer goes under. A band across the whole screen cannot be in\n * an `mj-wrapper` (it would shrink to the content's width), nor can another\n * wrapper: they split the layer in two.\n * @param {EmailNode} node\n */\nconst underLayer = (node) =>\n (node.tag === 'mj-section' && !node.attributes.margin && node.attributes['full-width'] !== 'full-width') || node.tag === 'mj-hero';\n\n/** @param {EmailNode} node */\nconst isContentLayer = (node) =>\n node.tag === 'mj-wrapper' && String(node.attributes['css-class'] || '').split(/\\s+/).includes(CONTENT_LAYER_CLASS);\n\nconst NAMED_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '\"', apos: \"'\", nbsp: ' ' };\n\n/** @param {string} value */\nexport function decodeAttribute(value) {\n return value.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (match, entity) => {\n if (entity[0] === '#') {\n const code = entity[1] === 'x' || entity[1] === 'X' ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);\n return Number.isFinite(code) && code > 0 && code < 0x110000 ? String.fromCodePoint(code) : match;\n }\n const named = /** @type {Record<string, string>} */ (NAMED_ENTITIES)[entity.toLowerCase()];\n return named ?? match;\n });\n}\n\n/** @param {string} value */\nexport function encodeAttribute(value) {\n return String(value).replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\n}\n\n/**\n * Reads the attributes of an opening tag, from `start` (just after the name)\n * to its `>`. Quotes may contain `>`.\n * @param {string} source @param {number} start\n * @returns {{attributes: Record<string, string>, end: number, selfClosing: boolean}}\n */\nfunction readAttributes(source, start) {\n /** @type {Record<string, string>} */\n const attributes = {};\n let i = start;\n const n = source.length;\n while (i < n) {\n while (i < n && /\\s/.test(source[i])) i += 1;\n if (source[i] === '>') return { attributes, end: i + 1, selfClosing: false };\n if (source[i] === '/' && source[i + 1] === '>') return { attributes, end: i + 2, selfClosing: true };\n if (i >= n) break;\n const nameMatch = /^[^\\s=/>\"']+/.exec(source.slice(i, i + 200));\n if (!nameMatch) {\n i += 1;\n continue;\n }\n const name = nameMatch[0].toLowerCase();\n i += nameMatch[0].length;\n while (i < n && /\\s/.test(source[i])) i += 1;\n let value = '';\n if (source[i] === '=') {\n i += 1;\n while (i < n && /\\s/.test(source[i])) i += 1;\n const quote = source[i];\n if (quote === '\"' || quote === \"'\") {\n const close = source.indexOf(quote, i + 1);\n const stop = close === -1 ? n : close;\n value = source.slice(i + 1, stop);\n i = stop + 1;\n } else {\n let bare = /^[^\\s>]*/.exec(source.slice(i))?.[0] || '';\n // `width=100/>`: the slash closes the tag, it is not in the value.\n if (bare.endsWith('/') && source[i + bare.length] === '>') bare = bare.slice(0, -1);\n value = bare;\n i += bare.length;\n }\n }\n attributes[name] = decodeAttribute(value);\n }\n return { attributes, end: n, selfClosing: false };\n}\n\n/**\n * MJML elements of a fragment (no `<mjml>` needed): `<mj-section>…</mj-section><mj-section>…`.\n * @param {string} source\n * @returns {EmailNode[]}\n */\nexport function parseMjmlFragment(source) {\n const text = String(source || '').replace(/^\\uFEFF/, '');\n /** @type {EmailNode} */\n const top = createNode('mj-fragment');\n /** @type {EmailNode[]} */\n const stack = [top];\n let i = 0;\n const n = text.length;\n\n while (i < n) {\n const lt = text.indexOf('<', i);\n if (lt === -1) break;\n i = lt;\n if (text.startsWith('<!--', i)) {\n const close = text.indexOf('-->', i + 4);\n i = close === -1 ? n : close + 3;\n continue;\n }\n if (text.startsWith('<?', i) || text.startsWith('<!', i)) {\n const close = text.indexOf('>', i);\n i = close === -1 ? n : close + 1;\n continue;\n }\n const closing = text[i + 1] === '/';\n const nameMatch = /^[a-z][a-z0-9-]*/i.exec(text.slice(i + (closing ? 2 : 1), i + 60));\n if (!nameMatch) {\n i += 1;\n continue;\n }\n const tag = nameMatch[0].toLowerCase();\n const afterName = i + (closing ? 2 : 1) + nameMatch[0].length;\n const isMjml = tag === 'mjml' || tag.startsWith('mj-');\n\n if (closing) {\n const close = text.indexOf('>', afterName);\n i = close === -1 ? n : close + 1;\n if (!isMjml) continue;\n // Close up to the matching element (tolerates a forgotten closing tag).\n for (let depth = stack.length - 1; depth > 0; depth -= 1) {\n if (stack[depth].tag === tag) {\n stack.length = depth;\n break;\n }\n }\n continue;\n }\n\n const { attributes: written, end, selfClosing } = readAttributes(text, afterName);\n const attributes = decodeBox(written);\n i = end;\n if (!isMjml) continue;\n\n const parent = stack[stack.length - 1];\n if (ENDING_TAGS.has(tag)) {\n let content = '';\n if (!selfClosing) {\n const closeRe = new RegExp(`</${tag}\\\\s*>`, 'ig');\n closeRe.lastIndex = i;\n const close = closeRe.exec(text);\n const stop = close ? close.index : n;\n content = text.slice(i, stop).trim();\n i = close ? close.index + close[0].length : n;\n }\n parent.children.push(createNode(tag, { attributes, content }));\n continue;\n }\n const node = createNode(tag, { attributes });\n parent.children.push(node);\n if (!selfClosing) stack.push(node);\n }\n return top.children;\n}\n\n/**\n * A whole email. Always returns an `mjml` root holding an `mj-body`: a bare\n * fragment is wrapped, a missing body is added.\n * @param {string} source\n * @returns {EmailNode}\n */\nexport function parseMjml(source) {\n const nodes = parseMjmlFragment(source);\n let root = nodes.find((node) => node.tag === 'mjml') || null;\n if (!root) {\n const body = nodes.find((node) => node.tag === 'mj-body');\n const head = nodes.find((node) => node.tag === 'mj-head');\n root = createNode('mjml', {\n children: [\n ...(head ? [head] : []),\n body || createNode('mj-body', { children: nodes.filter((node) => node.tag !== 'mj-head') }),\n ],\n });\n }\n const body = findFirst(root, 'mj-body');\n if (!body) root.children.push(createNode('mj-body'));\n else {\n const layer = body.children.find((child) => isContentLayer(child) ||\n (child.tag === 'mj-wrapper' && child.attributes['css-class'] === SECTION_MARGIN_CLASS && child.attributes['background-color']));\n const color = layer?.attributes['background-color'];\n if (color) body.attributes[CONTENT_BACKGROUND] = color;\n body.children = body.children.flatMap((child) => (isContentLayer(child) ? child.children : [child]));\n }\n const restoreMargins = (/** @type {EmailNode} */ parent) => {\n parent.children = parent.children.flatMap((child) => {\n if (child.tag === 'mj-wrapper' && String(child.attributes['css-class'] || '').split(/\\s+/).includes(SECTION_MARGIN_CLASS) &&\n child.children.length === 1 && child.children[0].tag === 'mj-section') {\n const section = child.children[0];\n section.attributes.margin = child.attributes.padding || '0px';\n if (child.attributes['full-width']) section.attributes['full-width'] = child.attributes['full-width'];\n return [section];\n }\n restoreMargins(child);\n return [child];\n });\n };\n restoreMargins(root);\n return root;\n}\n\n/**\n * The MJML of a tree. `pretty`: one element per line, indented (what is\n * stored and downloaded); otherwise on one line.\n * @param {EmailNode} node\n * @param {{pretty?: boolean, attributes?: (node: EmailNode) => Record<string, string>, extraChildren?: (node: EmailNode) => string}} [options]\n * `attributes`: replaces a node's attributes on write (the canvas adds its\n * markers there); `extraChildren`: MJML appended inside a container.\n */\nexport function serializeMjml(node, options = {}) {\n const { pretty = true } = options;\n /** @param {Record<string, string>} attributes */\n const attrsOf = (attributes) =>\n Object.entries(attributes)\n .map(([key, value]) => ` ${key}=\"${encodeAttribute(value)}\"`)\n .join('');\n /** @param {string} tag @param {Record<string, string>} attributes @param {string[]} inner @param {number} depth */\n const element = (tag, attributes, inner, depth) => {\n const indent = pretty ? ' '.repeat(depth) : '';\n const attrs = attrsOf(attributes);\n if (!inner.length) return `${indent}<${tag}${attrs} />`;\n return pretty ? `${indent}<${tag}${attrs}>\\n${inner.join('\\n')}\\n${indent}</${tag}>` : `<${tag}${attrs}>${inner.join('')}</${tag}>`;\n };\n /** The body's children, each run of sections under the layer in its `mj-wrapper`. @param {EmailNode} body @param {number} depth */\n const layered = (body, depth) => {\n const layer = { 'css-class': CONTENT_LAYER_CLASS, 'background-color': body.attributes[CONTENT_BACKGROUND], padding: '0px' };\n /** @type {string[]} */\n const out = [];\n /** @type {EmailNode[]} */\n let run = [];\n const flush = () => {\n if (run.length) out.push(element('mj-wrapper', layer, run.map((child) => write(child, depth + 2)), depth + 1));\n run = [];\n };\n for (const child of body.children) {\n if (underLayer(child)) run.push(child);\n else {\n flush();\n out.push(write(child, depth + 1));\n }\n }\n flush();\n return out;\n };\n /** @param {EmailNode} current @param {number} depth @returns {string} */\n const write = (current, depth) => {\n let attributes = encodeBox(current.tag, options.attributes ? options.attributes(current) : current.attributes);\n const margin = current.tag === 'mj-section' ? attributes.margin : null;\n if (margin) {\n const { margin: _margin, 'full-width': _fullWidth, ...sectionAttributes } = attributes;\n /** @type {Record<string, string>} */\n const wrapperAttributes = { 'css-class': SECTION_MARGIN_CLASS, padding: margin };\n if (attributes['full-width']) wrapperAttributes['full-width'] = attributes['full-width'];\n const background = findFirst(node, 'mj-body')?.attributes[CONTENT_BACKGROUND];\n if (background && !attributes['full-width']) wrapperAttributes['background-color'] = background;\n return element('mj-wrapper', wrapperAttributes, [\n element(current.tag, sectionAttributes, current.children.map((child) => write(child, depth + 2)), depth + 1),\n ], depth);\n }\n if (current.tag === 'mj-body' && CONTENT_BACKGROUND in attributes) {\n const { [CONTENT_BACKGROUND]: _layer, ...mjml } = attributes;\n attributes = mjml;\n }\n if (current.content !== null) {\n return `${pretty ? ' '.repeat(depth) : ''}<${current.tag}${attrsOf(attributes)}>${current.content}</${current.tag}>`;\n }\n const inner =\n current.tag === 'mj-body' && current.attributes[CONTENT_BACKGROUND]\n ? layered(current, depth)\n : current.children.map((child) => write(child, depth + 1));\n const extra = options.extraChildren ? options.extraChildren(current) : '';\n if (extra) inner.push(pretty ? `${' '.repeat(depth + 1)}${extra}` : extra);\n return element(current.tag, attributes, inner, depth);\n };\n return write(node, 0);\n}\n","// @ts-check\n/**\n * Building blocks shared by all blocks: palette, fonts, recurring properties.\n *\n * -- DEFAULT PALETTE ---------------------------------------------------------\n * Plain hex values: email clients load no stylesheet and understand neither\n * `var()` nor modern color functions, so every value ends up inline in a\n * `style=\"\"` attribute.\n *\n * -- EVERY BLOCK SETS ITS OWN TEXT ATTRIBUTES --------------------------------\n * Font, size, line height and color are written on the element itself, never\n * left to MJML defaults (the \"Ubuntu\" font loaded from Google, line height 1):\n * the canvas and the sent email then render the same thing, and Outlook gets\n * explicit values.\n *\n * Fonts: only web-safe stacks, installed everywhere and understood by\n * Outlook - a web font only renders in a minority of email clients.\n */\n\n/** @typedef {import('../core/EmailEditor.js').BlockProperty} BlockProperty */\n\n/** Text for an MJML attribute or element. @param {string} text */\nexport function escapeXml(text) {\n return String(text ?? '')\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n\n/** The default palette. */\nexport const PALETTE = {\n ink: '#2b3038',\n inkSoft: '#41506b',\n navy: '#212e5a',\n brand: '#2977bc',\n border: '#dfe6f0',\n canvas: '#eceff4',\n surface: '#ffffff',\n white: '#ffffff',\n};\n\n/** Default link of a new button. */\nexport const DEFAULT_BUTTON_URL = 'https://example.com';\n\nexport const FONT_STACK = 'Arial, Helvetica, sans-serif';\n\n/** @type {{value: string, label: string}[]} */\nexport const FONT_OPTIONS = [\n { value: 'Arial, Helvetica, sans-serif', label: 'Arial' },\n { value: 'Verdana, Geneva, sans-serif', label: 'Verdana' },\n { value: 'Tahoma, Geneva, sans-serif', label: 'Tahoma' },\n { value: \"'Trebuchet MS', Helvetica, sans-serif\", label: 'Trebuchet' },\n { value: 'Georgia, Times, serif', label: 'Georgia' },\n { value: \"'Times New Roman', Times, serif\", label: 'Times' },\n { value: \"'Courier New', Courier, monospace\", label: 'Courier' },\n];\n\n/** @type {{value: string, label: string}[]} */\nexport const ALIGN_OPTIONS = [\n { value: 'left', label: 'Left' },\n { value: 'center', label: 'Center' },\n { value: 'right', label: 'Right' },\n];\n\n/** Properties panel groups, in display order. */\nexport const GROUPS = {\n content: 'Content',\n link: 'Link',\n typography: 'Typography',\n colors: 'Colors',\n layout: 'Layout',\n spacing: 'Spacing',\n};\n\n/** Recurring properties. */\nexport const prop = {\n /** @returns {BlockProperty} */\n fontFamily: () => ({ key: 'font-family', label: 'Font', type: 'select', group: GROUPS.typography, options: FONT_OPTIONS }),\n /** @returns {BlockProperty} */\n fontSize: (min = 10, max = 48) => ({ key: 'font-size', label: 'Size', type: 'size', group: GROUPS.typography, min, max, unit: 'px' }),\n /** @returns {BlockProperty} */\n lineHeight: () => ({ key: 'line-height', label: 'Line height', type: 'size', group: GROUPS.typography, min: 10, max: 80, unit: 'px' }),\n /** @returns {BlockProperty} */\n color: (label = 'Text') => ({ key: 'color', label, type: 'color', group: GROUPS.colors }),\n /** @returns {BlockProperty} */\n background: (key = 'background-color', label = 'Background') => ({ key, label, type: 'color', group: GROUPS.colors }),\n /** @returns {BlockProperty} */\n align: (options = ALIGN_OPTIONS) => ({ key: 'align', label: 'Alignment', type: 'align', group: GROUPS.layout, options }),\n /** Align the containing column, or every column of a layout. @returns {BlockProperty} */\n verticalAlign: () => ({ key: 'vertical-align', label: 'Vertical alignment', type: 'select', group: GROUPS.layout,\n options: [{ value: 'top', label: 'Top' }, { value: 'middle', label: 'Middle' }, { value: 'bottom', label: 'Bottom' }] }),\n /**\n * `box`: where the box diagram shows it — `margin` when the space is outside\n * what the reader sees as the block (a button, an image), `padding` inside.\n * @param {'margin'|'padding'} [box]\n * @returns {BlockProperty}\n */\n padding: (key = 'padding', label = 'Padding', box = undefined) => ({ key, label, type: 'spacing', group: GROUPS.spacing, ...(box ? { box } : {}) }),\n /** A line around the block: widths, style, color, in one value. @returns {BlockProperty} */\n border: () => ({ key: 'border', label: 'Border', type: 'border', group: GROUPS.spacing, box: 'border' }),\n /** @returns {BlockProperty} */\n href: (label = 'Link URL') => ({ key: 'href', label, type: 'url', group: GROUPS.link, placeholder: 'https://' }),\n /**\n * `%` only where the box is square enough to want it (an image, an icon: 50 % is a circle):\n * on a wide button or section, a percentage of the width and of the height makes an oval.\n * @returns {BlockProperty}\n */\n radius: (units = ['px', '%']) => ({ key: 'border-radius', label: 'Corner radius', type: 'size', group: GROUPS.layout, min: 0, unit: 'px', ...(units.length > 1 ? { units } : {}) }),\n};\n\n/**\n * White one-column section: the wrapper of a content block dropped outside\n * any column (MJML does not accept text directly inside the body).\n *\n * Warning: padding in LONGHAND form, never `padding=\"...\"`. The canvas starts\n * from the longhand defaults (20 px for a section), which override the\n * shorthand, while the export omits them - the screen and the email would\n * diverge (see core/mjmlAttributes).\n *\n * @param {string} inner\n */\nexport function inWhiteSection(inner) {\n return (\n `<mj-section background-color=\"${PALETTE.surface}\" padding-top=\"0px\" padding-bottom=\"0px\">` +\n `<mj-column>${inner}</mj-column></mj-section>`\n );\n}\n","// @ts-check\n/**\n * BRAND — the look of a company's emails: its name, its logo, a main color,\n * a color for headings, a font and a text size. Set once (by hand, or read from the\n * company's website), it is used by every new email, template and block,\n * and can be applied to the email being edited.\n *\n * `applyBrand` repaints an email by ROLE, not by exact color, so it works on\n * any email — a template, an imported one, one the user built:\n *\n * buttons filled with the main color, text in the color that\n * reads on it (white or ink);\n * colored sections (banners) take the main color; their texts and\n * buttons switch to what reads on it;\n * headings (bold, 18 px and more, on white) take the headings\n * color; body text and gray footers keep theirs;\n * colored links take the main color, or the headings color when the\n * main one is too light to read on white;\n * fonts every text, button and menu link;\n * text size paragraphs (not bold, 13 to 18 px, not gray): their\n * line height follows; headings, labels and footers\n * keep theirs;\n * header (optional) the logo — or the name — at the top, and\n * the name in the footer.\n *\n * Dependency-free: runs in the browser, on the server and in unit tests.\n */\n\nimport { FONT_OPTIONS, PALETTE, escapeXml } from '../../blocks/shared.js';\nimport { createNode } from '../../engine/model.js';\nimport { parseMjml, parseMjmlFragment, serializeMjml } from '../../engine/mjml.js';\n\n/**\n * @typedef {{\n * name?: string,\n * logoUrl?: string,\n * logoWidth?: number,\n * primary?: string,\n * heading?: string,\n * font?: string,\n * fontSize?: number,\n * website?: string,\n * }} Brand\n * `primary`: buttons, banners, links; `heading`: headings; colors as\n * `#rrggbb`. `font`: one of the builder's web-safe stacks (FONT_OPTIONS).\n * `fontSize`: the paragraphs' size in px (BRAND_FONT_SIZES).\n * `website`: where it was read from, to read it again.\n *\n * @typedef {import('../../engine/model.js').EmailNode} EmailNode\n */\n\nconst HEX = /^#[0-9a-f]{6}$/;\nconst FONTS = new Set(FONT_OPTIONS.map((option) => option.value));\nexport const MAX_LOGO_WIDTH = 240;\n/** The paragraphs' sizes a brand offers, in px; the builder's own is 15. */\nexport const BRAND_FONT_SIZES = [13, 14, 15, 16, 17, 18];\n\n/* ── Colors ─────────────────────────────────────────────────────────────── */\n\n/**\n * A CSS color as RGB(A), or null: #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(),\n * rgba(), hsl(), hsla(), and the keywords white and black.\n * @param {unknown} value\n * @returns {{r: number, g: number, b: number, a: number}|null}\n */\nexport function parseColor(value) {\n const source = String(value ?? '').trim().toLowerCase();\n if (source === 'white') return { r: 255, g: 255, b: 255, a: 1 };\n if (source === 'black') return { r: 0, g: 0, b: 0, a: 1 };\n let match = source.match(/^#([0-9a-f]{3,8})$/);\n if (match) {\n const hex = match[1];\n if (hex.length === 3 || hex.length === 4) {\n const [r, g, b, a = 'ff'] = hex.split('').map((c) => c + c);\n return { r: parseInt(r, 16), g: parseInt(g, 16), b: parseInt(b, 16), a: parseInt(a, 16) / 255 };\n }\n if (hex.length === 6 || hex.length === 8) {\n return {\n r: parseInt(hex.slice(0, 2), 16),\n g: parseInt(hex.slice(2, 4), 16),\n b: parseInt(hex.slice(4, 6), 16),\n a: hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1,\n };\n }\n return null;\n }\n match = source.match(/^(rgba?|hsla?)\\(([^)]*)\\)$/);\n if (!match) return null;\n const parts = match[2].split(/[\\s,/]+/).filter(Boolean);\n if (parts.length < 3) return null;\n const alpha = parts[3] === undefined ? 1 : parts[3].endsWith('%') ? parseFloat(parts[3]) / 100 : parseFloat(parts[3]);\n if (match[1].startsWith('rgb')) {\n const channel = (/** @type {string} */ part) => (part.endsWith('%') ? (parseFloat(part) * 255) / 100 : parseFloat(part));\n const [r, g, b] = parts.slice(0, 3).map(channel);\n if ([r, g, b, alpha].some((n) => Number.isNaN(n))) return null;\n const clamp = (/** @type {number} */ n) => Math.max(0, Math.min(255, Math.round(n)));\n return { r: clamp(r), g: clamp(g), b: clamp(b), a: alpha };\n }\n const h = parseFloat(parts[0]);\n const s = parseFloat(parts[1]) / 100;\n const l = parseFloat(parts[2]) / 100;\n if ([h, s, l, alpha].some((n) => Number.isNaN(n))) return null;\n return { ...fromHsl(((h % 360) + 360) % 360, Math.max(0, Math.min(1, s)), Math.max(0, Math.min(1, l))), a: alpha };\n}\n\n/** @param {number} h @param {number} s @param {number} l */\nfunction fromHsl(h, s, l) {\n const c = (1 - Math.abs(2 * l - 1)) * s;\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1));\n const m = l - c / 2;\n const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];\n return { r: Math.round((r + m) * 255), g: Math.round((g + m) * 255), b: Math.round((b + m) * 255) };\n}\n\n/** @param {{r: number, g: number, b: number}} color */\nexport const toHex = ({ r, g, b }) => `#${[r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('')}`;\n\n/** Hue (0-360), saturation and lightness (0-1). @param {{r: number, g: number, b: number}} color */\nexport function toHsl({ r, g, b }) {\n const [R, G, B] = [r / 255, g / 255, b / 255];\n const max = Math.max(R, G, B);\n const min = Math.min(R, G, B);\n const l = (max + min) / 2;\n if (max === min) return { h: 0, s: 0, l };\n const d = max - min;\n const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n const h = max === R ? ((G - B) / d + (G < B ? 6 : 0)) * 60 : max === G ? ((B - R) / d + 2) * 60 : ((R - G) / d + 4) * 60;\n return { h, s, l };\n}\n\n/** WCAG relative luminance. @param {{r: number, g: number, b: number}} color */\nfunction luminance({ r, g, b }) {\n const linear = (/** @type {number} */ n) => {\n const c = n / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** WCAG contrast ratio of two colors (1 to 21). @param {string} a @param {string} b */\nexport function contrastRatio(a, b) {\n const ca = parseColor(a);\n const cb = parseColor(b);\n if (!ca || !cb) return 1;\n const [hi, lo] = [luminance(ca), luminance(cb)].sort((x, y) => y - x);\n return (hi + 0.05) / (lo + 0.05);\n}\n\n/** The text color that reads on `background`: white or ink. @param {string} background */\nexport function readableOn(background) {\n return contrastRatio(background, PALETTE.white) >= contrastRatio(background, PALETTE.ink) ? PALETTE.white : PALETTE.ink;\n}\n\n/**\n * A color meant to be noticed (a banner, a filled button), as opposed to\n * white, light tints, grays and near-black.\n * @param {unknown} value\n */\nexport function isColored(value) {\n const color = parseColor(value);\n if (!color || color.a < 0.5) return false;\n const { s, l } = toHsl(color);\n return s >= 0.2 && l >= 0.08 && l <= 0.88;\n}\n\n/** Dark enough to carry white text (navy, charcoal…). @param {unknown} value */\nfunction isDark(value) {\n const color = parseColor(value);\n return Boolean(color && color.a >= 0.5 && luminance(color) < 0.12);\n}\n\n/** A light gray (footers, captions): left as it is. @param {unknown} value */\nfunction isMuted(value) {\n const color = parseColor(value);\n if (!color) return false;\n const { s, l } = toHsl(color);\n return s < 0.2 && l > 0.4;\n}\n\n/* ── The brand itself ───────────────────────────────────────────────────── */\n\n/** @param {unknown} value */\nconst cleanColor = (value) => {\n const color = parseColor(value);\n return color && color.a >= 0.5 ? toHex(color) : '';\n};\n\n/**\n * A brand as stored and used: unknown fields dropped, colors as #rrggbb,\n * the font one of the builder's stacks, the logo an https or site-relative\n * image. Whatever is invalid is left out (the builder's default is used).\n * @param {unknown} input\n * @returns {Brand}\n */\nexport function cleanBrand(input) {\n const source = /** @type {Record<string, unknown>} */ (input && typeof input === 'object' ? input : {});\n /** @type {Brand} */\n const brand = {};\n const name = typeof source.name === 'string' ? source.name.replace(/\\s+/g, ' ').trim().slice(0, 80) : '';\n if (name) brand.name = name;\n const logo = typeof source.logoUrl === 'string' ? source.logoUrl.trim() : '';\n if (logo && logo.length <= 2000 && (/^https:\\/\\/[^\\s\"'<>]+$/i.test(logo) || /^\\/(?!\\/)[^\\s\"'<>]*$/.test(logo))) {\n brand.logoUrl = logo;\n const width = Math.round(Number(source.logoWidth));\n if (width >= 24 && width <= MAX_LOGO_WIDTH) brand.logoWidth = width;\n }\n const primary = cleanColor(source.primary);\n if (primary && HEX.test(primary)) brand.primary = primary;\n const heading = cleanColor(source.heading);\n if (heading && HEX.test(heading)) brand.heading = heading;\n if (typeof source.font === 'string' && FONTS.has(source.font)) brand.font = source.font;\n const fontSize = Number(source.fontSize);\n if (BRAND_FONT_SIZES.includes(fontSize)) brand.fontSize = fontSize;\n const website = typeof source.website === 'string' ? source.website.trim() : '';\n if (/^https?:\\/\\/[^\\s\"'<>]+$/i.test(website) && website.length <= 500) brand.website = website;\n return brand;\n}\n\n/** Does the brand change anything? @param {Brand|null|undefined} brand */\nexport const hasBrand = (brand) => Boolean(brand && Object.keys(cleanBrand(brand)).some((key) => key !== 'website'));\n\n/**\n * The sender the templates use: the brand's name and logo over the host's\n * sender (whose postal address stays).\n * @param {import('../templates/starter.js').StarterSender|null|undefined} sender\n * @param {Brand|null|undefined} brand\n */\nexport function brandedSender(sender, brand) {\n const base = { ...(sender || {}) };\n if (!brand) return base;\n if (brand.name) base.name = brand.name;\n if (brand.logoUrl) {\n base.logoUrl = brand.logoUrl;\n base.logoWidth = brand.logoWidth || base.logoWidth;\n }\n return base;\n}\n\n/**\n * The colors applyBrand paints with.\n * @param {Brand} brand\n */\nfunction paletteOf(brand) {\n const primary = brand.primary || null;\n return {\n primary,\n onPrimary: primary ? readableOn(primary) : null,\n heading: brand.heading || null,\n // A link must read on white: a too-light main color gives way.\n link: primary ? (contrastRatio(primary, PALETTE.white) >= 3 ? primary : brand.heading || PALETTE.ink) : null,\n font: brand.font || null,\n fontSize: brand.fontSize || null,\n };\n}\n\n/* ── Painting ───────────────────────────────────────────────────────────── */\n\nconst SECTION_LIKE = new Set(['mj-section', 'mj-wrapper', 'mj-hero', 'mj-column', 'mj-group']);\nconst FONT_TAGS = new Set(['mj-text', 'mj-button', 'mj-navbar-link', 'mj-social-element', 'mj-table']);\n\n/** @param {string|undefined} size */\nconst px = (size) => {\n const n = parseFloat(String(size ?? ''));\n return Number.isNaN(n) ? 0 : n;\n};\n\n/** @param {string|undefined} weight */\nconst isBold = (weight) => /^(bold|bolder|[6-9]00)$/.test(String(weight ?? '').trim());\n\n/**\n * A paragraph's attributes in a new size, its line height in proportion (a\n * text without a size has MJML's 13 px).\n * @param {Record<string, string>} attributes @param {number} size\n */\nfunction resize(attributes, size) {\n const from = px(attributes['font-size']) || 13;\n const lineHeight = String(attributes['line-height'] ?? '').trim();\n attributes['font-size'] = `${size}px`;\n if (/^\\d+(\\.\\d+)?px$/.test(lineHeight)) attributes['line-height'] = `${Math.round((px(lineHeight) * size) / from)}px`;\n}\n\n/**\n * The links of a text in a new color, when theirs is a color (a gray or a\n * black link is a choice, and stays).\n * @param {string} html @param {string} color\n */\nfunction recolorLinks(html, color) {\n return html.replace(/<a\\b[^>]*>/gi, (tag) =>\n tag.replace(/(style\\s*=\\s*\")([^\"]*)(\")/i, (_, open, style, close) =>\n `${open}${style.replace(/(^|;)(\\s*color\\s*:\\s*)([^;]+)/i, (whole, sep, prop, value) =>\n isColored(value) ? `${sep}${prop}${color}` : whole\n )}${close}`\n )\n );\n}\n\n/**\n * One node and what it holds, in the brand's colors.\n * @param {EmailNode} node\n * @param {ReturnType<typeof paletteOf>} palette\n * @param {boolean} onColor the node sits on a colored background\n * @returns {EmailNode}\n */\nfunction paint(node, palette, onColor) {\n const attributes = { ...node.attributes };\n let content = node.content;\n let childrenOnColor = onColor;\n const set = (/** @type {string} */ key, /** @type {string|null} */ value) => {\n if (value) attributes[key] = value;\n };\n\n if (SECTION_LIKE.has(node.tag)) {\n const background = attributes['background-color'];\n if (background && palette.primary && (isColored(background) || (isDark(background) && node.tag !== 'mj-column'))) {\n attributes['background-color'] = palette.primary;\n childrenOnColor = true;\n } else if (background && parseColor(background)) {\n childrenOnColor = false;\n }\n }\n\n if (FONT_TAGS.has(node.tag) && palette.font) set('font-family', palette.font);\n\n if (node.tag === 'mj-text' && content !== null) {\n const size = px(attributes['font-size']) || 13;\n if (palette.fontSize && !isBold(attributes['font-weight']) && size >= 13 && size <= 18 && !isMuted(attributes.color)) {\n resize(attributes, palette.fontSize);\n }\n if (onColor) {\n set('color', palette.onPrimary);\n } else {\n const heading = isBold(attributes['font-weight']) && px(attributes['font-size']) >= 18;\n if (heading && palette.heading && !isMuted(attributes.color)) attributes.color = palette.heading;\n if (palette.link) content = recolorLinks(content, palette.link);\n }\n }\n\n if (node.tag === 'mj-button') {\n const background = attributes['background-color'];\n // MJML's own default is a dark gray: a button without color is filled.\n const filled = !background || isColored(background) || isDark(background);\n if (palette.primary && filled) {\n set('background-color', onColor ? palette.onPrimary : palette.primary);\n set('color', onColor ? palette.primary : palette.onPrimary);\n } else if (palette.primary && onColor) {\n // A light button on a banner: kept light, its text in the main color.\n set('color', readableOn(background) === PALETTE.ink && contrastRatio(palette.primary, background) < 3 ? PALETTE.ink : palette.primary);\n } else if (palette.link && isColored(attributes.color)) {\n // An outlined button on white.\n attributes.color = palette.link;\n if (isColored(attributes['border-color'])) attributes['border-color'] = palette.link;\n }\n }\n\n if (node.tag === 'mj-navbar-link' && isColored(attributes.color)) {\n set('color', onColor ? palette.onPrimary : palette.link);\n }\n\n const children = node.children.map((child) => paint(child, palette, childrenOnColor));\n return { ...node, attributes, content, children };\n}\n\n/** @param {string} html */\nconst plainText = (html) =>\n html\n .replace(/<[^>]*>/g, ' ')\n .replace(/ /g, ' ')\n .replace(/&/g, '&')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/** @param {EmailNode} body */\nconst sectionsOf = (body) =>\n body.children.flatMap((child) => (child.tag === 'mj-wrapper' ? child.children.filter((c) => c.tag === 'mj-section') : [child]));\n\n/**\n * The logo, or the name, at the top; the name in the footer.\n * @param {EmailNode} root\n * @param {Brand} brand\n * @param {{names: string[], logos: string[]}} previous what the email may still show\n * @returns {EmailNode}\n */\nfunction rebrandHeader(root, brand, previous) {\n const body = root.children.find((child) => child.tag === 'mj-body');\n if (!body) return root;\n const names = previous.names.map((name) => String(name || '').trim()).filter((name) => name.length >= 2);\n const known = new Set(names.map((name) => name.toLowerCase()));\n const sections = sectionsOf(body);\n /** @type {Map<string, EmailNode>} */\n const replaced = new Map();\n\n const top = sections[0];\n const column = top?.children.find((child) => child.tag === 'mj-column');\n const first = column?.children[0];\n if (first?.tag === 'mj-image') {\n const small = px(first.attributes.width) > 0 && px(first.attributes.width) <= MAX_LOGO_WIDTH;\n const wasLogo = small || previous.logos.includes(first.attributes.src) || known.has(String(first.attributes.alt || '').toLowerCase());\n if (wasLogo && brand.logoUrl) {\n replaced.set(first.id, {\n ...first,\n attributes: {\n ...first.attributes,\n src: brand.logoUrl,\n alt: brand.name || first.attributes.alt || '',\n width: `${brand.logoWidth || Math.min(px(first.attributes.width) || 140, MAX_LOGO_WIDTH)}px`,\n },\n });\n }\n } else if (first?.tag === 'mj-text' && first.content !== null && known.has(plainText(first.content).toLowerCase())) {\n if (brand.logoUrl) {\n const keep = Object.fromEntries(Object.entries(first.attributes).filter(([key]) => key.startsWith('padding') || key === 'align'));\n replaced.set(\n first.id,\n createNode('mj-image', {\n id: first.id,\n attributes: { src: brand.logoUrl, alt: brand.name || '', width: `${brand.logoWidth || 140}px`, align: 'left', ...keep },\n })\n );\n } else if (brand.name) {\n replaced.set(first.id, { ...first, content: escapeXml(brand.name) });\n }\n }\n\n // The footer: the old name in its line becomes the new one.\n const bottom = sections.length > 1 ? sections[sections.length - 1] : null;\n const newName = brand.name;\n if (bottom && newName) {\n const swap = (/** @type {EmailNode} */ node) => {\n if (node.tag === 'mj-text' && node.content !== null) {\n let html = node.content;\n for (const name of names) {\n if (name !== newName) html = html.split(escapeXml(name)).join(escapeXml(newName));\n }\n if (html !== node.content) replaced.set(node.id, { ...node, content: html });\n }\n node.children.forEach(swap);\n };\n swap(bottom);\n }\n\n if (!replaced.size) return root;\n const rebuild = (/** @type {EmailNode} */ node) => replaced.get(node.id) || { ...node, children: node.children.map(rebuild) };\n return rebuild(root);\n}\n\n/**\n * An email in the brand's look.\n * @param {string} mjml\n * @param {Brand|null|undefined} brand\n * @param {{header?: boolean, previous?: {names?: (string|undefined)[], logos?: (string|undefined)[]}}} [options]\n * `header`: also put the logo (or name) at the top and the name in the\n * footer, replacing what `previous` lists (the names and logos the email\n * may still show: the host's sender, the brand before, \"Your company\").\n * @returns {string}\n */\nexport function applyBrand(mjml, brand, { header = false, previous = {} } = {}) {\n const clean = cleanBrand(brand);\n if (!hasBrand(clean)) return mjml;\n let root = parseMjml(mjml);\n root = paint(root, paletteOf(clean), false);\n if (header) {\n root = rebrandHeader(root, clean, {\n names: /** @type {string[]} */ ((previous.names || []).filter(Boolean)),\n logos: /** @type {string[]} */ ((previous.logos || []).filter(Boolean)),\n });\n }\n return serializeMjml(root);\n}\n\n/**\n * A fragment (a block about to be inserted) in the brand's look.\n * @param {string} mjml @param {Brand|null|undefined} brand\n */\nexport function applyBrandToFragment(mjml, brand) {\n const clean = cleanBrand(brand);\n if (!mjml || !hasBrand(clean)) return mjml;\n const palette = paletteOf(clean);\n return parseMjmlFragment(mjml)\n .map((node) => serializeMjml(paint(node, palette, false), { pretty: false }))\n .join('');\n}\n\n/**\n * A ready-made email (the starter, a gallery template) in the brand's look,\n * its header and footer naming the brand rather than the host's sender or\n * the \"Your company\" placeholder.\n * @param {string} mjml\n * @param {Brand|null|undefined} brand\n * @param {{sender?: import('../templates/starter.js').StarterSender|null, t?: (key: string) => string}} [context]\n */\nexport function brandTemplate(mjml, brand, { sender = null, t = (key) => key } = {}) {\n return applyBrand(mjml, brand, {\n header: true,\n previous: { names: [sender?.name, t('Your company')], logos: [sender?.logoUrl] },\n });\n}\n","// @ts-check\n/**\n * TAGS — colored labels on templates, to sort a library at a glance.\n *\n * The workspace keeps one list of tags, shared by every user like the custom\n * variables; a template carries at most `MAX_TEMPLATE_TAGS` of them, by id.\n * A tag's name is unique (case aside) and its color is one of `TAG_COLORS`,\n * so every tag reads well in the light and the dark theme.\n *\n * The same rules run in the browser (the tags dialog, the memory storage) and\n * on the server (`best-email-builder/server`).\n */\n\nimport { identity } from '../../i18n/index.js';\n\n/** @typedef {{id: string, label: string, color: string}} TemplateTag */\n\nexport const MAX_TEMPLATE_TAGS = 3;\n/** Tags in a workspace. */\nexport const MAX_TAGS = 100;\nexport const TAG_LIMITS = { label: 24 };\nexport const TAG_COLORS = ['gray', 'red', 'orange', 'amber', 'lime', 'green', 'teal', 'cyan', 'blue', 'violet', 'fuchsia', 'pink'];\n\nconst sameName = (a, b) => a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0;\n\n/**\n * @param {any} input `{label, color}`\n * @param {{existing?: TemplateTag[], editing?: string|null, t?: import('../../i18n/index.js').Translate}} [options]\n * `editing`: the id of the tag being edited (its own name is not a duplicate)\n * @returns {{tag: {label: string, color: string}, errors?: undefined} | {tag?: undefined, errors: Record<string, string>}}\n */\nexport function validateTag(input, { existing = [], editing = null, t = identity } = {}) {\n /** @type {Record<string, string>} */\n const errors = {};\n const label = String(input?.label ?? '').replace(/\\s+/g, ' ').trim();\n const color = String(input?.color ?? '');\n if (!label) errors.label = t('Name is required');\n else if (label.length > TAG_LIMITS.label) errors.label = t('{max} characters at most', { max: TAG_LIMITS.label });\n else if (existing.some((tag) => String(tag.id) !== String(editing) && sameName(tag.label, label))) {\n errors.label = t('A tag with this name already exists');\n }\n if (!TAG_COLORS.includes(color)) errors.color = t('Choose a color');\n if (Object.keys(errors).length) return { errors };\n return { tag: { label, color } };\n}\n\n/**\n * The tags a template may carry: known ids, each once, `MAX_TEMPLATE_TAGS`\n * at most, in the list's order.\n *\n * @param {unknown} ids\n * @param {TemplateTag[]} catalog\n * @param {{t?: import('../../i18n/index.js').Translate}} [options]\n * @returns {{ids: string[], error?: undefined} | {ids?: undefined, error: {code: string, message: string}}}\n */\nexport function checkTemplateTags(ids, catalog, { t = identity } = {}) {\n if (!Array.isArray(ids)) return { error: { code: 'INVALID_TAGS', message: t('A list of tags is expected') } };\n const wanted = new Set(ids.map(String));\n if (wanted.size > MAX_TEMPLATE_TAGS) {\n return { error: { code: 'TOO_MANY_TAGS', message: t('{max} tags at most per template', { max: MAX_TEMPLATE_TAGS }) } };\n }\n const known = new Set(catalog.map((tag) => String(tag.id)));\n if ([...wanted].some((id) => !known.has(id))) return { error: { code: 'UNKNOWN_TAG', message: t('Tag not found') } };\n return { ids: catalog.map((tag) => String(tag.id)).filter((id) => wanted.has(id)) };\n}\n\n/** The list's order: by name. @param {TemplateTag[]} tags */\nexport const sortTags = (tags) => [...tags].sort((a, b) => a.label.localeCompare(b.label));\n","// @ts-check\n/**\n * Images UPLOADED in the builder — one rule shared by the browser (immediate\n * rejection, storage/client.js) and the server (storage/server/assetFile.js).\n *\n * PNG, JPEG, GIF: the three formats every email client displays. WebP and SVG\n * do not display in Outlook, and an SVG can carry script.\n * The server reads the type from the file BYTES; the browser, from `file.type`.\n */\n\nimport { identity } from '../i18n/index.js';\n\n/** Maximum image size: beyond it, the email becomes slow to open. */\nexport const MAX_IMAGE_BYTES = 2 * 1024 * 1024;\n\n/** Accepted types → extension of the public key. */\nexport const IMAGE_TYPES = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/gif': 'gif' };\n\n/** Public key: 32 hex characters of the hash + extension. */\nexport const ASSET_KEY_PATTERN = /^[a-f0-9]{32}\\.(png|jpg|gif)$/;\n\nconst SIGNATURES = [\n { type: 'image/png', bytes: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] },\n { type: 'image/jpeg', bytes: [0xff, 0xd8, 0xff] },\n { type: 'image/gif', bytes: [0x47, 0x49, 0x46, 0x38] },\n];\n\n/**\n * Image type detected from the file signature, or `null`.\n * @param {Uint8Array} bytes\n * @returns {{type: string, ext: string}|null}\n */\nexport function detectImage(bytes) {\n if (!bytes || bytes.length < 8) return null;\n const found = SIGNATURES.find((s) => s.bytes.every((b, i) => bytes[i] === b));\n return found ? { type: found.type, ext: IMAGE_TYPES[found.type] } : null;\n}\n\n/**\n * Immediate rejection of a file the server would refuse, or `null`.\n * @param {{type?: string, size?: number}} file\n * @param {{t?: import('../i18n/index.js').Translate}} [options]\n */\nexport function imageUploadError(file, { t = identity } = {}) {\n if (!(String(file?.type || '') in IMAGE_TYPES)) return t('Format rejected: PNG, JPEG or GIF expected');\n if (Number(file?.size || 0) > MAX_IMAGE_BYTES) {\n return t('Image too large: {max} MB maximum', { max: MAX_IMAGE_BYTES / (1024 * 1024) });\n }\n return null;\n}\n"],"mappings":";;;;;AAUO,IAAM,wBAAwB;AAE9B,IAAM,gCAAgC;AAKtC,IAAM,gBAAgB,CAAC,WAAW,QAAQ;AAM1C,IAAM,qBAAqB;;;ACelC,IAAM,aAAa,CAAC;AAEb,IAAM,qBAAN,cAAiC,MAAM;AAAA;AAAA,EAE5C,YAAY,SAAS;AACnB,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEA,SAAS,cAAc,OAAO;AAC5B,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAMO,SAAS,eAAe,EAAE,QAAQ,eAAe,QAAQ,GAAG;AACjE,MAAI,CAAC,OAAQ,OAAM,IAAI,mBAAmB,0BAA0B;AACpE,MAAI,CAAC,cAAc,OAAO,EAAG,OAAM,IAAI,mBAAmB,kCAAkC;AAC5F,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA,eAAe,OAAO,iBAAiB,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
useLayoutWidth,
|
|
6
6
|
useSearchShortcut,
|
|
7
7
|
withPlaceholderImages
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SNQ37KCQ.js";
|
|
9
9
|
import {
|
|
10
10
|
Button,
|
|
11
11
|
Dialog,
|
|
@@ -23,14 +23,14 @@ import {
|
|
|
23
23
|
cn,
|
|
24
24
|
createHttpStorage,
|
|
25
25
|
useUi
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-5ZL3YA33.js";
|
|
27
27
|
import {
|
|
28
28
|
MAX_TEMPLATE_TAGS,
|
|
29
29
|
TAG_COLORS,
|
|
30
30
|
TAG_LIMITS,
|
|
31
31
|
sortTags,
|
|
32
32
|
validateTag
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-AABKWP7D.js";
|
|
34
34
|
|
|
35
35
|
// src/ui/library/TemplateLibrary.jsx
|
|
36
36
|
import { useCallback, useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
|
|
@@ -868,4 +868,4 @@ function TemplateLibrary({ locale = "en", messages, onNotify, ...props }) {
|
|
|
868
868
|
export {
|
|
869
869
|
TemplateLibrary
|
|
870
870
|
};
|
|
871
|
-
//# sourceMappingURL=chunk-
|
|
871
|
+
//# sourceMappingURL=chunk-BGRCQ7FC.js.map
|