@scrider/formatter 1.4.0 → 1.4.2

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
@@ -36,13 +36,17 @@ __export(index_exports, {
36
36
  BOX_OVERFLOW_VALUES: () => BOX_OVERFLOW_VALUES,
37
37
  BlockHandlerRegistry: () => BlockHandlerRegistry,
38
38
  BrowserDOMAdapter: () => BrowserDOMAdapter,
39
+ LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
39
40
  NODE_TYPE: () => NODE_TYPE,
40
41
  NodeDOMAdapter: () => NodeDOMAdapter,
41
42
  Registry: () => Registry,
43
+ SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
42
44
  alertBlockHandler: () => alertBlockHandler,
43
45
  alignFormat: () => alignFormat,
44
46
  backgroundFormat: () => backgroundFormat,
45
47
  blockFormat: () => blockFormat,
48
+ blockLineHeightStyleParts: () => blockLineHeightStyleParts,
49
+ blockPresentationStyleParts: () => blockPresentationStyleParts,
46
50
  blockquoteFormat: () => blockquoteFormat,
47
51
  boldFormat: () => boldFormat,
48
52
  boxBlockHandler: () => boxBlockHandler,
@@ -93,6 +97,7 @@ __export(index_exports, {
93
97
  markdownToDeltaSync: () => markdownToDeltaSync,
94
98
  nodeAdapter: () => nodeAdapter,
95
99
  normalizeDelta: () => normalizeDelta,
100
+ parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
96
101
  preloadRemark: () => preloadRemark,
97
102
  resolveDocumentPresentation: () => resolveDocumentPresentation,
98
103
  resolveTablePresentation: () => resolveTablePresentation,
@@ -2603,6 +2608,38 @@ function slugifyWithDedup(text, usedSlugs) {
2603
2608
  return `${base}-${count}`;
2604
2609
  }
2605
2610
 
2611
+ // src/conversion/html/block-presentation.ts
2612
+ var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
2613
+ var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2614
+ function parseScriderLineHeightMultiplier(value) {
2615
+ const trimmed = value.trim();
2616
+ if (!trimmed) return void 0;
2617
+ if (trimmed.endsWith("%")) {
2618
+ const pct = Number.parseFloat(trimmed.slice(0, -1));
2619
+ if (Number.isFinite(pct) && pct > 0) return pct / 100;
2620
+ return void 0;
2621
+ }
2622
+ const n = Number.parseFloat(trimmed);
2623
+ if (Number.isFinite(n) && n > 0) return n;
2624
+ return void 0;
2625
+ }
2626
+ function lineHeightStyleParts(multiplier) {
2627
+ const pct = Math.round(multiplier * 100);
2628
+ return [`line-height:${multiplier}`, `mso-line-height-alt:${pct}%`];
2629
+ }
2630
+ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
2631
+ if (!LINE_HEIGHT_BLOCK_TAGS.has(tag)) return [];
2632
+ const raw = blockAttributes?.[SCRIDER_LINE_HEIGHT_KEY];
2633
+ if (typeof raw === "string") {
2634
+ const fromBlock = parseScriderLineHeightMultiplier(raw);
2635
+ if (fromBlock !== void 0) return lineHeightStyleParts(fromBlock);
2636
+ }
2637
+ if (resolved?.lineSpacing !== void 0) {
2638
+ return lineHeightStyleParts(resolved.lineSpacing);
2639
+ }
2640
+ return [];
2641
+ }
2642
+
2606
2643
  // src/conversion/html/document-presentation.ts
2607
2644
  function resolveDocumentPresentation(presentation) {
2608
2645
  if (!presentation) return void 0;
@@ -2614,25 +2651,25 @@ function resolveDocumentPresentation(presentation) {
2614
2651
  }
2615
2652
  return { lineSpacing, textIndentCm, listBlockIndentCm };
2616
2653
  }
2617
- var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2618
- var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p", "li"]);
2654
+ var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
2619
2655
  function documentPresentationListWrapperStyleParts(resolved) {
2620
2656
  if (!resolved?.listBlockIndentCm) return [];
2621
- return [`padding-left:calc(1.5em + ${resolved.listBlockIndentCm}cm)`];
2657
+ return [`padding-left:1.25em`, `margin-left:${resolved.listBlockIndentCm}cm`];
2622
2658
  }
2623
2659
  function documentPresentationStyleParts(tag, resolved) {
2624
2660
  if (!resolved) return [];
2625
2661
  const parts = [];
2626
- if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
2627
- const pct = Math.round(resolved.lineSpacing * 100);
2628
- parts.push(`line-height:${resolved.lineSpacing}`);
2629
- parts.push(`mso-line-height-alt:${pct}%`);
2630
- }
2631
2662
  if (resolved.textIndentCm !== void 0 && TEXT_INDENT_TAGS.has(tag)) {
2632
2663
  parts.push(`text-indent:${resolved.textIndentCm}cm`);
2633
2664
  }
2634
2665
  return parts;
2635
2666
  }
2667
+ function blockPresentationStyleParts(tag, blockAttributes, resolved) {
2668
+ return [
2669
+ ...blockLineHeightStyleParts(tag, blockAttributes, resolved),
2670
+ ...documentPresentationStyleParts(tag, resolved)
2671
+ ];
2672
+ }
2636
2673
  function joinStyleParts(parts) {
2637
2674
  return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
2638
2675
  }
@@ -2779,6 +2816,7 @@ function deltaToHtml(delta, options = {}) {
2779
2816
  html += renderListItem(
2780
2817
  content,
2781
2818
  listItemAttrs,
2819
+ line.attributes,
2782
2820
  pretty,
2783
2821
  indentLevel,
2784
2822
  hierarchicalNumber,
@@ -3098,17 +3136,14 @@ function getListItemAttributes(attributes) {
3098
3136
  }
3099
3137
  return "";
3100
3138
  }
3101
- function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
3139
+ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
3102
3140
  const indent = pretty ? getIndent(indentLevel) : "";
3103
3141
  const innerContent = content || "<br>";
3104
3142
  let fullAttrs = attrs;
3105
3143
  if (hierarchicalNumber) {
3106
3144
  fullAttrs += ` data-number="${hierarchicalNumber}"`;
3107
3145
  }
3108
- const styleAttr = joinStyleParts(
3109
- documentPresentationStyleParts("li", resolvedDocumentPresentation)
3110
- );
3111
- fullAttrs += styleAttr;
3146
+ fullAttrs += getBlockStyleAttribute("li", blockAttributes, resolvedDocumentPresentation);
3112
3147
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
3113
3148
  return pretty ? html + "\n" : html;
3114
3149
  }
@@ -3120,7 +3155,11 @@ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPrese
3120
3155
  return pretty ? html + "\n" : html;
3121
3156
  }
3122
3157
  function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3123
- const styles = documentPresentationStyleParts(tag, resolvedDocumentPresentation);
3158
+ const styles = blockPresentationStyleParts(
3159
+ tag,
3160
+ attributes,
3161
+ resolvedDocumentPresentation
3162
+ );
3124
3163
  if (attributes) {
3125
3164
  const alignVal = attributes.align;
3126
3165
  if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
@@ -5260,13 +5299,17 @@ function extractTableRegion(ops, hintOpIdx) {
5260
5299
  BOX_OVERFLOW_VALUES,
5261
5300
  BlockHandlerRegistry,
5262
5301
  BrowserDOMAdapter,
5302
+ LINE_HEIGHT_BLOCK_TAGS,
5263
5303
  NODE_TYPE,
5264
5304
  NodeDOMAdapter,
5265
5305
  Registry,
5306
+ SCRIDER_LINE_HEIGHT_KEY,
5266
5307
  alertBlockHandler,
5267
5308
  alignFormat,
5268
5309
  backgroundFormat,
5269
5310
  blockFormat,
5311
+ blockLineHeightStyleParts,
5312
+ blockPresentationStyleParts,
5270
5313
  blockquoteFormat,
5271
5314
  boldFormat,
5272
5315
  boxBlockHandler,
@@ -5317,6 +5360,7 @@ function extractTableRegion(ops, hintOpIdx) {
5317
5360
  markdownToDeltaSync,
5318
5361
  nodeAdapter,
5319
5362
  normalizeDelta,
5363
+ parseScriderLineHeightMultiplier,
5320
5364
  preloadRemark,
5321
5365
  resolveDocumentPresentation,
5322
5366
  resolveTablePresentation,