/** * Plaza iframe embed helpers — full-page iframe height sync for publication pages. */ export const PLAZA_EMBED_QUERY = 'embed=plaza'; export function isPlazaEmbedRequest(query = {}) { return String(query?.embed ?? '').toLowerCase() === 'plaza'; } export function publishedPageCspForEmbed(isFullHtml) { if (isFullHtml) { return "default-src 'none'; style-src 'unsafe-inline' https:; img-src 'self' data: https: http:; font-src https: data:; base-uri 'none'; form-action 'self'; frame-ancestors *; script-src 'unsafe-inline'"; } return "default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors *; script-src 'unsafe-inline'"; } export function allowPlazaEmbedFrame(res) { res.removeHeader?.('X-Frame-Options'); } const EMBED_BOOTSTRAP = ``; const EMBED_LAYOUT_OVERRIDES = ''; /** Remove inline CSP meta tags that block plaza-embed-bootstrap (HTTP CSP header applies instead). */ export function stripPublicationHtmlCspMeta(html) { return String(html ?? '').replace( /]*>/gi, '', ); } /** Prepare stored publication HTML for Plaza iframe embed. */ export function preparePublicationHtmlForEmbed(html) { let source = stripPublicationHtmlCspMeta(html); if (!source.includes('id="plaza-embed-overrides"') && /]*>/i.test(source)) { source = source.replace(/]*)>/i, `${EMBED_LAYOUT_OVERRIDES}`); } return injectPlazaEmbedBootstrap(source); } export function injectPlazaEmbedBootstrap(html) { const source = String(html ?? ''); if (source.includes('id="plaza-embed-bootstrap"')) return source; if (/<\/body>/i.test(source)) { return source.replace(/<\/body>/i, `${EMBED_BOOTSTRAP}`); } return `${source}${EMBED_BOOTSTRAP}`; } export function appendPlazaEmbedQuery(url) { const value = String(url ?? '').trim(); if (!value) return value; if (value.includes(PLAZA_EMBED_QUERY)) return value; return value.includes('?') ? `${value}&${PLAZA_EMBED_QUERY}` : `${value}?${PLAZA_EMBED_QUERY}`; }