@templatical/import-topol 0.59.1 → 0.60.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
@@ -1,4 +1,4 @@
1
- import { DEFAULT_TEMPLATE_DEFAULTS, canonicalFontStack, createButtonBlock, createDefaultTemplateContent, createDividerBlock, createHtmlBlock, createImageBlock, createParagraphBlock, createSectionBlock, createSocialIconsBlock, createSpacerBlock, createTitleBlock, findOpenTagEnd, generateId, isLocaleTag, sourceHash } from "@templatical/types";
1
+ import { BUTTON_BLOCK_DEFAULTS, BUTTON_LINE_HEIGHT, COLUMN_LAYOUT_PERCENTS, DEFAULT_TEMPLATE_DEFAULTS, canonicalFontStack, columnWidthsIssue, createButtonBlock, createDefaultTemplateContent, createDividerBlock, createHtmlBlock, createImageBlock, createParagraphBlock, createSectionBlock, createSocialIconsBlock, createSpacerBlock, createTitleBlock, findOpenTagEnd, generateId, isLocaleTag, roundHundredths, sectionColumnPercents, sourceHash } from "@templatical/types";
2
2
  // src/localization.ts
3
3
  const seenWarnings = /* @__PURE__ */ new WeakMap();
4
4
  function warn(warnings, message) {
@@ -635,14 +635,48 @@ function convertText(node, ctx) {
635
635
  }
636
636
  };
637
637
  }
