@scrider/formatter 1.10.10 → 1.10.11

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.cjs CHANGED
@@ -4422,6 +4422,7 @@ function htmlToDelta(html, options = {}) {
4422
4422
  if (align) {
4423
4423
  currentBlockAttributes.align = align;
4424
4424
  }
4425
+ applyBlockIndentFromMargin(element);
4425
4426
  if (format.format === "header") {
4426
4427
  const id = element.getAttribute("id");
4427
4428
  if (id) {
@@ -4840,6 +4841,7 @@ function htmlToDelta(html, options = {}) {
4840
4841
  if (align) {
4841
4842
  currentBlockAttributes.align = align;
4842
4843
  }
4844
+ applyBlockIndentFromMargin(element);
4843
4845
  const children2 = element.childNodes;
4844
4846
  const firstChild = children2[0];
4845
4847
  const isBrOnlyParagraph = children2.length === 1 && firstChild !== void 0 && isElement(firstChild) && firstChild.tagName.toLowerCase() === "br" && !firstChild.hasAttribute("data-scrider-embed");
@@ -4856,6 +4858,26 @@ function htmlToDelta(html, options = {}) {
4856
4858
  }
4857
4859
  return null;
4858
4860
  }
4861
+ function parseIndentEm(raw) {
4862
+ if (!raw) return null;
4863
+ const match = raw.trim().match(/^(-?[\d.]+)em$/i);
4864
+ if (!match) return null;
4865
+ const em = Number.parseFloat(match[1]);
4866
+ if (!Number.isFinite(em) || em <= 0) return null;
4867
+ const level = Math.round(em / 2);
4868
+ if (level < 1 || level > 8) return null;
4869
+ return level;
4870
+ }
4871
+ function getIndentFromMarginLeft(element) {
4872
+ const fromAttr = (element.getAttribute?.("style") ?? "").match(/(?:^|;)\s*margin-left:\s*([^;]+)/i)?.[1];
4873
+ const fromStyle = element.style?.getPropertyValue?.("margin-left");
4874
+ return parseIndentEm(fromAttr) ?? parseIndentEm(fromStyle);
4875
+ }
4876
+ function applyBlockIndentFromMargin(element) {
4877
+ if (currentBlockAttributes.list != null) return;
4878
+ const indent = getIndentFromMarginLeft(element);
4879
+ if (indent != null) currentBlockAttributes.indent = indent;
4880
+ }
4859
4881
  const children = fragment.childNodes;
4860
4882
  for (let i = 0; i < children.length; i++) {
4861
4883
  const child = children[i];