@scrider/formatter 1.4.3 → 1.4.4

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
@@ -43,12 +43,15 @@ __export(index_exports, {
43
43
  Registry: () => Registry,
44
44
  SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
45
45
  SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
46
+ SCRIDER_MARGIN_BEFORE_KEY: () => SCRIDER_MARGIN_BEFORE_KEY,
46
47
  alertBlockHandler: () => alertBlockHandler,
47
48
  alignFormat: () => alignFormat,
48
49
  backgroundFormat: () => backgroundFormat,
49
50
  blockFormat: () => blockFormat,
50
51
  blockLineHeightStyleParts: () => blockLineHeightStyleParts,
51
52
  blockMarginAfterStyleParts: () => blockMarginAfterStyleParts,
53
+ blockMarginBeforeStyleParts: () => blockMarginBeforeStyleParts,
54
+ blockParagraphMarginStyleParts: () => blockParagraphMarginStyleParts,
52
55
  blockPresentationStyleParts: () => blockPresentationStyleParts,
53
56
  blockquoteFormat: () => blockquoteFormat,
54
57
  boldFormat: () => boldFormat,
@@ -102,6 +105,8 @@ __export(index_exports, {
102
105
  normalizeDelta: () => normalizeDelta,
103
106
  parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
104
107
  parseScriderMarginAfterEm: () => parseScriderMarginAfterEm,
108
+ parseScriderMarginBeforeEm: () => parseScriderMarginBeforeEm,
109
+ parseScriderMarginEm: () => parseScriderMarginEm,
105
110
  preloadRemark: () => preloadRemark,
106
111
  resolveDocumentPresentation: () => resolveDocumentPresentation,
107
112
  resolveTablePresentation: () => resolveTablePresentation,
@@ -2615,6 +2620,7 @@ function slugifyWithDedup(text, usedSlugs) {
2615
2620
  // src/conversion/html/block-presentation.ts
2616
2621
  var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
2617
2622
  var SCRIDER_MARGIN_AFTER_KEY = "scrider-margin-after";
2623
+ var SCRIDER_MARGIN_BEFORE_KEY = "scrider-margin-before";
2618
2624
  var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2619
2625
  var PARAGRAPH_SPACING_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
2620
2626
  function parseScriderLineHeightMultiplier(value) {
@@ -2645,7 +2651,7 @@ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
2645
2651
  }
2646
2652
  return [];
2647
2653
  }
2648
- function parseScriderMarginAfterEm(value) {
2654
+ function parseScriderMarginEm(value) {
2649
2655
  const trimmed = value.trim();
2650
2656
  if (!trimmed) return void 0;
2651
2657
  const emMatch = trimmed.match(/^(-?\d+(?:\.\d+)?)\s*em$/i);
@@ -2658,20 +2664,59 @@ function parseScriderMarginAfterEm(value) {
2658
2664
  if (Number.isFinite(n) && n >= 0) return n;
2659
2665
  return void 0;
2660
2666
  }
2661
- function marginAfterStyleParts(em) {
2662
- return [`margin-top:0`, `margin-bottom:${em}em`];
2667
+ var parseScriderMarginAfterEm = parseScriderMarginEm;
2668
+ var parseScriderMarginBeforeEm = parseScriderMarginEm;
2669
+ function resolveParagraphMarginEm(blockAttributes, blockKey, documentEm) {
2670
+ const raw = blockAttributes?.[blockKey];
2671
+ if (typeof raw === "string") {
2672
+ const fromBlock = parseScriderMarginEm(raw);
2673
+ if (fromBlock !== void 0) return fromBlock;
2674
+ }
2675
+ return documentEm;
2663
2676
  }
2664
- function blockMarginAfterStyleParts(tag, blockAttributes, resolved) {
2677
+ function blockParagraphMarginStyleParts(tag, blockAttributes, resolved) {
2665
2678
  if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
2666
- const raw = blockAttributes?.[SCRIDER_MARGIN_AFTER_KEY];
2667
- if (typeof raw === "string") {
2668
- const fromBlock = parseScriderMarginAfterEm(raw);
2669
- if (fromBlock !== void 0) return marginAfterStyleParts(fromBlock);
2679
+ const marginTop = resolveParagraphMarginEm(
2680
+ blockAttributes,
2681
+ SCRIDER_MARGIN_BEFORE_KEY,
2682
+ resolved?.paragraphSpacingBeforeEm
2683
+ );
2684
+ const marginBottom = resolveParagraphMarginEm(
2685
+ blockAttributes,
2686
+ SCRIDER_MARGIN_AFTER_KEY,
2687
+ resolved?.paragraphSpacingAfterEm
2688
+ );
2689
+ if (marginTop === void 0 && marginBottom === void 0) return [];
2690
+ const parts = [];
2691
+ if (marginTop !== void 0) {
2692
+ parts.push(`margin-top:${marginTop}em`);
2693
+ } else if (marginBottom !== void 0) {
2694
+ parts.push("margin-top:0");
2670
2695
  }
2671
- if (resolved?.paragraphSpacingAfterEm !== void 0) {
2672
- return marginAfterStyleParts(resolved.paragraphSpacingAfterEm);
2696
+ if (marginBottom !== void 0) {
2697
+ parts.push(`margin-bottom:${marginBottom}em`);
2673
2698
  }
2674
- return [];
2699
+ return parts;
2700
+ }
2701
+ function blockMarginAfterStyleParts(tag, blockAttributes, resolved) {
2702
+ if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
2703
+ const marginBottom = resolveParagraphMarginEm(
2704
+ blockAttributes,
2705
+ SCRIDER_MARGIN_AFTER_KEY,
2706
+ resolved?.paragraphSpacingAfterEm
2707
+ );
2708
+ if (marginBottom === void 0) return [];
2709
+ return ["margin-top:0", `margin-bottom:${marginBottom}em`];
2710
+ }
2711
+ function blockMarginBeforeStyleParts(tag, blockAttributes, resolved) {
2712
+ if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
2713
+ const marginTop = resolveParagraphMarginEm(
2714
+ blockAttributes,
2715
+ SCRIDER_MARGIN_BEFORE_KEY,
2716
+ resolved?.paragraphSpacingBeforeEm
2717
+ );
2718
+ if (marginTop === void 0) return [];
2719
+ return [`margin-top:${marginTop}em`];
2675
2720
  }
2676
2721
 
2677
2722
  // src/conversion/html/document-presentation.ts
@@ -2681,10 +2726,17 @@ function resolveDocumentPresentation(presentation) {
2681
2726
  const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
2682
2727
  const listBlockIndentCm = typeof presentation.listBlockIndentCm === "number" && presentation.listBlockIndentCm > 0 ? presentation.listBlockIndentCm : void 0;
2683
2728
  const paragraphSpacingAfterEm = typeof presentation.paragraphSpacingAfterEm === "number" && Number.isFinite(presentation.paragraphSpacingAfterEm) && presentation.paragraphSpacingAfterEm >= 0 ? presentation.paragraphSpacingAfterEm : void 0;
2684
- if (lineSpacing === void 0 && paragraphSpacingAfterEm === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
2729
+ const paragraphSpacingBeforeEm = typeof presentation.paragraphSpacingBeforeEm === "number" && Number.isFinite(presentation.paragraphSpacingBeforeEm) && presentation.paragraphSpacingBeforeEm >= 0 ? presentation.paragraphSpacingBeforeEm : void 0;
2730
+ if (lineSpacing === void 0 && paragraphSpacingAfterEm === void 0 && paragraphSpacingBeforeEm === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
2685
2731
  return void 0;
2686
2732
  }
2687
- return { lineSpacing, paragraphSpacingAfterEm, textIndentCm, listBlockIndentCm };
2733
+ return {
2734
+ lineSpacing,
2735
+ paragraphSpacingAfterEm,
2736
+ paragraphSpacingBeforeEm,
2737
+ textIndentCm,
2738
+ listBlockIndentCm
2739
+ };
2688
2740
  }
2689
2741
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
2690
2742
  function documentPresentationListWrapperStyleParts(resolved) {
@@ -2702,7 +2754,7 @@ function documentPresentationStyleParts(tag, resolved) {
2702
2754
  function blockPresentationStyleParts(tag, blockAttributes, resolved) {
2703
2755
  return [
2704
2756
  ...blockLineHeightStyleParts(tag, blockAttributes, resolved),
2705
- ...blockMarginAfterStyleParts(tag, blockAttributes, resolved),
2757
+ ...blockParagraphMarginStyleParts(tag, blockAttributes, resolved),
2706
2758
  ...documentPresentationStyleParts(tag, resolved)
2707
2759
  ];
2708
2760
  }
@@ -5342,12 +5394,15 @@ function extractTableRegion(ops, hintOpIdx) {
5342
5394
  Registry,
5343
5395
  SCRIDER_LINE_HEIGHT_KEY,
5344
5396
  SCRIDER_MARGIN_AFTER_KEY,
5397
+ SCRIDER_MARGIN_BEFORE_KEY,
5345
5398
  alertBlockHandler,
5346
5399
  alignFormat,
5347
5400
  backgroundFormat,
5348
5401
  blockFormat,
5349
5402
  blockLineHeightStyleParts,
5350
5403
  blockMarginAfterStyleParts,
5404
+ blockMarginBeforeStyleParts,
5405
+ blockParagraphMarginStyleParts,
5351
5406
  blockPresentationStyleParts,
5352
5407
  blockquoteFormat,
5353
5408
  boldFormat,
@@ -5401,6 +5456,8 @@ function extractTableRegion(ops, hintOpIdx) {
5401
5456
  normalizeDelta,
5402
5457
  parseScriderLineHeightMultiplier,
5403
5458
  parseScriderMarginAfterEm,
5459
+ parseScriderMarginBeforeEm,
5460
+ parseScriderMarginEm,
5404
5461
  preloadRemark,
5405
5462
  resolveDocumentPresentation,
5406
5463
  resolveTablePresentation,