@scrider/formatter 1.3.4 → 1.3.6

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,33 @@ 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
+ var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p", "li"]);
2506
+ function documentPresentationStyleParts(tag, resolved) {
2507
+ if (!resolved) return [];
2508
+ const parts = [];
2509
+ if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
2510
+ const pct = Math.round(resolved.lineSpacing * 100);
2511
+ parts.push(`line-height:${resolved.lineSpacing}`);
2512
+ parts.push(`mso-line-height-alt:${pct}%`);
2513
+ }
2514
+ if (resolved.textIndentCm !== void 0 && TEXT_INDENT_TAGS.has(tag)) {
2515
+ parts.push(`text-indent:${resolved.textIndentCm}cm`);
2516
+ }
2517
+ return parts;
2518
+ }
2519
+ function joinStyleParts(parts) {
2520
+ return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
2521
+ }
2522
+
2496
2523
  // src/conversion/html/table-presentation.ts
2497
2524
  var DEFAULT_BORDER_COLOR = "#e7e7e7";
2498
2525
  var DEFAULT_HEADER_BG = "#f5f5f5";
@@ -2563,6 +2590,7 @@ function deltaToHtml(delta, options = {}) {
2563
2590
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
2564
2591
  const blockHandlers = options.blockHandlers;
2565
2592
  const anchorLinks = options.anchorLinks ?? false;
2593
+ const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
2566
2594
  let html = "";
2567
2595
  let listStack = [];
2568
2596
  let counters = [];
@@ -2625,7 +2653,14 @@ function deltaToHtml(delta, options = {}) {
2625
2653
  if (hierarchicalNumbers && listType === "ordered") {
2626
2654
  hierarchicalNumber = counters.slice(0, indent + 1).join(".");
2627
2655
  }
2628
- html += renderListItem(content, listItemAttrs, pretty, indentLevel, hierarchicalNumber);
2656
+ html += renderListItem(
2657
+ content,
2658
+ listItemAttrs,
2659
+ pretty,
2660
+ indentLevel,
2661
+ hierarchicalNumber,
2662
+ resolvedDocumentPresentation
2663
+ );
2629
2664
  } else {
2630
2665
  let headingId;
2631
2666
  if (line.attributes?.header) {
@@ -2637,7 +2672,14 @@ function deltaToHtml(delta, options = {}) {
2637
2672
  headingId = slugifyWithDedup(plainText, slugUsageMap);
2638
2673
  }
2639
2674
  }
2640
- html += renderBlock(content, tag, line.attributes, pretty, headingId);
2675
+ html += renderBlock(
2676
+ content,
2677
+ tag,
2678
+ line.attributes,
2679
+ pretty,
2680
+ headingId,
2681
+ resolvedDocumentPresentation
2682
+ );
2641
2683
  }
2642
2684
  }
2643
2685
  html += closeAllLists(listStack, pretty);
@@ -2929,36 +2971,41 @@ function getListItemAttributes(attributes) {
2929
2971
  }
2930
2972
  return "";
2931
2973
  }
2932
- function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber) {
2974
+ function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
2933
2975
  const indent = pretty ? getIndent(indentLevel) : "";
2934
2976
  const innerContent = content || "<br>";
2935
2977
  let fullAttrs = attrs;
2936
2978
  if (hierarchicalNumber) {
2937
2979
  fullAttrs += ` data-number="${hierarchicalNumber}"`;
2938
2980
  }
2981
+ const styleAttr = joinStyleParts(
2982
+ documentPresentationStyleParts("li", resolvedDocumentPresentation)
2983
+ );
2984
+ fullAttrs += styleAttr;
2939
2985
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
2940
2986
  return pretty ? html + "\n" : html;
2941
2987
  }
2942
- function renderBlock(content, tag, attributes, pretty, id) {
2988
+ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
2943
2989
  const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
2944
- const styleAttr = getBlockStyleAttribute(attributes);
2990
+ const styleAttr = getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation);
2945
2991
  const innerContent = content || "<br>";
2946
2992
  const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
2947
2993
  return pretty ? html + "\n" : html;
2948
2994
  }
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`);
2995
+ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
2996
+ const styles = documentPresentationStyleParts(tag, resolvedDocumentPresentation);
2997
+ if (attributes) {
2998
+ const alignVal = attributes.align;
2999
+ if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
3000
+ styles.push(`text-align: ${alignVal}`);
3001
+ }
3002
+ if (attributes.indent && typeof attributes.indent === "number") {
3003
+ if (!attributes.list) {
3004
+ styles.push(`margin-left: ${attributes.indent * 2}em`);
3005
+ }
2959
3006
  }
2960
3007
  }
2961
- return styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
3008
+ return joinStyleParts(styles);
2962
3009
  }
2963
3010
  function extractPlainText(ops) {
2964
3011
  let text = "";
@@ -5110,6 +5157,7 @@ export {
5110
5157
  deltaToHtml,
5111
5158
  deltaToMarkdown,
5112
5159
  dividerFormat,
5160
+ documentPresentationStyleParts,
5113
5161
  escapeHtml,
5114
5162
  extractBoxOpAttributes,
5115
5163
  extractTableRegion,
@@ -5142,6 +5190,7 @@ export {
5142
5190
  nodeAdapter,
5143
5191
  normalizeDelta,
5144
5192
  preloadRemark,
5193
+ resolveDocumentPresentation,
5145
5194
  resolveTablePresentation,
5146
5195
  sanitizeDelta,
5147
5196
  sizeFormat,