638
+ /**
639
+ * A button's line height as `ButtonBlock.lineHeight`, a multiple of
640
+ * `fontSize`. A percentage is that number over 100, a unitless number is
641
+ * itself, a px length is that many pixels over `fontSize`, and an `em`
642
+ * length is the number itself. A leading dot (`.5`) is read. Rounded to two
643
+ * decimals. A missing value, `normal`, and a value that rounds to 1.2 stay
644
+ * unset, so the label keeps `BUTTON_LINE_HEIGHT`. Any other value that
645
+ * cannot be kept stays unset and pushes a note.
646
+ */
647
+ function readButtonLineHeight(value, fontSize, notes) {
648
+ const trimmed = String(value ?? "").trim();
649
+ if (trimmed === "" || /^normal$/i.test(trimmed)) return void 0;
650
+ const percent = /^((?:\d+(?:\.\d+)?|\.\d+))\s*%$/.exec(trimmed);
651
+ const unitless = /^((?:\d+(?:\.\d+)?|\.\d+))$/.exec(trimmed);
652
+ const px = /^((?:\d+(?:\.\d+)?|\.\d+))\s*px$/i.exec(trimmed);
653
+ const em = /^((?:\d+(?:\.\d+)?|\.\d+))\s*em$/i.exec(trimmed);
654
+ let ratio = NaN;
655
+ if (percent) ratio = Number(percent[1]) / 100;
656
+ else if (unitless) ratio = Number(unitless[1]);
657
+ else if (px) ratio = Number(px[1]) / fontSize;
658
+ else if (em) ratio = Number(em[1]);
659
+ const rounded = roundHundredths(ratio);
660
+ if (!Number.isFinite(rounded) || !(rounded > 0)) {
661
+ notes.push(`Button line-height "${trimmed}" could not be read; imported at 1.2.`);
662
+ return;
663
+ }
664
+ return rounded === BUTTON_LINE_HEIGHT ? void 0 : rounded;
665
+ }
638
666
  function convertButton(node, ctx) {
639
667
  const text = stripTags(node.content);
640
668
  if (!text) return null;
641
669
  const backgroundColor = parseColor(resolved(node, "background-color", ctx, "button"));
642
670
  const textColor = parseColor(resolved(node, "color", ctx, "button"));
643
671
  const fontFamily = canonicalFontStack(resolved(node, "font-family", ctx, "button"));
644
- const fontSizeRaw = resolved(node, "font-size", ctx);
672
+ const factorySize = Number(BUTTON_BLOCK_DEFAULTS.fontSize);
673
+ const statedFontSize = String(resolved(node, "font-size", ctx) ?? "").trim();
674
+ const parsedFontSize = parsePxValue(statedFontSize);
675
+ const fontSize = Number.isFinite(parsedFontSize) && parsedFontSize > 0 ? parsedFontSize : void 0;
645
676
  const radiusRaw = resolved(node, "border-radius", ctx);
677
+ const notes = [];
678
+ if (statedFontSize !== "" && fontSize === void 0) notes.push(`Button font-size "${statedFontSize}" could not be read; imported at ${factorySize}px.`);
679
+ const lineHeight = readButtonLineHeight(resolved(node, "line-height", ctx, "button"), fontSize ?? factorySize, notes);
646
680
  return {
647
681
  block: createButtonBlock({
648
682
  text,
@@ -650,7 +684,8 @@ function convertButton(node, ctx) {
650
684
  ...backgroundColor ? { backgroundColor } : {},
651
685
  ...textColor ? { textColor } : {},
652
686
  ...fontFamily ? { fontFamily } : {},
653
- ...fontSizeRaw === void 0 ? {} : { fontSize: parsePxValue(fontSizeRaw) },
687
+ ...fontSize !== void 0 ? { fontSize } : {},
688
+ ...lineHeight !== void 0 ? { lineHeight } : {},
654
689
  ...radiusRaw === void 0 ? {} : { borderRadius: parsePxValue(radiusRaw) },
655
690
  align: parseAlignment(attr(node, "align"), "center"),
656
691
  ...baseStyles(node)
@@ -658,7 +693,8 @@ function convertButton(node, ctx) {
658
693
  entry: {
659
694
  sourceTag: node.tagName,
660
695
  templaticalBlockType: "button",
661
- status: "converted"
696
+ status: notes.length > 0 ? "approximated" : "converted",
697
+ ...notes.length > 0 ? { note: notes.join(" ") } : {}
662
698
  }
663
699
  };
664
700
  }
@@ -885,58 +921,38 @@ function convertSocial(node, _ctx) {
885
921
  };
886
922
  }
887
923
  // src/section-builder.ts
888
- const LAYOUT_SHAPES = [
889
- {
890
- layout: "1",
891
- percents: [100]
892
- },
893
- {
894
- layout: "2",
895
- percents: [50, 50]
896
- },
897
- {
898
- layout: "1-2",
899
- percents: [33.33, 66.67]
900
- },
901
- {
902
- layout: "2-1",
903
- percents: [66.67, 33.33]
904
- },
905
- {
906
- layout: "1-3",
907
- percents: [25, 75]
908
- },
909
- {
910
- layout: "3-1",
911
- percents: [75, 25]
912
- },
913
- {
914
- layout: "3",
915
- percents: [
916
- 33.33,
917
- 33.33,
918
- 33.34
919
- ]
920
- },
921
- {
922
- layout: "1-2-1",
923
- percents: [
924
- 25,
925
- 50,
926
- 25
927
- ]
928
- },
929
- {
930
- layout: "4",
931
- percents: [
932
- 25,
933
- 25,
934
- 25,
935
- 25
936
- ]
937
- }
924
+ /** Preset match order. The first preset within the tolerance wins. */
925
+ const LAYOUT_MATCH_ORDER = [
926
+ "1",
927
+ "2",
928
+ "1-2",
929
+ "2-1",
930
+ "1-3",
931
+ "3-1",
932
+ "3",
933
+ "1-2-1",
934
+ "4"
938
935
  ];
936
+ /** Percentage points of drift tolerated per column before a match is inexact. */
939
937
  const WIDTH_TOLERANCE = 2;
938
+ /**
939
+ * One hundredth, the step `sectionColumnPercents` rounds to, plus the float
940
+ * error of subtracting two hundredths. Scaled shares this close to a preset
941
+ * are that preset.
942
+ */
943
+ const SCALED_TOLERANCE = .01 + 1e-9;
944
+ function evenLayout(count) {
945
+ if (count === 3) return "3";
946
+ if (count === 4) return "4";
947
+ return "2";
948
+ }
949
+ /** The first preset with one share per value, each within `tolerance`. */
950
+ function presetWithin(percents, tolerance) {
951
+ return LAYOUT_MATCH_ORDER.find((layout) => {
952
+ const target = COLUMN_LAYOUT_PERCENTS[layout];
953
+ return target.length === percents.length && target.every((share, index) => Math.abs(share - percents[index]) <= tolerance);
954
+ });
955
+ }
940
956
  const COLUMN_COUNT = {
941
957
  "1": 1,
942
958
  "2": 2,
@@ -948,7 +964,13 @@ const COLUMN_COUNT = {
948
964
  "1-3": 2,
949
965
  "1-2-1": 3
950
966
  };
951
- function columnPixels(layout, container) {
967
+ /**
968
+ * Each column's px width in `container`: the preset's shares, a third for
969
+ * `"3"`, `"1-2"` and `"2-1"`, or the `columnWidths` percentages when the
970
+ * section has them.
971
+ */
972
+ function columnPixels(layout, container, columnWidths) {
973
+ if (columnWidths) return columnWidths.map((percent) => container * percent / 100);
952
974
  switch (layout) {
953
975
  case "2": return [container / 2, container / 2];
954
976
  case "3": return [
@@ -975,11 +997,20 @@ function columnPixels(layout, container) {
975
997
  }
976
998
  }
977
999
  /**
978
- * Resolve column widths to one of the layouts this importer emits.
1000
+ * Resolve `mj-column` widths, as percentages of the section's inner box, to
1001
+ * a layout. Topol renders through MJML, so MJML's rules apply.
979
1002
  *
980
- * `exact: false` means the caller reports `approximated` — Topol permits any
981
- * column count at any width and this importer emits nine layouts, so this is the
982
- * importer's main irreducible loss.
1003
+ * A width list within `WIDTH_TOLERANCE` of a preset keeps that preset. An
1004
+ * absent width is `mj-column`'s default, the parent width divided by the
1005
+ * column count, whatever its siblings state, so a row with no widths is
1006
+ * the even preset. One column is `"1"`: exact at 100%, approximated
1007
+ * otherwise. Two, three or four columns that fit no preset are scaled to
1008
+ * 100: scaled shares equal to a preset keep that preset, any others keep
1009
+ * the even preset of that count plus `columnWidths`. Either is exact when
1010
+ * the widths already total 100 within half a point; otherwise scaling
1011
+ * changed the source layout. A width that cannot be stored (not above 0)
1012
+ * keeps the even preset, approximated. Five or more columns fold onto
1013
+ * `"4"`, approximated.
983
1014
  */
984
1015
  function matchColumnLayout(percents) {
985
1016
  const count = percents.length;
@@ -987,51 +1018,58 @@ function matchColumnLayout(percents) {
987
1018
  layout: "1",
988
1019
  exact: true
989
1020
  };
990
- if (percents.every((p) => p === null)) {
991
- if (count === 1) return {
992
- layout: "1",
993
- exact: true
994
- };
995
- if (count === 2) return {
996
- layout: "2",
997
- exact: true
998
- };
999
- if (count === 3) return {
1000
- layout: "3",
1001
- exact: true
1002
- };
1003
- if (count === 4) return {
1004
- layout: "4",
1005
- exact: true
1006
- };
1007
- return {
1008
- layout: "4",
1009
- exact: false
1010
- };
1011
- }
1012
- const known = percents.filter((p) => p !== null);
1013
- const unsetCount = count - known.length;
1014
- const remainder = unsetCount === 0 ? 0 : Math.max(0, 100 - known.reduce((a, b) => a + b, 0)) / unsetCount;
1015
- const resolved = percents.map((p) => p ?? remainder);
1016
- const sameCount = LAYOUT_SHAPES.filter((s) => s.percents.length === count);
1017
- for (const shape of sameCount) if (shape.percents.every((want, i) => Math.abs(want - resolved[i]) <= WIDTH_TOLERANCE)) return {
1018
- layout: shape.layout,
1021
+ if (count > 4) return {
1022
+ layout: "4",
1023
+ exact: false
1024
+ };
1025
+ const resolved = percents.map((percent) => percent ?? 100 / count);
1026
+ const preset = presetWithin(resolved, WIDTH_TOLERANCE);
1027
+ if (preset) return {
1028
+ layout: preset,
1019
1029
  exact: true
1020
1030
  };
1021
- const candidates = sameCount.length > 0 ? sameCount : LAYOUT_SHAPES.filter((s) => s.layout === "4");
1022
- let best = candidates[0];
1023
- let bestError = Infinity;
1024
- for (const shape of candidates) {
1025
- const error = shape.percents.reduce((sum, want, i) => sum + Math.abs(want - (resolved[i] ?? 0)), 0);
1026
- if (error < bestError) {
1027
- bestError = error;
1028
- best = shape;
1029
- }
1030
- }
1031
- return {
1032
- layout: best.layout,
1031
+ if (count === 1) return {
1032
+ layout: "1",
1033
+ exact: false
1034
+ };
1035
+ const layout = evenLayout(count);
1036
+ if (columnWidthsIssue({
1037
+ columns: layout,
1038
+ columnWidths: resolved
1039
+ }) !== null) return {
1040
+ layout,
1033
1041
  exact: false
1034
1042
  };
1043
+ const total = resolved.reduce((sum, share) => sum + share, 0);
1044
+ const exact = Math.abs(total - 100) <= .5;
1045
+ const scaled = sectionColumnPercents({
1046
+ columns: layout,
1047
+ columnWidths: resolved
1048
+ });
1049
+ const scaledPreset = presetWithin(scaled, SCALED_TOLERANCE);
1050
+ if (scaledPreset) return {
1051
+ layout: scaledPreset,
1052
+ exact
1053
+ };
1054
+ return {
1055
+ layout,
1056
+ exact,
1057
+ columnWidths: scaled
1058
+ };
1059
+ }
1060
+ const PX_WIDTH = /^(\d+(?:\.\d+)?)\s*px$/i;
1061
+ /**
1062
+ * A column's `width` as a percentage of `innerWidth`, or `null` when it
1063
+ * states none. A percentage is read as written. A px width is that many
1064
+ * pixels of the inner box, the email width less the section's side
1065
+ * padding, which is the box MJML sizes columns against.
1066
+ */
1067
+ function columnPercent(value, innerWidth) {
1068
+ const percent = parsePercent(value);
1069
+ if (percent !== null) return percent;
1070
+ const px = PX_WIDTH.exec((value ?? "").trim());
1071
+ if (!px || innerWidth <= 0) return null;
1072
+ return Number(px[1]) / innerWidth * 100;
1035
1073
  }
1036
1074
  function convertColumnChildren(column, ctx, entries) {
1037
1075
  const blocks = [];
@@ -1058,10 +1096,15 @@ function convertColumnChildren(column, ctx, entries) {
1058
1096
  function buildSection(node, ctx, entries) {
1059
1097
  const columns = (node.children ?? []).filter((c) => c.tagName === "mj-column");
1060
1098
  if (columns.length === 0) return [];
1099
+ const padding = parsePadding(node);
1100
+ const innerWidth = ctx.style.settings.width - padding.left - padding.right;
1061
1101
  const rawWidths = columns.map((c) => attr(c, "width"));
1062
- const { layout, exact } = matchColumnLayout(rawWidths.map((w) => parsePercent(w)));
1102
+ const matched = matchColumnLayout(rawWidths.map((w) => columnPercent(w, innerWidth)));
1103
+ const { layout, columnWidths } = matched;
1104
+ const pxDropped = innerWidth <= 0 && rawWidths.some((w) => w !== void 0 && PX_WIDTH.test(w.trim()));
1105
+ const exact = matched.exact && !pxDropped;
1063
1106
  const slots = COLUMN_COUNT[layout];
1064
- const pixels = columnPixels(layout, ctx.style.settings.width);
1107
+ const pixels = columnPixels(layout, Math.max(0, innerWidth), columnWidths);
1065
1108
  const children = Array.from({ length: slots }, () => []);
1066
1109
  const background = readMjmlBackgroundImage((name) => attr(node, name), "Section", ctx.style.settings.width);
1067
1110
  const notes = [...exact ? [] : [`Column widths ${rawWidths.map((w) => w ?? "auto").join(", ")} have no exact Templatical layout; resolved to "${layout}".${columns.length > 4 ? " Templatical supports up to four columns." : ""}`], ...background?.notes ?? []];
@@ -1083,9 +1126,10 @@ function buildSection(node, ctx, entries) {
1083
1126
  const fullWidth = attr(node, "full-width") === "full-width" && Boolean(backgroundColor || background);
1084
1127
  return [createSectionBlock({
1085
1128
  columns: layout,
1129
+ ...columnWidths ? { columnWidths } : {},
1086
1130
  children,
1087
1131
  styles: {
1088
- padding: parsePadding(node),
1132
+ padding,
1089
1133
  ...!fullWidth && backgroundColor ? { backgroundColor } : {}
1090
1134
  },
1091
1135
  ...!fullWidth && background ? { backgroundImage: background.image } : {},
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/localization.ts","../src/attribute-parser.ts","../src/content-inference.ts","../src/global-style.ts","../src/block-mapper.ts","../src/social-mapper.ts","../src/section-builder.ts","../src/converter.ts"],"sourcesContent":["import { isLocaleTag, sourceHash } from \"@templatical/types\";\nimport type {\n Block,\n BlockLocaleLayer,\n TemplateContent,\n} from \"@templatical/types\";\n\ntype Target = { l10n?: Record<string, BlockLocaleLayer> };\n\n// Callers also push to `warnings` directly, so each set catches up on the\n// entries appended since the last call instead of being the only record.\nconst seenWarnings = new WeakMap<\n string[],\n { set: Set<string>; size: number }\n>();\n\nexport function warn(warnings: string[], message: string): void {\n let seen = seenWarnings.get(warnings);\n if (!seen || seen.size > warnings.length) {\n seen = { set: new Set(), size: 0 };\n seenWarnings.set(warnings, seen);\n }\n for (; seen.size < warnings.length; seen.size++) {\n seen.set.add(warnings[seen.size]);\n }\n if (seen.set.has(message)) return;\n warnings.push(message);\n seen.set.add(message);\n seen.size++;\n}\n\nexport function localeTag(value: string, warnings: string[]): string | null {\n const locale = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(locale)) return locale;\n warn(warnings, `Dropped language \"${value}\": unsupported language tag.`);\n return null;\n}\n\n/** The `defaultLocale` option as a tag; `null`, with a warning, when it isn't one. */\nexport function defaultLocaleOption(\n value: string | undefined,\n warnings: string[],\n): string | null {\n if (!value) return null;\n const locale = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(locale)) return locale;\n warn(\n warnings,\n `Ignored defaultLocale \"${value}\": unsupported language tag. Used \"en\".`,\n );\n return null;\n}\n\nexport function text(\n target: Target,\n locale: string,\n path: string,\n base: string | undefined,\n value: string,\n): void {\n if (base === undefined) {\n set(target, locale, path, value);\n return;\n }\n const layer = ((target.l10n ??= {})[locale] ??= {});\n (layer.text ??= {})[path] = { value, sourceHash: sourceHash(base) };\n}\n\nexport function set(\n target: Target,\n locale: string,\n path: string,\n value: unknown,\n): void {\n const layer = ((target.l10n ??= {})[locale] ??= {});\n (layer.set ??= {})[path] = value;\n}\n\n/** Register only non-default versions, leaving single-language imports unchanged. */\nexport function registerLocales(content: TemplateContent): void {\n const locales = new Set<string>();\n const visit = (target: Target) => {\n if (!target.l10n) return;\n delete target.l10n[content.settings.locale];\n for (const locale of Object.keys(target.l10n)) locales.add(locale);\n if (Object.keys(target.l10n).length === 0) delete target.l10n;\n };\n visit(content.settings);\n const walk = (blocks: Block[]) => {\n for (const block of blocks) {\n visit(block);\n if (block.type === \"section\") block.children.forEach(walk);\n }\n };\n walk(content.blocks);\n if (locales.size) content.settings.locales = [...locales];\n}\n","import type {\n BackgroundImage,\n BackgroundPositionX,\n BackgroundPositionY,\n BackgroundSize,\n SpacingValue,\n} from \"@templatical/types\";\nimport type { TopolNode } from \"./types\";\n\n/**\n * Read one attribute as a string, treating Topol's explicit `null` — and an\n * empty string — as absent.\n *\n * Topol writes literal `null` for an unset attribute rather than omitting the\n * key, so a `!== undefined` check would report it as present and write a null\n * into the block. Every optional-field read goes through here.\n */\nexport function attr(node: TopolNode, key: string): string | undefined {\n const raw = node.attributes?.[key];\n if (raw === null || raw === undefined) return undefined;\n if (typeof raw === \"object\") return undefined;\n const value = String(raw);\n return value === \"\" ? undefined : value;\n}\n\n/** Read one attribute as a number, or `undefined` when unset or non-numeric. */\nexport function numAttr(node: TopolNode, key: string): number | undefined {\n const value = attr(node, key);\n if (value === undefined) return undefined;\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\n/**\n * Parse a px-like value into a rounded integer. Returns 0 for a missing value\n * and for units the block model cannot express (em, rem, %).\n *\n * Trims first, then matches with no `\\s*` on either side of the optional\n * `px` unit. A trailing run of spaces can otherwise be claimed by either the\n * surrounding `\\s*` or by backtracking out of the digit/unit match, and a\n * *failing* match (no `px`, no digits — anything not shaped like a length)\n * retries every such split before giving up: `\"0\" + \" \".repeat(n) + \"x\"` is\n * polynomial in `n` against that pattern. Trimming first removes the only\n * whitespace the pattern needs to tolerate, so the match itself has nothing\n * ambiguous left to backtrack over.\n */\nexport function parsePxValue(value: string | number | undefined): number {\n if (value === undefined || value === null || value === \"\") return 0;\n if (typeof value === \"number\") return Math.round(value);\n const trimmed = value.trim();\n const match = /^(-?\\d+(?:\\.\\d+)?)(?:px)?$/.exec(trimmed);\n return match ? Math.round(parseFloat(match[1])) : 0;\n}\n\nconst NAMED_COLORS: Record<string, string> = {\n black: \"#000000\",\n white: \"#ffffff\",\n red: \"#ff0000\",\n green: \"#008000\",\n blue: \"#0000ff\",\n yellow: \"#ffff00\",\n cyan: \"#00ffff\",\n magenta: \"#ff00ff\",\n gray: \"#808080\",\n grey: \"#808080\",\n silver: \"#c0c0c0\",\n maroon: \"#800000\",\n olive: \"#808000\",\n lime: \"#00ff00\",\n aqua: \"#00ffff\",\n teal: \"#008080\",\n navy: \"#000080\",\n fuchsia: \"#ff00ff\",\n purple: \"#800080\",\n orange: \"#ffa500\",\n pink: \"#ffc0cb\",\n};\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const clamp = (n: number) => Math.max(0, Math.min(255, Math.round(n)));\n const hex = (n: number) => clamp(n).toString(16).padStart(2, \"0\");\n return `#${hex(r)}${hex(g)}${hex(b)}`;\n}\n\n/**\n * Normalize a colour to 6-digit lowercase hex.\n *\n * Returns `\"\"` for transparent/inherit/none and for anything unrecognised —\n * the empty string is the block model's \"unset\", which the colour pickers\n * clear to, so it is meaningfully different from returning a default.\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 if (/^#[0-9a-f]{6}$/.test(trimmed)) return trimmed;\n if (/^#[0-9a-f]{3}$/.test(trimmed)) {\n const [, r, g, b] = trimmed;\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n const rgb = trimmed.match(\n /^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*[\\d.]+\\s*)?\\)$/,\n );\n if (rgb) return rgbToHex(+rgb[1], +rgb[2], +rgb[3]);\n return NAMED_COLORS[trimmed] ?? \"\";\n}\n\nfunction expandShorthand(value: string | undefined): SpacingValue {\n if (!value) return { top: 0, right: 0, bottom: 0, left: 0 };\n const v = value\n .trim()\n .split(/\\s+/)\n .map((p) => parsePxValue(p));\n switch (v.length) {\n case 1:\n return { top: v[0], right: v[0], bottom: v[0], left: v[0] };\n case 2:\n return { top: v[0], right: v[1], bottom: v[0], left: v[1] };\n case 3:\n return { top: v[0], right: v[1], bottom: v[2], left: v[1] };\n default:\n return { top: v[0], right: v[1], bottom: v[2], left: v[3] };\n }\n}\n\n/**\n * Read a node's padding, handling both forms Topol emits: a shorthand string\n * (`\"9px 9px 9px 9px\"`, used by most leaves) and four separate bare-number\n * keys (`padding-top: 24`, used by `mj-divider`). A separate key wins over the\n * shorthand for its own side.\n */\nexport function parsePadding(node: TopolNode): SpacingValue {\n const base = expandShorthand(attr(node, \"padding\"));\n const side = (key: string, fallback: number) => {\n const value = attr(node, key);\n return value === undefined ? fallback : parsePxValue(value);\n };\n return {\n top: side(\"padding-top\", base.top),\n right: side(\"padding-right\", base.right),\n bottom: side(\"padding-bottom\", base.bottom),\n left: side(\"padding-left\", base.left),\n };\n}\n\n/**\n * Read a percentage. Returns `null` when the value is not a percentage, so a\n * caller can tell \"no width given\" from \"0%\" — column matching depends on that\n * distinction.\n */\nexport function parsePercent(\n value: string | number | undefined,\n): number | null {\n if (value === undefined || value === null || value === \"\") return null;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n const match = value.trim().match(/^(\\d+(?:\\.\\d+)?)\\s*%$/);\n return match ? parseFloat(match[1]) : null;\n}\n\n/** Narrow an alignment to the three the block model accepts. */\nexport function parseAlignment(\n value: string | undefined,\n fallback: \"left\" | \"center\" | \"right\" = \"left\",\n): \"left\" | \"center\" | \"right\" {\n const v = (value ?? \"\").trim().toLowerCase();\n return v === \"left\" || v === \"center\" || v === \"right\" ? v : fallback;\n}\n\n/** Narrow a border style to the three `DividerBlock.lineStyle` accepts. */\nexport function parseBorderStyle(\n value: string | undefined,\n): \"solid\" | \"dashed\" | \"dotted\" {\n const v = (value ?? \"\").trim().toLowerCase();\n return v === \"dashed\" || v === \"dotted\" ? v : \"solid\";\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/** What MJML paints for a `background-*` attribute an `mj-section` / `mj-wrapper` leaves out. */\nconst MJML_BACKGROUND_DEFAULTS = {\n size: \"auto\",\n x: \"center\",\n y: \"top\",\n repeat: true,\n} as const;\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/**\n * An `mj-section` / `mj-wrapper` background image, `null` when\n * `background-url` is absent or blank. `read` returns an attribute's\n * resolved value. Unset attributes take MJML's own defaults, so the import\n * paints what MJML painted; a value with no exact keyword takes the nearest\n * one and adds a note naming it. `label` names the element in each note, and\n * a px `background-size` is measured against `boxWidth`.\n */\nexport function readMjmlBackgroundImage(\n read: (name: string) => string | undefined,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const url = (read(\"background-url\") ?? \"\").trim();\n if (!url) 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 = MJML_BACKGROUND_DEFAULTS.size;\n const rawSize = read(\"background-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 = MJML_BACKGROUND_DEFAULTS.x;\n let y: BackgroundPositionY = MJML_BACKGROUND_DEFAULTS.y;\n let lossyX = false;\n let lossyY = false;\n const rawPosition = read(\"background-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 = read(\"background-position-x\")?.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 = read(\"background-position-y\")?.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 = MJML_BACKGROUND_DEFAULTS.repeat;\n const rawRepeat = read(\"background-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 { image: { url, size, position: { x, y }, repeat }, notes };\n}\n","import { findOpenTagEnd } from \"@templatical/types\";\nimport type { HeadingLevel } from \"@templatical/types\";\n\nexport type InferredText =\n | { kind: \"title\"; level: HeadingLevel; inner: string; clampedFrom?: number }\n | { kind: \"paragraph\"; html: string };\n\n/**\n * A single heading element wrapping the whole content, captured with its level\n * and inner markup. Anchored at both ends so a heading with a sibling does not\n * match — that case is a paragraph.\n */\nconst SOLE_HEADING = /^<h([1-6])(?:\\s[^>]*)?>([\\s\\S]*)<\\/h\\1>$/i;\n\nconst BLOCK_ROOT = /^<(p|h[1-6]|ul|ol|blockquote|div|table)\\b/i;\n\n/**\n * Resolve a Topol `content` string to a Title or a Paragraph.\n *\n * Topol has no menu or table construct, so this is a two-way choice — the MJML\n * importer needs four arms because `mj-text` is the output of four different\n * block renderers there. Paragraph is the terminal arm and always reachable,\n * so this function is total.\n */\nexport function inferTextBlock(content: string | undefined): InferredText {\n const trimmed = (content ?? \"\").trim();\n if (trimmed === \"\") return { kind: \"paragraph\", html: \"<p></p>\" };\n\n const heading = trimmed.match(SOLE_HEADING);\n if (heading) {\n const source = Number(heading[1]);\n const level = Math.min(source, 4) as HeadingLevel;\n return {\n kind: \"title\",\n level,\n inner: heading[2].trim(),\n ...(source > 4 ? { clampedFrom: source } : {}),\n };\n }\n\n return {\n kind: \"paragraph\",\n html: BLOCK_ROOT.test(trimmed) ? trimmed : `<p>${trimmed}</p>`,\n };\n}\n\nconst ENTITIES: Record<string, string> = {\n \"&amp;\": \"&\",\n \"&lt;\": \"<\",\n \"&gt;\": \">\",\n \"&quot;\": '\"',\n \"&#39;\": \"'\",\n \"&apos;\": \"'\",\n \"&nbsp;\": \" \",\n};\n\n/**\n * Remove every `<tag>` from `html`, keeping the text between them.\n *\n * A single-pass linear scan rather than `/<[^>]*>/g`: that regex is\n * polynomial over input with many `<` starts and no closing `>`, since\n * `[^>]*` backtracks at every one of them — `\"<\".repeat(n)` is quadratic in\n * `n`. `findOpenTagEnd` (from `@templatical/types`) resolves each `<` with a\n * bounded, quote-aware forward scan instead, so the walk stays O(n): every\n * character is visited at most once by `indexOf` and once by\n * `findOpenTagEnd`, because the cursor only moves forward and an\n * unterminated tag ends the walk rather than retrying from inside it. On\n * that unterminated case the remainder of the string — the dangling `<`\n * included — is emitted as-is, matching what `/<[^>]*>/g` does with\n * malformed markup: it can never complete a match without a `>`, so the\n * text is left untouched from that point on.\n */\nfunction removeTags(html: string): string {\n let out = \"\";\n let i = 0;\n while (i < html.length) {\n const open = html.indexOf(\"<\", i);\n if (open === -1) {\n out += html.substring(i);\n break;\n }\n out += html.substring(i, open);\n const tagEnd = findOpenTagEnd(html, open + 1);\n if (tagEnd === -1) {\n out += html.substring(open);\n break;\n }\n i = tagEnd + 1;\n }\n return out;\n}\n\n/**\n * The visible text of a markup fragment, for a button label — `ButtonBlock.text`\n * is a plain string, so the markup Topol stores in `content` cannot travel.\n */\nexport function stripTags(html: string | undefined): string {\n if (!html) return \"\";\n const text = removeTags(html);\n const decoded = text.replace(\n /&(?:amp|lt|gt|quot|#39|apos|nbsp);/g,\n (m) => ENTITIES[m] ?? m,\n );\n return decoded.replace(/\\s+/g, \" \").trim();\n}\n","import {\n canonicalFontStack,\n DEFAULT_TEMPLATE_DEFAULTS,\n} from \"@templatical/types\";\nimport type { TemplateContent, TemplateSettings } from \"@templatical/types\";\nimport { attr, parseColor, parsePxValue } from \"./attribute-parser\";\nimport type { TopolDesign, TopolNode } from \"./types\";\n\n/**\n * `DEFAULT_TEMPLATE_DEFAULTS` is typed `Partial<TemplateSettings>` so a\n * consumer can override any subset, but its own literal always sets the six\n * required fields. Narrowing once here is what lets each read come out as\n * `number`/`string`/`boolean` rather than `| undefined`. A plain typed\n * assignment cannot substitute: `Partial<T>` is not assignable to\n * `Required<Pick<T, …>>`, so `tsc` rejects it outright.\n */\nconst REQUIRED_DEFAULTS = DEFAULT_TEMPLATE_DEFAULTS as Required<\n Pick<\n TemplateSettings,\n | \"width\"\n | \"backgroundColor\"\n | \"textColor\"\n | \"linkUnderline\"\n | \"fontFamily\"\n | \"locale\"\n >\n>;\n\nexport interface GlobalStyle {\n settings: TemplateContent[\"settings\"];\n /** From nested objects like `\"mj-text\": { … }`. */\n tagDefaults: Record<string, Record<string, string>>;\n /** From flat `<selector>:<property>` keys; the bare selector is `\"\"`. */\n selectorDefaults: Record<string, Record<string, string>>;\n}\n\n/** A per-tag default, or undefined when the design sets none. */\nexport function tagDefault(\n style: GlobalStyle,\n tag: string,\n key: string,\n): string | undefined {\n return style.tagDefaults[tag]?.[key];\n}\n\n/** A per-selector default (`\"\"` is the document default), or undefined. */\nexport function selectorDefault(\n style: GlobalStyle,\n selector: string,\n key: string,\n): string | undefined {\n return style.selectorDefaults[selector]?.[key];\n}\n\n/**\n * Split the root's `attributes` into settings, per-tag defaults and\n * per-selector defaults.\n *\n * The root mixes two idioms: `<selector>:<property>` flat keys (`:color`,\n * `a:color`, `h1:font-family`) and `<tag>: { … }` nested objects, which are\n * the analogue of MJML's `mj-attributes`.\n */\nexport function readGlobalStyle(\n root: TopolDesign,\n container: TopolNode | undefined,\n warnings: string[],\n): GlobalStyle {\n const tagDefaults: Record<string, Record<string, string>> = Object.create(\n null,\n );\n const selectorDefaults: Record<\n string,\n Record<string, string>\n > = Object.create(null);\n\n for (const [key, value] of Object.entries(root.attributes ?? {})) {\n if (value !== null && typeof value === \"object\") {\n const bucket = (tagDefaults[key] ??= Object.create(null));\n for (const [k, v] of Object.entries(value)) {\n if (v !== null && v !== undefined) bucket[k] = String(v);\n }\n continue;\n }\n\n const colon = key.indexOf(\":\");\n // No colon means a root-level setting rather than a selector default —\n // `containerWidth` and `fonts` are the two real cases, and both are read\n // directly by name below instead of through the caches built here.\n if (colon === -1) continue;\n const selector = key.slice(0, colon);\n const property = key.slice(colon + 1);\n if (value === null || value === undefined) continue;\n const bucket = (selectorDefaults[selector] ??= Object.create(null));\n bucket[property] = String(value);\n }\n\n // containerWidth is authored only here, on the root. It is also denormalised\n // onto every leaf as the enclosing column's computed width (600/300/150 in\n // one template), so no other module may read it.\n const width =\n parsePxValue(attr(root, \"containerWidth\")) || REQUIRED_DEFAULTS.width;\n\n const backgroundColor =\n (container ? parseColor(attr(container, \"background-color\")) : \"\") ||\n REQUIRED_DEFAULTS.backgroundColor;\n\n const textColor =\n parseColor(selectorDefaults[\"\"]?.color) || REQUIRED_DEFAULTS.textColor;\n\n const fontFamily =\n canonicalFontStack(selectorDefaults[\"\"]?.[\"font-family\"]) ||\n canonicalFontStack(attr(root, \"fonts\")) ||\n REQUIRED_DEFAULTS.fontFamily;\n\n const linkColor = parseColor(selectorDefaults[\"a\"]?.color);\n\n const lineHeight = selectorDefaults[\"\"]?.[\"line-height\"];\n if (lineHeight !== undefined) {\n warnings.push(\n `Dropped the document line-height (${lineHeight}) — Templatical has no document-level line-height setting.`,\n );\n }\n\n const settings: TemplateContent[\"settings\"] = {\n width,\n backgroundColor,\n textColor,\n linkUnderline: REQUIRED_DEFAULTS.linkUnderline,\n fontFamily,\n locale: REQUIRED_DEFAULTS.locale,\n ...(linkColor ? { linkColor } : {}),\n };\n\n return { settings, tagDefaults, selectorDefaults };\n}\n","import {\n canonicalFontStack,\n createButtonBlock,\n createDividerBlock,\n createHtmlBlock,\n createImageBlock,\n createParagraphBlock,\n createSpacerBlock,\n createTitleBlock,\n} from \"@templatical/types\";\nimport type { Block, BlockStyles } from \"@templatical/types\";\nimport {\n attr,\n numAttr,\n parseAlignment,\n parseBorderStyle,\n parseColor,\n parsePadding,\n parsePxValue,\n} from \"./attribute-parser\";\nimport { inferTextBlock, stripTags } from \"./content-inference\";\nimport { selectorDefault, tagDefault, type GlobalStyle } from \"./global-style\";\nimport type { ImportReportEntry, TopolNode } from \"./types\";\n\nexport interface MapContext {\n uidMap?: Map<string, { node: TopolNode; block: Block | null }>;\n style: GlobalStyle;\n /** The rendered width of the column holding this node, for `width: \"full\"`. */\n columnWidth: number;\n}\n\nexport interface Converted {\n block: Block | null;\n entry: ImportReportEntry;\n}\n\n/**\n * Read a node's own attribute, falling back to the design's per-tag then\n * per-selector default. Returns undefined when nothing sets it, so the caller\n * can omit the field and let the block factory's default stand.\n */\nfunction resolved(\n node: TopolNode,\n key: string,\n ctx: MapContext,\n selector?: string,\n): string | undefined {\n return (\n attr(node, key) ??\n tagDefault(ctx.style, node.tagName, key) ??\n (selector === undefined\n ? undefined\n : selectorDefault(ctx.style, selector, key))\n );\n}\n\n/**\n * The `styles` every leaf block shares.\n *\n * The block background is the row behind the element, which MJML reads from\n * `container-background-color` on every leaf and which the renderer writes\n * `styles.backgroundColor` back out as. A leaf's `background-color` must not\n * feed it: on `mj-button` it is the button face (`backgroundColor`, read in\n * `convertButton`), on `mj-text` MJML never paints it, and on image, spacer,\n * divider and social it is invalid and dropped. Reading it here paints a\n * button's whole row in its fill colour. `buildSection` reads\n * `background-color` itself, since on `mj-section` it is the section's fill.\n */\nexport function baseStyles(node: TopolNode): { styles: BlockStyles } {\n const backgroundColor = parseColor(attr(node, \"container-background-color\"));\n return {\n styles: {\n padding: parsePadding(node),\n ...(backgroundColor ? { backgroundColor } : {}),\n },\n };\n}\n\nfunction convertText(node: TopolNode, ctx: MapContext): Converted {\n const inferred = inferTextBlock(node.content);\n\n if (inferred.kind === \"paragraph\") {\n return {\n block: createParagraphBlock({\n content: inferred.html,\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-text\",\n templaticalBlockType: \"paragraph\",\n status: \"converted\",\n },\n };\n }\n\n const selector = `h${inferred.level}`;\n const color = parseColor(resolved(node, \"color\", ctx, selector));\n const fontFamily = canonicalFontStack(\n resolved(node, \"font-family\", ctx, selector),\n );\n\n const block = createTitleBlock({\n content: inferred.inner,\n level: inferred.level,\n textAlign: parseAlignment(attr(node, \"align\"), \"left\"),\n ...(color ? { color } : {}),\n ...(fontFamily ? { fontFamily } : {}),\n ...baseStyles(node),\n });\n\n return {\n block,\n entry: {\n sourceTag: \"mj-text\",\n templaticalBlockType: \"title\",\n status: inferred.clampedFrom ? \"approximated\" : \"converted\",\n ...(inferred.clampedFrom\n ? {\n note: `Heading level h${inferred.clampedFrom} clamped to 4 — Templatical titles support h1-h4.`,\n }\n : {}),\n },\n };\n}\n\nfunction convertButton(node: TopolNode, ctx: MapContext): Converted | null {\n const text = stripTags(node.content);\n if (!text) return null;\n\n const backgroundColor = parseColor(\n resolved(node, \"background-color\", ctx, \"button\"),\n );\n const textColor = parseColor(resolved(node, \"color\", ctx, \"button\"));\n const fontFamily = canonicalFontStack(\n resolved(node, \"font-family\", ctx, \"button\"),\n );\n const fontSizeRaw = resolved(node, \"font-size\", ctx);\n const radiusRaw = resolved(node, \"border-radius\", ctx);\n\n return {\n block: createButtonBlock({\n text,\n url: attr(node, \"href\") ?? \"\",\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(textColor ? { textColor } : {}),\n ...(fontFamily ? { fontFamily } : {}),\n ...(fontSizeRaw === undefined\n ? {}\n : { fontSize: parsePxValue(fontSizeRaw) }),\n ...(radiusRaw === undefined\n ? {}\n : { borderRadius: parsePxValue(radiusRaw) }),\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: node.tagName,\n templaticalBlockType: \"button\",\n status: \"converted\",\n },\n };\n}\n\nfunction convertImage(\n node: TopolNode,\n ctx: MapContext,\n sourceTag: string,\n): Converted | null {\n const src = attr(node, \"src\");\n if (!src) return null;\n\n const widthPercent = numAttr(node, \"widthPercent\");\n const pxWidth = numAttr(node, \"width\");\n const href = attr(node, \"href\");\n const base = baseStyles(node);\n // MJML caps an image at its column less its own side padding, so a px width\n // that reaches that renders as \"full\" does.\n const room =\n ctx.columnWidth - base.styles.padding.left - base.styles.padding.right;\n\n const width =\n widthPercent === 100 || pxWidth === undefined || pxWidth >= room\n ? (\"full\" as const)\n : Math.round(pxWidth);\n\n const isGif = sourceTag === \"mj-gif\";\n\n return {\n block: createImageBlock({\n src,\n alt: attr(node, \"alt\") ?? \"\",\n width,\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...(href ? { linkUrl: href } : {}),\n ...base,\n }),\n entry: {\n sourceTag,\n templaticalBlockType: \"image\",\n status: isGif ? \"approximated\" : \"converted\",\n ...(isGif\n ? {\n note: \"<mj-gif> imported as an image block; Templatical has no dedicated GIF block.\",\n }\n : {}),\n },\n };\n}\n\nfunction convertSpacer(node: TopolNode): Converted {\n const height = attr(node, \"height\");\n return {\n block: createSpacerBlock({\n ...(height === undefined ? {} : { height: parsePxValue(height) }),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-spacer\",\n templaticalBlockType: \"spacer\",\n status: \"converted\",\n },\n };\n}\n\nfunction convertDivider(node: TopolNode): Converted {\n const color = parseColor(attr(node, \"border-color\"));\n const thickness = attr(node, \"border-width\");\n return {\n block: createDividerBlock({\n lineStyle: parseBorderStyle(attr(node, \"border-style\")),\n ...(color ? { color } : {}),\n ...(thickness === undefined\n ? {}\n : { thickness: parsePxValue(thickness) }),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-divider\",\n templaticalBlockType: \"divider\",\n status: \"converted\",\n },\n };\n}\n\n/**\n * Convert one leaf node to a block.\n *\n * Returns `null` for a node that produces nothing *and* warrants no report\n * entry — an image with no `src`, a button with no label. `mj-social` is not\n * handled here; the converter routes it to `convertSocial`.\n */\nexport function convertLeaf(\n node: TopolNode,\n ctx: MapContext,\n): Converted | null {\n switch (node.tagName) {\n case \"mj-text\":\n return convertText(node, ctx);\n case \"mj-button\":\n return convertButton(node, ctx);\n case \"mj-image\":\n return convertImage(node, ctx, \"mj-image\");\n case \"mj-gif\":\n return convertImage(node, ctx, \"mj-gif\");\n case \"mj-spacer\":\n return convertSpacer(node);\n case \"mj-divider\":\n return convertDivider(node);\n default:\n return {\n block: createHtmlBlock({\n content: JSON.stringify(node),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: node.tagName,\n templaticalBlockType: \"html\",\n status: \"html-fallback\",\n note: `<${node.tagName}> has no Templatical block equivalent; the original node is preserved as JSON.`,\n },\n };\n }\n}\n","import { createSocialIconsBlock, generateId } from \"@templatical/types\";\nimport type {\n SocialIcon,\n SocialIconTone,\n SocialIconSize,\n SocialIconStyle,\n SocialPlatform,\n} from \"@templatical/types\";\nimport { attr, parseAlignment, parsePxValue } from \"./attribute-parser\";\nimport { baseStyles, type Converted, type MapContext } from \"./block-mapper\";\nimport type { TopolNode } from \"./types\";\n\n/**\n * Exhaustive over `SocialPlatform` on purpose: adding a member to that union\n * without adding it here is a compile error, so this cannot silently fall back\n * to \"website\" for a platform the block model gained.\n */\nconst KNOWN_PLATFORMS: Record<SocialPlatform, true> = {\n facebook: true,\n twitter: true,\n instagram: true,\n linkedin: true,\n xing: true,\n youtube: true,\n tiktok: true,\n pinterest: true,\n email: true,\n whatsapp: true,\n telegram: true,\n discord: true,\n snapchat: true,\n reddit: true,\n github: true,\n dribbble: true,\n behance: true,\n website: true,\n};\n\nconst ALIASES: Record<string, SocialPlatform> = {\n x: \"twitter\",\n \"x-twitter\": \"twitter\",\n};\n\nconst ICON_SIZES: Array<[number, SocialIconSize]> = [\n [24, \"small\"],\n [32, \"medium\"],\n [48, \"large\"],\n];\n\nconst KNOWN_STYLES = new Set<string>([\n \"solid\",\n \"outlined\",\n \"rounded\",\n \"square\",\n \"circle\",\n]);\n\n// Topol ships icon sets whose folder name is not a Templatical style name.\n// `outlinedbw` is the outlined set in black and white, so it imports as\n// outlined in the dark tone; mapping it to the `solid` fallback would import\n// an outlined icon set as filled. Measured: both `/social-icos/outlined/` and\n// `/social-icos/outlinedbw/` appear across the reference exports.\nconst STYLE_ALIASES: Record<\n string,\n { style: SocialIconStyle; tone: SocialIconTone }\n> = {\n outlinedbw: { style: \"outlined\", tone: \"dark\" },\n};\n\nfunction normalizePlatform(raw: string): SocialPlatform | null {\n const cleaned = raw.trim().toLowerCase();\n if (!cleaned) return null;\n if (ALIASES[cleaned]) return ALIASES[cleaned];\n return cleaned in KNOWN_PLATFORMS ? (cleaned as SocialPlatform) : null;\n}\n\nfunction nearestSize(px: number): { size: SocialIconSize; exact: boolean } {\n let best = ICON_SIZES[1];\n let gap = Infinity;\n for (const candidate of ICON_SIZES) {\n const d = Math.abs(candidate[0] - px);\n if (d < gap) {\n gap = d;\n best = candidate;\n }\n }\n return { size: best[1], exact: gap === 0 };\n}\n\n/** The style (and tone) the segment of `https://…/social-icos/<style>/` names. */\nfunction styleFromBaseUrl(\n baseUrl: string | undefined,\n): { style: SocialIconStyle; tone?: SocialIconTone } | undefined {\n if (!baseUrl) return undefined;\n const segment = baseUrl.split(\"?\")[0].split(\"/\").filter(Boolean).at(-1) ?? \"\";\n if (KNOWN_STYLES.has(segment)) return { style: segment as SocialIconStyle };\n return STYLE_ALIASES[segment];\n}\n\n/**\n * Convert Topol's MJML v3 social block.\n *\n * `display` decides which icons render and in what order; a platform with\n * `*-href` set but absent from `display` was not shown in the email and is\n * not imported.\n */\nexport function convertSocial(\n node: TopolNode,\n _ctx: MapContext,\n): Converted | null {\n const display = attr(node, \"display\");\n if (!display) return null;\n\n const notes: string[] = [];\n const icons: SocialIcon[] = [];\n const seen = new Set<string>();\n const repeated = new Map<string, number>();\n\n for (const token of display.trim().split(/\\s+/)) {\n const rawName = token.split(\":\")[0];\n if (!rawName) continue;\n\n const url = attr(node, `${rawName}-href`);\n if (!url) continue;\n\n const platform = normalizePlatform(rawName);\n const key = JSON.stringify([platform ?? \"website\", url]);\n if (seen.has(key)) {\n const name = platform ?? \"website\";\n repeated.set(name, (repeated.get(name) ?? 0) + 1);\n continue;\n }\n seen.add(key);\n if (!platform) {\n notes.push(\n `Unrecognised social platform \"${rawName}\" mapped to \"website\".`,\n );\n }\n\n icons.push({ id: generateId(), platform: platform ?? \"website\", url });\n }\n for (const [platform, count] of repeated) {\n notes.push(\n `Dropped ${count} repeated \"${platform}\" ${count === 1 ? \"icon\" : \"icons\"}.`,\n );\n }\n\n if (icons.length === 0) return null;\n\n const fromBaseUrl = styleFromBaseUrl(attr(node, \"base-url\"));\n\n const declaredSize = attr(node, \"icon-size\");\n let iconSize: SocialIconSize | undefined;\n if (declaredSize !== undefined) {\n const px = parsePxValue(declaredSize);\n const resolved = nearestSize(px);\n iconSize = resolved.size;\n if (!resolved.exact) {\n notes.push(\n `Icon size ${declaredSize} is not one of 24/32/48px; resolved to \"${resolved.size}\".`,\n );\n }\n }\n\n return {\n block: createSocialIconsBlock({\n icons,\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...(iconSize ? { iconSize } : {}),\n ...(fromBaseUrl ? { iconStyle: fromBaseUrl.style } : {}),\n ...(fromBaseUrl?.tone ? { iconTone: fromBaseUrl.tone } : {}),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-social\",\n templaticalBlockType: \"social\",\n status: notes.length > 0 ? \"approximated\" : \"converted\",\n ...(notes.length > 0 ? { note: notes.join(\" \") } : {}),\n },\n };\n}\n","import { createSectionBlock } from \"@templatical/types\";\nimport type { Block, ColumnLayout } from \"@templatical/types\";\nimport {\n attr,\n parseColor,\n parsePadding,\n parsePercent,\n readMjmlBackgroundImage,\n} from \"./attribute-parser\";\nimport { convertLeaf, type MapContext } from \"./block-mapper\";\nimport { convertSocial } from \"./social-mapper\";\nimport type { ImportReportEntry, TopolNode } from \"./types\";\n\nconst LAYOUT_SHAPES: Array<{ layout: ColumnLayout; percents: number[] }> = [\n { layout: \"1\", percents: [100] },\n { layout: \"2\", percents: [50, 50] },\n { layout: \"1-2\", percents: [33.33, 66.67] },\n { layout: \"2-1\", percents: [66.67, 33.33] },\n { layout: \"1-3\", percents: [25, 75] },\n { layout: \"3-1\", percents: [75, 25] },\n { layout: \"3\", percents: [33.33, 33.33, 33.34] },\n { layout: \"1-2-1\", percents: [25, 50, 25] },\n { layout: \"4\", percents: [25, 25, 25, 25] },\n];\n\nconst WIDTH_TOLERANCE = 2;\n\nconst COLUMN_COUNT: Record<ColumnLayout, number> = {\n \"1\": 1,\n \"2\": 2,\n \"3\": 3,\n \"4\": 4,\n \"2-1\": 2,\n \"1-2\": 2,\n \"3-1\": 2,\n \"1-3\": 2,\n \"1-2-1\": 3,\n};\n\nfunction columnPixels(layout: ColumnLayout, container: number): number[] {\n switch (layout) {\n case \"2\":\n return [container / 2, container / 2];\n case \"3\":\n return [container / 3, container / 3, container / 3];\n case \"1-2\":\n return [container / 3, (container * 2) / 3];\n case \"2-1\":\n return [(container * 2) / 3, container / 3];\n case \"1-3\":\n return [container / 4, (container * 3) / 4];\n case \"3-1\":\n return [(container * 3) / 4, container / 4];\n case \"1-2-1\":\n return [container / 4, container / 2, container / 4];\n case \"4\":\n return [container / 4, container / 4, container / 4, container / 4];\n default:\n return [container];\n }\n}\n\n/**\n * Resolve column widths to one of the layouts this importer emits.\n *\n * `exact: false` means the caller reports `approximated` — Topol permits any\n * column count at any width and this importer emits nine layouts, so this is the\n * importer's main irreducible loss.\n */\nexport function matchColumnLayout(percents: Array<number | null>): {\n layout: ColumnLayout;\n exact: boolean;\n} {\n const count = percents.length;\n if (count === 0) return { layout: \"1\", exact: true };\n\n // All-unset is \"distribute equally\", which is exactly what the n-column\n // layout means — not a missing value to approximate around.\n if (percents.every((p) => p === null)) {\n if (count === 1) return { layout: \"1\", exact: true };\n if (count === 2) return { layout: \"2\", exact: true };\n if (count === 3) return { layout: \"3\", exact: true };\n if (count === 4) return { layout: \"4\", exact: true };\n return { layout: \"4\", exact: false };\n }\n\n const known = percents.filter((p): p is number => p !== null);\n const unsetCount = count - known.length;\n const remainder =\n unsetCount === 0\n ? 0\n : Math.max(0, 100 - known.reduce((a, b) => a + b, 0)) / unsetCount;\n const resolved = percents.map((p) => p ?? remainder);\n\n const sameCount = LAYOUT_SHAPES.filter((s) => s.percents.length === count);\n\n for (const shape of sameCount) {\n if (\n shape.percents.every(\n (want, i) => Math.abs(want - resolved[i]) <= WIDTH_TOLERANCE,\n )\n ) {\n return { layout: shape.layout, exact: true };\n }\n }\n\n const candidates =\n sameCount.length > 0\n ? sameCount\n : LAYOUT_SHAPES.filter((s) => s.layout === \"4\");\n\n let best = candidates[0];\n let bestError = Infinity;\n for (const shape of candidates) {\n const error = shape.percents.reduce(\n (sum, want, i) => sum + Math.abs(want - (resolved[i] ?? 0)),\n 0,\n );\n if (error < bestError) {\n bestError = error;\n best = shape;\n }\n }\n\n return { layout: best.layout, exact: false };\n}\n\nfunction convertColumnChildren(\n column: TopolNode,\n ctx: MapContext,\n entries: ImportReportEntry[],\n): Block[] {\n const blocks: Block[] = [];\n for (const child of column.children ?? []) {\n const converted =\n child.tagName === \"mj-social\"\n ? convertSocial(child, ctx)\n : convertLeaf(child, ctx);\n if (child.uid)\n ctx.uidMap?.set(child.uid, {\n node: child,\n block: converted?.block ?? null,\n });\n if (!converted) continue;\n entries.push(converted.entry);\n if (converted.block) blocks.push(converted.block);\n }\n return blocks;\n}\n\n/**\n * Build a `SectionBlock` from an `mj-section`. Returns an array so the caller\n * can treat an empty section (no columns) as producing nothing.\n *\n * Reads `attributes` only. The node's top-level camelCase keys\n * (`backgroundColor`, `paddingTop`, …) are stale editor state that disagrees\n * with `attributes` in every measured case.\n */\nexport function buildSection(\n node: TopolNode,\n ctx: MapContext,\n entries: ImportReportEntry[],\n): Block[] {\n const columns = (node.children ?? []).filter(\n (c) => c.tagName === \"mj-column\",\n );\n if (columns.length === 0) return [];\n\n const rawWidths = columns.map((c) => attr(c, \"width\"));\n const percents = rawWidths.map((w) => parsePercent(w));\n const { layout, exact } = matchColumnLayout(percents);\n\n const slots = COLUMN_COUNT[layout];\n const pixels = columnPixels(layout, ctx.style.settings.width);\n const children: Block[][] = Array.from({ length: slots }, () => []);\n\n const background = readMjmlBackgroundImage(\n (name) => attr(node, name),\n \"Section\",\n ctx.style.settings.width,\n );\n const notes = [\n ...(exact\n ? []\n : [\n `Column widths ${rawWidths.map((w) => w ?? \"auto\").join(\", \")} have no exact Templatical layout; resolved to \"${layout}\".${columns.length > 4 ? \" Templatical supports up to four columns.\" : \"\"}`,\n ]),\n ...(background?.notes ?? []),\n ];\n entries.push({\n sourceTag: \"mj-section\",\n templaticalBlockType: \"section\",\n status: notes.length > 0 ? \"approximated\" : \"converted\",\n ...(notes.length > 0 ? { note: notes.join(\" \") } : {}),\n });\n\n columns.forEach((column, index) => {\n const slot = Math.min(index, slots - 1);\n const columnCtx: MapContext = {\n ...ctx,\n columnWidth: Math.round(pixels[slot] ?? ctx.style.settings.width),\n };\n children[slot].push(...convertColumnChildren(column, columnCtx, entries));\n });\n\n const backgroundColor = parseColor(attr(node, \"background-color\"));\n // `full-width=\"full-width\"` makes this section's own background the\n // viewport band. The section stays transparent over it.\n const fullWidth =\n attr(node, \"full-width\") === \"full-width\" &&\n Boolean(backgroundColor || background);\n\n return [\n createSectionBlock({\n columns: layout,\n children,\n styles: {\n padding: parsePadding(node),\n ...(!fullWidth && backgroundColor ? { backgroundColor } : {}),\n },\n ...(!fullWidth && background\n ? { backgroundImage: background.image }\n : {}),\n ...(fullWidth\n ? {\n wrapper: {\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(background ? { backgroundImage: background.image } : {}),\n fullWidth: true,\n },\n }\n : {}),\n }),\n ];\n}\n","import {\n defaultLocaleOption,\n localeTag,\n registerLocales,\n set,\n text,\n warn,\n} from \"./localization\";\nimport { convertLeaf } from \"./block-mapper\";\nimport { createDefaultTemplateContent } from \"@templatical/types\";\nimport type { Block, TemplateContent } from \"@templatical/types\";\nimport { readGlobalStyle } from \"./global-style\";\nimport { buildSection } from \"./section-builder\";\nimport type { MapContext } from \"./block-mapper\";\nimport type {\n ImportReport,\n ImportReportEntry,\n ImportResult,\n TopolDesign,\n} from \"./types\";\n\nexport interface ConvertTopolOptions {\n /** Used when the source declares no default language. */\n defaultLocale?: string;\n}\n\nconst ROOT_TAG = \"mj-global-style\";\n// Designs saved by Topol's editor hold their sections under either tag.\nconst CONTAINER_TAGS = new Set([\"mj-container\", \"mj-body\"]);\n\nconst INVALID_DESIGN_MESSAGE =\n 'Invalid Topol template: expected the design JSON object — Topol hands you this directly from its editor\\'s onSave callback, or under \"definition\" (template API) or \"json\" (predefined-templates API) in its API response.';\n\nconst EMPTY_DESIGN_WARNING =\n \"No convertible content was found in the Topol design. Check that its mj-container (or mj-body) holds at least one mj-section.\";\n\n/**\n * Convert a Topol.io design into a Templatical template.\n *\n * The input is the design object itself — the node whose `tagName` is\n * `mj-global-style`, not a whole API response. Topol's editor hands it to\n * you directly as the first argument to `onSave`; its REST APIs wrap it\n * instead, under `definition` on the template-retrieval endpoint or `json`\n * (alongside `html`) on the predefined-templates endpoint. That is\n * documented rather than sniffed: guessing which field holds the design\n * risks importing an envelope's `html`, which belongs to a different\n * package entirely.\n *\n * @example\n * ```ts\n * const { content, report } = convertTopolTemplate(design);\n * const editor = init({ container: '#editor', content });\n * console.log(report.summary);\n * ```\n */\nexport function convertTopolTemplate(\n design: TopolDesign | string,\n options: ConvertTopolOptions = {},\n): ImportResult {\n const root: unknown = typeof design === \"string\" ? safeParse(design) : design;\n\n if (typeof root !== \"object\" || root === null || Array.isArray(root)) {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n\n const topolDesign = root as TopolDesign;\n\n if (topolDesign.tagName !== ROOT_TAG) {\n // Topol's REST APIs wrap the design rather than returning it bare: the\n // template-retrieval endpoint uses \"definition\", the predefined/premade\n // templates endpoint uses \"json\" (alongside \"html\"). A response object\n // passed here by mistake still carries one of those keys, so that\n // mistake is named directly instead of falling through to the generic\n // wrong-tagName message below.\n if (\"json\" in topolDesign || \"definition\" in topolDesign) {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n throw new Error(\n `Invalid Topol template: expected a root node with tagName \"${ROOT_TAG}\".`,\n );\n }\n\n const container = (topolDesign.children ?? []).find((child) =>\n CONTAINER_TAGS.has(child.tagName),\n );\n\n const entries: ImportReportEntry[] = [];\n const warnings: string[] = [];\n const blocks: Block[] = [];\n\n const style = readGlobalStyle(topolDesign, container, warnings);\n const languages = topolDesign.langs ?? [];\n const primary =\n languages.find((language) => language.primary) ?? languages[0];\n style.settings.locale =\n (primary ? localeTag(primary.key, warnings) : null) ??\n defaultLocaleOption(options.defaultLocale, warnings) ??\n \"en\";\n const uidMap: NonNullable<MapContext[\"uidMap\"]> = new Map();\n\n const ctx: MapContext = {\n uidMap,\n style,\n columnWidth: style.settings.width,\n };\n\n for (const child of container?.children ?? []) {\n if (child.tagName !== \"mj-section\") continue;\n blocks.push(...buildSection(child, ctx, entries));\n }\n\n if (blocks.length === 0) {\n warnings.push(EMPTY_DESIGN_WARNING);\n }\n\n const content: TemplateContent = {\n ...createDefaultTemplateContent(),\n blocks,\n settings: style.settings,\n };\n\n const preview = primary?.translations?.[\"mj-preview\"]?.content;\n if (typeof preview === \"string\") content.settings.preheaderText = preview;\n for (const language of languages) {\n const locale = localeTag(language.key, warnings);\n if (!locale) continue;\n for (const [uid, translation] of Object.entries(\n language.translations ?? {},\n )) {\n if (uid === \"mj-subject\") {\n warn(\n warnings,\n `Dropped language \"${locale}\" mj-subject: the host owns this field.`,\n );\n continue;\n }\n if (locale === content.settings.locale) continue;\n if (uid === \"mj-preview\") {\n if (typeof translation.content === \"string\")\n text(\n content.settings,\n locale,\n \"preheaderText\",\n content.settings.preheaderText,\n translation.content,\n );\n continue;\n }\n const target = uidMap.get(uid);\n const block = target?.block;\n if (!block || block.type === \"html\") {\n warn(\n warnings,\n `Dropped language \"${locale}\" translation for uid \"${uid}\": target converted to ${block ? \"HTML fallback\" : \"null\"}.`,\n );\n continue;\n }\n if (typeof translation.content === \"string\") {\n const converted = convertLeaf(\n { ...target.node, content: translation.content },\n ctx,\n )?.block;\n if (\n (block.type === \"title\" || block.type === \"paragraph\") &&\n converted &&\n (converted.type === \"title\" || converted.type === \"paragraph\")\n )\n text(block, locale, \"content\", block.content, converted.content);\n else if (block.type === \"button\" && converted?.type === \"button\")\n text(block, locale, \"text\", block.text, converted.text);\n else\n warn(\n warnings,\n `Dropped language \"${locale}\" content for uid \"${uid}\": no language mapping for this format.`,\n );\n }\n for (const [key, value] of Object.entries(translation.attributes ?? {})) {\n if (typeof value !== \"string\") continue;\n if (key === \"alt\" && block.type === \"image\")\n text(block, locale, \"alt\", block.alt, value);\n else if (key === \"href\" && block.type === \"button\")\n set(block, locale, \"url\", value);\n else if (key === \"href\" && block.type === \"image\")\n set(block, locale, \"linkUrl\", value);\n else if (key === \"src\" && block.type === \"image\")\n set(block, locale, \"src\", value);\n else\n warn(\n warnings,\n `Dropped language \"${locale}\" attribute \"${key}\" for uid \"${uid}\": no language mapping for this format.`,\n );\n }\n }\n }\n registerLocales(content);\n const versions = languages\n .map((language) => localeTag(language.key, warnings))\n .filter(\n (locale): locale is string =>\n locale !== null && locale !== content.settings.locale,\n );\n if (versions.length) content.settings.locales = [...new Set(versions)];\n\n const summary = {\n total: entries.length,\n converted: entries.filter((e) => e.status === \"converted\").length,\n approximated: entries.filter((e) => e.status === \"approximated\").length,\n htmlFallback: entries.filter((e) => e.status === \"html-fallback\").length,\n skipped: entries.filter((e) => e.status === \"skipped\").length,\n };\n\n const report: ImportReport = { entries, warnings, summary };\n\n return { content, report };\n}\n\nfunction safeParse(source: string): unknown {\n try {\n return JSON.parse(source);\n } catch {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n}\n"],"mappings":";;AAWA,MAAM,+BAAe,IAAI,QAGvB;AAEF,SAAgB,KAAK,UAAoB,SAAuB;CAC9D,IAAI,OAAO,aAAa,IAAI,QAAQ;CACpC,IAAI,CAAC,QAAQ,KAAK,OAAO,SAAS,QAAQ;EACxC,OAAO;GAAE,qBAAK,IAAI,IAAI;GAAG,MAAM;EAAE;EACjC,aAAa,IAAI,UAAU,IAAI;CACjC;CACA,OAAO,KAAK,OAAO,SAAS,QAAQ,KAAK,QACvC,KAAK,IAAI,IAAI,SAAS,KAAK,KAAK;CAElC,IAAI,KAAK,IAAI,IAAI,OAAO,GAAG;CAC3B,SAAS,KAAK,OAA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OAAO,KAAK;SAE/B,KACE,UACA,qBAAqB,OAAO,eAAe,IAAI,aAAa,IAAI,wCAClE;GACJ;EACF;CACF;CACA,gBAAgB,OAAO;CACvB,MAAM,WAAW,UACd,KAAK,aAAa,UAAU,SAAS,KAAK,QAAQ,CAAC,CAAC,CACpD,QACE,WACC,WAAW,QAAQ,WAAW,QAAQ,SAAS,MACnD;CACF,IAAI,SAAS,QAAQ,QAAQ,SAAS,UAAU,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC;CAYrE,OAAO;EAAE;EAAS,QAAA;GAFa;GAAS;GAAU,SAAA;IAPhD,OAAO,QAAQ;IACf,WAAW,QAAQ,QAAQ,MAAM,EAAE,WAAW,WAAW,CAAC,CAAC;IAC3D,cAAc,QAAQ,QAAQ,MAAM,EAAE,WAAW,cAAc,CAAC,CAAC;IACjE,cAAc,QAAQ,QAAQ,MAAM,EAAE,WAAW,eAAe,CAAC,CAAC;IAClE,SAAS,QAAQ,QAAQ,MAAM,EAAE,WAAW,SAAS,CAAC,CAAC;GAGD;EAEjC;CAAE;AAC3B;AAEA,SAAS,UAAU,QAAyB;CAC1C,IAAI;EACF,OAAO,KAAK,MAAM,MAAM;CAC1B,QAAQ;EACN,MAAM,IAAI,MAAM,sBAAsB;CACxC;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/localization.ts","../src/attribute-parser.ts","../src/content-inference.ts","../src/global-style.ts","../src/block-mapper.ts","../src/social-mapper.ts","../src/section-builder.ts","../src/converter.ts"],"sourcesContent":["import { isLocaleTag, sourceHash } from \"@templatical/types\";\nimport type {\n Block,\n BlockLocaleLayer,\n TemplateContent,\n} from \"@templatical/types\";\n\ntype Target = { l10n?: Record<string, BlockLocaleLayer> };\n\n// Callers also push to `warnings` directly, so each set catches up on the\n// entries appended since the last call instead of being the only record.\nconst seenWarnings = new WeakMap<\n string[],\n { set: Set<string>; size: number }\n>();\n\nexport function warn(warnings: string[], message: string): void {\n let seen = seenWarnings.get(warnings);\n if (!seen || seen.size > warnings.length) {\n seen = { set: new Set(), size: 0 };\n seenWarnings.set(warnings, seen);\n }\n for (; seen.size < warnings.length; seen.size++) {\n seen.set.add(warnings[seen.size]);\n }\n if (seen.set.has(message)) return;\n warnings.push(message);\n seen.set.add(message);\n seen.size++;\n}\n\nexport function localeTag(value: string, warnings: string[]): string | null {\n const locale = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(locale)) return locale;\n warn(warnings, `Dropped language \"${value}\": unsupported language tag.`);\n return null;\n}\n\n/** The `defaultLocale` option as a tag; `null`, with a warning, when it isn't one. */\nexport function defaultLocaleOption(\n value: string | undefined,\n warnings: string[],\n): string | null {\n if (!value) return null;\n const locale = value.replaceAll(\"_\", \"-\");\n if (isLocaleTag(locale)) return locale;\n warn(\n warnings,\n `Ignored defaultLocale \"${value}\": unsupported language tag. Used \"en\".`,\n );\n return null;\n}\n\nexport function text(\n target: Target,\n locale: string,\n path: string,\n base: string | undefined,\n value: string,\n): void {\n if (base === undefined) {\n set(target, locale, path, value);\n return;\n }\n const layer = ((target.l10n ??= {})[locale] ??= {});\n (layer.text ??= {})[path] = { value, sourceHash: sourceHash(base) };\n}\n\nexport function set(\n target: Target,\n locale: string,\n path: string,\n value: unknown,\n): void {\n const layer = ((target.l10n ??= {})[locale] ??= {});\n (layer.set ??= {})[path] = value;\n}\n\n/** Register only non-default versions, leaving single-language imports unchanged. */\nexport function registerLocales(content: TemplateContent): void {\n const locales = new Set<string>();\n const visit = (target: Target) => {\n if (!target.l10n) return;\n delete target.l10n[content.settings.locale];\n for (const locale of Object.keys(target.l10n)) locales.add(locale);\n if (Object.keys(target.l10n).length === 0) delete target.l10n;\n };\n visit(content.settings);\n const walk = (blocks: Block[]) => {\n for (const block of blocks) {\n visit(block);\n if (block.type === \"section\") block.children.forEach(walk);\n }\n };\n walk(content.blocks);\n if (locales.size) content.settings.locales = [...locales];\n}\n","import type {\n BackgroundImage,\n BackgroundPositionX,\n BackgroundPositionY,\n BackgroundSize,\n SpacingValue,\n} from \"@templatical/types\";\nimport type { TopolNode } from \"./types\";\n\n/**\n * Read one attribute as a string, treating Topol's explicit `null` — and an\n * empty string — as absent.\n *\n * Topol writes literal `null` for an unset attribute rather than omitting the\n * key, so a `!== undefined` check would report it as present and write a null\n * into the block. Every optional-field read goes through here.\n */\nexport function attr(node: TopolNode, key: string): string | undefined {\n const raw = node.attributes?.[key];\n if (raw === null || raw === undefined) return undefined;\n if (typeof raw === \"object\") return undefined;\n const value = String(raw);\n return value === \"\" ? undefined : value;\n}\n\n/** Read one attribute as a number, or `undefined` when unset or non-numeric. */\nexport function numAttr(node: TopolNode, key: string): number | undefined {\n const value = attr(node, key);\n if (value === undefined) return undefined;\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\n/**\n * Parse a px-like value into a rounded integer. Returns 0 for a missing value\n * and for units the block model cannot express (em, rem, %).\n *\n * Trims first, then matches with no `\\s*` on either side of the optional\n * `px` unit. A trailing run of spaces can otherwise be claimed by either the\n * surrounding `\\s*` or by backtracking out of the digit/unit match, and a\n * *failing* match (no `px`, no digits — anything not shaped like a length)\n * retries every such split before giving up: `\"0\" + \" \".repeat(n) + \"x\"` is\n * polynomial in `n` against that pattern. Trimming first removes the only\n * whitespace the pattern needs to tolerate, so the match itself has nothing\n * ambiguous left to backtrack over.\n */\nexport function parsePxValue(value: string | number | undefined): number {\n if (value === undefined || value === null || value === \"\") return 0;\n if (typeof value === \"number\") return Math.round(value);\n const trimmed = value.trim();\n const match = /^(-?\\d+(?:\\.\\d+)?)(?:px)?$/.exec(trimmed);\n return match ? Math.round(parseFloat(match[1])) : 0;\n}\n\nconst NAMED_COLORS: Record<string, string> = {\n black: \"#000000\",\n white: \"#ffffff\",\n red: \"#ff0000\",\n green: \"#008000\",\n blue: \"#0000ff\",\n yellow: \"#ffff00\",\n cyan: \"#00ffff\",\n magenta: \"#ff00ff\",\n gray: \"#808080\",\n grey: \"#808080\",\n silver: \"#c0c0c0\",\n maroon: \"#800000\",\n olive: \"#808000\",\n lime: \"#00ff00\",\n aqua: \"#00ffff\",\n teal: \"#008080\",\n navy: \"#000080\",\n fuchsia: \"#ff00ff\",\n purple: \"#800080\",\n orange: \"#ffa500\",\n pink: \"#ffc0cb\",\n};\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const clamp = (n: number) => Math.max(0, Math.min(255, Math.round(n)));\n const hex = (n: number) => clamp(n).toString(16).padStart(2, \"0\");\n return `#${hex(r)}${hex(g)}${hex(b)}`;\n}\n\n/**\n * Normalize a colour to 6-digit lowercase hex.\n *\n * Returns `\"\"` for transparent/inherit/none and for anything unrecognised —\n * the empty string is the block model's \"unset\", which the colour pickers\n * clear to, so it is meaningfully different from returning a default.\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 if (/^#[0-9a-f]{6}$/.test(trimmed)) return trimmed;\n if (/^#[0-9a-f]{3}$/.test(trimmed)) {\n const [, r, g, b] = trimmed;\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n const rgb = trimmed.match(\n /^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*[\\d.]+\\s*)?\\)$/,\n );\n if (rgb) return rgbToHex(+rgb[1], +rgb[2], +rgb[3]);\n return NAMED_COLORS[trimmed] ?? \"\";\n}\n\nfunction expandShorthand(value: string | undefined): SpacingValue {\n if (!value) return { top: 0, right: 0, bottom: 0, left: 0 };\n const v = value\n .trim()\n .split(/\\s+/)\n .map((p) => parsePxValue(p));\n switch (v.length) {\n case 1:\n return { top: v[0], right: v[0], bottom: v[0], left: v[0] };\n case 2:\n return { top: v[0], right: v[1], bottom: v[0], left: v[1] };\n case 3:\n return { top: v[0], right: v[1], bottom: v[2], left: v[1] };\n default:\n return { top: v[0], right: v[1], bottom: v[2], left: v[3] };\n }\n}\n\n/**\n * Read a node's padding, handling both forms Topol emits: a shorthand string\n * (`\"9px 9px 9px 9px\"`, used by most leaves) and four separate bare-number\n * keys (`padding-top: 24`, used by `mj-divider`). A separate key wins over the\n * shorthand for its own side.\n */\nexport function parsePadding(node: TopolNode): SpacingValue {\n const base = expandShorthand(attr(node, \"padding\"));\n const side = (key: string, fallback: number) => {\n const value = attr(node, key);\n return value === undefined ? fallback : parsePxValue(value);\n };\n return {\n top: side(\"padding-top\", base.top),\n right: side(\"padding-right\", base.right),\n bottom: side(\"padding-bottom\", base.bottom),\n left: side(\"padding-left\", base.left),\n };\n}\n\n/**\n * Read a percentage. Returns `null` when the value is not a percentage, so a\n * caller can tell \"no width given\" from \"0%\" — column matching depends on that\n * distinction.\n */\nexport function parsePercent(\n value: string | number | undefined,\n): number | null {\n if (value === undefined || value === null || value === \"\") return null;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n const match = value.trim().match(/^(\\d+(?:\\.\\d+)?)\\s*%$/);\n return match ? parseFloat(match[1]) : null;\n}\n\n/** Narrow an alignment to the three the block model accepts. */\nexport function parseAlignment(\n value: string | undefined,\n fallback: \"left\" | \"center\" | \"right\" = \"left\",\n): \"left\" | \"center\" | \"right\" {\n const v = (value ?? \"\").trim().toLowerCase();\n return v === \"left\" || v === \"center\" || v === \"right\" ? v : fallback;\n}\n\n/** Narrow a border style to the three `DividerBlock.lineStyle` accepts. */\nexport function parseBorderStyle(\n value: string | undefined,\n): \"solid\" | \"dashed\" | \"dotted\" {\n const v = (value ?? \"\").trim().toLowerCase();\n return v === \"dashed\" || v === \"dotted\" ? v : \"solid\";\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/** What MJML paints for a `background-*` attribute an `mj-section` / `mj-wrapper` leaves out. */\nconst MJML_BACKGROUND_DEFAULTS = {\n size: \"auto\",\n x: \"center\",\n y: \"top\",\n repeat: true,\n} as const;\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/**\n * An `mj-section` / `mj-wrapper` background image, `null` when\n * `background-url` is absent or blank. `read` returns an attribute's\n * resolved value. Unset attributes take MJML's own defaults, so the import\n * paints what MJML painted; a value with no exact keyword takes the nearest\n * one and adds a note naming it. `label` names the element in each note, and\n * a px `background-size` is measured against `boxWidth`.\n */\nexport function readMjmlBackgroundImage(\n read: (name: string) => string | undefined,\n label: string,\n boxWidth: number | undefined,\n): ReadBackgroundImage | null {\n const url = (read(\"background-url\") ?? \"\").trim();\n if (!url) 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 = MJML_BACKGROUND_DEFAULTS.size;\n const rawSize = read(\"background-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 = MJML_BACKGROUND_DEFAULTS.x;\n let y: BackgroundPositionY = MJML_BACKGROUND_DEFAULTS.y;\n let lossyX = false;\n let lossyY = false;\n const rawPosition = read(\"background-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 = read(\"background-position-x\")?.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 = read(\"background-position-y\")?.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 = MJML_BACKGROUND_DEFAULTS.repeat;\n const rawRepeat = read(\"background-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 { image: { url, size, position: { x, y }, repeat }, notes };\n}\n","import { findOpenTagEnd } from \"@templatical/types\";\nimport type { HeadingLevel } from \"@templatical/types\";\n\nexport type InferredText =\n | { kind: \"title\"; level: HeadingLevel; inner: string; clampedFrom?: number }\n | { kind: \"paragraph\"; html: string };\n\n/**\n * A single heading element wrapping the whole content, captured with its level\n * and inner markup. Anchored at both ends so a heading with a sibling does not\n * match — that case is a paragraph.\n */\nconst SOLE_HEADING = /^<h([1-6])(?:\\s[^>]*)?>([\\s\\S]*)<\\/h\\1>$/i;\n\nconst BLOCK_ROOT = /^<(p|h[1-6]|ul|ol|blockquote|div|table)\\b/i;\n\n/**\n * Resolve a Topol `content` string to a Title or a Paragraph.\n *\n * Topol has no menu or table construct, so this is a two-way choice — the MJML\n * importer needs four arms because `mj-text` is the output of four different\n * block renderers there. Paragraph is the terminal arm and always reachable,\n * so this function is total.\n */\nexport function inferTextBlock(content: string | undefined): InferredText {\n const trimmed = (content ?? \"\").trim();\n if (trimmed === \"\") return { kind: \"paragraph\", html: \"<p></p>\" };\n\n const heading = trimmed.match(SOLE_HEADING);\n if (heading) {\n const source = Number(heading[1]);\n const level = Math.min(source, 4) as HeadingLevel;\n return {\n kind: \"title\",\n level,\n inner: heading[2].trim(),\n ...(source > 4 ? { clampedFrom: source } : {}),\n };\n }\n\n return {\n kind: \"paragraph\",\n html: BLOCK_ROOT.test(trimmed) ? trimmed : `<p>${trimmed}</p>`,\n };\n}\n\nconst ENTITIES: Record<string, string> = {\n \"&amp;\": \"&\",\n \"&lt;\": \"<\",\n \"&gt;\": \">\",\n \"&quot;\": '\"',\n \"&#39;\": \"'\",\n \"&apos;\": \"'\",\n \"&nbsp;\": \" \",\n};\n\n/**\n * Remove every `<tag>` from `html`, keeping the text between them.\n *\n * A single-pass linear scan rather than `/<[^>]*>/g`: that regex is\n * polynomial over input with many `<` starts and no closing `>`, since\n * `[^>]*` backtracks at every one of them — `\"<\".repeat(n)` is quadratic in\n * `n`. `findOpenTagEnd` (from `@templatical/types`) resolves each `<` with a\n * bounded, quote-aware forward scan instead, so the walk stays O(n): every\n * character is visited at most once by `indexOf` and once by\n * `findOpenTagEnd`, because the cursor only moves forward and an\n * unterminated tag ends the walk rather than retrying from inside it. On\n * that unterminated case the remainder of the string — the dangling `<`\n * included — is emitted as-is, matching what `/<[^>]*>/g` does with\n * malformed markup: it can never complete a match without a `>`, so the\n * text is left untouched from that point on.\n */\nfunction removeTags(html: string): string {\n let out = \"\";\n let i = 0;\n while (i < html.length) {\n const open = html.indexOf(\"<\", i);\n if (open === -1) {\n out += html.substring(i);\n break;\n }\n out += html.substring(i, open);\n const tagEnd = findOpenTagEnd(html, open + 1);\n if (tagEnd === -1) {\n out += html.substring(open);\n break;\n }\n i = tagEnd + 1;\n }\n return out;\n}\n\n/**\n * The visible text of a markup fragment, for a button label — `ButtonBlock.text`\n * is a plain string, so the markup Topol stores in `content` cannot travel.\n */\nexport function stripTags(html: string | undefined): string {\n if (!html) return \"\";\n const text = removeTags(html);\n const decoded = text.replace(\n /&(?:amp|lt|gt|quot|#39|apos|nbsp);/g,\n (m) => ENTITIES[m] ?? m,\n );\n return decoded.replace(/\\s+/g, \" \").trim();\n}\n","import {\n canonicalFontStack,\n DEFAULT_TEMPLATE_DEFAULTS,\n} from \"@templatical/types\";\nimport type { TemplateContent, TemplateSettings } from \"@templatical/types\";\nimport { attr, parseColor, parsePxValue } from \"./attribute-parser\";\nimport type { TopolDesign, TopolNode } from \"./types\";\n\n/**\n * `DEFAULT_TEMPLATE_DEFAULTS` is typed `Partial<TemplateSettings>` so a\n * consumer can override any subset, but its own literal always sets the six\n * required fields. Narrowing once here is what lets each read come out as\n * `number`/`string`/`boolean` rather than `| undefined`. A plain typed\n * assignment cannot substitute: `Partial<T>` is not assignable to\n * `Required<Pick<T, …>>`, so `tsc` rejects it outright.\n */\nconst REQUIRED_DEFAULTS = DEFAULT_TEMPLATE_DEFAULTS as Required<\n Pick<\n TemplateSettings,\n | \"width\"\n | \"backgroundColor\"\n | \"textColor\"\n | \"linkUnderline\"\n | \"fontFamily\"\n | \"locale\"\n >\n>;\n\nexport interface GlobalStyle {\n settings: TemplateContent[\"settings\"];\n /** From nested objects like `\"mj-text\": { … }`. */\n tagDefaults: Record<string, Record<string, string>>;\n /** From flat `<selector>:<property>` keys; the bare selector is `\"\"`. */\n selectorDefaults: Record<string, Record<string, string>>;\n}\n\n/** A per-tag default, or undefined when the design sets none. */\nexport function tagDefault(\n style: GlobalStyle,\n tag: string,\n key: string,\n): string | undefined {\n return style.tagDefaults[tag]?.[key];\n}\n\n/** A per-selector default (`\"\"` is the document default), or undefined. */\nexport function selectorDefault(\n style: GlobalStyle,\n selector: string,\n key: string,\n): string | undefined {\n return style.selectorDefaults[selector]?.[key];\n}\n\n/**\n * Split the root's `attributes` into settings, per-tag defaults and\n * per-selector defaults.\n *\n * The root mixes two idioms: `<selector>:<property>` flat keys (`:color`,\n * `a:color`, `h1:font-family`) and `<tag>: { … }` nested objects, which are\n * the analogue of MJML's `mj-attributes`.\n */\nexport function readGlobalStyle(\n root: TopolDesign,\n container: TopolNode | undefined,\n warnings: string[],\n): GlobalStyle {\n const tagDefaults: Record<string, Record<string, string>> = Object.create(\n null,\n );\n const selectorDefaults: Record<\n string,\n Record<string, string>\n > = Object.create(null);\n\n for (const [key, value] of Object.entries(root.attributes ?? {})) {\n if (value !== null && typeof value === \"object\") {\n const bucket = (tagDefaults[key] ??= Object.create(null));\n for (const [k, v] of Object.entries(value)) {\n if (v !== null && v !== undefined) bucket[k] = String(v);\n }\n continue;\n }\n\n const colon = key.indexOf(\":\");\n // No colon means a root-level setting rather than a selector default —\n // `containerWidth` and `fonts` are the two real cases, and both are read\n // directly by name below instead of through the caches built here.\n if (colon === -1) continue;\n const selector = key.slice(0, colon);\n const property = key.slice(colon + 1);\n if (value === null || value === undefined) continue;\n const bucket = (selectorDefaults[selector] ??= Object.create(null));\n bucket[property] = String(value);\n }\n\n // containerWidth is authored only here, on the root. It is also denormalised\n // onto every leaf as the enclosing column's computed width (600/300/150 in\n // one template), so no other module may read it.\n const width =\n parsePxValue(attr(root, \"containerWidth\")) || REQUIRED_DEFAULTS.width;\n\n const backgroundColor =\n (container ? parseColor(attr(container, \"background-color\")) : \"\") ||\n REQUIRED_DEFAULTS.backgroundColor;\n\n const textColor =\n parseColor(selectorDefaults[\"\"]?.color) || REQUIRED_DEFAULTS.textColor;\n\n const fontFamily =\n canonicalFontStack(selectorDefaults[\"\"]?.[\"font-family\"]) ||\n canonicalFontStack(attr(root, \"fonts\")) ||\n REQUIRED_DEFAULTS.fontFamily;\n\n const linkColor = parseColor(selectorDefaults[\"a\"]?.color);\n\n const lineHeight = selectorDefaults[\"\"]?.[\"line-height\"];\n if (lineHeight !== undefined) {\n warnings.push(\n `Dropped the document line-height (${lineHeight}) — Templatical has no document-level line-height setting.`,\n );\n }\n\n const settings: TemplateContent[\"settings\"] = {\n width,\n backgroundColor,\n textColor,\n linkUnderline: REQUIRED_DEFAULTS.linkUnderline,\n fontFamily,\n locale: REQUIRED_DEFAULTS.locale,\n ...(linkColor ? { linkColor } : {}),\n };\n\n return { settings, tagDefaults, selectorDefaults };\n}\n","import {\n BUTTON_BLOCK_DEFAULTS,\n BUTTON_LINE_HEIGHT,\n canonicalFontStack,\n createButtonBlock,\n createDividerBlock,\n createHtmlBlock,\n createImageBlock,\n createParagraphBlock,\n createSpacerBlock,\n createTitleBlock,\n roundHundredths,\n} from \"@templatical/types\";\nimport type { Block, BlockStyles } from \"@templatical/types\";\nimport {\n attr,\n numAttr,\n parseAlignment,\n parseBorderStyle,\n parseColor,\n parsePadding,\n parsePxValue,\n} from \"./attribute-parser\";\nimport { inferTextBlock, stripTags } from \"./content-inference\";\nimport { selectorDefault, tagDefault, type GlobalStyle } from \"./global-style\";\nimport type { ImportReportEntry, TopolNode } from \"./types\";\n\nexport interface MapContext {\n uidMap?: Map<string, { node: TopolNode; block: Block | null }>;\n style: GlobalStyle;\n /** The rendered width of the column holding this node, for `width: \"full\"`. */\n columnWidth: number;\n}\n\nexport interface Converted {\n block: Block | null;\n entry: ImportReportEntry;\n}\n\n/**\n * Read a node's own attribute, falling back to the design's per-tag then\n * per-selector default. Returns undefined when nothing sets it, so the caller\n * can omit the field and let the block factory's default stand.\n */\nfunction resolved(\n node: TopolNode,\n key: string,\n ctx: MapContext,\n selector?: string,\n): string | undefined {\n return (\n attr(node, key) ??\n tagDefault(ctx.style, node.tagName, key) ??\n (selector === undefined\n ? undefined\n : selectorDefault(ctx.style, selector, key))\n );\n}\n\n/**\n * The `styles` every leaf block shares.\n *\n * The block background is the row behind the element, which MJML reads from\n * `container-background-color` on every leaf and which the renderer writes\n * `styles.backgroundColor` back out as. A leaf's `background-color` must not\n * feed it: on `mj-button` it is the button face (`backgroundColor`, read in\n * `convertButton`), on `mj-text` MJML never paints it, and on image, spacer,\n * divider and social it is invalid and dropped. Reading it here paints a\n * button's whole row in its fill colour. `buildSection` reads\n * `background-color` itself, since on `mj-section` it is the section's fill.\n */\nexport function baseStyles(node: TopolNode): { styles: BlockStyles } {\n const backgroundColor = parseColor(attr(node, \"container-background-color\"));\n return {\n styles: {\n padding: parsePadding(node),\n ...(backgroundColor ? { backgroundColor } : {}),\n },\n };\n}\n\nfunction convertText(node: TopolNode, ctx: MapContext): Converted {\n const inferred = inferTextBlock(node.content);\n\n if (inferred.kind === \"paragraph\") {\n return {\n block: createParagraphBlock({\n content: inferred.html,\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-text\",\n templaticalBlockType: \"paragraph\",\n status: \"converted\",\n },\n };\n }\n\n const selector = `h${inferred.level}`;\n const color = parseColor(resolved(node, \"color\", ctx, selector));\n const fontFamily = canonicalFontStack(\n resolved(node, \"font-family\", ctx, selector),\n );\n\n const block = createTitleBlock({\n content: inferred.inner,\n level: inferred.level,\n textAlign: parseAlignment(attr(node, \"align\"), \"left\"),\n ...(color ? { color } : {}),\n ...(fontFamily ? { fontFamily } : {}),\n ...baseStyles(node),\n });\n\n return {\n block,\n entry: {\n sourceTag: \"mj-text\",\n templaticalBlockType: \"title\",\n status: inferred.clampedFrom ? \"approximated\" : \"converted\",\n ...(inferred.clampedFrom\n ? {\n note: `Heading level h${inferred.clampedFrom} clamped to 4 — Templatical titles support h1-h4.`,\n }\n : {}),\n },\n };\n}\n\n/**\n * A button's line height as `ButtonBlock.lineHeight`, a multiple of\n * `fontSize`. A percentage is that number over 100, a unitless number is\n * itself, a px length is that many pixels over `fontSize`, and an `em`\n * length is the number itself. A leading dot (`.5`) is read. Rounded to two\n * decimals. A missing value, `normal`, and a value that rounds to 1.2 stay\n * unset, so the label keeps `BUTTON_LINE_HEIGHT`. Any other value that\n * cannot be kept stays unset and pushes a note.\n */\nfunction readButtonLineHeight(\n value: unknown,\n fontSize: number,\n notes: string[],\n): number | undefined {\n const trimmed = String(value ?? \"\").trim();\n if (trimmed === \"\" || /^normal$/i.test(trimmed)) return undefined;\n\n const percent = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+))\\s*%$/.exec(trimmed);\n const unitless = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+))$/.exec(trimmed);\n const px = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+))\\s*px$/i.exec(trimmed);\n const em = /^((?:\\d+(?:\\.\\d+)?|\\.\\d+))\\s*em$/i.exec(trimmed);\n let ratio = Number.NaN;\n if (percent) ratio = Number(percent[1]) / 100;\n else if (unitless) ratio = Number(unitless[1]);\n else if (px) ratio = Number(px[1]) / fontSize;\n else if (em) ratio = Number(em[1]);\n\n const rounded = roundHundredths(ratio);\n if (!Number.isFinite(rounded) || !(rounded > 0)) {\n notes.push(\n `Button line-height \"${trimmed}\" could not be read; imported at 1.2.`,\n );\n return undefined;\n }\n return rounded === BUTTON_LINE_HEIGHT ? undefined : rounded;\n}\n\nfunction convertButton(node: TopolNode, ctx: MapContext): Converted | null {\n const text = stripTags(node.content);\n if (!text) return null;\n\n const backgroundColor = parseColor(\n resolved(node, \"background-color\", ctx, \"button\"),\n );\n const textColor = parseColor(resolved(node, \"color\", ctx, \"button\"));\n const fontFamily = canonicalFontStack(\n resolved(node, \"font-family\", ctx, \"button\"),\n );\n // A stated font size that is not px, not finite, or not above 0, leaves the\n // factory size with a note, and a px line height is measured against the\n // size the label renders at.\n const factorySize = Number(BUTTON_BLOCK_DEFAULTS.fontSize);\n const statedFontSize = String(resolved(node, \"font-size\", ctx) ?? \"\").trim();\n const parsedFontSize = parsePxValue(statedFontSize);\n const fontSize =\n Number.isFinite(parsedFontSize) && parsedFontSize > 0\n ? parsedFontSize\n : undefined;\n const radiusRaw = resolved(node, \"border-radius\", ctx);\n const notes: string[] = [];\n if (statedFontSize !== \"\" && fontSize === undefined) {\n notes.push(\n `Button font-size \"${statedFontSize}\" could not be read; imported at ${factorySize}px.`,\n );\n }\n const lineHeight = readButtonLineHeight(\n resolved(node, \"line-height\", ctx, \"button\"),\n fontSize ?? factorySize,\n notes,\n );\n\n return {\n block: createButtonBlock({\n text,\n url: attr(node, \"href\") ?? \"\",\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(textColor ? { textColor } : {}),\n ...(fontFamily ? { fontFamily } : {}),\n ...(fontSize !== undefined ? { fontSize } : {}),\n ...(lineHeight !== undefined ? { lineHeight } : {}),\n ...(radiusRaw === undefined\n ? {}\n : { borderRadius: parsePxValue(radiusRaw) }),\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: node.tagName,\n templaticalBlockType: \"button\",\n status: notes.length > 0 ? \"approximated\" : \"converted\",\n ...(notes.length > 0 ? { note: notes.join(\" \") } : {}),\n },\n };\n}\n\nfunction convertImage(\n node: TopolNode,\n ctx: MapContext,\n sourceTag: string,\n): Converted | null {\n const src = attr(node, \"src\");\n if (!src) return null;\n\n const widthPercent = numAttr(node, \"widthPercent\");\n const pxWidth = numAttr(node, \"width\");\n const href = attr(node, \"href\");\n const base = baseStyles(node);\n // MJML caps an image at its column less its own side padding, so a px width\n // that reaches that renders as \"full\" does.\n const room =\n ctx.columnWidth - base.styles.padding.left - base.styles.padding.right;\n\n const width =\n widthPercent === 100 || pxWidth === undefined || pxWidth >= room\n ? (\"full\" as const)\n : Math.round(pxWidth);\n\n const isGif = sourceTag === \"mj-gif\";\n\n return {\n block: createImageBlock({\n src,\n alt: attr(node, \"alt\") ?? \"\",\n width,\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...(href ? { linkUrl: href } : {}),\n ...base,\n }),\n entry: {\n sourceTag,\n templaticalBlockType: \"image\",\n status: isGif ? \"approximated\" : \"converted\",\n ...(isGif\n ? {\n note: \"<mj-gif> imported as an image block; Templatical has no dedicated GIF block.\",\n }\n : {}),\n },\n };\n}\n\nfunction convertSpacer(node: TopolNode): Converted {\n const height = attr(node, \"height\");\n return {\n block: createSpacerBlock({\n ...(height === undefined ? {} : { height: parsePxValue(height) }),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-spacer\",\n templaticalBlockType: \"spacer\",\n status: \"converted\",\n },\n };\n}\n\nfunction convertDivider(node: TopolNode): Converted {\n const color = parseColor(attr(node, \"border-color\"));\n const thickness = attr(node, \"border-width\");\n return {\n block: createDividerBlock({\n lineStyle: parseBorderStyle(attr(node, \"border-style\")),\n ...(color ? { color } : {}),\n ...(thickness === undefined\n ? {}\n : { thickness: parsePxValue(thickness) }),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-divider\",\n templaticalBlockType: \"divider\",\n status: \"converted\",\n },\n };\n}\n\n/**\n * Convert one leaf node to a block.\n *\n * Returns `null` for a node that produces nothing *and* warrants no report\n * entry — an image with no `src`, a button with no label. `mj-social` is not\n * handled here; the converter routes it to `convertSocial`.\n */\nexport function convertLeaf(\n node: TopolNode,\n ctx: MapContext,\n): Converted | null {\n switch (node.tagName) {\n case \"mj-text\":\n return convertText(node, ctx);\n case \"mj-button\":\n return convertButton(node, ctx);\n case \"mj-image\":\n return convertImage(node, ctx, \"mj-image\");\n case \"mj-gif\":\n return convertImage(node, ctx, \"mj-gif\");\n case \"mj-spacer\":\n return convertSpacer(node);\n case \"mj-divider\":\n return convertDivider(node);\n default:\n return {\n block: createHtmlBlock({\n content: JSON.stringify(node),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: node.tagName,\n templaticalBlockType: \"html\",\n status: \"html-fallback\",\n note: `<${node.tagName}> has no Templatical block equivalent; the original node is preserved as JSON.`,\n },\n };\n }\n}\n","import { createSocialIconsBlock, generateId } from \"@templatical/types\";\nimport type {\n SocialIcon,\n SocialIconTone,\n SocialIconSize,\n SocialIconStyle,\n SocialPlatform,\n} from \"@templatical/types\";\nimport { attr, parseAlignment, parsePxValue } from \"./attribute-parser\";\nimport { baseStyles, type Converted, type MapContext } from \"./block-mapper\";\nimport type { TopolNode } from \"./types\";\n\n/**\n * Exhaustive over `SocialPlatform` on purpose: adding a member to that union\n * without adding it here is a compile error, so this cannot silently fall back\n * to \"website\" for a platform the block model gained.\n */\nconst KNOWN_PLATFORMS: Record<SocialPlatform, true> = {\n facebook: true,\n twitter: true,\n instagram: true,\n linkedin: true,\n xing: true,\n youtube: true,\n tiktok: true,\n pinterest: true,\n email: true,\n whatsapp: true,\n telegram: true,\n discord: true,\n snapchat: true,\n reddit: true,\n github: true,\n dribbble: true,\n behance: true,\n website: true,\n};\n\nconst ALIASES: Record<string, SocialPlatform> = {\n x: \"twitter\",\n \"x-twitter\": \"twitter\",\n};\n\nconst ICON_SIZES: Array<[number, SocialIconSize]> = [\n [24, \"small\"],\n [32, \"medium\"],\n [48, \"large\"],\n];\n\nconst KNOWN_STYLES = new Set<string>([\n \"solid\",\n \"outlined\",\n \"rounded\",\n \"square\",\n \"circle\",\n]);\n\n// Topol ships icon sets whose folder name is not a Templatical style name.\n// `outlinedbw` is the outlined set in black and white, so it imports as\n// outlined in the dark tone; mapping it to the `solid` fallback would import\n// an outlined icon set as filled. Measured: both `/social-icos/outlined/` and\n// `/social-icos/outlinedbw/` appear across the reference exports.\nconst STYLE_ALIASES: Record<\n string,\n { style: SocialIconStyle; tone: SocialIconTone }\n> = {\n outlinedbw: { style: \"outlined\", tone: \"dark\" },\n};\n\nfunction normalizePlatform(raw: string): SocialPlatform | null {\n const cleaned = raw.trim().toLowerCase();\n if (!cleaned) return null;\n if (ALIASES[cleaned]) return ALIASES[cleaned];\n return cleaned in KNOWN_PLATFORMS ? (cleaned as SocialPlatform) : null;\n}\n\nfunction nearestSize(px: number): { size: SocialIconSize; exact: boolean } {\n let best = ICON_SIZES[1];\n let gap = Infinity;\n for (const candidate of ICON_SIZES) {\n const d = Math.abs(candidate[0] - px);\n if (d < gap) {\n gap = d;\n best = candidate;\n }\n }\n return { size: best[1], exact: gap === 0 };\n}\n\n/** The style (and tone) the segment of `https://…/social-icos/<style>/` names. */\nfunction styleFromBaseUrl(\n baseUrl: string | undefined,\n): { style: SocialIconStyle; tone?: SocialIconTone } | undefined {\n if (!baseUrl) return undefined;\n const segment = baseUrl.split(\"?\")[0].split(\"/\").filter(Boolean).at(-1) ?? \"\";\n if (KNOWN_STYLES.has(segment)) return { style: segment as SocialIconStyle };\n return STYLE_ALIASES[segment];\n}\n\n/**\n * Convert Topol's MJML v3 social block.\n *\n * `display` decides which icons render and in what order; a platform with\n * `*-href` set but absent from `display` was not shown in the email and is\n * not imported.\n */\nexport function convertSocial(\n node: TopolNode,\n _ctx: MapContext,\n): Converted | null {\n const display = attr(node, \"display\");\n if (!display) return null;\n\n const notes: string[] = [];\n const icons: SocialIcon[] = [];\n const seen = new Set<string>();\n const repeated = new Map<string, number>();\n\n for (const token of display.trim().split(/\\s+/)) {\n const rawName = token.split(\":\")[0];\n if (!rawName) continue;\n\n const url = attr(node, `${rawName}-href`);\n if (!url) continue;\n\n const platform = normalizePlatform(rawName);\n const key = JSON.stringify([platform ?? \"website\", url]);\n if (seen.has(key)) {\n const name = platform ?? \"website\";\n repeated.set(name, (repeated.get(name) ?? 0) + 1);\n continue;\n }\n seen.add(key);\n if (!platform) {\n notes.push(\n `Unrecognised social platform \"${rawName}\" mapped to \"website\".`,\n );\n }\n\n icons.push({ id: generateId(), platform: platform ?? \"website\", url });\n }\n for (const [platform, count] of repeated) {\n notes.push(\n `Dropped ${count} repeated \"${platform}\" ${count === 1 ? \"icon\" : \"icons\"}.`,\n );\n }\n\n if (icons.length === 0) return null;\n\n const fromBaseUrl = styleFromBaseUrl(attr(node, \"base-url\"));\n\n const declaredSize = attr(node, \"icon-size\");\n let iconSize: SocialIconSize | undefined;\n if (declaredSize !== undefined) {\n const px = parsePxValue(declaredSize);\n const resolved = nearestSize(px);\n iconSize = resolved.size;\n if (!resolved.exact) {\n notes.push(\n `Icon size ${declaredSize} is not one of 24/32/48px; resolved to \"${resolved.size}\".`,\n );\n }\n }\n\n return {\n block: createSocialIconsBlock({\n icons,\n align: parseAlignment(attr(node, \"align\"), \"center\"),\n ...(iconSize ? { iconSize } : {}),\n ...(fromBaseUrl ? { iconStyle: fromBaseUrl.style } : {}),\n ...(fromBaseUrl?.tone ? { iconTone: fromBaseUrl.tone } : {}),\n ...baseStyles(node),\n }),\n entry: {\n sourceTag: \"mj-social\",\n templaticalBlockType: \"social\",\n status: notes.length > 0 ? \"approximated\" : \"converted\",\n ...(notes.length > 0 ? { note: notes.join(\" \") } : {}),\n },\n };\n}\n","import {\n COLUMN_LAYOUT_PERCENTS,\n columnWidthsIssue,\n createSectionBlock,\n sectionColumnPercents,\n} from \"@templatical/types\";\nimport type { Block, ColumnLayout } from \"@templatical/types\";\nimport {\n attr,\n parseColor,\n parsePadding,\n parsePercent,\n readMjmlBackgroundImage,\n} from \"./attribute-parser\";\nimport { convertLeaf, type MapContext } from \"./block-mapper\";\nimport { convertSocial } from \"./social-mapper\";\nimport type { ImportReportEntry, TopolNode } from \"./types\";\n\n/** Preset match order. The first preset within the tolerance wins. */\nconst LAYOUT_MATCH_ORDER: readonly ColumnLayout[] = [\n \"1\",\n \"2\",\n \"1-2\",\n \"2-1\",\n \"1-3\",\n \"3-1\",\n \"3\",\n \"1-2-1\",\n \"4\",\n];\n\n/** Percentage points of drift tolerated per column before a match is inexact. */\nconst WIDTH_TOLERANCE = 2;\n\n/**\n * One hundredth, the step `sectionColumnPercents` rounds to, plus the float\n * error of subtracting two hundredths. Scaled shares this close to a preset\n * are that preset.\n */\nconst SCALED_TOLERANCE = 0.01 + 1e-9;\n\nfunction evenLayout(count: number): ColumnLayout {\n if (count === 3) return \"3\";\n if (count === 4) return \"4\";\n return \"2\";\n}\n\n/** The first preset with one share per value, each within `tolerance`. */\nfunction presetWithin(\n percents: readonly number[],\n tolerance: number,\n): ColumnLayout | undefined {\n return LAYOUT_MATCH_ORDER.find((layout) => {\n const target = COLUMN_LAYOUT_PERCENTS[layout];\n return (\n target.length === percents.length &&\n target.every(\n (share, index) => Math.abs(share - percents[index]!) <= tolerance,\n )\n );\n });\n}\n\nconst COLUMN_COUNT: Record<ColumnLayout, number> = {\n \"1\": 1,\n \"2\": 2,\n \"3\": 3,\n \"4\": 4,\n \"2-1\": 2,\n \"1-2\": 2,\n \"3-1\": 2,\n \"1-3\": 2,\n \"1-2-1\": 3,\n};\n\n/**\n * Each column's px width in `container`: the preset's shares, a third for\n * `\"3\"`, `\"1-2\"` and `\"2-1\"`, or the `columnWidths` percentages when the\n * section has them.\n */\nfunction columnPixels(\n layout: ColumnLayout,\n container: number,\n columnWidths: readonly number[] | undefined,\n): number[] {\n if (columnWidths) {\n return columnWidths.map((percent) => (container * percent) / 100);\n }\n switch (layout) {\n case \"2\":\n return [container / 2, container / 2];\n case \"3\":\n return [container / 3, container / 3, container / 3];\n case \"1-2\":\n return [container / 3, (container * 2) / 3];\n case \"2-1\":\n return [(container * 2) / 3, container / 3];\n case \"1-3\":\n return [container / 4, (container * 3) / 4];\n case \"3-1\":\n return [(container * 3) / 4, container / 4];\n case \"1-2-1\":\n return [container / 4, container / 2, container / 4];\n case \"4\":\n return [container / 4, container / 4, container / 4, container / 4];\n default:\n return [container];\n }\n}\n\n/**\n * Resolve `mj-column` widths, as percentages of the section's inner box, to\n * a layout. Topol renders through MJML, so MJML's rules apply.\n *\n * A width list within `WIDTH_TOLERANCE` of a preset keeps that preset. An\n * absent width is `mj-column`'s default, the parent width divided by the\n * column count, whatever its siblings state, so a row with no widths is\n * the even preset. One column is `\"1\"`: exact at 100%, approximated\n * otherwise. Two, three or four columns that fit no preset are scaled to\n * 100: scaled shares equal to a preset keep that preset, any others keep\n * the even preset of that count plus `columnWidths`. Either is exact when\n * the widths already total 100 within half a point; otherwise scaling\n * changed the source layout. A width that cannot be stored (not above 0)\n * keeps the even preset, approximated. Five or more columns fold onto\n * `\"4\"`, approximated.\n */\nexport function matchColumnLayout(percents: Array<number | null>): {\n layout: ColumnLayout;\n exact: boolean;\n columnWidths?: number[];\n} {\n const count = percents.length;\n if (count === 0) return { layout: \"1\", exact: true };\n if (count > 4) return { layout: \"4\", exact: false };\n\n const resolved = percents.map((percent) => percent ?? 100 / count);\n const preset = presetWithin(resolved, WIDTH_TOLERANCE);\n if (preset) return { layout: preset, exact: true };\n if (count === 1) return { layout: \"1\", exact: false };\n\n const layout = evenLayout(count);\n if (columnWidthsIssue({ columns: layout, columnWidths: resolved }) !== null) {\n return { layout, exact: false };\n }\n // Half a point treats a float sum of shares that already are 100 as exact.\n const total = resolved.reduce((sum, share) => sum + share, 0);\n const exact = Math.abs(total - 100) <= 0.5;\n const scaled = sectionColumnPercents({\n columns: layout,\n columnWidths: resolved,\n });\n const scaledPreset = presetWithin(scaled, SCALED_TOLERANCE);\n if (scaledPreset) return { layout: scaledPreset, exact };\n return { layout, exact, columnWidths: scaled };\n}\n\nconst PX_WIDTH = /^(\\d+(?:\\.\\d+)?)\\s*px$/i;\n\n/**\n * A column's `width` as a percentage of `innerWidth`, or `null` when it\n * states none. A percentage is read as written. A px width is that many\n * pixels of the inner box, the email width less the section's side\n * padding, which is the box MJML sizes columns against.\n */\nfunction columnPercent(\n value: string | undefined,\n innerWidth: number,\n): number | null {\n const percent = parsePercent(value);\n if (percent !== null) return percent;\n const px = PX_WIDTH.exec((value ?? \"\").trim());\n if (!px || innerWidth <= 0) return null;\n return (Number(px[1]) / innerWidth) * 100;\n}\n\nfunction convertColumnChildren(\n column: TopolNode,\n ctx: MapContext,\n entries: ImportReportEntry[],\n): Block[] {\n const blocks: Block[] = [];\n for (const child of column.children ?? []) {\n const converted =\n child.tagName === \"mj-social\"\n ? convertSocial(child, ctx)\n : convertLeaf(child, ctx);\n if (child.uid)\n ctx.uidMap?.set(child.uid, {\n node: child,\n block: converted?.block ?? null,\n });\n if (!converted) continue;\n entries.push(converted.entry);\n if (converted.block) blocks.push(converted.block);\n }\n return blocks;\n}\n\n/**\n * Build a `SectionBlock` from an `mj-section`. Returns an array so the caller\n * can treat an empty section (no columns) as producing nothing.\n *\n * Reads `attributes` only. The node's top-level camelCase keys\n * (`backgroundColor`, `paddingTop`, …) are stale editor state that disagrees\n * with `attributes` in every measured case.\n */\nexport function buildSection(\n node: TopolNode,\n ctx: MapContext,\n entries: ImportReportEntry[],\n): Block[] {\n const columns = (node.children ?? []).filter(\n (c) => c.tagName === \"mj-column\",\n );\n if (columns.length === 0) return [];\n\n const padding = parsePadding(node);\n const innerWidth = ctx.style.settings.width - padding.left - padding.right;\n const rawWidths = columns.map((c) => attr(c, \"width\"));\n const percents = rawWidths.map((w) => columnPercent(w, innerWidth));\n const matched = matchColumnLayout(percents);\n const { layout, columnWidths } = matched;\n // With no inner box a px width has nothing to be a share of, so it is\n // dropped and the row's ratio is lost.\n const pxDropped =\n innerWidth <= 0 &&\n rawWidths.some((w) => w !== undefined && PX_WIDTH.test(w.trim()));\n const exact = matched.exact && !pxDropped;\n\n const slots = COLUMN_COUNT[layout];\n // MJML lays the columns out in the inner box, so each column's room is\n // its share of that box, not of the email width.\n const pixels = columnPixels(layout, Math.max(0, innerWidth), columnWidths);\n const children: Block[][] = Array.from({ length: slots }, () => []);\n\n const background = readMjmlBackgroundImage(\n (name) => attr(node, name),\n \"Section\",\n ctx.style.settings.width,\n );\n const notes = [\n ...(exact\n ? []\n : [\n `Column widths ${rawWidths.map((w) => w ?? \"auto\").join(\", \")} have no exact Templatical layout; resolved to \"${layout}\".${columns.length > 4 ? \" Templatical supports up to four columns.\" : \"\"}`,\n ]),\n ...(background?.notes ?? []),\n ];\n entries.push({\n sourceTag: \"mj-section\",\n templaticalBlockType: \"section\",\n status: notes.length > 0 ? \"approximated\" : \"converted\",\n ...(notes.length > 0 ? { note: notes.join(\" \") } : {}),\n });\n\n columns.forEach((column, index) => {\n const slot = Math.min(index, slots - 1);\n const columnCtx: MapContext = {\n ...ctx,\n columnWidth: Math.round(pixels[slot] ?? ctx.style.settings.width),\n };\n children[slot].push(...convertColumnChildren(column, columnCtx, entries));\n });\n\n const backgroundColor = parseColor(attr(node, \"background-color\"));\n // `full-width=\"full-width\"` makes this section's own background the\n // viewport band. The section stays transparent over it.\n const fullWidth =\n attr(node, \"full-width\") === \"full-width\" &&\n Boolean(backgroundColor || background);\n\n return [\n createSectionBlock({\n columns: layout,\n ...(columnWidths ? { columnWidths } : {}),\n children,\n styles: {\n padding,\n ...(!fullWidth && backgroundColor ? { backgroundColor } : {}),\n },\n ...(!fullWidth && background\n ? { backgroundImage: background.image }\n : {}),\n ...(fullWidth\n ? {\n wrapper: {\n ...(backgroundColor ? { backgroundColor } : {}),\n ...(background ? { backgroundImage: background.image } : {}),\n fullWidth: true,\n },\n }\n : {}),\n }),\n ];\n}\n","import {\n defaultLocaleOption,\n localeTag,\n registerLocales,\n set,\n text,\n warn,\n} from \"./localization\";\nimport { convertLeaf } from \"./block-mapper\";\nimport { createDefaultTemplateContent } from \"@templatical/types\";\nimport type { Block, TemplateContent } from \"@templatical/types\";\nimport { readGlobalStyle } from \"./global-style\";\nimport { buildSection } from \"./section-builder\";\nimport type { MapContext } from \"./block-mapper\";\nimport type {\n ImportReport,\n ImportReportEntry,\n ImportResult,\n TopolDesign,\n} from \"./types\";\n\nexport interface ConvertTopolOptions {\n /** Used when the source declares no default language. */\n defaultLocale?: string;\n}\n\nconst ROOT_TAG = \"mj-global-style\";\n// Designs saved by Topol's editor hold their sections under either tag.\nconst CONTAINER_TAGS = new Set([\"mj-container\", \"mj-body\"]);\n\nconst INVALID_DESIGN_MESSAGE =\n 'Invalid Topol template: expected the design JSON object — Topol hands you this directly from its editor\\'s onSave callback, or under \"definition\" (template API) or \"json\" (predefined-templates API) in its API response.';\n\nconst EMPTY_DESIGN_WARNING =\n \"No convertible content was found in the Topol design. Check that its mj-container (or mj-body) holds at least one mj-section.\";\n\n/**\n * Convert a Topol.io design into a Templatical template.\n *\n * The input is the design object itself — the node whose `tagName` is\n * `mj-global-style`, not a whole API response. Topol's editor hands it to\n * you directly as the first argument to `onSave`; its REST APIs wrap it\n * instead, under `definition` on the template-retrieval endpoint or `json`\n * (alongside `html`) on the predefined-templates endpoint. That is\n * documented rather than sniffed: guessing which field holds the design\n * risks importing an envelope's `html`, which belongs to a different\n * package entirely.\n *\n * @example\n * ```ts\n * const { content, report } = convertTopolTemplate(design);\n * const editor = init({ container: '#editor', content });\n * console.log(report.summary);\n * ```\n */\nexport function convertTopolTemplate(\n design: TopolDesign | string,\n options: ConvertTopolOptions = {},\n): ImportResult {\n const root: unknown = typeof design === \"string\" ? safeParse(design) : design;\n\n if (typeof root !== \"object\" || root === null || Array.isArray(root)) {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n\n const topolDesign = root as TopolDesign;\n\n if (topolDesign.tagName !== ROOT_TAG) {\n // Topol's REST APIs wrap the design rather than returning it bare: the\n // template-retrieval endpoint uses \"definition\", the predefined/premade\n // templates endpoint uses \"json\" (alongside \"html\"). A response object\n // passed here by mistake still carries one of those keys, so that\n // mistake is named directly instead of falling through to the generic\n // wrong-tagName message below.\n if (\"json\" in topolDesign || \"definition\" in topolDesign) {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n throw new Error(\n `Invalid Topol template: expected a root node with tagName \"${ROOT_TAG}\".`,\n );\n }\n\n const container = (topolDesign.children ?? []).find((child) =>\n CONTAINER_TAGS.has(child.tagName),\n );\n\n const entries: ImportReportEntry[] = [];\n const warnings: string[] = [];\n const blocks: Block[] = [];\n\n const style = readGlobalStyle(topolDesign, container, warnings);\n const languages = topolDesign.langs ?? [];\n const primary =\n languages.find((language) => language.primary) ?? languages[0];\n style.settings.locale =\n (primary ? localeTag(primary.key, warnings) : null) ??\n defaultLocaleOption(options.defaultLocale, warnings) ??\n \"en\";\n const uidMap: NonNullable<MapContext[\"uidMap\"]> = new Map();\n\n const ctx: MapContext = {\n uidMap,\n style,\n columnWidth: style.settings.width,\n };\n\n for (const child of container?.children ?? []) {\n if (child.tagName !== \"mj-section\") continue;\n blocks.push(...buildSection(child, ctx, entries));\n }\n\n if (blocks.length === 0) {\n warnings.push(EMPTY_DESIGN_WARNING);\n }\n\n const content: TemplateContent = {\n ...createDefaultTemplateContent(),\n blocks,\n settings: style.settings,\n };\n\n const preview = primary?.translations?.[\"mj-preview\"]?.content;\n if (typeof preview === \"string\") content.settings.preheaderText = preview;\n for (const language of languages) {\n const locale = localeTag(language.key, warnings);\n if (!locale) continue;\n for (const [uid, translation] of Object.entries(\n language.translations ?? {},\n )) {\n if (uid === \"mj-subject\") {\n warn(\n warnings,\n `Dropped language \"${locale}\" mj-subject: the host owns this field.`,\n );\n continue;\n }\n if (locale === content.settings.locale) continue;\n if (uid === \"mj-preview\") {\n if (typeof translation.content === \"string\")\n text(\n content.settings,\n locale,\n \"preheaderText\",\n content.settings.preheaderText,\n translation.content,\n );\n continue;\n }\n const target = uidMap.get(uid);\n const block = target?.block;\n if (!block || block.type === \"html\") {\n warn(\n warnings,\n `Dropped language \"${locale}\" translation for uid \"${uid}\": target converted to ${block ? \"HTML fallback\" : \"null\"}.`,\n );\n continue;\n }\n if (typeof translation.content === \"string\") {\n const converted = convertLeaf(\n { ...target.node, content: translation.content },\n ctx,\n )?.block;\n if (\n (block.type === \"title\" || block.type === \"paragraph\") &&\n converted &&\n (converted.type === \"title\" || converted.type === \"paragraph\")\n )\n text(block, locale, \"content\", block.content, converted.content);\n else if (block.type === \"button\" && converted?.type === \"button\")\n text(block, locale, \"text\", block.text, converted.text);\n else\n warn(\n warnings,\n `Dropped language \"${locale}\" content for uid \"${uid}\": no language mapping for this format.`,\n );\n }\n for (const [key, value] of Object.entries(translation.attributes ?? {})) {\n if (typeof value !== \"string\") continue;\n if (key === \"alt\" && block.type === \"image\")\n text(block, locale, \"alt\", block.alt, value);\n else if (key === \"href\" && block.type === \"button\")\n set(block, locale, \"url\", value);\n else if (key === \"href\" && block.type === \"image\")\n set(block, locale, \"linkUrl\", value);\n else if (key === \"src\" && block.type === \"image\")\n set(block, locale, \"src\", value);\n else\n warn(\n warnings,\n `Dropped language \"${locale}\" attribute \"${key}\" for uid \"${uid}\": no language mapping for this format.`,\n );\n }\n }\n }\n registerLocales(content);\n const versions = languages\n .map((language) => localeTag(language.key, warnings))\n .filter(\n (locale): locale is string =>\n locale !== null && locale !== content.settings.locale,\n );\n if (versions.length) content.settings.locales = [...new Set(versions)];\n\n const summary = {\n total: entries.length,\n converted: entries.filter((e) => e.status === \"converted\").length,\n approximated: entries.filter((e) => e.status === \"approximated\").length,\n htmlFallback: entries.filter((e) => e.status === \"html-fallback\").length,\n skipped: entries.filter((e) => e.status === \"skipped\").length,\n };\n\n const report: ImportReport = { entries, warnings, summary };\n\n return { content, report };\n}\n\nfunction safeParse(source: string): unknown {\n try {\n return JSON.parse(source);\n } catch {\n throw new Error(INVALID_DESIGN_MESSAGE);\n }\n}\n"],"mappings":";;AAWA,MAAM,+BAAe,IAAI,QAGvB;AAEF,SAAgB,KAAK,UAAoB,SAAuB;CAC9D,IAAI,OAAO,aAAa,IAAI,QAAQ;CACpC,IAAI,CAAC,QAAQ,KAAK,OAAO,SAAS,QAAQ;EACxC,OAAO;GAAE,qBAAK,IAAI,IAAI;GAAG,MAAM;EAAE;EACjC,aAAa,IAAI,UAAU,IAAI;CACjC;CACA,OAAO,KAAK,OAAO,SAAS,QAAQ,KAAK,QACvC,KAAK,IAAI,IAAI,SAAS,KAAK,KAAK;CAElC,IAAI,KAAK,IAAI,IAAI,OAAO,GAAG;CAC3B,SAAS,KAAK,OAAO;CACrB,KAAK,IAAI,IAAI,OAAO;CACpB,KAAK;AACP;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KAAK;SAE/B,KACE,UACA,qBAAqB,OAAO,eAAe,IAAI,aAAa,IAAI,wCAClE;GACJ;EACF;CACF;CACA,gBAAgB,OAAO;CACvB,MAAM,WAAW,UACd,KAAK,aAAa,UAAU,SAAS,KAAK,QAAQ,CAAC,CAAC,CACpD,QACE,WACC,WAAW,QAAQ,WAAW,QAAQ,SAAS,MACnD;CACF,IAAI,SAAS,QAAQ,QAAQ,SAAS,UAAU,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC;CAYrE,OAAO;EAAE;EAAS,QAAA;GAFa;GAAS;GAAU,SAAA;IAPhD,OAAO,QAAQ;IACf,WAAW,QAAQ,QAAQ,MAAM,EAAE,WAAW,WAAW,CAAC,CAAC;IAC3D,cAAc,QAAQ,QAAQ,MAAM,EAAE,WAAW,cAAc,CAAC,CAAC;IACjE,cAAc,QAAQ,QAAQ,MAAM,EAAE,WAAW,eAAe,CAAC,CAAC;IAClE,SAAS,QAAQ,QAAQ,MAAM,EAAE,WAAW,SAAS,CAAC,CAAC;GAGD;EAEjC;CAAE;AAC3B;AAEA,SAAS,UAAU,QAAyB;CAC1C,IAAI;EACF,OAAO,KAAK,MAAM,MAAM;CAC1B,QAAQ;EACN,MAAM,IAAI,MAAM,sBAAsB;CACxC;AACF"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@templatical/import-topol",
3
3
  "description": "Convert Topol.io email templates to Templatical format",
4
- "version": "0.59.1",
4
+ "version": "0.60.0",
5
5
  "bugs": "https://github.com/templatical/sdk/issues",
6
6
  "dependencies": {
7
- "@templatical/types": "0.59.1"
7
+ "@templatical/types": "0.60.0"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@types/node": "^26.6.6",