@emailens/cli 0.13.12 → 0.13.14

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.
@@ -63434,27 +63434,28 @@ function vmlToCss(html3) {
63434
63434
  out = out.replace(
63435
63435
  /<v:roundrect([^>]*)>([\s\S]*?)<\/v:roundrect>/gi,
63436
63436
  (_m2, rawAttrs, inner) => {
63437
- var _a22, _b, _c2, _d, _e2, _f, _g, _h2;
63437
+ var _a22, _b, _c2, _d, _e2, _f, _g, _h2, _i2, _j;
63438
63438
  const a2 = attrs(rawAttrs);
63439
63439
  const s2 = styleProps((_a22 = a2.style) != null ? _a22 : "");
63440
- const w2 = (_b = px(s2.width)) != null ? _b : 0;
63441
- const h = (_c2 = px(s2.height)) != null ? _c2 : 0;
63442
- const radius = arcsizeToRadius((_d = a2.arcsize) != null ? _d : "20%", w2, h);
63440
+ const auto = /^auto$/i.test((_c2 = (_b = s2.width) == null ? void 0 : _b.trim()) != null ? _c2 : "");
63441
+ const w2 = auto ? 64 : (_d = px(s2.width)) != null ? _d : 0;
63442
+ const h = (_e2 = px(s2.height)) != null ? _e2 : 0;
63443
+ const radius = arcsizeToRadius((_f = a2.arcsize) != null ? _f : "20%", w2, h);
63443
63444
  const fillTag = inner.match(/<v:fill([^>]*?)\/?>/i);
63444
63445
  const f3 = fillTag ? attrs(fillTag[1]) : {};
63445
63446
  const imageData = inner.match(/<v:imagedata([^>]*?)\/?>/i);
63446
63447
  const imageSrc = imageData ? attrs(imageData[1]).src : void 0;
63447
- const fill = (_f = (_e2 = f3.color) != null ? _e2 : a2.fillcolor) != null ? _f : "transparent";
63448
+ const fill = (_h2 = (_g = f3.color) != null ? _g : a2.fillcolor) != null ? _h2 : "transparent";
63448
63449
  const image = imageSrc ? `;background-image:url('${imageSrc}');background-size:100% 100%;background-repeat:no-repeat` : "";
63449
63450
  const stroked = !(a2.stroke === "f" || a2.stroke === "false");
63450
- const middle = /middle/i.test((_g = s2["v-text-anchor"]) != null ? _g : "");
63451
- const label = inner.replace(/<v:fill[^>]*?\/?>(?:\s*<\/v:fill>)?/gi, "").replace(/<v:imagedata[^>]*?\/?>(?:\s*<\/v:imagedata>)?/gi, "").replace(/<\/?w:anchorlock[^>]*>/gi, "").replace(/<center\b/gi, "<span").replace(/<\/center>/gi, "</span>").trim();
63451
+ const middle = /middle/i.test((_i2 = s2["v-text-anchor"]) != null ? _i2 : "");
63452
+ const label = inner.replace(/<v:fill[^>]*?\/?>(?:\s*<\/v:fill>)?/gi, "").replace(/<v:imagedata[^>]*?\/?>(?:\s*<\/v:imagedata>)?/gi, "").replace(/<\/?w:anchorlock[^>]*>/gi, "").replace(/<center\b/gi, "<span").replace(/<\/center>/gi, "</span>").trim().replace(/^<span(?: style="([^"]*)")?/i, (tag, style) => auto ? `<span style="display:block;max-height:1lh;overflow:hidden;padding:0 9.6px;${style != null ? style : ""}"` : tag);
63452
63453
  const box2 = [
63453
63454
  w2 ? `width:${w2}px` : "",
63454
63455
  h ? `height:${h}px` : "",
63455
63456
  `border-radius:${radius}px`,
63456
63457
  `background:${fill}${image}`,
63457
- stroked ? `border:1px solid ${(_h2 = a2.strokecolor) != null ? _h2 : "#000"}` : "border:none",
63458
+ stroked ? `border:1px solid ${(_j = a2.strokecolor) != null ? _j : "#000"}` : "border:none",
63458
63459
  "display:inline-flex",
63459
63460
  "justify-content:center",
63460
63461
  `align-items:${middle ? "center" : "flex-start"}`,
@@ -63610,6 +63611,17 @@ function blankLabelsAfterNestedShape(html3) {
63610
63611
  );
63611
63612
  return html3.slice(0, at2) + tail;
63612
63613
  }
63614
+ var LINK_LINE_BLOCKS = /* @__PURE__ */ new Set(["div", "p", "table", "ul", "ol", "h1", "h2", "h3", "h4", "h5", "h6", "center", "blockquote", "hr"]);
63615
+ var INLINE_TAGS = /* @__PURE__ */ new Set(["span", "a", "b", "strong", "i", "em", "u", "font", "small", "big", "sub", "sup"]);
63616
+ var WORD_PARSED = /^(?:mso-.*|font(?:-(?:family|size|weight|style|variant))?|color|background(?:-color)?|line-height|letter-spacing|white-space|word-wrap|text-(?:align|decoration|transform|indent|shadow)|vertical-align|direction|unicode-bidi|width|height|(?:margin|padding)(?:-(?:top|right|bottom|left))?|border(?:-(?:top|right|bottom|left))?(?:-(?:color|style|width))?)$/;
63617
+ var WORD_PARSED_VALUES = { "word-break": /^normal$/i, display: /^(?:inline|none)$/i };
63618
+ function wordParsesAll(props) {
63619
+ for (const [name, value] of props) {
63620
+ const values = WORD_PARSED_VALUES[name];
63621
+ if (values ? !values.test(value.replace(/\s*!important$/i, "").trim()) : !WORD_PARSED.test(name)) return false;
63622
+ }
63623
+ return true;
63624
+ }
63613
63625
  var PADDING = ["padding", "padding-top", "padding-right", "padding-bottom", "padding-left"];
63614
63626
  var MARGIN = ["margin", "margin-top", "margin-right", "margin-bottom", "margin-left"];
63615
63627
  var BORDER_WIDTH = [
@@ -63625,6 +63637,16 @@ var BORDER_WIDTH = [
63625
63637
  "border-left-width"
63626
63638
  ];
63627
63639
  var NATURAL_LINE = 1.15;
63640
+ var GILL_VDMX = [14, 14, 15, 16, 18, 18, 21, 21, 23, 25, 27, 27, 29, 30, 31];
63641
+ var isGill = (family = "") => /^\s*['"]?gill sans/i.test(family);
63642
+ var FACE_LINE = [[/^\s*['"]?arial black\b/i, 1.41]];
63643
+ var naturalHeight = (size, family = "") => {
63644
+ var _a22, _b;
63645
+ if (!isGill(family)) return Math.round(size * ((_b = (_a22 = FACE_LINE.find(([face]) => face.test(family))) == null ? void 0 : _a22[1]) != null ? _b : NATURAL_LINE));
63646
+ const ppem = Math.round(size);
63647
+ return ppem <= 22 ? GILL_VDMX[Math.max(ppem, 8) - 8] : Math.ceil(0.9292 * size) + Math.ceil(0.2305 * size);
63648
+ };
63649
+ var GILL_LARGE = "'Gill Sans MT Large'";
63628
63650
  var TABLE_GUTTER = 3.5;
63629
63651
  var INVISIBLE_ONLY = /^[\s\u00a0\u00ad\u034f\u200b-\u200d\u2007\ufeff]+$/;
63630
63652
  var LIST_TRAILING_PX = 18;
@@ -63785,8 +63807,33 @@ function markHiddenCells(html3) {
63785
63807
  );
63786
63808
  }
63787
63809
  function prepareWordSource(html3) {
63788
- return markHiddenCells(dropWordUnknownColors(html3));
63810
+ return markUnparsedInlines(wordSubstitutes(markHiddenCells(dropWordUnknownColors(html3))));
63789
63811
  }
63812
+ var UNPARSED_MARK = "data-word-unparsed";
63813
+ var INLINE_STYLE = new RegExp(String.raw`<(${[...INLINE_TAGS].join("|")})(?=\s)(?=[^>]*?\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)'))`, "gi");
63814
+ var markUnparsedInlines = (html3) => html3.replace(INLINE_STYLE, (open, _tag, dq, sq) => {
63815
+ var _a22;
63816
+ return wordParsesAll(parseInlineStyle((_a22 = dq != null ? dq : sq) != null ? _a22 : "")) ? open : `${open} ${UNPARSED_MARK}`;
63817
+ });
63818
+ var WORD_SUBSTITUTES = { rubik: "Calibri" };
63819
+ var SUBSTITUTED = new RegExp(String.raw`(font(?:-family)?\s*:[^;"}]*?)(['"]?)\b(${Object.keys(WORD_SUBSTITUTES).join("|")})\b\2`, "gi");
63820
+ var wordSubstitutes = (html3) => html3.replace(SUBSTITUTED, (_3, lead, _q, name) => `${lead}${WORD_SUBSTITUTES[name.toLowerCase()]}`);
63821
+ var OFFICE_CLOUD_FONTS = [
63822
+ "Work Sans",
63823
+ "Lato",
63824
+ "Montserrat",
63825
+ "Nunito",
63826
+ "Nunito Sans",
63827
+ "Open Sans",
63828
+ "DM Sans",
63829
+ "IBM Plex Sans",
63830
+ "Ubuntu",
63831
+ "Source Code Pro",
63832
+ "Raleway",
63833
+ "Playfair Display",
63834
+ "Poppins"
63835
+ ];
63836
+ var CLOUD = new Set(OFFICE_CLOUD_FONTS.map((f3) => f3.toLowerCase()));
63790
63837
  function declaredFaces($3) {
63791
63838
  const faces = /* @__PURE__ */ new Map();
63792
63839
  $3("style").each((_3, block) => {
@@ -63796,7 +63843,7 @@ function declaredFaces($3) {
63796
63843
  const family = props.get("font-family");
63797
63844
  const named = ((_b = props.get("mso-font-alt")) == null ? void 0 : _b.replace(/["']/g, "").trim()) || null;
63798
63845
  const alt = named && /^sans-serif$/i.test(named) ? WORD_DEFAULT : named;
63799
- if (family) faces.set(firstFamily(family), (_c2 = alt != null ? alt : faces.get(firstFamily(family))) != null ? _c2 : null);
63846
+ if (family && !CLOUD.has(firstFamily(family))) faces.set(firstFamily(family), (_c2 = alt != null ? alt : faces.get(firstFamily(family))) != null ? _c2 : null);
63800
63847
  }
63801
63848
  });
63802
63849
  return faces;
@@ -63828,8 +63875,36 @@ function leftPadding(props) {
63828
63875
  const value = parts.length === 4 ? parts[3] : parts.length >= 2 ? parts[1] : parts[0];
63829
63876
  return /^\d+(?:\.\d+)?(?:px)?$/.test(value != null ? value : "") ? parseFloat(value) : 0;
63830
63877
  }
63878
+ var SPACING = /^(?:line-height|mso-line-height-rule|mso-line-height-alt|font-size|font|font-family|background|background-color)$/;
63879
+ function sheetSpacing($3) {
63880
+ const found = /* @__PURE__ */ new Map();
63881
+ $3("style").each((_3, block) => {
63882
+ var _a22, _b;
63883
+ for (const { selector, body } of topLevelRules((_a22 = $3(block).html()) != null ? _a22 : "")) {
63884
+ const rule = [...parseInlineStyle(body.replace(/!important/gi, ""))].filter(([k2]) => SPACING.test(k2));
63885
+ if (!rule.length) continue;
63886
+ for (const one of selector.split(",")) {
63887
+ for (const el2 of matchedByWord($3, one)) {
63888
+ const has2 = (_b = found.get(el2)) != null ? _b : /* @__PURE__ */ new Map();
63889
+ for (const [k2, v] of rule) has2.set(k2, v);
63890
+ found.set(el2, has2);
63891
+ }
63892
+ }
63893
+ }
63894
+ });
63895
+ return found;
63896
+ }
63831
63897
  function applyWordBoxModel($3) {
63832
63898
  const faces = declaredFaces($3);
63899
+ const sheet = sheetSpacing($3);
63900
+ const spacingOf = (el2) => {
63901
+ var _a22, _b;
63902
+ const all = new Map([...(_a22 = sheet.get(el2)) != null ? _a22 : [], ...parseInlineStyle($3(el2).attr("style") || "")]);
63903
+ const alt = (_b = all.get("mso-line-height-alt")) == null ? void 0 : _b.trim();
63904
+ const altEm = /^([\d.]+)em$/i.exec(alt != null ? alt : "");
63905
+ if (alt) all.set("line-height", altEm ? `${Number(altEm[1]) * 16}px` : alt);
63906
+ return all;
63907
+ };
63833
63908
  $3("[style]").each((_3, node) => {
63834
63909
  var _a22, _b, _c2, _d, _e2, _f, _g, _h2, _i2, _j, _k, _l2, _m2, _n2;
63835
63910
  const el2 = node;
@@ -63889,7 +63964,7 @@ function applyWordBoxModel($3) {
63889
63964
  const lineHeight = /^([\d.]+)px$/i.exec((_k = props.get("line-height")) != null ? _k : "");
63890
63965
  const fontSize = /^([\d.]+)px$/i.exec((_l2 = props.get("font-size")) != null ? _l2 : "");
63891
63966
  if (lineHeight && fontSize && !/exactly/i.test((_m2 = props.get("mso-line-height-rule")) != null ? _m2 : "")) {
63892
- const natural = Math.round(Number(fontSize[1]) * NATURAL_LINE);
63967
+ const natural = naturalHeight(Number(fontSize[1]), props.get("font-family"));
63893
63968
  if (Number(lineHeight[1]) < natural) props.set("line-height", `${natural}px`);
63894
63969
  }
63895
63970
  for (const prop2 of ["word-spacing", "outline", "outline-width", "outline-style", "outline-color", "outline-offset"]) {
@@ -63927,6 +64002,18 @@ function applyWordBoxModel($3) {
63927
64002
  props.set("line-height", "0");
63928
64003
  cell.empty().attr("style", serializeStyle(props));
63929
64004
  });
64005
+ $3("p").each((_3, node) => {
64006
+ if (!$3(node).children().length && !/[^ \t\r\n]/.test($3(node).text())) $3(node).remove();
64007
+ });
64008
+ $3("img").each((_3, node) => {
64009
+ var _a22, _b;
64010
+ const img = $3(node);
64011
+ const props = parseInlineStyle(img.attr("style") || "");
64012
+ const height = Number.parseFloat((_b = (_a22 = props.get("height")) != null ? _a22 : img.attr("height")) != null ? _b : "");
64013
+ if (img.closest("td, th").length || !(height <= 1)) return;
64014
+ props.set("display", "block");
64015
+ img.attr("style", serializeStyle(props));
64016
+ });
63930
64017
  $3("hr").each((_3, node) => {
63931
64018
  var _a22, _b, _c2;
63932
64019
  const props = parseInlineStyle($3(node).attr("style") || "");
@@ -63941,9 +64028,18 @@ function applyWordBoxModel($3) {
63941
64028
  ]);
63942
64029
  $3(node).attr("style", serializeStyle(set));
63943
64030
  });
64031
+ const blank = (n2) => n2.type === "comment" || n2.type === "text" && !n2.data.trim();
63944
64032
  $3("a").each((_3, node) => {
63945
- if (!$3(node).children("div").length) return;
63946
- $3(node).before('<div style="height:21px"></div>').after('<div style="height:20px"></div>');
64033
+ if (!$3(node).children("div, p").length) return;
64034
+ let before2 = node.prev;
64035
+ while (before2 && blank(before2)) before2 = before2.prev;
64036
+ let after2 = node.next;
64037
+ while (after2 && blank(after2)) after2 = after2.next;
64038
+ const parent2 = node.parent;
64039
+ const endsCell = !after2 && (parent2 == null ? void 0 : parent2.type) === "tag" && /^t[dh]$/.test(parent2.name);
64040
+ if (!before2 || before2.type === "tag" && LINK_LINE_BLOCKS.has(before2.name))
64041
+ $3(node).before('<div style="height:21px"></div>');
64042
+ if (!endsCell) $3(node).after('<div style="height:20px"></div>');
63947
64043
  });
63948
64044
  $3("a[style*='text-decoration-line']").each((_3, node) => {
63949
64045
  const props = parseInlineStyle($3(node).attr("style") || "");
@@ -64000,6 +64096,7 @@ function applyWordBoxModel($3) {
64000
64096
  if (text3.length > 20 && INVISIBLE_ONLY.test(text3)) el2.text(String.fromCharCode(160));
64001
64097
  });
64002
64098
  $3("ul,ol").each((_3, node) => {
64099
+ var _a22;
64003
64100
  const el2 = node;
64004
64101
  const props = parseInlineStyle($3(el2).attr("style") || "");
64005
64102
  let previous = el2.prev;
@@ -64009,11 +64106,27 @@ function applyWordBoxModel($3) {
64009
64106
  const style = parseInlineStyle($3(item).attr("style") || "");
64010
64107
  return style.has("margin") || style.has("margin-top") || style.has("margin-bottom");
64011
64108
  });
64012
- props.set("margin-top", afterBreak || previous && !tight ? "1lh!important" : "0!important");
64109
+ const nested = ((_a22 = el2.parent) == null ? void 0 : _a22.type) === "tag" && el2.parent.name === "li";
64110
+ props.set("margin-top", afterBreak || previous && !tight && !nested ? "1lh!important" : "0!important");
64013
64111
  props.set("margin-bottom", tight ? "0!important" : `${LIST_TRAILING_PX}px!important`);
64014
64112
  props.set("padding-left", `${LIST_TEXT_INDENT_PX}px!important`);
64015
64113
  $3(el2).attr("style", serializeStyle(props));
64016
64114
  });
64115
+ $3("br").each((_3, node) => {
64116
+ let at2 = node;
64117
+ let unparsed = false;
64118
+ for (; ; ) {
64119
+ for (let next2 = at2.next; next2; next2 = next2.next) {
64120
+ if (next2.type !== "text" || !/^[ \t\r\n]*$/.test(next2.data)) return;
64121
+ }
64122
+ const parent2 = at2.parent;
64123
+ if ((parent2 == null ? void 0 : parent2.type) !== "tag" || !INLINE_TAGS.has(parent2.name)) break;
64124
+ if ($3(parent2).attr(UNPARSED_MARK) !== void 0) unparsed = true;
64125
+ at2 = parent2;
64126
+ }
64127
+ if (unparsed) $3(node).after("<br>");
64128
+ });
64129
+ $3(`[${UNPARSED_MARK}]`).removeAttr(UNPARSED_MARK);
64017
64130
  $3("picture source").remove();
64018
64131
  $3("table").each((_3, node) => {
64019
64132
  var _a22, _b, _c2;
@@ -64049,37 +64162,91 @@ function applyWordBoxModel($3) {
64049
64162
  })) return;
64050
64163
  cell.attr("style", `${style}${style.trim() === "" || /;\s*$/.test(style) ? "" : ";"}text-align:left`);
64051
64164
  });
64165
+ const sheetMargins = /* @__PURE__ */ new Map();
64166
+ $3("style").each((_3, block) => {
64167
+ var _a22, _b;
64168
+ for (const { selector, body } of topLevelRules((_a22 = $3(block).html()) != null ? _a22 : "")) {
64169
+ if (!/margin/i.test(body)) continue;
64170
+ let cells = [];
64171
+ try {
64172
+ cells = $3(selector).filter("td, th").toArray();
64173
+ } catch (e2) {
64174
+ continue;
64175
+ }
64176
+ const rule = parseInlineStyle(body.replace(/!important/gi, ""));
64177
+ for (const cell of cells) {
64178
+ const has2 = (_b = sheetMargins.get(cell)) != null ? _b : /* @__PURE__ */ new Map();
64179
+ for (const [k2, v] of rule) if (/^margin(?:-top|-bottom)?$/.test(k2)) has2.set(k2, v);
64180
+ sheetMargins.set(cell, has2);
64181
+ }
64182
+ }
64183
+ });
64184
+ const verticalMargins = (props) => {
64185
+ var _a22, _b, _c2, _d;
64186
+ const box2 = ((_a22 = props.get("margin")) != null ? _a22 : "").trim().split(/\s+/).filter(Boolean);
64187
+ const read = (v) => v === void 0 ? void 0 : Number.parseFloat(v) || 0;
64188
+ return { top: read((_b = props.get("margin-top")) != null ? _b : box2[0]), bottom: read((_d = (_c2 = props.get("margin-bottom")) != null ? _c2 : box2[2]) != null ? _d : box2[0]) };
64189
+ };
64190
+ const holdsBareText = (cell) => {
64191
+ const inline = $3(cell).clone();
64192
+ inline.find("table, div, p, ul, ol, h1, h2, h3, h4, h5, h6").remove();
64193
+ return /[^\s ]/.test(inline.text());
64194
+ };
64052
64195
  $3("table").each((_3, node) => {
64053
- var _a22, _b, _c2, _d, _e2, _f, _g, _h2;
64196
+ var _a22, _b, _c2, _d, _e2;
64054
64197
  const table = $3(node);
64055
64198
  const props = parseInlineStyle(table.attr("style") || "");
64056
64199
  const box2 = ((_a22 = props.get("margin")) != null ? _a22 : "").trim().split(/\s+/).filter(Boolean);
64057
- const top = Number.parseFloat((_c2 = (_b = props.get("margin-top")) != null ? _b : box2[0]) != null ? _c2 : "") || 0;
64058
- const bottom = Number.parseFloat((_f = (_e2 = (_d = props.get("margin-bottom")) != null ? _d : box2[2]) != null ? _e2 : box2[0]) != null ? _f : "") || 0;
64059
- if (top <= 0 && bottom <= 0 || /center/i.test((_g = table.attr("align")) != null ? _g : "")) return;
64060
- const rows = table.find("> tr, > tbody > tr");
64061
- const grow = (row, side, by2) => {
64062
- row.children("td, th").each((_22, cell) => {
64063
- var _a32, _b2, _c22, _d2;
64064
- const own = parseInlineStyle($3(cell).attr("style") || "");
64065
- const pad = ((_a32 = own.get("padding")) != null ? _a32 : "").trim().split(/\s+/).filter(Boolean);
64066
- const was = Number.parseFloat((_d2 = (_c22 = own.get(`padding-${side}`)) != null ? _c22 : side === "top" ? pad[0] : (_b2 = pad[2]) != null ? _b2 : pad[0]) != null ? _d2 : "") || 0;
64067
- own.set(`padding-${side}`, `${was + by2}px`);
64068
- $3(cell).attr("style", serializeStyle(own));
64069
- });
64070
- };
64071
- if (!rows.length) return;
64072
- if (top > 0) grow(rows.first(), "top", top);
64073
- if (bottom > 0) grow(rows.last(), "bottom", bottom);
64200
+ const centred = /center/i.test((_b = table.attr("align")) != null ? _b : "");
64201
+ const margins = verticalMargins(props);
64202
+ const top = centred ? 0 : (_c2 = margins.top) != null ? _c2 : 0;
64203
+ const bottom = centred ? 0 : (_d = margins.bottom) != null ? _d : 0;
64204
+ table.find("> tr, > tbody > tr").each((_22, row) => {
64205
+ var _a32, _b2, _c22, _d2, _e22, _f, _g;
64206
+ const cells = $3(row).children("td, th").toArray();
64207
+ const bare = cells.filter(holdsBareText);
64208
+ if (!bare.length) return;
64209
+ for (const cell of cells) {
64210
+ const mine = bare.includes(cell) ? verticalMargins(new Map([...(_a32 = sheetMargins.get(cell)) != null ? _a32 : [], ...parseInlineStyle($3(cell).attr("style") || "")])) : { top: void 0, bottom: void 0 };
64211
+ const style = parseInlineStyle($3(cell).attr("style") || "");
64212
+ const pad = ((_b2 = style.get("padding")) != null ? _b2 : "").trim().split(/\s+/).filter(Boolean);
64213
+ for (const [side, by2] of [["top", (_c22 = mine.top) != null ? _c22 : top], ["bottom", (_d2 = mine.bottom) != null ? _d2 : bottom]]) {
64214
+ if (by2 <= 0) continue;
64215
+ const was = Number.parseFloat((_g = (_f = style.get(`padding-${side}`)) != null ? _f : side === "top" ? pad[0] : (_e22 = pad[2]) != null ? _e22 : pad[0]) != null ? _g : "") || 0;
64216
+ style.set(`padding-${side}`, `${was + by2}px`);
64217
+ }
64218
+ $3(cell).attr("style", serializeStyle(style));
64219
+ }
64220
+ });
64221
+ if (top <= 0 && bottom <= 0 || centred) return;
64074
64222
  props.delete("margin-top");
64075
64223
  props.delete("margin-bottom");
64076
64224
  if (box2.length) {
64077
64225
  props.delete("margin");
64078
- if (box2[1]) props.set("margin-left", (_h2 = box2[3]) != null ? _h2 : box2[1]);
64226
+ if (box2[1]) props.set("margin-left", (_e2 = box2[3]) != null ? _e2 : box2[1]);
64079
64227
  if (box2[1]) props.set("margin-right", box2[1]);
64080
64228
  }
64081
64229
  table.attr("style", serializeStyle(props));
64082
64230
  });
64231
+ $3("tr").each((_3, row) => {
64232
+ const cells = $3(row).children("td, th").toArray();
64233
+ if (cells.length < 2) return;
64234
+ const sides = cells.map((cell) => {
64235
+ var _a22, _b, _c2, _d;
64236
+ const style = parseInlineStyle($3(cell).attr("style") || "");
64237
+ const pad = ((_a22 = style.get("padding")) != null ? _a22 : "").trim().split(/\s+/).filter(Boolean);
64238
+ const read = (v) => Number.parseFloat(v != null ? v : "") || 0;
64239
+ return { style, top: read((_b = style.get("padding-top")) != null ? _b : pad[0]), bottom: read((_d = (_c2 = style.get("padding-bottom")) != null ? _c2 : pad[2]) != null ? _d : pad[0]) };
64240
+ });
64241
+ const top = Math.max(...sides.map((s2) => s2.top));
64242
+ const bottom = Math.max(...sides.map((s2) => s2.bottom));
64243
+ cells.forEach((cell, i2) => {
64244
+ const { style } = sides[i2];
64245
+ if (sides[i2].top < top) style.set("padding-top", `${top}px`);
64246
+ if (sides[i2].bottom < bottom) style.set("padding-bottom", `${bottom}px`);
64247
+ if (sides[i2].top < top || sides[i2].bottom < bottom) $3(cell).attr("style", serializeStyle(style));
64248
+ });
64249
+ });
64083
64250
  $3("table").each((_3, node) => {
64084
64251
  var _a22, _b;
64085
64252
  const props = parseInlineStyle($3(node).attr("style") || "");
@@ -64136,10 +64303,103 @@ function applyWordBoxModel($3) {
64136
64303
  const after2 = serializeStyle(props);
64137
64304
  if (after2) p.attr("style", after2);
64138
64305
  });
64139
- const reset = "<style>h2{margin:0}p{margin:14pt 0}</style>";
64306
+ $3("span, a, strong, b, em, i, u, font").each((_3, node) => {
64307
+ var _a22, _b, _c2;
64308
+ const el2 = node;
64309
+ const props = parseInlineStyle($3(el2).attr("style") || "");
64310
+ if (/block/i.test((_a22 = props.get("display")) != null ? _a22 : "")) return;
64311
+ const spacing = $3(el2).parents().toArray().map(spacingOf).find((st2) => st2.has("line-height"));
64312
+ if (!/^[\d.]+px$/i.test((_b = spacing == null ? void 0 : spacing.get("line-height")) != null ? _b : "") || /exactly/i.test((_c2 = spacing == null ? void 0 : spacing.get("mso-line-height-rule")) != null ? _c2 : "")) return;
64313
+ props.set("line-height", "normal");
64314
+ $3(el2).attr("style", serializeStyle(props));
64315
+ });
64316
+ $3("p, div, td, th, li, h1, h2, h3, h4, h5, h6").each((_3, node) => {
64317
+ var _a22;
64318
+ const el2 = node;
64319
+ const kids = $3(el2).contents().toArray().filter((n2) => !(n2.type === "comment" || n2.type === "text" && !/[^\s]/.test(n2.data)));
64320
+ if (!kids.length || !kids.every((n2) => n2.type === "tag" && INLINE_TAGS.has(n2.name))) return;
64321
+ if ($3(el2).find("img, table, svg, a, [style*='display']").length) return;
64322
+ const spacing = [el2, ...$3(el2).parents().toArray()].map(spacingOf).find((st2) => st2.has("line-height"));
64323
+ const line = ((_a22 = spacing == null ? void 0 : spacing.get("line-height")) != null ? _a22 : "normal").replace(/\s*!important$/i, "").trim();
64324
+ if (!(line === "normal" || /^\d*\.\d+$/.test(line) && Number(line) >= 1)) return;
64325
+ const own = parseInlineStyle($3(el2).attr("style") || "");
64326
+ own.set("line-height", "0");
64327
+ $3(el2).attr("style", serializeStyle(own));
64328
+ for (const kid of kids) {
64329
+ const props = parseInlineStyle($3(kid).attr("style") || "");
64330
+ if (props.has("line-height")) continue;
64331
+ props.set("line-height", "normal");
64332
+ $3(kid).attr("style", serializeStyle(props));
64333
+ }
64334
+ });
64335
+ const inherited2 = (el2, prop2) => [el2, ...$3(el2).parents().toArray()].map(spacingOf).find((st2) => st2.has(prop2));
64336
+ const sizeOf = (el2) => {
64337
+ var _a22, _b, _c2;
64338
+ const sized = [el2, ...$3(el2).parents().toArray()].map(spacingOf).find((st2) => {
64339
+ var _a32;
64340
+ return st2.has("font-size") || /\d(?:\.\d+)?px/.test((_a32 = st2.get("font")) != null ? _a32 : "");
64341
+ });
64342
+ const px2 = (_c2 = /^([\d.]+)px$/i.exec((_a22 = sized == null ? void 0 : sized.get("font-size")) != null ? _a22 : "")) != null ? _c2 : /(?:^|\s)([\d.]+)px/.exec((_b = sized == null ? void 0 : sized.get("font")) != null ? _b : "");
64343
+ return px2 ? Number(px2[1]) : void 0;
64344
+ };
64345
+ $3("p, div, h1, h2, h3, h4, h5, h6, li, td, th").each((_3, node) => {
64346
+ var _a22, _b, _c2, _d;
64347
+ const el2 = node;
64348
+ const block = $3(el2);
64349
+ if (block.find("p, div, h1, h2, h3, h4, h5, h6, li, table, ul, ol").length || !/[^\s ]/.test(block.text())) return;
64350
+ const own = parseInlineStyle(block.attr("style") || "");
64351
+ if (hasBorder(own)) return;
64352
+ const mine = spacingOf(el2);
64353
+ const spacing = inherited2(el2, "line-height");
64354
+ const line = /^([\d.]+)px$/i.exec((_a22 = spacing == null ? void 0 : spacing.get("line-height")) != null ? _a22 : "");
64355
+ const size = sizeOf(el2);
64356
+ if (!line || !size) return;
64357
+ let largest = size;
64358
+ block.find("*").each((_22, inner) => {
64359
+ var _a32;
64360
+ const px2 = /^([\d.]+)px$/i.exec((_a32 = spacingOf(inner).get("font-size")) != null ? _a32 : "");
64361
+ if (px2) largest = Math.max(largest, Number(px2[1]));
64362
+ });
64363
+ const exactly = /exactly/i.test((_b = spacing == null ? void 0 : spacing.get("mso-line-height-rule")) != null ? _b : "");
64364
+ const natural = naturalHeight(size, (_c2 = inherited2(el2, "font-family")) == null ? void 0 : _c2.get("font-family"));
64365
+ if (!exactly && largest === size && Number(line[1]) < natural) {
64366
+ own.set("line-height", `${natural}px`);
64367
+ block.attr("style", serializeStyle(own));
64368
+ return;
64369
+ }
64370
+ const leading = Math.round((Number(line[1]) - largest * NATURAL_LINE) * 10) / 10;
64371
+ const shift = Math.round(leading * (exactly ? 0.3 : 0.5) * 10) / 10;
64372
+ if (shift <= 0) return;
64373
+ block.wrapInner(
64374
+ exactly ? `<span style="position:relative;top:${shift}px"></span>` : `<span style="vertical-align:bottom;line-height:normal"></span>`
64375
+ );
64376
+ const tag = el2.tagName.toLowerCase();
64377
+ const fill = (_d = mine.get("background-color")) != null ? _d : mine.get("background");
64378
+ if (exactly || tag === "td" || tag === "th" || !fill || /\(|\s/.test(fill.trim())) return;
64379
+ own.delete("background-color");
64380
+ own.set("background", `linear-gradient(transparent ${leading}px, ${fill.trim()} ${leading}px)`);
64381
+ block.attr("style", serializeStyle(own));
64382
+ });
64383
+ $3("body *").each((_3, node) => {
64384
+ var _a22, _b;
64385
+ const el2 = node;
64386
+ if (!$3(el2).contents().toArray().some((n2) => n2.type === "text" && /[^\s ]/.test(n2.data))) return;
64387
+ const family = (_b = (_a22 = inherited2(el2, "font-family")) == null ? void 0 : _a22.get("font-family")) != null ? _b : "";
64388
+ const size = sizeOf(el2);
64389
+ if (!isGill(family) || size === void 0) return;
64390
+ const block = $3(el2).closest("p, div, li, td, th, h1, h2, h3, h4, h5, h6").get(0);
64391
+ const blockSize = block && block !== el2 ? sizeOf(block) : void 0;
64392
+ const large = family.trim().startsWith(GILL_LARGE);
64393
+ if (large === (size > 22 || blockSize !== void 0 && size > blockSize)) return;
64394
+ const props = parseInlineStyle($3(el2).attr("style") || "");
64395
+ const stack = family.replace(new RegExp(String.raw`^\s*${GILL_LARGE},\s*`), "");
64396
+ props.set("font-family", large ? stack : `${GILL_LARGE}, ${stack}`);
64397
+ $3(el2).attr("style", serializeStyle(props));
64398
+ });
64399
+ const reset = "<style>h2{margin:0}p{margin:14pt 0}td,th{box-sizing:border-box}</style>";
64140
64400
  const head = $3("head");
64141
64401
  if (head.length) head.prepend(reset);
64142
- else if ($3("p,h2").length) $3.root().prepend(reset);
64402
+ else if ($3("p,h2,td,th").length) $3.root().prepend(reset);
64143
64403
  }
64144
64404
  var MAX_HTML_SIZE = 2 * 1024 * 1024;
64145
64405
  var MAX_WARNING_LOCATIONS = 100;
@@ -66616,7 +66876,7 @@ function simulateDarkMode(html3, clientId) {
66616
66876
  }
66617
66877
  break;
66618
66878
  case "outlook-windows-legacy":
66619
- applyColorInversion($3, "full", clientId);
66879
+ applyColorInversion($3, "outlook-classic", clientId);
66620
66880
  if (!html3.includes("prefers-color-scheme")) {
66621
66881
  warnings.push({
66622
66882
  severity: "info",
@@ -66698,7 +66958,9 @@ function simulateDarkMode(html3, clientId) {
66698
66958
  return { html: $3.html(), warnings };
66699
66959
  }
66700
66960
  var MEASURED_CANVAS = {
66701
- "outlook-macos": { bg: "#1e1e1e", fg: "#ffffff" }
66961
+ "outlook-macos": { bg: "#1e1e1e", fg: "#ffffff" },
66962
+ // ponytail: fg unmeasured; Word's automatic text is black, which maps here.
66963
+ "outlook-windows-legacy": { bg: "#262626", fg: "#f6f6f6" }
66702
66964
  };
66703
66965
  var SAMPLED_DARK = {
66704
66966
  "outlook-web": { eeeae4: "#595651" },
@@ -66755,6 +67017,53 @@ function outlookMacColor(value, role) {
66755
67017
  if (c2.r === c2.g && c2.g === c2.b) return withLabLightness(c2, (l2) => Math.min(l2, 88.5 - 0.772 * l2), D65);
66756
67018
  return withLabLightness(c2, () => 34.6, D65);
66757
67019
  }
67020
+ var WORD_DARK_GREYS = [
67021
+ [0, 246],
67022
+ [15, 233],
67023
+ [30, 225],
67024
+ [45, 216],
67025
+ [60, 206],
67026
+ [75, 196],
67027
+ [90, 185],
67028
+ [105, 174],
67029
+ [120, 163],
67030
+ [135, 151],
67031
+ [150, 139],
67032
+ [165, 126],
67033
+ [180, 113],
67034
+ [195, 99],
67035
+ [210, 85],
67036
+ [225, 70],
67037
+ [240, 55],
67038
+ [255, 38]
67039
+ ];
67040
+ var greyL = (v) => {
67041
+ const s2 = v / 255;
67042
+ return 116 * labF(s2 <= 0.04045 ? s2 / 12.92 : ((s2 + 0.055) / 1.055) ** 2.4) - 16;
67043
+ };
67044
+ var WORD_DARK_L = WORD_DARK_GREYS.map(([from, to2]) => [greyL(from), greyL(to2)]);
67045
+ var wordDarkL = (l2) => {
67046
+ const i2 = Math.max(1, WORD_DARK_L.findIndex(([x2]) => x2 >= Math.min(l2, 100)));
67047
+ const [[x0, y0], [x1, y1]] = [WORD_DARK_L[i2 - 1], WORD_DARK_L[i2]];
67048
+ return y0 + (y1 - y0) * (l2 - x0) / (x1 - x0);
67049
+ };
67050
+ function outlookClassicColor(value) {
67051
+ const c2 = parseColor(value);
67052
+ if (!c2 || c2.a === 0) return null;
67053
+ const linear = [c2.r, c2.g, c2.b].map((v) => {
67054
+ const s2 = v / 255;
67055
+ return s2 <= 0.04045 ? s2 / 12.92 : ((s2 + 0.055) / 1.055) ** 2.4;
67056
+ });
67057
+ const y3 = 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2];
67058
+ const l2 = 116 * labF(y3) - 16;
67059
+ const out = labFInv((wordDarkL(l2) + 16) / 116);
67060
+ const k2 = y3 > 0 ? Math.sqrt(out / y3) : 1;
67061
+ const [r2, g3, b2] = linear.map((v) => {
67062
+ const t2 = Math.min(1, Math.max(0, out + k2 * (v - y3)));
67063
+ return Math.round(255 * (t2 <= 31308e-7 ? 12.92 * t2 : 1.055 * t2 ** (1 / 2.4) - 0.055));
67064
+ });
67065
+ return hex({ r: r2, g: g3, b: b2 });
67066
+ }
66758
67067
  function gmailAndroidColor(value, role) {
66759
67068
  const parsed = parseColor(value);
66760
67069
  if (!parsed || parsed.a === 0) return null;
@@ -66767,6 +67076,7 @@ function invertColor(value, mode, clientId, role = "bg") {
66767
67076
  var _a22;
66768
67077
  if (mode === "gmail-android") return gmailAndroidColor(value, role);
66769
67078
  if (mode === "outlook-macos") return outlookMacColor(value, role);
67079
+ if (mode === "outlook-classic") return outlookClassicColor(value);
66770
67080
  const pinned = clientId && ((_a22 = SAMPLED_DARK[clientId]) == null ? void 0 : _a22[value.trim().replace("#", "").toLowerCase()]);
66771
67081
  if (pinned) return pinned;
66772
67082
  const parsed = parseColor(value);
@@ -66808,12 +67118,25 @@ function extractBackgroundColor(value) {
66808
67118
  }
66809
67119
  return null;
66810
67120
  }
67121
+ var BORDER_SHORTHAND = /^border(-(top|right|bottom|left))?$/;
67122
+ function invertBorder(value, mode, clientId) {
67123
+ let changed = false;
67124
+ const next2 = value.replace(/#[0-9a-f]{3,8}(?![0-9a-z])|rgba?\([^)]*\)/gi, (token) => {
67125
+ const inverted = invertColor(token, mode, clientId);
67126
+ if (!inverted) return token;
67127
+ changed = true;
67128
+ return inverted;
67129
+ });
67130
+ return changed ? next2 : null;
67131
+ }
66811
67132
  function applyColorInversion($3, mode, clientId) {
66812
67133
  $3("[style]").each((_3, el2) => {
66813
67134
  const style = $3(el2).attr("style") || "";
66814
67135
  const props = parseInlineStyle(style);
66815
67136
  let changed = false;
67137
+ const keepFill = mode === "outlook-classic" && $3(el2).is("[data-vml]");
66816
67138
  props.forEach((value, prop2) => {
67139
+ if (keepFill && prop2 !== "color") return;
66817
67140
  if (COLOR_PROPS.has(prop2)) {
66818
67141
  const inverted = invertColor(value, mode, clientId, prop2 === "color" ? "fg" : "bg");
66819
67142
  if (inverted) {
@@ -66821,6 +67144,13 @@ function applyColorInversion($3, mode, clientId) {
66821
67144
  changed = true;
66822
67145
  }
66823
67146
  }
67147
+ if (BORDER_SHORTHAND.test(prop2)) {
67148
+ const inverted = invertBorder(value, mode, clientId);
67149
+ if (inverted) {
67150
+ props.set(prop2, inverted);
67151
+ changed = true;
67152
+ }
67153
+ }
66824
67154
  if (prop2 === "background") {
66825
67155
  const bgColor = extractBackgroundColor(value);
66826
67156
  if (bgColor) {
@@ -66845,9 +67175,16 @@ function applyColorInversion($3, mode, clientId) {
66845
67175
  enter(node) {
66846
67176
  if (node.type !== "Declaration") return;
66847
67177
  const prop2 = node.property.toLowerCase();
66848
- if (!COLOR_PROPS.has(prop2) && prop2 !== "background") return;
67178
+ const border = BORDER_SHORTHAND.test(prop2);
67179
+ if (!COLOR_PROPS.has(prop2) && prop2 !== "background" && !border) return;
66849
67180
  const valueStr = hy(node.value);
66850
- if (prop2 === "background") {
67181
+ if (border) {
67182
+ const inverted = invertBorder(valueStr, mode, clientId);
67183
+ if (inverted) {
67184
+ node.value = py(inverted, { context: "value" });
67185
+ modified = true;
67186
+ }
67187
+ } else if (prop2 === "background") {
66851
67188
  const bgColor = extractBackgroundColor(valueStr);
66852
67189
  if (bgColor) {
66853
67190
  const inverted = invertColor(bgColor, mode, clientId);
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ import {
32
32
  simulateDarkMode,
33
33
  toFramework,
34
34
  transformForAllClients
35
- } from "./chunk-3TDW4LHR.js";
35
+ } from "./chunk-MVU52ONA.js";
36
36
  import "./chunk-ABDTBRVK.js";
37
37
  import "./chunk-2AP7CT6R.js";
38
38
  import "./chunk-NXBRJX3V.js";
@@ -33468,27 +33468,28 @@ h1 {
33468
33468
  out = out.replace(
33469
33469
  /<v:roundrect([^>]*)>([\s\S]*?)<\/v:roundrect>/gi,
33470
33470
  (_m, rawAttrs, inner) => {
33471
- var _a2, _b, _c, _d, _e, _f, _g, _h;
33471
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
33472
33472
  const a = attrs(rawAttrs);
33473
33473
  const s = styleProps((_a2 = a.style) != null ? _a2 : "");
33474
- const w = (_b = px(s.width)) != null ? _b : 0;
33475
- const h = (_c = px(s.height)) != null ? _c : 0;
33476
- const radius = arcsizeToRadius((_d = a.arcsize) != null ? _d : "20%", w, h);
33474
+ const auto = /^auto$/i.test((_c = (_b = s.width) == null ? void 0 : _b.trim()) != null ? _c : "");
33475
+ const w = auto ? 64 : (_d = px(s.width)) != null ? _d : 0;
33476
+ const h = (_e = px(s.height)) != null ? _e : 0;
33477
+ const radius = arcsizeToRadius((_f = a.arcsize) != null ? _f : "20%", w, h);
33477
33478
  const fillTag = inner.match(/<v:fill([^>]*?)\/?>/i);
33478
33479
  const f = fillTag ? attrs(fillTag[1]) : {};
33479
33480
  const imageData = inner.match(/<v:imagedata([^>]*?)\/?>/i);
33480
33481
  const imageSrc = imageData ? attrs(imageData[1]).src : void 0;
33481
- const fill = (_f = (_e = f.color) != null ? _e : a.fillcolor) != null ? _f : "transparent";
33482
+ const fill = (_h = (_g = f.color) != null ? _g : a.fillcolor) != null ? _h : "transparent";
33482
33483
  const image = imageSrc ? `;background-image:url('${imageSrc}');background-size:100% 100%;background-repeat:no-repeat` : "";
33483
33484
  const stroked = !(a.stroke === "f" || a.stroke === "false");
33484
- const middle = /middle/i.test((_g = s["v-text-anchor"]) != null ? _g : "");
33485
- const label = inner.replace(/<v:fill[^>]*?\/?>(?:\s*<\/v:fill>)?/gi, "").replace(/<v:imagedata[^>]*?\/?>(?:\s*<\/v:imagedata>)?/gi, "").replace(/<\/?w:anchorlock[^>]*>/gi, "").replace(/<center\b/gi, "<span").replace(/<\/center>/gi, "</span>").trim();
33485
+ const middle = /middle/i.test((_i = s["v-text-anchor"]) != null ? _i : "");
33486
+ const label = inner.replace(/<v:fill[^>]*?\/?>(?:\s*<\/v:fill>)?/gi, "").replace(/<v:imagedata[^>]*?\/?>(?:\s*<\/v:imagedata>)?/gi, "").replace(/<\/?w:anchorlock[^>]*>/gi, "").replace(/<center\b/gi, "<span").replace(/<\/center>/gi, "</span>").trim().replace(/^<span(?: style="([^"]*)")?/i, (tag, style) => auto ? `<span style="display:block;max-height:1lh;overflow:hidden;padding:0 9.6px;${style != null ? style : ""}"` : tag);
33486
33487
  const box = [
33487
33488
  w ? `width:${w}px` : "",
33488
33489
  h ? `height:${h}px` : "",
33489
33490
  `border-radius:${radius}px`,
33490
33491
  `background:${fill}${image}`,
33491
- stroked ? `border:1px solid ${(_h = a.strokecolor) != null ? _h : "#000"}` : "border:none",
33492
+ stroked ? `border:1px solid ${(_j = a.strokecolor) != null ? _j : "#000"}` : "border:none",
33492
33493
  "display:inline-flex",
33493
33494
  "justify-content:center",
33494
33495
  `align-items:${middle ? "center" : "flex-start"}`,
@@ -33648,6 +33649,17 @@ h1 {
33648
33649
  if (!/<!--\[if/i.test(html)) return html;
33649
33650
  return vmlToCss(resolveMsoBranch(html));
33650
33651
  }
33652
+ var LINK_LINE_BLOCKS = /* @__PURE__ */ new Set(["div", "p", "table", "ul", "ol", "h1", "h2", "h3", "h4", "h5", "h6", "center", "blockquote", "hr"]);
33653
+ var INLINE_TAGS = /* @__PURE__ */ new Set(["span", "a", "b", "strong", "i", "em", "u", "font", "small", "big", "sub", "sup"]);
33654
+ var WORD_PARSED = /^(?:mso-.*|font(?:-(?:family|size|weight|style|variant))?|color|background(?:-color)?|line-height|letter-spacing|white-space|word-wrap|text-(?:align|decoration|transform|indent|shadow)|vertical-align|direction|unicode-bidi|width|height|(?:margin|padding)(?:-(?:top|right|bottom|left))?|border(?:-(?:top|right|bottom|left))?(?:-(?:color|style|width))?)$/;
33655
+ var WORD_PARSED_VALUES = { "word-break": /^normal$/i, display: /^(?:inline|none)$/i };
33656
+ function wordParsesAll(props) {
33657
+ for (const [name, value] of props) {
33658
+ const values = WORD_PARSED_VALUES[name];
33659
+ if (values ? !values.test(value.replace(/\s*!important$/i, "").trim()) : !WORD_PARSED.test(name)) return false;
33660
+ }
33661
+ return true;
33662
+ }
33651
33663
  var PADDING = ["padding", "padding-top", "padding-right", "padding-bottom", "padding-left"];
33652
33664
  var MARGIN = ["margin", "margin-top", "margin-right", "margin-bottom", "margin-left"];
33653
33665
  var BORDER_WIDTH = [
@@ -33663,6 +33675,16 @@ h1 {
33663
33675
  "border-left-width"
33664
33676
  ];
33665
33677
  var NATURAL_LINE = 1.15;
33678
+ var GILL_VDMX = [14, 14, 15, 16, 18, 18, 21, 21, 23, 25, 27, 27, 29, 30, 31];
33679
+ var isGill = (family = "") => /^\s*['"]?gill sans/i.test(family);
33680
+ var FACE_LINE = [[/^\s*['"]?arial black\b/i, 1.41]];
33681
+ var naturalHeight = (size, family = "") => {
33682
+ var _a2, _b;
33683
+ if (!isGill(family)) return Math.round(size * ((_b = (_a2 = FACE_LINE.find(([face]) => face.test(family))) == null ? void 0 : _a2[1]) != null ? _b : NATURAL_LINE));
33684
+ const ppem = Math.round(size);
33685
+ return ppem <= 22 ? GILL_VDMX[Math.max(ppem, 8) - 8] : Math.ceil(0.9292 * size) + Math.ceil(0.2305 * size);
33686
+ };
33687
+ var GILL_LARGE = "'Gill Sans MT Large'";
33666
33688
  var TABLE_GUTTER = 3.5;
33667
33689
  var INVISIBLE_ONLY = /^[\s\u00a0\u00ad\u034f\u200b-\u200d\u2007\ufeff]+$/;
33668
33690
  var LIST_TRAILING_PX = 18;
@@ -33823,8 +33845,33 @@ h1 {
33823
33845
  );
33824
33846
  }
33825
33847
  function prepareWordSource(html) {
33826
- return markHiddenCells(dropWordUnknownColors(html));
33848
+ return markUnparsedInlines(wordSubstitutes(markHiddenCells(dropWordUnknownColors(html))));
33827
33849
  }
33850
+ var UNPARSED_MARK = "data-word-unparsed";
33851
+ var INLINE_STYLE = new RegExp(String.raw`<(${[...INLINE_TAGS].join("|")})(?=\s)(?=[^>]*?\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)'))`, "gi");
33852
+ var markUnparsedInlines = (html) => html.replace(INLINE_STYLE, (open, _tag, dq, sq) => {
33853
+ var _a2;
33854
+ return wordParsesAll(parseInlineStyle((_a2 = dq != null ? dq : sq) != null ? _a2 : "")) ? open : `${open} ${UNPARSED_MARK}`;
33855
+ });
33856
+ var WORD_SUBSTITUTES = { rubik: "Calibri" };
33857
+ var SUBSTITUTED = new RegExp(String.raw`(font(?:-family)?\s*:[^;"}]*?)(['"]?)\b(${Object.keys(WORD_SUBSTITUTES).join("|")})\b\2`, "gi");
33858
+ var wordSubstitutes = (html) => html.replace(SUBSTITUTED, (_, lead, _q, name) => `${lead}${WORD_SUBSTITUTES[name.toLowerCase()]}`);
33859
+ var OFFICE_CLOUD_FONTS = [
33860
+ "Work Sans",
33861
+ "Lato",
33862
+ "Montserrat",
33863
+ "Nunito",
33864
+ "Nunito Sans",
33865
+ "Open Sans",
33866
+ "DM Sans",
33867
+ "IBM Plex Sans",
33868
+ "Ubuntu",
33869
+ "Source Code Pro",
33870
+ "Raleway",
33871
+ "Playfair Display",
33872
+ "Poppins"
33873
+ ];
33874
+ var CLOUD = new Set(OFFICE_CLOUD_FONTS.map((f) => f.toLowerCase()));
33828
33875
  function declaredFaces($) {
33829
33876
  const faces = /* @__PURE__ */ new Map();
33830
33877
  $("style").each((_, block) => {
@@ -33834,7 +33881,7 @@ h1 {
33834
33881
  const family = props.get("font-family");
33835
33882
  const named = ((_b = props.get("mso-font-alt")) == null ? void 0 : _b.replace(/["']/g, "").trim()) || null;
33836
33883
  const alt = named && /^sans-serif$/i.test(named) ? WORD_DEFAULT : named;
33837
- if (family) faces.set(firstFamily(family), (_c = alt != null ? alt : faces.get(firstFamily(family))) != null ? _c : null);
33884
+ if (family && !CLOUD.has(firstFamily(family))) faces.set(firstFamily(family), (_c = alt != null ? alt : faces.get(firstFamily(family))) != null ? _c : null);
33838
33885
  }
33839
33886
  });
33840
33887
  return faces;
@@ -33866,8 +33913,36 @@ h1 {
33866
33913
  const value = parts.length === 4 ? parts[3] : parts.length >= 2 ? parts[1] : parts[0];
33867
33914
  return /^\d+(?:\.\d+)?(?:px)?$/.test(value != null ? value : "") ? parseFloat(value) : 0;
33868
33915
  }
33916
+ var SPACING = /^(?:line-height|mso-line-height-rule|mso-line-height-alt|font-size|font|font-family|background|background-color)$/;
33917
+ function sheetSpacing($) {
33918
+ const found = /* @__PURE__ */ new Map();
33919
+ $("style").each((_, block) => {
33920
+ var _a2, _b;
33921
+ for (const { selector, body } of topLevelRules((_a2 = $(block).html()) != null ? _a2 : "")) {
33922
+ const rule = [...parseInlineStyle(body.replace(/!important/gi, ""))].filter(([k]) => SPACING.test(k));
33923
+ if (!rule.length) continue;
33924
+ for (const one of selector.split(",")) {
33925
+ for (const el of matchedByWord($, one)) {
33926
+ const has = (_b = found.get(el)) != null ? _b : /* @__PURE__ */ new Map();
33927
+ for (const [k, v] of rule) has.set(k, v);
33928
+ found.set(el, has);
33929
+ }
33930
+ }
33931
+ }
33932
+ });
33933
+ return found;
33934
+ }
33869
33935
  function applyWordBoxModel($) {
33870
33936
  const faces = declaredFaces($);
33937
+ const sheet = sheetSpacing($);
33938
+ const spacingOf = (el) => {
33939
+ var _a2, _b;
33940
+ const all = new Map([...(_a2 = sheet.get(el)) != null ? _a2 : [], ...parseInlineStyle($(el).attr("style") || "")]);
33941
+ const alt = (_b = all.get("mso-line-height-alt")) == null ? void 0 : _b.trim();
33942
+ const altEm = /^([\d.]+)em$/i.exec(alt != null ? alt : "");
33943
+ if (alt) all.set("line-height", altEm ? `${Number(altEm[1]) * 16}px` : alt);
33944
+ return all;
33945
+ };
33871
33946
  $("[style]").each((_, node) => {
33872
33947
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
33873
33948
  const el = node;
@@ -33927,7 +34002,7 @@ h1 {
33927
34002
  const lineHeight = /^([\d.]+)px$/i.exec((_k = props.get("line-height")) != null ? _k : "");
33928
34003
  const fontSize = /^([\d.]+)px$/i.exec((_l = props.get("font-size")) != null ? _l : "");
33929
34004
  if (lineHeight && fontSize && !/exactly/i.test((_m = props.get("mso-line-height-rule")) != null ? _m : "")) {
33930
- const natural = Math.round(Number(fontSize[1]) * NATURAL_LINE);
34005
+ const natural = naturalHeight(Number(fontSize[1]), props.get("font-family"));
33931
34006
  if (Number(lineHeight[1]) < natural) props.set("line-height", `${natural}px`);
33932
34007
  }
33933
34008
  for (const prop of ["word-spacing", "outline", "outline-width", "outline-style", "outline-color", "outline-offset"]) {
@@ -33965,6 +34040,18 @@ h1 {
33965
34040
  props.set("line-height", "0");
33966
34041
  cell.empty().attr("style", serializeStyle(props));
33967
34042
  });
34043
+ $("p").each((_, node) => {
34044
+ if (!$(node).children().length && !/[^ \t\r\n]/.test($(node).text())) $(node).remove();
34045
+ });
34046
+ $("img").each((_, node) => {
34047
+ var _a2, _b;
34048
+ const img = $(node);
34049
+ const props = parseInlineStyle(img.attr("style") || "");
34050
+ const height = Number.parseFloat((_b = (_a2 = props.get("height")) != null ? _a2 : img.attr("height")) != null ? _b : "");
34051
+ if (img.closest("td, th").length || !(height <= 1)) return;
34052
+ props.set("display", "block");
34053
+ img.attr("style", serializeStyle(props));
34054
+ });
33968
34055
  $("hr").each((_, node) => {
33969
34056
  var _a2, _b, _c;
33970
34057
  const props = parseInlineStyle($(node).attr("style") || "");
@@ -33979,9 +34066,18 @@ h1 {
33979
34066
  ]);
33980
34067
  $(node).attr("style", serializeStyle(set));
33981
34068
  });
34069
+ const blank = (n) => n.type === "comment" || n.type === "text" && !n.data.trim();
33982
34070
  $("a").each((_, node) => {
33983
- if (!$(node).children("div").length) return;
33984
- $(node).before('<div style="height:21px"></div>').after('<div style="height:20px"></div>');
34071
+ if (!$(node).children("div, p").length) return;
34072
+ let before = node.prev;
34073
+ while (before && blank(before)) before = before.prev;
34074
+ let after = node.next;
34075
+ while (after && blank(after)) after = after.next;
34076
+ const parent = node.parent;
34077
+ const endsCell = !after && (parent == null ? void 0 : parent.type) === "tag" && /^t[dh]$/.test(parent.name);
34078
+ if (!before || before.type === "tag" && LINK_LINE_BLOCKS.has(before.name))
34079
+ $(node).before('<div style="height:21px"></div>');
34080
+ if (!endsCell) $(node).after('<div style="height:20px"></div>');
33985
34081
  });
33986
34082
  $("a[style*='text-decoration-line']").each((_, node) => {
33987
34083
  const props = parseInlineStyle($(node).attr("style") || "");
@@ -34038,6 +34134,7 @@ h1 {
34038
34134
  if (text.length > 20 && INVISIBLE_ONLY.test(text)) el.text(String.fromCharCode(160));
34039
34135
  });
34040
34136
  $("ul,ol").each((_, node) => {
34137
+ var _a2;
34041
34138
  const el = node;
34042
34139
  const props = parseInlineStyle($(el).attr("style") || "");
34043
34140
  let previous = el.prev;
@@ -34047,11 +34144,27 @@ h1 {
34047
34144
  const style = parseInlineStyle($(item).attr("style") || "");
34048
34145
  return style.has("margin") || style.has("margin-top") || style.has("margin-bottom");
34049
34146
  });
34050
- props.set("margin-top", afterBreak || previous && !tight ? "1lh!important" : "0!important");
34147
+ const nested = ((_a2 = el.parent) == null ? void 0 : _a2.type) === "tag" && el.parent.name === "li";
34148
+ props.set("margin-top", afterBreak || previous && !tight && !nested ? "1lh!important" : "0!important");
34051
34149
  props.set("margin-bottom", tight ? "0!important" : `${LIST_TRAILING_PX}px!important`);
34052
34150
  props.set("padding-left", `${LIST_TEXT_INDENT_PX}px!important`);
34053
34151
  $(el).attr("style", serializeStyle(props));
34054
34152
  });
34153
+ $("br").each((_, node) => {
34154
+ let at = node;
34155
+ let unparsed = false;
34156
+ for (; ; ) {
34157
+ for (let next = at.next; next; next = next.next) {
34158
+ if (next.type !== "text" || !/^[ \t\r\n]*$/.test(next.data)) return;
34159
+ }
34160
+ const parent = at.parent;
34161
+ if ((parent == null ? void 0 : parent.type) !== "tag" || !INLINE_TAGS.has(parent.name)) break;
34162
+ if ($(parent).attr(UNPARSED_MARK) !== void 0) unparsed = true;
34163
+ at = parent;
34164
+ }
34165
+ if (unparsed) $(node).after("<br>");
34166
+ });
34167
+ $(`[${UNPARSED_MARK}]`).removeAttr(UNPARSED_MARK);
34055
34168
  $("picture source").remove();
34056
34169
  $("table").each((_, node) => {
34057
34170
  var _a2, _b, _c;
@@ -34087,37 +34200,91 @@ h1 {
34087
34200
  })) return;
34088
34201
  cell.attr("style", `${style}${style.trim() === "" || /;\s*$/.test(style) ? "" : ";"}text-align:left`);
34089
34202
  });
34203
+ const sheetMargins = /* @__PURE__ */ new Map();
34204
+ $("style").each((_, block) => {
34205
+ var _a2, _b;
34206
+ for (const { selector, body } of topLevelRules((_a2 = $(block).html()) != null ? _a2 : "")) {
34207
+ if (!/margin/i.test(body)) continue;
34208
+ let cells = [];
34209
+ try {
34210
+ cells = $(selector).filter("td, th").toArray();
34211
+ } catch (e) {
34212
+ continue;
34213
+ }
34214
+ const rule = parseInlineStyle(body.replace(/!important/gi, ""));
34215
+ for (const cell of cells) {
34216
+ const has = (_b = sheetMargins.get(cell)) != null ? _b : /* @__PURE__ */ new Map();
34217
+ for (const [k, v] of rule) if (/^margin(?:-top|-bottom)?$/.test(k)) has.set(k, v);
34218
+ sheetMargins.set(cell, has);
34219
+ }
34220
+ }
34221
+ });
34222
+ const verticalMargins = (props) => {
34223
+ var _a2, _b, _c, _d;
34224
+ const box = ((_a2 = props.get("margin")) != null ? _a2 : "").trim().split(/\s+/).filter(Boolean);
34225
+ const read = (v) => v === void 0 ? void 0 : Number.parseFloat(v) || 0;
34226
+ return { top: read((_b = props.get("margin-top")) != null ? _b : box[0]), bottom: read((_d = (_c = props.get("margin-bottom")) != null ? _c : box[2]) != null ? _d : box[0]) };
34227
+ };
34228
+ const holdsBareText = (cell) => {
34229
+ const inline = $(cell).clone();
34230
+ inline.find("table, div, p, ul, ol, h1, h2, h3, h4, h5, h6").remove();
34231
+ return /[^\s ]/.test(inline.text());
34232
+ };
34090
34233
  $("table").each((_, node) => {
34091
- var _a2, _b, _c, _d, _e, _f, _g, _h;
34234
+ var _a2, _b, _c, _d, _e;
34092
34235
  const table = $(node);
34093
34236
  const props = parseInlineStyle(table.attr("style") || "");
34094
34237
  const box = ((_a2 = props.get("margin")) != null ? _a2 : "").trim().split(/\s+/).filter(Boolean);
34095
- const top = Number.parseFloat((_c = (_b = props.get("margin-top")) != null ? _b : box[0]) != null ? _c : "") || 0;
34096
- const bottom = Number.parseFloat((_f = (_e = (_d = props.get("margin-bottom")) != null ? _d : box[2]) != null ? _e : box[0]) != null ? _f : "") || 0;
34097
- if (top <= 0 && bottom <= 0 || /center/i.test((_g = table.attr("align")) != null ? _g : "")) return;
34098
- const rows = table.find("> tr, > tbody > tr");
34099
- const grow = (row, side, by) => {
34100
- row.children("td, th").each((_2, cell) => {
34101
- var _a3, _b2, _c2, _d2;
34102
- const own = parseInlineStyle($(cell).attr("style") || "");
34103
- const pad = ((_a3 = own.get("padding")) != null ? _a3 : "").trim().split(/\s+/).filter(Boolean);
34104
- const was = Number.parseFloat((_d2 = (_c2 = own.get(`padding-${side}`)) != null ? _c2 : side === "top" ? pad[0] : (_b2 = pad[2]) != null ? _b2 : pad[0]) != null ? _d2 : "") || 0;
34105
- own.set(`padding-${side}`, `${was + by}px`);
34106
- $(cell).attr("style", serializeStyle(own));
34107
- });
34108
- };
34109
- if (!rows.length) return;
34110
- if (top > 0) grow(rows.first(), "top", top);
34111
- if (bottom > 0) grow(rows.last(), "bottom", bottom);
34238
+ const centred = /center/i.test((_b = table.attr("align")) != null ? _b : "");
34239
+ const margins = verticalMargins(props);
34240
+ const top = centred ? 0 : (_c = margins.top) != null ? _c : 0;
34241
+ const bottom = centred ? 0 : (_d = margins.bottom) != null ? _d : 0;
34242
+ table.find("> tr, > tbody > tr").each((_2, row) => {
34243
+ var _a3, _b2, _c2, _d2, _e2, _f, _g;
34244
+ const cells = $(row).children("td, th").toArray();
34245
+ const bare = cells.filter(holdsBareText);
34246
+ if (!bare.length) return;
34247
+ for (const cell of cells) {
34248
+ const mine = bare.includes(cell) ? verticalMargins(new Map([...(_a3 = sheetMargins.get(cell)) != null ? _a3 : [], ...parseInlineStyle($(cell).attr("style") || "")])) : { top: void 0, bottom: void 0 };
34249
+ const style = parseInlineStyle($(cell).attr("style") || "");
34250
+ const pad = ((_b2 = style.get("padding")) != null ? _b2 : "").trim().split(/\s+/).filter(Boolean);
34251
+ for (const [side, by] of [["top", (_c2 = mine.top) != null ? _c2 : top], ["bottom", (_d2 = mine.bottom) != null ? _d2 : bottom]]) {
34252
+ if (by <= 0) continue;
34253
+ const was = Number.parseFloat((_g = (_f = style.get(`padding-${side}`)) != null ? _f : side === "top" ? pad[0] : (_e2 = pad[2]) != null ? _e2 : pad[0]) != null ? _g : "") || 0;
34254
+ style.set(`padding-${side}`, `${was + by}px`);
34255
+ }
34256
+ $(cell).attr("style", serializeStyle(style));
34257
+ }
34258
+ });
34259
+ if (top <= 0 && bottom <= 0 || centred) return;
34112
34260
  props.delete("margin-top");
34113
34261
  props.delete("margin-bottom");
34114
34262
  if (box.length) {
34115
34263
  props.delete("margin");
34116
- if (box[1]) props.set("margin-left", (_h = box[3]) != null ? _h : box[1]);
34264
+ if (box[1]) props.set("margin-left", (_e = box[3]) != null ? _e : box[1]);
34117
34265
  if (box[1]) props.set("margin-right", box[1]);
34118
34266
  }
34119
34267
  table.attr("style", serializeStyle(props));
34120
34268
  });
34269
+ $("tr").each((_, row) => {
34270
+ const cells = $(row).children("td, th").toArray();
34271
+ if (cells.length < 2) return;
34272
+ const sides = cells.map((cell) => {
34273
+ var _a2, _b, _c, _d;
34274
+ const style = parseInlineStyle($(cell).attr("style") || "");
34275
+ const pad = ((_a2 = style.get("padding")) != null ? _a2 : "").trim().split(/\s+/).filter(Boolean);
34276
+ const read = (v) => Number.parseFloat(v != null ? v : "") || 0;
34277
+ return { style, top: read((_b = style.get("padding-top")) != null ? _b : pad[0]), bottom: read((_d = (_c = style.get("padding-bottom")) != null ? _c : pad[2]) != null ? _d : pad[0]) };
34278
+ });
34279
+ const top = Math.max(...sides.map((s) => s.top));
34280
+ const bottom = Math.max(...sides.map((s) => s.bottom));
34281
+ cells.forEach((cell, i) => {
34282
+ const { style } = sides[i];
34283
+ if (sides[i].top < top) style.set("padding-top", `${top}px`);
34284
+ if (sides[i].bottom < bottom) style.set("padding-bottom", `${bottom}px`);
34285
+ if (sides[i].top < top || sides[i].bottom < bottom) $(cell).attr("style", serializeStyle(style));
34286
+ });
34287
+ });
34121
34288
  $("table").each((_, node) => {
34122
34289
  var _a2, _b;
34123
34290
  const props = parseInlineStyle($(node).attr("style") || "");
@@ -34174,10 +34341,103 @@ h1 {
34174
34341
  const after = serializeStyle(props);
34175
34342
  if (after) p.attr("style", after);
34176
34343
  });
34177
- const reset = "<style>h2{margin:0}p{margin:14pt 0}</style>";
34344
+ $("span, a, strong, b, em, i, u, font").each((_, node) => {
34345
+ var _a2, _b, _c;
34346
+ const el = node;
34347
+ const props = parseInlineStyle($(el).attr("style") || "");
34348
+ if (/block/i.test((_a2 = props.get("display")) != null ? _a2 : "")) return;
34349
+ const spacing = $(el).parents().toArray().map(spacingOf).find((st) => st.has("line-height"));
34350
+ if (!/^[\d.]+px$/i.test((_b = spacing == null ? void 0 : spacing.get("line-height")) != null ? _b : "") || /exactly/i.test((_c = spacing == null ? void 0 : spacing.get("mso-line-height-rule")) != null ? _c : "")) return;
34351
+ props.set("line-height", "normal");
34352
+ $(el).attr("style", serializeStyle(props));
34353
+ });
34354
+ $("p, div, td, th, li, h1, h2, h3, h4, h5, h6").each((_, node) => {
34355
+ var _a2;
34356
+ const el = node;
34357
+ const kids = $(el).contents().toArray().filter((n) => !(n.type === "comment" || n.type === "text" && !/[^\s]/.test(n.data)));
34358
+ if (!kids.length || !kids.every((n) => n.type === "tag" && INLINE_TAGS.has(n.name))) return;
34359
+ if ($(el).find("img, table, svg, a, [style*='display']").length) return;
34360
+ const spacing = [el, ...$(el).parents().toArray()].map(spacingOf).find((st) => st.has("line-height"));
34361
+ const line = ((_a2 = spacing == null ? void 0 : spacing.get("line-height")) != null ? _a2 : "normal").replace(/\s*!important$/i, "").trim();
34362
+ if (!(line === "normal" || /^\d*\.\d+$/.test(line) && Number(line) >= 1)) return;
34363
+ const own = parseInlineStyle($(el).attr("style") || "");
34364
+ own.set("line-height", "0");
34365
+ $(el).attr("style", serializeStyle(own));
34366
+ for (const kid of kids) {
34367
+ const props = parseInlineStyle($(kid).attr("style") || "");
34368
+ if (props.has("line-height")) continue;
34369
+ props.set("line-height", "normal");
34370
+ $(kid).attr("style", serializeStyle(props));
34371
+ }
34372
+ });
34373
+ const inherited2 = (el, prop) => [el, ...$(el).parents().toArray()].map(spacingOf).find((st) => st.has(prop));
34374
+ const sizeOf = (el) => {
34375
+ var _a2, _b, _c;
34376
+ const sized = [el, ...$(el).parents().toArray()].map(spacingOf).find((st) => {
34377
+ var _a3;
34378
+ return st.has("font-size") || /\d(?:\.\d+)?px/.test((_a3 = st.get("font")) != null ? _a3 : "");
34379
+ });
34380
+ const px2 = (_c = /^([\d.]+)px$/i.exec((_a2 = sized == null ? void 0 : sized.get("font-size")) != null ? _a2 : "")) != null ? _c : /(?:^|\s)([\d.]+)px/.exec((_b = sized == null ? void 0 : sized.get("font")) != null ? _b : "");
34381
+ return px2 ? Number(px2[1]) : void 0;
34382
+ };
34383
+ $("p, div, h1, h2, h3, h4, h5, h6, li, td, th").each((_, node) => {
34384
+ var _a2, _b, _c, _d;
34385
+ const el = node;
34386
+ const block = $(el);
34387
+ if (block.find("p, div, h1, h2, h3, h4, h5, h6, li, table, ul, ol").length || !/[^\s ]/.test(block.text())) return;
34388
+ const own = parseInlineStyle(block.attr("style") || "");
34389
+ if (hasBorder(own)) return;
34390
+ const mine = spacingOf(el);
34391
+ const spacing = inherited2(el, "line-height");
34392
+ const line = /^([\d.]+)px$/i.exec((_a2 = spacing == null ? void 0 : spacing.get("line-height")) != null ? _a2 : "");
34393
+ const size = sizeOf(el);
34394
+ if (!line || !size) return;
34395
+ let largest = size;
34396
+ block.find("*").each((_2, inner) => {
34397
+ var _a3;
34398
+ const px2 = /^([\d.]+)px$/i.exec((_a3 = spacingOf(inner).get("font-size")) != null ? _a3 : "");
34399
+ if (px2) largest = Math.max(largest, Number(px2[1]));
34400
+ });
34401
+ const exactly = /exactly/i.test((_b = spacing == null ? void 0 : spacing.get("mso-line-height-rule")) != null ? _b : "");
34402
+ const natural = naturalHeight(size, (_c = inherited2(el, "font-family")) == null ? void 0 : _c.get("font-family"));
34403
+ if (!exactly && largest === size && Number(line[1]) < natural) {
34404
+ own.set("line-height", `${natural}px`);
34405
+ block.attr("style", serializeStyle(own));
34406
+ return;
34407
+ }
34408
+ const leading = Math.round((Number(line[1]) - largest * NATURAL_LINE) * 10) / 10;
34409
+ const shift = Math.round(leading * (exactly ? 0.3 : 0.5) * 10) / 10;
34410
+ if (shift <= 0) return;
34411
+ block.wrapInner(
34412
+ exactly ? `<span style="position:relative;top:${shift}px"></span>` : `<span style="vertical-align:bottom;line-height:normal"></span>`
34413
+ );
34414
+ const tag = el.tagName.toLowerCase();
34415
+ const fill = (_d = mine.get("background-color")) != null ? _d : mine.get("background");
34416
+ if (exactly || tag === "td" || tag === "th" || !fill || /\(|\s/.test(fill.trim())) return;
34417
+ own.delete("background-color");
34418
+ own.set("background", `linear-gradient(transparent ${leading}px, ${fill.trim()} ${leading}px)`);
34419
+ block.attr("style", serializeStyle(own));
34420
+ });
34421
+ $("body *").each((_, node) => {
34422
+ var _a2, _b;
34423
+ const el = node;
34424
+ if (!$(el).contents().toArray().some((n) => n.type === "text" && /[^\s ]/.test(n.data))) return;
34425
+ const family = (_b = (_a2 = inherited2(el, "font-family")) == null ? void 0 : _a2.get("font-family")) != null ? _b : "";
34426
+ const size = sizeOf(el);
34427
+ if (!isGill(family) || size === void 0) return;
34428
+ const block = $(el).closest("p, div, li, td, th, h1, h2, h3, h4, h5, h6").get(0);
34429
+ const blockSize = block && block !== el ? sizeOf(block) : void 0;
34430
+ const large = family.trim().startsWith(GILL_LARGE);
34431
+ if (large === (size > 22 || blockSize !== void 0 && size > blockSize)) return;
34432
+ const props = parseInlineStyle($(el).attr("style") || "");
34433
+ const stack = family.replace(new RegExp(String.raw`^\s*${GILL_LARGE},\s*`), "");
34434
+ props.set("font-family", large ? stack : `${GILL_LARGE}, ${stack}`);
34435
+ $(el).attr("style", serializeStyle(props));
34436
+ });
34437
+ const reset = "<style>h2{margin:0}p{margin:14pt 0}td,th{box-sizing:border-box}</style>";
34178
34438
  const head = $("head");
34179
34439
  if (head.length) head.prepend(reset);
34180
- else if ($("p,h2").length) $.root().prepend(reset);
34440
+ else if ($("p,h2,td,th").length) $.root().prepend(reset);
34181
34441
  }
34182
34442
  var MAX_HTML_SIZE = 2 * 1024 * 1024;
34183
34443
  var MAX_WARNING_LOCATIONS = 100;
@@ -36704,7 +36964,7 @@ h1 {
36704
36964
  }
36705
36965
  break;
36706
36966
  case "outlook-windows-legacy":
36707
- applyColorInversion($, "full", clientId);
36967
+ applyColorInversion($, "outlook-classic", clientId);
36708
36968
  if (!html.includes("prefers-color-scheme")) {
36709
36969
  warnings.push({
36710
36970
  severity: "info",
@@ -36786,7 +37046,9 @@ h1 {
36786
37046
  return { html: $.html(), warnings };
36787
37047
  }
36788
37048
  var MEASURED_CANVAS = {
36789
- "outlook-macos": { bg: "#1e1e1e", fg: "#ffffff" }
37049
+ "outlook-macos": { bg: "#1e1e1e", fg: "#ffffff" },
37050
+ // ponytail: fg unmeasured; Word's automatic text is black, which maps here.
37051
+ "outlook-windows-legacy": { bg: "#262626", fg: "#f6f6f6" }
36790
37052
  };
36791
37053
  var SAMPLED_DARK = {
36792
37054
  "outlook-web": { eeeae4: "#595651" },
@@ -36843,6 +37105,53 @@ h1 {
36843
37105
  if (c.r === c.g && c.g === c.b) return withLabLightness(c, (l) => Math.min(l, 88.5 - 0.772 * l), D65);
36844
37106
  return withLabLightness(c, () => 34.6, D65);
36845
37107
  }
37108
+ var WORD_DARK_GREYS = [
37109
+ [0, 246],
37110
+ [15, 233],
37111
+ [30, 225],
37112
+ [45, 216],
37113
+ [60, 206],
37114
+ [75, 196],
37115
+ [90, 185],
37116
+ [105, 174],
37117
+ [120, 163],
37118
+ [135, 151],
37119
+ [150, 139],
37120
+ [165, 126],
37121
+ [180, 113],
37122
+ [195, 99],
37123
+ [210, 85],
37124
+ [225, 70],
37125
+ [240, 55],
37126
+ [255, 38]
37127
+ ];
37128
+ var greyL = (v) => {
37129
+ const s = v / 255;
37130
+ return 116 * labF(s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4) - 16;
37131
+ };
37132
+ var WORD_DARK_L = WORD_DARK_GREYS.map(([from, to]) => [greyL(from), greyL(to)]);
37133
+ var wordDarkL = (l) => {
37134
+ const i = Math.max(1, WORD_DARK_L.findIndex(([x]) => x >= Math.min(l, 100)));
37135
+ const [[x0, y0], [x1, y1]] = [WORD_DARK_L[i - 1], WORD_DARK_L[i]];
37136
+ return y0 + (y1 - y0) * (l - x0) / (x1 - x0);
37137
+ };
37138
+ function outlookClassicColor(value) {
37139
+ const c = parseColor(value);
37140
+ if (!c || c.a === 0) return null;
37141
+ const linear = [c.r, c.g, c.b].map((v) => {
37142
+ const s = v / 255;
37143
+ return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
37144
+ });
37145
+ const y = 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2];
37146
+ const l = 116 * labF(y) - 16;
37147
+ const out = labFInv((wordDarkL(l) + 16) / 116);
37148
+ const k = y > 0 ? Math.sqrt(out / y) : 1;
37149
+ const [r, g, b] = linear.map((v) => {
37150
+ const t = Math.min(1, Math.max(0, out + k * (v - y)));
37151
+ return Math.round(255 * (t <= 31308e-7 ? 12.92 * t : 1.055 * t ** (1 / 2.4) - 0.055));
37152
+ });
37153
+ return hex({ r, g, b });
37154
+ }
36846
37155
  function gmailAndroidColor(value, role) {
36847
37156
  const parsed = parseColor(value);
36848
37157
  if (!parsed || parsed.a === 0) return null;
@@ -36855,6 +37164,7 @@ h1 {
36855
37164
  var _a2;
36856
37165
  if (mode === "gmail-android") return gmailAndroidColor(value, role);
36857
37166
  if (mode === "outlook-macos") return outlookMacColor(value, role);
37167
+ if (mode === "outlook-classic") return outlookClassicColor(value);
36858
37168
  const pinned = clientId && ((_a2 = SAMPLED_DARK[clientId]) == null ? void 0 : _a2[value.trim().replace("#", "").toLowerCase()]);
36859
37169
  if (pinned) return pinned;
36860
37170
  const parsed = parseColor(value);
@@ -36896,12 +37206,25 @@ h1 {
36896
37206
  }
36897
37207
  return null;
36898
37208
  }
37209
+ var BORDER_SHORTHAND = /^border(-(top|right|bottom|left))?$/;
37210
+ function invertBorder(value, mode, clientId) {
37211
+ let changed = false;
37212
+ const next = value.replace(/#[0-9a-f]{3,8}(?![0-9a-z])|rgba?\([^)]*\)/gi, (token) => {
37213
+ const inverted = invertColor(token, mode, clientId);
37214
+ if (!inverted) return token;
37215
+ changed = true;
37216
+ return inverted;
37217
+ });
37218
+ return changed ? next : null;
37219
+ }
36899
37220
  function applyColorInversion($, mode, clientId) {
36900
37221
  $("[style]").each((_, el) => {
36901
37222
  const style = $(el).attr("style") || "";
36902
37223
  const props = parseInlineStyle(style);
36903
37224
  let changed = false;
37225
+ const keepFill = mode === "outlook-classic" && $(el).is("[data-vml]");
36904
37226
  props.forEach((value, prop) => {
37227
+ if (keepFill && prop !== "color") return;
36905
37228
  if (COLOR_PROPS.has(prop)) {
36906
37229
  const inverted = invertColor(value, mode, clientId, prop === "color" ? "fg" : "bg");
36907
37230
  if (inverted) {
@@ -36909,6 +37232,13 @@ h1 {
36909
37232
  changed = true;
36910
37233
  }
36911
37234
  }
37235
+ if (BORDER_SHORTHAND.test(prop)) {
37236
+ const inverted = invertBorder(value, mode, clientId);
37237
+ if (inverted) {
37238
+ props.set(prop, inverted);
37239
+ changed = true;
37240
+ }
37241
+ }
36912
37242
  if (prop === "background") {
36913
37243
  const bgColor = extractBackgroundColor(value);
36914
37244
  if (bgColor) {
@@ -36933,9 +37263,16 @@ h1 {
36933
37263
  enter(node) {
36934
37264
  if (node.type !== "Declaration") return;
36935
37265
  const prop = node.property.toLowerCase();
36936
- if (!COLOR_PROPS.has(prop) && prop !== "background") return;
37266
+ const border = BORDER_SHORTHAND.test(prop);
37267
+ if (!COLOR_PROPS.has(prop) && prop !== "background" && !border) return;
36937
37268
  const valueStr = csstree4.generate(node.value);
36938
- if (prop === "background") {
37269
+ if (border) {
37270
+ const inverted = invertBorder(valueStr, mode, clientId);
37271
+ if (inverted) {
37272
+ node.value = csstree4.parse(inverted, { context: "value" });
37273
+ modified = true;
37274
+ }
37275
+ } else if (prop === "background") {
36939
37276
  const bgColor = extractBackgroundColor(valueStr);
36940
37277
  if (bgColor) {
36941
37278
  const inverted = invertColor(bgColor, mode, clientId);
@@ -43085,7 +43422,7 @@ Href: ${href}`
43085
43422
  // package.json
43086
43423
  var package_default = {
43087
43424
  name: "@emailens/cli",
43088
- version: "0.13.12",
43425
+ version: "0.13.14",
43089
43426
  description: "CLI tool for email compatibility analysis: lint, preview and export HTML, MJML, Maizzle and React Email rendering across 21 email clients.",
43090
43427
  type: "module",
43091
43428
  bin: {
@@ -43126,7 +43463,7 @@ var package_default = {
43126
43463
  },
43127
43464
  devDependencies: {
43128
43465
  "@anthropic-ai/sdk": "^0.52.0",
43129
- "@emailens/engine": "^0.18.14",
43466
+ "@emailens/engine": "^0.18.16",
43130
43467
  "@types/bun": "^1.4.0",
43131
43468
  "@types/mjml": "^4.7.4",
43132
43469
  "@types/node": "^25.9.5",
package/dist/test.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  auditEmail,
6
6
  flattenToLintIssues,
7
7
  loadProjectConfig
8
- } from "./chunk-3TDW4LHR.js";
8
+ } from "./chunk-MVU52ONA.js";
9
9
  import "./chunk-ABDTBRVK.js";
10
10
  import "./chunk-2AP7CT6R.js";
11
11
  import "./chunk-NXBRJX3V.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emailens/cli",
3
- "version": "0.13.12",
3
+ "version": "0.13.14",
4
4
  "description": "CLI tool for email compatibility analysis: lint, preview and export HTML, MJML, Maizzle and React Email rendering across 21 email clients.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@anthropic-ai/sdk": "^0.52.0",
44
- "@emailens/engine": "^0.18.14",
44
+ "@emailens/engine": "^0.18.16",
45
45
  "@types/bun": "^1.4.0",
46
46
  "@types/mjml": "^4.7.4",
47
47
  "@types/node": "^25.9.5",