@emailens/engine 0.3.1 → 0.5.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/README.md +255 -246
- package/dist/chunk-LW2IMTBA.js +326 -0
- package/dist/chunk-LW2IMTBA.js.map +1 -0
- package/dist/chunk-PFONR3YC.js +56 -0
- package/dist/chunk-PFONR3YC.js.map +1 -0
- package/dist/chunk-SZ5O5PDZ.js +78 -0
- package/dist/chunk-SZ5O5PDZ.js.map +1 -0
- package/dist/chunk-W4SPWESS.js +64 -0
- package/dist/chunk-W4SPWESS.js.map +1 -0
- package/dist/compile/index.cjs +585 -0
- package/dist/compile/index.cjs.map +1 -0
- package/dist/compile/index.d.cts +47 -0
- package/dist/compile/index.d.ts +47 -0
- package/dist/compile/index.js +59 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/index.cjs +5485 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +273 -0
- package/dist/index.d.ts +84 -231
- package/dist/index.js +1455 -927
- package/dist/index.js.map +1 -1
- package/dist/maizzle-YDSYDVSM.js +8 -0
- package/dist/maizzle-YDSYDVSM.js.map +1 -0
- package/dist/mjml-IYGC6AOM.js +8 -0
- package/dist/mjml-IYGC6AOM.js.map +1 -0
- package/dist/react-email-AN62KVVF.js +8 -0
- package/dist/react-email-AN62KVVF.js.map +1 -0
- package/dist/react-email-BQljgXbo.d.cts +289 -0
- package/dist/react-email-BQljgXbo.d.ts +289 -0
- package/package.json +97 -60
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { E as EmailClient, F as Framework, T as TransformResult, C as CSSWarning, a as CodeFix, D as DiffResult, b as ExportPromptOptions, A as AiProvider, c as AiFixResult, S as SpamAnalysisOptions, d as SpamReport, L as LinkReport, e as AccessibilityReport, I as ImageReport } from './react-email-BQljgXbo.cjs';
|
|
2
|
+
export { f as AccessibilityIssue, g as CompileError, h as CompileReactEmailOptions, i as EstimateOptions, j as ExportScope, k as FixType, l as ImageInfo, m as ImageIssue, n as InputFormat, o as LinkIssue, P as PreviewResult, p as SandboxStrategy, q as SpamIssue, r as SupportLevel, s as TokenEstimate, t as TokenEstimateWithWarnings, u as estimateAiFixTokens, v as generateFixPrompt, w as heuristicTokenCount } from './react-email-BQljgXbo.cjs';
|
|
3
|
+
|
|
4
|
+
declare const EMAIL_CLIENTS: EmailClient[];
|
|
5
|
+
declare function getClient(id: string): EmailClient | undefined;
|
|
6
|
+
|
|
7
|
+
declare function transformForClient(html: string, clientId: string, framework?: Framework): TransformResult;
|
|
8
|
+
declare function transformForAllClients(html: string, framework?: Framework): TransformResult[];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Analyze an HTML email and return CSS compatibility warnings
|
|
12
|
+
* for all target email clients.
|
|
13
|
+
*
|
|
14
|
+
* The `framework` parameter controls which fix snippets are attached
|
|
15
|
+
* to warnings — it does NOT change which warnings fire. Analysis always
|
|
16
|
+
* runs on compiled HTML (what email clients actually receive). Fix
|
|
17
|
+
* snippets reference source-level constructs so users know how to
|
|
18
|
+
* modify their framework source code.
|
|
19
|
+
*/
|
|
20
|
+
declare function analyzeEmail(html: string, framework?: Framework): CSSWarning[];
|
|
21
|
+
/**
|
|
22
|
+
* Generate a summary of CSS compatibility for the email.
|
|
23
|
+
*/
|
|
24
|
+
declare function generateCompatibilityScore(warnings: CSSWarning[]): Record<string, {
|
|
25
|
+
score: number;
|
|
26
|
+
errors: number;
|
|
27
|
+
warnings: number;
|
|
28
|
+
info: number;
|
|
29
|
+
}>;
|
|
30
|
+
/** Filter warnings for a specific client. */
|
|
31
|
+
declare function warningsForClient(warnings: CSSWarning[], clientId: string): CSSWarning[];
|
|
32
|
+
/** Get only error-severity warnings. */
|
|
33
|
+
declare function errorWarnings(warnings: CSSWarning[]): CSSWarning[];
|
|
34
|
+
/** Get only structural fix warnings. */
|
|
35
|
+
declare function structuralWarnings(warnings: CSSWarning[]): CSSWarning[];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Simulate dark mode rendering for an email.
|
|
39
|
+
* Email clients apply dark mode differently:
|
|
40
|
+
* - Some invert colors (Gmail Android)
|
|
41
|
+
* - Some use prefers-color-scheme media query (Apple Mail)
|
|
42
|
+
* - Some do partial inversion (Outlook.com)
|
|
43
|
+
*/
|
|
44
|
+
declare function simulateDarkMode(html: string, clientId: string): {
|
|
45
|
+
html: string;
|
|
46
|
+
warnings: CSSWarning[];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Look up a code fix for a given property, client, and optional framework.
|
|
51
|
+
* Returns undefined if no fix snippet exists.
|
|
52
|
+
*
|
|
53
|
+
* Resolution order (most specific to least specific):
|
|
54
|
+
* 1. property::clientPrefix::framework (e.g. "display:flex::outlook::jsx")
|
|
55
|
+
* 2. property::framework (e.g. "display:grid::jsx")
|
|
56
|
+
* 3. property::clientPrefix (e.g. "border-radius::outlook")
|
|
57
|
+
* 4. property (generic fix)
|
|
58
|
+
*/
|
|
59
|
+
declare function getCodeFix(property: string, clientId: string, framework?: Framework): CodeFix | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Look up a suggestion string for a given property, client, and optional framework.
|
|
62
|
+
*
|
|
63
|
+
* Resolution order mirrors `getCodeFix()`:
|
|
64
|
+
* 1. property::clientPrefix::framework
|
|
65
|
+
* 2. property::framework
|
|
66
|
+
* 3. property::clientPrefix
|
|
67
|
+
* 4. property (generic)
|
|
68
|
+
*
|
|
69
|
+
* `isGenericFallback` is true when a framework was specified but no
|
|
70
|
+
* framework-specific entry was found (resolution fell through to tiers 3–4).
|
|
71
|
+
*/
|
|
72
|
+
declare function getSuggestion(property: string, clientId: string, framework?: Framework): {
|
|
73
|
+
text: string;
|
|
74
|
+
isGenericFallback: boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Compare two sets of analysis results to show what improved,
|
|
79
|
+
* what regressed, and what stayed the same.
|
|
80
|
+
*/
|
|
81
|
+
declare function diffResults(before: {
|
|
82
|
+
scores: Record<string, {
|
|
83
|
+
score: number;
|
|
84
|
+
errors: number;
|
|
85
|
+
warnings: number;
|
|
86
|
+
info: number;
|
|
87
|
+
}>;
|
|
88
|
+
warnings: CSSWarning[];
|
|
89
|
+
}, after: {
|
|
90
|
+
scores: Record<string, {
|
|
91
|
+
score: number;
|
|
92
|
+
errors: number;
|
|
93
|
+
warnings: number;
|
|
94
|
+
info: number;
|
|
95
|
+
}>;
|
|
96
|
+
warnings: CSSWarning[];
|
|
97
|
+
}): DiffResult[];
|
|
98
|
+
|
|
99
|
+
interface GenerateAiFixOptions extends ExportPromptOptions {
|
|
100
|
+
/** Callback that sends a prompt to an LLM and returns the response text. */
|
|
101
|
+
provider: AiProvider;
|
|
102
|
+
/**
|
|
103
|
+
* Maximum input tokens for the prompt. If the estimated prompt exceeds
|
|
104
|
+
* this, warnings are intelligently truncated (info first, then CSS-only
|
|
105
|
+
* duplicates). Defaults to 16000.
|
|
106
|
+
*/
|
|
107
|
+
maxInputTokens?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generate an AI-powered fix for email compatibility issues.
|
|
111
|
+
*
|
|
112
|
+
* This uses the deterministic engine's analysis (warnings, scores, fix snippets)
|
|
113
|
+
* to build a structured prompt, then delegates to an LLM for context-aware
|
|
114
|
+
* structural fixes that static snippets cannot handle.
|
|
115
|
+
*
|
|
116
|
+
* The engine stays provider-agnostic — consumers pass their own `AiProvider`
|
|
117
|
+
* callback (Anthropic SDK, Vercel AI SDK, OpenRouter, etc.).
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import Anthropic from "@anthropic-ai/sdk";
|
|
122
|
+
* import { analyzeEmail, generateCompatibilityScore, generateAiFix } from "@emailens/engine";
|
|
123
|
+
*
|
|
124
|
+
* const anthropic = new Anthropic();
|
|
125
|
+
* const warnings = analyzeEmail(html, "jsx");
|
|
126
|
+
* const scores = generateCompatibilityScore(warnings);
|
|
127
|
+
*
|
|
128
|
+
* // 1. Check cost before calling
|
|
129
|
+
* const estimate = await estimateAiFixTokens({
|
|
130
|
+
* originalHtml: html, warnings, scores, scope: "all", format: "jsx",
|
|
131
|
+
* });
|
|
132
|
+
* console.log(`~${estimate.inputTokens} input tokens`);
|
|
133
|
+
*
|
|
134
|
+
* // 2. Generate the fix
|
|
135
|
+
* const result = await generateAiFix({
|
|
136
|
+
* originalHtml: html, warnings, scores, scope: "all", format: "jsx",
|
|
137
|
+
* provider: async (prompt) => {
|
|
138
|
+
* const msg = await anthropic.messages.create({
|
|
139
|
+
* model: "claude-sonnet-4-6",
|
|
140
|
+
* max_tokens: 8192,
|
|
141
|
+
* system: AI_FIX_SYSTEM_PROMPT,
|
|
142
|
+
* messages: [{ role: "user", content: prompt }],
|
|
143
|
+
* });
|
|
144
|
+
* return msg.content[0].type === "text" ? msg.content[0].text : "";
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function generateAiFix(options: GenerateAiFixOptions): Promise<AiFixResult>;
|
|
150
|
+
/**
|
|
151
|
+
* System prompt for the AI fix provider. Consumers should pass this as
|
|
152
|
+
* the `system` parameter to their LLM call for best results.
|
|
153
|
+
*/
|
|
154
|
+
declare const AI_FIX_SYSTEM_PROMPT = "You are an expert email developer specializing in cross-client HTML email compatibility. You fix emails to render correctly across all email clients.\n\nRules:\n- Return ONLY the fixed code inside a single code fence. No explanations before or after.\n- Preserve all existing content, text, links, and visual design.\n- For structural issues (fixType: \"structural\"), you MUST restructure the HTML \u2014 CSS-only changes will not work.\n- Common structural patterns:\n - word-break/overflow-wrap unsupported \u2192 wrap text in <table><tr><td> with constrained width\n - display:flex/grid \u2192 convert to <table> layout (match the original column count and proportions)\n - border-radius in Outlook \u2192 use VML <v:roundrect> with <!--[if mso]> conditionals\n - background-image in Outlook \u2192 use VML <v:rect> with <v:fill>\n - max-width in Outlook \u2192 wrap in <!--[if mso]><table width=\"N\"> conditional\n - position:absolute \u2192 use <table> cells for layout\n - <svg> \u2192 replace with <img> pointing to a hosted PNG\n- For CSS-only issues (fixType: \"css\"), swap properties or add fallbacks.\n- Apply ALL fixes from the issues list \u2014 do not skip any.\n- Use the framework syntax specified (JSX/MJML/Maizzle/HTML).\n- For JSX: use camelCase style props, React Email components, and proper TypeScript types.\n- For MJML: use mj-* elements and attributes.\n- For Maizzle: use Tailwind CSS classes.";
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Properties that require HTML structural changes (not just CSS swaps)
|
|
158
|
+
* to fix. These cannot be solved by replacing one CSS value with another.
|
|
159
|
+
*/
|
|
160
|
+
declare const STRUCTURAL_FIX_PROPERTIES: Set<string>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Analyze an HTML email for spam indicators.
|
|
164
|
+
*
|
|
165
|
+
* Returns a 0-100 score (100 = clean, 0 = very spammy) and an array
|
|
166
|
+
* of issues found. Uses heuristic rules modeled after common spam
|
|
167
|
+
* filter triggers (CAN-SPAM, GDPR, SpamAssassin patterns).
|
|
168
|
+
*/
|
|
169
|
+
declare function analyzeSpam(html: string, options?: SpamAnalysisOptions): SpamReport;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Extract and validate all links from an HTML email.
|
|
173
|
+
*
|
|
174
|
+
* Performs static analysis only (no network requests). Checks for
|
|
175
|
+
* empty/placeholder hrefs, javascript: protocol, insecure HTTP,
|
|
176
|
+
* generic link text, accessibility issues, and more.
|
|
177
|
+
*/
|
|
178
|
+
declare function validateLinks(html: string): LinkReport;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Audit an HTML email for accessibility issues.
|
|
182
|
+
*
|
|
183
|
+
* Checks for missing lang attributes, image alt text, small fonts,
|
|
184
|
+
* layout table roles, link accessibility, heading hierarchy, and
|
|
185
|
+
* color contrast. Returns a 0–100 score and detailed issues.
|
|
186
|
+
*/
|
|
187
|
+
declare function checkAccessibility(html: string): AccessibilityReport;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Analyze images in an HTML email for best practices.
|
|
191
|
+
*
|
|
192
|
+
* Checks for missing dimensions, oversized data URIs, missing alt
|
|
193
|
+
* attributes, unsupported formats (WebP, SVG), tracking pixels,
|
|
194
|
+
* missing display:block, and overall image heaviness.
|
|
195
|
+
*/
|
|
196
|
+
declare function analyzeImages(html: string): ImageReport;
|
|
197
|
+
|
|
198
|
+
interface AuditOptions {
|
|
199
|
+
framework?: Framework;
|
|
200
|
+
/** Options for spam analysis */
|
|
201
|
+
spam?: SpamAnalysisOptions;
|
|
202
|
+
/** Skip specific checks */
|
|
203
|
+
skip?: Array<"spam" | "links" | "accessibility" | "images" | "compatibility">;
|
|
204
|
+
}
|
|
205
|
+
interface AuditReport {
|
|
206
|
+
compatibility: {
|
|
207
|
+
warnings: CSSWarning[];
|
|
208
|
+
scores: Record<string, {
|
|
209
|
+
score: number;
|
|
210
|
+
errors: number;
|
|
211
|
+
warnings: number;
|
|
212
|
+
info: number;
|
|
213
|
+
}>;
|
|
214
|
+
};
|
|
215
|
+
spam: SpamReport;
|
|
216
|
+
links: LinkReport;
|
|
217
|
+
accessibility: AccessibilityReport;
|
|
218
|
+
images: ImageReport;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Run all email analysis checks in a single call.
|
|
222
|
+
*
|
|
223
|
+
* Returns a unified report with compatibility warnings + scores,
|
|
224
|
+
* spam analysis, link validation, accessibility audit, and image analysis.
|
|
225
|
+
* Use the `skip` option to omit checks you don't need.
|
|
226
|
+
*/
|
|
227
|
+
declare function auditEmail(html: string, options?: AuditOptions): AuditReport;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Shared constants used across the engine.
|
|
231
|
+
*/
|
|
232
|
+
/** Maximum HTML input size: 2MB. Inputs exceeding this are rejected early. */
|
|
233
|
+
declare const MAX_HTML_SIZE: number;
|
|
234
|
+
declare const GENERIC_LINK_TEXT: Set<string>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* WCAG 2.1 color parsing, luminance, and contrast utilities.
|
|
238
|
+
*
|
|
239
|
+
* Handles hex (#fff, #ffffff, #rrggbbaa), rgb()/rgba(), 148 named CSS colors,
|
|
240
|
+
* and `transparent`. Returns null for unresolvable values like var(), inherit,
|
|
241
|
+
* currentColor.
|
|
242
|
+
*/
|
|
243
|
+
interface RGBA {
|
|
244
|
+
r: number;
|
|
245
|
+
g: number;
|
|
246
|
+
b: number;
|
|
247
|
+
a: number;
|
|
248
|
+
}
|
|
249
|
+
type WcagGrade = "AAA" | "AA" | "AA Large" | "Fail";
|
|
250
|
+
/**
|
|
251
|
+
* Parse a CSS color value to RGBA. Returns null for unresolvable values.
|
|
252
|
+
*/
|
|
253
|
+
declare function parseColor(value: string): RGBA | null;
|
|
254
|
+
/**
|
|
255
|
+
* Compute WCAG 2.1 relative luminance for an sRGB color.
|
|
256
|
+
* Input values 0-255.
|
|
257
|
+
*/
|
|
258
|
+
declare function relativeLuminance(r: number, g: number, b: number): number;
|
|
259
|
+
/**
|
|
260
|
+
* Compute the WCAG contrast ratio between two relative luminances.
|
|
261
|
+
*/
|
|
262
|
+
declare function contrastRatio(l1: number, l2: number): number;
|
|
263
|
+
/**
|
|
264
|
+
* Determine WCAG 2.1 conformance grade for a contrast ratio.
|
|
265
|
+
*/
|
|
266
|
+
declare function wcagGrade(ratio: number): WcagGrade;
|
|
267
|
+
/**
|
|
268
|
+
* Alpha-blend a foreground RGBA onto an opaque background (r, g, b 0-255).
|
|
269
|
+
* Returns the flattened [r, g, b] as 0-255 values.
|
|
270
|
+
*/
|
|
271
|
+
declare function alphaBlend(fg: RGBA, bgR: number, bgG: number, bgB: number): [number, number, number];
|
|
272
|
+
|
|
273
|
+
export { AI_FIX_SYSTEM_PROMPT, AccessibilityReport, AiFixResult, AiProvider, type AuditOptions, type AuditReport, CSSWarning, CodeFix, DiffResult, EMAIL_CLIENTS, EmailClient, ExportPromptOptions, Framework, GENERIC_LINK_TEXT, type GenerateAiFixOptions, ImageReport, LinkReport, MAX_HTML_SIZE, type RGBA, STRUCTURAL_FIX_PROPERTIES, SpamAnalysisOptions, SpamReport, TransformResult, type WcagGrade, alphaBlend, analyzeEmail, analyzeImages, analyzeSpam, auditEmail, checkAccessibility, contrastRatio, diffResults, errorWarnings, generateAiFix, generateCompatibilityScore, getClient, getCodeFix, getSuggestion, parseColor, relativeLuminance, simulateDarkMode, structuralWarnings, transformForAllClients, transformForClient, validateLinks, warningsForClient, wcagGrade };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,233 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
originalHtml: string;
|
|
4
|
-
warnings: CSSWarning[];
|
|
5
|
-
scores: Record<string, {
|
|
6
|
-
score: number;
|
|
7
|
-
errors: number;
|
|
8
|
-
warnings: number;
|
|
9
|
-
info: number;
|
|
10
|
-
}>;
|
|
11
|
-
scope: ExportScope;
|
|
12
|
-
selectedClientId?: string;
|
|
13
|
-
format?: "html" | "jsx" | "mjml" | "maizzle";
|
|
14
|
-
}
|
|
15
|
-
declare function generateFixPrompt(options: ExportPromptOptions): string;
|
|
16
|
-
|
|
17
|
-
interface TokenEstimate {
|
|
18
|
-
/** Estimated input tokens (prompt + system prompt) */
|
|
19
|
-
inputTokens: number;
|
|
20
|
-
/** Estimated output tokens (fixed code response) */
|
|
21
|
-
estimatedOutputTokens: number;
|
|
22
|
-
/** Raw character count of the prompt */
|
|
23
|
-
promptCharacters: number;
|
|
24
|
-
/** Character count of just the HTML being fixed */
|
|
25
|
-
htmlCharacters: number;
|
|
26
|
-
/** Total warnings included in the prompt */
|
|
27
|
-
warningCount: number;
|
|
28
|
-
/** How many warnings are structural (need HTML changes) */
|
|
29
|
-
structuralCount: number;
|
|
30
|
-
/** Whether warnings were truncated to fit within limits */
|
|
31
|
-
truncated: boolean;
|
|
32
|
-
/** Number of warnings removed during truncation */
|
|
33
|
-
warningsRemoved: number;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Extended return type from `estimateAiFixTokens()` that includes both the
|
|
37
|
-
* token metrics AND the (potentially truncated) warnings list. The `warnings`
|
|
38
|
-
* field is used internally by `generateAiFix()` to build the prompt with the
|
|
39
|
-
* truncated set, but is NOT exposed in `AiFixResult.tokenEstimate` to keep
|
|
40
|
-
* the public API clean.
|
|
41
|
-
*/
|
|
42
|
-
interface TokenEstimateWithWarnings extends TokenEstimate {
|
|
43
|
-
/** The warnings after smart truncation (may be shorter than the input list) */
|
|
44
|
-
warnings: CSSWarning[];
|
|
45
|
-
}
|
|
46
|
-
interface EstimateOptions extends Omit<ExportPromptOptions, "warnings"> {
|
|
47
|
-
warnings: CSSWarning[];
|
|
48
|
-
/**
|
|
49
|
-
* Maximum input tokens to target. If the estimated prompt exceeds
|
|
50
|
-
* this, warnings will be truncated (info first, then duplicates).
|
|
51
|
-
* Defaults to 16000 (~56KB of prompt text).
|
|
52
|
-
*/
|
|
53
|
-
maxInputTokens?: number;
|
|
54
|
-
/**
|
|
55
|
-
* Optional precise token counter. If provided, it will be called
|
|
56
|
-
* with the final prompt text for an exact count. Consumers can wire
|
|
57
|
-
* this to `anthropic.messages.countTokens()`.
|
|
58
|
-
*/
|
|
59
|
-
tokenCounter?: (text: string) => Promise<number> | number;
|
|
60
|
-
/**
|
|
61
|
-
* Token count for the system prompt. Added to the input token estimate
|
|
62
|
-
* since the system prompt counts against the context window. Defaults
|
|
63
|
-
* to 250 (matching the built-in AI_FIX_SYSTEM_PROMPT). Set to 0 if
|
|
64
|
-
* not using a system prompt, or override for custom system prompts.
|
|
65
|
-
*/
|
|
66
|
-
systemPromptTokens?: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Estimate tokens for an AI fix prompt BEFORE making the API call.
|
|
70
|
-
* Use this to show cost estimates, check limits, and decide whether
|
|
71
|
-
* to proceed.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* const estimate = await estimateAiFixTokens({
|
|
76
|
-
* originalHtml: html,
|
|
77
|
-
* warnings,
|
|
78
|
-
* scores,
|
|
79
|
-
* scope: "all",
|
|
80
|
-
* format: "jsx",
|
|
81
|
-
* });
|
|
82
|
-
*
|
|
83
|
-
* console.log(`~${estimate.inputTokens} input tokens`);
|
|
84
|
-
* console.log(`~${estimate.estimatedOutputTokens} output tokens`);
|
|
85
|
-
* console.log(`Truncated: ${estimate.truncated}`);
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
declare function estimateAiFixTokens(options: EstimateOptions): Promise<TokenEstimateWithWarnings>;
|
|
89
|
-
/**
|
|
90
|
-
* Quick synchronous heuristic token count. No deps, no API calls.
|
|
91
|
-
* Accuracy: within ~10-15% of real Claude tokenizer for code/HTML.
|
|
92
|
-
*/
|
|
93
|
-
declare function heuristicTokenCount(text: string): number;
|
|
94
|
-
|
|
95
|
-
type SupportLevel = "supported" | "partial" | "unsupported" | "unknown";
|
|
96
|
-
type Framework = "jsx" | "mjml" | "maizzle";
|
|
97
|
-
type InputFormat = "html" | Framework;
|
|
98
|
-
interface EmailClient {
|
|
99
|
-
id: string;
|
|
100
|
-
name: string;
|
|
101
|
-
category: "webmail" | "desktop" | "mobile";
|
|
102
|
-
engine: string;
|
|
103
|
-
darkModeSupport: boolean;
|
|
104
|
-
icon: string;
|
|
105
|
-
}
|
|
106
|
-
interface CodeFix {
|
|
107
|
-
before: string;
|
|
108
|
-
after: string;
|
|
109
|
-
language: "html" | "css" | "jsx" | "mjml" | "maizzle";
|
|
110
|
-
description: string;
|
|
111
|
-
}
|
|
112
|
-
type FixType = "css" | "structural";
|
|
113
|
-
interface CSSWarning {
|
|
114
|
-
severity: "error" | "warning" | "info";
|
|
115
|
-
client: string;
|
|
116
|
-
property: string;
|
|
117
|
-
message: string;
|
|
118
|
-
suggestion?: string;
|
|
119
|
-
fix?: CodeFix;
|
|
120
|
-
fixIsGenericFallback?: boolean;
|
|
121
|
-
fixType?: FixType;
|
|
122
|
-
line?: number;
|
|
123
|
-
selector?: string;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Callback that sends a prompt to an LLM and returns the text response.
|
|
127
|
-
* Consumers bring their own AI provider (Anthropic SDK, Vercel AI, etc.).
|
|
128
|
-
*/
|
|
129
|
-
type AiProvider = (prompt: string) => Promise<string>;
|
|
130
|
-
interface AiFixResult {
|
|
131
|
-
/** The fixed email code returned by the AI */
|
|
132
|
-
code: string;
|
|
133
|
-
/** The raw prompt that was sent to the AI */
|
|
134
|
-
prompt: string;
|
|
135
|
-
/** Number of warnings the fix was targeting */
|
|
136
|
-
targetedWarnings: number;
|
|
137
|
-
/** How many of those had fixType: "structural" */
|
|
138
|
-
structuralCount: number;
|
|
139
|
-
/** Token estimate for the AI call */
|
|
140
|
-
tokenEstimate: TokenEstimate;
|
|
141
|
-
}
|
|
142
|
-
interface TransformResult {
|
|
143
|
-
clientId: string;
|
|
144
|
-
html: string;
|
|
145
|
-
warnings: CSSWarning[];
|
|
146
|
-
}
|
|
147
|
-
interface PreviewResult {
|
|
148
|
-
id: string;
|
|
149
|
-
originalHtml: string;
|
|
150
|
-
transforms: TransformResult[];
|
|
151
|
-
cssReport: CSSWarning[];
|
|
152
|
-
createdAt: string;
|
|
153
|
-
}
|
|
154
|
-
interface DiffResult {
|
|
155
|
-
clientId: string;
|
|
156
|
-
scoreBefore: number;
|
|
157
|
-
scoreAfter: number;
|
|
158
|
-
scoreDelta: number;
|
|
159
|
-
fixed: CSSWarning[];
|
|
160
|
-
introduced: CSSWarning[];
|
|
161
|
-
unchanged: CSSWarning[];
|
|
162
|
-
}
|
|
163
|
-
interface SpamIssue {
|
|
164
|
-
rule: string;
|
|
165
|
-
severity: "error" | "warning" | "info";
|
|
166
|
-
message: string;
|
|
167
|
-
detail?: string;
|
|
168
|
-
}
|
|
169
|
-
interface SpamReport {
|
|
170
|
-
score: number;
|
|
171
|
-
level: "low" | "medium" | "high";
|
|
172
|
-
issues: SpamIssue[];
|
|
173
|
-
}
|
|
174
|
-
interface SpamAnalysisOptions {
|
|
175
|
-
/** Value of the List-Unsubscribe header, if present */
|
|
176
|
-
listUnsubscribeHeader?: string;
|
|
177
|
-
/** Type of email — transactional emails are exempt from unsubscribe requirements */
|
|
178
|
-
emailType?: "marketing" | "transactional";
|
|
179
|
-
}
|
|
180
|
-
interface LinkIssue {
|
|
181
|
-
severity: "error" | "warning" | "info";
|
|
182
|
-
rule: string;
|
|
183
|
-
message: string;
|
|
184
|
-
href?: string;
|
|
185
|
-
text?: string;
|
|
186
|
-
}
|
|
187
|
-
interface LinkReport {
|
|
188
|
-
totalLinks: number;
|
|
189
|
-
issues: LinkIssue[];
|
|
190
|
-
breakdown: {
|
|
191
|
-
https: number;
|
|
192
|
-
http: number;
|
|
193
|
-
mailto: number;
|
|
194
|
-
tel: number;
|
|
195
|
-
anchor: number;
|
|
196
|
-
other: number;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
interface AccessibilityIssue {
|
|
200
|
-
severity: "error" | "warning" | "info";
|
|
201
|
-
rule: string;
|
|
202
|
-
message: string;
|
|
203
|
-
element?: string;
|
|
204
|
-
details?: string;
|
|
205
|
-
}
|
|
206
|
-
interface AccessibilityReport {
|
|
207
|
-
score: number;
|
|
208
|
-
issues: AccessibilityIssue[];
|
|
209
|
-
}
|
|
210
|
-
interface ImageIssue {
|
|
211
|
-
rule: string;
|
|
212
|
-
severity: "error" | "warning" | "info";
|
|
213
|
-
message: string;
|
|
214
|
-
src?: string;
|
|
215
|
-
}
|
|
216
|
-
interface ImageInfo {
|
|
217
|
-
src: string;
|
|
218
|
-
alt: string | null;
|
|
219
|
-
width: string | null;
|
|
220
|
-
height: string | null;
|
|
221
|
-
isTrackingPixel: boolean;
|
|
222
|
-
dataUriBytes: number;
|
|
223
|
-
issues: string[];
|
|
224
|
-
}
|
|
225
|
-
interface ImageReport {
|
|
226
|
-
total: number;
|
|
227
|
-
totalDataUriBytes: number;
|
|
228
|
-
issues: ImageIssue[];
|
|
229
|
-
images: ImageInfo[];
|
|
230
|
-
}
|
|
1
|
+
import { E as EmailClient, F as Framework, T as TransformResult, C as CSSWarning, a as CodeFix, D as DiffResult, b as ExportPromptOptions, A as AiProvider, c as AiFixResult, S as SpamAnalysisOptions, d as SpamReport, L as LinkReport, e as AccessibilityReport, I as ImageReport } from './react-email-BQljgXbo.js';
|
|
2
|
+
export { f as AccessibilityIssue, g as CompileError, h as CompileReactEmailOptions, i as EstimateOptions, j as ExportScope, k as FixType, l as ImageInfo, m as ImageIssue, n as InputFormat, o as LinkIssue, P as PreviewResult, p as SandboxStrategy, q as SpamIssue, r as SupportLevel, s as TokenEstimate, t as TokenEstimateWithWarnings, u as estimateAiFixTokens, v as generateFixPrompt, w as heuristicTokenCount } from './react-email-BQljgXbo.js';
|
|
231
3
|
|
|
232
4
|
declare const EMAIL_CLIENTS: EmailClient[];
|
|
233
5
|
declare function getClient(id: string): EmailClient | undefined;
|
|
@@ -255,6 +27,12 @@ declare function generateCompatibilityScore(warnings: CSSWarning[]): Record<stri
|
|
|
255
27
|
warnings: number;
|
|
256
28
|
info: number;
|
|
257
29
|
}>;
|
|
30
|
+
/** Filter warnings for a specific client. */
|
|
31
|
+
declare function warningsForClient(warnings: CSSWarning[], clientId: string): CSSWarning[];
|
|
32
|
+
/** Get only error-severity warnings. */
|
|
33
|
+
declare function errorWarnings(warnings: CSSWarning[]): CSSWarning[];
|
|
34
|
+
/** Get only structural fix warnings. */
|
|
35
|
+
declare function structuralWarnings(warnings: CSSWarning[]): CSSWarning[];
|
|
258
36
|
|
|
259
37
|
/**
|
|
260
38
|
* Simulate dark mode rendering for an email.
|
|
@@ -417,4 +195,79 @@ declare function checkAccessibility(html: string): AccessibilityReport;
|
|
|
417
195
|
*/
|
|
418
196
|
declare function analyzeImages(html: string): ImageReport;
|
|
419
197
|
|
|
420
|
-
|
|
198
|
+
interface AuditOptions {
|
|
199
|
+
framework?: Framework;
|
|
200
|
+
/** Options for spam analysis */
|
|
201
|
+
spam?: SpamAnalysisOptions;
|
|
202
|
+
/** Skip specific checks */
|
|
203
|
+
skip?: Array<"spam" | "links" | "accessibility" | "images" | "compatibility">;
|
|
204
|
+
}
|
|
205
|
+
interface AuditReport {
|
|
206
|
+
compatibility: {
|
|
207
|
+
warnings: CSSWarning[];
|
|
208
|
+
scores: Record<string, {
|
|
209
|
+
score: number;
|
|
210
|
+
errors: number;
|
|
211
|
+
warnings: number;
|
|
212
|
+
info: number;
|
|
213
|
+
}>;
|
|
214
|
+
};
|
|
215
|
+
spam: SpamReport;
|
|
216
|
+
links: LinkReport;
|
|
217
|
+
accessibility: AccessibilityReport;
|
|
218
|
+
images: ImageReport;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Run all email analysis checks in a single call.
|
|
222
|
+
*
|
|
223
|
+
* Returns a unified report with compatibility warnings + scores,
|
|
224
|
+
* spam analysis, link validation, accessibility audit, and image analysis.
|
|
225
|
+
* Use the `skip` option to omit checks you don't need.
|
|
226
|
+
*/
|
|
227
|
+
declare function auditEmail(html: string, options?: AuditOptions): AuditReport;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Shared constants used across the engine.
|
|
231
|
+
*/
|
|
232
|
+
/** Maximum HTML input size: 2MB. Inputs exceeding this are rejected early. */
|
|
233
|
+
declare const MAX_HTML_SIZE: number;
|
|
234
|
+
declare const GENERIC_LINK_TEXT: Set<string>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* WCAG 2.1 color parsing, luminance, and contrast utilities.
|
|
238
|
+
*
|
|
239
|
+
* Handles hex (#fff, #ffffff, #rrggbbaa), rgb()/rgba(), 148 named CSS colors,
|
|
240
|
+
* and `transparent`. Returns null for unresolvable values like var(), inherit,
|
|
241
|
+
* currentColor.
|
|
242
|
+
*/
|
|
243
|
+
interface RGBA {
|
|
244
|
+
r: number;
|
|
245
|
+
g: number;
|
|
246
|
+
b: number;
|
|
247
|
+
a: number;
|
|
248
|
+
}
|
|
249
|
+
type WcagGrade = "AAA" | "AA" | "AA Large" | "Fail";
|
|
250
|
+
/**
|
|
251
|
+
* Parse a CSS color value to RGBA. Returns null for unresolvable values.
|
|
252
|
+
*/
|
|
253
|
+
declare function parseColor(value: string): RGBA | null;
|
|
254
|
+
/**
|
|
255
|
+
* Compute WCAG 2.1 relative luminance for an sRGB color.
|
|
256
|
+
* Input values 0-255.
|
|
257
|
+
*/
|
|
258
|
+
declare function relativeLuminance(r: number, g: number, b: number): number;
|
|
259
|
+
/**
|
|
260
|
+
* Compute the WCAG contrast ratio between two relative luminances.
|
|
261
|
+
*/
|
|
262
|
+
declare function contrastRatio(l1: number, l2: number): number;
|
|
263
|
+
/**
|
|
264
|
+
* Determine WCAG 2.1 conformance grade for a contrast ratio.
|
|
265
|
+
*/
|
|
266
|
+
declare function wcagGrade(ratio: number): WcagGrade;
|
|
267
|
+
/**
|
|
268
|
+
* Alpha-blend a foreground RGBA onto an opaque background (r, g, b 0-255).
|
|
269
|
+
* Returns the flattened [r, g, b] as 0-255 values.
|
|
270
|
+
*/
|
|
271
|
+
declare function alphaBlend(fg: RGBA, bgR: number, bgG: number, bgB: number): [number, number, number];
|
|
272
|
+
|
|
273
|
+
export { AI_FIX_SYSTEM_PROMPT, AccessibilityReport, AiFixResult, AiProvider, type AuditOptions, type AuditReport, CSSWarning, CodeFix, DiffResult, EMAIL_CLIENTS, EmailClient, ExportPromptOptions, Framework, GENERIC_LINK_TEXT, type GenerateAiFixOptions, ImageReport, LinkReport, MAX_HTML_SIZE, type RGBA, STRUCTURAL_FIX_PROPERTIES, SpamAnalysisOptions, SpamReport, TransformResult, type WcagGrade, alphaBlend, analyzeEmail, analyzeImages, analyzeSpam, auditEmail, checkAccessibility, contrastRatio, diffResults, errorWarnings, generateAiFix, generateCompatibilityScore, getClient, getCodeFix, getSuggestion, parseColor, relativeLuminance, simulateDarkMode, structuralWarnings, transformForAllClients, transformForClient, validateLinks, warningsForClient, wcagGrade };
|