@templatical/import-stripo 0.54.2 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ const ZERO$3 = {
44
44
  bottom: 0,
45
45
  left: 0
46
46
  };
47
- /** Column shares of the body width. The third column takes the rounding remainder. */
47
+ /** Column shares of the body width. The third column of `"3"` takes the rounding remainder. */
48
48
  const COLUMN_SHARES = {
49
49
  "1": [100],
50
50
  "2": [50, 50],
@@ -52,6 +52,12 @@ const COLUMN_SHARES = {
52
52
  33.33,
53
53
  33.33,
54
54
  33.34
55
+ ],
56
+ "4": [
57
+ 25,
58
+ 25,
59
+ 25,
60
+ 25
55
61
  ]
56
62
  };
57
63
  const DIVIDER_WIDTH = /^(-?\d+(?:\.\d+)?)\s*(%|px)?$/i;
@@ -123,7 +129,7 @@ function parseColor(value) {
123
129
  }
124
130
  function parsePxValue(value) {
125
131
  if (!value) return 0;
126
- const match = value.trim().match(/^(-?\d+(?:\.\d+)?)\s*(?:px)?\s*$/);
132
+ const match = value.trim().match(/^(-?\d+(?:\.\d+)?)\s*(?:px)?$/);
127
133
  return match ? Math.round(parseFloat(match[1])) : 0;
128
134
  }
129
135
  /** Inline `background-color` / `background` wins over the `bgcolor` attribute. */
