@emailens/engine 0.12.0 → 0.12.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/dist/index.cjs CHANGED
@@ -99,6 +99,7 @@ __export(index_exports, {
99
99
  checkMobileContrast: () => checkMobileContrast,
100
100
  checkOverflow: () => checkOverflow,
101
101
  checkSize: () => checkSize,
102
+ checkStyleSurvival: () => checkStyleSurvival,
102
103
  checkTemplateVariables: () => checkTemplateVariables,
103
104
  checkVisual: () => checkVisual,
104
105
  checkVml: () => checkVml,
@@ -11068,9 +11069,74 @@ var MAIZZLE_SUGGESTION_DATABASE = {
11068
11069
  "opacity::maizzle": "Use solid Tailwind color classes instead of opacity."
11069
11070
  };
11070
11071
 
11072
+ // src/fix-snippets/framework-markup.ts
11073
+ var FRAMEWORK_MARKUP_SUGGESTIONS = {
11074
+ // ── The doctype ───────────────────────────────────────────────────────
11075
+ // Every client that "does not support" it simply rewrites it, and none of
11076
+ // the three frameworks lets you omit it. There is nothing to do.
11077
+ "doctype::mjml": "MJML writes the doctype itself, and the clients that replace it do so without changing how the email renders. Nothing to change in your MJML.",
11078
+ "doctype::maizzle": "Your Maizzle layout writes the doctype, and the clients that replace it do so without changing how the email renders. Nothing to change.",
11079
+ "doctype::jsx": "React Email's <Html> renders the doctype, and the clients that replace it do so without changing how the email renders. Nothing to change.",
11080
+ // ── lang and dir ──────────────────────────────────────────────────────
11081
+ // Dropped, these cost screen-reader language and bidi hints, not layout.
11082
+ "[lang]::mjml": "MJML sets lang on <html> from the lang attribute on <mjml>. Where a client drops it only assistive technology notices, so leave it: removing it helps nobody.",
11083
+ "[lang]::maizzle": "Your Maizzle layout sets lang on <html>. Where a client drops it only assistive technology notices, so leave it.",
11084
+ "[lang]::jsx": "React Email renders this from <Html lang=\u2026>. Where a client drops it only assistive technology notices, so leave it.",
11085
+ "[dir]::mjml": "MJML sets dir from the dir attribute on <mjml>. For a right-to-left email, also set align on mj-text and mj-section, which those clients do honour.",
11086
+ "[dir]::maizzle": "Your Maizzle layout sets dir. For a right-to-left email, also set align on the cells, which these clients do honour.",
11087
+ "[dir]::jsx": "React Email renders this from <Html dir=\u2026>. For a right-to-left email, also set textAlign on the components, which these clients do honour.",
11088
+ // ── role ──────────────────────────────────────────────────────────────
11089
+ // All three add it to their layout tables. Dropping it loses the
11090
+ // screen-reader hint and nothing visual.
11091
+ "[role]::mjml": 'MJML adds role="presentation" to the tables it generates. A client that strips it announces the layout table to screen readers, which is worth knowing but is not something you can change from your MJML.',
11092
+ "[role]::maizzle": "Maizzle's markup transformer adds role to layout tables. A client that strips it announces the table to screen readers; you can turn the transformer off, but the attribute is better present than absent.",
11093
+ "[role]::jsx": "React Email's layout components add role to their tables. A client that strips it announces the table to screen readers, which is not something to fix in your component.",
11094
+ // ── align ─────────────────────────────────────────────────────────────
11095
+ "[align]::mjml": "MJML writes align onto the cells it generates. Set it through the align attribute on mj-section, mj-column, mj-image or mj-text; for the clients that ignore it, add text-align through mj-style and a css-class.",
11096
+ "[align]::maizzle": "Maizzle writes align onto your table cells. For the clients that ignore it, add a text-align utility as well: those survive inlining.",
11097
+ "[align]::jsx": "React Email components render align. For the clients that ignore it, pass textAlign in the style prop too, which is inlined and survives.",
11098
+ // ── width and height ──────────────────────────────────────────────────
11099
+ "[width]::mjml": "MJML writes width from mj-image's or mj-section's width attribute. A client that drops it sizes the element by its content, so also set width through mj-style and a css-class.",
11100
+ "[width]::maizzle": "Maizzle writes width onto the table it generates. A client that drops it sizes by content, so keep a width utility on the element as well: inlined CSS survives where the attribute does not.",
11101
+ "[width]::jsx": "React Email renders width from the component's width prop. A client that drops it sizes by content, so set width in the style prop too.",
11102
+ "[height]::mjml": "MJML writes height from mj-image's height attribute. A client that drops it sizes by content, which for an image means reflow while it loads; set height through mj-style and a css-class as well.",
11103
+ "[height]::maizzle": "Maizzle writes height onto the element. A client that drops it sizes by content, so keep a height utility on it as well.",
11104
+ "[height]::jsx": "React Email renders height from the component's height prop. Set it in the style prop too, so the clients that drop the attribute still reserve the space.",
11105
+ // ── <body> ────────────────────────────────────────────────────────────
11106
+ "<body>::mjml": "MJML styles <body> from mj-body's background-color. Clients that replace <body> with a <div> lose it, so set background-color on mj-section too and the page still fills.",
11107
+ "<body>::maizzle": "Your layout styles <body>. Clients that replace it with a <div> lose those styles, so put the background on a full-width wrapper table as well.",
11108
+ "<body>::jsx": "React Email's <Body> carries your style prop. Clients that replace <body> with a <div> lose it, so put the background on a wrapping <Section> too."
11109
+ };
11110
+ var STYLE_SURVIVAL_NOTES = {
11111
+ "gmail-space-separated-color::mjml": "The block comes from mj-style; write the colour with commas there.",
11112
+ "gmail-space-separated-color::maizzle": "Maizzle rewrites colours it inlines, but a rule left in a <style> block passes through untouched. Fix it in your CSS source.",
11113
+ "gmail-space-separated-color::jsx": "The block comes from a <style> element in your component; write the colour with commas.",
11114
+ "gmail-space-separated-color-inline::mjml": "MJML builds inline styles from component attributes, so the colour came from one of them: write it with commas.",
11115
+ "gmail-space-separated-color-inline::maizzle": "This survived inlining, so it was written inline in your template rather than in a utility class. Write it with commas.",
11116
+ "gmail-space-separated-color-inline::jsx": "The colour is in a style prop object; write it with commas.",
11117
+ "outlook-double-brace::mjml": "The stylesheet is assembled from mj-style. Put a newline before the closing brace of the media query, or stop minifying that block.",
11118
+ "outlook-double-brace::maizzle": "Maizzle's minifier produces this. Leave a space between the braces in the source, or exclude the <style> block from minification.",
11119
+ "outlook-double-brace::jsx": "The stylesheet comes from a <style> element in your component. Put a newline before the media query's closing brace.",
11120
+ "yahoo-attribute-selector-semicolon::mjml": "The selector is in mj-style; split it into [style^=\u2026][style$=\u2026] there.",
11121
+ "yahoo-attribute-selector-semicolon::maizzle": "The selector is in your CSS source; split it into [style^=\u2026][style$=\u2026] there.",
11122
+ "yahoo-attribute-selector-semicolon::jsx": "The selector is in a <style> element in your component; split it into [style^=\u2026][style$=\u2026].",
11123
+ "outlook-web-chained-class::mjml": "css-class takes several names, and MJML passes them through as written. Give the element one class carrying both rules instead.",
11124
+ "outlook-web-chained-class::maizzle": "A compound like .a.b usually comes from @apply or an arbitrary variant. Flatten it into a single class in your component layer.",
11125
+ "outlook-web-chained-class::jsx": "Give the element one class carrying both rules, or move the declarations into the style prop, which is inlined and unaffected.",
11126
+ "outlook-first-class-only::mjml": "The classes come from css-class. Merge the conflicting ones into a single class in mj-style.",
11127
+ "outlook-first-class-only::maizzle": "Inlining sidesteps this entirely, and Maizzle inlines by default. If you turned it off, merge the conflicting utilities into one component class.",
11128
+ "outlook-first-class-only::jsx": "Merge the conflicting classes, or move the declarations into the style prop, which is inlined and unaffected by this.",
11129
+ "outlook-first-class-descendants::mjml": "The rule is in mj-style. Target the child directly with its own css-class rather than through a descendant selector.",
11130
+ "outlook-first-class-descendants::maizzle": "Inlining sidesteps this, and Maizzle inlines by default. Otherwise put the rule on the child element rather than on an ancestor's class.",
11131
+ "outlook-first-class-descendants::jsx": "Put the declarations on the child component, through its own class or its style prop, rather than through a descendant selector."
11132
+ };
11133
+
11071
11134
  // src/fix-snippets/index.ts
11072
11135
  var FIX_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_FIX_DATABASE), JSX_FIX_DATABASE), MJML_FIX_DATABASE), MAIZZLE_FIX_DATABASE);
