@scrider/formatter 1.3.4 → 1.3.5

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.d.cts CHANGED
@@ -1292,6 +1292,23 @@ declare function validateDelta(delta: Delta, registry: Registry): boolean;
1292
1292
  */
1293
1293
  declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
+ /**
1296
+ * Document-level HTML presentation for deltaToHtml (clipboard, export).
1297
+ * Not stored in Delta — mirrors editor Settings (line spacing, first-line indent).
1298
+ */
1299
+ interface DocumentPresentation {
1300
+ /** Line spacing multiplier, e.g. 1.5 */
1301
+ lineSpacing?: number;
1302
+ /** First-line indent in centimeters, e.g. 1.25 */
1303
+ textIndentCm?: number;
1304
+ }
1305
+ interface ResolvedDocumentPresentation {
1306
+ lineSpacing: number | undefined;
1307
+ textIndentCm: number | undefined;
1308
+ }
1309
+ declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1310
+ declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1311
+
1295
1312
  /**
1296
1313
  * Simple Table HTML presentation options for deltaToHtml (clipboard, export).
1297
1314
  * Structural data stays in Delta (table-row, table-col-align); this only affects inline styles.
@@ -1398,6 +1415,11 @@ interface DeltaToHtmlOptions {
1398
1415
  * Office/HTML export and clipboard. Does not change Delta; omitted = legacy bare `<table>`.
1399
1416
  */
1400
1417
  tablePresentation?: TablePresentation;
1418
+ /**
1419
+ * Document-level paragraph styles (line spacing, first-line indent) as inline CSS for
1420
+ * Office/HTML export and clipboard. Does not change Delta.
1421
+ */
1422
+ documentPresentation?: DocumentPresentation;
1401
1423
  }
1402
1424
  /**
1403
1425
  * Convert a Delta to an HTML string
@@ -1863,4 +1885,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
1863
1885
  */
1864
1886
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
1865
1887
 
1866
- export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedTablePresentation, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, preloadRemark, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
1888
+ export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.d.ts CHANGED
@@ -1292,6 +1292,23 @@ declare function validateDelta(delta: Delta, registry: Registry): boolean;
1292
1292
  */
1293
1293
  declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
+ /**
1296
+ * Document-level HTML presentation for deltaToHtml (clipboard, export).
1297
+ * Not stored in Delta — mirrors editor Settings (line spacing, first-line indent).
1298
+ */
1299
+ interface DocumentPresentation {
1300
+ /** Line spacing multiplier, e.g. 1.5 */
1301
+ lineSpacing?: number;
1302
+ /** First-line indent in centimeters, e.g. 1.25 */
1303
+ textIndentCm?: number;
1304
+ }
1305
+ interface ResolvedDocumentPresentation {
1306
+ lineSpacing: number | undefined;
1307
+ textIndentCm: number | undefined;
1308
+ }
1309
+ declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1310
+ declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1311
+
1295
1312
  /**
1296
1313
  * Simple Table HTML presentation options for deltaToHtml (clipboard, export).
1297
1314
  * Structural data stays in Delta (table-row, table-col-align); this only affects inline styles.
@@ -1398,6 +1415,11 @@ interface DeltaToHtmlOptions {
1398
1415
  * Office/HTML export and clipboard. Does not change Delta; omitted = legacy bare `<table>`.
1399
1416
  */
1400
1417
  tablePresentation?: TablePresentation;
1418
+ /**
1419
+ * Document-level paragraph styles (line spacing, first-line indent) as inline CSS for
1420
+ * Office/HTML export and clipboard. Does not change Delta.
1421
+ */
1422
+ documentPresentation?: DocumentPresentation;
1401
1423
  }
1402
1424
  /**
1403
1425
  * Convert a Delta to an HTML string
@@ -1863,4 +1885,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
1863
1885
  */
1864
1886
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
1865
1887
 
1866
- export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedTablePresentation, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, preloadRemark, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
1888
+ export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.js CHANGED
@@ -2493,6 +2493,32 @@ function slugifyWithDedup(text, usedSlugs) {
2493
2493
  return `${base}-${count}`;
2494
2494
  }
2495
2495
 
2496
+ // src/conversion/html/document-presentation.ts
2497
+ function resolveDocumentPresentation(presentation) {
2498
+ if (!presentation) return void 0;
2499
+ const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
2500
+ const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
2501
+ if (lineSpacing === void 0 && textIndentCm === void 0) return void 0;
2502
+ return { lineSpacing, textIndentCm };
2503
+ }
2504
+ var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2505
+ function documentPresentationStyleParts(tag, resolved) {
2506
+ if (!resolved) return [];
2507
+ const parts = [];
2508
+ if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
2509
+ const pct = Math.round(resolved.lineSpacing * 100);
2510
+ parts.push(`line-height:${resolved.lineSpacing}`);
2511
+ parts.push(`mso-line-height-alt:${pct}%`);
2512
+ }
2513
+ if (resolved.textIndentCm !== void 0 && tag === "p") {
2514
+ parts.push(`text-indent:${resolved.textIndentCm}cm`);
2515
+ }
2516
+ return parts;
2517
+ }
2518
+ function joinStyleParts(parts) {
2519
+ return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
2520
+ }
2521
+
2496
2522
  // src/conversion/html/table-presentation.ts
