@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.js CHANGED
@@ -10939,9 +10939,74 @@ var MAIZZLE_SUGGESTION_DATABASE = {
10939
10939
  "opacity::maizzle": "Use solid Tailwind color classes instead of opacity."
10940
10940
  };
10941
10941
 
10942
+ // src/fix-snippets/framework-markup.ts
10943
+ var FRAMEWORK_MARKUP_SUGGESTIONS = {
10944
+ // ── The doctype ───────────────────────────────────────────────────────
10945
+ // Every client that "does not support" it simply rewrites it, and none of
10946
+ // the three frameworks lets you omit it. There is nothing to do.
10947
+ "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.",
10948
+ "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.",
10949
+ "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.",
10950
+ // ── lang and dir ──────────────────────────────────────────────────────
10951
+ // Dropped, these cost screen-reader language and bidi hints, not layout.
10952
+ "[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.",
10953
+ "[lang]::maizzle": "Your Maizzle layout sets lang on <html>. Where a client drops it only assistive technology notices, so leave it.",
10954
+ "[lang]::jsx": "React Email renders this from <Html lang=\u2026>. Where a client drops it only assistive technology notices, so leave it.",
10955
+ "[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.",
10956
+ "[dir]::maizzle": "Your Maizzle layout sets dir. For a right-to-left email, also set align on the cells, which these clients do honour.",
10957
+ "[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.",
10958
+ // ── role ──────────────────────────────────────────────────────────────
10959
+ // All three add it to their layout tables. Dropping it loses the
10960
+ // screen-reader hint and nothing visual.
10961
+ "[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.',
10962
+ "[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.",
10963
+ "[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.",
10964
+ // ── align ─────────────────────────────────────────────────────────────
10965
+ "[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.",
10966
+ "[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.",
10967
+ "[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.",
10968
+ // ── width and height ──────────────────────────────────────────────────
10969
+ "[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.",
10970
+ "[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.",
10971
+ "[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.",
10972
+ "[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.",
10973
+ "[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.",
10974
+ "[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.",
10975
+ // ── <body> ────────────────────────────────────────────────────────────
10976
+ "<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.",
10977
+ "<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.",
10978
+ "<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."
10979
+ };
10980
+ var STYLE_SURVIVAL_NOTES = {
10981
+ "gmail-space-separated-color::mjml": "The block comes from mj-style; write the colour with commas there.",
10982
+ "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.",
10983
+ "gmail-space-separated-color::jsx": "The block comes from a <style> element in your component; write the colour with commas.",
10984
+ "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.",
10985
+ "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.",
10986
+ "gmail-space-separated-color-inline::jsx": "The colour is in a style prop object; write it with commas.",
10987
+ "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.",
10988
+ "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.",
10989
+ "outlook-double-brace::jsx": "The stylesheet comes from a <style> element in your component. Put a newline before the media query's closing brace.",
10990
+ "yahoo-attribute-selector-semicolon::mjml": "The selector is in mj-style; split it into [style^=\u2026][style$=\u2026] there.",
10991
+ "yahoo-attribute-selector-semicolon::maizzle": "The selector is in your CSS source; split it into [style^=\u2026][style$=\u2026] there.",
10992
+ "yahoo-attribute-selector-semicolon::jsx": "The selector is in a <style> element in your component; split it into [style^=\u2026][style$=\u2026].",
10993
+ "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.",
10994
+ "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.",
10995
+ "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.",
10996
+ "outlook-first-class-only::mjml": "The classes come from css-class. Merge the conflicting ones into a single class in mj-style.",
10997
+ "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.",
10998
+ "outlook-first-class-only::jsx": "Merge the conflicting classes, or move the declarations into the style prop, which is inlined and unaffected by this.",
10999
+ "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.",
11000
+ "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.",
11001
+ "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."
11002
+ };
11003
+
10942
11004
  // src/fix-snippets/index.ts
10943
11005
  var FIX_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_FIX_DATABASE), JSX_FIX_DATABASE), MJML_FIX_DATABASE), MAIZZLE_FIX_DATABASE);