11073
- var SUGGESTION_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_SUGGESTION_DATABASE), JSX_SUGGESTION_DATABASE), MJML_SUGGESTION_DATABASE), MAIZZLE_SUGGESTION_DATABASE);
11136
+ var SUGGESTION_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_SUGGESTION_DATABASE), JSX_SUGGESTION_DATABASE), MJML_SUGGESTION_DATABASE), MAIZZLE_SUGGESTION_DATABASE), FRAMEWORK_MARKUP_SUGGESTIONS);
11137
+ function getStyleSurvivalNote(rule, framework) {
11138
+ return framework ? STYLE_SURVIVAL_NOTES[`${rule}::${framework}`] : void 0;
11139
+ }
11074
11140
  function getCodeFix(property, clientId, framework) {
11075
11141
  const clientPrefix = getClientPrefix(clientId);
11076
11142
  if (framework && clientPrefix) {
@@ -12171,6 +12237,8 @@ var GENERIC_LINK_TEXT = /* @__PURE__ */ new Set([
12171
12237
  ]);
12172
12238
  var GMAIL_CLIP_THRESHOLD = 102 * 1024;
12173
12239
  var GMAIL_CLIP_WARNING_THRESHOLD = 90 * 1024;
12240
+ var GMAIL_STYLE_LIMIT = 16 * 1024;
12241
+ var GMAIL_STYLE_WARNING_THRESHOLD = 14 * 1024;
12174
12242
  var CLIENT_DISPLAY_LIMITS = [
12175
12243
  { client: "Gmail (Web)", subjectLimit: 70, preheaderLimit: 90 },
12176
12244
  { client: "Gmail (Mobile)", subjectLimit: 40, preheaderLimit: 45 },
@@ -12205,7 +12273,8 @@ var EMPTY_LINKS = {
12205
12273
  var EMPTY_ACCESSIBILITY = { score: 100, issues: [] };
12206
12274
  var EMPTY_IMAGES = { total: 0, totalDataUriBytes: 0, issues: [], images: [] };
12207
12275
  var EMPTY_INBOX_PREVIEW = { subject: null, preheader: null, subjectLength: 0, preheaderLength: 0, truncation: [], issues: [] };
12208
- var EMPTY_SIZE = { htmlBytes: 0, humanSize: "0 B", clipped: false, issues: [] };
12276
+ var EMPTY_SIZE = { htmlBytes: 0, styleBytes: 0, humanSize: "0 B", clipped: false, issues: [] };
12277
+ var EMPTY_STYLE_SURVIVAL = { issues: [] };
12209
12278
  var EMPTY_TEMPLATE = { unresolvedCount: 0, issues: [] };
12210
12279
  var EMPTY_OVERFLOW = { hasOverflow: false, issues: [] };
12211
12280
  var EMPTY_VML = { hasVml: false, issues: [] };
@@ -14744,6 +14813,272 @@ function extractCode(response) {
14744
14813
  return response.trim();
14745
14814
  }
14746
14815
 
14816
+ // src/style-survival.ts
14817
+ var csstree6 = __toESM(require("css-tree"), 1);
14818
+ var WORD_ENGINE = ["outlook-windows-legacy"];
14819
+ var OUTLOOK_WEB = ["outlook-web", "outlook-windows"];
14820
+ var OUTLOOK_WEB_AND_MOBILE = [
14821
+ "outlook-web",
14822
+ "outlook-windows",
14823
+ "outlook-ios",
14824
+ "outlook-android"
14825
+ ];
14826
+ var GMAIL = ["gmail-web", "gmail-android", "gmail-ios"];
14827
+ var YAHOO_AOL = [
14828
+ "yahoo-mail",
14829
+ "yahoo-mail-android",
14830
+ "yahoo-mail-ios",
14831
+ "aol"
14832
+ ];
14833
+ var MAX_LOCS = 20;
14834
+ function hasSpaceSeparatedColor(css) {
14835
+ const fn = /\b(?:rgba?|hsla?)\(/gi;
14836
+ let m;
14837
+ while (m = fn.exec(css)) {
14838
+ const start = m.index + m[0].length;
14839
+ let depth = 1;
14840
+ let comma = false;
14841
+ let i = start;
14842
+ for (; i < css.length && depth > 0; i++) {
14843
+ const c = css[i];
14844
+ if (c === "(") depth++;
14845
+ else if (c === ")") depth--;
14846
+ else if (c === "," && depth === 1) comma = true;
14847
+ }
14848
+ if (depth > 0) continue;
14849
+ const args = css.slice(start, i - 1);
14850
+ if (!comma && /\S\s+\S/.test(args)) return true;
14851
+ }
14852
+ return false;
14853
+ }
14854
+ var ATTR_SELECTOR_SEMICOLON = /\[[^\]]*;[^\]]*\]/;
14855
+ var DOUBLE_BRACE = /\}\}/;
14856
+ function readSheet(ast) {
14857
+ const propsByClass = /* @__PURE__ */ new Map();
14858
+ const classesWithDescendants = /* @__PURE__ */ new Set();
14859
+ const chainedClassSelectors = [];
14860
+ csstree6.walk(ast, {
14861
+ visit: "Rule",
14862
+ enter(rule) {
14863
+ var _a;
14864
+ if (rule.type !== "Rule" || rule.prelude.type !== "SelectorList") return;
14865
+ const props = /* @__PURE__ */ new Set();
14866
+ csstree6.walk(rule.block, {
14867
+ visit: "Declaration",
14868
+ enter(d) {
14869
+ if (d.type === "Declaration") props.add(d.property.toLowerCase());
14870
+ }
14871
+ });
14872
+ for (const selector of rule.prelude.children) {
14873
+ if (selector.type !== "Selector") continue;
14874
+ const parts = selector.children.toArray();
14875
+ const classes = parts.filter((p) => p.type === "ClassSelector");
14876
+ if (!classes.length) continue;
14877
+ let run = 0;
14878
+ for (const part of parts) {
14879
+ if (part.type === "ClassSelector" || part.type === "IdSelector") {
14880
+ run++;
14881
+ if (run === 2) {
14882
+ chainedClassSelectors.push(csstree6.generate(selector));
14883
+ break;
14884
+ }
14885
+ } else if (part.type !== "PseudoClassSelector" && part.type !== "PseudoElementSelector") {
14886
+ run = 0;
14887
+ }
14888
+ }
14889
+ const hasCombinator = parts.some(
14890
+ (p) => p.type === "Combinator" || p.type === "WhiteSpace"
14891
+ );
14892
+ if (hasCombinator) {
14893
+ const head = parts[0];
14894
+ if ((head == null ? void 0 : head.type) === "ClassSelector") classesWithDescendants.add(head.name);
14895
+ continue;
14896
+ }
14897
+ if (parts.length === classes.length && classes.length === 1) {
14898
+ const name = classes[0].name;
14899
+ const seen = (_a = propsByClass.get(name)) != null ? _a : /* @__PURE__ */ new Set();
14900
+ for (const p of props) seen.add(p);
14901
+ propsByClass.set(name, seen);
14902
+ }
14903
+ }
14904
+ }
14905
+ });
14906
+ return { propsByClass, classesWithDescendants, chainedClassSelectors };
14907
+ }
14908
+ function checkStyleSurvivalFromDom($, source, framework) {
14909
+ const issues = [];
14910
+ const add2 = (rule, severity, clients, message, locs, detail) => {
14911
+ const frameworkNote = getStyleSurvivalNote(rule, framework);
14912
+ issues.push(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
14913
+ rule,
14914
+ severity,
14915
+ clients: [...clients],
14916
+ message
14917
+ }, frameworkNote ? { frameworkNote } : {}), detail ? { detail } : {}), locs.length ? { loc: locs[0], locs: locs.slice(0, MAX_LOCS) } : {}), locs.length > MAX_LOCS ? { locsTruncated: true } : {}));
14918
+ };
14919
+ const sheets = [];
14920
+ const hits = { spaceColor: 0, doubleBrace: 0, attrSemicolon: 0, chained: 0 };
14921
+ const spaceColorLocs = [];
14922
+ const doubleBraceLocs = [];
14923
+ const attrSemicolonLocs = [];
14924
+ const chainedLocs = [];
14925
+ let chainedExample = "";
14926
+ $("style").each((_, el) => {
14927
+ const cssText = $(el).text();
14928
+ if (!cssText.trim()) return;
14929
+ const anchor = cssBlockAnchor(el, cssText, source);
14930
+ const at = (index) => {
14931
+ const before = cssText.slice(0, index);
14932
+ const line = before.split("\n").length;
14933
+ const column = index - before.lastIndexOf("\n");
14934
+ return locInCssBlock(anchor, {
14935
+ start: { line, column, offset: index },
14936
+ end: { line, column: column + 1, offset: index + 1 }
14937
+ });
14938
+ };
14939
+ const push = (into, index) => {
14940
+ var _a;
14941
+ const loc = (_a = at(index)) != null ? _a : locOfElement(el);
14942
+ if (loc) into.push(loc);
14943
+ };
14944
+ if (hasSpaceSeparatedColor(cssText)) {
14945
+ hits.spaceColor++;
14946
+ push(spaceColorLocs, cssText.search(/\b(?:rgba?|hsla?)\(/i));
14947
+ }
14948
+ const brace = cssText.search(DOUBLE_BRACE);
14949
+ if (brace >= 0) {
14950
+ hits.doubleBrace++;
14951
+ push(doubleBraceLocs, brace);
14952
+ }
14953
+ const attr2 = cssText.search(ATTR_SELECTOR_SEMICOLON);
14954
+ if (attr2 >= 0) {
14955
+ hits.attrSemicolon++;
14956
+ push(attrSemicolonLocs, attr2);
14957
+ }
14958
+ try {
14959
+ const sheet = readSheet(csstree6.parse(cssText, { positions: true }));
14960
+ sheets.push(sheet);
14961
+ if (sheet.chainedClassSelectors.length) {
14962
+ hits.chained++;
14963
+ chainedExample || (chainedExample = sheet.chainedClassSelectors[0]);
14964
+ push(chainedLocs, 0);
14965
+ }
14966
+ } catch (e) {
14967
+ }
14968
+ });
14969
+ const inlineColorEls = $("[style]").toArray().filter((el) => {
14970
+ var _a;
14971
+ return hasSpaceSeparatedColor((_a = $(el).attr("style")) != null ? _a : "");
14972
+ });
14973
+ if (hits.spaceColor) {
14974
+ add2(
14975
+ "gmail-space-separated-color",
14976
+ "error",
14977
+ GMAIL,
14978
+ "Gmail removes an entire <style> block containing a space-separated colour like `rgb(0 0 0)`. Write it with commas, `rgb(0, 0, 0)`, and the block survives.",
14979
+ spaceColorLocs
14980
+ );
14981
+ }
14982
+ if (inlineColorEls.length) {
14983
+ add2(
14984
+ "gmail-space-separated-color-inline",
14985
+ "error",
14986
+ GMAIL,
14987
+ `Gmail drops every declaration in a style attribute that uses a space-separated colour like \`rgb(0 0 0)\`, not only the colour. ${inlineColorEls.length} element${inlineColorEls.length > 1 ? "s are" : " is"} affected; write the colour with commas.`,
14988
+ inlineColorEls.map((el) => locOfElement(el)).filter((l) => !!l)
14989
+ );
14990
+ }
14991
+ if (hits.doubleBrace) {
14992
+ add2(
14993
+ "outlook-double-brace",
14994
+ "error",
14995
+ OUTLOOK_WEB_AND_MOBILE,
14996
+ "Outlook.com and Outlook on iOS/Android discard every style rule after `}}`. Minified CSS closing a media query produces it. Put a space or newline between the two braces and the rest of the sheet survives.",
14997
+ doubleBraceLocs
14998
+ );
14999
+ }
15000
+ if (hits.attrSemicolon) {
15001
+ add2(
15002
+ "yahoo-attribute-selector-semicolon",
15003
+ "error",
15004
+ YAHOO_AOL,
15005
+ 'Yahoo and AOL discard every style rule after an attribute selector whose value contains a semicolon, such as `div[style="margin: 16px;"]`. Split it into `[style^=\u2026][style$=\u2026]` and the rest of the sheet survives.',
15006
+ attrSemicolonLocs
15007
+ );
15008
+ }
15009
+ if (hits.chained) {
15010
+ add2(
15011
+ "outlook-web-chained-class",
15012
+ "warning",
15013
+ OUTLOOK_WEB,
15014
+ `Outlook.com rewrites class names to namespace them and only rewrites the first in a compound selector, so \`${chainedExample}\` stops matching. Give the element one class that carries both rules.`,
15015
+ chainedLocs
15016
+ );
15017
+ }
15018
+ const conflicting = [];
15019
+ const shadowed = [];
15020
+ let conflictCount = 0;
15021
+ let shadowCount = 0;
15022
+ let conflictExample = "";
15023
+ $("[class]").each((_, el) => {
15024
+ var _a, _b;
15025
+ const names = ((_a = $(el).attr("class")) != null ? _a : "").split(/\s+/).filter(Boolean);
15026
+ if (names.length < 2) return;
15027
+ const loc = locOfElement(el);
15028
+ const seen = /* @__PURE__ */ new Map();
15029
+ for (const sheet of sheets) {
15030
+ for (const name of names) {
15031
+ for (const prop of (_b = sheet.propsByClass.get(name)) != null ? _b : []) {
15032
+ const first = seen.get(prop);
15033
+ if (first && first !== name) {
15034
+ conflictExample || (conflictExample = `.${first} and .${name} both set ${prop}`);
15035
+ conflictCount++;
15036
+ if (loc) conflicting.push(loc);
15037
+ return;
15038
+ }
15039
+ if (!first) seen.set(prop, name);
15040
+ }
15041
+ }
15042
+ if (names.some((n) => sheet.classesWithDescendants.has(n))) {
15043
+ shadowCount++;
15044
+ if (loc) shadowed.push(loc);
15045
+ return;
15046
+ }
15047
+ }
15048
+ });
15049
+ if (conflictCount) {
15050
+ add2(
15051
+ "outlook-first-class-only",
15052
+ "warning",
15053
+ WORD_ENGINE,
15054
+ `Outlook on Windows applies only the first class on an element, so a second class setting the same property never takes effect (${conflictExample}). Merge them into one class.`,
15055
+ conflicting
15056
+ );
15057
+ }
15058
+ if (shadowCount) {
15059
+ add2(
15060
+ "outlook-first-class-descendants",
15061
+ "warning",
15062
+ WORD_ENGINE,
15063
+ "Outlook on Windows ignores a descendant rule like `.text td` once the element carries a second class. Move the rule onto the child, or give the element a single class.",
15064
+ shadowed
15065
+ );
15066
+ }
15067
+ return { issues };
15068
+ }
15069
+ function checkStyleSurvival(html, options) {
15070
+ return fromHtml(
15071
+ html,
15072
+ EMPTY_STYLE_SURVIVAL,
15073
+ ($) => checkStyleSurvivalFromDom(
15074
+ $,
15075
+ (options == null ? void 0 : options.positions) ? html : void 0,
15076
+ options == null ? void 0 : options.framework
15077
+ ),
15078
+ options
15079
+ );
15080
+ }
15081
+
14747
15082
  // src/rules/feature-urls.ts
