// stacksjs/stacks#1902 (B2) — pure-TS CSS inliner for email HTML. // // Gmail (especially the Android app) and older Outlook clients strip // or ignore `` — that specific block // is treated as opaque (not parsed, not stripped). /** * Options accepted by {@link inlineCss}. */ export interface InlineCssOptions { /** * When `false`, returns the HTML unchanged. Production-default ON, * dev-default OFF — see `email/src/template.ts` for the env gate. */ inline?: boolean /** * Append `!important` to every inlined declaration. Email clients * often have their own user agents that override author styles, * so this is the safe default. */ important?: boolean } /** * Inline `` // block with a placeholder so we don't accidentally consume it. We // restore the placeholder at the very end. const passthroughBlocks: string[] = [] working = working.replace( /]*\bdata-inline=["']false["'][^>]*>[\s\S]*?<\/style>/gi, (match) => { passthroughBlocks.push(match) return `\0STX_PASSTHROUGH_${passthroughBlocks.length - 1}\0` }, ) // Pull out every remaining `` // Inject before `` if present; otherwise prepend. working = /<\/head>/i.test(working) ? working.replace(/<\/head>/i, `${styleTag}\n`) : `${styleTag}\n${working}` } return restorePassthroughs(working, passthroughBlocks) } /** * Replace placeholders with their original `