10944
- var SUGGESTION_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_SUGGESTION_DATABASE), JSX_SUGGESTION_DATABASE), MJML_SUGGESTION_DATABASE), MAIZZLE_SUGGESTION_DATABASE);
11006
+ var SUGGESTION_DATABASE = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, HTML_SUGGESTION_DATABASE), JSX_SUGGESTION_DATABASE), MJML_SUGGESTION_DATABASE), MAIZZLE_SUGGESTION_DATABASE), FRAMEWORK_MARKUP_SUGGESTIONS);
11007
+ function getStyleSurvivalNote(rule, framework) {
11008
+ return framework ? STYLE_SURVIVAL_NOTES[`${rule}::${framework}`] : void 0;
11009
+ }
10945
11010
  function getCodeFix(property, clientId, framework) {
10946
11011
  const clientPrefix = getClientPrefix(clientId);
10947
11012
  if (framework && clientPrefix) {
@@ -12042,6 +12107,8 @@ var GENERIC_LINK_TEXT = /* @__PURE__ */ new Set([
12042
12107
  ]);
12043
12108
  var GMAIL_CLIP_THRESHOLD = 102 * 1024;
12044
12109
  var GMAIL_CLIP_WARNING_THRESHOLD = 90 * 1024;
12110
+ var GMAIL_STYLE_LIMIT = 16 * 1024;
12111
+ var GMAIL_STYLE_WARNING_THRESHOLD = 14 * 1024;
12045
12112
  var CLIENT_DISPLAY_LIMITS = [
12046
12113
  { client: "Gmail (Web)", subjectLimit: 70, preheaderLimit: 90 },
12047
12114
  { client: "Gmail (Mobile)", subjectLimit: 40, preheaderLimit: 45 },
@@ -12076,7 +12143,8 @@ var EMPTY_LINKS = {
12076
12143
  var EMPTY_ACCESSIBILITY = { score: 100, issues: [] };
12077
12144
  var EMPTY_IMAGES = { total: 0, totalDataUriBytes: 0, issues: [], images: [] };
12078
12145
  var EMPTY_INBOX_PREVIEW = { subject: null, preheader: null, subjectLength: 0, preheaderLength: 0, truncation: [], issues: [] };
12079
- var EMPTY_SIZE = { htmlBytes: 0, humanSize: "0 B", clipped: false, issues: [] };
12146
+ var EMPTY_SIZE = { htmlBytes: 0, styleBytes: 0, humanSize: "0 B", clipped: false, issues: [] };
12147
+ var EMPTY_STYLE_SURVIVAL = { issues: [] };
12080
12148
  var EMPTY_TEMPLATE = { unresolvedCount: 0, issues: [] };
12081
12149
  var EMPTY_OVERFLOW = { hasOverflow: false, issues: [] };
12082
12150
  var EMPTY_VML = { hasVml: false, issues: [] };
@@ -14615,6 +14683,272 @@ function extractCode(response) {
14615
14683
  return response.trim();
14616
14684
  }
14617
14685
 
14686
+ // src/style-survival.ts
14687
+ import * as csstree6 from "css-tree";
14688
+ var WORD_ENGINE = ["outlook-windows-legacy"];
14689
+ var OUTLOOK_WEB = ["outlook-web", "outlook-windows"];
14690
+ var OUTLOOK_WEB_AND_MOBILE = [
14691
+ "outlook-web",
14692
+ "outlook-windows",
14693
+ "outlook-ios",
14694
+ "outlook-android"
14695
+ ];
14696
+ var GMAIL = ["gmail-web", "gmail-android", "gmail-ios"];
14697
+ var YAHOO_AOL = [
14698
+ "yahoo-mail",
14699
+ "yahoo-mail-android",
14700
+ "yahoo-mail-ios",
14701
+ "aol"
14702
+ ];
14703
+ var MAX_LOCS = 20;
14704
+ function hasSpaceSeparatedColor(css) {
14705
+ const fn = /\b(?:rgba?|hsla?)\(/gi;
14706
+ let m;
14707
+ while (m = fn.exec(css)) {
14708
+ const start = m.index + m[0].length;
14709
+ let depth = 1;
14710
+ let comma = false;
14711
+ let i = start;
14712
+ for (; i < css.length && depth > 0; i++) {
14713
+ const c = css[i];
14714
+ if (c === "(") depth++;
14715
+ else if (c === ")") depth--;
14716
+ else if (c === "," && depth === 1) comma = true;
14717
+ }
14718
+ if (depth > 0) continue;
14719
+ const args = css.slice(start, i - 1);
14720
+ if (!comma && /\S\s+\S/.test(args)) return true;
14721
+ }
14722
+ return false;
14723
+ }
14724
+ var ATTR_SELECTOR_SEMICOLON = /\[[^\]]*;[^\]]*\]/;
14725
+ var DOUBLE_BRACE = /\}\}/;
14726
+ function readSheet(ast) {
14727
+ const propsByClass = /* @__PURE__ */ new Map();
14728
+ const classesWithDescendants = /* @__PURE__ */ new Set();
14729
+ const chainedClassSelectors = [];
14730
+ csstree6.walk(ast, {
14731
+ visit: "Rule",
14732
+ enter(rule) {
14733
+ var _a;
14734
+ if (rule.type !== "Rule" || rule.prelude.type !== "SelectorList") return;
14735
+ const props = /* @__PURE__ */ new Set();
14736
+ csstree6.walk(rule.block, {
14737
+ visit: "Declaration",
14738
+ enter(d) {
14739
+ if (d.type === "Declaration") props.add(d.property.toLowerCase());
14740
+ }
14741
+ });
14742
+ for (const selector of rule.prelude.children) {
14743
+ if (selector.type !== "Selector") continue;
14744
+ const parts = selector.children.toArray();
14745
+ const classes = parts.filter((p) => p.type === "ClassSelector");
14746
+ if (!classes.length) continue;
14747
+ let run = 0;
14748
+ for (const part of parts) {
14749
+ if (part.type === "ClassSelector" || part.type === "IdSelector") {
14750
+ run++;
14751
+ if (run === 2) {
14752
+ chainedClassSelectors.push(csstree6.generate(selector));
14753
+ break;
14754
+ }
14755
+ } else if (part.type !== "PseudoClassSelector" && part.type !== "PseudoElementSelector") {
14756
+ run = 0;
14757
+ }
14758
+ }
14759
+ const hasCombinator = parts.some(
14760
+ (p) => p.type === "Combinator" || p.type === "WhiteSpace"
14761
+ );
14762
+ if (hasCombinator) {
14763
+ const head = parts[0];
14764
+ if ((head == null ? void 0 : head.type) === "ClassSelector") classesWithDescendants.add(head.name);
14765
+ continue;
14766
+ }
14767
+ if (parts.length === classes.length && classes.length === 1) {
14768
+ const name = classes[0].name;
14769
+ const seen = (_a = propsByClass.get(name)) != null ? _a : /* @__PURE__ */ new Set();
14770
+ for (const p of props) seen.add(p);
14771
+ propsByClass.set(name, seen);
14772
+ }
14773
+ }
14774
+ }
14775
+ });
14776
+ return { propsByClass, classesWithDescendants, chainedClassSelectors };
14777
+ }
14778
+ function checkStyleSurvivalFromDom($, source, framework) {
14779
+ const issues = [];
14780
+ const add2 = (rule, severity, clients, message, locs, detail) => {
14781
+ const frameworkNote = getStyleSurvivalNote(rule, framework);
14782
+ issues.push(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
14783
+ rule,
14784
+ severity,
14785
+ clients: [...clients],
14786
+ message
14787
+ }, frameworkNote ? { frameworkNote } : {}), detail ? { detail } : {}), locs.length ? { loc: locs[0], locs: locs.slice(0, MAX_LOCS) } : {}), locs.length > MAX_LOCS ? { locsTruncated: true } : {}));
14788
+ };
14789
+ const sheets = [];
14790
+ const hits = { spaceColor: 0, doubleBrace: 0, attrSemicolon: 0, chained: 0 };
14791
+ const spaceColorLocs = [];
14792
+ const doubleBraceLocs = [];
14793
+ const attrSemicolonLocs = [];
14794
+ const chainedLocs = [];
14795
+ let chainedExample = "";
14796
+ $("style").each((_, el) => {
14797
+ const cssText = $(el).text();
14798
+ if (!cssText.trim()) return;
14799
+ const anchor = cssBlockAnchor(el, cssText, source);
14800
+ const at = (index) => {
14801
+ const before = cssText.slice(0, index);
14802
+ const line = before.split("\n").length;
14803
+ const column = index - before.lastIndexOf("\n");
14804
+ return locInCssBlock(anchor, {
14805
+ start: { line, column, offset: index },
14806
+ end: { line, column: column + 1, offset: index + 1 }
14807
+ });
14808
+ };
14809
+ const push = (into, index) => {
14810
+ var _a;
14811
+ const loc = (_a = at(index)) != null ? _a : locOfElement(el);
14812
+ if (loc) into.push(loc);
14813
+ };
14814
+ if (hasSpaceSeparatedColor(cssText)) {
14815
+ hits.spaceColor++;
14816
+ push(spaceColorLocs, cssText.search(/\b(?:rgba?|hsla?)\(/i));
14817
+ }
14818
+ const brace = cssText.search(DOUBLE_BRACE);
14819
+ if (brace >= 0) {
14820
+ hits.doubleBrace++;
14821
+ push(doubleBraceLocs, brace);
14822
+ }
14823
+ const attr2 = cssText.search(ATTR_SELECTOR_SEMICOLON);
14824
+ if (attr2 >= 0) {
14825
+ hits.attrSemicolon++;
14826
+ push(attrSemicolonLocs, attr2);
14827
+ }
14828
+ try {
14829
+ const sheet = readSheet(csstree6.parse(cssText, { positions: true }));
14830
+ sheets.push(sheet);
14831
+ if (sheet.chainedClassSelectors.length) {
14832
+ hits.chained++;
14833
+ chainedExample || (chainedExample = sheet.chainedClassSelectors[0]);
14834
+ push(chainedLocs, 0);
14835
+ }
14836
+ } catch (e) {
14837
+ }
14838
+ });
14839
+ const inlineColorEls = $("[style]").toArray().filter((el) => {
14840
+ var _a;
14841
+ return hasSpaceSeparatedColor((_a = $(el).attr("style")) != null ? _a : "");
14842
+ });
14843
+ if (hits.spaceColor) {
14844
+ add2(
14845
+ "gmail-space-separated-color",
14846
+ "error",
14847
+ GMAIL,
14848
+ "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.",
14849
+ spaceColorLocs
14850
+ );
14851
+ }
14852
+ if (inlineColorEls.length) {
14853
+ add2(
14854
+ "gmail-space-separated-color-inline",
14855
+ "error",
14856
+ GMAIL,
14857
+ `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.`,
14858
+ inlineColorEls.map((el) => locOfElement(el)).filter((l) => !!l)
14859
+ );
14860
+ }
14861
+ if (hits.doubleBrace) {
14862
+ add2(
14863
+ "outlook-double-brace",
14864
+ "error",
14865
+ OUTLOOK_WEB_AND_MOBILE,
14866
+ "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.",
14867
+ doubleBraceLocs
14868
+ );
14869
+ }
14870
+ if (hits.attrSemicolon) {
14871
+ add2(
14872
+ "yahoo-attribute-selector-semicolon",
14873
+ "error",
14874
+ YAHOO_AOL,
14875
+ '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.',
14876
+ attrSemicolonLocs
14877
+ );
14878
+ }
14879
+ if (hits.chained) {
14880
+ add2(
14881
+ "outlook-web-chained-class",
14882
+ "warning",
14883
+ OUTLOOK_WEB,
14884
+ `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.`,
14885
+ chainedLocs
14886
+ );
14887
+ }
14888
+ const conflicting = [];
14889
+ const shadowed = [];
14890
+ let conflictCount = 0;
14891
+ let shadowCount = 0;
14892
+ let conflictExample = "";
14893
+ $("[class]").each((_, el) => {
14894
+ var _a, _b;
14895
+ const names = ((_a = $(el).attr("class")) != null ? _a : "").split(/\s+/).filter(Boolean);
14896
+ if (names.length < 2) return;
14897
+ const loc = locOfElement(el);
14898
+ const seen = /* @__PURE__ */ new Map();
14899
+ for (const sheet of sheets) {
14900
+ for (const name of names) {
14901
+ for (const prop of (_b = sheet.propsByClass.get(name)) != null ? _b : []) {
14902
+ const first = seen.get(prop);
14903
+ if (first && first !== name) {
14904
+ conflictExample || (conflictExample = `.${first} and .${name} both set ${prop}`);
14905
+ conflictCount++;
14906
+ if (loc) conflicting.push(loc);
14907
+ return;
14908
+ }
14909
+ if (!first) seen.set(prop, name);
14910
+ }
14911
+ }
14912
+ if (names.some((n) => sheet.classesWithDescendants.has(n))) {
14913
+ shadowCount++;
14914
+ if (loc) shadowed.push(loc);
14915
+ return;
14916
+ }
14917
+ }
14918
+ });
14919
+ if (conflictCount) {
14920
+ add2(
14921
+ "outlook-first-class-only",
14922
+ "warning",
14923
+ WORD_ENGINE,
14924
+ `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.`,
14925
+ conflicting
14926
+ );
14927
+ }
14928
+ if (shadowCount) {
14929
+ add2(
14930
+ "outlook-first-class-descendants",
14931
+ "warning",
14932
+ WORD_ENGINE,
14933
+ "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.",
14934
+ shadowed
14935
+ );
14936
+ }
14937
+ return { issues };
14938
+ }
14939
+ function checkStyleSurvival(html, options) {
14940
+ return fromHtml(
14941
+ html,
14942
+ EMPTY_STYLE_SURVIVAL,
14943
+ ($) => checkStyleSurvivalFromDom(
14944
+ $,
14945
+ (options == null ? void 0 : options.positions) ? html : void 0,
14946
+ options == null ? void 0 : options.framework
14947
+ ),
14948
+ options
14949
+ );
14950
+ }
14951
+
14618
14952
  // src/rules/feature-urls.ts
