@samva/markup 0.16.0 → 0.17.1
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/AGENTS.md +42 -40
- package/CHANGELOG.md +72 -0
- package/README.md +10 -9
- package/dist/{brand-jFV6YtSV.d.ts → assets-CS5Xa_mr.d.ts} +41 -3
- package/dist/{brand-Ci05p37c.js → brand-CIiEqkU7.js} +64 -3
- package/dist/{brand-plugin-CHhcei-j.d.ts → brand-plugin-Dj9SMpfS.d.ts} +3 -1
- package/dist/brand.d.ts +2 -3
- package/dist/brand.js +3 -4
- package/dist/compatibility.d.ts +76 -0
- package/dist/compatibility.js +807 -0
- package/dist/compiled-template-Bc4Dq9zy.d.ts +268 -0
- package/dist/compiler.d.ts +59 -193
- package/dist/compiler.js +473 -775
- package/dist/{components-3XHjYD3i.js → components-C5850-Qg.js} +37 -29
- package/dist/css-B_aVKrDo.js +436 -0
- package/dist/css-color-DLM12Osu.js +315 -0
- package/dist/{diagnostic-codes-8XDLR9ef.js → diagnostic-codes-DZKb0Xcg.js} +40 -1
- package/dist/{diagnostics-CUYlQ_6x.d.ts → diagnostics-D4vSLQrO.d.ts} +1 -10
- package/dist/diagnostics.d.ts +6 -2
- package/dist/diagnostics.js +3 -4
- package/dist/edit.d.ts +10 -9
- package/dist/edit.js +12 -11
- package/dist/email/jsx-dev-runtime.d.ts +1 -1
- package/dist/email/jsx-dev-runtime.js +1 -1
- package/dist/email/jsx-runtime.d.ts +2 -2
- package/dist/email/jsx-runtime.js +2 -2
- package/dist/email.d.ts +1 -1
- package/dist/email.js +1 -1
- package/dist/html-DJUK2YJF.js +483 -0
- package/dist/index.d.ts +1 -1
- package/dist/{jsx-runtime-DC7xG0aA.d.ts → jsx-runtime-DL8NVF1f.d.ts} +12 -6
- package/dist/{jsx-runtime-CBlexoeR.js → jsx-runtime-qL19u3Fy.js} +17 -10
- package/dist/preview-rNoJBEIY.d.ts +104 -0
- package/dist/{profile-BsY4dkan.js → profile-JTvgCD6X.js} +714 -29
- package/dist/{html-BvRFepeO.js → render-template-DwPDm3Hq.js} +155 -572
- package/dist/render.d.ts +40 -28
- package/dist/render.js +3 -47
- package/dist/selectors-CYWCoxZr.js +157 -0
- package/dist/sms.d.ts +1 -1
- package/dist/sms.js +1 -1
- package/dist/{template-B-UDXK8a.d.ts → template-DmNcoH4Q.d.ts} +2 -9
- package/dist/{theme-css-s9QwD5Ko.js → theme-css-P9F5S7Ic.js} +3 -316
- package/dist/whatsapp.d.ts +1 -1
- package/dist/whatsapp.js +1 -1
- package/generated/contract.json +7 -2
- package/generated/reference.md +3 -2
- package/package.json +5 -5
- package/skills/sml/SKILL.md +2 -2
- package/dist/assets-BSpgZOSR.js +0 -61
- package/dist/assets-BSuNT9gr.d.ts +0 -39
- package/dist/brand-footer-ClRtWnIc.d.ts +0 -40
- package/dist/brand-footer-DXVGsKE5.js +0 -746
- package/dist/brand-sample.d.ts +0 -4
- package/dist/brand-sample.js +0 -2
- package/dist/cascade-DoLWZ66g.js +0 -701
- package/dist/diagnostic-model-DJtqbETd.js +0 -36
- package/dist/ir-KJLFW08u.js +0 -5
- package/dist/render-CVnXZMyK.js +0 -258
- package/dist/render-CuZej25A.d.ts +0 -564
- package/dist/theme-imports-u_P0ygvQ.js +0 -102
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import { r as renderEmail } from "./render-template-DwPDm3Hq.js";
|
|
2
|
+
import { n as parseColor } from "./css-color-DLM12Osu.js";
|
|
3
|
+
import { n as matchesSelector } from "./selectors-CYWCoxZr.js";
|
|
4
|
+
import { t as parseStylesheet } from "./css-B_aVKrDo.js";
|
|
5
|
+
import { generate, parse, walk } from "css-tree";
|
|
6
|
+
import { caniemail, parseHtml, rawData } from "caniemail";
|
|
7
|
+
//#region src/email/compatibility-assessment.ts
|
|
8
|
+
const VERIFIED_VALUES = /^(?:left|right|center|justify)$/i;
|
|
9
|
+
const SIMPLE_COLOR = /^(?:#[\da-f]{3,8}|rgba?\([^()]+\)|transparent|white|black)$/i;
|
|
10
|
+
/**
|
|
11
|
+
* A feature matrix establishes support, not the effect on a particular message.
|
|
12
|
+
* These rules interpret the pinned caniemail@2.0.2 limitations using emitted
|
|
13
|
+
* values. Unresolved layout, fallback and client-account behavior stays unverified.
|
|
14
|
+
*/
|
|
15
|
+
const assessCompatibility = (title, client, support, context, blocking) => {
|
|
16
|
+
const result = (assessment, heading, explanation) => ({
|
|
17
|
+
assessment,
|
|
18
|
+
title: heading,
|
|
19
|
+
explanation
|
|
20
|
+
});
|
|
21
|
+
if (client === "outlook.windows" && support === "partial" && (title === "display" || title === "display:none") && context.hiddenContentOffsets.length > 0) return result("risk", "Hidden content becomes visible in classic Outlook", "Classic Outlook ignores display:none on images and does not inherit it onto nested tables. The emitted inline styles contain hidden content without a resolved hiding fallback. Add a supported hiding fallback before publishing.");
|
|
22
|
+
if (blocking) return result("risk", `${title} is unavailable in a target client`, "This construct is required for message content, structure or navigation. Replace it with a supported construct before publishing.");
|
|
23
|
+
const explained = context.explanation(title, client, support);
|
|
24
|
+
if (explained !== void 0) return result(title.startsWith("system-ui,") ? "degradation" : "not-applicable", title.startsWith("system-ui,") ? "A fallback font will be used" : `${title}: limitation avoided`, explained);
|
|
25
|
+
const declarations = (property) => context.declarations(property);
|
|
26
|
+
const every = (property, predicate) => {
|
|
27
|
+
const values = declarations(property);
|
|
28
|
+
return context.complete && values.length > 0 && values.every(({ value }) => predicate(value));
|
|
29
|
+
};
|
|
30
|
+
const attributesAvoid = (attribute, unsupportedElement) => {
|
|
31
|
+
const values = context.attributes(attribute);
|
|
32
|
+
return values.length > 0 && values.every(({ element }) => element !== unsupportedElement);
|
|
33
|
+
};
|
|
34
|
+
if (title === "font-size" && support === "partial" && ["outlook.windows", "yahoo.desktop-webmail"].includes(client) && declarations("font-size").some(({ value }) => /\d(?:\.\d+)?rem\b/i.test(value))) return result("risk", "Text sizes use unsupported rem units", "These clients cannot apply the emitted rem font sizes. Use pixel sizes to preserve the intended text size.");
|
|
35
|
+
if (title === "target attribute" && context.attributes("target").some(({ value }) => value !== "_blank")) return result("risk", "Links cannot keep the requested window target", "These clients open links in a new window regardless of the requested target. Use a new-window target or remove the dependency on another browsing context.");
|
|
36
|
+
if (title.startsWith("system-ui,") && declarations("font-family").some(({ value }) => !/(?:^|,)\s*(?:sans-serif|serif|monospace)\s*$/i.test(value))) return result("risk", "An unsupported font stack has no generic fallback", "Declare a generic fallback so the client has an explicit font choice when the requested system font is unavailable.");
|
|
37
|
+
if (title === "border-radius" && support !== "partial") return result("degradation", "Corners may appear square", "CSS corner rounding is unavailable in this client. Uncovered elements appear square; a separate VML shape can retain rounding. This finding does not establish a content or navigation failure.");
|
|
38
|
+
if (title === "border-radius" && client === "yahoo.desktop-webmail" && support === "partial") return result("degradation", "Corner shapes may differ", "This client does not support elliptical slash syntax. Review the recorded values if that corner shape is part of the intended design.");
|
|
39
|
+
if (title === "background") {
|
|
40
|
+
const values = [...declarations("background"), ...declarations("background-color")];
|
|
41
|
+
if (context.complete && values.length > 0 && values.every(({ value }) => SIMPLE_COLOR.test(value)) && declarations("background-image").every(({ value }) => value.toLowerCase() === "none")) return result("not-applicable", "Backgrounds use supported color values", "The emitted backgrounds use simple colors. The cited multiple-background and background-size shorthand limitations do not apply.");
|
|
42
|
+
}
|
|
43
|
+
if (title === "dir attribute" && client === "outlook.windows" && attributesAvoid("dir", "a")) return result("not-applicable", "Direction is set outside links", "The cited direction bug affects anchor elements. No emitted anchor carries a dir attribute.");
|
|
44
|
+
if (title === "lang attribute" && client === "yahoo.desktop-webmail" && attributesAvoid("lang", "td")) return result("not-applicable", "Language is set outside table cells", "The cited language-attribute limitation affects table cells. No emitted td carries a lang attribute.");
|
|
45
|
+
if (title === "role attribute" && client === "yahoo.desktop-webmail" && context.attributes("role").length > 0 && context.attributes("role").every(({ element }) => element === "table")) return result("not-applicable", "Roles are applied to supported tables", "Every emitted role attribute is on a table, matching this client's supported element scope.");
|
|
46
|
+
if (title === "text-align" && support === "partial" && every("text-align", (value) => VERIFIED_VALUES.test(value))) return result("not-applicable", "Text uses supported alignment values", "The emitted alignment values do not use match-parent or flow-relative start/end values.");
|
|
47
|
+
if (title === "font-weight" && support === "partial") {
|
|
48
|
+
const pattern = client === "outlook.windows" ? /^(?:normal|bold|400|700)$/i : /^(?:normal|bold|[1-9]00)$/i;
|
|
49
|
+
if (every("font-weight", (value) => pattern.test(value))) return result("not-applicable", "Font weights avoid the numeric limitation", "The emitted weights use values preserved by this client's pinned numeric-weight rule.");
|
|
50
|
+
return result("degradation", "Font weight may be approximated", "This client may substitute a supported weight. Text remains present, but its emphasis can look different.");
|
|
51
|
+
}
|
|
52
|
+
if (title === "outline" && every("outline", (value) => value === "none" || value === "0")) return result("unverified", "Image outlines need a client check", "The emitted styles remove outlines. The matrix cannot establish whether this client adds its own link or image outline.");
|
|
53
|
+
if (title === "width attribute" && client === "outlook.windows" && context.attributes(title.split(" ")[0]).some(({ value, element }) => element === "img" && value.includes("%"))) return result("risk", "Percentage image dimensions use the wrong reference size", "Classic Outlook sizes percentage image attributes against the image file rather than its parent. Use fixed image dimensions with an appropriate responsive fallback.");
|
|
54
|
+
if (title === "overflow" && declarations("overflow").some(({ value }) => /^(?:auto|scroll)$/i.test(value))) return result("risk", "Scrollable content may be inaccessible", "These clients cannot reliably expose content hidden behind a scrolling container. Keep required email content visible without scrolling inside an element.");
|
|
55
|
+
return result("unverified", {
|
|
56
|
+
"<body> element": "Body styling needs a client check",
|
|
57
|
+
border: "Borders need an Outlook check",
|
|
58
|
+
"color-scheme meta tag": "Dark appearance needs a client check",
|
|
59
|
+
display: "Display behavior needs a client check",
|
|
60
|
+
"display:none": "Hidden content needs an Outlook check",
|
|
61
|
+
"height attribute": "Image sizing needs a high-DPI Outlook check",
|
|
62
|
+
"height property": "Element heights need a client check",
|
|
63
|
+
"line-height": "Line spacing needs an Outlook check",
|
|
64
|
+
margin: "Outer spacing needs a client check",
|
|
65
|
+
"max-height property": "Height limits need an Outlook check",
|
|
66
|
+
"max-width": "Width limits need a client check",
|
|
67
|
+
"@media": "Conditional styles need a client check",
|
|
68
|
+
opacity: "Transparent content needs an Outlook check",
|
|
69
|
+
overflow: "Clipped content needs a client check",
|
|
70
|
+
"overflow-wrap": "Long text wrapping needs a client check",
|
|
71
|
+
padding: "Cell spacing needs an Outlook check",
|
|
72
|
+
"<style> element": "Retained styles need a client check",
|
|
73
|
+
"text-decoration": "Link decoration needs a client check",
|
|
74
|
+
"width attribute": "Image sizing needs a high-DPI Outlook check",
|
|
75
|
+
"width property": "Element widths need an Outlook check",
|
|
76
|
+
"word-break": "Word breaking needs a client check"
|
|
77
|
+
}[title] ?? `${title} needs a client check`, "The feature matrix identifies a support difference but does not establish its effect on this message. Check the affected fixtures in the listed clients before relying on this behavior; no automatic source change is justified by this observation alone.");
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/email/compatibility-context.ts
|
|
81
|
+
const NON_HIDING_VALUES = {
|
|
82
|
+
"mso-hide": /^none$/,
|
|
83
|
+
visibility: /^visible$/,
|
|
84
|
+
opacity: /^(?:1(?:\.0+)?|100(?:\.0+)?%)$/,
|
|
85
|
+
overflow: /^visible$/,
|
|
86
|
+
"overflow-y": /^visible$/,
|
|
87
|
+
"overflow-x": /^visible$/,
|
|
88
|
+
clip: /^auto$/,
|
|
89
|
+
"clip-path": /^none$/
|
|
90
|
+
};
|
|
91
|
+
const POSITIVE_FIXED_HEIGHT = /^(?:\d+(?:\.\d+)?|\.\d+)(?:px|pt|pc|in|cm|mm)$/;
|
|
92
|
+
/** Evidence from actual declarations and elements, never a text match in email content. */
|
|
93
|
+
const compatibilityContext = (html, css) => {
|
|
94
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
95
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
96
|
+
const elements = /* @__PURE__ */ new Map();
|
|
97
|
+
let complete = true;
|
|
98
|
+
let unresolvedStyles = false;
|
|
99
|
+
const hiddenContentOffsets = [];
|
|
100
|
+
const addCss = (source, context, offset, element) => {
|
|
101
|
+
const inline = /* @__PURE__ */ new Map();
|
|
102
|
+
if (context === "stylesheet" && source.trim() !== "") unresolvedStyles = true;
|
|
103
|
+
try {
|
|
104
|
+
const ast = parse(source, { context });
|
|
105
|
+
walk(ast, (node) => {
|
|
106
|
+
if (node.type === "Raw") complete = false;
|
|
107
|
+
if (node.type !== "Declaration") return;
|
|
108
|
+
const property = node.property.toLowerCase();
|
|
109
|
+
const entries = declarations.get(property) ?? [];
|
|
110
|
+
const value = generate(node.value);
|
|
111
|
+
entries.push({
|
|
112
|
+
value,
|
|
113
|
+
offset,
|
|
114
|
+
element
|
|
115
|
+
});
|
|
116
|
+
if (!inline.get(property)?.important || node.important) inline.set(property, {
|
|
117
|
+
value: value.toLowerCase(),
|
|
118
|
+
important: Boolean(node.important)
|
|
119
|
+
});
|
|
120
|
+
declarations.set(property, entries);
|
|
121
|
+
});
|
|
122
|
+
} catch {
|
|
123
|
+
complete = false;
|
|
124
|
+
}
|
|
125
|
+
return inline;
|
|
126
|
+
};
|
|
127
|
+
const { document } = parseHtml(html);
|
|
128
|
+
const visit = (node, ancestors = []) => {
|
|
129
|
+
let descendants = ancestors;
|
|
130
|
+
if (node.type === "comment" && /\[if\b/i.test(node.data)) unresolvedStyles = true;
|
|
131
|
+
if ("attribs" in node) {
|
|
132
|
+
const offset = node.startIndex ?? void 0;
|
|
133
|
+
if (offset !== void 0) {
|
|
134
|
+
const entries = elements.get(node.name) ?? [];
|
|
135
|
+
entries.push(offset);
|
|
136
|
+
elements.set(node.name, entries);
|
|
137
|
+
}
|
|
138
|
+
for (const [name, value] of Object.entries(node.attribs)) {
|
|
139
|
+
const entries = attributes.get(name) ?? [];
|
|
140
|
+
entries.push({
|
|
141
|
+
value,
|
|
142
|
+
offset,
|
|
143
|
+
element: node.name
|
|
144
|
+
});
|
|
145
|
+
attributes.set(name, entries);
|
|
146
|
+
}
|
|
147
|
+
const styles = node.attribs.style === void 0 ? /* @__PURE__ */ new Map() : addCss(node.attribs.style, "declarationList", offset, node.name);
|
|
148
|
+
descendants = [...ancestors, {
|
|
149
|
+
offset,
|
|
150
|
+
styles
|
|
151
|
+
}];
|
|
152
|
+
const fallback = descendants.some(({ styles: candidate }) => {
|
|
153
|
+
const candidateDisplay = candidate.get("display")?.value;
|
|
154
|
+
return candidateDisplay !== void 0 && !/^(?:none|block|inline|inline-block|table|table-row|table-cell|table-row-group)$/i.test(candidateDisplay) || candidate.has("all") || Object.entries(NON_HIDING_VALUES).some(([property, neutral]) => {
|
|
155
|
+
const value = candidate.get(property)?.value;
|
|
156
|
+
return value !== void 0 && !neutral.test(value);
|
|
157
|
+
}) || ["height", "max-height"].some((property) => {
|
|
158
|
+
const value = candidate.get(property)?.value;
|
|
159
|
+
return value !== void 0 && value !== (property === "height" ? "auto" : "none") && !(POSITIVE_FIXED_HEIGHT.test(value) && Number.parseFloat(value) > 0);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const hiddenAncestor = ancestors.find(({ styles: candidate }) => candidate.get("display")?.value === "none");
|
|
163
|
+
const display = styles.get("display")?.value;
|
|
164
|
+
if (!fallback && node.name === "img" && display === "none" && hiddenAncestor === void 0 && offset !== void 0) hiddenContentOffsets.push(offset);
|
|
165
|
+
if (!fallback && node.name === "table" && hiddenAncestor !== void 0 && display === void 0 && hiddenAncestor.offset !== void 0) hiddenContentOffsets.push(hiddenAncestor.offset);
|
|
166
|
+
if (node.name === "style") {
|
|
167
|
+
for (const child of node.children) if (child.type === "text") addCss(child.data, "stylesheet");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if ("children" in node) for (const child of node.children) visit(child, descendants);
|
|
171
|
+
};
|
|
172
|
+
for (const child of document.children) visit(child);
|
|
173
|
+
if (css !== void 0) addCss(css, "stylesheet");
|
|
174
|
+
const everyValue = (property, predicate) => {
|
|
175
|
+
const entries = declarations.get(property);
|
|
176
|
+
return complete && entries !== void 0 && entries.length > 0 && entries.every(({ value }) => predicate(value));
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
/** Known hidden-content failures; unresolved cascade or fallback evidence cannot block. */
|
|
180
|
+
get hiddenContentOffsets() {
|
|
181
|
+
return complete && !unresolvedStyles ? [...new Set(hiddenContentOffsets)] : [];
|
|
182
|
+
},
|
|
183
|
+
/** Incomplete CSS cannot prove that every occurrence avoids a limitation. */
|
|
184
|
+
get complete() {
|
|
185
|
+
return complete;
|
|
186
|
+
},
|
|
187
|
+
declarations(property) {
|
|
188
|
+
return declarations.get(property) ?? [];
|
|
189
|
+
},
|
|
190
|
+
attributes(name) {
|
|
191
|
+
return attributes.get(name) ?? [];
|
|
192
|
+
},
|
|
193
|
+
/** Bounded exceptions to caniemail@2.0.2's feature-wide matrix, tied to its client rules. */
|
|
194
|
+
explanation(title, client, support) {
|
|
195
|
+
if (title === "font-size" && support === "partial" && ["outlook.windows", "yahoo.desktop-webmail"].includes(client) && everyValue("font-size", (value) => /^(?:0|(?:\d+(?:\.\d+)?|\.\d+)px)$/i.test(value))) return "All font sizes use pixels; this client's rem-unit limitation does not apply.";
|
|
196
|
+
if (title === "border-radius" && support === "partial" && client === "yahoo.desktop-webmail" && everyValue("border-radius", (value) => /^(?:0|(?:\d+(?:\.\d+)?|\.\d+)(?:px|%))(?:\s+(?:0|(?:\d+(?:\.\d+)?|\.\d+)(?:px|%))){0,3}$/i.test(value))) return "These corner radii do not use the unsupported elliptical slash syntax.";
|
|
197
|
+
if (title === "target attribute" && [
|
|
198
|
+
"gmail.desktop-webmail",
|
|
199
|
+
"gmail.ios",
|
|
200
|
+
"gmail.android",
|
|
201
|
+
"outlook.outlook-com",
|
|
202
|
+
"yahoo.desktop-webmail",
|
|
203
|
+
"outlook.windows",
|
|
204
|
+
"apple-mail.macos",
|
|
205
|
+
"apple-mail.ios"
|
|
206
|
+
].includes(client) && attributes.has("target") && attributes.get("target").every(({ value }) => value === "_blank")) return "Links already request a new window, matching the client's enforced behavior.";
|
|
207
|
+
if (title === "system-ui, ui-serif, ui-sans-serif, ui-rounded, ui-monospace" && everyValue("font-family", (value) => /(?:^|,)\s*(?:sans-serif|serif|monospace)\s*$/i.test(value))) return "Every font stack ends with a generic fallback. Font appearance can differ in this client.";
|
|
208
|
+
},
|
|
209
|
+
offsets(title) {
|
|
210
|
+
const element = /^<([a-z0-9]+)> element$/i.exec(title);
|
|
211
|
+
if (element !== null) return elements.get(element[1]) ?? [];
|
|
212
|
+
const attribute = /^([a-z-]+) attribute$/i.exec(title);
|
|
213
|
+
const entries = attribute !== null ? attributes.get(attribute[1]) : declarations.get(title.startsWith("system-ui,") ? "font-family" : title.replace(/ property$/, ""));
|
|
214
|
+
return [...new Set(entries?.flatMap(({ offset }) => offset === void 0 ? [] : [offset]) ?? [])];
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/email/contrast.ts
|
|
220
|
+
const CANVAS = {
|
|
221
|
+
light: {
|
|
222
|
+
r: 1,
|
|
223
|
+
g: 1,
|
|
224
|
+
b: 1,
|
|
225
|
+
a: 1
|
|
226
|
+
},
|
|
227
|
+
dark: {
|
|
228
|
+
r: 18 / 255,
|
|
229
|
+
g: 18 / 255,
|
|
230
|
+
b: 18 / 255,
|
|
231
|
+
a: 1
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
/** The ratios `email-contrast` holds a message to, and what counts as large text. */
|
|
235
|
+
const CONTRAST_THRESHOLDS = {
|
|
236
|
+
/** Text below this is an error at any size. */
|
|
237
|
+
textError: 3,
|
|
238
|
+
/** Normal-size text below this is a warning (WCAG AA). */
|
|
239
|
+
textWarning: 4.5,
|
|
240
|
+
/** Text at least this many pixels is large, as is bold text at `largeBoldPx`. */
|
|
241
|
+
largePx: 24,
|
|
242
|
+
largeBoldPx: 18.5,
|
|
243
|
+
/** A filled button below this against its surroundings is an error. */
|
|
244
|
+
shapeError: 1.5,
|
|
245
|
+
/** A filled button below this is a warning (WCAG 1.4.11). */
|
|
246
|
+
shapeWarning: 3,
|
|
247
|
+
/** A button border at least this against the surroundings keeps the shape. */
|
|
248
|
+
border: 3
|
|
249
|
+
};
|
|
250
|
+
const TEXT_ERROR = CONTRAST_THRESHOLDS.textError;
|
|
251
|
+
const TEXT_WARNING = CONTRAST_THRESHOLDS.textWarning;
|
|
252
|
+
const LARGE_PX = CONTRAST_THRESHOLDS.largePx;
|
|
253
|
+
const LARGE_BOLD_PX = CONTRAST_THRESHOLDS.largeBoldPx;
|
|
254
|
+
const SHAPE_ERROR = CONTRAST_THRESHOLDS.shapeError;
|
|
255
|
+
const SHAPE_WARNING = CONTRAST_THRESHOLDS.shapeWarning;
|
|
256
|
+
const INSET_BORDER = CONTRAST_THRESHOLDS.border;
|
|
257
|
+
const SKIPPED_TAGS = /* @__PURE__ */ new Set([
|
|
258
|
+
"head",
|
|
259
|
+
"style",
|
|
260
|
+
"title",
|
|
261
|
+
"script"
|
|
262
|
+
]);
|
|
263
|
+
const INVISIBLE = /[\s\u200b-\u200f\ufeff\u00a0\u00ad]|\u034f/g;
|
|
264
|
+
const DARK_QUERY = /^@media\b[^{]*\(\s*prefers-color-scheme\s*:\s*dark\s*\)/i;
|
|
265
|
+
const clamp = (value) => value < 0 ? 0 : value > 1 ? 1 : value;
|
|
266
|
+
const channel = (value) => {
|
|
267
|
+
const v = clamp(value);
|
|
268
|
+
return v <= .04045 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4;
|
|
269
|
+
};
|
|
270
|
+
const luminance = (color) => .2126 * channel(color.r) + .7152 * channel(color.g) + .0722 * channel(color.b);
|
|
271
|
+
const ratioOf = (left, right) => {
|
|
272
|
+
const a = luminance(left);
|
|
273
|
+
const b = luminance(right);
|
|
274
|
+
return (Math.max(a, b) + .05) / (Math.min(a, b) + .05);
|
|
275
|
+
};
|
|
276
|
+
const hex = (color) => `#${[
|
|
277
|
+
color.r,
|
|
278
|
+
color.g,
|
|
279
|
+
color.b
|
|
280
|
+
].map((value) => Math.round(clamp(value) * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
281
|
+
const over = (top, below) => ({
|
|
282
|
+
r: top.r * top.a + below.r * (1 - top.a),
|
|
283
|
+
g: top.g * top.a + below.g * (1 - top.a),
|
|
284
|
+
b: top.b * top.a + below.b * (1 - top.a),
|
|
285
|
+
a: 1
|
|
286
|
+
});
|
|
287
|
+
const declarationsOf = (source) => {
|
|
288
|
+
const found = [];
|
|
289
|
+
try {
|
|
290
|
+
walk(parse(source, {
|
|
291
|
+
context: "declarationList",
|
|
292
|
+
positions: false
|
|
293
|
+
}), (node) => {
|
|
294
|
+
if (node.type === "Declaration") found.push({
|
|
295
|
+
property: node.property.toLowerCase(),
|
|
296
|
+
value: generate(node.value).trim()
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
} catch {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
return found;
|
|
303
|
+
};
|
|
304
|
+
/** Split on whitespace that is not inside parentheses. */
|
|
305
|
+
const tokens = (value) => {
|
|
306
|
+
const found = [];
|
|
307
|
+
let depth = 0;
|
|
308
|
+
let current = "";
|
|
309
|
+
for (const char of value) {
|
|
310
|
+
if (char === "(") depth += 1;
|
|
311
|
+
if (char === ")") depth -= 1;
|
|
312
|
+
if (/\s/.test(char) && depth === 0) {
|
|
313
|
+
if (current !== "") found.push(current);
|
|
314
|
+
current = "";
|
|
315
|
+
} else current += char;
|
|
316
|
+
}
|
|
317
|
+
if (current !== "") found.push(current);
|
|
318
|
+
return found;
|
|
319
|
+
};
|
|
320
|
+
const declaredColor = (value) => {
|
|
321
|
+
const color = parseColor(value);
|
|
322
|
+
return color === void 0 ? "unknown" : color;
|
|
323
|
+
};
|
|
324
|
+
const pixels = (value) => {
|
|
325
|
+
const trimmed = value.trim();
|
|
326
|
+
if (/^[+-]?0+(?:\.0+)?$/.test(trimmed)) return 0;
|
|
327
|
+
const match = /^(\d+(?:\.\d+)?|\.\d+)px$/i.exec(trimmed);
|
|
328
|
+
return match === null ? void 0 : Number(match[1]);
|
|
329
|
+
};
|
|
330
|
+
const BORDER_STYLES = /^(?:solid|dashed|dotted|double|groove|ridge|inset|outset|none|hidden)$/i;
|
|
331
|
+
const WIDTH_KEYWORDS = {
|
|
332
|
+
thin: 1,
|
|
333
|
+
medium: 3,
|
|
334
|
+
thick: 5
|
|
335
|
+
};
|
|
336
|
+
const resolve = (declarations) => {
|
|
337
|
+
let background;
|
|
338
|
+
let image = false;
|
|
339
|
+
let color;
|
|
340
|
+
let display;
|
|
341
|
+
let fontSize;
|
|
342
|
+
let bold;
|
|
343
|
+
const border = {
|
|
344
|
+
width: void 0,
|
|
345
|
+
visible: void 0,
|
|
346
|
+
color: void 0
|
|
347
|
+
};
|
|
348
|
+
for (const { property, value } of declarations) {
|
|
349
|
+
const lower = value.toLowerCase();
|
|
350
|
+
switch (property) {
|
|
351
|
+
case "background":
|
|
352
|
+
image = /url\(|gradient\(/.test(lower);
|
|
353
|
+
background = tokens(value).filter((part) => !/^(?:url|[\w-]*gradient)\(/i.test(part)).map(parseColor).find((entry) => entry !== void 0) ?? (/var\(|currentcolor|inherit|initial|unset/.test(lower) ? "unknown" : void 0);
|
|
354
|
+
break;
|
|
355
|
+
case "background-color":
|
|
356
|
+
background = declaredColor(value);
|
|
357
|
+
break;
|
|
358
|
+
case "background-image":
|
|
359
|
+
image = lower !== "none";
|
|
360
|
+
break;
|
|
361
|
+
case "color":
|
|
362
|
+
color = declaredColor(value);
|
|
363
|
+
break;
|
|
364
|
+
case "display":
|
|
365
|
+
display = lower.replace(/\s*!important$/, "");
|
|
366
|
+
break;
|
|
367
|
+
case "font-size":
|
|
368
|
+
fontSize = pixels(value);
|
|
369
|
+
break;
|
|
370
|
+
case "font-weight": {
|
|
371
|
+
const weight = Number(lower);
|
|
372
|
+
if (lower === "bold" || lower === "bolder") bold = true;
|
|
373
|
+
else if (lower === "normal" || lower === "lighter") bold = false;
|
|
374
|
+
else if (!Number.isNaN(weight)) bold = weight >= 700;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
case "border":
|
|
378
|
+
case "border-width":
|
|
379
|
+
case "border-color":
|
|
380
|
+
case "border-style": {
|
|
381
|
+
const parts = tokens(value);
|
|
382
|
+
if (property === "border") {
|
|
383
|
+
border.width = WIDTH_KEYWORDS.medium;
|
|
384
|
+
border.visible = false;
|
|
385
|
+
border.color = "unknown";
|
|
386
|
+
}
|
|
387
|
+
const styles = parts.filter((part) => BORDER_STYLES.test(part));
|
|
388
|
+
if (styles.length > 0) border.visible = styles.every((part) => !/^(?:none|hidden)$/i.test(part));
|
|
389
|
+
const sizes = parts.map((part) => pixels(part) ?? WIDTH_KEYWORDS[part.toLowerCase()]).filter((entry) => entry !== void 0);
|
|
390
|
+
if (sizes.length > 0) border.width = Math.min(...sizes);
|
|
391
|
+
else if (property === "border-width") border.width = void 0;
|
|
392
|
+
const named = parts.filter((part) => pixels(part) === void 0 && WIDTH_KEYWORDS[part.toLowerCase()] === void 0 && !BORDER_STYLES.test(part));
|
|
393
|
+
if (property !== "border-width" && property !== "border-style" && named.length > 0) {
|
|
394
|
+
const colors = named.map(parseColor);
|
|
395
|
+
border.color = colors.every((entry) => entry !== void 0) ? colors[0] : "unknown";
|
|
396
|
+
}
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
background,
|
|
403
|
+
image,
|
|
404
|
+
color,
|
|
405
|
+
display,
|
|
406
|
+
fontSize,
|
|
407
|
+
bold,
|
|
408
|
+
border
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
/** Properties a declaration list sets, for deciding whether an unimportant dark rule can apply. */
|
|
412
|
+
const has = (declarations, property) => declarations.some((entry) => entry.property === property);
|
|
413
|
+
const advance = (parent, style, tag) => {
|
|
414
|
+
let background = parent.background;
|
|
415
|
+
let ownBackground;
|
|
416
|
+
if (style.image || style.background === "unknown") background = "unknown";
|
|
417
|
+
else if (style.background !== void 0 && style.background.a > 0) {
|
|
418
|
+
if (style.background.a >= 1) background = style.background;
|
|
419
|
+
else if (parent.background !== "unknown") background = over(style.background, parent.background);
|
|
420
|
+
else background = "unknown";
|
|
421
|
+
if (background !== "unknown") ownBackground = background;
|
|
422
|
+
}
|
|
423
|
+
let color = tag === "a" ? void 0 : parent.color;
|
|
424
|
+
if (style.color === "unknown") color = "unknown";
|
|
425
|
+
else if (style.color !== void 0) color = style.color;
|
|
426
|
+
return {
|
|
427
|
+
ownBackground,
|
|
428
|
+
state: {
|
|
429
|
+
background,
|
|
430
|
+
color,
|
|
431
|
+
fontSize: style.fontSize ?? parent.fontSize,
|
|
432
|
+
bold: style.bold ?? parent.bold,
|
|
433
|
+
hidden: parent.hidden || style.display === "none"
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
const originsAt$1 = (positions, offset) => {
|
|
438
|
+
if (offset === void 0) return [];
|
|
439
|
+
let best;
|
|
440
|
+
for (const position of positions) {
|
|
441
|
+
if (offset < position.start || offset >= position.end) continue;
|
|
442
|
+
if (best === void 0 || position.end - position.start < best.end - best.start) best = position;
|
|
443
|
+
}
|
|
444
|
+
return best?.origins ?? [];
|
|
445
|
+
};
|
|
446
|
+
const compareRules = (left, right) => {
|
|
447
|
+
const important = (rule) => rule.declarations.some((d) => d.important) ? 1 : 0;
|
|
448
|
+
return important(left) - important(right) || left.specificity[0] - right.specificity[0] || left.specificity[1] - right.specificity[1] || left.specificity[2] - right.specificity[2] || left.order - right.order;
|
|
449
|
+
};
|
|
450
|
+
const textOf = (node) => node.children.map((child) => "data" in child ? String(child.data) : "").join("");
|
|
451
|
+
const MODE_LABEL = {
|
|
452
|
+
light: "Light mode",
|
|
453
|
+
dark: "Dark mode"
|
|
454
|
+
};
|
|
455
|
+
const FIX = "Pair background and text tokens (bg-primary with text-primary-foreground) and give the theme's dark-mode @theme a value for the token, or choose colors that reach";
|
|
456
|
+
/**
|
|
457
|
+
* Check text and filled-control contrast in the emitted document, in light and
|
|
458
|
+
* dark presentation.
|
|
459
|
+
*/
|
|
460
|
+
const checkEmailContrast = (input) => {
|
|
461
|
+
const { document } = parseHtml(input.html);
|
|
462
|
+
const sheets = input.css === void 0 ? [] : [input.css];
|
|
463
|
+
const collect = (nodes) => {
|
|
464
|
+
for (const node of nodes) {
|
|
465
|
+
if (!("attribs" in node)) continue;
|
|
466
|
+
if (node.name === "style") sheets.push(textOf(node));
|
|
467
|
+
else collect(node.children);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
collect(document.children);
|
|
471
|
+
const darkRules = sheets.flatMap((sheet) => parseStylesheet(sheet).rules).filter((rule) => rule.conditions.length === 1 && DARK_QUERY.test(rule.conditions[0])).toSorted(compareRules);
|
|
472
|
+
const findings = /* @__PURE__ */ new Map();
|
|
473
|
+
const report = (mode, kind, foreground, background, ratio, required, severity, offset) => {
|
|
474
|
+
const origins = originsAt$1(input.positions ?? [], offset);
|
|
475
|
+
const measured = ratio.toFixed(2);
|
|
476
|
+
const colors = `${hex(foreground)} on ${hex(background)}`;
|
|
477
|
+
const message = kind === "text" ? `${MODE_LABEL[mode]}: text ${colors} has a contrast ratio of ${measured}:1; ${required}:1 is required. ${FIX} ${required}:1.` : `${MODE_LABEL[mode]}: the button background ${hex(foreground)} against its surroundings ${hex(background)} has a contrast ratio of ${measured}:1; ${SHAPE_WARNING}:1 is required for the shape to stay visible (below ${SHAPE_ERROR}:1 it disappears). ${FIX} ${SHAPE_WARNING}:1, or give the button a border that does.`;
|
|
478
|
+
const key = JSON.stringify([
|
|
479
|
+
mode,
|
|
480
|
+
kind,
|
|
481
|
+
hex(foreground),
|
|
482
|
+
hex(background),
|
|
483
|
+
measured,
|
|
484
|
+
origins
|
|
485
|
+
]);
|
|
486
|
+
const existing = findings.get(key);
|
|
487
|
+
if (existing !== void 0) {
|
|
488
|
+
if (origins.length > 0) existing.occurrences.push(origins);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
findings.set(key, {
|
|
492
|
+
key,
|
|
493
|
+
occurrences: origins.length > 0 ? [origins] : [],
|
|
494
|
+
diagnostic: {
|
|
495
|
+
code: "email-contrast",
|
|
496
|
+
severity,
|
|
497
|
+
message,
|
|
498
|
+
origins,
|
|
499
|
+
...input.fixture === void 0 ? {} : { fixtures: [input.fixture] }
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
const visit = (node, parents, parentAncestry, previous) => {
|
|
504
|
+
const inline = declarationsOf(node.attribs.style ?? "");
|
|
505
|
+
const attribute = node.attribs.bgcolor === void 0 ? [] : [{
|
|
506
|
+
property: "background-color",
|
|
507
|
+
value: node.attribs.bgcolor
|
|
508
|
+
}];
|
|
509
|
+
const shape = {
|
|
510
|
+
type: "Element",
|
|
511
|
+
tag: node.name,
|
|
512
|
+
props: node.attribs,
|
|
513
|
+
children: [],
|
|
514
|
+
origins: [],
|
|
515
|
+
authored: false
|
|
516
|
+
};
|
|
517
|
+
const ancestry = {
|
|
518
|
+
element: shape,
|
|
519
|
+
parent: parentAncestry,
|
|
520
|
+
previous
|
|
521
|
+
};
|
|
522
|
+
const base = [...attribute, ...inline];
|
|
523
|
+
const dark = [...base];
|
|
524
|
+
for (const rule of darkRules) {
|
|
525
|
+
if (!matchesSelector(rule.matcher, ancestry)) continue;
|
|
526
|
+
for (const declaration of rule.declarations) {
|
|
527
|
+
const property = declaration.property.toLowerCase();
|
|
528
|
+
if (declaration.important || !has(inline, property)) dark.push({
|
|
529
|
+
property,
|
|
530
|
+
value: declaration.value.replace(/\s*!important$/i, "")
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
const styles = {
|
|
535
|
+
light: resolve(base),
|
|
536
|
+
dark: resolve(dark)
|
|
537
|
+
};
|
|
538
|
+
const direct = node.children.some((child) => child.type === "text" && String(child.data).replace(INVISIBLE, "") !== "");
|
|
539
|
+
const states = {
|
|
540
|
+
light: parents.light,
|
|
541
|
+
dark: parents.dark
|
|
542
|
+
};
|
|
543
|
+
for (const mode of ["light", "dark"]) {
|
|
544
|
+
const parent = parents[mode];
|
|
545
|
+
const style = styles[mode];
|
|
546
|
+
const { state, ownBackground } = advance(parent, style, node.name);
|
|
547
|
+
states[mode] = state;
|
|
548
|
+
if (state.hidden) continue;
|
|
549
|
+
if (node.name === "a" && ownBackground !== void 0 && parent.background !== "unknown" && !style.image) {
|
|
550
|
+
const ratio = ratioOf(ownBackground, parent.background);
|
|
551
|
+
if (ratio < SHAPE_WARNING) {
|
|
552
|
+
const { width, visible, color } = style.border;
|
|
553
|
+
const bordered = visible === true && width !== void 0 && width > 0 && color !== void 0;
|
|
554
|
+
if (!(bordered && color !== "unknown" && ratioOf(over(color, parent.background), parent.background) >= INSET_BORDER) && !(bordered && color === "unknown")) report(mode, "button", ownBackground, parent.background, ratio, SHAPE_WARNING, ratio < SHAPE_ERROR ? "error" : "warning", node.startIndex ?? void 0);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (direct && state.color !== void 0 && state.color !== "unknown" && state.background !== "unknown") {
|
|
558
|
+
const ink = over(state.color, state.background);
|
|
559
|
+
const ratio = ratioOf(ink, state.background);
|
|
560
|
+
const required = state.fontSize !== void 0 && (state.fontSize >= LARGE_PX || state.bold && state.fontSize >= LARGE_BOLD_PX) ? TEXT_ERROR : TEXT_WARNING;
|
|
561
|
+
if (ratio < required) report(mode, "text", ink, state.background, ratio, required, ratio < TEXT_ERROR ? "error" : "warning", node.startIndex ?? void 0);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (!SKIPPED_TAGS.has(node.name) && (!states.light.hidden || !states.dark.hidden)) {
|
|
565
|
+
let siblings = [];
|
|
566
|
+
for (const child of node.children) {
|
|
567
|
+
if (!("attribs" in child) || SKIPPED_TAGS.has(child.name)) continue;
|
|
568
|
+
const done = visit(child, states, ancestry, siblings);
|
|
569
|
+
siblings = [...siblings, done];
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return shape;
|
|
573
|
+
};
|
|
574
|
+
const root = {
|
|
575
|
+
light: {
|
|
576
|
+
background: CANVAS.light,
|
|
577
|
+
color: void 0,
|
|
578
|
+
fontSize: void 0,
|
|
579
|
+
bold: false,
|
|
580
|
+
hidden: false
|
|
581
|
+
},
|
|
582
|
+
dark: {
|
|
583
|
+
background: CANVAS.dark,
|
|
584
|
+
color: void 0,
|
|
585
|
+
fontSize: void 0,
|
|
586
|
+
bold: false,
|
|
587
|
+
hidden: false
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
let siblings = [];
|
|
591
|
+
for (const node of document.children) {
|
|
592
|
+
if (!("attribs" in node) || SKIPPED_TAGS.has(node.name)) continue;
|
|
593
|
+
siblings = [...siblings, visit(node, root, void 0, siblings)];
|
|
594
|
+
}
|
|
595
|
+
return [...findings.values()].map(({ diagnostic, occurrences }) => ({
|
|
596
|
+
...diagnostic,
|
|
597
|
+
...occurrences.length > 1 ? { occurrences } : {}
|
|
598
|
+
}));
|
|
599
|
+
};
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/email/compatibility.ts
|
|
602
|
+
/**
|
|
603
|
+
* The pinned matrix. Every finding is reported per client, and a client absent
|
|
604
|
+
* from this list is a client Samva makes no claim about.
|
|
605
|
+
*/
|
|
606
|
+
const EMAIL_CLIENT_MATRIX = [
|
|
607
|
+
{
|
|
608
|
+
id: "gmail.desktop-webmail",
|
|
609
|
+
label: "Gmail web"
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
id: "gmail.ios",
|
|
613
|
+
label: "Gmail iOS"
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
id: "gmail.android",
|
|
617
|
+
label: "Gmail Android"
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
id: "apple-mail.macos",
|
|
621
|
+
label: "Apple Mail macOS"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
id: "apple-mail.ios",
|
|
625
|
+
label: "Apple Mail iOS"
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
id: "yahoo.desktop-webmail",
|
|
629
|
+
label: "Yahoo web"
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
id: "outlook.outlook-com",
|
|
633
|
+
label: "Outlook web and new Windows"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
id: "outlook.windows",
|
|
637
|
+
label: "Outlook classic Windows"
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
const LABELS = new Map(EMAIL_CLIENT_MATRIX.map((target) => [target.id, target.label]));
|
|
641
|
+
const COMPATIBILITY_PROVENANCE = {
|
|
642
|
+
rules: "caniemail@2.0.2",
|
|
643
|
+
apiVersion: rawData.api_version,
|
|
644
|
+
lastUpdate: rawData.last_update_date
|
|
645
|
+
};
|
|
646
|
+
/**
|
|
647
|
+
* The constructs whose loss actually breaks a message: the recipient reads
|
|
648
|
+
* something different, in a different order, follows a link that does not work,
|
|
649
|
+
* or sees a layout that has collapsed. A target client dropping one of these
|
|
650
|
+
* blocks publication.
|
|
651
|
+
*
|
|
652
|
+
* The list is deliberately short and enumerated, because the contract is to
|
|
653
|
+
* block *known* failures. Nonessential differences require an assessment of
|
|
654
|
+
* emitted values: a concrete risk warns, expected differences and unverified
|
|
655
|
+
* behavior remain compatibility observations.
|
|
656
|
+
*/
|
|
657
|
+
const ESSENTIAL_CONSTRUCTS = /* @__PURE__ */ new Set([
|
|
658
|
+
"<table> element",
|
|
659
|
+
"<div> element",
|
|
660
|
+
"<p> element",
|
|
661
|
+
"<span> element",
|
|
662
|
+
"<ul>, <ol> and <dl>",
|
|
663
|
+
"<h1> to <h6> elements",
|
|
664
|
+
"HTML5 doctype",
|
|
665
|
+
"width attribute",
|
|
666
|
+
"height attribute",
|
|
667
|
+
"align attribute",
|
|
668
|
+
"valign attribute",
|
|
669
|
+
"<img> element",
|
|
670
|
+
"display",
|
|
671
|
+
"mailto: links",
|
|
672
|
+
"Local anchors"
|
|
673
|
+
]);
|
|
674
|
+
const KNOWN_TITLES = new Set(rawData.data.map((feature) => feature.title));
|
|
675
|
+
/** The innermost recorded node containing an offset, so a finding names its element. */
|
|
676
|
+
const originsAt = (positions, offset) => {
|
|
677
|
+
let best;
|
|
678
|
+
for (const position of positions) {
|
|
679
|
+
if (offset < position.start || offset >= position.end) continue;
|
|
680
|
+
if (best === void 0 || position.end - position.start < best.end - best.start) best = position;
|
|
681
|
+
}
|
|
682
|
+
return best?.origins ?? [];
|
|
683
|
+
};
|
|
684
|
+
const slug = (title) => title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
685
|
+
/**
|
|
686
|
+
* Check the emitted document against the pinned matrix.
|
|
687
|
+
*
|
|
688
|
+
* Findings are grouped by construct rather than repeated per client, so one
|
|
689
|
+
* unsupported property is one diagnostic naming every client that drops it.
|
|
690
|
+
*/
|
|
691
|
+
const checkHtmlCompatibility = (input) => {
|
|
692
|
+
const targets = input.clients ?? EMAIL_CLIENT_MATRIX;
|
|
693
|
+
const context = compatibilityContext(input.html, input.css);
|
|
694
|
+
const targetClients = targets.map((target) => target.id);
|
|
695
|
+
const reports = [caniemail({
|
|
696
|
+
clients: targetClients,
|
|
697
|
+
html: input.html
|
|
698
|
+
}), ...input.css === void 0 ? [] : [caniemail({
|
|
699
|
+
clients: targetClients,
|
|
700
|
+
css: input.css
|
|
701
|
+
})]];
|
|
702
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
703
|
+
for (const bucket of reports.flatMap((report) => [report.issues.errors, report.issues.warnings])) for (const [client, issues] of bucket) {
|
|
704
|
+
const label = LABELS.get(client) ?? client;
|
|
705
|
+
for (const raw of issues) {
|
|
706
|
+
const hiddenContentFailure = client === "outlook.windows" && raw.support === "partial" && (raw.title === "display" || raw.title === "display:none") && context.hiddenContentOffsets.length > 0;
|
|
707
|
+
const blocking = hiddenContentFailure || raw.support !== "partial" && ESSENTIAL_CONSTRUCTS.has(raw.title);
|
|
708
|
+
const { explanation, ...compatibility } = assessCompatibility(raw.title, client, raw.support, context, blocking);
|
|
709
|
+
const key = JSON.stringify([
|
|
710
|
+
raw.title,
|
|
711
|
+
raw.support,
|
|
712
|
+
compatibility,
|
|
713
|
+
explanation
|
|
714
|
+
]);
|
|
715
|
+
const offsets = hiddenContentFailure ? context.hiddenContentOffsets : context.offsets(raw.title);
|
|
716
|
+
const entry = grouped.get(key);
|
|
717
|
+
if (entry === void 0) grouped.set(key, {
|
|
718
|
+
title: raw.title,
|
|
719
|
+
support: raw.support,
|
|
720
|
+
clients: /* @__PURE__ */ new Set([label]),
|
|
721
|
+
notes: new Set(raw.notes),
|
|
722
|
+
explanation,
|
|
723
|
+
compatibility,
|
|
724
|
+
blocking,
|
|
725
|
+
offsets
|
|
726
|
+
});
|
|
727
|
+
else {
|
|
728
|
+
entry.clients.add(label);
|
|
729
|
+
for (const note of raw.notes) entry.notes.add(note);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const findings = [];
|
|
734
|
+
for (const entry of grouped.values()) {
|
|
735
|
+
const severity = entry.blocking ? "error" : entry.compatibility.assessment === "risk" ? "warning" : "info";
|
|
736
|
+
const occurrences = entry.offsets.map((offset) => originsAt(input.positions ?? [], offset)).filter((origins) => origins.length > 0);
|
|
737
|
+
const clients = [...entry.clients].sort();
|
|
738
|
+
const dropped = entry.support === "partial" ? clients.length === 1 ? "partially supports" : "partially support" : clients.length === 1 ? "does not support" : "do not support";
|
|
739
|
+
findings.push({
|
|
740
|
+
code: `caniemail/${slug(entry.title)}`,
|
|
741
|
+
severity,
|
|
742
|
+
message: `${clients.join(", ")} ${dropped} ${entry.title}. ${entry.explanation}`,
|
|
743
|
+
compatibility: entry.compatibility,
|
|
744
|
+
origins: occurrences[0] ?? [],
|
|
745
|
+
...occurrences.length === 0 ? {} : { occurrences },
|
|
746
|
+
...input.fixture === void 0 ? {} : { fixtures: [input.fixture] },
|
|
747
|
+
clients,
|
|
748
|
+
...entry.notes.size === 0 ? {} : { notes: [...entry.notes].join(" ") },
|
|
749
|
+
provenance: `${COMPATIBILITY_PROVENANCE.rules} (caniemail data ${COMPATIBILITY_PROVENANCE.apiVersion}, updated ${COMPATIBILITY_PROVENANCE.lastUpdate})`
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
findings.push(...checkEmailContrast(input));
|
|
753
|
+
return findings.sort((left, right) => left.code.localeCompare(right.code));
|
|
754
|
+
};
|
|
755
|
+
/**
|
|
756
|
+
* Constructs the pinned data says nothing about for a target client. These are
|
|
757
|
+
* reported so "we did not check that" is never mistaken for "that works".
|
|
758
|
+
*/
|
|
759
|
+
const unknownCoverage = (titles) => [...titles].filter((title) => !KNOWN_TITLES.has(title)).sort().map((title) => ({
|
|
760
|
+
code: "caniemail/unknown-coverage",
|
|
761
|
+
severity: "info",
|
|
762
|
+
message: `The pinned rules say nothing about ${title}, so no client claim is made about it. Verify it in a real client before relying on it.`,
|
|
763
|
+
origins: [],
|
|
764
|
+
provenance: `${COMPATIBILITY_PROVENANCE.rules} (caniemail data ${COMPATIBILITY_PROVENANCE.apiVersion}, updated ${COMPATIBILITY_PROVENANCE.lastUpdate})`
|
|
765
|
+
}));
|
|
766
|
+
/** A publication carrying one of these is refused; the message would arrive broken. */
|
|
767
|
+
const hasBlockingCompatibility = (findings) => findings.some((finding) => finding.severity === "error");
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region src/sml/compatibility.ts
|
|
770
|
+
/**
|
|
771
|
+
* Check what each declared fixture delivers against the pinned client matrix. The rules run on the
|
|
772
|
+
* rendered document, because what a client drops is what the compiler produced, and every finding
|
|
773
|
+
* is located at the source of the element that produced it. A fixture the renderer refuses throws
|
|
774
|
+
* its `RenderError`: validate fixtures before asking what they deliver.
|
|
775
|
+
*/
|
|
776
|
+
const checkCompatibility = (template, fixtures, options = {}) => {
|
|
777
|
+
if (template.email === void 0) return [];
|
|
778
|
+
const sources = template.sources ?? [];
|
|
779
|
+
const findings = [];
|
|
780
|
+
for (const [fixture, input] of Object.entries(fixtures)) {
|
|
781
|
+
const rendered = renderEmail(template, input, {
|
|
782
|
+
positions: true,
|
|
783
|
+
...options.brandPlugin === void 0 ? {} : { brandPlugin: options.brandPlugin }
|
|
784
|
+
});
|
|
785
|
+
const positions = (rendered.positions ?? []).map((position, index) => ({
|
|
786
|
+
start: position.start,
|
|
787
|
+
end: position.end,
|
|
788
|
+
tag: position.tag,
|
|
789
|
+
instancePath: String(index),
|
|
790
|
+
authored: true,
|
|
791
|
+
origins: position.src === void 0 ? [] : [{
|
|
792
|
+
fileName: sources[position.src[2] ?? 0] ?? "",
|
|
793
|
+
lineNumber: position.src[0],
|
|
794
|
+
columnNumber: position.src[1]
|
|
795
|
+
}]
|
|
796
|
+
}));
|
|
797
|
+
findings.push(...checkHtmlCompatibility({
|
|
798
|
+
html: rendered.html,
|
|
799
|
+
fixture,
|
|
800
|
+
positions,
|
|
801
|
+
...options.clients === void 0 ? {} : { clients: options.clients }
|
|
802
|
+
}));
|
|
803
|
+
}
|
|
804
|
+
return findings;
|
|
805
|
+
};
|
|
806
|
+
//#endregion
|
|
807
|
+
export { COMPATIBILITY_PROVENANCE, EMAIL_CLIENT_MATRIX, ESSENTIAL_CONSTRUCTS, checkCompatibility, checkHtmlCompatibility, hasBlockingCompatibility, unknownCoverage };
|