@@ -224,9 +230,27 @@ function readBoxPadding(classAttr, styleAttr) {
224
230
  /**
225
231
  * Body fill paints the section. A band that is neither the page nor the body
226
232
  * becomes the section wrapper. A transparent body leaves the band on the section.
233
+ *
234
+ * `bleed` is a stripe around a fixed-width body. The band is then a viewport
235
+ * wrapper, including when it matches the body, and a transparent body moves
236
+ * that single background off the section.
227
237
  */
228
- function resolveSectionPaint(pageBackground, band, body) {
238
+ function resolveSectionPaint(pageBackground, band, body, bleed = false) {
229
239
  const page = pageBackground || "#ffffff";
240
+ if (bleed && band && band !== page) {
241
+ if (body) return {
242
+ backgroundColor: body,
243
+ wrapperColor: band,
244
+ fullWidth: true,
245
+ notes: []
246
+ };
247
+ return {
248
+ backgroundColor: "",
249
+ wrapperColor: band,
250
+ fullWidth: true,
251
+ notes: []
252
+ };
253
+ }
230
254
  if (body) {
231
255
  if (band && band !== page && band !== body) return {
232
256
  backgroundColor: body,
@@ -243,6 +267,22 @@ function resolveSectionPaint(pageBackground, band, body) {
243
267
  notes: []
244
268
  };
245
269
  }
270
+ /**
271
+ * The section wrapper for a band colour and a stripe image. No paint, no
272
+ * wrapper. A stripe image is the viewport band even when the colour was
273
+ * approximated at the email width.
274
+ */
275
+ function sectionWrapper(paint, bandImage) {
276
+ if (!paint.wrapperColor && !bandImage) return void 0;
277
+ return {
278
+ ...paint.wrapperColor ? { backgroundColor: paint.wrapperColor } : {},
279
+ ...bandImage ? { backgroundImage: {
280
+ ...bandImage,
281
+ position: { ...bandImage.position }
282
+ } } : {},
283
+ ...paint.fullWidth || bandImage ? { fullWidth: true } : {}
284
+ };
285
+ }
246
286
  /** `es-*-body` width in px, or 600 when the document does not state one. */
247
287
  function emailBodyWidth(widthAttr, styleAttr) {
248
288
  const n = parsePxValue((widthAttr || parseStyleAttribute(styleAttr).width || "").trim());
@@ -705,11 +745,11 @@ function droppedColumnsNote(columns) {
705
745
  /**
706
746
  * The image a section paints, nearest first: the structure's own, then the
707
747
  * body's, then the containers', moved up when there is one or all share the
708
- * same image, then the stripe's while the body leaves it showing. An image
709
- * that showed in the section but can't be kept is named in a note. A body
710
- * image beneath the structure's own is covered in this section, so it isn't
711
- * named; it still paints the stripe's other sections. The image is a copy,
712
- * so sections that share a source don't share an object.
748
+ * same image. The stripe's image is the viewport band (`band`), never the
749
+ * section's. An image that showed in the section but can't be kept is named
750
+ * in a note. A body image beneath the structure's own is covered in this
751
+ * section, so it isn't named; it still paints the stripe's other sections.
752
+ * The image is a copy, so sections that share a source don't share an object.
713
753
  */
714
754
  function resolveSectionImage(layers) {
715
755
  const notes = [];
@@ -724,24 +764,32 @@ function resolveSectionImage(layers) {
724
764
  };
725
765
  else notes.push(droppedColumnsNote(withImage));
726
766
  }
767
+ let bandImage;
768
+ let bandSource = null;
727
769
  if (layers.band) {
728
- if (!picked && !layers.bodyPainted) {
729
- picked = layers.band;
730
- notes.push("The stripe's background image spans the full width in Stripo; the section paints it at the content width.");
731
- } else notes.push("The stripe's background image outside the content width was dropped.");
770
+ bandImage = {
771
+ ...layers.band.read.image,
772
+ position: { ...layers.band.read.image.position }
773
+ };
774
+ bandSource = layers.band.source;
775
+ notes.push(...layers.band.read.notes);
732
776
  }
733
777
  if (!picked) return {
734
778
  image: void 0,
779
+ ...bandImage ? { band: bandImage } : {},
735
780
  notes,
736
- source: null
781
+ source: null,
782
+ bandSource
737
783
  };
738
784
  return {
739
785
  image: {
740
786
  ...picked.read.image,
741
787
  position: { ...picked.read.image.position }
742
788
  },
789
+ ...bandImage ? { band: bandImage } : {},
743
790
  notes: [...picked.read.notes, ...notes],
744
- source: picked.source
791
+ source: picked.source,
792
+ bandSource
745
793
  };
746
794
  }
747
795
  /**
@@ -754,9 +802,40 @@ function withoutBandOverImage(paint, hasImage) {
754
802
  if (!hasImage || !paint.wrapperColor) return paint;
755
803
  return {
756
804
  backgroundColor: paint.backgroundColor,
757
- notes: [`The band colour ${paint.wrapperColor} was dropped: Outlook desktop paints a wrapper colour over the section's background image.`]
805
+ notes: [`The band colour ${paint.wrapperColor} was dropped: Outlook desktop paints a wrapper colour over the section's background image.`],
806
+ ...paint.fullWidth ? { fullWidth: true } : {}
758
807
  };
759
808
  }
809
+ // src/column-width.ts
810
+ /** Widths within 1px count as the same column width. */
811
+ const COLUMN_WIDTH_TOLERANCE = 1;
812
+ const EQUAL_COLUMN_WORD = {
813
+ "2": "two",
814
+ "3": "three",
815
+ "4": "four"
816
+ };
817
+ /**
818
+ * Positive px from an inline `width`, else from the `width` attribute.
819
+ * A non-px length is unread.
820
+ */
821
+ function statedPx(widthAttr, styleAttr) {
822
+ const inline = parsePxValue(parseStyleAttribute(styleAttr).width);
823
+ if (inline > 0) return inline;
824
+ const attribute = parsePxValue(widthAttr);
825
+ return attribute > 0 ? attribute : void 0;
826
+ }
827
+ /**
828
+ * A note when at least two readable widths differ by more than 1px.
829
+ * An unread width stays in its place as "an unstated width".
830
+ */
831
+ function unequalWidthNote(widths, layout) {
832
+ const readable = [];
833
+ for (const width of widths) if (width !== void 0) readable.push(width);
834
+ if (readable.length < 2) return void 0;
835
+ if (Math.max(...readable) - Math.min(...readable) <= COLUMN_WIDTH_TOLERANCE) return void 0;
836
+ const parts = widths.map((width) => width === void 0 ? "an unstated width" : `${width}px`);
837
+ return `Columns of ${`${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`} became ${EQUAL_COLUMN_WORD[layout]} equal columns.`;
838
+ }
760
839
  // src/fragment.ts
761
840
  /** Paint after `createSectionBlock` so `styles` keeps its required padding. */
762
841
  function withBackground(section, backgroundColor) {
@@ -863,6 +942,7 @@ const NAMED = {
863
942
  instagram: "instagram",
864
943
  inst: "instagram",
865
944
  linkedin: "linkedin",
945
+ xing: "xing",
866
946
  youtube: "youtube",
867
947
  yt: "youtube",
868
948
  tiktok: "tiktok",
@@ -882,22 +962,51 @@ function peel(raw) {
882
962
  return raw.toLowerCase().replace(/\.(png|jpe?g|gif|svg|webp)$/i, "").replace(/[^a-z0-9]+/g, " ").trim();
883
963
  }
884
964
  /**
885
- * Map a Stripo icon's title, alt, or src stem onto a SocialPlatform.
886
- * Unknown names become `website` — same floor as the MJML importer.
965
+ * The file name of an icon src. An absolute URL contributes its last path
966
+ * segment, so the host is not a name; an empty path has none. A relative or
967
+ * protocol-relative src resolves against a placeholder base for the same
968
+ * reason. The query and hash are not part of the name.
887
969
  */
888
- function normalizePlatform(name, src, alt) {
889
- for (const candidate of [
890
- name,
891
- alt,
892
- src
893
- ]) {
894
- if (!candidate) continue;
895
- const words = peel(candidate).split(/\s+/);
896
- for (const w of words) if (NAMED[w]) return NAMED[w];
897
- const stem = peel(candidate.split("/").pop() ?? "");
898
- for (const w of stem.split(/\s+/)) if (NAMED[w]) return NAMED[w];
970
+ function srcFileName(src) {
971
+ try {
972
+ return new URL(src, "https://placeholder.invalid").pathname.split("/").pop() || "";
973
+ } catch {
974
+ return "";
899
975
  }
900
- return "website";
976
+ }
977
+ /** A Stripo website icon is named website, web, or link. */
978
+ const WEBSITE_NAMES = /* @__PURE__ */ new Set([
979
+ "website",
980
+ "web",
981
+ "link"
982
+ ]);
983
+ function namedPlatform(candidate) {
984
+ if (!candidate) return void 0;
985
+ for (const w of peel(candidate).split(/\s+/)) {
986
+ const hit = NAMED[w];
987
+ if (hit) return hit;
988
+ }
989
+ }
990
+ function explicitWebsite(candidate) {
991
+ if (!candidate) return false;
992
+ for (const w of peel(candidate).split(/\s+/)) if (WEBSITE_NAMES.has(w)) return true;
993
+ return false;
994
+ }
995
+ /**
996
+ * The platform named by a Stripo icon's title, alt, or src file name.
997
+ * An explicit website, web, or link name is `website`. Undefined when none
998
+ * of those names a platform.
999
+ */
1000
+ function matchPlatform(name, src, alt) {
1001
+ for (const candidate of [name, alt]) {
1002
+ const hit = namedPlatform(candidate);
1003
+ if (hit) return hit;
1004
+ if (explicitWebsite(candidate)) return "website";
1005
+ }
1006
+ const file = src ? srcFileName(src) : "";
1007
+ const fromFile = namedPlatform(file);
1008
+ if (fromFile) return fromFile;
1009
+ if (explicitWebsite(file)) return "website";
901
1010
  }
902
1011
  // src/labelled.ts
903
1012
  const ZERO$2 = {
@@ -1096,20 +1205,26 @@ function menuFrom($el, $, sourceTag, ctx) {
1096
1205
  pushEntry(ctx, sourceTag, "menu", "converted");
1097
1206
  return createMenuBlock({ items });
1098
1207
  }
1208
+ function genericWebsiteNote(count) {
1209
+ return count === 1 ? "1 icon became a generic website icon." : `${count} icons became generic website icons.`;
1210
+ }
1099
1211
  function socialFrom($el, $, sourceTag, ctx) {
1100
1212
  const icons = [];
1213
+ let generic = 0;
1101
1214
  $el.find("a").each((_, a) => {
1102
1215
  const $a = $(a);
1103
1216
  const $img = $a.find("img").first();
1104
1217
  const url = $a.attr("href") ?? "#";
1105
- const platform = normalizePlatform($img.attr("title"), $img.attr("src"), $img.attr("alt"));
1218
+ const platform = matchPlatform($img.attr("title"), $img.attr("src"), $img.attr("alt"));
1219
+ if (!platform) generic += 1;
1106
1220
  icons.push({
1107
1221
  id: generateId(),
1108
- platform,
1222
+ platform: platform ?? "website",
1109
1223
  url
1110
1224
  });
1111
1225
  });
1112
- pushEntry(ctx, sourceTag, "social", "converted");
1226
+ const note = generic > 0 ? genericWebsiteNote(generic) : void 0;
1227
+ pushEntry(ctx, sourceTag, "social", note ? "approximated" : "converted", note);
1113
1228
  return createSocialIconsBlock({ icons });
1114
1229
  }
1115
1230
  function labelledInnerBlocks($el, $, ctx) {
@@ -1122,7 +1237,7 @@ const ZERO$1 = {
1122
1237
  bottom: 0,
1123
1238
  left: 0
1124
1239
  };
1125
- const COLUMN_TOKENS = ["es-left", "es-right"];
1240
+ const COLUMN_TOKENS$1 = ["es-left", "es-right"];
1126
1241
  const STRIPE_TOKENS = [
1127
1242
  "es-header",
1128
1243
  "es-content",
@@ -1185,7 +1300,7 @@ function splitPadding(padding, count, index) {
1185
1300
  };
1186
1301
  }
1187
1302
  function isColumn($el) {
1188
- return $el.is("table") && hasAnyToken($el, COLUMN_TOKENS);
1303
+ return $el.is("table") && hasAnyToken($el, COLUMN_TOKENS$1);
1189
1304
  }
1190
1305
  function containsColumn($el, $) {
1191
1306
  const stop = $el[0];
@@ -1193,10 +1308,10 @@ function containsColumn($el, $) {
1193
1308
  $el.find("table").each((_, node) => {
1194
1309
  if (found) return;
1195
1310
  const $n = $(node);
1196
- if (!hasAnyToken($n, COLUMN_TOKENS)) return;
1311
+ if (!hasAnyToken($n, COLUMN_TOKENS$1)) return;
1197
1312
  let $parent = $n.parent();
1198
1313
  while ($parent.length > 0 && $parent[0] !== stop) {
1199
- if (hasAnyToken($parent, COLUMN_TOKENS)) return;
1314
+ if (hasAnyToken($parent, COLUMN_TOKENS$1)) return;
1200
1315
  $parent = $parent.parent();
1201
1316
  }
1202
1317
  found = true;
@@ -1318,31 +1433,43 @@ function regionFromElement($el, $, ctx, room) {
1318
1433
  function hasBlocks(children) {
1319
1434
  return children.some((column) => column.length > 0);
1320
1435
  }
1436
+ /** The column table's px width, else its cell's. A non-px length is unread. */
1437
+ function declaredColumnPx($col) {
1438
+ const fromTable = statedPx($col.attr("width"), $col.attr("style"));
1439
+ if (fromTable !== void 0) return fromTable;
1440
+ const $cell = directCell($col);
1441
+ return statedPx($cell.attr("width"), $cell.attr("style"));
1442
+ }
1321
1443
  function columnChildren(cols, $, ctx, bodyWidth, padding) {
1322
1444
  const count = cols.length;
1323
- const layout = count >= 3 ? "3" : count === 2 ? "2" : "1";
1324
- const rooms = columnRooms(bodyWidth, count >= 4 ? "3" : layout, padding, count >= 4 ? 3 : layout === "1" ? 1 : count);
1445
+ const layout = count >= 4 ? "4" : count === 3 ? "3" : count === 2 ? "2" : "1";
1446
+ const fold = count >= 5;
1447
+ const rooms = columnRooms(bodyWidth, layout, padding, fold ? 4 : layout === "1" ? 1 : count);
1325
1448
  let children;
1326
- if (count >= 4) {
1449
+ if (fold) {
1327
1450
  const rest = [];
1328
- for (const el of cols.slice(2)) rest.push(...regionFromElement($(el), $, ctx, rooms[2]));
1451
+ for (const el of cols.slice(3)) rest.push(...regionFromElement($(el), $, ctx, rooms[3]));
1329
1452
  children = [
1330
1453
  regionFromElement($(cols[0]), $, ctx, rooms[0]),
1331
1454
  regionFromElement($(cols[1]), $, ctx, rooms[1]),
1455
+ regionFromElement($(cols[2]), $, ctx, rooms[2]),
1332
1456
  rest
1333
1457
  ];
1334
1458
  } else children = cols.map((el, index) => regionFromElement($(el), $, ctx, rooms[index]));
1335
1459
  if (!hasBlocks(children)) return null;
1336
- if (count < 4) return {
1460
+ const widthNote = layout === "1" ? void 0 : unequalWidthNote(cols.map((el) => declaredColumnPx($(el))), layout);
1461
+ if (!fold) return {
1337
1462
  children,
1338
- layout: count >= 3 ? "3" : layout
1463
+ layout,
1464
+ widthNote
1339
1465
  };
1340
- const flattenNote = `Row with ${count} columns was flattened; extra columns merged into the third slot. Templatical supports up to 3 columns per section.`;
1466
+ const flattenNote = `Row with ${count} columns was flattened; extra columns merged into the fourth slot. Templatical supports up to four columns per section.`;
1341
1467
  ctx.warnings.push(flattenNote);
1342
1468
  return {
1343
1469
  children,
1344
- layout: "3",
1345
- flattenNote
1470
+ layout,
1471
+ flattenNote,
1472
+ widthNote
1346
1473
  };
1347
1474
  }
1348
1475
  function flowNodes(pieces) {
@@ -1411,6 +1538,7 @@ function sectionsFromRow($row, $, ctx, token, paint, images, bodyWidth) {
1411
1538
  children: built.children,
1412
1539
  layout: built.layout,
1413
1540
  extra: built.flattenNote,
1541
+ widthNote: built.widthNote,
1414
1542
  columnImages: cols.map((el) => columnImage($(el), bodyWidth))
1415
1543
  });
1416
1544
  continue;
@@ -1439,16 +1567,19 @@ function sectionsFromRow($row, $, ctx, token, paint, images, bodyWidth) {
1439
1567
  const notes = [
1440
1568
  ...groupPaint.notes,
1441
1569
  group.extra,
1570
+ group.widthNote,
1442
1571
  ...image.notes,
1443
1572
  seam
1444
1573
  ].filter((note) => Boolean(note));
1445
1574
  const entry = pushEntry(ctx, token, "section", notes.length > 0 ? "approximated" : "converted", notes.length > 0 ? notes.join(" ") : void 0);
1446
1575
  recordImageSpan(ctx, image.source, entry);
1576
+ recordImageSpan(ctx, image.bandSource, entry);
1577
+ const wrapper = sectionWrapper(groupPaint, image.band);
1447
1578
  return withBackground(createSectionBlock({
1448
1579
  columns: group.layout,
1449
1580
  children: group.children,
1450
1581
  styles: { padding: splitPadding(padding, rendered.length, index) },
1451
- ...groupPaint.wrapperColor ? { wrapper: { backgroundColor: groupPaint.wrapperColor } } : {},
1582
+ ...wrapper ? { wrapper } : {},
1452
1583
  ...image.image ? { backgroundImage: image.image } : {}
1453
1584
  }), groupPaint.backgroundColor);
1454
1585
  });
@@ -1460,7 +1591,7 @@ function sectionsFromStripe($stripe, $, ctx) {
1460
1591
  const rows = $body.length > 0 ? directRows($body, $) : directRows($stripe, $);
1461
1592
  const $width = $body.length > 0 ? $body : $stripe;
1462
1593
  const bodyWidth = emailBodyWidth($width.attr("width"), $width.attr("style"));
1463
- const paint = resolveSectionPaint(ctx.pageBackground ?? "#ffffff", bandColor$1($stripe), $body.length > 0 ? paintOf($body) : "");
1594
+ const paint = resolveSectionPaint(ctx.pageBackground ?? "#ffffff", bandColor$1($stripe), $body.length > 0 ? paintOf($body) : "", $body.length > 0);
1464
1595
  const images = {
1465
1596
  body: imageLayer($body, "Section", bodyWidth),
1466
1597
  band: bandImage($stripe, directCell($stripe), bodyWidth),
@@ -1569,17 +1700,38 @@ const ZERO = {
1569
1700
  left: 0
1570
1701
  };
1571
1702
  const BODY_SELECTOR = "[class~='es-header-body'], [class~='es-content-body'], [class~='es-footer-body']";
1703
+ const COLUMN_TOKENS = ["es-left", "es-right"];
1572
1704
  function columnLayout(count, ctx) {
1573
1705
  if (count <= 1) return { layout: "1" };
1574
1706
  if (count === 2) return { layout: "2" };
1575
1707
  if (count === 3) return { layout: "3" };
1576
- const flattenNote = `Row with ${count} columns was flattened to a single column. Templatical supports up to 3 columns per section.`;
1708
+ if (count === 4) return { layout: "4" };
1709
+ const flattenNote = `Row with ${count} columns was flattened to a single column. Templatical supports up to four columns per section.`;
1577
1710
  ctx.warnings.push(flattenNote);
1578
1711
  return {
1579
1712
  layout: "1",
1580
1713
  flattenNote
1581
1714
  };
1582
1715
  }
1716
+ /** The frame's `es-left` / `es-right` table, stopping at the structure. */
1717
+ function columnTable($frame, $structure) {
1718
+ const stop = $structure[0];
1719
+ let $parent = $frame.parent();
1720
+ while ($parent.length > 0 && $parent[0] !== stop) {
1721
+ if ($parent.is("table") && hasAnyToken($parent, COLUMN_TOKENS)) return $parent;
1722
+ $parent = $parent.parent();
1723
+ }
1724
+ return null;
1725
+ }
1726
+ /** Column-table width, else the frame's. A non-px width is unread. */
1727
+ function frameWidth($frame, $structure) {
1728
+ const $table = columnTable($frame, $structure);
1729
+ if ($table) {
1730
+ const fromTable = statedPx($table.attr("width"), $table.attr("style"));
1731
+ if (fromTable !== void 0) return fromTable;
1732
+ }
1733
+ return statedPx($frame.attr("width"), $frame.attr("style"));
1734
+ }
1583
1735
  function esdBlockKind($el) {
1584
1736
  const token = tokenStartingWith($el, "esd-block-");
1585
1737
  return token ? token.slice(10) : void 0;
@@ -1634,10 +1786,10 @@ function bandColor($stripe) {
1634
1786
  const $cell = bandCell($stripe);
1635
1787
  return $cell.length > 0 ? colorFromPaint($cell.attr("style"), $cell.attr("bgcolor")) : "";
1636
1788
  }
1637
- function paintFor($el, ctx) {
1789
+ function paintFor($el, ctx, bleed = false) {
1638
1790
  const $stripe = enclosing($el, "[class~='esd-stripe']");
1639
1791
  const $body = enclosing($el, BODY_SELECTOR);
1640
- return resolveSectionPaint(ctx.pageBackground ?? "#ffffff", $stripe ? bandColor($stripe) : "", $body ? colorFromPaint($body.attr("style"), $body.attr("bgcolor")) : "");
1792
+ return resolveSectionPaint(ctx.pageBackground ?? "#ffffff", $stripe ? bandColor($stripe) : "", $body ? colorFromPaint($body.attr("style"), $body.attr("bgcolor")) : "", bleed);
1641
1793
  }
1642
1794
  function sectionFromStructure($structure, $, ctx) {
1643
1795
  const frames = $structure.find("[class~='esd-container-frame']").toArray().map((n) => $(n)).filter(($el) => {
@@ -1651,7 +1803,7 @@ function sectionFromStructure($structure, $, ctx) {
1651
1803
  const padding = readBoxPadding($structure.attr("class"), $structure.attr("style"));
1652
1804
  const $body = enclosing($structure, BODY_SELECTOR);
1653
1805
  const bodyWidth = emailBodyWidth($body?.attr("width"), $body?.attr("style"));
1654
- const rooms = columnRooms(bodyWidth, layout, padding, layout === "1" ? 1 : Math.min(frameCount, 3));
1806
+ const rooms = columnRooms(bodyWidth, layout, padding, layout === "1" ? 1 : frameCount);
1655
1807
  let children;
1656
1808
  if (layout === "1") {
1657
1809
  const merged = [];
@@ -1668,24 +1820,23 @@ function sectionFromStructure($structure, $, ctx) {
1668
1820
  columns: frames.map(($f) => imageOf($f, "Column", bodyWidth)),
1669
1821
  bodyPainted: $body ? colorFromPaint($body.attr("style"), $body.attr("bgcolor")) !== "" : false
1670
1822
  });
1671
- const paint = withoutBandOverImage(paintFor($structure, ctx), image.image !== void 0);
1823
+ const paint = withoutBandOverImage(paintFor($structure, ctx, $stripe !== null && $body !== null), image.image !== void 0);
1824
+ const widthNote = layout === "1" ? void 0 : unequalWidthNote(frames.map(($frame) => frameWidth($frame, $structure)), layout);
1672
1825
  const notes = [
1673
1826
  ...paint.notes,
1674
1827
  flattenNote,
1828
+ widthNote,
1675
1829
  ...image.notes
1676
1830
  ].filter((note) => Boolean(note));
1677
- if (notes.length > 0) {
1678
- const entry = pushEntry(ctx, "esd-structure", "section", "approximated", notes.join(" "));
1679
- recordImageSpan(ctx, image.source, entry);
1680
- } else if (frameCount <= 3) {
1681
- const entry = pushEntry(ctx, "esd-structure", "section", "converted");
1682
- recordImageSpan(ctx, image.source, entry);
1683
- }
1831
+ const entry = pushEntry(ctx, "esd-structure", "section", notes.length > 0 ? "approximated" : "converted", notes.length > 0 ? notes.join(" ") : void 0);
1832
+ recordImageSpan(ctx, image.source, entry);
1833
+ recordImageSpan(ctx, image.bandSource, entry);
1834
+ const wrapper = sectionWrapper(paint, image.band);
1684
1835
  return withBackground(createSectionBlock({
1685
1836
  columns: layout,
1686
1837
  children,
1687
1838
  styles: { padding },
1688
- ...paint.wrapperColor ? { wrapper: { backgroundColor: paint.wrapperColor } } : {},
1839
+ ...wrapper ? { wrapper } : {},
1689
1840
  ...image.image ? { backgroundImage: image.image } : {}
1690
1841
  }), paint.backgroundColor);
1691
1842
  }
@@ -1709,11 +1860,13 @@ function convertEditor(html, ctx) {
1709
1860
  const notes = [...paint.notes, ...image.notes].filter((note) => Boolean(note));
1710
1861
  const entry = pushEntry(ctx, "esd-stripe", "section", notes.length > 0 ? "approximated" : "converted", notes.length > 0 ? notes.join(" ") : void 0);
1711
1862
  recordImageSpan(ctx, image.source, entry);
1863
+ recordImageSpan(ctx, image.bandSource, entry);
1864
+ const wrapper = sectionWrapper(paint, image.band);
1712
1865
  return withBackground(createSectionBlock({
1713
1866
  columns: "1",
1714
1867
  children: [blocksInContainer($stripe, $, ctx, columnRooms(600, "1", ZERO, 1)[0])],
1715
1868
  styles: { padding: { ...ZERO } },
1716
- ...paint.wrapperColor ? { wrapper: { backgroundColor: paint.wrapperColor } } : {},
1869
+ ...wrapper ? { wrapper } : {},
1717
1870
  ...image.image ? { backgroundImage: image.image } : {}
1718
1871
  }), paint.backgroundColor);
1719
1872
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ZERO","ZERO","ZERO","BODY_SELECTOR","bandColor"],"sources":["../src/classes.ts","../src/css.ts","../src/fragment.ts","../src/platform.ts","../src/labelled.ts","../src/compiled.ts","../src/detect.ts","../src/editor.ts","../src/converter.ts"],"sourcesContent":["import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\n\nexport function classTokens($el: Cheerio<Element>): string[] {\n return ($el.attr(\"class\") ?? \"\").trim().split(/\\s+/).filter(Boolean);\n}\n\nexport function hasToken($el: Cheerio<Element>, token: string): boolean {\n return classTokens($el).includes(token);\n}\n\nexport function hasAnyToken(\n $el: Cheerio<Element>,\n tokens: readonly string[],\n): boolean {\n const set = new Set(classTokens($el));\n return tokens.some((t) => set.has(t));\n}\n\nexport function tokenStartingWith(\n $el: Cheerio<Element>,\n prefix: string,\n): string | undefined {\n return classTokens($el).find((t) => t.startsWith(prefix));\n}\n\n/** Elements carrying `token` that are not nested in another such element. */\nexport function topLevelWithToken(\n $: CheerioAPI,\n token: string,\n $root?: Cheerio<Element>,\n): Cheerio<Element>[] {\n const selector = `[class~=\"${token}\"]`;\n const $found = $root ? $root.find(selector) : $(selector);\n const out: Cheerio<Element>[] = [];\n $found.each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n const nested = $el.parents(selector);\n if ($root && $root.length) {\n const outside = nested.filter((_, p) => {\n const $p = $(p) as Cheerio<Element>;\n return $p.closest($root).length === 0 && !$p.is($root);\n });\n if (nested.length - outside.length > 0) return;\n } else if (nested.length > 0) {\n return;\n }\n out.push($el);\n });\n return out;\n}\n\nexport function isHidden($el: Cheerio<Element>): boolean {\n return hasToken($el, \"es-hidden\") || hasToken($el, \"esd-hidden\");\n}\n","/**\n * Tiny CSS readers for paint, padding and divider width.\n * Hex (3/6), a bare bgcolor hex, and rgb()/rgba() (alpha dropped).\n * \"transparent\" is unset. A present padding longhand of 0 beats the shorthand.\n */\n\nimport type {\n BackgroundImage,\n BackgroundPositionX,\n BackgroundPositionY,\n BackgroundSize,\n DividerBlock,\n SpacingValue,\n} from \"@templatical/types\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** Column shares of the body width. The third column takes the rounding remainder. */\nconst COLUMN_SHARES = {\n \"1\": [100],\n \"2\": [50, 50],\n \"3\": [33.33, 33.33, 33.34],\n} as const;\n\nconst DIVIDER_WIDTH = /^(-?\\d+(?:\\.\\d+)?)\\s*(%|px)?$/i;\n\nconst SIDE_LETTER: Record<string, keyof SpacingValue> = {\n t: \"top\",\n r: \"right\",\n b: \"bottom\",\n l: \"left\",\n};\n\n/**\n * A `style` attribute as a key/value map. A semicolon inside quotes or\n * parentheses — `url(\"a;b\")`, `url(data:image/png;base64,…)` — belongs to\n * its value.\n */\nexport function parseStyleAttribute(\n styleAttr: string | undefined,\n): Record<string, string> {\n const result: Record<string, string> = {};\n if (!styleAttr) return result;\n for (const decl of splitTopLevel(styleAttr, \";\")) {\n const idx = decl.indexOf(\":\");\n if (idx === -1) continue;\n const key = decl.slice(0, idx).trim().toLowerCase();\n const value = decl.slice(idx + 1).trim();\n if (key && value) result[key] = value;\n }\n return result;\n}\n\n/**\n * Split `value` at each `separator` that sits outside quotes and parentheses.\n * A value whose quote or parenthesis never closes is split at every\n * `separator` instead, so a malformed declaration costs only itself and the\n * ones after it still read.\n */\nfunction splitTopLevel(value: string, separator: string): string[] {\n const parts: string[] = [];\n let depth = 0;\n let quote = \"\";\n let start = 0;\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n if (quote) {\n if (char === quote) quote = \"\";\n continue;\n }\n if (char === '\"' || char === \"'\") quote = char;\n else if (char === \"(\") depth++;\n else if (char === \")\") depth = Math.max(0, depth - 1);\n else if (char === separator && depth === 0) {\n parts.push(value.slice(start, i));\n start = i + 1;\n }\n }\n if (quote || depth > 0) return value.split(separator);\n parts.push(value.slice(start));\n return parts;\n}\n\nfunction channelHex(value: number): string {\n const clamped = Math.max(0, Math.min(255, Math.round(value)));\n return clamped.toString(16).padStart(2, \"0\");\n}\n\nexport function parseColor(value: string | undefined): string {\n if (!value) return \"\";\n const trimmed = value.trim().toLowerCase();\n if (trimmed === \"transparent\" || trimmed === \"inherit\" || trimmed === \"none\")\n return \"\";\n const hex = trimmed.startsWith(\"#\")\n ? trimmed\n : /^[0-9a-f]{3}$|^[0-9a-f]{6}$/.test(trimmed)\n ? `#${trimmed}`\n : \"\";\n if (/^#[0-9a-f]{6}$/.test(hex)) return hex;\n if (/^#[0-9a-f]{3}$/.test(hex)) {\n return `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;\n }\n const rgb = trimmed.match(\n /^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*[\\d.]+\\s*)?\\)$/,\n );\n if (rgb) {\n return `#${channelHex(Number(rgb[1]))}${channelHex(Number(rgb[2]))}${channelHex(Number(rgb[3]))}`;\n }\n return \"\";\n}\n\nexport function parsePxValue(value: string | undefined): number {\n if (!value) return 0;\n const match = value.trim().match(/^(-?\\d+(?:\\.\\d+)?)\\s*(?:px)?\\s*$/);\n return match ? Math.round(parseFloat(match[1])) : 0;\n}\n\n/** Inline `background-color` / `background` wins over the `bgcolor` attribute. */\nexport function colorFromPaint(\n styleAttr: string | undefined,\n bgcolor?: string,\n): string {\n const styles = parseStyleAttribute(styleAttr);\n const fromShorthand = styles.background\n ? parseColor(styles.background.trim().split(/\\s+/)[0])\n : \"\";\n return (\n parseColor(styles[\"background-color\"]) ||\n fromShorthand ||\n parseColor(bgcolor) ||\n \"\"\n );\n}\n\nexport function parsePaddingShorthand(value: string | undefined): SpacingValue {\n if (!value) return { ...ZERO };\n const values = value\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((part) => parsePxValue(part));\n if (values.length === 0) return { ...ZERO };\n if (values.length === 1) {\n return {\n top: values[0],\n right: values[0],\n bottom: values[0],\n left: values[0],\n };\n }\n if (values.length === 2) {\n return {\n top: values[0],\n right: values[1],\n bottom: values[0],\n left: values[1],\n };\n }\n if (values.length === 3) {\n return {\n top: values[0],\n right: values[1],\n bottom: values[2],\n left: values[1],\n };\n }\n return {\n top: values[0],\n right: values[1],\n bottom: values[2],\n left: values[3],\n };\n}\n\n/**\n * Longhand wins when it is present, including an explicit 0.\n * A missing longhand falls back to the shorthand, then 0.\n */\nexport function readPadding(styles: Record<string, string>): SpacingValue {\n const shorthand =\n styles.padding !== undefined ? parsePaddingShorthand(styles.padding) : ZERO;\n const side = (name: keyof SpacingValue): number => {\n const key = `padding-${name}`;\n if (styles[key] !== undefined) return parsePxValue(styles[key]);\n return shorthand[name];\n };\n return {\n top: side(\"top\"),\n right: side(\"right\"),\n bottom: side(\"bottom\"),\n left: side(\"left\"),\n };\n}\n\n/** `es-p20` sets every side; `es-p10t` / `r` / `b` / `l` then override one side. */\nexport function paddingFromClasses(\n classAttr: string | undefined,\n): SpacingValue {\n const pad: SpacingValue = { ...ZERO };\n const tokens = (classAttr ?? \"\").split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n const all = /^es-p(\\d+)$/.exec(token);\n if (!all) continue;\n const n = Number(all[1]);\n pad.top = n;\n pad.right = n;\n pad.bottom = n;\n pad.left = n;\n }\n for (const token of tokens) {\n const side = /^es-p(\\d+)([trbl])$/.exec(token);\n if (!side) continue;\n pad[SIDE_LETTER[side[2]]] = Number(side[1]);\n }\n return pad;\n}\n\n/**\n * Class padding first, then inline padding per side.\n * A shorthand replaces every side; a longhand replaces only that side.\n */\nexport function readBoxPadding(\n classAttr: string | undefined,\n styleAttr: string | undefined,\n): SpacingValue {\n const base = paddingFromClasses(classAttr);\n const styles = parseStyleAttribute(styleAttr);\n const hasShorthand = styles.padding !== undefined;\n const shorthand = hasShorthand ? parsePaddingShorthand(styles.padding) : base;\n const side = (name: keyof SpacingValue): number => {\n const key = `padding-${name}`;\n if (styles[key] !== undefined) return parsePxValue(styles[key]);\n if (hasShorthand) return shorthand[name];\n return base[name];\n };\n return {\n top: side(\"top\"),\n right: side(\"right\"),\n bottom: side(\"bottom\"),\n left: side(\"left\"),\n };\n}\n\nexport interface SectionPaint {\n backgroundColor: string;\n wrapperColor?: string;\n notes: string[];\n}\n\n/**\n * Body fill paints the section. A band that is neither the page nor the body\n * becomes the section wrapper. A transparent body leaves the band on the section.\n */\nexport function resolveSectionPaint(\n pageBackground: string,\n band: string,\n body: string,\n): SectionPaint {\n const page = pageBackground || \"#ffffff\";\n if (body) {\n if (band && band !== page && band !== body) {\n return {\n backgroundColor: body,\n wrapperColor: band,\n notes: [\"The band colour was imported as a section wrapper.\"],\n };\n }\n return { backgroundColor: body, notes: [] };\n }\n return { backgroundColor: band, notes: [] };\n}\n\n/** `es-*-body` width in px, or 600 when the document does not state one. */\nexport function emailBodyWidth(\n widthAttr: string | undefined,\n styleAttr: string | undefined,\n): number {\n const raw = (widthAttr || parseStyleAttribute(styleAttr).width || \"\").trim();\n const n = parsePxValue(raw);\n return n > 0 ? n : 600;\n}\n\n/**\n * Room each column has for a line, before the line's own side padding.\n * The share is of the body width; the first column then loses the section's\n * left padding and the last loses the right. One column loses both.\n * A room that is not positive is unknown — the caller keeps the stated px.\n */\nexport function columnRooms(\n bodyWidth: number,\n layout: \"1\" | \"2\" | \"3\",\n padding: SpacingValue,\n slotCount: number,\n): Array<number | undefined> {\n const shares = COLUMN_SHARES[layout];\n const count = layout === \"1\" ? 1 : slotCount;\n const width = bodyWidth > 0 ? bodyWidth : 600;\n return Array.from({ length: count }, (_, index) => {\n const span = layout === \"1\" ? width : (width * shares[index]) / 100;\n const left = layout === \"1\" || index === 0 ? padding.left : 0;\n const right = layout === \"1\" || index === count - 1 ? padding.right : 0;\n const room = span - left - right;\n return room > 0 ? room : undefined;\n });\n}\n\n/**\n * No width, `auto` and `100%` span the column. Another percentage stays a\n * share, clamped to 0–100 and rounded to two decimals. A px width stays px\n * until it reaches `room` less the divider's own side padding.\n */\nexport function readDividerWidth(\n raw: string,\n room: number | undefined,\n ownLeft: number,\n ownRight: number,\n notes: string[],\n): DividerBlock[\"width\"] {\n const trimmed = raw.trim();\n if (\n trimmed === \"\" ||\n trimmed.toLowerCase() === \"auto\" ||\n trimmed === \"100%\"\n ) {\n return \"full\";\n }\n const match = trimmed.match(DIVIDER_WIDTH);\n if (!match) {\n notes.push(\n `Divider width \"${trimmed}\" could not be read; imported as full width.`,\n );\n return \"full\";\n }\n const value = parseFloat(match[1]);\n if ((match[2] ?? \"\").toLowerCase() === \"%\") {\n const percent = Math.min(100, Math.max(0, value));\n if (percent !== value) {\n notes.push(`Divider width ${trimmed} was clamped to ${percent}%.`);\n }\n const share = Math.round((percent + Number.EPSILON) * 100) / 100;\n return share === 100 ? \"full\" : `${share}%`;\n }\n const px = Math.max(0, Math.round(value));\n if (value < 0) notes.push(`Divider width ${trimmed} was clamped to 0px.`);\n if (room === undefined || room <= 0) return px;\n return px >= room - ownLeft - ownRight ? \"full\" : px;\n}\n\nconst BORDER_STYLES = new Set([\n \"none\",\n \"hidden\",\n \"dotted\",\n \"dashed\",\n \"solid\",\n \"double\",\n \"groove\",\n \"ridge\",\n \"inset\",\n \"outset\",\n]);\n\nexport interface ParsedBorder {\n width: number;\n style: string;\n color: string;\n}\n\n/** A `border-bottom` / `border-top` shorthand. Color is empty when absent. */\nexport function parseBorderShorthand(value: string | undefined): ParsedBorder {\n const parsed: ParsedBorder = { width: 0, style: \"solid\", color: \"\" };\n if (!value) return parsed;\n for (const token of value.trim().split(/\\s+/)) {\n const lower = token.toLowerCase();\n if (BORDER_STYLES.has(lower)) {\n parsed.style = lower;\n } else if (/^-?\\d+(?:\\.\\d+)?(?:px)?$/i.test(lower)) {\n parsed.width = parsePxValue(lower);\n } else {\n const color = parseColor(lower);\n if (color) parsed.color = color;\n }\n }\n return parsed;\n}\n\nexport function visibleLineBorder(\n styles: Record<string, string>,\n): ParsedBorder | null {\n for (const key of [\"border-bottom\", \"border-top\"]) {\n if (styles[key] === undefined) continue;\n const parsed = parseBorderShorthand(styles[key]);\n if (\n parsed.width > 0 &&\n parsed.style !== \"none\" &&\n parsed.style !== \"hidden\"\n ) {\n return parsed;\n }\n }\n return null;\n}\n\n/** A background image read from the source, with a note for each value that had no exact keyword. */\nexport interface ReadBackgroundImage {\n image: BackgroundImage;\n notes: string[];\n}\n\nconst X_GRID = [\"left\", \"center\", \"right\"] as const;\nconst Y_GRID = [\"top\", \"center\", \"bottom\"] as const;\nconst PERCENT = /^(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))%$/;\nconst LENGTH = /^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)[a-z]*$/;\n\n/**\n * `background-size` as a keyword. A size with a side at 100%, or a px width\n * spanning the box, fills it as `cover` does; any other length or percentage\n * draws the image at a size of its own, which `auto` is closest to.\n */\nfunction backgroundSizeKeyword(\n raw: string,\n boxWidth: number | undefined,\n): { size: BackgroundSize; exact: boolean } {\n const parts = raw.toLowerCase().split(/\\s+/);\n const [first] = parts;\n if (parts.length === 1 && (first === \"cover\" || first === \"contain\")) {\n return { size: first, exact: true };\n }\n if (parts.every((part) => part === \"auto\")) {\n return { size: \"auto\", exact: true };\n }\n const px = /^(\\d+(?:\\.\\d+)?|\\.\\d+)px$/.exec(first);\n const fills =\n parts.includes(\"100%\") ||\n (px !== null && boxWidth !== undefined && Number(px[1]) >= boxWidth);\n return { size: fills ? \"cover\" : \"auto\", exact: false };\n}\n\n/**\n * `background-position` split into x and y the way MJML and CSS read it: a\n * lone `top` / `bottom` names y and centres x, any other lone value is x\n * with y centred, and a pair is x then y unless it leads with `top` /\n * `bottom` (or with `center` before `left` / `right`). Three- and four-value\n * edge offsets keep their edge keywords only.\n */\nfunction splitBackgroundPosition(raw: string): {\n x: string;\n y: string;\n exact: boolean;\n} {\n const parts = raw.toLowerCase().split(/\\s+/);\n if (parts.length === 1) {\n const [only] = parts;\n return only === \"top\" || only === \"bottom\"\n ? { x: \"center\", y: only, exact: true }\n : { x: only, y: \"center\", exact: true };\n }\n if (parts.length === 2) {\n const [a, b] = parts;\n const yFirst =\n a === \"top\" ||\n a === \"bottom\" ||\n (a === \"center\" && (b === \"left\" || b === \"right\"));\n return yFirst ? { x: b, y: a, exact: true } : { x: a, y: b, exact: true };\n }\n return {\n x: parts.find((part) => part === \"left\" || part === \"right\") ?? \"center\",\n y: parts.find((part) => part === \"top\" || part === \"bottom\") ?? \"center\",\n exact: false,\n };\n}\n\n/**\n * One axis as a grid point: its keyword; the point nearest a percentage,\n * ties going to the centre; or the start edge for a length, which is an\n * offset from it. `null` when the token is unreadable.\n */\nfunction backgroundAxisPoint<T extends string>(\n token: string,\n grid: readonly [T, T, T],\n): { point: T; exact: boolean } | null {\n const keyword = grid.find((point) => point === token);\n if (keyword) return { point: keyword, exact: true };\n const percent = PERCENT.exec(token);\n if (percent) {\n const n = Number(percent[1]);\n return {\n point: n < 25 ? grid[0] : n > 75 ? grid[2] : grid[1],\n exact: n === 0 || n === 50 || n === 100,\n };\n }\n if (LENGTH.test(token)) {\n return { point: grid[0], exact: parseFloat(token) === 0 };\n }\n return null;\n}\n\n/**\n * `background-repeat`: unrepeated only when every axis is `no-repeat`.\n * Anything but plain `repeat` tiles too, inexactly.\n */\nfunction backgroundRepeatFlag(raw: string): {\n repeat: boolean;\n exact: boolean;\n} {\n const parts = raw.toLowerCase().split(/\\s+/);\n if (parts.every((part) => part === \"no-repeat\")) {\n return { repeat: false, exact: true };\n }\n return { repeat: true, exact: parts.every((part) => part === \"repeat\") };\n}\n\n/** CSS's initial values: what a browser paints for a longhand the source leaves out. */\nconst CSS_BACKGROUND_DEFAULTS = {\n size: \"auto\",\n x: \"left\",\n y: \"top\",\n repeat: true,\n} as const;\n\nconst IMAGE_FUNCTION = /^(?:url|[a-z-]*gradient|image-set)\\(/;\nconst REPEAT_TOKENS = new Set([\n \"repeat\",\n \"no-repeat\",\n \"repeat-x\",\n \"repeat-y\",\n \"round\",\n \"space\",\n]);\nconst POSITION_TOKENS = new Set([\"left\", \"right\", \"top\", \"bottom\", \"center\"]);\nconst NON_COLOR_TOKENS = new Set([\n \"none\",\n \"scroll\",\n \"fixed\",\n \"local\",\n \"border-box\",\n \"padding-box\",\n \"content-box\",\n \"text\",\n \"cover\",\n \"contain\",\n \"auto\",\n]);\nconst MEASURE = /^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:%|[a-z]+)?$/i;\n\n/**\n * The URL inside the first CSS `url(…)`, unquoted and trimmed; \"\" when there\n * is none or it is malformed. A forward scan rather than a regex, so a long\n * run of unclosed `url(` can't make it backtrack.\n */\nfunction cssUrl(value: string | undefined): string {\n const text = value ?? \"\";\n const start = text.search(/url\\(/i);\n if (start === -1) return \"\";\n let i = start + 4;\n while (i < text.length && /\\s/.test(text[i])) i++;\n const quote = text[i];\n if (quote === '\"' || quote === \"'\") {\n const close = text.indexOf(quote, i + 1);\n if (close === -1) return \"\";\n let j = close + 1;\n while (j < text.length && /\\s/.test(text[j])) j++;\n return text[j] === \")\" ? text.slice(i + 1, close).trim() : \"\";\n }\n const close = text.indexOf(\")\", i);\n if (close === -1) return \"\";\n const inner = text.slice(i, close);\n return /[\"']/.test(inner) ? \"\" : inner.trim();\n}\n\n/**\n * Whitespace-separated tokens, keeping a function's arguments together and\n * making the `/` between position and size a token of its own.\n */\nfunction cssTokens(value: string): string[] {\n const tokens: string[] = [];\n let depth = 0;\n let quote = \"\";\n let current = \"\";\n const push = (): void => {\n if (current) tokens.push(current);\n current = \"\";\n };\n for (const char of value) {\n if (quote) {\n current += char;\n if (char === quote) quote = \"\";\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n current += char;\n continue;\n }\n if (char === \"(\") depth++;\n if (char === \")\") depth = Math.max(0, depth - 1);\n if (depth === 0 && /\\s/.test(char)) {\n push();\n continue;\n }\n if (depth === 0 && char === \"/\") {\n push();\n tokens.push(\"/\");\n continue;\n }\n current += char;\n }\n push();\n return tokens;\n}\n\nfunction isColorToken(token: string): boolean {\n const lower = token.toLowerCase();\n if (lower === \"/\" || IMAGE_FUNCTION.test(lower)) return false;\n return (\n !REPEAT_TOKENS.has(lower) &&\n !POSITION_TOKENS.has(lower) &&\n !NON_COLOR_TOKENS.has(lower) &&\n !MEASURE.test(lower)\n );\n}\n\nexport interface BackgroundShorthand {\n /** The colour token as written; \"\" when there is none. */\n color: string;\n url: string;\n size: string;\n position: string;\n repeat: string;\n layers: number;\n}\n\n/**\n * The parts of a `background` shorthand. The colour comes from the last\n * layer, the only one CSS lets carry it; the image and its size, position\n * and repeat come from the first layer with a `url()`.\n */\nexport function parseBackgroundShorthand(value: string): BackgroundShorthand {\n const layers = splitTopLevel(value, \",\")\n .map((layer) => layer.trim())\n .filter(Boolean);\n const last = cssTokens(layers[layers.length - 1] ?? \"\");\n const color = last.find(isColorToken) ?? \"\";\n const imageLayer = layers.find((layer) => cssUrl(layer) !== \"\");\n if (!imageLayer) {\n return {\n color,\n url: \"\",\n size: \"\",\n position: \"\",\n repeat: \"\",\n layers: layers.length,\n };\n }\n\n const tokens = cssTokens(imageLayer);\n const slash = tokens.indexOf(\"/\");\n const before = slash === -1 ? tokens : tokens.slice(0, slash);\n const after = slash === -1 ? [] : tokens.slice(slash + 1);\n const size: string[] = [];\n for (const token of after) {\n const lower = token.toLowerCase();\n const isSize =\n lower === \"cover\" ||\n lower === \"contain\" ||\n lower === \"auto\" ||\n MEASURE.test(lower);\n if (size.length === 2 || !isSize) break;\n size.push(token);\n }\n const rest = [...before, ...after.slice(size.length)];\n return {\n color,\n url: cssUrl(imageLayer),\n size: size.join(\" \"),\n position: before\n .filter(\n (token) =>\n POSITION_TOKENS.has(token.toLowerCase()) || MEASURE.test(token),\n )\n .join(\" \"),\n repeat: rest\n .filter((token) => REPEAT_TOKENS.has(token.toLowerCase()))\n .join(\" \"),\n layers: layers.length,\n };\n}\n\n/**\n * A background image from a URL and its longhands. A longhand left out takes\n * CSS's initial value; a value with no exact keyword takes the nearest one\n * and adds a note naming it. `null` for a blank URL.\n */\nfunction buildBackgroundImage(\n url: string,\n longhands: {\n size?: string;\n position?: string;\n positionX?: string;\n positionY?: string;\n repeat?: string;\n },\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const trimmedUrl = url.trim();\n if (!trimmedUrl) return null;\n\n const notes: string[] = [];\n const lossy = (name: string, raw: string, shown: string): void => {\n notes.push(\n `${label} ${name} \"${raw}\" has no exact Templatical equivalent; imported as \"${shown}\".`,\n );\n };\n\n let size: BackgroundSize = CSS_BACKGROUND_DEFAULTS.size;\n const rawSize = longhands.size?.trim();\n if (rawSize) {\n const parsed = backgroundSizeKeyword(rawSize, boxWidth);\n size = parsed.size;\n if (!parsed.exact) lossy(\"background-size\", rawSize, size);\n }\n\n let x: BackgroundPositionX = CSS_BACKGROUND_DEFAULTS.x;\n let y: BackgroundPositionY = CSS_BACKGROUND_DEFAULTS.y;\n let lossyX = false;\n let lossyY = false;\n const rawPosition = longhands.position?.trim();\n if (rawPosition) {\n const split = splitBackgroundPosition(rawPosition);\n const readX = backgroundAxisPoint(split.x, X_GRID);\n const readY = backgroundAxisPoint(split.y, Y_GRID);\n x = readX?.point ?? x;\n y = readY?.point ?? y;\n lossyX = !split.exact || !readX?.exact;\n lossyY = !split.exact || !readY?.exact;\n }\n // A readable `-x` / `-y` replaces its axis, and with it whatever the\n // position lost there; the position's note then names what was imported.\n const rawX = longhands.positionX?.trim();\n const overrideX = rawX\n ? backgroundAxisPoint(rawX.toLowerCase(), X_GRID)\n : null;\n if (overrideX) {\n x = overrideX.point;\n lossyX = false;\n }\n const rawY = longhands.positionY?.trim();\n const overrideY = rawY\n ? backgroundAxisPoint(rawY.toLowerCase(), Y_GRID)\n : null;\n if (overrideY) {\n y = overrideY.point;\n lossyY = false;\n }\n if (rawPosition && (lossyX || lossyY)) {\n lossy(\"background-position\", rawPosition, `${x} ${y}`);\n }\n if (rawX && !overrideX?.exact) lossy(\"background-position-x\", rawX, x);\n if (rawY && !overrideY?.exact) lossy(\"background-position-y\", rawY, y);\n\n let repeat: boolean = CSS_BACKGROUND_DEFAULTS.repeat;\n const rawRepeat = longhands.repeat?.trim();\n if (rawRepeat) {\n const parsed = backgroundRepeatFlag(rawRepeat);\n repeat = parsed.repeat;\n if (!parsed.exact) {\n lossy(\"background-repeat\", rawRepeat, repeat ? \"repeat\" : \"no-repeat\");\n }\n }\n\n return {\n image: { url: trimmedUrl, size, position: { x, y }, repeat },\n notes,\n };\n}\n\n/**\n * A background image from CSS declarations: `background-image`, else the\n * `background` shorthand's image, with the size, position and repeat\n * longhands winning over the shorthand's. A style map keeps no declaration\n * order, so a longhand is taken to follow the shorthand, as it usually does.\n * Of several layers the first image is kept, and a note says so. `null`\n * when the declarations paint no image.\n */\nexport function readCssBackground(\n styles: Record<string, string>,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const shorthand =\n styles.background !== undefined\n ? parseBackgroundShorthand(styles.background)\n : null;\n const imageLayers =\n styles[\"background-image\"] !== undefined\n ? splitTopLevel(styles[\"background-image\"], \",\").map((layer) =>\n layer.trim(),\n )\n : null;\n const index = imageLayers\n ? imageLayers.findIndex((layer) => cssUrl(layer) !== \"\")\n : -1;\n const url = imageLayers\n ? index === -1\n ? \"\"\n : cssUrl(imageLayers[index])\n : (shorthand?.url ?? \"\");\n if (!url) return null;\n\n const layer = (value: string | undefined): string | undefined => {\n if (value === undefined) return undefined;\n const parts = splitTopLevel(value, \",\").map((part) => part.trim());\n return parts[Math.max(index, 0)] ?? parts[0];\n };\n const read = buildBackgroundImage(\n url,\n {\n size: layer(styles[\"background-size\"]) ?? shorthand?.size,\n position: layer(styles[\"background-position\"]) ?? shorthand?.position,\n positionX: styles[\"background-position-x\"],\n positionY: styles[\"background-position-y\"],\n repeat: layer(styles[\"background-repeat\"]) ?? shorthand?.repeat,\n },\n label,\n boxWidth,\n );\n const layers = imageLayers?.length ?? shorthand?.layers ?? 1;\n if (read && layers > 1) {\n read.notes.unshift(\n `${label} background has ${layers} layers; only the image \"${url}\" was imported.`,\n );\n }\n return read;\n}\n\n/**\n * The image an element paints: its inline CSS background, else its legacy\n * `background` attribute. A `background-image` or `background` declaration\n * overrides the attribute; a `background-color` doesn't. The image twin of\n * `colorFromPaint`.\n */\nexport function imageFromPaint(\n styleAttr: string | undefined,\n backgroundAttr: string | undefined,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const styles = parseStyleAttribute(styleAttr);\n if (\n styles[\"background-image\"] !== undefined ||\n styles.background !== undefined\n ) {\n return readCssBackground(styles, label, boxWidth);\n }\n return buildBackgroundImage(backgroundAttr ?? \"\", {}, label, boxWidth);\n}\n\n/** An image an element paints, and that element, which identifies the image when it spans several sections. */\nexport interface ImageLayer {\n read: ReadBackgroundImage;\n source: object;\n}\n\n/** Every image that can reach one section. */\nexport interface SectionImageLayers {\n /** The structure (row) cell's own image. */\n structure: ImageLayer | null;\n /** The `es-*-body` image: the content area behind every structure in the stripe. */\n body: ImageLayer | null;\n /** The stripe's image: the full-width band. */\n band: ImageLayer | null;\n /** Each container's image, in column order. */\n columns: Array<ReadBackgroundImage | null>;\n /** Whether the body paints a colour, which hides the band in the content area. */\n bodyPainted: boolean;\n}\n\nexport interface SectionImage {\n image: BackgroundImage | undefined;\n notes: string[];\n /** The element the image came from when other sections can share it; `null` for a container's. */\n source: object | null;\n}\n\nfunction sameImage(a: BackgroundImage, b: BackgroundImage): boolean {\n return (\n a.url === b.url &&\n a.size === b.size &&\n a.repeat === b.repeat &&\n a.position.x === b.position.x &&\n a.position.y === b.position.y\n );\n}\n\nfunction droppedColumnsNote(columns: number[]): string {\n return columns.length === 1\n ? `The background image on column ${columns[0]} was dropped. A Templatical section has one background image.`\n : `Background images on columns ${columns.join(\", \")} were dropped. A Templatical section has one background image.`;\n}\n\n/**\n * The image a section paints, nearest first: the structure's own, then the\n * body's, then the containers', moved up when there is one or all share the\n * same image, then the stripe's while the body leaves it showing. An image\n * that showed in the section but can't be kept is named in a note. A body\n * image beneath the structure's own is covered in this section, so it isn't\n * named; it still paints the stripe's other sections. The image is a copy,\n * so sections that share a source don't share an object.\n */\nexport function resolveSectionImage(layers: SectionImageLayers): SectionImage {\n const notes: string[] = [];\n let picked: { read: ReadBackgroundImage; source: object | null } | null =\n layers.structure ?? layers.body;\n\n const withImage = layers.columns.flatMap((read, index) =>\n read ? [index + 1] : [],\n );\n const first = layers.columns[0] ?? null;\n const shared =\n first !== null &&\n layers.columns.every(\n (read) => read !== null && sameImage(read.image, first.image),\n );\n if (withImage.length > 0) {\n if (!picked && shared) picked = { read: first, source: null };\n else notes.push(droppedColumnsNote(withImage));\n }\n\n if (layers.band) {\n if (!picked && !layers.bodyPainted) {\n picked = layers.band;\n notes.push(\n \"The stripe's background image spans the full width in Stripo; the section paints it at the content width.\",\n );\n } else {\n notes.push(\n \"The stripe's background image outside the content width was dropped.\",\n );\n }\n }\n\n if (!picked) return { image: undefined, notes, source: null };\n return {\n image: {\n ...picked.read.image,\n position: { ...picked.read.image.position },\n },\n notes: [...picked.read.notes, ...notes],\n source: picked.source,\n };\n}\n\n/**\n * The paint, minus a band colour that would become the section's wrapper\n * colour, when the section has a background image. The wrapper has no\n * padding, so the colour shows nowhere except Outlook desktop, which paints\n * it over the section's image.\n */\nexport function withoutBandOverImage(\n paint: SectionPaint,\n hasImage: boolean,\n): SectionPaint {\n if (!hasImage || !paint.wrapperColor) return paint;\n return {\n backgroundColor: paint.backgroundColor,\n notes: [\n `The band colour ${paint.wrapperColor} was dropped: Outlook desktop paints a wrapper colour over the section's background image.`,\n ],\n };\n}\n","import type { Cheerio } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport { convertHtmlTemplate } from \"@templatical/import-html\";\nimport type { ImportReportEntry } from \"@templatical/import-html\";\nimport type { Block, SectionBlock } from \"@templatical/types\";\nimport {\n imageFromPaint,\n type ImageLayer,\n type ReadBackgroundImage,\n} from \"./css\";\n\nexport interface ConvertCtx {\n entries: ImportReportEntry[];\n warnings: string[];\n /** Caller's plugin CSS. Applied inside each HTML fragment, never raw. */\n css?: string;\n /** `es-wrapper` colour, or `#ffffff` when the document has none. */\n pageBackground?: string;\n /**\n * The report entries of the sections that took each shared image, keyed by\n * the element that paints it (a body, stripe or structure cell).\n */\n imageSpans?: Map<object, ImportReportEntry[]>;\n}\n\n/** Paint after `createSectionBlock` so `styles` keeps its required padding. */\nexport function withBackground(\n section: SectionBlock,\n backgroundColor: string,\n): SectionBlock {\n if (backgroundColor) section.styles.backgroundColor = backgroundColor;\n return section;\n}\n\nexport function flattenBlocks(blocks: Block[]): Block[] {\n const out: Block[] = [];\n for (const b of blocks) {\n if (b.type === \"section\") {\n for (const col of b.children ?? []) out.push(...flattenBlocks(col));\n } else {\n out.push(b);\n }\n }\n return out;\n}\n\nfunction fragmentDocument(inner: string, css?: string): string {\n const safe = css ? css.replace(/<\\/style/gi, \"<\\\\/style\") : \"\";\n const head = safe ? `<head><style>${safe}</style></head>` : \"\";\n return `<!DOCTYPE html><html>${head}<body>${inner}</body></html>`;\n}\n\n/** The start of the HTML importer's page-image warning. */\nconst PAGE_IMAGE_WARNING = \"The email background image \";\n/** The start of the HTML importer's warning about an invalid `<html lang>`. */\nconst DEFAULT_LANGUAGE_WARNING = \"Ignored the source's default language \";\n\n/**\n * Run the generic HTML importer on a subtree and keep its blocks.\n * Section entries belong to the row the HTML importer invented; Stripo's own\n * section entries are recorded by the caller. A fragment's `<body>` is\n * synthetic, so the page-image warning the HTML importer raises for a `body`\n * background in the caller's CSS is dropped; Stripo reports the page image\n * once, from `es-wrapper`. A fragment's language is synthetic too (a nested\n * `<html lang>` merges into it), so Stripo reports the default language once,\n * from the page.\n */\nexport function blocksFromHtml(inner: string, ctx: ConvertCtx): Block[] {\n const result = convertHtmlTemplate(fragmentDocument(inner, ctx.css));\n for (const entry of result.report.entries) {\n if (entry.templaticalBlockType === \"section\") continue;\n ctx.entries.push(entry);\n }\n ctx.warnings.push(\n ...result.report.warnings.filter(\n (warning) =>\n !warning.startsWith(PAGE_IMAGE_WARNING) &&\n !warning.startsWith(DEFAULT_LANGUAGE_WARNING),\n ),\n );\n return flattenBlocks(result.content.blocks);\n}\n\nexport function pushEntry(\n ctx: ConvertCtx,\n sourceTag: string,\n templaticalBlockType: string | null,\n status: ImportReportEntry[\"status\"],\n note?: string,\n): ImportReportEntry {\n const entry: ImportReportEntry = {\n sourceTag,\n templaticalBlockType,\n status,\n ...(note ? { note } : {}),\n };\n ctx.entries.push(entry);\n return entry;\n}\n\n/** Record that a section's entry took the image `source` paints. */\nexport function recordImageSpan(\n ctx: ConvertCtx,\n source: object | null,\n entry: ImportReportEntry,\n): void {\n if (!source) return;\n ctx.imageSpans ??= new Map();\n const spanned = ctx.imageSpans.get(source) ?? [];\n spanned.push(entry);\n ctx.imageSpans.set(source, spanned);\n}\n\n/** Note on each entry whose section shares its image with another section. */\nexport function noteImageSpans(ctx: ConvertCtx): void {\n for (const spanned of ctx.imageSpans?.values() ?? []) {\n if (spanned.length < 2) continue;\n const note = `A background image behind ${spanned.length} sections was applied to each of them — Templatical has no multi-section band.`;\n for (const entry of spanned) {\n entry.status = \"approximated\";\n entry.note = entry.note ? `${entry.note} ${note}` : note;\n }\n }\n}\n\n/** The image an element paints: its inline CSS background, else its `background` attribute. */\nexport function imageOf(\n $el: Cheerio<Element>,\n label: string,\n boxWidth: number,\n): ReadBackgroundImage | null {\n return imageFromPaint(\n $el.attr(\"style\"),\n $el.attr(\"background\"),\n label,\n boxWidth,\n );\n}\n\n/** An element's image with that element as its source; `null` when there is no element or it paints none. */\nexport function imageLayer(\n $el: Cheerio<Element> | null,\n label: string,\n boxWidth: number,\n): ImageLayer | null {\n if (!$el) return null;\n const read = imageOf($el, label, boxWidth);\n return read ? { read, source: $el[0] } : null;\n}\n\n/**\n * The stripe's image: on the stripe, else on `$cell`, the cell Stripo paints\n * instead of a table stripe, as the band colour is read. A `td` / `th` stripe\n * is its own paint. The stripe names the image either way, since it is the\n * element that spans the sections.\n */\nexport function bandImage(\n $stripe: Cheerio<Element>,\n $cell: Cheerio<Element>,\n boxWidth: number,\n): ImageLayer | null {\n const own = imageLayer($stripe, \"Stripe\", boxWidth);\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return null;\n const cell = $cell.length > 0 ? imageOf($cell, \"Stripe\", boxWidth) : null;\n return cell ? { read: cell, source: $stripe[0] } : null;\n}\n","import type { SocialPlatform } from \"@templatical/types\";\n\nconst NAMED: Record<string, SocialPlatform> = {\n facebook: \"facebook\",\n fb: \"facebook\",\n twitter: \"twitter\",\n x: \"twitter\",\n instagram: \"instagram\",\n inst: \"instagram\",\n linkedin: \"linkedin\",\n youtube: \"youtube\",\n yt: \"youtube\",\n tiktok: \"tiktok\",\n pinterest: \"pinterest\",\n email: \"email\",\n mail: \"email\",\n whatsapp: \"whatsapp\",\n telegram: \"telegram\",\n discord: \"discord\",\n snapchat: \"snapchat\",\n reddit: \"reddit\",\n github: \"github\",\n dribbble: \"dribbble\",\n behance: \"behance\",\n};\n\nfunction peel(raw: string): string {\n return raw\n .toLowerCase()\n .replace(/\\.(png|jpe?g|gif|svg|webp)$/i, \"\")\n .replace(/[^a-z0-9]+/g, \" \")\n .trim();\n}\n\n/**\n * Map a Stripo icon's title, alt, or src stem onto a SocialPlatform.\n * Unknown names become `website` — same floor as the MJML importer.\n */\nexport function normalizePlatform(\n name?: string,\n src?: string,\n alt?: string,\n): SocialPlatform {\n for (const candidate of [name, alt, src]) {\n if (!candidate) continue;\n const words = peel(candidate).split(/\\s+/);\n for (const w of words) {\n if (NAMED[w]) return NAMED[w];\n }\n const stem = peel(candidate.split(\"/\").pop() ?? \"\");\n for (const w of stem.split(/\\s+/)) {\n if (NAMED[w]) return NAMED[w];\n }\n }\n return \"website\";\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport {\n createButtonBlock,\n createDividerBlock,\n createMenuBlock,\n createSocialIconsBlock,\n createSpacerBlock,\n generateId,\n} from \"@templatical/types\";\nimport type {\n Block,\n DividerBlock,\n MenuItemData,\n SocialIcon,\n SpacingValue,\n} from \"@templatical/types\";\nimport { hasAnyToken, hasToken, isHidden } from \"./classes\";\nimport {\n colorFromPaint,\n parseColor,\n parsePxValue,\n parseStyleAttribute,\n readDividerWidth,\n readPadding,\n visibleLineBorder,\n type ParsedBorder,\n} from \"./css\";\nimport { blocksFromHtml, pushEntry, type ConvertCtx } from \"./fragment\";\nimport { normalizePlatform } from \"./platform\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** Tables whose padding is the section's padding. A divider must not copy it. */\nconst STRUCTURE_TABLES = [\n \"es-header-body\",\n \"es-content-body\",\n \"es-footer-body\",\n \"es-header\",\n \"es-content\",\n \"es-footer\",\n] as const;\n\nconst MAPPED_LINE_STYLES = new Set([\n \"double\",\n \"groove\",\n \"ridge\",\n \"inset\",\n \"outset\",\n]);\n\nfunction firstAnchor($el: Cheerio<Element>): Cheerio<Element> {\n const $self = $el.is(\"a\") ? $el : $el.find(\"a\").first();\n return $self as Cheerio<Element>;\n}\n\nexport function buttonFrom(\n $el: Cheerio<Element>,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block {\n const $a = firstAnchor($el);\n const text = ($a.text() ?? \"\").trim() || \"Shop Now\";\n const url = $a.attr(\"href\") ?? \"#\";\n const target = $a.attr(\"target\");\n const own = parseStyleAttribute($a.attr(\"style\"));\n const parent = parseStyleAttribute($a.parent().attr(\"style\"));\n const backgroundColor =\n colorFromPaint($a.attr(\"style\")) ||\n colorFromPaint($a.parent().attr(\"style\"));\n const textColor = parseColor(own.color) || parseColor(parent.color);\n const borderRadius =\n parsePxValue(own[\"border-radius\"]) || parsePxValue(parent[\"border-radius\"]);\n pushEntry(ctx, sourceTag, \"button\", \"converted\");\n return createButtonBlock({\n text,\n url,\n ...(target === \"_blank\" ? { openInNewTab: true } : {}),\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(textColor ? { textColor } : {}),\n ...(borderRadius > 0 ? { borderRadius } : {}),\n });\n}\n\nfunction declaresPadding($el: Cheerio<Element>): boolean {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n return (\n styles.padding !== undefined ||\n styles[\"padding-top\"] !== undefined ||\n styles[\"padding-right\"] !== undefined ||\n styles[\"padding-bottom\"] !== undefined ||\n styles[\"padding-left\"] !== undefined\n );\n}\n\n/**\n * The structure cell's padding becomes the section's padding. Reading it again\n * as the divider's own padding shortens the line twice.\n */\nfunction isStructureCell($cell: Cheerio<Element>): boolean {\n if (!$cell.is(\"td\") && !$cell.is(\"th\")) return false;\n if (hasToken($cell, \"esd-structure\")) return true;\n let $table = $cell.parent().parent();\n if ($table.is(\"tbody\") || $table.is(\"thead\") || $table.is(\"tfoot\")) {\n $table = $table.parent();\n }\n return $table.is(\"table\") && hasAnyToken($table, STRUCTURE_TABLES);\n}\n\nfunction spacerElement($root: Cheerio<Element>): Cheerio<Element> {\n if (hasToken($root, \"es-spacer\")) return $root;\n const $inner = $root.find(\"[class~='es-spacer']\").first();\n return ($inner.length ? $inner : $root) as Cheerio<Element>;\n}\n\nfunction lineBorder(\n $root: Cheerio<Element>,\n $spacer: Cheerio<Element>,\n $: CheerioAPI,\n): ParsedBorder | null {\n const own = visibleLineBorder(parseStyleAttribute($root.attr(\"style\")));\n if (own) return own;\n const onSpacer = visibleLineBorder(\n parseStyleAttribute($spacer.attr(\"style\")),\n );\n if (onSpacer) return onSpacer;\n let found: ParsedBorder | null = null;\n $spacer.find(\"td, th\").each((_, cell) => {\n if (found) return;\n found = visibleLineBorder(parseStyleAttribute($(cell).attr(\"style\")));\n });\n return found;\n}\n\nfunction dividerPadding(\n $root: Cheerio<Element>,\n $spacer: Cheerio<Element>,\n): SpacingValue {\n if (declaresPadding($root)) {\n return readPadding(parseStyleAttribute($root.attr(\"style\")));\n }\n if ($spacer[0] !== $root[0] && declaresPadding($spacer)) {\n return readPadding(parseStyleAttribute($spacer.attr(\"style\")));\n }\n const $parent = $spacer.parent();\n if (\n ($parent.is(\"td\") || $parent.is(\"th\")) &&\n !isStructureCell($parent as Cheerio<Element>)\n ) {\n return readPadding(parseStyleAttribute($parent.attr(\"style\")));\n }\n return { ...ZERO };\n}\n\n/**\n * No align and no margin is unset. A partial Stripo line with neither sits on\n * the left; the caller supplies that default.\n */\nfunction specifiedAlign(\n $el: Cheerio<Element>,\n): \"left\" | \"center\" | \"right\" | undefined {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n const alignAttr = ($el.attr(\"align\") ?? \"\").trim().toLowerCase();\n const alignKnown =\n alignAttr === \"left\" || alignAttr === \"center\" || alignAttr === \"right\";\n const hasMargin =\n styles.margin !== undefined ||\n styles[\"margin-left\"] !== undefined ||\n styles[\"margin-right\"] !== undefined;\n if (!alignKnown && !hasMargin) return undefined;\n\n let left = \"auto\";\n let right = \"auto\";\n if (alignAttr === \"left\") left = \"0\";\n if (alignAttr === \"right\") right = \"0\";\n\n const margin = (styles.margin ?? \"\").trim().split(/\\s+/).filter(Boolean);\n if (margin.length > 0) {\n right = margin[1] ?? margin[0];\n left = margin.length === 4 ? margin[3] : right;\n }\n if (styles[\"margin-left\"] !== undefined) left = styles[\"margin-left\"];\n if (styles[\"margin-right\"] !== undefined) right = styles[\"margin-right\"];\n\n const isAuto = (value: string) => value.trim().toLowerCase() === \"auto\";\n if (isAuto(left) && isAuto(right)) return \"center\";\n return isAuto(left) ? \"right\" : \"left\";\n}\n\nfunction placementOf(\n $spacer: Cheerio<Element>,\n $root: Cheerio<Element>,\n): \"left\" | \"center\" | \"right\" {\n const own = specifiedAlign($spacer);\n if (own) return own;\n for (const $candidate of [$spacer.parent(), $root.parent()]) {\n if (!$candidate.is(\"td\") && !$candidate.is(\"th\")) continue;\n const fromCell = specifiedAlign($candidate as Cheerio<Element>);\n if (fromCell) return fromCell;\n }\n return \"left\";\n}\n\nfunction spacerHeight($el: Cheerio<Element>): number {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n const fromStyle = parsePxValue(styles.height);\n if (fromStyle > 0) return fromStyle;\n const fromAttr = parsePxValue($el.attr(\"height\"));\n if (fromAttr > 0) return fromAttr;\n const pad = readPadding(styles);\n const vertical = pad.top + pad.bottom;\n return vertical > 0 ? vertical : 24;\n}\n\nfunction dividerBlock(\n border: ParsedBorder,\n padding: SpacingValue,\n width: DividerBlock[\"width\"],\n): Block {\n const lineStyle =\n border.style === \"dashed\" || border.style === \"dotted\"\n ? border.style\n : \"solid\";\n return createDividerBlock({\n lineStyle,\n color: border.color || \"#e5e7eb\",\n thickness: border.width,\n width,\n styles: { padding },\n });\n}\n\n/**\n * A bordered spacer is a divider. `room` is the column width the line can\n * span, after the section padding that column owns.\n */\nexport function spacerFrom(\n $el: Cheerio<Element>,\n sourceTag: string,\n ctx: ConvertCtx,\n $: CheerioAPI,\n room?: number,\n): Block {\n const $spacer = spacerElement($el);\n const border = lineBorder($el, $spacer, $);\n if (!border) {\n const height = spacerHeight($spacer);\n pushEntry(ctx, sourceTag, \"spacer\", \"converted\");\n return createSpacerBlock({ height });\n }\n\n const padding = dividerPadding($el, $spacer);\n const styles = parseStyleAttribute($spacer.attr(\"style\"));\n const raw = (styles.width ?? $spacer.attr(\"width\") ?? \"\").trim();\n const notes: string[] = [];\n const width = readDividerWidth(raw, room, padding.left, padding.right, notes);\n if (MAPPED_LINE_STYLES.has(border.style)) {\n notes.push(`Divider border style \"${border.style}\" was imported as solid.`);\n }\n if (width !== \"full\") {\n const align = placementOf($spacer, $el);\n if (align !== \"center\") {\n notes.push(\n `The source aligns this divider ${align}; Templatical centres every divider.`,\n );\n }\n }\n pushEntry(\n ctx,\n sourceTag,\n \"divider\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n return dividerBlock(border, padding, width);\n}\n\nfunction menuItems($table: Cheerio<Element>, $: CheerioAPI): MenuItemData[] {\n const items: MenuItemData[] = [];\n $table.find(\"td\").each((_, td) => {\n const $td = $(td) as Cheerio<Element>;\n if (isHidden($td)) return;\n const $a = $td.find(\"a\").first();\n if (!$a.length) return;\n const text = ($a.text() ?? \"\").trim();\n if (!text) return;\n items.push({\n id: generateId(),\n text,\n url: $a.attr(\"href\") ?? \"#\",\n openInNewTab: $a.attr(\"target\") === \"_blank\",\n bold: false,\n underline: false,\n });\n });\n return items;\n}\n\n/**\n * A compiled/editor `table.es-menu` / `esd-block-menu` is a MenuBlock only\n * when one row holds two or more item cells. A single 100% cell is a stacked\n * step (Password reset) and must fall through.\n */\nexport function menuFrom(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block | null {\n const $table = $el.is(\"table\") ? $el : $el.find(\"table\").first();\n const $row = $table.find(\"tr\").first();\n const itemCells = $row\n .children(\"td\")\n .toArray()\n .filter((td) => !isHidden($(td) as Cheerio<Element>));\n if (itemCells.length < 2) return null;\n const items = menuItems($table, $);\n if (items.length < 2) return null;\n pushEntry(ctx, sourceTag, \"menu\", \"converted\");\n return createMenuBlock({ items });\n}\n\nexport function socialFrom(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block {\n const icons: SocialIcon[] = [];\n $el.find(\"a\").each((_, a) => {\n const $a = $(a) as Cheerio<Element>;\n const $img = $a.find(\"img\").first();\n const url = $a.attr(\"href\") ?? \"#\";\n const platform = normalizePlatform(\n $img.attr(\"title\"),\n $img.attr(\"src\"),\n $img.attr(\"alt\"),\n );\n icons.push({ id: generateId(), platform, url });\n });\n pushEntry(ctx, sourceTag, \"social\", \"converted\");\n return createSocialIconsBlock({ icons });\n}\n\nexport function labelledInnerBlocks(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block[] {\n return blocksFromHtml($.html($el) ?? \"\", ctx);\n}\n","import { load, type Cheerio, type CheerioAPI } from \"cheerio\";\nimport type { AnyNode, Element } from \"domhandler\";\nimport { createSectionBlock } from \"@templatical/types\";\nimport type { Block, ColumnLayout, SpacingValue } from \"@templatical/types\";\nimport { hasAnyToken, hasToken, isHidden } from \"./classes\";\nimport {\n colorFromPaint,\n columnRooms,\n emailBodyWidth,\n readBoxPadding,\n resolveSectionImage,\n resolveSectionPaint,\n withoutBandOverImage,\n type ImageLayer,\n type ReadBackgroundImage,\n type SectionPaint,\n} from \"./css\";\nimport {\n bandImage,\n blocksFromHtml,\n imageLayer,\n imageOf,\n pushEntry,\n recordImageSpan,\n withBackground,\n type ConvertCtx,\n} from \"./fragment\";\nimport { buttonFrom, menuFrom, socialFrom, spacerFrom } from \"./labelled\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\nconst COLUMN_TOKENS = [\"es-left\", \"es-right\"] as const;\nconst STRIPE_TOKENS = [\"es-header\", \"es-content\", \"es-footer\"] as const;\nconst BODY_SELECTOR =\n \"[class~='es-header-body'], [class~='es-content-body'], [class~='es-footer-body']\";\n\nconst BETWEEN_NOTE = \"Content between columns was placed after them.\";\nconst SEAM_NOTE = \"This row's padding was split across more than one section.\";\n\ntype WidgetKind = \"menu\" | \"social\" | \"button\" | \"spacer\";\n\ntype Piece =\n { kind: \"flow\"; nodes: AnyNode[] } | { kind: \"column\"; el: Element };\n\nfunction paintOf($el: Cheerio<Element>): string {\n return colorFromPaint($el.attr(\"style\"), $el.attr(\"bgcolor\"));\n}\n\nfunction stripeToken($el: Cheerio<Element>): string | undefined {\n return STRIPE_TOKENS.find((token) => hasToken($el, token));\n}\n\nfunction topStripes($: CheerioAPI): Cheerio<Element>[] {\n const out: Cheerio<Element>[] = [];\n $(\"[class]\").each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n if (!stripeToken($el)) return;\n const nested = $el\n .parents()\n .toArray()\n .some((parent) =>\n hasAnyToken($(parent) as Cheerio<Element>, STRIPE_TOKENS),\n );\n if (nested) return;\n out.push($el);\n });\n return out;\n}\n\nfunction directRows(\n $table: Cheerio<Element>,\n $: CheerioAPI,\n): Cheerio<Element>[] {\n const $direct = $table.children(\"tr\");\n const $nested = $table.children(\"tbody, thead, tfoot\").children(\"tr\");\n const $rows = $direct.length > 0 ? $direct : $nested;\n return $rows.toArray().map((node) => $(node) as Cheerio<Element>);\n}\n\nfunction directCell($table: Cheerio<Element>): Cheerio<Element> {\n const $direct = $table.children(\"tr\").children(\"td, th\");\n const $nested = $table\n .children(\"tbody, thead, tfoot\")\n .children(\"tr\")\n .children(\"td, th\");\n return ($direct.length > 0 ? $direct : $nested).first() as Cheerio<Element>;\n}\n\n/** Paint on the stripe table, else on its cell. A `td` stripe is its own paint. */\nfunction bandColor($stripe: Cheerio<Element>): string {\n const own = paintOf($stripe);\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return \"\";\n const $cell = directCell($stripe);\n return $cell.length > 0 ? paintOf($cell) : \"\";\n}\n\n/** A column's image: on its `es-left` / `es-right` table, else on that table's cell. */\nfunction columnImage(\n $column: Cheerio<Element>,\n boxWidth: number,\n): ReadBackgroundImage | null {\n const own = imageOf($column, \"Column\", boxWidth);\n if (own) return own;\n const $cell = directCell($column);\n return $cell.length > 0 ? imageOf($cell, \"Column\", boxWidth) : null;\n}\n\ninterface StripeImages {\n body: ImageLayer | null;\n band: ImageLayer | null;\n bodyPainted: boolean;\n}\n\nfunction hasPadding(padding: SpacingValue): boolean {\n return (\n padding.top !== 0 ||\n padding.right !== 0 ||\n padding.bottom !== 0 ||\n padding.left !== 0\n );\n}\n\nfunction splitPadding(\n padding: SpacingValue,\n count: number,\n index: number,\n): SpacingValue {\n if (count <= 1) return { ...padding };\n return {\n top: index === 0 ? padding.top : 0,\n right: padding.right,\n bottom: index === count - 1 ? padding.bottom : 0,\n left: padding.left,\n };\n}\n\nfunction isColumn($el: Cheerio<Element>): boolean {\n return $el.is(\"table\") && hasAnyToken($el, COLUMN_TOKENS);\n}\n\nfunction containsColumn($el: Cheerio<Element>, $: CheerioAPI): boolean {\n const stop = $el[0];\n let found = false;\n $el.find(\"table\").each((_, node) => {\n if (found) return;\n const $n = $(node) as Cheerio<Element>;\n if (!hasAnyToken($n, COLUMN_TOKENS)) return;\n let $parent = $n.parent();\n while ($parent.length > 0 && $parent[0] !== stop) {\n if (hasAnyToken($parent as Cheerio<Element>, COLUMN_TOKENS)) return;\n $parent = $parent.parent();\n }\n found = true;\n });\n return found;\n}\n\n/**\n * Columns in one cell are one section. Flow before them, between them and\n * after them becomes its own one-column section, in that order.\n */\nfunction collectPieces($root: Cheerio<Element>, $: CheerioAPI): Piece[] {\n const pieces: Piece[] = [];\n const walk = ($parent: Cheerio<Element>) => {\n const flow: AnyNode[] = [];\n const flush = () => {\n if (flow.length === 0) return;\n pieces.push({ kind: \"flow\", nodes: flow.splice(0, flow.length) });\n };\n for (const node of $parent.contents().toArray()) {\n if (node.type === \"text\") {\n if (node.data.trim()) flow.push(node);\n continue;\n }\n if (node.type !== \"tag\") continue;\n const $el = $(node) as Cheerio<Element>;\n if (isHidden($el)) continue;\n if (isColumn($el)) {\n flush();\n pieces.push({ kind: \"column\", el: node });\n continue;\n }\n if (containsColumn($el, $)) {\n flush();\n walk($el);\n continue;\n }\n flow.push(node);\n }\n flush();\n };\n walk($root);\n return pieces;\n}\n\nfunction widgetKind($el: Cheerio<Element>): WidgetKind | null {\n if (hasToken($el, \"es-menu\")) {\n if (!$el.is(\"table\") && $el.find(\"table\").length > 0) return null;\n return \"menu\";\n }\n if (hasToken($el, \"es-social\")) return \"social\";\n if (hasToken($el, \"es-button\")) {\n if ($el.is(\"a\") || $el.find(\"a\").length > 0) return \"button\";\n return null;\n }\n if (hasToken($el, \"es-spacer\")) return \"spacer\";\n return null;\n}\n\nfunction containsWidget($el: Cheerio<Element>, $: CheerioAPI): boolean {\n let found = false;\n $el.find(\"[class]\").each((_, node) => {\n if (found) return;\n if (widgetKind($(node) as Cheerio<Element>)) found = true;\n });\n return found;\n}\n\nfunction widgetBlocks(\n $el: Cheerio<Element>,\n kind: WidgetKind,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room: number | undefined,\n): Block[] {\n if (kind === \"button\") return [buttonFrom($el, \"es-button\", ctx)];\n if (kind === \"spacer\") return [spacerFrom($el, \"es-spacer\", ctx, $, room)];\n if (kind === \"social\") return [socialFrom($el, $, \"es-social\", ctx)];\n const menu = menuFrom($el, $, \"es-menu\", ctx);\n if (menu) return [menu];\n return blocksFromHtml($.html($el) ?? \"\", ctx);\n}\n\n/** Widgets stay where they sit. A run of everything else goes through HTML import. */\nfunction convertRegion(\n nodes: AnyNode[],\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const out: Block[] = [];\n let pending = \"\";\n const flush = () => {\n if (!pending.trim()) {\n pending = \"\";\n return;\n }\n out.push(...blocksFromHtml(pending, ctx));\n pending = \"\";\n };\n const visit = (node: AnyNode) => {\n if (node.type === \"text\") {\n if (node.data.trim()) pending += node.data;\n return;\n }\n if (node.type !== \"tag\") return;\n const $el = $(node) as Cheerio<Element>;\n if ($el.is(\"head, style, script\")) return;\n if (isHidden($el)) return;\n const kind = widgetKind($el);\n if (kind) {\n flush();\n out.push(...widgetBlocks($el, kind, $, ctx, room));\n return;\n }\n if (containsWidget($el, $)) {\n for (const child of $el.contents().toArray()) visit(child);\n return;\n }\n pending += $.html(node) ?? \"\";\n };\n for (const node of nodes) visit(node);\n flush();\n return out;\n}\n\nfunction regionFromElement(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n return convertRegion($el.contents().toArray(), $, ctx, room);\n}\n\nfunction hasBlocks(children: Block[][]): boolean {\n return children.some((column) => column.length > 0);\n}\n\nfunction columnChildren(\n cols: Element[],\n $: CheerioAPI,\n ctx: ConvertCtx,\n bodyWidth: number,\n padding: SpacingValue,\n): { children: Block[][]; layout: ColumnLayout; flattenNote?: string } | null {\n const count = cols.length;\n const layout: ColumnLayout = count >= 3 ? \"3\" : count === 2 ? \"2\" : \"1\";\n const used = count >= 4 ? 3 : layout === \"1\" ? 1 : count;\n const rooms = columnRooms(\n bodyWidth,\n count >= 4 ? \"3\" : layout,\n padding,\n used,\n );\n let children: Block[][];\n if (count >= 4) {\n const rest: Block[] = [];\n for (const el of cols.slice(2)) {\n rest.push(\n ...regionFromElement($(el) as Cheerio<Element>, $, ctx, rooms[2]),\n );\n }\n children = [\n regionFromElement($(cols[0]) as Cheerio<Element>, $, ctx, rooms[0]),\n regionFromElement($(cols[1]) as Cheerio<Element>, $, ctx, rooms[1]),\n rest,\n ];\n } else {\n children = cols.map((el, index) =>\n regionFromElement($(el) as Cheerio<Element>, $, ctx, rooms[index]),\n );\n }\n if (!hasBlocks(children)) return null;\n if (count < 4) return { children, layout: count >= 3 ? \"3\" : layout };\n const flattenNote = `Row with ${count} columns was flattened; extra columns merged into the third slot. Templatical supports up to 3 columns per section.`;\n ctx.warnings.push(flattenNote);\n return { children, layout: \"3\", flattenNote };\n}\n\nfunction flowNodes(pieces: Piece[]): AnyNode[] {\n return pieces.flatMap((piece) => (piece.kind === \"flow\" ? piece.nodes : []));\n}\n\nfunction groupsFromPieces(\n pieces: Piece[],\n): Array<{ mode: \"flow\" | \"columns\"; pieces: Piece[]; extra?: string }> {\n const columns = pieces.filter((piece) => piece.kind === \"column\");\n if (columns.length === 0) {\n return pieces.length > 0 ? [{ mode: \"flow\", pieces }] : [];\n }\n let first = -1;\n let last = -1;\n pieces.forEach((piece, index) => {\n if (piece.kind !== \"column\") return;\n if (first === -1) first = index;\n last = index;\n });\n const groups: Array<{\n mode: \"flow\" | \"columns\";\n pieces: Piece[];\n extra?: string;\n }> = [];\n const leading = pieces.slice(0, first);\n if (leading.length > 0) groups.push({ mode: \"flow\", pieces: leading });\n groups.push({ mode: \"columns\", pieces: columns });\n const between = pieces\n .slice(first + 1, last)\n .filter((piece) => piece.kind === \"flow\");\n if (between.length > 0) {\n groups.push({ mode: \"flow\", pieces: between, extra: BETWEEN_NOTE });\n }\n const trailing = pieces.slice(last + 1);\n if (trailing.length > 0) groups.push({ mode: \"flow\", pieces: trailing });\n return groups;\n}\n\nfunction sectionsFromRow(\n $row: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n token: string,\n paint: SectionPaint,\n images: StripeImages,\n bodyWidth: number,\n): Block[] {\n if (isHidden($row)) return [];\n const pieces: Piece[] = [];\n let padding = { ...ZERO };\n let sawCell = false;\n let $structure: Cheerio<Element> | null = null;\n $row.children(\"td, th\").each((_, cell) => {\n const $cell = $(cell) as Cheerio<Element>;\n if (isHidden($cell)) return;\n if (!sawCell) {\n padding = readBoxPadding($cell.attr(\"class\"), $cell.attr(\"style\"));\n sawCell = true;\n $structure = $cell;\n }\n pieces.push(...collectPieces($cell, $));\n });\n if (!sawCell || pieces.length === 0) return [];\n\n const rendered: Array<{\n children: Block[][];\n layout: ColumnLayout;\n extra?: string;\n columnImages: Array<ReadBackgroundImage | null>;\n }> = [];\n for (const group of groupsFromPieces(pieces)) {\n if (group.mode === \"columns\") {\n const cols = group.pieces.flatMap((piece) =>\n piece.kind === \"column\" ? [piece.el] : [],\n );\n const built = columnChildren(cols, $, ctx, bodyWidth, padding);\n if (!built) continue;\n rendered.push({\n children: built.children,\n layout: built.layout,\n extra: built.flattenNote,\n columnImages: cols.map((el) =>\n columnImage($(el) as Cheerio<Element>, bodyWidth),\n ),\n });\n continue;\n }\n const blocks = convertRegion(\n flowNodes(group.pieces),\n $,\n ctx,\n columnRooms(bodyWidth, \"1\", padding, 1)[0],\n );\n if (blocks.length === 0) continue;\n rendered.push({\n children: [blocks],\n layout: \"1\",\n extra: group.extra,\n columnImages: [],\n });\n }\n if (rendered.length === 0) return [];\n\n const seam =\n rendered.length > 1 && hasPadding(padding) ? SEAM_NOTE : undefined;\n const structure = imageLayer($structure, \"Section\", bodyWidth);\n return rendered.map((group, index) => {\n const image = resolveSectionImage({\n structure,\n body: images.body,\n band: images.band,\n columns: group.columnImages,\n bodyPainted: images.bodyPainted,\n });\n const groupPaint = withoutBandOverImage(paint, image.image !== undefined);\n const notes = [\n ...groupPaint.notes,\n group.extra,\n ...image.notes,\n seam,\n ].filter((note): note is string => Boolean(note));\n const entry = pushEntry(\n ctx,\n token,\n \"section\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n recordImageSpan(ctx, image.source, entry);\n const section = createSectionBlock({\n columns: group.layout,\n children: group.children,\n styles: { padding: splitPadding(padding, rendered.length, index) },\n ...(groupPaint.wrapperColor\n ? { wrapper: { backgroundColor: groupPaint.wrapperColor } }\n : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, groupPaint.backgroundColor);\n });\n}\n\nfunction sectionsFromStripe(\n $stripe: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block[] {\n if (isHidden($stripe)) return [];\n const token = stripeToken($stripe) ?? \"es-content\";\n const $body = $stripe.find(BODY_SELECTOR).first() as Cheerio<Element>;\n const rows = $body.length > 0 ? directRows($body, $) : directRows($stripe, $);\n const $width = $body.length > 0 ? $body : $stripe;\n const bodyWidth = emailBodyWidth($width.attr(\"width\"), $width.attr(\"style\"));\n const paint = resolveSectionPaint(\n ctx.pageBackground ?? \"#ffffff\",\n bandColor($stripe),\n $body.length > 0 ? paintOf($body) : \"\",\n );\n const images: StripeImages = {\n body: imageLayer($body, \"Section\", bodyWidth),\n band: bandImage($stripe, directCell($stripe), bodyWidth),\n bodyPainted: $body.length > 0 && paintOf($body) !== \"\",\n };\n const out: Block[] = [];\n for (const $row of rows) {\n out.push(...sectionsFromRow($row, $, ctx, token, paint, images, bodyWidth));\n }\n return out;\n}\n\nexport function convertCompiled(html: string, ctx: ConvertCtx): Block[] {\n const $ = load(html);\n const stripes = topStripes($);\n if (stripes.length === 0) {\n return convertRegion($.root().contents().toArray(), $, ctx);\n }\n const out: Block[] = [];\n for (const $stripe of stripes)\n out.push(...sectionsFromStripe($stripe, $, ctx));\n return out;\n}\n","const EDITOR_TOKENS = new Set([\n \"esd-stripe\",\n \"esd-structure\",\n \"esd-container-frame\",\n]);\n\nconst COMPILED_TOKENS = new Set([\n \"es-wrapper\",\n \"es-content-body\",\n \"es-header-body\",\n]);\n\nexport type StripoKind = \"editor\" | \"compiled\";\n\nfunction isTagNameEnd(ch: string | undefined): boolean {\n return ch === undefined || !/[A-Za-z0-9_]/.test(ch);\n}\n\n/**\n * Drop every `tag` element, including a closer with extra attributes or\n * whitespace (`</style >`, `</script foo>`). Linear `indexOf` — a regex\n * here fails `js/bad-tag-filter` or `js/polynomial-redos`, and Cheerio\n * rewrites a bare `<td>` fragment and would drop the attributes we need.\n */\nfunction withoutElements(html: string, tag: string): string {\n const open = `<${tag}`;\n const close = `</${tag}`;\n const lower = html.toLowerCase();\n let out = \"\";\n let pos = 0;\n while (pos < html.length) {\n const start = lower.indexOf(open, pos);\n if (start === -1) {\n out += html.slice(pos);\n break;\n }\n if (!isTagNameEnd(lower[start + open.length])) {\n out += html.slice(pos, start + open.length);\n pos = start + open.length;\n continue;\n }\n out += html.slice(pos, start);\n const gt = html.indexOf(\">\", start);\n if (gt === -1) break;\n const closeAt = lower.indexOf(close, gt + 1);\n if (closeAt === -1) break;\n const closeGt = html.indexOf(\">\", closeAt);\n if (closeGt === -1) break;\n out += \" \";\n pos = closeGt + 1;\n }\n return out;\n}\n\n/**\n * Class tokens from attributes only. Stylesheets and scripts are dropped\n * first so a compiled leftover `.esd-block-html table` rule cannot trip\n * editor detection.\n */\nfunction markupClassTokens(html: string): string[] {\n const stripped = withoutElements(withoutElements(html, \"style\"), \"script\");\n const tokens: string[] = [];\n const re = /\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/gi;\n let m: RegExpExecArray | null;\n while ((m = re.exec(stripped))) {\n tokens.push(...m[2].trim().split(/\\s+/).filter(Boolean));\n }\n return tokens;\n}\n\nfunction isEditorToken(token: string): boolean {\n return EDITOR_TOKENS.has(token) || token.startsWith(\"esd-block-\");\n}\n\n/**\n * Which Stripo HTML surface this is, or null if it is not Stripo markup.\n *\n * Editor-source (`getTemplateData`) carries `esd-*` on elements. Compiled\n * export carries `es-wrapper` / `es-*-body` and never `esd-*` on a class\n * attribute. A CSS-only leftover (`.esd-block-html` in a stylesheet) is not\n * a discriminator — stylesheets are stripped before the check.\n */\nexport function detectStripoKind(html: string): StripoKind | null {\n if (typeof html !== \"string\" || html.trim().length === 0) return null;\n const tokens = markupClassTokens(html);\n if (tokens.some(isEditorToken)) return \"editor\";\n if (tokens.some((t) => COMPILED_TOKENS.has(t))) return \"compiled\";\n return null;\n}\n\nexport function isStripoHtml(html: string): boolean {\n return detectStripoKind(html) !== null;\n}\n","import { load, type Cheerio, type CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport { createHtmlBlock, createSectionBlock } from \"@templatical/types\";\nimport type { Block, SpacingValue } from \"@templatical/types\";\nimport { isHidden, tokenStartingWith, topLevelWithToken } from \"./classes\";\nimport {\n colorFromPaint,\n columnRooms,\n emailBodyWidth,\n readBoxPadding,\n resolveSectionImage,\n resolveSectionPaint,\n withoutBandOverImage,\n type SectionPaint,\n} from \"./css\";\nimport {\n bandImage,\n imageLayer,\n imageOf,\n pushEntry,\n recordImageSpan,\n withBackground,\n type ConvertCtx,\n} from \"./fragment\";\nimport {\n buttonFrom,\n labelledInnerBlocks,\n menuFrom,\n socialFrom,\n spacerFrom,\n} from \"./labelled\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\nconst BODY_SELECTOR =\n \"[class~='es-header-body'], [class~='es-content-body'], [class~='es-footer-body']\";\n\nfunction columnLayout(\n count: number,\n ctx: ConvertCtx,\n): { layout: \"1\" | \"2\" | \"3\"; flattenNote?: string } {\n if (count <= 1) return { layout: \"1\" };\n if (count === 2) return { layout: \"2\" };\n if (count === 3) return { layout: \"3\" };\n const flattenNote = `Row with ${count} columns was flattened to a single column. Templatical supports up to 3 columns per section.`;\n ctx.warnings.push(flattenNote);\n return { layout: \"1\", flattenNote };\n}\n\nfunction esdBlockKind($el: Cheerio<Element>): string | undefined {\n const token = tokenStartingWith($el, \"esd-block-\");\n return token ? token.slice(\"esd-block-\".length) : undefined;\n}\n\nfunction convertEsdBlock(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const kind = esdBlockKind($el);\n if (!kind) return labelledInnerBlocks($el, $, ctx);\n if (kind === \"button\") return [buttonFrom($el, \"esd-block-button\", ctx)];\n if (kind === \"spacer\")\n return [spacerFrom($el, \"esd-block-spacer\", ctx, $, room)];\n if (kind === \"social\") return [socialFrom($el, $, \"esd-block-social\", ctx)];\n if (kind === \"menu\") {\n const menu = menuFrom($el, $, \"esd-block-menu\", ctx);\n if (menu) return [menu];\n return labelledInnerBlocks($el, $, ctx);\n }\n if (kind === \"html\") {\n pushEntry(\n ctx,\n \"esd-block-html\",\n \"html\",\n \"html-fallback\",\n \"HTML block preserved as HTML.\",\n );\n return [createHtmlBlock({ content: ($el.html() ?? \"\").trim() })];\n }\n // image / text / anything else: generic HTML mapping of the inner markup\n pushEntry(\n ctx,\n `esd-block-${kind}`,\n kind === \"image\" ? \"image\" : \"paragraph\",\n \"converted\",\n );\n return labelledInnerBlocks($el, $, ctx);\n}\n\nfunction blocksInContainer(\n $frame: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const out: Block[] = [];\n const seen = new Set<Element>();\n $frame.find(\"[class]\").each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n if (!tokenStartingWith($el, \"esd-block-\")) return;\n const nested = $el\n .parents()\n .toArray()\n .some((p) => tokenStartingWith($(p) as Cheerio<Element>, \"esd-block-\"));\n if (nested) return;\n if (seen.has(node)) return;\n seen.add(node);\n out.push(...convertEsdBlock($el, $, ctx, room));\n });\n if (out.length === 0) return labelledInnerBlocks($frame, $, ctx);\n return out;\n}\n\nfunction enclosing(\n $el: Cheerio<Element>,\n selector: string,\n): Cheerio<Element> | null {\n if ($el.is(selector)) return $el;\n const $parent = $el.parents(selector).first();\n return $parent.length > 0 ? ($parent as Cheerio<Element>) : null;\n}\n\n/** A table stripe's first cell, which Stripo paints instead of the table. */\nfunction bandCell($stripe: Cheerio<Element>): Cheerio<Element> {\n const $direct = $stripe.children(\"tr\").children(\"td, th\");\n const $nested = $stripe\n .children(\"tbody, thead\")\n .children(\"tr\")\n .children(\"td, th\");\n return ($direct.length > 0 ? $direct : $nested).first() as Cheerio<Element>;\n}\n\nfunction bandColor($stripe: Cheerio<Element>): string {\n const own = colorFromPaint($stripe.attr(\"style\"), $stripe.attr(\"bgcolor\"));\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return \"\";\n const $cell = bandCell($stripe);\n return $cell.length > 0\n ? colorFromPaint($cell.attr(\"style\"), $cell.attr(\"bgcolor\"))\n : \"\";\n}\n\nfunction paintFor($el: Cheerio<Element>, ctx: ConvertCtx): SectionPaint {\n const $stripe = enclosing($el, \"[class~='esd-stripe']\");\n const $body = enclosing($el, BODY_SELECTOR);\n return resolveSectionPaint(\n ctx.pageBackground ?? \"#ffffff\",\n $stripe ? bandColor($stripe) : \"\",\n $body ? colorFromPaint($body.attr(\"style\"), $body.attr(\"bgcolor\")) : \"\",\n );\n}\n\nfunction sectionFromStructure(\n $structure: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block {\n const frames = $structure\n .find(\"[class~='esd-container-frame']\")\n .toArray()\n .map((n) => $(n) as Cheerio<Element>)\n .filter(($el) => {\n if (isHidden($el)) return false;\n return (\n $el.parents(\"[class~='esd-container-frame']\").filter((_, p) => {\n return $(p).closest($structure).length > 0;\n }).length === 0\n );\n });\n\n const frameCount = frames.length;\n const { layout, flattenNote } = columnLayout(\n frameCount === 0 ? 1 : frameCount,\n ctx,\n );\n const padding = readBoxPadding(\n $structure.attr(\"class\"),\n $structure.attr(\"style\"),\n );\n const $body = enclosing($structure, BODY_SELECTOR);\n const bodyWidth = emailBodyWidth($body?.attr(\"width\"), $body?.attr(\"style\"));\n const rooms = columnRooms(\n bodyWidth,\n layout,\n padding,\n layout === \"1\" ? 1 : Math.min(frameCount, 3),\n );\n let children: Block[][];\n if (layout === \"1\") {\n const merged: Block[] = [];\n const room = rooms[0];\n if (frames.length === 0) {\n merged.push(...blocksInContainer($structure, $, ctx, room));\n } else {\n for (const $f of frames)\n merged.push(...blocksInContainer($f, $, ctx, room));\n }\n children = [merged];\n } else {\n children = frames.map(($f, index) =>\n blocksInContainer($f, $, ctx, rooms[index]),\n );\n }\n const $stripe = enclosing($structure, \"[class~='esd-stripe']\");\n const image = resolveSectionImage({\n structure: imageLayer($structure, \"Section\", bodyWidth),\n body: imageLayer($body, \"Section\", bodyWidth),\n band: $stripe ? bandImage($stripe, bandCell($stripe), bodyWidth) : null,\n columns: frames.map(($f) => imageOf($f, \"Column\", bodyWidth)),\n bodyPainted: $body\n ? colorFromPaint($body.attr(\"style\"), $body.attr(\"bgcolor\")) !== \"\"\n : false,\n });\n const paint = withoutBandOverImage(\n paintFor($structure, ctx),\n image.image !== undefined,\n );\n const notes = [...paint.notes, flattenNote, ...image.notes].filter(\n (note): note is string => Boolean(note),\n );\n if (notes.length > 0) {\n const entry = pushEntry(\n ctx,\n \"esd-structure\",\n \"section\",\n \"approximated\",\n notes.join(\" \"),\n );\n recordImageSpan(ctx, image.source, entry);\n } else if (frameCount <= 3) {\n const entry = pushEntry(ctx, \"esd-structure\", \"section\", \"converted\");\n recordImageSpan(ctx, image.source, entry);\n }\n const section = createSectionBlock({\n columns: layout,\n children,\n styles: { padding },\n ...(paint.wrapperColor\n ? { wrapper: { backgroundColor: paint.wrapperColor } }\n : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, paint.backgroundColor);\n}\n\nexport function convertEditor(html: string, ctx: ConvertCtx): Block[] {\n const $ = load(html);\n const structures = topLevelWithToken($, \"esd-structure\");\n if (structures.length > 0) {\n return structures.map(($s) => sectionFromStructure($s, $, ctx));\n }\n const stripes = topLevelWithToken($, \"esd-stripe\");\n if (stripes.length === 0) {\n return labelledInnerBlocks($.root() as unknown as Cheerio<Element>, $, ctx);\n }\n return stripes.map(($stripe) => {\n const inner = $stripe.find(\"[class~='esd-structure']\");\n if (inner.length > 0) {\n return sectionFromStructure(inner.first() as Cheerio<Element>, $, ctx);\n }\n const image = resolveSectionImage({\n structure: null,\n body: null,\n band: bandImage($stripe, bandCell($stripe), 600),\n columns: [],\n bodyPainted: false,\n });\n const paint = withoutBandOverImage(\n paintFor($stripe, ctx),\n image.image !== undefined,\n );\n const notes = [...paint.notes, ...image.notes].filter(\n (note): note is string => Boolean(note),\n );\n const entry = pushEntry(\n ctx,\n \"esd-stripe\",\n \"section\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n recordImageSpan(ctx, image.source, entry);\n const section = createSectionBlock({\n columns: \"1\",\n children: [\n blocksInContainer($stripe, $, ctx, columnRooms(600, \"1\", ZERO, 1)[0]),\n ],\n styles: { padding: { ...ZERO } },\n ...(paint.wrapperColor\n ? { wrapper: { backgroundColor: paint.wrapperColor } }\n : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, paint.backgroundColor);\n });\n}\n","import { load, type CheerioAPI } from \"cheerio\";\nimport { convertHtmlTemplate } from \"@templatical/import-html\";\nimport type { ImportReport, ImportResult } from \"@templatical/import-html\";\nimport { createDefaultTemplateContent, isLocaleTag } from \"@templatical/types\";\nimport { convertCompiled } from \"./compiled\";\nimport { colorFromPaint, imageFromPaint } from \"./css\";\nimport { detectStripoKind } from \"./detect\";\nimport { convertEditor } from \"./editor\";\nimport { noteImageSpans, type ConvertCtx } from \"./fragment\";\n\nexport interface ConvertStripoOptions {\n /** Used when the source declares no default language. */\n defaultLocale?: string;\n /** Sibling CSS from plugin `getTemplateData()`. Applied inside each HTML fragment. */\n css?: string;\n}\n\n/**\n * The default language, as `convertHtmlTemplate` reads it: `<html lang>`, else\n * `defaultLocale`, else `\"en\"`. A value that isn't a language tag after `_` →\n * `-` is skipped, with a warning naming it. The fallback converter warns on its\n * own report, so the Stripo path repeats the check for its report.\n */\nfunction defaultLanguage(\n declared: string | undefined,\n defaultLocale: string | undefined,\n warnings: string[],\n): string {\n const rejected: string[] = [];\n let locale = \"en\";\n for (const [value, name] of [\n [declared, \"the source's default language\"],\n [defaultLocale, \"defaultLocale\"],\n ] as const) {\n if (!value) continue;\n const tag = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(tag)) {\n locale = tag;\n break;\n }\n rejected.push(`Ignored ${name} \"${value}\": unsupported language tag.`);\n }\n for (const message of rejected) warnings.push(`${message} Used \"${locale}\".`);\n return locale;\n}\n\nfunction injectCss(html: string, css?: string): string {\n if (!css || css.trim().length === 0) return html;\n const $ = load(html);\n if ($(\"head\").length === 0) {\n $(\"html\").prepend(\"<head></head>\");\n }\n // Style elements serialize as HTML rawtext, so a literal `</style` in the\n // CSS would close the element and the rest would parse as markup — which\n // can flip editor/compiled detection. Neutralize the closer; then set a\n // text node rather than interpolating into an HTML string.\n const safe = css.replace(/<\\/style/gi, \"<\\\\/style\");\n const $style = $(\"<style></style>\").attr(\"data-stripo-css\", \"1\").text(safe);\n $(\"head\").append($style);\n return $.html() ?? html;\n}\n\n/** First painted `es-wrapper-color` / `es-wrapper`, or white when neither is set. */\nfunction pageBackground($: CheerioAPI): string {\n const nodes = $(\n \"[class~='es-wrapper-color'], [class~='es-wrapper']\",\n ).toArray();\n for (const node of nodes) {\n const $el = $(node);\n const color = colorFromPaint($el.attr(\"style\"), $el.attr(\"bgcolor\"));\n if (color) return color;\n }\n return \"#ffffff\";\n}\n\n/** The page's background image, which has no Templatical equivalent: the first `es-wrapper-color` / `es-wrapper` that paints one. */\nfunction pageImageWarning($: CheerioAPI): string | null {\n const nodes = $(\n \"[class~='es-wrapper-color'], [class~='es-wrapper']\",\n ).toArray();\n for (const node of nodes) {\n const $el = $(node);\n const read = imageFromPaint(\n $el.attr(\"style\"),\n $el.attr(\"background\"),\n \"Page\",\n undefined,\n );\n if (read) {\n return `The email background image \"${read.image.url}\" was dropped; Templatical has no email-level background image.`;\n }\n }\n return null;\n}\n\nfunction summarize(ctx: ConvertCtx): ImportReport {\n const summary = {\n total: ctx.entries.length,\n converted: 0,\n approximated: 0,\n htmlFallback: 0,\n skipped: 0,\n };\n for (const e of ctx.entries) {\n if (e.status === \"converted\") summary.converted++;\n else if (e.status === \"approximated\") summary.approximated++;\n else if (e.status === \"html-fallback\") summary.htmlFallback++;\n else if (e.status === \"skipped\") summary.skipped++;\n }\n return { entries: ctx.entries, warnings: ctx.warnings, summary };\n}\n\n/**\n * Convert a Stripo template to Templatical content.\n *\n * Auto-detects the surface from class attributes:\n * - `esd-*` on elements → plugin/editor `getTemplateData` HTML\n * - `es-wrapper` / `es-*-body` without `esd-*` → compiled File→HTML export\n *\n * Pass `options.css` when converting plugin storage (`getTemplateData().css`).\n */\nexport function convertStripoTemplate(\n html: string,\n options?: ConvertStripoOptions,\n): ImportResult {\n if (typeof html !== \"string\") {\n throw new Error(\n \"Invalid Stripo template: expected a string. Pass the HTML source as a string.\",\n );\n }\n if (html.trim().length === 0) {\n throw new Error(\n \"Invalid Stripo template: input is empty. Pass the HTML source of a Stripo email.\",\n );\n }\n\n const prepared = injectCss(html, options?.css);\n const kind = detectStripoKind(prepared);\n const fallback = convertHtmlTemplate(prepared, {\n defaultLocale: options?.defaultLocale,\n });\n\n if (!kind) {\n return {\n content: fallback.content,\n report: {\n ...fallback.report,\n warnings: [\n \"No Stripo class attributes found; converted as generic HTML.\",\n ...fallback.report.warnings,\n ],\n },\n };\n }\n\n const ctx: ConvertCtx = {\n entries: [],\n warnings: [],\n css: options?.css,\n };\n const $page = load(prepared);\n const locale = defaultLanguage(\n $page(\"html\").attr(\"lang\")?.trim(),\n options?.defaultLocale,\n ctx.warnings,\n );\n const pageBg = pageBackground($page);\n const pageImage = pageImageWarning($page);\n if (pageImage) ctx.warnings.push(pageImage);\n ctx.pageBackground = pageBg;\n const blocks =\n kind === \"editor\"\n ? convertEditor(prepared, ctx)\n : convertCompiled(prepared, ctx);\n noteImageSpans(ctx);\n\n // After `fallback.content`: its settings carry the HTML importer's white\n // page, which would hide the wrapper colour.\n const defaults = createDefaultTemplateContent();\n return {\n content: {\n ...defaults,\n ...fallback.content,\n blocks,\n settings: {\n ...defaults.settings,\n ...fallback.content.settings,\n locale,\n backgroundColor: pageBg,\n },\n },\n report: summarize(ctx),\n };\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,KAAiC;CAC3D,QAAQ,IAAI,KAAK,OAAO,KAAK,GAAA,CAAI,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;AACrE;AAEA,SAAgB,SAAS,KAAuB,OAAwB;CACtE,OAAO,YAAY,GAAG,CAAC,CAAC,SAAS,KAAK;AACxC;AAEA,SAAgB,YACd,KACA,QACS;CACT,MAAM,MAAM,IAAI,IAAI,YAAY,GAAG,CAAC;CACpC,OAAO,OAAO,MAAM,MAAM,IAAI,IAAI,CAAC,CAAC;AACtC;AAEA,SAAgB,kBACd,KACA,QACoB;CACpB,OAAO,YAAY,GAAG,CAAC,CAAC,MAAM,MAAM,EAAE,WAAW,MAAM,CAAC;AAC1D;;AAGA,SAAgB,kBACd,GACA,OACA,OACoB;CACpB,MAAM,WAAW,YAAY,MAAM;CACnC,MAAM,SAAS,QAAQ,MAAM,KAAK,QAAQ,IAAI,E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AG,SAAS;GACZ;GACA,UAAU;IACR,GAAG,SAAS;IACZ,GAAG,SAAS,QAAQ;IACpB;IACA,iBAAiB;GACnB;EACF;EACA,QAAQ,UAAU,GAAG;CACvB;AACF"}
1
+ {"version":3,"file":"index.js","names":["ZERO","ZERO","ZERO","COLUMN_TOKENS","BODY_SELECTOR","bandColor"],"sources":["../src/classes.ts","../src/css.ts","../src/column-width.ts","../src/fragment.ts","../src/platform.ts","../src/labelled.ts","../src/compiled.ts","../src/detect.ts","../src/editor.ts","../src/converter.ts"],"sourcesContent":["import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\n\nexport function classTokens($el: Cheerio<Element>): string[] {\n return ($el.attr(\"class\") ?? \"\").trim().split(/\\s+/).filter(Boolean);\n}\n\nexport function hasToken($el: Cheerio<Element>, token: string): boolean {\n return classTokens($el).includes(token);\n}\n\nexport function hasAnyToken(\n $el: Cheerio<Element>,\n tokens: readonly string[],\n): boolean {\n const set = new Set(classTokens($el));\n return tokens.some((t) => set.has(t));\n}\n\nexport function tokenStartingWith(\n $el: Cheerio<Element>,\n prefix: string,\n): string | undefined {\n return classTokens($el).find((t) => t.startsWith(prefix));\n}\n\n/** Elements carrying `token` that are not nested in another such element. */\nexport function topLevelWithToken(\n $: CheerioAPI,\n token: string,\n $root?: Cheerio<Element>,\n): Cheerio<Element>[] {\n const selector = `[class~=\"${token}\"]`;\n const $found = $root ? $root.find(selector) : $(selector);\n const out: Cheerio<Element>[] = [];\n $found.each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n const nested = $el.parents(selector);\n if ($root && $root.length) {\n const outside = nested.filter((_, p) => {\n const $p = $(p) as Cheerio<Element>;\n return $p.closest($root).length === 0 && !$p.is($root);\n });\n if (nested.length - outside.length > 0) return;\n } else if (nested.length > 0) {\n return;\n }\n out.push($el);\n });\n return out;\n}\n\nexport function isHidden($el: Cheerio<Element>): boolean {\n return hasToken($el, \"es-hidden\") || hasToken($el, \"esd-hidden\");\n}\n","/**\n * Tiny CSS readers for paint, padding and divider width.\n * Hex (3/6), a bare bgcolor hex, and rgb()/rgba() (alpha dropped).\n * \"transparent\" is unset. A present padding longhand of 0 beats the shorthand.\n */\n\nimport type {\n BackgroundImage,\n BackgroundPositionX,\n BackgroundPositionY,\n BackgroundSize,\n DividerBlock,\n SectionWrapper,\n SpacingValue,\n} from \"@templatical/types\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** Column shares of the body width. The third column of `\"3\"` takes the rounding remainder. */\nconst COLUMN_SHARES = {\n \"1\": [100],\n \"2\": [50, 50],\n \"3\": [33.33, 33.33, 33.34],\n \"4\": [25, 25, 25, 25],\n} as const;\n\nconst DIVIDER_WIDTH = /^(-?\\d+(?:\\.\\d+)?)\\s*(%|px)?$/i;\n\nconst SIDE_LETTER: Record<string, keyof SpacingValue> = {\n t: \"top\",\n r: \"right\",\n b: \"bottom\",\n l: \"left\",\n};\n\n/**\n * A `style` attribute as a key/value map. A semicolon inside quotes or\n * parentheses — `url(\"a;b\")`, `url(data:image/png;base64,…)` — belongs to\n * its value.\n */\nexport function parseStyleAttribute(\n styleAttr: string | undefined,\n): Record<string, string> {\n const result: Record<string, string> = {};\n if (!styleAttr) return result;\n for (const decl of splitTopLevel(styleAttr, \";\")) {\n const idx = decl.indexOf(\":\");\n if (idx === -1) continue;\n const key = decl.slice(0, idx).trim().toLowerCase();\n const value = decl.slice(idx + 1).trim();\n if (key && value) result[key] = value;\n }\n return result;\n}\n\n/**\n * Split `value` at each `separator` that sits outside quotes and parentheses.\n * A value whose quote or parenthesis never closes is split at every\n * `separator` instead, so a malformed declaration costs only itself and the\n * ones after it still read.\n */\nfunction splitTopLevel(value: string, separator: string): string[] {\n const parts: string[] = [];\n let depth = 0;\n let quote = \"\";\n let start = 0;\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n if (quote) {\n if (char === quote) quote = \"\";\n continue;\n }\n if (char === '\"' || char === \"'\") quote = char;\n else if (char === \"(\") depth++;\n else if (char === \")\") depth = Math.max(0, depth - 1);\n else if (char === separator && depth === 0) {\n parts.push(value.slice(start, i));\n start = i + 1;\n }\n }\n if (quote || depth > 0) return value.split(separator);\n parts.push(value.slice(start));\n return parts;\n}\n\nfunction channelHex(value: number): string {\n const clamped = Math.max(0, Math.min(255, Math.round(value)));\n return clamped.toString(16).padStart(2, \"0\");\n}\n\nexport function parseColor(value: string | undefined): string {\n if (!value) return \"\";\n const trimmed = value.trim().toLowerCase();\n if (trimmed === \"transparent\" || trimmed === \"inherit\" || trimmed === \"none\")\n return \"\";\n const hex = trimmed.startsWith(\"#\")\n ? trimmed\n : /^[0-9a-f]{3}$|^[0-9a-f]{6}$/.test(trimmed)\n ? `#${trimmed}`\n : \"\";\n if (/^#[0-9a-f]{6}$/.test(hex)) return hex;\n if (/^#[0-9a-f]{3}$/.test(hex)) {\n return `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;\n }\n const rgb = trimmed.match(\n /^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*[\\d.]+\\s*)?\\)$/,\n );\n if (rgb) {\n return `#${channelHex(Number(rgb[1]))}${channelHex(Number(rgb[2]))}${channelHex(Number(rgb[3]))}`;\n }\n return \"\";\n}\n\nexport function parsePxValue(value: string | undefined): number {\n if (!value) return 0;\n const match = value.trim().match(/^(-?\\d+(?:\\.\\d+)?)\\s*(?:px)?$/);\n return match ? Math.round(parseFloat(match[1])) : 0;\n}\n\n/** Inline `background-color` / `background` wins over the `bgcolor` attribute. */\nexport function colorFromPaint(\n styleAttr: string | undefined,\n bgcolor?: string,\n): string {\n const styles = parseStyleAttribute(styleAttr);\n const fromShorthand = styles.background\n ? parseColor(styles.background.trim().split(/\\s+/)[0])\n : \"\";\n return (\n parseColor(styles[\"background-color\"]) ||\n fromShorthand ||\n parseColor(bgcolor) ||\n \"\"\n );\n}\n\nexport function parsePaddingShorthand(value: string | undefined): SpacingValue {\n if (!value) return { ...ZERO };\n const values = value\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((part) => parsePxValue(part));\n if (values.length === 0) return { ...ZERO };\n if (values.length === 1) {\n return {\n top: values[0],\n right: values[0],\n bottom: values[0],\n left: values[0],\n };\n }\n if (values.length === 2) {\n return {\n top: values[0],\n right: values[1],\n bottom: values[0],\n left: values[1],\n };\n }\n if (values.length === 3) {\n return {\n top: values[0],\n right: values[1],\n bottom: values[2],\n left: values[1],\n };\n }\n return {\n top: values[0],\n right: values[1],\n bottom: values[2],\n left: values[3],\n };\n}\n\n/**\n * Longhand wins when it is present, including an explicit 0.\n * A missing longhand falls back to the shorthand, then 0.\n */\nexport function readPadding(styles: Record<string, string>): SpacingValue {\n const shorthand =\n styles.padding !== undefined ? parsePaddingShorthand(styles.padding) : ZERO;\n const side = (name: keyof SpacingValue): number => {\n const key = `padding-${name}`;\n if (styles[key] !== undefined) return parsePxValue(styles[key]);\n return shorthand[name];\n };\n return {\n top: side(\"top\"),\n right: side(\"right\"),\n bottom: side(\"bottom\"),\n left: side(\"left\"),\n };\n}\n\n/** `es-p20` sets every side; `es-p10t` / `r` / `b` / `l` then override one side. */\nexport function paddingFromClasses(\n classAttr: string | undefined,\n): SpacingValue {\n const pad: SpacingValue = { ...ZERO };\n const tokens = (classAttr ?? \"\").split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n const all = /^es-p(\\d+)$/.exec(token);\n if (!all) continue;\n const n = Number(all[1]);\n pad.top = n;\n pad.right = n;\n pad.bottom = n;\n pad.left = n;\n }\n for (const token of tokens) {\n const side = /^es-p(\\d+)([trbl])$/.exec(token);\n if (!side) continue;\n pad[SIDE_LETTER[side[2]]] = Number(side[1]);\n }\n return pad;\n}\n\n/**\n * Class padding first, then inline padding per side.\n * A shorthand replaces every side; a longhand replaces only that side.\n */\nexport function readBoxPadding(\n classAttr: string | undefined,\n styleAttr: string | undefined,\n): SpacingValue {\n const base = paddingFromClasses(classAttr);\n const styles = parseStyleAttribute(styleAttr);\n const hasShorthand = styles.padding !== undefined;\n const shorthand = hasShorthand ? parsePaddingShorthand(styles.padding) : base;\n const side = (name: keyof SpacingValue): number => {\n const key = `padding-${name}`;\n if (styles[key] !== undefined) return parsePxValue(styles[key]);\n if (hasShorthand) return shorthand[name];\n return base[name];\n };\n return {\n top: side(\"top\"),\n right: side(\"right\"),\n bottom: side(\"bottom\"),\n left: side(\"left\"),\n };\n}\n\nexport interface SectionPaint {\n backgroundColor: string;\n wrapperColor?: string;\n /** The wrapper colour is a viewport band, not an email-width frame. */\n fullWidth?: boolean;\n notes: string[];\n}\n\n/**\n * Body fill paints the section. A band that is neither the page nor the body\n * becomes the section wrapper. A transparent body leaves the band on the section.\n *\n * `bleed` is a stripe around a fixed-width body. The band is then a viewport\n * wrapper, including when it matches the body, and a transparent body moves\n * that single background off the section.\n */\nexport function resolveSectionPaint(\n pageBackground: string,\n band: string,\n body: string,\n bleed = false,\n): SectionPaint {\n const page = pageBackground || \"#ffffff\";\n if (bleed && band && band !== page) {\n if (body) {\n return {\n backgroundColor: body,\n wrapperColor: band,\n fullWidth: true,\n notes: [],\n };\n }\n return {\n backgroundColor: \"\",\n wrapperColor: band,\n fullWidth: true,\n notes: [],\n };\n }\n if (body) {\n if (band && band !== page && band !== body) {\n return {\n backgroundColor: body,\n wrapperColor: band,\n notes: [\"The band colour was imported as a section wrapper.\"],\n };\n }\n return { backgroundColor: body, notes: [] };\n }\n return { backgroundColor: band, notes: [] };\n}\n\n/**\n * The section wrapper for a band colour and a stripe image. No paint, no\n * wrapper. A stripe image is the viewport band even when the colour was\n * approximated at the email width.\n */\nexport function sectionWrapper(\n paint: SectionPaint,\n bandImage: BackgroundImage | undefined,\n): SectionWrapper | undefined {\n if (!paint.wrapperColor && !bandImage) return undefined;\n return {\n ...(paint.wrapperColor ? { backgroundColor: paint.wrapperColor } : {}),\n ...(bandImage\n ? {\n backgroundImage: {\n ...bandImage,\n position: { ...bandImage.position },\n },\n }\n : {}),\n ...(paint.fullWidth || bandImage ? { fullWidth: true } : {}),\n };\n}\n\n/** `es-*-body` width in px, or 600 when the document does not state one. */\nexport function emailBodyWidth(\n widthAttr: string | undefined,\n styleAttr: string | undefined,\n): number {\n const raw = (widthAttr || parseStyleAttribute(styleAttr).width || \"\").trim();\n const n = parsePxValue(raw);\n return n > 0 ? n : 600;\n}\n\n/**\n * Room each column has for a line, before the line's own side padding.\n * The share is of the body width; the first column then loses the section's\n * left padding and the last loses the right. One column loses both.\n * A room that is not positive is unknown — the caller keeps the stated px.\n */\nexport function columnRooms(\n bodyWidth: number,\n layout: \"1\" | \"2\" | \"3\" | \"4\",\n padding: SpacingValue,\n slotCount: number,\n): Array<number | undefined> {\n const shares = COLUMN_SHARES[layout];\n const count = layout === \"1\" ? 1 : slotCount;\n const width = bodyWidth > 0 ? bodyWidth : 600;\n return Array.from({ length: count }, (_, index) => {\n const span = layout === \"1\" ? width : (width * shares[index]) / 100;\n const left = layout === \"1\" || index === 0 ? padding.left : 0;\n const right = layout === \"1\" || index === count - 1 ? padding.right : 0;\n const room = span - left - right;\n return room > 0 ? room : undefined;\n });\n}\n\n/**\n * No width, `auto` and `100%` span the column. Another percentage stays a\n * share, clamped to 0–100 and rounded to two decimals. A px width stays px\n * until it reaches `room` less the divider's own side padding.\n */\nexport function readDividerWidth(\n raw: string,\n room: number | undefined,\n ownLeft: number,\n ownRight: number,\n notes: string[],\n): DividerBlock[\"width\"] {\n const trimmed = raw.trim();\n if (\n trimmed === \"\" ||\n trimmed.toLowerCase() === \"auto\" ||\n trimmed === \"100%\"\n ) {\n return \"full\";\n }\n const match = trimmed.match(DIVIDER_WIDTH);\n if (!match) {\n notes.push(\n `Divider width \"${trimmed}\" could not be read; imported as full width.`,\n );\n return \"full\";\n }\n const value = parseFloat(match[1]);\n if ((match[2] ?? \"\").toLowerCase() === \"%\") {\n const percent = Math.min(100, Math.max(0, value));\n if (percent !== value) {\n notes.push(`Divider width ${trimmed} was clamped to ${percent}%.`);\n }\n const share = Math.round((percent + Number.EPSILON) * 100) / 100;\n return share === 100 ? \"full\" : `${share}%`;\n }\n const px = Math.max(0, Math.round(value));\n if (value < 0) notes.push(`Divider width ${trimmed} was clamped to 0px.`);\n if (room === undefined || room <= 0) return px;\n return px >= room - ownLeft - ownRight ? \"full\" : px;\n}\n\nconst BORDER_STYLES = new Set([\n \"none\",\n \"hidden\",\n \"dotted\",\n \"dashed\",\n \"solid\",\n \"double\",\n \"groove\",\n \"ridge\",\n \"inset\",\n \"outset\",\n]);\n\nexport interface ParsedBorder {\n width: number;\n style: string;\n color: string;\n}\n\n/** A `border-bottom` / `border-top` shorthand. Color is empty when absent. */\nexport function parseBorderShorthand(value: string | undefined): ParsedBorder {\n const parsed: ParsedBorder = { width: 0, style: \"solid\", color: \"\" };\n if (!value) return parsed;\n for (const token of value.trim().split(/\\s+/)) {\n const lower = token.toLowerCase();\n if (BORDER_STYLES.has(lower)) {\n parsed.style = lower;\n } else if (/^-?\\d+(?:\\.\\d+)?(?:px)?$/i.test(lower)) {\n parsed.width = parsePxValue(lower);\n } else {\n const color = parseColor(lower);\n if (color) parsed.color = color;\n }\n }\n return parsed;\n}\n\nexport function visibleLineBorder(\n styles: Record<string, string>,\n): ParsedBorder | null {\n for (const key of [\"border-bottom\", \"border-top\"]) {\n if (styles[key] === undefined) continue;\n const parsed = parseBorderShorthand(styles[key]);\n if (\n parsed.width > 0 &&\n parsed.style !== \"none\" &&\n parsed.style !== \"hidden\"\n ) {\n return parsed;\n }\n }\n return null;\n}\n\n/** A background image read from the source, with a note for each value that had no exact keyword. */\nexport interface ReadBackgroundImage {\n image: BackgroundImage;\n notes: string[];\n}\n\nconst X_GRID = [\"left\", \"center\", \"right\"] as const;\nconst Y_GRID = [\"top\", \"center\", \"bottom\"] as const;\nconst PERCENT = /^(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))%$/;\nconst LENGTH = /^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)[a-z]*$/;\n\n/**\n * `background-size` as a keyword. A size with a side at 100%, or a px width\n * spanning the box, fills it as `cover` does; any other length or percentage\n * draws the image at a size of its own, which `auto` is closest to.\n */\nfunction backgroundSizeKeyword(\n raw: string,\n boxWidth: number | undefined,\n): { size: BackgroundSize; exact: boolean } {\n const parts = raw.toLowerCase().split(/\\s+/);\n const [first] = parts;\n if (parts.length === 1 && (first === \"cover\" || first === \"contain\")) {\n return { size: first, exact: true };\n }\n if (parts.every((part) => part === \"auto\")) {\n return { size: \"auto\", exact: true };\n }\n const px = /^(\\d+(?:\\.\\d+)?|\\.\\d+)px$/.exec(first);\n const fills =\n parts.includes(\"100%\") ||\n (px !== null && boxWidth !== undefined && Number(px[1]) >= boxWidth);\n return { size: fills ? \"cover\" : \"auto\", exact: false };\n}\n\n/**\n * `background-position` split into x and y the way MJML and CSS read it: a\n * lone `top` / `bottom` names y and centres x, any other lone value is x\n * with y centred, and a pair is x then y unless it leads with `top` /\n * `bottom` (or with `center` before `left` / `right`). Three- and four-value\n * edge offsets keep their edge keywords only.\n */\nfunction splitBackgroundPosition(raw: string): {\n x: string;\n y: string;\n exact: boolean;\n} {\n const parts = raw.toLowerCase().split(/\\s+/);\n if (parts.length === 1) {\n const [only] = parts;\n return only === \"top\" || only === \"bottom\"\n ? { x: \"center\", y: only, exact: true }\n : { x: only, y: \"center\", exact: true };\n }\n if (parts.length === 2) {\n const [a, b] = parts;\n const yFirst =\n a === \"top\" ||\n a === \"bottom\" ||\n (a === \"center\" && (b === \"left\" || b === \"right\"));\n return yFirst ? { x: b, y: a, exact: true } : { x: a, y: b, exact: true };\n }\n return {\n x: parts.find((part) => part === \"left\" || part === \"right\") ?? \"center\",\n y: parts.find((part) => part === \"top\" || part === \"bottom\") ?? \"center\",\n exact: false,\n };\n}\n\n/**\n * One axis as a grid point: its keyword; the point nearest a percentage,\n * ties going to the centre; or the start edge for a length, which is an\n * offset from it. `null` when the token is unreadable.\n */\nfunction backgroundAxisPoint<T extends string>(\n token: string,\n grid: readonly [T, T, T],\n): { point: T; exact: boolean } | null {\n const keyword = grid.find((point) => point === token);\n if (keyword) return { point: keyword, exact: true };\n const percent = PERCENT.exec(token);\n if (percent) {\n const n = Number(percent[1]);\n return {\n point: n < 25 ? grid[0] : n > 75 ? grid[2] : grid[1],\n exact: n === 0 || n === 50 || n === 100,\n };\n }\n if (LENGTH.test(token)) {\n return { point: grid[0], exact: parseFloat(token) === 0 };\n }\n return null;\n}\n\n/**\n * `background-repeat`: unrepeated only when every axis is `no-repeat`.\n * Anything but plain `repeat` tiles too, inexactly.\n */\nfunction backgroundRepeatFlag(raw: string): {\n repeat: boolean;\n exact: boolean;\n} {\n const parts = raw.toLowerCase().split(/\\s+/);\n if (parts.every((part) => part === \"no-repeat\")) {\n return { repeat: false, exact: true };\n }\n return { repeat: true, exact: parts.every((part) => part === \"repeat\") };\n}\n\n/** CSS's initial values: what a browser paints for a longhand the source leaves out. */\nconst CSS_BACKGROUND_DEFAULTS = {\n size: \"auto\",\n x: \"left\",\n y: \"top\",\n repeat: true,\n} as const;\n\nconst IMAGE_FUNCTION = /^(?:url|[a-z-]*gradient|image-set)\\(/;\nconst REPEAT_TOKENS = new Set([\n \"repeat\",\n \"no-repeat\",\n \"repeat-x\",\n \"repeat-y\",\n \"round\",\n \"space\",\n]);\nconst POSITION_TOKENS = new Set([\"left\", \"right\", \"top\", \"bottom\", \"center\"]);\nconst NON_COLOR_TOKENS = new Set([\n \"none\",\n \"scroll\",\n \"fixed\",\n \"local\",\n \"border-box\",\n \"padding-box\",\n \"content-box\",\n \"text\",\n \"cover\",\n \"contain\",\n \"auto\",\n]);\nconst MEASURE = /^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:%|[a-z]+)?$/i;\n\n/**\n * The URL inside the first CSS `url(…)`, unquoted and trimmed; \"\" when there\n * is none or it is malformed. A forward scan rather than a regex, so a long\n * run of unclosed `url(` can't make it backtrack.\n */\nfunction cssUrl(value: string | undefined): string {\n const text = value ?? \"\";\n const start = text.search(/url\\(/i);\n if (start === -1) return \"\";\n let i = start + 4;\n while (i < text.length && /\\s/.test(text[i])) i++;\n const quote = text[i];\n if (quote === '\"' || quote === \"'\") {\n const close = text.indexOf(quote, i + 1);\n if (close === -1) return \"\";\n let j = close + 1;\n while (j < text.length && /\\s/.test(text[j])) j++;\n return text[j] === \")\" ? text.slice(i + 1, close).trim() : \"\";\n }\n const close = text.indexOf(\")\", i);\n if (close === -1) return \"\";\n const inner = text.slice(i, close);\n return /[\"']/.test(inner) ? \"\" : inner.trim();\n}\n\n/**\n * Whitespace-separated tokens, keeping a function's arguments together and\n * making the `/` between position and size a token of its own.\n */\nfunction cssTokens(value: string): string[] {\n const tokens: string[] = [];\n let depth = 0;\n let quote = \"\";\n let current = \"\";\n const push = (): void => {\n if (current) tokens.push(current);\n current = \"\";\n };\n for (const char of value) {\n if (quote) {\n current += char;\n if (char === quote) quote = \"\";\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n current += char;\n continue;\n }\n if (char === \"(\") depth++;\n if (char === \")\") depth = Math.max(0, depth - 1);\n if (depth === 0 && /\\s/.test(char)) {\n push();\n continue;\n }\n if (depth === 0 && char === \"/\") {\n push();\n tokens.push(\"/\");\n continue;\n }\n current += char;\n }\n push();\n return tokens;\n}\n\nfunction isColorToken(token: string): boolean {\n const lower = token.toLowerCase();\n if (lower === \"/\" || IMAGE_FUNCTION.test(lower)) return false;\n return (\n !REPEAT_TOKENS.has(lower) &&\n !POSITION_TOKENS.has(lower) &&\n !NON_COLOR_TOKENS.has(lower) &&\n !MEASURE.test(lower)\n );\n}\n\nexport interface BackgroundShorthand {\n /** The colour token as written; \"\" when there is none. */\n color: string;\n url: string;\n size: string;\n position: string;\n repeat: string;\n layers: number;\n}\n\n/**\n * The parts of a `background` shorthand. The colour comes from the last\n * layer, the only one CSS lets carry it; the image and its size, position\n * and repeat come from the first layer with a `url()`.\n */\nexport function parseBackgroundShorthand(value: string): BackgroundShorthand {\n const layers = splitTopLevel(value, \",\")\n .map((layer) => layer.trim())\n .filter(Boolean);\n const last = cssTokens(layers[layers.length - 1] ?? \"\");\n const color = last.find(isColorToken) ?? \"\";\n const imageLayer = layers.find((layer) => cssUrl(layer) !== \"\");\n if (!imageLayer) {\n return {\n color,\n url: \"\",\n size: \"\",\n position: \"\",\n repeat: \"\",\n layers: layers.length,\n };\n }\n\n const tokens = cssTokens(imageLayer);\n const slash = tokens.indexOf(\"/\");\n const before = slash === -1 ? tokens : tokens.slice(0, slash);\n const after = slash === -1 ? [] : tokens.slice(slash + 1);\n const size: string[] = [];\n for (const token of after) {\n const lower = token.toLowerCase();\n const isSize =\n lower === \"cover\" ||\n lower === \"contain\" ||\n lower === \"auto\" ||\n MEASURE.test(lower);\n if (size.length === 2 || !isSize) break;\n size.push(token);\n }\n const rest = [...before, ...after.slice(size.length)];\n return {\n color,\n url: cssUrl(imageLayer),\n size: size.join(\" \"),\n position: before\n .filter(\n (token) =>\n POSITION_TOKENS.has(token.toLowerCase()) || MEASURE.test(token),\n )\n .join(\" \"),\n repeat: rest\n .filter((token) => REPEAT_TOKENS.has(token.toLowerCase()))\n .join(\" \"),\n layers: layers.length,\n };\n}\n\n/**\n * A background image from a URL and its longhands. A longhand left out takes\n * CSS's initial value; a value with no exact keyword takes the nearest one\n * and adds a note naming it. `null` for a blank URL.\n */\nfunction buildBackgroundImage(\n url: string,\n longhands: {\n size?: string;\n position?: string;\n positionX?: string;\n positionY?: string;\n repeat?: string;\n },\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const trimmedUrl = url.trim();\n if (!trimmedUrl) return null;\n\n const notes: string[] = [];\n const lossy = (name: string, raw: string, shown: string): void => {\n notes.push(\n `${label} ${name} \"${raw}\" has no exact Templatical equivalent; imported as \"${shown}\".`,\n );\n };\n\n let size: BackgroundSize = CSS_BACKGROUND_DEFAULTS.size;\n const rawSize = longhands.size?.trim();\n if (rawSize) {\n const parsed = backgroundSizeKeyword(rawSize, boxWidth);\n size = parsed.size;\n if (!parsed.exact) lossy(\"background-size\", rawSize, size);\n }\n\n let x: BackgroundPositionX = CSS_BACKGROUND_DEFAULTS.x;\n let y: BackgroundPositionY = CSS_BACKGROUND_DEFAULTS.y;\n let lossyX = false;\n let lossyY = false;\n const rawPosition = longhands.position?.trim();\n if (rawPosition) {\n const split = splitBackgroundPosition(rawPosition);\n const readX = backgroundAxisPoint(split.x, X_GRID);\n const readY = backgroundAxisPoint(split.y, Y_GRID);\n x = readX?.point ?? x;\n y = readY?.point ?? y;\n lossyX = !split.exact || !readX?.exact;\n lossyY = !split.exact || !readY?.exact;\n }\n // A readable `-x` / `-y` replaces its axis, and with it whatever the\n // position lost there; the position's note then names what was imported.\n const rawX = longhands.positionX?.trim();\n const overrideX = rawX\n ? backgroundAxisPoint(rawX.toLowerCase(), X_GRID)\n : null;\n if (overrideX) {\n x = overrideX.point;\n lossyX = false;\n }\n const rawY = longhands.positionY?.trim();\n const overrideY = rawY\n ? backgroundAxisPoint(rawY.toLowerCase(), Y_GRID)\n : null;\n if (overrideY) {\n y = overrideY.point;\n lossyY = false;\n }\n if (rawPosition && (lossyX || lossyY)) {\n lossy(\"background-position\", rawPosition, `${x} ${y}`);\n }\n if (rawX && !overrideX?.exact) lossy(\"background-position-x\", rawX, x);\n if (rawY && !overrideY?.exact) lossy(\"background-position-y\", rawY, y);\n\n let repeat: boolean = CSS_BACKGROUND_DEFAULTS.repeat;\n const rawRepeat = longhands.repeat?.trim();\n if (rawRepeat) {\n const parsed = backgroundRepeatFlag(rawRepeat);\n repeat = parsed.repeat;\n if (!parsed.exact) {\n lossy(\"background-repeat\", rawRepeat, repeat ? \"repeat\" : \"no-repeat\");\n }\n }\n\n return {\n image: { url: trimmedUrl, size, position: { x, y }, repeat },\n notes,\n };\n}\n\n/**\n * A background image from CSS declarations: `background-image`, else the\n * `background` shorthand's image, with the size, position and repeat\n * longhands winning over the shorthand's. A style map keeps no declaration\n * order, so a longhand is taken to follow the shorthand, as it usually does.\n * Of several layers the first image is kept, and a note says so. `null`\n * when the declarations paint no image.\n */\nexport function readCssBackground(\n styles: Record<string, string>,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const shorthand =\n styles.background !== undefined\n ? parseBackgroundShorthand(styles.background)\n : null;\n const imageLayers =\n styles[\"background-image\"] !== undefined\n ? splitTopLevel(styles[\"background-image\"], \",\").map((layer) =>\n layer.trim(),\n )\n : null;\n const index = imageLayers\n ? imageLayers.findIndex((layer) => cssUrl(layer) !== \"\")\n : -1;\n const url = imageLayers\n ? index === -1\n ? \"\"\n : cssUrl(imageLayers[index])\n : (shorthand?.url ?? \"\");\n if (!url) return null;\n\n const layer = (value: string | undefined): string | undefined => {\n if (value === undefined) return undefined;\n const parts = splitTopLevel(value, \",\").map((part) => part.trim());\n return parts[Math.max(index, 0)] ?? parts[0];\n };\n const read = buildBackgroundImage(\n url,\n {\n size: layer(styles[\"background-size\"]) ?? shorthand?.size,\n position: layer(styles[\"background-position\"]) ?? shorthand?.position,\n positionX: styles[\"background-position-x\"],\n positionY: styles[\"background-position-y\"],\n repeat: layer(styles[\"background-repeat\"]) ?? shorthand?.repeat,\n },\n label,\n boxWidth,\n );\n const layers = imageLayers?.length ?? shorthand?.layers ?? 1;\n if (read && layers > 1) {\n read.notes.unshift(\n `${label} background has ${layers} layers; only the image \"${url}\" was imported.`,\n );\n }\n return read;\n}\n\n/**\n * The image an element paints: its inline CSS background, else its legacy\n * `background` attribute. A `background-image` or `background` declaration\n * overrides the attribute; a `background-color` doesn't. The image twin of\n * `colorFromPaint`.\n */\nexport function imageFromPaint(\n styleAttr: string | undefined,\n backgroundAttr: string | undefined,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const styles = parseStyleAttribute(styleAttr);\n if (\n styles[\"background-image\"] !== undefined ||\n styles.background !== undefined\n ) {\n return readCssBackground(styles, label, boxWidth);\n }\n return buildBackgroundImage(backgroundAttr ?? \"\", {}, label, boxWidth);\n}\n\n/** An image an element paints, and that element, which identifies the image when it spans several sections. */\nexport interface ImageLayer {\n read: ReadBackgroundImage;\n source: object;\n}\n\n/** Every image that can reach one section. */\nexport interface SectionImageLayers {\n /** The structure (row) cell's own image. */\n structure: ImageLayer | null;\n /** The `es-*-body` image: the content area behind every structure in the stripe. */\n body: ImageLayer | null;\n /** The stripe's image: the full-width band. */\n band: ImageLayer | null;\n /** Each container's image, in column order. */\n columns: Array<ReadBackgroundImage | null>;\n /** Whether the body paints a colour, which hides the band in the content area. */\n bodyPainted: boolean;\n}\n\nexport interface SectionImage {\n image: BackgroundImage | undefined;\n /** The stripe's image, copied. It paints the viewport band, not the section. */\n band?: BackgroundImage;\n notes: string[];\n /** The element the image came from when other sections can share it; `null` for a container's. */\n source: object | null;\n /** The stripe element, when it paints `band`. */\n bandSource: object | null;\n}\n\nfunction sameImage(a: BackgroundImage, b: BackgroundImage): boolean {\n return (\n a.url === b.url &&\n a.size === b.size &&\n a.repeat === b.repeat &&\n a.position.x === b.position.x &&\n a.position.y === b.position.y\n );\n}\n\nfunction droppedColumnsNote(columns: number[]): string {\n return columns.length === 1\n ? `The background image on column ${columns[0]} was dropped. A Templatical section has one background image.`\n : `Background images on columns ${columns.join(\", \")} were dropped. A Templatical section has one background image.`;\n}\n\n/**\n * The image a section paints, nearest first: the structure's own, then the\n * body's, then the containers', moved up when there is one or all share the\n * same image. The stripe's image is the viewport band (`band`), never the\n * section's. An image that showed in the section but can't be kept is named\n * in a note. A body image beneath the structure's own is covered in this\n * section, so it isn't named; it still paints the stripe's other sections.\n * The image is a copy, so sections that share a source don't share an object.\n */\nexport function resolveSectionImage(layers: SectionImageLayers): SectionImage {\n const notes: string[] = [];\n let picked: { read: ReadBackgroundImage; source: object | null } | null =\n layers.structure ?? layers.body;\n\n const withImage = layers.columns.flatMap((read, index) =>\n read ? [index + 1] : [],\n );\n const first = layers.columns[0] ?? null;\n const shared =\n first !== null &&\n layers.columns.every(\n (read) => read !== null && sameImage(read.image, first.image),\n );\n if (withImage.length > 0) {\n if (!picked && shared) picked = { read: first, source: null };\n else notes.push(droppedColumnsNote(withImage));\n }\n\n let bandImage: BackgroundImage | undefined;\n let bandSource: object | null = null;\n if (layers.band) {\n bandImage = {\n ...layers.band.read.image,\n position: { ...layers.band.read.image.position },\n };\n bandSource = layers.band.source;\n notes.push(...layers.band.read.notes);\n }\n\n if (!picked) {\n return {\n image: undefined,\n ...(bandImage ? { band: bandImage } : {}),\n notes,\n source: null,\n bandSource,\n };\n }\n return {\n image: {\n ...picked.read.image,\n position: { ...picked.read.image.position },\n },\n ...(bandImage ? { band: bandImage } : {}),\n notes: [...picked.read.notes, ...notes],\n source: picked.source,\n bandSource,\n };\n}\n\n/**\n * The paint, minus a band colour that would become the section's wrapper\n * colour, when the section has a background image. The wrapper has no\n * padding, so the colour shows nowhere except Outlook desktop, which paints\n * it over the section's image.\n */\nexport function withoutBandOverImage(\n paint: SectionPaint,\n hasImage: boolean,\n): SectionPaint {\n if (!hasImage || !paint.wrapperColor) return paint;\n return {\n backgroundColor: paint.backgroundColor,\n notes: [\n `The band colour ${paint.wrapperColor} was dropped: Outlook desktop paints a wrapper colour over the section's background image.`,\n ],\n ...(paint.fullWidth ? { fullWidth: true } : {}),\n };\n}\n","import { parsePxValue, parseStyleAttribute } from \"./css\";\n\n/** Widths within 1px count as the same column width. */\nconst COLUMN_WIDTH_TOLERANCE = 1;\nconst EQUAL_COLUMN_WORD = { \"2\": \"two\", \"3\": \"three\", \"4\": \"four\" } as const;\n\n/**\n * Positive px from an inline `width`, else from the `width` attribute.\n * A non-px length is unread.\n */\nexport function statedPx(\n widthAttr: string | undefined,\n styleAttr: string | undefined,\n): number | undefined {\n const inline = parsePxValue(parseStyleAttribute(styleAttr).width);\n if (inline > 0) return inline;\n const attribute = parsePxValue(widthAttr);\n return attribute > 0 ? attribute : undefined;\n}\n\n/**\n * A note when at least two readable widths differ by more than 1px.\n * An unread width stays in its place as \"an unstated width\".\n */\nexport function unequalWidthNote(\n widths: Array<number | undefined>,\n layout: \"2\" | \"3\" | \"4\",\n): string | undefined {\n const readable: number[] = [];\n for (const width of widths) {\n if (width !== undefined) readable.push(width);\n }\n if (readable.length < 2) return undefined;\n const spread = Math.max(...readable) - Math.min(...readable);\n if (spread <= COLUMN_WIDTH_TOLERANCE) return undefined;\n const parts = widths.map((width) =>\n width === undefined ? \"an unstated width\" : `${width}px`,\n );\n const listed = `${parts.slice(0, -1).join(\", \")} and ${parts[parts.length - 1]}`;\n return `Columns of ${listed} became ${EQUAL_COLUMN_WORD[layout]} equal columns.`;\n}\n","import type { Cheerio } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport { convertHtmlTemplate } from \"@templatical/import-html\";\nimport type { ImportReportEntry } from \"@templatical/import-html\";\nimport type { Block, SectionBlock } from \"@templatical/types\";\nimport {\n imageFromPaint,\n type ImageLayer,\n type ReadBackgroundImage,\n} from \"./css\";\n\nexport interface ConvertCtx {\n entries: ImportReportEntry[];\n warnings: string[];\n /** Caller's plugin CSS. Applied inside each HTML fragment, never raw. */\n css?: string;\n /** `es-wrapper` colour, or `#ffffff` when the document has none. */\n pageBackground?: string;\n /**\n * The report entries of the sections that took each shared image, keyed by\n * the element that paints it (a body, stripe or structure cell).\n */\n imageSpans?: Map<object, ImportReportEntry[]>;\n}\n\n/** Paint after `createSectionBlock` so `styles` keeps its required padding. */\nexport function withBackground(\n section: SectionBlock,\n backgroundColor: string,\n): SectionBlock {\n if (backgroundColor) section.styles.backgroundColor = backgroundColor;\n return section;\n}\n\nexport function flattenBlocks(blocks: Block[]): Block[] {\n const out: Block[] = [];\n for (const b of blocks) {\n if (b.type === \"section\") {\n for (const col of b.children ?? []) out.push(...flattenBlocks(col));\n } else {\n out.push(b);\n }\n }\n return out;\n}\n\nfunction fragmentDocument(inner: string, css?: string): string {\n const safe = css ? css.replace(/<\\/style/gi, \"<\\\\/style\") : \"\";\n const head = safe ? `<head><style>${safe}</style></head>` : \"\";\n return `<!DOCTYPE html><html>${head}<body>${inner}</body></html>`;\n}\n\n/** The start of the HTML importer's page-image warning. */\nconst PAGE_IMAGE_WARNING = \"The email background image \";\n/** The start of the HTML importer's warning about an invalid `<html lang>`. */\nconst DEFAULT_LANGUAGE_WARNING = \"Ignored the source's default language \";\n\n/**\n * Run the generic HTML importer on a subtree and keep its blocks.\n * Section entries belong to the row the HTML importer invented; Stripo's own\n * section entries are recorded by the caller. A fragment's `<body>` is\n * synthetic, so the page-image warning the HTML importer raises for a `body`\n * background in the caller's CSS is dropped; Stripo reports the page image\n * once, from `es-wrapper`. A fragment's language is synthetic too (a nested\n * `<html lang>` merges into it), so Stripo reports the default language once,\n * from the page.\n */\nexport function blocksFromHtml(inner: string, ctx: ConvertCtx): Block[] {\n const result = convertHtmlTemplate(fragmentDocument(inner, ctx.css));\n for (const entry of result.report.entries) {\n if (entry.templaticalBlockType === \"section\") continue;\n ctx.entries.push(entry);\n }\n ctx.warnings.push(\n ...result.report.warnings.filter(\n (warning) =>\n !warning.startsWith(PAGE_IMAGE_WARNING) &&\n !warning.startsWith(DEFAULT_LANGUAGE_WARNING),\n ),\n );\n return flattenBlocks(result.content.blocks);\n}\n\nexport function pushEntry(\n ctx: ConvertCtx,\n sourceTag: string,\n templaticalBlockType: string | null,\n status: ImportReportEntry[\"status\"],\n note?: string,\n): ImportReportEntry {\n const entry: ImportReportEntry = {\n sourceTag,\n templaticalBlockType,\n status,\n ...(note ? { note } : {}),\n };\n ctx.entries.push(entry);\n return entry;\n}\n\n/** Record that a section's entry took the image `source` paints. */\nexport function recordImageSpan(\n ctx: ConvertCtx,\n source: object | null,\n entry: ImportReportEntry,\n): void {\n if (!source) return;\n ctx.imageSpans ??= new Map();\n const spanned = ctx.imageSpans.get(source) ?? [];\n spanned.push(entry);\n ctx.imageSpans.set(source, spanned);\n}\n\n/** Note on each entry whose section shares its image with another section. */\nexport function noteImageSpans(ctx: ConvertCtx): void {\n for (const spanned of ctx.imageSpans?.values() ?? []) {\n if (spanned.length < 2) continue;\n const note = `A background image behind ${spanned.length} sections was applied to each of them — Templatical has no multi-section band.`;\n for (const entry of spanned) {\n entry.status = \"approximated\";\n entry.note = entry.note ? `${entry.note} ${note}` : note;\n }\n }\n}\n\n/** The image an element paints: its inline CSS background, else its `background` attribute. */\nexport function imageOf(\n $el: Cheerio<Element>,\n label: string,\n boxWidth: number,\n): ReadBackgroundImage | null {\n return imageFromPaint(\n $el.attr(\"style\"),\n $el.attr(\"background\"),\n label,\n boxWidth,\n );\n}\n\n/** An element's image with that element as its source; `null` when there is no element or it paints none. */\nexport function imageLayer(\n $el: Cheerio<Element> | null,\n label: string,\n boxWidth: number,\n): ImageLayer | null {\n if (!$el) return null;\n const read = imageOf($el, label, boxWidth);\n return read ? { read, source: $el[0] } : null;\n}\n\n/**\n * The stripe's image: on the stripe, else on `$cell`, the cell Stripo paints\n * instead of a table stripe, as the band colour is read. A `td` / `th` stripe\n * is its own paint. The stripe names the image either way, since it is the\n * element that spans the sections.\n */\nexport function bandImage(\n $stripe: Cheerio<Element>,\n $cell: Cheerio<Element>,\n boxWidth: number,\n): ImageLayer | null {\n const own = imageLayer($stripe, \"Stripe\", boxWidth);\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return null;\n const cell = $cell.length > 0 ? imageOf($cell, \"Stripe\", boxWidth) : null;\n return cell ? { read: cell, source: $stripe[0] } : null;\n}\n","import type { SocialPlatform } from \"@templatical/types\";\n\nconst NAMED: Record<string, SocialPlatform> = {\n facebook: \"facebook\",\n fb: \"facebook\",\n twitter: \"twitter\",\n x: \"twitter\",\n instagram: \"instagram\",\n inst: \"instagram\",\n linkedin: \"linkedin\",\n xing: \"xing\",\n youtube: \"youtube\",\n yt: \"youtube\",\n tiktok: \"tiktok\",\n pinterest: \"pinterest\",\n email: \"email\",\n mail: \"email\",\n whatsapp: \"whatsapp\",\n telegram: \"telegram\",\n discord: \"discord\",\n snapchat: \"snapchat\",\n reddit: \"reddit\",\n github: \"github\",\n dribbble: \"dribbble\",\n behance: \"behance\",\n};\n\nfunction peel(raw: string): string {\n return raw\n .toLowerCase()\n .replace(/\\.(png|jpe?g|gif|svg|webp)$/i, \"\")\n .replace(/[^a-z0-9]+/g, \" \")\n .trim();\n}\n\n/**\n * The file name of an icon src. An absolute URL contributes its last path\n * segment, so the host is not a name; an empty path has none. A relative or\n * protocol-relative src resolves against a placeholder base for the same\n * reason. The query and hash are not part of the name.\n */\nfunction srcFileName(src: string): string {\n try {\n const url = new URL(src, \"https://placeholder.invalid\");\n return url.pathname.split(\"/\").pop() || \"\";\n } catch {\n return \"\";\n }\n}\n\n/** A Stripo website icon is named website, web, or link. */\nconst WEBSITE_NAMES = new Set([\"website\", \"web\", \"link\"]);\n\nfunction namedPlatform(\n candidate: string | undefined,\n): SocialPlatform | undefined {\n if (!candidate) return undefined;\n for (const w of peel(candidate).split(/\\s+/)) {\n const hit = NAMED[w];\n if (hit) return hit;\n }\n return undefined;\n}\n\nfunction explicitWebsite(candidate: string | undefined): boolean {\n if (!candidate) return false;\n for (const w of peel(candidate).split(/\\s+/)) {\n if (WEBSITE_NAMES.has(w)) return true;\n }\n return false;\n}\n\n/**\n * The platform named by a Stripo icon's title, alt, or src file name.\n * An explicit website, web, or link name is `website`. Undefined when none\n * of those names a platform.\n */\nexport function matchPlatform(\n name?: string,\n src?: string,\n alt?: string,\n): SocialPlatform | undefined {\n for (const candidate of [name, alt]) {\n const hit = namedPlatform(candidate);\n if (hit) return hit;\n // An explicit website label outranks the platform a file name suggests.\n if (explicitWebsite(candidate)) return \"website\";\n }\n // Only the file name identifies an icon; the host and folders of a URL do not.\n const file = src ? srcFileName(src) : \"\";\n const fromFile = namedPlatform(file);\n if (fromFile) return fromFile;\n if (explicitWebsite(file)) return \"website\";\n return undefined;\n}\n\n/**\n * Map a Stripo icon's title, alt, or src stem onto a SocialPlatform.\n * Unknown names become `website` — same floor as the MJML importer.\n */\nexport function normalizePlatform(\n name?: string,\n src?: string,\n alt?: string,\n): SocialPlatform {\n return matchPlatform(name, src, alt) ?? \"website\";\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport {\n createButtonBlock,\n createDividerBlock,\n createMenuBlock,\n createSocialIconsBlock,\n createSpacerBlock,\n generateId,\n} from \"@templatical/types\";\nimport type {\n Block,\n DividerBlock,\n MenuItemData,\n SocialIcon,\n SpacingValue,\n} from \"@templatical/types\";\nimport { hasAnyToken, hasToken, isHidden } from \"./classes\";\nimport {\n colorFromPaint,\n parseColor,\n parsePxValue,\n parseStyleAttribute,\n readDividerWidth,\n readPadding,\n visibleLineBorder,\n type ParsedBorder,\n} from \"./css\";\nimport { blocksFromHtml, pushEntry, type ConvertCtx } from \"./fragment\";\nimport { matchPlatform } from \"./platform\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** Tables whose padding is the section's padding. A divider must not copy it. */\nconst STRUCTURE_TABLES = [\n \"es-header-body\",\n \"es-content-body\",\n \"es-footer-body\",\n \"es-header\",\n \"es-content\",\n \"es-footer\",\n] as const;\n\nconst MAPPED_LINE_STYLES = new Set([\n \"double\",\n \"groove\",\n \"ridge\",\n \"inset\",\n \"outset\",\n]);\n\nfunction firstAnchor($el: Cheerio<Element>): Cheerio<Element> {\n const $self = $el.is(\"a\") ? $el : $el.find(\"a\").first();\n return $self as Cheerio<Element>;\n}\n\nexport function buttonFrom(\n $el: Cheerio<Element>,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block {\n const $a = firstAnchor($el);\n const text = ($a.text() ?? \"\").trim() || \"Shop Now\";\n const url = $a.attr(\"href\") ?? \"#\";\n const target = $a.attr(\"target\");\n const own = parseStyleAttribute($a.attr(\"style\"));\n const parent = parseStyleAttribute($a.parent().attr(\"style\"));\n const backgroundColor =\n colorFromPaint($a.attr(\"style\")) ||\n colorFromPaint($a.parent().attr(\"style\"));\n const textColor = parseColor(own.color) || parseColor(parent.color);\n const borderRadius =\n parsePxValue(own[\"border-radius\"]) || parsePxValue(parent[\"border-radius\"]);\n pushEntry(ctx, sourceTag, \"button\", \"converted\");\n return createButtonBlock({\n text,\n url,\n ...(target === \"_blank\" ? { openInNewTab: true } : {}),\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(textColor ? { textColor } : {}),\n ...(borderRadius > 0 ? { borderRadius } : {}),\n });\n}\n\nfunction declaresPadding($el: Cheerio<Element>): boolean {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n return (\n styles.padding !== undefined ||\n styles[\"padding-top\"] !== undefined ||\n styles[\"padding-right\"] !== undefined ||\n styles[\"padding-bottom\"] !== undefined ||\n styles[\"padding-left\"] !== undefined\n );\n}\n\n/**\n * The structure cell's padding becomes the section's padding. Reading it again\n * as the divider's own padding shortens the line twice.\n */\nfunction isStructureCell($cell: Cheerio<Element>): boolean {\n if (!$cell.is(\"td\") && !$cell.is(\"th\")) return false;\n if (hasToken($cell, \"esd-structure\")) return true;\n let $table = $cell.parent().parent();\n if ($table.is(\"tbody\") || $table.is(\"thead\") || $table.is(\"tfoot\")) {\n $table = $table.parent();\n }\n return $table.is(\"table\") && hasAnyToken($table, STRUCTURE_TABLES);\n}\n\nfunction spacerElement($root: Cheerio<Element>): Cheerio<Element> {\n if (hasToken($root, \"es-spacer\")) return $root;\n const $inner = $root.find(\"[class~='es-spacer']\").first();\n return ($inner.length ? $inner : $root) as Cheerio<Element>;\n}\n\nfunction lineBorder(\n $root: Cheerio<Element>,\n $spacer: Cheerio<Element>,\n $: CheerioAPI,\n): ParsedBorder | null {\n const own = visibleLineBorder(parseStyleAttribute($root.attr(\"style\")));\n if (own) return own;\n const onSpacer = visibleLineBorder(\n parseStyleAttribute($spacer.attr(\"style\")),\n );\n if (onSpacer) return onSpacer;\n let found: ParsedBorder | null = null;\n $spacer.find(\"td, th\").each((_, cell) => {\n if (found) return;\n found = visibleLineBorder(parseStyleAttribute($(cell).attr(\"style\")));\n });\n return found;\n}\n\nfunction dividerPadding(\n $root: Cheerio<Element>,\n $spacer: Cheerio<Element>,\n): SpacingValue {\n if (declaresPadding($root)) {\n return readPadding(parseStyleAttribute($root.attr(\"style\")));\n }\n if ($spacer[0] !== $root[0] && declaresPadding($spacer)) {\n return readPadding(parseStyleAttribute($spacer.attr(\"style\")));\n }\n const $parent = $spacer.parent();\n if (\n ($parent.is(\"td\") || $parent.is(\"th\")) &&\n !isStructureCell($parent as Cheerio<Element>)\n ) {\n return readPadding(parseStyleAttribute($parent.attr(\"style\")));\n }\n return { ...ZERO };\n}\n\n/**\n * No align and no margin is unset. A partial Stripo line with neither sits on\n * the left; the caller supplies that default.\n */\nfunction specifiedAlign(\n $el: Cheerio<Element>,\n): \"left\" | \"center\" | \"right\" | undefined {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n const alignAttr = ($el.attr(\"align\") ?? \"\").trim().toLowerCase();\n const alignKnown =\n alignAttr === \"left\" || alignAttr === \"center\" || alignAttr === \"right\";\n const hasMargin =\n styles.margin !== undefined ||\n styles[\"margin-left\"] !== undefined ||\n styles[\"margin-right\"] !== undefined;\n if (!alignKnown && !hasMargin) return undefined;\n\n let left = \"auto\";\n let right = \"auto\";\n if (alignAttr === \"left\") left = \"0\";\n if (alignAttr === \"right\") right = \"0\";\n\n const margin = (styles.margin ?? \"\").trim().split(/\\s+/).filter(Boolean);\n if (margin.length > 0) {\n right = margin[1] ?? margin[0];\n left = margin.length === 4 ? margin[3] : right;\n }\n if (styles[\"margin-left\"] !== undefined) left = styles[\"margin-left\"];\n if (styles[\"margin-right\"] !== undefined) right = styles[\"margin-right\"];\n\n const isAuto = (value: string) => value.trim().toLowerCase() === \"auto\";\n if (isAuto(left) && isAuto(right)) return \"center\";\n return isAuto(left) ? \"right\" : \"left\";\n}\n\nfunction placementOf(\n $spacer: Cheerio<Element>,\n $root: Cheerio<Element>,\n): \"left\" | \"center\" | \"right\" {\n const own = specifiedAlign($spacer);\n if (own) return own;\n for (const $candidate of [$spacer.parent(), $root.parent()]) {\n if (!$candidate.is(\"td\") && !$candidate.is(\"th\")) continue;\n const fromCell = specifiedAlign($candidate as Cheerio<Element>);\n if (fromCell) return fromCell;\n }\n return \"left\";\n}\n\nfunction spacerHeight($el: Cheerio<Element>): number {\n const styles = parseStyleAttribute($el.attr(\"style\"));\n const fromStyle = parsePxValue(styles.height);\n if (fromStyle > 0) return fromStyle;\n const fromAttr = parsePxValue($el.attr(\"height\"));\n if (fromAttr > 0) return fromAttr;\n const pad = readPadding(styles);\n const vertical = pad.top + pad.bottom;\n return vertical > 0 ? vertical : 24;\n}\n\nfunction dividerBlock(\n border: ParsedBorder,\n padding: SpacingValue,\n width: DividerBlock[\"width\"],\n): Block {\n const lineStyle =\n border.style === \"dashed\" || border.style === \"dotted\"\n ? border.style\n : \"solid\";\n return createDividerBlock({\n lineStyle,\n color: border.color || \"#e5e7eb\",\n thickness: border.width,\n width,\n styles: { padding },\n });\n}\n\n/**\n * A bordered spacer is a divider. `room` is the column width the line can\n * span, after the section padding that column owns.\n */\nexport function spacerFrom(\n $el: Cheerio<Element>,\n sourceTag: string,\n ctx: ConvertCtx,\n $: CheerioAPI,\n room?: number,\n): Block {\n const $spacer = spacerElement($el);\n const border = lineBorder($el, $spacer, $);\n if (!border) {\n const height = spacerHeight($spacer);\n pushEntry(ctx, sourceTag, \"spacer\", \"converted\");\n return createSpacerBlock({ height });\n }\n\n const padding = dividerPadding($el, $spacer);\n const styles = parseStyleAttribute($spacer.attr(\"style\"));\n const raw = (styles.width ?? $spacer.attr(\"width\") ?? \"\").trim();\n const notes: string[] = [];\n const width = readDividerWidth(raw, room, padding.left, padding.right, notes);\n if (MAPPED_LINE_STYLES.has(border.style)) {\n notes.push(`Divider border style \"${border.style}\" was imported as solid.`);\n }\n if (width !== \"full\") {\n const align = placementOf($spacer, $el);\n if (align !== \"center\") {\n notes.push(\n `The source aligns this divider ${align}; Templatical centres every divider.`,\n );\n }\n }\n pushEntry(\n ctx,\n sourceTag,\n \"divider\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n return dividerBlock(border, padding, width);\n}\n\nfunction menuItems($table: Cheerio<Element>, $: CheerioAPI): MenuItemData[] {\n const items: MenuItemData[] = [];\n $table.find(\"td\").each((_, td) => {\n const $td = $(td) as Cheerio<Element>;\n if (isHidden($td)) return;\n const $a = $td.find(\"a\").first();\n if (!$a.length) return;\n const text = ($a.text() ?? \"\").trim();\n if (!text) return;\n items.push({\n id: generateId(),\n text,\n url: $a.attr(\"href\") ?? \"#\",\n openInNewTab: $a.attr(\"target\") === \"_blank\",\n bold: false,\n underline: false,\n });\n });\n return items;\n}\n\n/**\n * A compiled/editor `table.es-menu` / `esd-block-menu` is a MenuBlock only\n * when one row holds two or more item cells. A single 100% cell is a stacked\n * step (Password reset) and must fall through.\n */\nexport function menuFrom(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block | null {\n const $table = $el.is(\"table\") ? $el : $el.find(\"table\").first();\n const $row = $table.find(\"tr\").first();\n const itemCells = $row\n .children(\"td\")\n .toArray()\n .filter((td) => !isHidden($(td) as Cheerio<Element>));\n if (itemCells.length < 2) return null;\n const items = menuItems($table, $);\n if (items.length < 2) return null;\n pushEntry(ctx, sourceTag, \"menu\", \"converted\");\n return createMenuBlock({ items });\n}\n\nfunction genericWebsiteNote(count: number): string {\n return count === 1\n ? \"1 icon became a generic website icon.\"\n : `${count} icons became generic website icons.`;\n}\n\nexport function socialFrom(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n sourceTag: string,\n ctx: ConvertCtx,\n): Block {\n const icons: SocialIcon[] = [];\n let generic = 0;\n $el.find(\"a\").each((_, a) => {\n const $a = $(a) as Cheerio<Element>;\n const $img = $a.find(\"img\").first();\n const url = $a.attr(\"href\") ?? \"#\";\n const platform = matchPlatform(\n $img.attr(\"title\"),\n $img.attr(\"src\"),\n $img.attr(\"alt\"),\n );\n if (!platform) generic += 1;\n icons.push({ id: generateId(), platform: platform ?? \"website\", url });\n });\n const note = generic > 0 ? genericWebsiteNote(generic) : undefined;\n pushEntry(\n ctx,\n sourceTag,\n \"social\",\n note ? \"approximated\" : \"converted\",\n note,\n );\n return createSocialIconsBlock({ icons });\n}\n\nexport function labelledInnerBlocks(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block[] {\n return blocksFromHtml($.html($el) ?? \"\", ctx);\n}\n","import { load, type Cheerio, type CheerioAPI } from \"cheerio\";\nimport type { AnyNode, Element } from \"domhandler\";\nimport { createSectionBlock } from \"@templatical/types\";\nimport type { Block, ColumnLayout, SpacingValue } from \"@templatical/types\";\nimport { hasAnyToken, hasToken, isHidden } from \"./classes\";\nimport { statedPx, unequalWidthNote } from \"./column-width\";\nimport {\n colorFromPaint,\n columnRooms,\n emailBodyWidth,\n readBoxPadding,\n resolveSectionImage,\n resolveSectionPaint,\n sectionWrapper,\n withoutBandOverImage,\n type ImageLayer,\n type ReadBackgroundImage,\n type SectionPaint,\n} from \"./css\";\nimport {\n bandImage,\n blocksFromHtml,\n imageLayer,\n imageOf,\n pushEntry,\n recordImageSpan,\n withBackground,\n type ConvertCtx,\n} from \"./fragment\";\nimport { buttonFrom, menuFrom, socialFrom, spacerFrom } from \"./labelled\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\nconst COLUMN_TOKENS = [\"es-left\", \"es-right\"] as const;\nconst STRIPE_TOKENS = [\"es-header\", \"es-content\", \"es-footer\"] as const;\nconst BODY_SELECTOR =\n \"[class~='es-header-body'], [class~='es-content-body'], [class~='es-footer-body']\";\n\nconst BETWEEN_NOTE = \"Content between columns was placed after them.\";\nconst SEAM_NOTE = \"This row's padding was split across more than one section.\";\n\ntype WidgetKind = \"menu\" | \"social\" | \"button\" | \"spacer\";\n\ntype Piece =\n { kind: \"flow\"; nodes: AnyNode[] } | { kind: \"column\"; el: Element };\n\nfunction paintOf($el: Cheerio<Element>): string {\n return colorFromPaint($el.attr(\"style\"), $el.attr(\"bgcolor\"));\n}\n\nfunction stripeToken($el: Cheerio<Element>): string | undefined {\n return STRIPE_TOKENS.find((token) => hasToken($el, token));\n}\n\nfunction topStripes($: CheerioAPI): Cheerio<Element>[] {\n const out: Cheerio<Element>[] = [];\n $(\"[class]\").each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n if (!stripeToken($el)) return;\n const nested = $el\n .parents()\n .toArray()\n .some((parent) =>\n hasAnyToken($(parent) as Cheerio<Element>, STRIPE_TOKENS),\n );\n if (nested) return;\n out.push($el);\n });\n return out;\n}\n\nfunction directRows(\n $table: Cheerio<Element>,\n $: CheerioAPI,\n): Cheerio<Element>[] {\n const $direct = $table.children(\"tr\");\n const $nested = $table.children(\"tbody, thead, tfoot\").children(\"tr\");\n const $rows = $direct.length > 0 ? $direct : $nested;\n return $rows.toArray().map((node) => $(node) as Cheerio<Element>);\n}\n\nfunction directCell($table: Cheerio<Element>): Cheerio<Element> {\n const $direct = $table.children(\"tr\").children(\"td, th\");\n const $nested = $table\n .children(\"tbody, thead, tfoot\")\n .children(\"tr\")\n .children(\"td, th\");\n return ($direct.length > 0 ? $direct : $nested).first() as Cheerio<Element>;\n}\n\n/** Paint on the stripe table, else on its cell. A `td` stripe is its own paint. */\nfunction bandColor($stripe: Cheerio<Element>): string {\n const own = paintOf($stripe);\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return \"\";\n const $cell = directCell($stripe);\n return $cell.length > 0 ? paintOf($cell) : \"\";\n}\n\n/** A column's image: on its `es-left` / `es-right` table, else on that table's cell. */\nfunction columnImage(\n $column: Cheerio<Element>,\n boxWidth: number,\n): ReadBackgroundImage | null {\n const own = imageOf($column, \"Column\", boxWidth);\n if (own) return own;\n const $cell = directCell($column);\n return $cell.length > 0 ? imageOf($cell, \"Column\", boxWidth) : null;\n}\n\ninterface StripeImages {\n body: ImageLayer | null;\n band: ImageLayer | null;\n bodyPainted: boolean;\n}\n\nfunction hasPadding(padding: SpacingValue): boolean {\n return (\n padding.top !== 0 ||\n padding.right !== 0 ||\n padding.bottom !== 0 ||\n padding.left !== 0\n );\n}\n\nfunction splitPadding(\n padding: SpacingValue,\n count: number,\n index: number,\n): SpacingValue {\n if (count <= 1) return { ...padding };\n return {\n top: index === 0 ? padding.top : 0,\n right: padding.right,\n bottom: index === count - 1 ? padding.bottom : 0,\n left: padding.left,\n };\n}\n\nfunction isColumn($el: Cheerio<Element>): boolean {\n return $el.is(\"table\") && hasAnyToken($el, COLUMN_TOKENS);\n}\n\nfunction containsColumn($el: Cheerio<Element>, $: CheerioAPI): boolean {\n const stop = $el[0];\n let found = false;\n $el.find(\"table\").each((_, node) => {\n if (found) return;\n const $n = $(node) as Cheerio<Element>;\n if (!hasAnyToken($n, COLUMN_TOKENS)) return;\n let $parent = $n.parent();\n while ($parent.length > 0 && $parent[0] !== stop) {\n if (hasAnyToken($parent as Cheerio<Element>, COLUMN_TOKENS)) return;\n $parent = $parent.parent();\n }\n found = true;\n });\n return found;\n}\n\n/**\n * Columns in one cell are one section. Flow before them, between them and\n * after them becomes its own one-column section, in that order.\n */\nfunction collectPieces($root: Cheerio<Element>, $: CheerioAPI): Piece[] {\n const pieces: Piece[] = [];\n const walk = ($parent: Cheerio<Element>) => {\n const flow: AnyNode[] = [];\n const flush = () => {\n if (flow.length === 0) return;\n pieces.push({ kind: \"flow\", nodes: flow.splice(0, flow.length) });\n };\n for (const node of $parent.contents().toArray()) {\n if (node.type === \"text\") {\n if (node.data.trim()) flow.push(node);\n continue;\n }\n if (node.type !== \"tag\") continue;\n const $el = $(node) as Cheerio<Element>;\n if (isHidden($el)) continue;\n if (isColumn($el)) {\n flush();\n pieces.push({ kind: \"column\", el: node });\n continue;\n }\n if (containsColumn($el, $)) {\n flush();\n walk($el);\n continue;\n }\n flow.push(node);\n }\n flush();\n };\n walk($root);\n return pieces;\n}\n\nfunction widgetKind($el: Cheerio<Element>): WidgetKind | null {\n if (hasToken($el, \"es-menu\")) {\n if (!$el.is(\"table\") && $el.find(\"table\").length > 0) return null;\n return \"menu\";\n }\n if (hasToken($el, \"es-social\")) return \"social\";\n if (hasToken($el, \"es-button\")) {\n if ($el.is(\"a\") || $el.find(\"a\").length > 0) return \"button\";\n return null;\n }\n if (hasToken($el, \"es-spacer\")) return \"spacer\";\n return null;\n}\n\nfunction containsWidget($el: Cheerio<Element>, $: CheerioAPI): boolean {\n let found = false;\n $el.find(\"[class]\").each((_, node) => {\n if (found) return;\n if (widgetKind($(node) as Cheerio<Element>)) found = true;\n });\n return found;\n}\n\nfunction widgetBlocks(\n $el: Cheerio<Element>,\n kind: WidgetKind,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room: number | undefined,\n): Block[] {\n if (kind === \"button\") return [buttonFrom($el, \"es-button\", ctx)];\n if (kind === \"spacer\") return [spacerFrom($el, \"es-spacer\", ctx, $, room)];\n if (kind === \"social\") return [socialFrom($el, $, \"es-social\", ctx)];\n const menu = menuFrom($el, $, \"es-menu\", ctx);\n if (menu) return [menu];\n return blocksFromHtml($.html($el) ?? \"\", ctx);\n}\n\n/** Widgets stay where they sit. A run of everything else goes through HTML import. */\nfunction convertRegion(\n nodes: AnyNode[],\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const out: Block[] = [];\n let pending = \"\";\n const flush = () => {\n if (!pending.trim()) {\n pending = \"\";\n return;\n }\n out.push(...blocksFromHtml(pending, ctx));\n pending = \"\";\n };\n const visit = (node: AnyNode) => {\n if (node.type === \"text\") {\n if (node.data.trim()) pending += node.data;\n return;\n }\n if (node.type !== \"tag\") return;\n const $el = $(node) as Cheerio<Element>;\n if ($el.is(\"head, style, script\")) return;\n if (isHidden($el)) return;\n const kind = widgetKind($el);\n if (kind) {\n flush();\n out.push(...widgetBlocks($el, kind, $, ctx, room));\n return;\n }\n if (containsWidget($el, $)) {\n for (const child of $el.contents().toArray()) visit(child);\n return;\n }\n pending += $.html(node) ?? \"\";\n };\n for (const node of nodes) visit(node);\n flush();\n return out;\n}\n\nfunction regionFromElement(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n return convertRegion($el.contents().toArray(), $, ctx, room);\n}\n\nfunction hasBlocks(children: Block[][]): boolean {\n return children.some((column) => column.length > 0);\n}\n\n/** The column table's px width, else its cell's. A non-px length is unread. */\nfunction declaredColumnPx($col: Cheerio<Element>): number | undefined {\n const fromTable = statedPx($col.attr(\"width\"), $col.attr(\"style\"));\n if (fromTable !== undefined) return fromTable;\n const $cell = directCell($col);\n return statedPx($cell.attr(\"width\"), $cell.attr(\"style\"));\n}\n\nfunction columnChildren(\n cols: Element[],\n $: CheerioAPI,\n ctx: ConvertCtx,\n bodyWidth: number,\n padding: SpacingValue,\n): {\n children: Block[][];\n layout: ColumnLayout;\n flattenNote?: string;\n widthNote?: string;\n} | null {\n const count = cols.length;\n const layout: \"1\" | \"2\" | \"3\" | \"4\" =\n count >= 4 ? \"4\" : count === 3 ? \"3\" : count === 2 ? \"2\" : \"1\";\n const fold = count >= 5;\n const used = fold ? 4 : layout === \"1\" ? 1 : count;\n const rooms = columnRooms(bodyWidth, layout, padding, used);\n let children: Block[][];\n if (fold) {\n const rest: Block[] = [];\n for (const el of cols.slice(3)) {\n rest.push(\n ...regionFromElement($(el) as Cheerio<Element>, $, ctx, rooms[3]),\n );\n }\n children = [\n regionFromElement($(cols[0]) as Cheerio<Element>, $, ctx, rooms[0]),\n regionFromElement($(cols[1]) as Cheerio<Element>, $, ctx, rooms[1]),\n regionFromElement($(cols[2]) as Cheerio<Element>, $, ctx, rooms[2]),\n rest,\n ];\n } else {\n children = cols.map((el, index) =>\n regionFromElement($(el) as Cheerio<Element>, $, ctx, rooms[index]),\n );\n }\n if (!hasBlocks(children)) return null;\n const widthNote =\n layout === \"1\"\n ? undefined\n : unequalWidthNote(\n cols.map((el) => declaredColumnPx($(el) as Cheerio<Element>)),\n layout,\n );\n if (!fold) return { children, layout, widthNote };\n const flattenNote = `Row with ${count} columns was flattened; extra columns merged into the fourth slot. Templatical supports up to four columns per section.`;\n ctx.warnings.push(flattenNote);\n return { children, layout, flattenNote, widthNote };\n}\n\nfunction flowNodes(pieces: Piece[]): AnyNode[] {\n return pieces.flatMap((piece) => (piece.kind === \"flow\" ? piece.nodes : []));\n}\n\nfunction groupsFromPieces(\n pieces: Piece[],\n): Array<{ mode: \"flow\" | \"columns\"; pieces: Piece[]; extra?: string }> {\n const columns = pieces.filter((piece) => piece.kind === \"column\");\n if (columns.length === 0) {\n return pieces.length > 0 ? [{ mode: \"flow\", pieces }] : [];\n }\n let first = -1;\n let last = -1;\n pieces.forEach((piece, index) => {\n if (piece.kind !== \"column\") return;\n if (first === -1) first = index;\n last = index;\n });\n const groups: Array<{\n mode: \"flow\" | \"columns\";\n pieces: Piece[];\n extra?: string;\n }> = [];\n const leading = pieces.slice(0, first);\n if (leading.length > 0) groups.push({ mode: \"flow\", pieces: leading });\n groups.push({ mode: \"columns\", pieces: columns });\n const between = pieces\n .slice(first + 1, last)\n .filter((piece) => piece.kind === \"flow\");\n if (between.length > 0) {\n groups.push({ mode: \"flow\", pieces: between, extra: BETWEEN_NOTE });\n }\n const trailing = pieces.slice(last + 1);\n if (trailing.length > 0) groups.push({ mode: \"flow\", pieces: trailing });\n return groups;\n}\n\nfunction sectionsFromRow(\n $row: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n token: string,\n paint: SectionPaint,\n images: StripeImages,\n bodyWidth: number,\n): Block[] {\n if (isHidden($row)) return [];\n const pieces: Piece[] = [];\n let padding = { ...ZERO };\n let sawCell = false;\n let $structure: Cheerio<Element> | null = null;\n $row.children(\"td, th\").each((_, cell) => {\n const $cell = $(cell) as Cheerio<Element>;\n if (isHidden($cell)) return;\n if (!sawCell) {\n padding = readBoxPadding($cell.attr(\"class\"), $cell.attr(\"style\"));\n sawCell = true;\n $structure = $cell;\n }\n pieces.push(...collectPieces($cell, $));\n });\n if (!sawCell || pieces.length === 0) return [];\n\n const rendered: Array<{\n children: Block[][];\n layout: ColumnLayout;\n extra?: string;\n widthNote?: string;\n columnImages: Array<ReadBackgroundImage | null>;\n }> = [];\n for (const group of groupsFromPieces(pieces)) {\n if (group.mode === \"columns\") {\n const cols = group.pieces.flatMap((piece) =>\n piece.kind === \"column\" ? [piece.el] : [],\n );\n const built = columnChildren(cols, $, ctx, bodyWidth, padding);\n if (!built) continue;\n rendered.push({\n children: built.children,\n layout: built.layout,\n extra: built.flattenNote,\n widthNote: built.widthNote,\n columnImages: cols.map((el) =>\n columnImage($(el) as Cheerio<Element>, bodyWidth),\n ),\n });\n continue;\n }\n const blocks = convertRegion(\n flowNodes(group.pieces),\n $,\n ctx,\n columnRooms(bodyWidth, \"1\", padding, 1)[0],\n );\n if (blocks.length === 0) continue;\n rendered.push({\n children: [blocks],\n layout: \"1\",\n extra: group.extra,\n columnImages: [],\n });\n }\n if (rendered.length === 0) return [];\n\n const seam =\n rendered.length > 1 && hasPadding(padding) ? SEAM_NOTE : undefined;\n const structure = imageLayer($structure, \"Section\", bodyWidth);\n return rendered.map((group, index) => {\n const image = resolveSectionImage({\n structure,\n body: images.body,\n band: images.band,\n columns: group.columnImages,\n bodyPainted: images.bodyPainted,\n });\n const groupPaint = withoutBandOverImage(paint, image.image !== undefined);\n const notes = [\n ...groupPaint.notes,\n group.extra,\n group.widthNote,\n ...image.notes,\n seam,\n ].filter((note): note is string => Boolean(note));\n const entry = pushEntry(\n ctx,\n token,\n \"section\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n recordImageSpan(ctx, image.source, entry);\n recordImageSpan(ctx, image.bandSource, entry);\n const wrapper = sectionWrapper(groupPaint, image.band);\n const section = createSectionBlock({\n columns: group.layout,\n children: group.children,\n styles: { padding: splitPadding(padding, rendered.length, index) },\n ...(wrapper ? { wrapper } : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, groupPaint.backgroundColor);\n });\n}\n\nfunction sectionsFromStripe(\n $stripe: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block[] {\n if (isHidden($stripe)) return [];\n const token = stripeToken($stripe) ?? \"es-content\";\n const $body = $stripe.find(BODY_SELECTOR).first() as Cheerio<Element>;\n const rows = $body.length > 0 ? directRows($body, $) : directRows($stripe, $);\n const $width = $body.length > 0 ? $body : $stripe;\n const bodyWidth = emailBodyWidth($width.attr(\"width\"), $width.attr(\"style\"));\n const paint = resolveSectionPaint(\n ctx.pageBackground ?? \"#ffffff\",\n bandColor($stripe),\n $body.length > 0 ? paintOf($body) : \"\",\n $body.length > 0,\n );\n const images: StripeImages = {\n body: imageLayer($body, \"Section\", bodyWidth),\n band: bandImage($stripe, directCell($stripe), bodyWidth),\n bodyPainted: $body.length > 0 && paintOf($body) !== \"\",\n };\n const out: Block[] = [];\n for (const $row of rows) {\n out.push(...sectionsFromRow($row, $, ctx, token, paint, images, bodyWidth));\n }\n return out;\n}\n\nexport function convertCompiled(html: string, ctx: ConvertCtx): Block[] {\n const $ = load(html);\n const stripes = topStripes($);\n if (stripes.length === 0) {\n return convertRegion($.root().contents().toArray(), $, ctx);\n }\n const out: Block[] = [];\n for (const $stripe of stripes)\n out.push(...sectionsFromStripe($stripe, $, ctx));\n return out;\n}\n","const EDITOR_TOKENS = new Set([\n \"esd-stripe\",\n \"esd-structure\",\n \"esd-container-frame\",\n]);\n\nconst COMPILED_TOKENS = new Set([\n \"es-wrapper\",\n \"es-content-body\",\n \"es-header-body\",\n]);\n\nexport type StripoKind = \"editor\" | \"compiled\";\n\nfunction isTagNameEnd(ch: string | undefined): boolean {\n return ch === undefined || !/[A-Za-z0-9_]/.test(ch);\n}\n\n/**\n * Drop every `tag` element, including a closer with extra attributes or\n * whitespace (`</style >`, `</script foo>`). Linear `indexOf` — a regex\n * here fails `js/bad-tag-filter` or `js/polynomial-redos`, and Cheerio\n * rewrites a bare `<td>` fragment and would drop the attributes we need.\n */\nfunction withoutElements(html: string, tag: string): string {\n const open = `<${tag}`;\n const close = `</${tag}`;\n const lower = html.toLowerCase();\n let out = \"\";\n let pos = 0;\n while (pos < html.length) {\n const start = lower.indexOf(open, pos);\n if (start === -1) {\n out += html.slice(pos);\n break;\n }\n if (!isTagNameEnd(lower[start + open.length])) {\n out += html.slice(pos, start + open.length);\n pos = start + open.length;\n continue;\n }\n out += html.slice(pos, start);\n const gt = html.indexOf(\">\", start);\n if (gt === -1) break;\n const closeAt = lower.indexOf(close, gt + 1);\n if (closeAt === -1) break;\n const closeGt = html.indexOf(\">\", closeAt);\n if (closeGt === -1) break;\n out += \" \";\n pos = closeGt + 1;\n }\n return out;\n}\n\n/**\n * Class tokens from attributes only. Stylesheets and scripts are dropped\n * first so a compiled leftover `.esd-block-html table` rule cannot trip\n * editor detection.\n */\nfunction markupClassTokens(html: string): string[] {\n const stripped = withoutElements(withoutElements(html, \"style\"), \"script\");\n const tokens: string[] = [];\n const re = /\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/gi;\n let m: RegExpExecArray | null;\n while ((m = re.exec(stripped))) {\n tokens.push(...m[2].trim().split(/\\s+/).filter(Boolean));\n }\n return tokens;\n}\n\nfunction isEditorToken(token: string): boolean {\n return EDITOR_TOKENS.has(token) || token.startsWith(\"esd-block-\");\n}\n\n/**\n * Which Stripo HTML surface this is, or null if it is not Stripo markup.\n *\n * Editor-source (`getTemplateData`) carries `esd-*` on elements. Compiled\n * export carries `es-wrapper` / `es-*-body` and never `esd-*` on a class\n * attribute. A CSS-only leftover (`.esd-block-html` in a stylesheet) is not\n * a discriminator — stylesheets are stripped before the check.\n */\nexport function detectStripoKind(html: string): StripoKind | null {\n if (typeof html !== \"string\" || html.trim().length === 0) return null;\n const tokens = markupClassTokens(html);\n if (tokens.some(isEditorToken)) return \"editor\";\n if (tokens.some((t) => COMPILED_TOKENS.has(t))) return \"compiled\";\n return null;\n}\n\nexport function isStripoHtml(html: string): boolean {\n return detectStripoKind(html) !== null;\n}\n","import { load, type Cheerio, type CheerioAPI } from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport { createHtmlBlock, createSectionBlock } from \"@templatical/types\";\nimport type { Block, SpacingValue } from \"@templatical/types\";\nimport {\n hasAnyToken,\n isHidden,\n tokenStartingWith,\n topLevelWithToken,\n} from \"./classes\";\nimport { statedPx, unequalWidthNote } from \"./column-width\";\nimport {\n colorFromPaint,\n columnRooms,\n emailBodyWidth,\n readBoxPadding,\n resolveSectionImage,\n resolveSectionPaint,\n sectionWrapper,\n withoutBandOverImage,\n type SectionPaint,\n} from \"./css\";\nimport {\n bandImage,\n imageLayer,\n imageOf,\n pushEntry,\n recordImageSpan,\n withBackground,\n type ConvertCtx,\n} from \"./fragment\";\nimport {\n buttonFrom,\n labelledInnerBlocks,\n menuFrom,\n socialFrom,\n spacerFrom,\n} from \"./labelled\";\n\nconst ZERO: SpacingValue = { top: 0, right: 0, bottom: 0, left: 0 };\nconst BODY_SELECTOR =\n \"[class~='es-header-body'], [class~='es-content-body'], [class~='es-footer-body']\";\nconst COLUMN_TOKENS = [\"es-left\", \"es-right\"] as const;\n\nfunction columnLayout(\n count: number,\n ctx: ConvertCtx,\n): { layout: \"1\" | \"2\" | \"3\" | \"4\"; flattenNote?: string } {\n if (count <= 1) return { layout: \"1\" };\n if (count === 2) return { layout: \"2\" };\n if (count === 3) return { layout: \"3\" };\n if (count === 4) return { layout: \"4\" };\n const flattenNote = `Row with ${count} columns was flattened to a single column. Templatical supports up to four columns per section.`;\n ctx.warnings.push(flattenNote);\n return { layout: \"1\", flattenNote };\n}\n\n/** The frame's `es-left` / `es-right` table, stopping at the structure. */\nfunction columnTable(\n $frame: Cheerio<Element>,\n $structure: Cheerio<Element>,\n): Cheerio<Element> | null {\n const stop = $structure[0];\n let $parent = $frame.parent();\n while ($parent.length > 0 && $parent[0] !== stop) {\n if (\n $parent.is(\"table\") &&\n hasAnyToken($parent as Cheerio<Element>, COLUMN_TOKENS)\n ) {\n return $parent as Cheerio<Element>;\n }\n $parent = $parent.parent();\n }\n return null;\n}\n\n/** Column-table width, else the frame's. A non-px width is unread. */\nfunction frameWidth(\n $frame: Cheerio<Element>,\n $structure: Cheerio<Element>,\n): number | undefined {\n const $table = columnTable($frame, $structure);\n if ($table) {\n const fromTable = statedPx($table.attr(\"width\"), $table.attr(\"style\"));\n if (fromTable !== undefined) return fromTable;\n }\n return statedPx($frame.attr(\"width\"), $frame.attr(\"style\"));\n}\n\nfunction esdBlockKind($el: Cheerio<Element>): string | undefined {\n const token = tokenStartingWith($el, \"esd-block-\");\n return token ? token.slice(\"esd-block-\".length) : undefined;\n}\n\nfunction convertEsdBlock(\n $el: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const kind = esdBlockKind($el);\n if (!kind) return labelledInnerBlocks($el, $, ctx);\n if (kind === \"button\") return [buttonFrom($el, \"esd-block-button\", ctx)];\n if (kind === \"spacer\")\n return [spacerFrom($el, \"esd-block-spacer\", ctx, $, room)];\n if (kind === \"social\") return [socialFrom($el, $, \"esd-block-social\", ctx)];\n if (kind === \"menu\") {\n const menu = menuFrom($el, $, \"esd-block-menu\", ctx);\n if (menu) return [menu];\n return labelledInnerBlocks($el, $, ctx);\n }\n if (kind === \"html\") {\n pushEntry(\n ctx,\n \"esd-block-html\",\n \"html\",\n \"html-fallback\",\n \"HTML block preserved as HTML.\",\n );\n return [createHtmlBlock({ content: ($el.html() ?? \"\").trim() })];\n }\n // image / text / anything else: generic HTML mapping of the inner markup\n pushEntry(\n ctx,\n `esd-block-${kind}`,\n kind === \"image\" ? \"image\" : \"paragraph\",\n \"converted\",\n );\n return labelledInnerBlocks($el, $, ctx);\n}\n\nfunction blocksInContainer(\n $frame: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n room?: number,\n): Block[] {\n const out: Block[] = [];\n const seen = new Set<Element>();\n $frame.find(\"[class]\").each((_, node) => {\n const $el = $(node) as Cheerio<Element>;\n if (!tokenStartingWith($el, \"esd-block-\")) return;\n const nested = $el\n .parents()\n .toArray()\n .some((p) => tokenStartingWith($(p) as Cheerio<Element>, \"esd-block-\"));\n if (nested) return;\n if (seen.has(node)) return;\n seen.add(node);\n out.push(...convertEsdBlock($el, $, ctx, room));\n });\n if (out.length === 0) return labelledInnerBlocks($frame, $, ctx);\n return out;\n}\n\nfunction enclosing(\n $el: Cheerio<Element>,\n selector: string,\n): Cheerio<Element> | null {\n if ($el.is(selector)) return $el;\n const $parent = $el.parents(selector).first();\n return $parent.length > 0 ? ($parent as Cheerio<Element>) : null;\n}\n\n/** A table stripe's first cell, which Stripo paints instead of the table. */\nfunction bandCell($stripe: Cheerio<Element>): Cheerio<Element> {\n const $direct = $stripe.children(\"tr\").children(\"td, th\");\n const $nested = $stripe\n .children(\"tbody, thead\")\n .children(\"tr\")\n .children(\"td, th\");\n return ($direct.length > 0 ? $direct : $nested).first() as Cheerio<Element>;\n}\n\nfunction bandColor($stripe: Cheerio<Element>): string {\n const own = colorFromPaint($stripe.attr(\"style\"), $stripe.attr(\"bgcolor\"));\n if (own) return own;\n if ($stripe.is(\"td\") || $stripe.is(\"th\")) return \"\";\n const $cell = bandCell($stripe);\n return $cell.length > 0\n ? colorFromPaint($cell.attr(\"style\"), $cell.attr(\"bgcolor\"))\n : \"\";\n}\n\nfunction paintFor(\n $el: Cheerio<Element>,\n ctx: ConvertCtx,\n bleed = false,\n): SectionPaint {\n const $stripe = enclosing($el, \"[class~='esd-stripe']\");\n const $body = enclosing($el, BODY_SELECTOR);\n return resolveSectionPaint(\n ctx.pageBackground ?? \"#ffffff\",\n $stripe ? bandColor($stripe) : \"\",\n $body ? colorFromPaint($body.attr(\"style\"), $body.attr(\"bgcolor\")) : \"\",\n bleed,\n );\n}\n\nfunction sectionFromStructure(\n $structure: Cheerio<Element>,\n $: CheerioAPI,\n ctx: ConvertCtx,\n): Block {\n const frames = $structure\n .find(\"[class~='esd-container-frame']\")\n .toArray()\n .map((n) => $(n) as Cheerio<Element>)\n .filter(($el) => {\n if (isHidden($el)) return false;\n return (\n $el.parents(\"[class~='esd-container-frame']\").filter((_, p) => {\n return $(p).closest($structure).length > 0;\n }).length === 0\n );\n });\n\n const frameCount = frames.length;\n const { layout, flattenNote } = columnLayout(\n frameCount === 0 ? 1 : frameCount,\n ctx,\n );\n const padding = readBoxPadding(\n $structure.attr(\"class\"),\n $structure.attr(\"style\"),\n );\n const $body = enclosing($structure, BODY_SELECTOR);\n const bodyWidth = emailBodyWidth($body?.attr(\"width\"), $body?.attr(\"style\"));\n const rooms = columnRooms(\n bodyWidth,\n layout,\n padding,\n layout === \"1\" ? 1 : frameCount,\n );\n let children: Block[][];\n if (layout === \"1\") {\n const merged: Block[] = [];\n const room = rooms[0];\n if (frames.length === 0) {\n merged.push(...blocksInContainer($structure, $, ctx, room));\n } else {\n for (const $f of frames)\n merged.push(...blocksInContainer($f, $, ctx, room));\n }\n children = [merged];\n } else {\n children = frames.map(($f, index) =>\n blocksInContainer($f, $, ctx, rooms[index]),\n );\n }\n const $stripe = enclosing($structure, \"[class~='esd-stripe']\");\n const image = resolveSectionImage({\n structure: imageLayer($structure, \"Section\", bodyWidth),\n body: imageLayer($body, \"Section\", bodyWidth),\n band: $stripe ? bandImage($stripe, bandCell($stripe), bodyWidth) : null,\n columns: frames.map(($f) => imageOf($f, \"Column\", bodyWidth)),\n bodyPainted: $body\n ? colorFromPaint($body.attr(\"style\"), $body.attr(\"bgcolor\")) !== \"\"\n : false,\n });\n // A stripe with no inner body keeps its colour on the section.\n const paint = withoutBandOverImage(\n paintFor($structure, ctx, $stripe !== null && $body !== null),\n image.image !== undefined,\n );\n const widthNote =\n layout === \"1\"\n ? undefined\n : unequalWidthNote(\n frames.map(($frame) => frameWidth($frame, $structure)),\n layout,\n );\n const notes = [...paint.notes, flattenNote, widthNote, ...image.notes].filter(\n (note): note is string => Boolean(note),\n );\n const entry = pushEntry(\n ctx,\n \"esd-structure\",\n \"section\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n recordImageSpan(ctx, image.source, entry);\n recordImageSpan(ctx, image.bandSource, entry);\n const wrapper = sectionWrapper(paint, image.band);\n const section = createSectionBlock({\n columns: layout,\n children,\n styles: { padding },\n ...(wrapper ? { wrapper } : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, paint.backgroundColor);\n}\n\nexport function convertEditor(html: string, ctx: ConvertCtx): Block[] {\n const $ = load(html);\n const structures = topLevelWithToken($, \"esd-structure\");\n if (structures.length > 0) {\n return structures.map(($s) => sectionFromStructure($s, $, ctx));\n }\n const stripes = topLevelWithToken($, \"esd-stripe\");\n if (stripes.length === 0) {\n return labelledInnerBlocks($.root() as unknown as Cheerio<Element>, $, ctx);\n }\n return stripes.map(($stripe) => {\n const inner = $stripe.find(\"[class~='esd-structure']\");\n if (inner.length > 0) {\n return sectionFromStructure(inner.first() as Cheerio<Element>, $, ctx);\n }\n const image = resolveSectionImage({\n structure: null,\n body: null,\n band: bandImage($stripe, bandCell($stripe), 600),\n columns: [],\n bodyPainted: false,\n });\n const paint = withoutBandOverImage(\n paintFor($stripe, ctx),\n image.image !== undefined,\n );\n const notes = [...paint.notes, ...image.notes].filter(\n (note): note is string => Boolean(note),\n );\n const entry = pushEntry(\n ctx,\n \"esd-stripe\",\n \"section\",\n notes.length > 0 ? \"approximated\" : \"converted\",\n notes.length > 0 ? notes.join(\" \") : undefined,\n );\n recordImageSpan(ctx, image.source, entry);\n recordImageSpan(ctx, image.bandSource, entry);\n const wrapper = sectionWrapper(paint, image.band);\n const section = createSectionBlock({\n columns: \"1\",\n children: [\n blocksInContainer($stripe, $, ctx, columnRooms(600, \"1\", ZERO, 1)[0]),\n ],\n styles: { padding: { ...ZERO } },\n ...(wrapper ? { wrapper } : {}),\n ...(image.image ? { backgroundImage: image.image } : {}),\n });\n return withBackground(section, paint.backgroundColor);\n });\n}\n","import { load, type CheerioAPI } from \"cheerio\";\nimport { convertHtmlTemplate } from \"@templatical/import-html\";\nimport type { ImportReport, ImportResult } from \"@templatical/import-html\";\nimport { createDefaultTemplateContent, isLocaleTag } from \"@templatical/types\";\nimport { convertCompiled } from \"./compiled\";\nimport { colorFromPaint, imageFromPaint } from \"./css\";\nimport { detectStripoKind } from \"./detect\";\nimport { convertEditor } from \"./editor\";\nimport { noteImageSpans, type ConvertCtx } from \"./fragment\";\n\nexport interface ConvertStripoOptions {\n /** Used when the source declares no default language. */\n defaultLocale?: string;\n /** Sibling CSS from plugin `getTemplateData()`. Applied inside each HTML fragment. */\n css?: string;\n}\n\n/**\n * The default language, as `convertHtmlTemplate` reads it: `<html lang>`, else\n * `defaultLocale`, else `\"en\"`. A value that isn't a language tag after `_` →\n * `-` is skipped, with a warning naming it. The fallback converter warns on its\n * own report, so the Stripo path repeats the check for its report.\n */\nfunction defaultLanguage(\n declared: string | undefined,\n defaultLocale: string | undefined,\n warnings: string[],\n): string {\n const rejected: string[] = [];\n let locale = \"en\";\n for (const [value, name] of [\n [declared, \"the source's default language\"],\n [defaultLocale, \"defaultLocale\"],\n ] as const) {\n if (!value) continue;\n const tag = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(tag)) {\n locale = tag;\n break;\n }\n rejected.push(`Ignored ${name} \"${value}\": unsupported language tag.`);\n }\n for (const message of rejected) warnings.push(`${message} Used \"${locale}\".`);\n return locale;\n}\n\nfunction injectCss(html: string, css?: string): string {\n if (!css || css.trim().length === 0) return html;\n const $ = load(html);\n if ($(\"head\").length === 0) {\n $(\"html\").prepend(\"<head></head>\");\n }\n // Style elements serialize as HTML rawtext, so a literal `</style` in the\n // CSS would close the element and the rest would parse as markup — which\n // can flip editor/compiled detection. Neutralize the closer; then set a\n // text node rather than interpolating into an HTML string.\n const safe = css.replace(/<\\/style/gi, \"<\\\\/style\");\n const $style = $(\"<style></style>\").attr(\"data-stripo-css\", \"1\").text(safe);\n $(\"head\").append($style);\n return $.html() ?? html;\n}\n\n/** First painted `es-wrapper-color` / `es-wrapper`, or white when neither is set. */\nfunction pageBackground($: CheerioAPI): string {\n const nodes = $(\n \"[class~='es-wrapper-color'], [class~='es-wrapper']\",\n ).toArray();\n for (const node of nodes) {\n const $el = $(node);\n const color = colorFromPaint($el.attr(\"style\"), $el.attr(\"bgcolor\"));\n if (color) return color;\n }\n return \"#ffffff\";\n}\n\n/** The page's background image, which has no Templatical equivalent: the first `es-wrapper-color` / `es-wrapper` that paints one. */\nfunction pageImageWarning($: CheerioAPI): string | null {\n const nodes = $(\n \"[class~='es-wrapper-color'], [class~='es-wrapper']\",\n ).toArray();\n for (const node of nodes) {\n const $el = $(node);\n const read = imageFromPaint(\n $el.attr(\"style\"),\n $el.attr(\"background\"),\n \"Page\",\n undefined,\n );\n if (read) {\n return `The email background image \"${read.image.url}\" was dropped; Templatical has no email-level background image.`;\n }\n }\n return null;\n}\n\nfunction summarize(ctx: ConvertCtx): ImportReport {\n const summary = {\n total: ctx.entries.length,\n converted: 0,\n approximated: 0,\n htmlFallback: 0,\n skipped: 0,\n };\n for (const e of ctx.entries) {\n if (e.status === \"converted\") summary.converted++;\n else if (e.status === \"approximated\") summary.approximated++;\n else if (e.status === \"html-fallback\") summary.htmlFallback++;\n else if (e.status === \"skipped\") summary.skipped++;\n }\n return { entries: ctx.entries, warnings: ctx.warnings, summary };\n}\n\n/**\n * Convert a Stripo template to Templatical content.\n *\n * Auto-detects the surface from class attributes:\n * - `esd-*` on elements → plugin/editor `getTemplateData` HTML\n * - `es-wrapper` / `es-*-body` without `esd-*` → compiled File→HTML export\n *\n * Pass `options.css` when converting plugin storage (`getTemplateData().css`).\n */\nexport function convertStripoTemplate(\n html: string,\n options?: ConvertStripoOptions,\n): ImportResult {\n if (typeof html !== \"string\") {\n throw new Error(\n \"Invalid Stripo template: expected a string. Pass the HTML source as a string.\",\n );\n }\n if (html.trim().length === 0) {\n throw new Error(\n \"Invalid Stripo template: input is empty. Pass the HTML source of a Stripo email.\",\n );\n }\n\n const prepared = injectCss(html, options?.css);\n const kind = detectStripoKind(prepared);\n const fallback = convertHtmlTemplate(prepared, {\n defaultLocale: options?.defaultLocale,\n });\n\n if (!kind) {\n return {\n content: fallback.content,\n report: {\n ...fallback.report,\n warnings: [\n \"No Stripo class attributes found; converted as generic HTML.\",\n ...fallback.report.warnings,\n ],\n },\n };\n }\n\n const ctx: ConvertCtx = {\n entries: [],\n warnings: [],\n css: options?.css,\n };\n const $page = load(prepared);\n const locale = defaultLanguage(\n $page(\"html\").attr(\"lang\")?.trim(),\n options?.defaultLocale,\n ctx.warnings,\n );\n const pageBg = pageBackground($page);\n const pageImage = pageImageWarning($page);\n if (pageImage) ctx.warnings.push(pageImage);\n ctx.pageBackground = pageBg;\n const blocks =\n kind === \"editor\"\n ? convertEditor(prepared, ctx)\n : convertCompiled(prepared, ctx);\n noteImageSpans(ctx);\n\n // After `fallback.content`: its settings carry the HTML importer's white\n // page, which would hide the wrapper colour.\n const defaults = createDefaultTemplateContent();\n return {\n content: {\n ...defaults,\n ...fallback.content,\n blocks,\n settings: {\n ...defaults.settings,\n ...fallback.content.settings,\n locale,\n backgroundColor: pageBg,\n },\n },\n report: summarize(ctx),\n };\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,KAAiC;CAC3D,QAAQ,IAAI,KAAK,OAAO,KAAK,GAAA,CAAI,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;AACrE;AAEA,SAAgB,SAAS,KAAuB,OAAwB;CACtE,OAAO,YAAY,GAAG,CAAC,CAAC,SAAS,KAAK;AACxC;AAEA,SAAgB,YACd,KACA,QACS;CACT,MAAM,MAAM,IAAI,IAAI,YAAY,GAAG,CAAC;CACpC,OAAO,OAAO,MAAM,MAAM,IAAI,IAAI,CAAC,CAAC;AACtC;AAEA,SAAgB,kBACd,KACA,QACoB;CACpB,OAAO,YAAY,GAAG,CAAC,CAAC,MAAM,MAAM,EAAE,WAAW,MAAM,CAAC;AAC1D;;AAGA,SAAgB,kBACd,GACA,OACA,OACoB;CACpB,MAAM,WAAW,YAAY,MAAM;CACnC,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GACnB;EACF;EACA,QAAQ,UAAU,GAAG;CACvB;AACF"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@templatical/import-stripo",
3
3
  "description": "Convert Stripo email templates to Templatical format",
4
- "version": "0.54.2",
4
+ "version": "0.56.0",
5
5
  "bugs": "https://github.com/templatical/sdk/issues",
6
6
  "dependencies": {
7
- "@templatical/import-html": "0.54.2",
8
- "@templatical/types": "0.54.2",
7
+ "@templatical/import-html": "0.56.0",
8
+ "@templatical/types": "0.56.0",
9
9
  "cheerio": "^1.2.0",
10
10
  "domhandler": "^6.0.1"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/node": "^26.6.6",
14
14
  "typescript": "^6.0.3",
15
- "vitest": "^5.0.5"
15
+ "vitest": "^5.1.0"
16
16
  },
17
17
  "exports": {
18
18
  ".": {