14619
14953
  var FEATURE_URLS = {
14620
14954
  "!important": "https://www.caniemail.com/features/css-important/",
@@ -15564,7 +15898,7 @@ function validateLinks(html, options) {
15564
15898
 
15565
15899
  // src/accessibility-checker.ts
15566
15900
  import * as cheerio5 from "cheerio";
15567
- import * as csstree6 from "css-tree";
15901
+ import * as csstree7 from "css-tree";
15568
15902
  var RULE_PENALTY_CAPS = {
15569
15903
  "img-missing-alt": 3,
15570
15904
  "link-generic-text": 3,
@@ -15808,7 +16142,7 @@ function specificityFromTokens(selector) {
15808
16142
  }
15809
16143
  function specificityOf(selector) {
15810
16144
  try {
15811
- const ast = csstree6.parse(selector, { context: "selector" });
16145
+ const ast = csstree7.parse(selector, { context: "selector" });
15812
16146
  return specificityOfSelector(ast);
15813
16147
  } catch (e) {
15814
16148
  return specificityFromTokens(selector);
@@ -15853,14 +16187,14 @@ function computeCascade($, ctx) {
15853
16187
  });
15854
16188
  });
15855
16189
  const handleRule = (node) => {
15856
- const selectorList = csstree6.generate(node.prelude).trim();
16190
+ const selectorList = csstree7.generate(node.prelude).trim();
15857
16191
  if (!selectorList) return;
15858
16192
  const decls = [];
15859
16193
  node.block.children.forEach((child) => {
15860
16194
  if (child.type !== "Declaration") return;
15861
16195
  const prop = child.property.toLowerCase();
15862
16196
  if (!CASCADE_PROPS.has(prop)) return;
15863
- decls.push({ prop, value: csstree6.generate(child.value), important: !!child.important });
16197
+ decls.push({ prop, value: csstree7.generate(child.value), important: !!child.important });
15864
16198
  });
15865
16199
  if (!decls.length) return;
15866
16200
  for (const selector of splitTopLevel(selectorList).map((x) => x.trim()).filter(Boolean)) {
@@ -15890,7 +16224,7 @@ function computeCascade($, ctx) {
15890
16224
  return;
15891
16225
  }
15892
16226
  if (node.type !== "Atrule" || node.name.toLowerCase() !== "media" || !node.block) return;
15893
- const prelude = node.prelude ? csstree6.generate(node.prelude) : "";
16227
+ const prelude = node.prelude ? csstree7.generate(node.prelude) : "";
15894
16228
  if (!mediaApplies(prelude, ctx)) return;
15895
16229
  visitBlock(node.block.children);
15896
16230
  });
@@ -15898,7 +16232,7 @@ function computeCascade($, ctx) {
15898
16232
  $("style").each((_, styleEl) => {
15899
16233
  let ast;
15900
16234
  try {
15901
- ast = csstree6.parse($(styleEl).text());
16235
+ ast = csstree7.parse($(styleEl).text());
15902
16236
  } catch (e) {
15903
16237
  return;
15904
16238
  }
@@ -16679,8 +17013,9 @@ function humanizeBytes(bytes) {
16679
17013
  const mb = kb / 1024;
16680
17014
  return `${mb.toFixed(2)} MB`;
16681
17015
  }
16682
- function checkSizeFromDom(_$, html) {
17016
+ function checkSizeFromDom($, html) {
16683
17017
  const htmlBytes = new TextEncoder().encode(html).length;
17018
+ const styleBytes = $("style").toArray().reduce((n, el) => n + new TextEncoder().encode($(el).text()).length, 0);
16684
17019
  const humanSize = humanizeBytes(htmlBytes);
16685
17020
  const issues = [];
16686
17021
  let clipped = false;
@@ -16700,7 +17035,22 @@ function checkSizeFromDom(_$, html) {
16700
17035
  detail: `${htmlBytes} bytes is within ${GMAIL_CLIP_THRESHOLD - htmlBytes} bytes of the clip threshold.`
16701
17036
  });
16702
17037
  }
16703
- return { htmlBytes, humanSize, clipped, issues };
17038
+ if (styleBytes > GMAIL_STYLE_LIMIT) {
17039
+ issues.push({
17040
+ rule: "gmail-style-truncated",
17041
+ severity: "error",
17042
+ 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.`,
17043
+ detail: `${styleBytes} bytes of CSS across all <style> elements exceeds the ${GMAIL_STYLE_LIMIT} byte limit.`
17044
+ });
17045
+ } else if (styleBytes > GMAIL_STYLE_WARNING_THRESHOLD) {
17046
+ issues.push({
17047
+ rule: "gmail-style-warning",
17048
+ severity: "warning",
17049
+ message: `${humanizeBytes(styleBytes)} of CSS, approaching Gmail's 16 KB <style> ceiling. Past it, later rules are dropped silently.`,
17050
+ detail: `${styleBytes} bytes is within ${GMAIL_STYLE_LIMIT - styleBytes} bytes of the limit.`
17051
+ });
17052
+ }
17053
+ return { htmlBytes, styleBytes, humanSize, clipped, issues };
16704
17054
  }
16705
17055
  function checkSize(html) {
16706
17056
  return fromHtml(html, EMPTY_SIZE, checkSizeFromDom);
@@ -16814,7 +17164,7 @@ function checkTemplateVariables(html, options) {
16814
17164
  }
16815
17165
 
16816
17166
  // src/overflow-checker.ts
16817
- import * as csstree7 from "css-tree";
17167
+ import * as csstree8 from "css-tree";
16818
17168
  var RESPONSIVE_MIN_WIDTH = 320;
16819
17169
  function fixedPxWidth($el) {
16820
17170
  const style = $el.attr("style") || "";
@@ -16891,11 +17241,11 @@ function checkOverflowFromDom($, source) {
16891
17241
  const anchor = cssBlockAnchor(el, cssText, source);
16892
17242
  let ast;
16893
17243
  try {
16894
- ast = csstree7.parse(cssText, { positions: true });
17244
+ ast = csstree8.parse(cssText, { positions: true });
16895
17245
  } catch (e) {
16896
17246
  return;
16897
17247
  }
16898
- csstree7.walk(ast, {
17248
+ csstree8.walk(ast, {
16899
17249
  visit: "Rule",
16900
17250
  enter(node) {
16901
17251
  if (node.type !== "Rule") return;
@@ -16905,7 +17255,7 @@ function checkOverflowFromDom($, source) {
16905
17255
  node.block.children.forEach((child) => {
16906
17256
  if (child.type !== "Declaration") return;
16907
17257
  const prop = child.property.toLowerCase();
16908
- const val = csstree7.generate(child.value);
17258
+ const val = csstree8.generate(child.value);
16909
17259
  if (prop === "width") {
16910
17260
  const m = val.match(/^(\d+)px$/);
16911
17261
  if (m) {
@@ -16918,7 +17268,7 @@ function checkOverflowFromDom($, source) {
16918
17268
  }
16919
17269
  });
16920
17270
  if (widthPx !== null && widthPx > EMAIL_MAX_WIDTH && !fluid) {
16921
- const selector = csstree7.generate(node.prelude).trim().slice(0, 40);
17271
+ const selector = csstree8.generate(node.prelude).trim().slice(0, 40);
16922
17272
  addWidthIssue(widthPx, selector || "rule", issues, seen, widthLoc);
16923
17273
  }
16924
17274
  }
@@ -17243,7 +17593,7 @@ function checkVml(html, options) {
17243
17593
  }
17244
17594
 
17245
17595
  // src/visual-checker.ts
17246
- import * as csstree8 from "css-tree";
17596
+ import * as csstree9 from "css-tree";
17247
17597
  var CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
17248
17598
  var GRADIENT_RE = /(?:linear|radial|conic)-gradient\(/i;
17249
17599
  function isSolidColor(value) {
@@ -17349,7 +17699,7 @@ function ruleToMap(node) {
17349
17699
  const map = /* @__PURE__ */ new Map();
17350
17700
  node.block.children.forEach((child) => {
17351
17701
  if (child.type === "Declaration") {
17352
- map.set(child.property.toLowerCase(), csstree8.generate(child.value));
17702
+ map.set(child.property.toLowerCase(), csstree9.generate(child.value));
17353
17703
  }
17354
17704
  });
17355
17705
  return map;
@@ -17368,11 +17718,11 @@ function checkVisualFromDom($, source) {
17368
17718
  const anchor = cssBlockAnchor(el, cssText, source);
17369
17719
  let ast;
17370
17720
  try {
17371
- ast = csstree8.parse(cssText, { positions: true });
17721
+ ast = csstree9.parse(cssText, { positions: true });
17372
17722
  } catch (e) {
17373
17723
  return;
17374
17724
  }
17375
- csstree8.walk(ast, {
17725
+ csstree9.walk(ast, {
17376
17726
  visit: "Rule",
17377
17727
  enter(node) {
17378
17728
  if (node.type !== "Rule") return;
@@ -17398,7 +17748,7 @@ function checkVisual(html, options) {
17398
17748
  }
17399
17749
 
17400
17750
  // src/design-consistency.ts
17401
- import * as csstree9 from "css-tree";
17751
+ import * as csstree10 from "css-tree";
17402
17752
  var SAME_COLOUR_DISTANCE = 0.02;
17403
17753
  var LIMITS = {
17404
17754
  fontSize: 8,
@@ -17452,15 +17802,15 @@ function collect($) {
17452
17802
  $("style").each((_, el) => {
17453
17803
  let ast;
17454
17804
  try {
17455
- ast = csstree9.parse($(el).text());
17805
+ ast = csstree10.parse($(el).text());
17456
17806
  } catch (e) {
17457
17807
  return;
17458
17808
  }
17459
- csstree9.walk(ast, {
17809
+ csstree10.walk(ast, {
17460
17810
  visit: "Declaration",
17461
17811
  enter(node) {
17462
17812
  if (node.type !== "Declaration") return;
17463
- record(node.property, csstree9.generate(node.value));
17813
+ record(node.property, csstree10.generate(node.value));
17464
17814
  }
17465
17815
  });
17466
17816
  });
@@ -17569,6 +17919,7 @@ var EMPTY_AUDIT = {
17569
17919
  images: EMPTY_IMAGES,
17570
17920
  inboxPreview: EMPTY_INBOX_PREVIEW,
17571
17921
  size: EMPTY_SIZE,
17922
+ styleSurvival: EMPTY_STYLE_SURVIVAL,
17572
17923
  templateVariables: EMPTY_TEMPLATE,
17573
17924
  overflow: EMPTY_OVERFLOW,
17574
17925
  visual: EMPTY_VISUAL,
@@ -17597,6 +17948,7 @@ function runAudit($, html, framework, options) {
17597
17948
  const images = skip.has("images") ? EMPTY_IMAGES : analyzeImagesFromDom($);
17598
17949
  const inboxPreview = skip.has("inboxPreview") ? EMPTY_INBOX_PREVIEW : extractInboxPreviewFromDom($);
17599
17950
  const size = skip.has("size") ? EMPTY_SIZE : checkSizeFromDom($, html);
17951
+ const styleSurvival = skip.has("styleSurvival") ? EMPTY_STYLE_SURVIVAL : checkStyleSurvivalFromDom($, source, framework);
17600
17952
  const templateVariables = skip.has("templateVariables") ? EMPTY_TEMPLATE : checkTemplateVariablesFromDom($, source);
17601
17953
  const overflow = skip.has("overflow") ? EMPTY_OVERFLOW : checkOverflowFromDom($, source);
17602
17954
  const visual = skip.has("visual") ? EMPTY_VISUAL : checkVisualFromDom($, source);
@@ -17607,7 +17959,7 @@ function runAudit($, html, framework, options) {
17607
17959
  ]);
17608
17960
  const design = skip.has("design") ? EMPTY_DESIGN : checkDesignConsistencyFromDom($);
17609
17961
  const mobileContrast = skip.has("mobileContrast") || skip.has("accessibility") ? [] : checkMobileContrastFromDom($, accessibility.issues);
17610
- return { compatibility: { warnings, scores }, spam, links, accessibility, images, inboxPreview, size, templateVariables, overflow, visual, vml, darkContrast, mobileContrast, design };
17962
+ return { compatibility: { warnings, scores }, spam, links, accessibility, images, inboxPreview, size, styleSurvival, templateVariables, overflow, visual, vml, darkContrast, mobileContrast, design };
17611
17963
  }
17612
17964
  function auditEmail(html, options) {
17613
17965
  return fromHtml(html, EMPTY_AUDIT, ($, h) => runAudit($, h, options == null ? void 0 : options.framework, options), options);
@@ -17651,7 +18003,7 @@ function toPlainText(html) {
17651
18003
  if (trimmed) lines.push(trimmed);
17652
18004
  currentLine = "";
17653
18005
  }
17654
- function walk9(node) {
18006
+ function walk10(node) {
17655
18007
  var _a;
17656
18008
  if (node.type === "text") {
17657
18009
  const text = node.data.replace(/\s+/g, " ");
@@ -17700,7 +18052,7 @@ function toPlainText(html) {
17700
18052
  currentLine = "- ";
17701
18053
  }
17702
18054
  for (const child of el.children) {
17703
- walk9(child);
18055
+ walk10(child);
17704
18056
  }
17705
18057
  if (isBlock) flushLine();
17706
18058
  }
@@ -17708,7 +18060,7 @@ function toPlainText(html) {
17708
18060
  const root = body.length ? body[0] : $.root()[0];
17709
18061
  if (root && "children" in root) {
17710
18062
  for (const child of root.children) {
17711
- walk9(child);
18063
+ walk10(child);
17712
18064
  }
17713
18065
  }
17714
18066
  flushLine();
@@ -17839,6 +18191,7 @@ export {
17839
18191
  checkMobileContrast,
17840
18192
  checkOverflow,
17841
18193
  checkSize,
18194
+ checkStyleSurvival,
17842
18195
  checkTemplateVariables,
17843
18196
  checkVisual,
17844
18197
  checkVml,