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