14748
15083
  var FEATURE_URLS = {
14749
15084
  "!important": "https://www.caniemail.com/features/css-important/",
@@ -15693,7 +16028,7 @@ function validateLinks(html, options) {
15693
16028
 
15694
16029
  // src/accessibility-checker.ts
15695
16030
  var cheerio5 = __toESM(require("cheerio"), 1);
15696
- var csstree6 = __toESM(require("css-tree"), 1);
16031
+ var csstree7 = __toESM(require("css-tree"), 1);
15697
16032
  var RULE_PENALTY_CAPS = {
15698
16033
  "img-missing-alt": 3,
15699
16034
  "link-generic-text": 3,
@@ -15937,7 +16272,7 @@ function specificityFromTokens(selector) {
15937
16272
  }
15938
16273
  function specificityOf(selector) {
15939
16274
  try {
15940
- const ast = csstree6.parse(selector, { context: "selector" });
16275
+ const ast = csstree7.parse(selector, { context: "selector" });
15941
16276
  return specificityOfSelector(ast);
15942
16277
  } catch (e) {
15943
16278
  return specificityFromTokens(selector);
@@ -15982,14 +16317,14 @@ function computeCascade($, ctx) {
15982
16317
  });
15983
16318
  });
15984
16319
  const handleRule = (node) => {
15985
- const selectorList = csstree6.generate(node.prelude).trim();
16320
+ const selectorList = csstree7.generate(node.prelude).trim();
15986
16321
  if (!selectorList) return;
15987
16322
  const decls = [];
15988
16323
  node.block.children.forEach((child) => {
15989
16324
  if (child.type !== "Declaration") return;
15990
16325
  const prop = child.property.toLowerCase();
15991
16326
  if (!CASCADE_PROPS.has(prop)) return;
15992
- decls.push({ prop, value: csstree6.generate(child.value), important: !!child.important });
16327
+ decls.push({ prop, value: csstree7.generate(child.value), important: !!child.important });
15993
16328
  });
15994
16329
  if (!decls.length) return;
15995
16330
  for (const selector of splitTopLevel(selectorList).map((x) => x.trim()).filter(Boolean)) {
@@ -16019,7 +16354,7 @@ function computeCascade($, ctx) {
16019
16354
  return;
16020
16355
  }
16021
16356
  if (node.type !== "Atrule" || node.name.toLowerCase() !== "media" || !node.block) return;
16022
- const prelude = node.prelude ? csstree6.generate(node.prelude) : "";
16357
+ const prelude = node.prelude ? csstree7.generate(node.prelude) : "";
16023
16358
  if (!mediaApplies(prelude, ctx)) return;
16024
16359
  visitBlock(node.block.children);
16025
16360
  });
@@ -16027,7 +16362,7 @@ function computeCascade($, ctx) {
16027
16362
  $("style").each((_, styleEl) => {
16028
16363
  let ast;
16029
16364
  try {
16030
- ast = csstree6.parse($(styleEl).text());
16365
+ ast = csstree7.parse($(styleEl).text());
16031
16366
  } catch (e) {
16032
16367
  return;
16033
16368
  }
@@ -16808,8 +17143,9 @@ function humanizeBytes(bytes) {
16808
17143
  const mb = kb / 1024;
16809
17144
  return `${mb.toFixed(2)} MB`;
16810
17145
  }
16811
- function checkSizeFromDom(_$, html) {
17146
+ function checkSizeFromDom($, html) {
16812
17147
  const htmlBytes = new TextEncoder().encode(html).length;
17148
+ const styleBytes = $("style").toArray().reduce((n, el) => n + new TextEncoder().encode($(el).text()).length, 0);
16813
17149
  const humanSize = humanizeBytes(htmlBytes);
16814
17150
  const issues = [];
16815
17151
  let clipped = false;
@@ -16829,7 +17165,22 @@ function checkSizeFromDom(_$, html) {
16829
17165
  detail: `${htmlBytes} bytes is within ${GMAIL_CLIP_THRESHOLD - htmlBytes} bytes of the clip threshold.`
16830
17166
  });
16831
17167
  }
16832
- return { htmlBytes, humanSize, clipped, issues };
17168
+ if (styleBytes > GMAIL_STYLE_LIMIT) {
17169
+ issues.push({
17170
+ rule: "gmail-style-truncated",
17171
+ severity: "error",
17172
+ message: `${humanizeBytes(styleBytes)} of CSS is past Gmail's 16 KB ceiling for <style>. Gmail keeps the rules before the limit and drops the rest, so the email renders with part of its CSS and no error anywhere.`,
17173
+ detail: `${styleBytes} bytes of CSS across all <style> elements exceeds the ${GMAIL_STYLE_LIMIT} byte limit.`
17174
+ });
17175
+ } else if (styleBytes > GMAIL_STYLE_WARNING_THRESHOLD) {
17176
+ issues.push({
17177
+ rule: "gmail-style-warning",
17178
+ severity: "warning",
17179
+ message: `${humanizeBytes(styleBytes)} of CSS, approaching Gmail's 16 KB <style> ceiling. Past it, later rules are dropped silently.`,
17180
+ detail: `${styleBytes} bytes is within ${GMAIL_STYLE_LIMIT - styleBytes} bytes of the limit.`
17181
+ });
17182
+ }
17183
+ return { htmlBytes, styleBytes, humanSize, clipped, issues };
16833
17184
  }
16834
17185
  function checkSize(html) {
16835
17186
  return fromHtml(html, EMPTY_SIZE, checkSizeFromDom);
@@ -16943,7 +17294,7 @@ function checkTemplateVariables(html, options) {
16943
17294
  }
16944
17295
 
16945
17296
  // src/overflow-checker.ts
16946
- var csstree7 = __toESM(require("css-tree"), 1);
17297
+ var csstree8 = __toESM(require("css-tree"), 1);
16947
17298
  var RESPONSIVE_MIN_WIDTH = 320;
16948
17299
  function fixedPxWidth($el) {
16949
17300
  const style = $el.attr("style") || "";
@@ -17020,11 +17371,11 @@ function checkOverflowFromDom($, source) {
17020
17371
  const anchor = cssBlockAnchor(el, cssText, source);
17021
17372
  let ast;
17022
17373
  try {
17023
- ast = csstree7.parse(cssText, { positions: true });
17374
+ ast = csstree8.parse(cssText, { positions: true });
17024
17375
  } catch (e) {
17025
17376
  return;
17026
17377
  }
17027
- csstree7.walk(ast, {
17378
+ csstree8.walk(ast, {
17028
17379
  visit: "Rule",
17029
17380
  enter(node) {
17030
17381
  if (node.type !== "Rule") return;
@@ -17034,7 +17385,7 @@ function checkOverflowFromDom($, source) {
17034
17385
  node.block.children.forEach((child) => {
17035
17386
  if (child.type !== "Declaration") return;
17036
17387
  const prop = child.property.toLowerCase();
17037
- const val = csstree7.generate(child.value);
17388
+ const val = csstree8.generate(child.value);
17038
17389
  if (prop === "width") {
17039
17390
  const m = val.match(/^(\d+)px$/);
17040
17391
  if (m) {
@@ -17047,7 +17398,7 @@ function checkOverflowFromDom($, source) {
17047
17398
  }
17048
17399
  });
17049
17400
  if (widthPx !== null && widthPx > EMAIL_MAX_WIDTH && !fluid) {
17050
- const selector = csstree7.generate(node.prelude).trim().slice(0, 40);
17401
+ const selector = csstree8.generate(node.prelude).trim().slice(0, 40);
17051
17402
  addWidthIssue(widthPx, selector || "rule", issues, seen, widthLoc);
17052
17403
  }
17053
17404
  }
@@ -17372,7 +17723,7 @@ function checkVml(html, options) {
17372
17723
  }
17373
17724
 
17374
17725
  // src/visual-checker.ts
17375
- var csstree8 = __toESM(require("css-tree"), 1);
17726
+ var csstree9 = __toESM(require("css-tree"), 1);
17376
17727
  var CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
17377
17728
  var GRADIENT_RE = /(?:linear|radial|conic)-gradient\(/i;
17378
17729
  function isSolidColor(value) {
@@ -17478,7 +17829,7 @@ function ruleToMap(node) {
17478
17829
  const map = /* @__PURE__ */ new Map();
17479
17830
  node.block.children.forEach((child) => {
17480
17831
  if (child.type === "Declaration") {
17481
- map.set(child.property.toLowerCase(), csstree8.generate(child.value));
17832
+ map.set(child.property.toLowerCase(), csstree9.generate(child.value));
17482
17833
  }
17483
17834
  });
17484
17835
  return map;
@@ -17497,11 +17848,11 @@ function checkVisualFromDom($, source) {
17497
17848
  const anchor = cssBlockAnchor(el, cssText, source);
17498
17849
  let ast;
17499
17850
  try {
17500
- ast = csstree8.parse(cssText, { positions: true });
17851
+ ast = csstree9.parse(cssText, { positions: true });
17501
17852
  } catch (e) {
17502
17853
  return;
17503
17854
  }
17504
- csstree8.walk(ast, {
17855
+ csstree9.walk(ast, {
17505
17856
  visit: "Rule",
17506
17857
  enter(node) {
17507
17858
  if (node.type !== "Rule") return;
@@ -17527,7 +17878,7 @@ function checkVisual(html, options) {
17527
17878
  }
17528
17879
 
17529
17880
  // src/design-consistency.ts
17530
- var csstree9 = __toESM(require("css-tree"), 1);
17881
+ var csstree10 = __toESM(require("css-tree"), 1);
17531
17882
  var SAME_COLOUR_DISTANCE = 0.02;
17532
17883
  var LIMITS = {
17533
17884
  fontSize: 8,
@@ -17581,15 +17932,15 @@ function collect($) {
17581
17932
  $("style").each((_, el) => {
17582
17933
  let ast;
17583
17934
  try {
17584
- ast = csstree9.parse($(el).text());
17935
+ ast = csstree10.parse($(el).text());
17585
17936
  } catch (e) {
17586
17937
  return;
17587
17938
  }
17588
- csstree9.walk(ast, {
17939
+ csstree10.walk(ast, {
17589
17940
  visit: "Declaration",
17590
17941
  enter(node) {
17591
17942
  if (node.type !== "Declaration") return;
17592
- record(node.property, csstree9.generate(node.value));
17943
+ record(node.property, csstree10.generate(node.value));
17593
17944
  }
17594
17945
  });
17595
17946
  });
@@ -17698,6 +18049,7 @@ var EMPTY_AUDIT = {
17698
18049
  images: EMPTY_IMAGES,
17699
18050
  inboxPreview: EMPTY_INBOX_PREVIEW,
17700
18051
  size: EMPTY_SIZE,
18052
+ styleSurvival: EMPTY_STYLE_SURVIVAL,
17701
18053
  templateVariables: EMPTY_TEMPLATE,
17702
18054
  overflow: EMPTY_OVERFLOW,
17703
18055
  visual: EMPTY_VISUAL,
@@ -17726,6 +18078,7 @@ function runAudit($, html, framework, options) {
17726
18078
  const images = skip.has("images") ? EMPTY_IMAGES : analyzeImagesFromDom($);
17727
18079
  const inboxPreview = skip.has("inboxPreview") ? EMPTY_INBOX_PREVIEW : extractInboxPreviewFromDom($);
17728
18080
  const size = skip.has("size") ? EMPTY_SIZE : checkSizeFromDom($, html);
18081
+ const styleSurvival = skip.has("styleSurvival") ? EMPTY_STYLE_SURVIVAL : checkStyleSurvivalFromDom($, source, framework);
17729
18082
  const templateVariables = skip.has("templateVariables") ? EMPTY_TEMPLATE : checkTemplateVariablesFromDom($, source);
17730
18083
  const overflow = skip.has("overflow") ? EMPTY_OVERFLOW : checkOverflowFromDom($, source);
17731
18084
  const visual = skip.has("visual") ? EMPTY_VISUAL : checkVisualFromDom($, source);
@@ -17736,7 +18089,7 @@ function runAudit($, html, framework, options) {
17736
18089
  ]);
17737
18090
  const design = skip.has("design") ? EMPTY_DESIGN : checkDesignConsistencyFromDom($);
17738
18091
  const mobileContrast = skip.has("mobileContrast") || skip.has("accessibility") ? [] : checkMobileContrastFromDom($, accessibility.issues);
17739
- return { compatibility: { warnings, scores }, spam, links, accessibility, images, inboxPreview, size, templateVariables, overflow, visual, vml, darkContrast, mobileContrast, design };
18092
+ return { compatibility: { warnings, scores }, spam, links, accessibility, images, inboxPreview, size, styleSurvival, templateVariables, overflow, visual, vml, darkContrast, mobileContrast, design };
17740
18093
  }
17741
18094
  function auditEmail(html, options) {
17742
18095
  return fromHtml(html, EMPTY_AUDIT, ($, h) => runAudit($, h, options == null ? void 0 : options.framework, options), options);
@@ -17780,7 +18133,7 @@ function toPlainText(html) {
17780
18133
  if (trimmed) lines.push(trimmed);
17781
18134
  currentLine = "";
17782
18135
  }
17783
- function walk9(node) {
18136
+ function walk10(node) {
17784
18137
  var _a;
17785
18138
  if (node.type === "text") {
17786
18139
  const text = node.data.replace(/\s+/g, " ");
@@ -17829,7 +18182,7 @@ function toPlainText(html) {
17829
18182
  currentLine = "- ";
17830
18183
  }
17831
18184
  for (const child of el.children) {
17832
- walk9(child);
18185
+ walk10(child);
17833
18186
  }
17834
18187
  if (isBlock) flushLine();
17835
18188
  }
@@ -17837,7 +18190,7 @@ function toPlainText(html) {
17837
18190
  const root = body.length ? body[0] : $.root()[0];
17838
18191
  if (root && "children" in root) {
17839
18192
  for (const child of root.children) {
17840
- walk9(child);
18193
+ walk10(child);
17841
18194
  }
17842
18195
  }
17843
18196
  flushLine();
@@ -17979,6 +18332,7 @@ var CompileError = class extends Error {
17979
18332
  checkMobileContrast,
17980
18333
  checkOverflow,
17981
18334
  checkSize,
18335
+ checkStyleSurvival,
17982
18336
  checkTemplateVariables,
17983
18337
  checkVisual,
17984
18338
  checkVml,