2497
2523
  var DEFAULT_BORDER_COLOR = "#e7e7e7";
2498
2524
  var DEFAULT_HEADER_BG = "#f5f5f5";
@@ -2563,6 +2589,7 @@ function deltaToHtml(delta, options = {}) {
2563
2589
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
2564
2590
  const blockHandlers = options.blockHandlers;
2565
2591
  const anchorLinks = options.anchorLinks ?? false;
2592
+ const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
2566
2593
  let html = "";
2567
2594
  let listStack = [];
2568
2595
  let counters = [];
@@ -2625,7 +2652,14 @@ function deltaToHtml(delta, options = {}) {
2625
2652
  if (hierarchicalNumbers && listType === "ordered") {
2626
2653
  hierarchicalNumber = counters.slice(0, indent + 1).join(".");
2627
2654
  }
2628
- html += renderListItem(content, listItemAttrs, pretty, indentLevel, hierarchicalNumber);
2655
+ html += renderListItem(
2656
+ content,
2657
+ listItemAttrs,
2658
+ pretty,
2659
+ indentLevel,
2660
+ hierarchicalNumber,
2661
+ resolvedDocumentPresentation
2662
+ );
2629
2663
  } else {
2630
2664
  let headingId;
2631
2665
  if (line.attributes?.header) {
@@ -2637,7 +2671,14 @@ function deltaToHtml(delta, options = {}) {
2637
2671
  headingId = slugifyWithDedup(plainText, slugUsageMap);
2638
2672
  }
2639
2673
  }
2640
- html += renderBlock(content, tag, line.attributes, pretty, headingId);
2674
+ html += renderBlock(
2675
+ content,
2676
+ tag,
2677
+ line.attributes,
2678
+ pretty,
2679
+ headingId,
2680
+ resolvedDocumentPresentation
2681
+ );
2641
2682
  }
2642
2683
  }
2643
2684
  html += closeAllLists(listStack, pretty);
@@ -2929,36 +2970,41 @@ function getListItemAttributes(attributes) {
2929
2970
  }
2930
2971
  return "";
2931
2972
  }
2932
- function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber) {
2973
+ function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
2933
2974
  const indent = pretty ? getIndent(indentLevel) : "";
2934
2975
  const innerContent = content || "<br>";
2935
2976
  let fullAttrs = attrs;
2936
2977
  if (hierarchicalNumber) {
2937
2978
  fullAttrs += ` data-number="${hierarchicalNumber}"`;
2938
2979
  }
2980
+ const styleAttr = joinStyleParts(
2981
+ documentPresentationStyleParts("li", resolvedDocumentPresentation)
2982
+ );
2983
+ fullAttrs += styleAttr;
2939
2984
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
2940
2985
  return pretty ? html + "\n" : html;
2941
2986
  }
2942
- function renderBlock(content, tag, attributes, pretty, id) {
2987
+ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
2943
2988
  const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
2944
- const styleAttr = getBlockStyleAttribute(attributes);
2989
+ const styleAttr = getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation);
2945
2990
  const innerContent = content || "<br>";
2946
2991
  const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
2947
2992
  return pretty ? html + "\n" : html;
2948
2993
  }
2949
- function getBlockStyleAttribute(attributes) {
2950
- if (!attributes) return "";
2951
- const styles = [];
2952
- const alignVal = attributes.align;
2953
- if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
2954
- styles.push(`text-align: ${alignVal}`);
2955
- }
2956
- if (attributes.indent && typeof attributes.indent === "number") {
2957
- if (!attributes.list) {
2958
- styles.push(`margin-left: ${attributes.indent * 2}em`);
2994
+ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
2995
+ const styles = documentPresentationStyleParts(tag, resolvedDocumentPresentation);
2996
+ if (attributes) {
2997
+ const alignVal = attributes.align;
2998
+ if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
2999
+ styles.push(`text-align: ${alignVal}`);
3000
+ }
3001
+ if (attributes.indent && typeof attributes.indent === "number") {
3002
+ if (!attributes.list) {
3003
+ styles.push(`margin-left: ${attributes.indent * 2}em`);
3004
+ }
2959
3005
  }
2960
3006
  }
2961
- return styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
3007
+ return joinStyleParts(styles);
2962
3008
  }
2963
3009
  function extractPlainText(ops) {
2964
3010
  let text = "";
@@ -5110,6 +5156,7 @@ export {
5110
5156
  deltaToHtml,
5111
5157
  deltaToMarkdown,
5112
5158
  dividerFormat,
5159
+ documentPresentationStyleParts,
5113
5160
  escapeHtml,
5114
5161
  extractBoxOpAttributes,
5115
5162
  extractTableRegion,
@@ -5142,6 +5189,7 @@ export {
5142
5189
  nodeAdapter,
5143
5190
  normalizeDelta,
5144
5191
  preloadRemark,
5192
+ resolveDocumentPresentation,
5145
5193
  resolveTablePresentation,
5146
5194
  sanitizeDelta,
5147
5195
  sizeFormat,