@trafica/editor 1.0.58 → 1.0.60

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.mjs CHANGED
@@ -1722,21 +1722,34 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
1722
1722
  case "image": {
1723
1723
  const src = escapeAttr((_j = (_i = node.attrs) == null ? void 0 : _i.src) != null ? _j : "");
1724
1724
  const alt = escapeAttr((_l = (_k = node.attrs) == null ? void 0 : _k.alt) != null ? _l : "");
1725
- const width = ((_m = node.attrs) == null ? void 0 : _m.width) ? ` width="${node.attrs.width}"` : "";
1726
- const alignVal = (_n = node.attrs) == null ? void 0 : _n.align;
1727
- const alignAttr = alignVal ? ` data-align="${alignVal}"` : "";
1725
+ const widthPx = (_m = node.attrs) == null ? void 0 : _m.width;
1726
+ const widthAttr = widthPx ? ` width="${widthPx}"` : "";
1727
+ const align = (_n = node.attrs) == null ? void 0 : _n.align;
1728
1728
  const caption = ((_o = node.attrs) == null ? void 0 : _o.caption) ? escapeHTML(node.attrs.caption) : "";
1729
1729
  const x = (_p = node.attrs) == null ? void 0 : _p.x;
1730
1730
  const y = (_q = node.attrs) == null ? void 0 : _q.y;
1731
- const isDraggable = x !== void 0;
1732
- const effectiveAlign = alignVal != null ? alignVal : isDraggable ? "left" : void 0;
1733
- const alignStyle = effectiveAlign === "center" ? "display:block;margin-left:auto;margin-right:auto;text-align:center;" : effectiveAlign === "right" ? "display:block;margin-left:auto;text-align:right;" : effectiveAlign === "left" ? "display:block;margin-right:auto;text-align:left;" : "";
1734
- const posAttrs = isDraggable ? ` data-x="${Math.round(x)}" data-y="${Math.round(y != null ? y : 0)}"` : "";
1735
- const figStyle = alignStyle ? ` style="${alignStyle}"` : "";
1736
- if (caption) {
1737
- return `<figure${alignAttr}${posAttrs}${figStyle}><img src="${src}" alt="${alt}"${width} style="max-width:100%;height:auto;" /><figcaption>${caption}</figcaption></figure>`;
1731
+ const figStyles = ["display:block", "max-width:100%", "width:fit-content", "margin:1em 0"];
1732
+ const dataAttrs = [];
1733
+ if (x !== void 0) {
1734
+ const ix = Math.round(x);
1735
+ const iy = Math.round(y != null ? y : 0);
1736
+ dataAttrs.push(`data-x="${ix}"`, `data-y="${iy}"`);
1737
+ figStyles.push("position:absolute", `left:${ix}px`, `top:${iy}px`, "margin:0", "z-index:10");
1738
+ } else if (align === "center") {
1739
+ dataAttrs.push('data-align="center"');
1740
+ figStyles.push("margin-left:auto", "margin-right:auto");
1741
+ } else if (align === "right") {
1742
+ dataAttrs.push('data-align="right"');
1743
+ figStyles.push("margin-left:auto", "margin-right:0");
1744
+ } else if (align === "left") {
1745
+ dataAttrs.push('data-align="left"');
1746
+ figStyles.push("margin-left:0", "margin-right:auto");
1738
1747
  }
1739
- return `<figure${alignAttr}${posAttrs}${figStyle}><img src="${src}" alt="${alt}"${width} style="max-width:100%;height:auto;" /></figure>`;
1748
+ const figAttrStr = dataAttrs.length ? " " + dataAttrs.join(" ") : "";
1749
+ const figStyleStr = ` style="${figStyles.join(";")};"`;
1750
+ const imgStyle = ` style="display:block;max-width:100%;height:auto${widthPx ? `;width:${widthPx}px` : ""};"`;
1751
+ const captionHTML = caption ? `<figcaption style="display:block;text-align:center;font-size:0.8em;color:#6b7280;margin-top:0.4em;font-style:italic;">${caption}</figcaption>` : "";
1752
+ return `<figure${figAttrStr}${figStyleStr}><img src="${src}" alt="${alt}"${widthAttr}${imgStyle} />${captionHTML}</figure>`;
1740
1753
  }
1741
1754
  case "horizontal_rule":
1742
1755
  return "<hr />";