@scrider/formatter 1.4.1 → 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.d.cts CHANGED
@@ -1292,13 +1292,26 @@ declare function validateDelta(delta: Delta, registry: Registry): boolean;
1292
1292
  */
1293
1293
  declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
+ /** Per-paragraph line spacing stored on `\n` (Word paste, Settings Apply, toolbar). */
1296
+ declare const SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
1297
+ /** Block tags that receive line spacing (not headings). */
1298
+ declare const LINE_HEIGHT_BLOCK_TAGS: Set<string>;
1295
1299
  /**
1300
+ * Parse a line-height multiplier from Delta / inline CSS values
1301
+ * (`1.5`, `2`, `150%`).
1302
+ */
1303
+ declare function parseScriderLineHeightMultiplier(value: string): number | undefined;
1304
+ /**
1305
+ * Line-height for a block tag: `scrider-line-height` on the line → documentPresentation → none.
1306
+ */
1307
+ declare function blockLineHeightStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
1296
1308
 
1309
+ /**
1297
1310
  * Document-level HTML presentation for deltaToHtml (clipboard, export).
1298
-
1299
- * Not stored in Delta mirrors editor Settings (line spacing, indents).
1300
-
1311
+ * Mirrors editor Settings when block attrs are absent.
1312
+ * Per-block line spacing: {@link blockLineHeightStyleParts} (`scrider-line-height` on `\n`).
1301
1313
  */
1314
+
1302
1315
  interface DocumentPresentation {
1303
1316
  /** Line spacing multiplier, e.g. 1.5 */
1304
1317
  lineSpacing?: number;
@@ -1313,7 +1326,12 @@ interface ResolvedDocumentPresentation {
1313
1326
  listBlockIndentCm: number | undefined;
1314
1327
  }
1315
1328
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1329
+ /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1316
1330
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1331
+ /**
1332
+ * All block presentation styles for deltaToHtml: Delta attrs, then document defaults.
1333
+ */
1334
+ declare function blockPresentationStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
1317
1335
 
1318
1336
  /**
1319
1337
  * Simple Table HTML presentation options for deltaToHtml (clipboard, export).
@@ -1891,4 +1909,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
1891
1909
  */
1892
1910
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
1893
1911
 
1894
- 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 };
1912
+ 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, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockPresentationStyleParts, 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, parseScriderLineHeightMultiplier, 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,13 +1292,26 @@ declare function validateDelta(delta: Delta, registry: Registry): boolean;
1292
1292
  */
1293
1293
  declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
+ /** Per-paragraph line spacing stored on `\n` (Word paste, Settings Apply, toolbar). */
1296
+ declare const SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
1297
+ /** Block tags that receive line spacing (not headings). */
1298
+ declare const LINE_HEIGHT_BLOCK_TAGS: Set<string>;
1295
1299
  /**
1300
+ * Parse a line-height multiplier from Delta / inline CSS values
1301
+ * (`1.5`, `2`, `150%`).
1302
+ */
1303
+ declare function parseScriderLineHeightMultiplier(value: string): number | undefined;
1304
+ /**
1305
+ * Line-height for a block tag: `scrider-line-height` on the line → documentPresentation → none.
1306
+ */
1307
+ declare function blockLineHeightStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
1296
1308
 
1309
+ /**
1297
1310
  * Document-level HTML presentation for deltaToHtml (clipboard, export).
1298
-
1299
- * Not stored in Delta mirrors editor Settings (line spacing, indents).
1300
-
1311
+ * Mirrors editor Settings when block attrs are absent.
1312
+ * Per-block line spacing: {@link blockLineHeightStyleParts} (`scrider-line-height` on `\n`).
1301
1313
  */
1314
+
1302
1315
  interface DocumentPresentation {
1303
1316
  /** Line spacing multiplier, e.g. 1.5 */
1304
1317
  lineSpacing?: number;
@@ -1313,7 +1326,12 @@ interface ResolvedDocumentPresentation {
1313
1326
  listBlockIndentCm: number | undefined;
1314
1327
  }
1315
1328
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1329
+ /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1316
1330
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1331
+ /**
1332
+ * All block presentation styles for deltaToHtml: Delta attrs, then document defaults.
1333
+ */
1334
+ declare function blockPresentationStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
1317
1335
 
1318
1336
  /**
1319
1337
  * Simple Table HTML presentation options for deltaToHtml (clipboard, export).
@@ -1891,4 +1909,4 @@ declare function isTableNewlineOp(op: Op | undefined): boolean;
1891
1909
  */
1892
1910
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
1893
1911
 
1894
- 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 };
1912
+ 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, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, type SanitizeOptions, type TableBlockData, type TableCellAlign, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockPresentationStyleParts, 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, parseScriderLineHeightMultiplier, 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,38 @@ function slugifyWithDedup(text, usedSlugs) {
2493
2493
  return `${base}-${count}`;
2494
2494
  }
2495
2495
 
2496
+ // src/conversion/html/block-presentation.ts
2497
+ var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
2498
+ var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2499
+ function parseScriderLineHeightMultiplier(value) {
2500
+ const trimmed = value.trim();
2501
+ if (!trimmed) return void 0;
2502
+ if (trimmed.endsWith("%")) {
2503
+ const pct = Number.parseFloat(trimmed.slice(0, -1));
2504
+ if (Number.isFinite(pct) && pct > 0) return pct / 100;
2505
+ return void 0;
2506
+ }
2507
+ const n = Number.parseFloat(trimmed);
2508
+ if (Number.isFinite(n) && n > 0) return n;
2509
+ return void 0;
2510
+ }
2511
+ function lineHeightStyleParts(multiplier) {
2512
+ const pct = Math.round(multiplier * 100);
2513
+ return [`line-height:${multiplier}`, `mso-line-height-alt:${pct}%`];
2514
+ }
2515
+ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
2516
+ if (!LINE_HEIGHT_BLOCK_TAGS.has(tag)) return [];
2517
+ const raw = blockAttributes?.[SCRIDER_LINE_HEIGHT_KEY];
2518
+ if (typeof raw === "string") {
2519
+ const fromBlock = parseScriderLineHeightMultiplier(raw);
2520
+ if (fromBlock !== void 0) return lineHeightStyleParts(fromBlock);
2521
+ }
2522
+ if (resolved?.lineSpacing !== void 0) {
2523
+ return lineHeightStyleParts(resolved.lineSpacing);
2524
+ }
2525
+ return [];
2526
+ }
2527
+
2496
2528
  // src/conversion/html/document-presentation.ts
2497
2529
  function resolveDocumentPresentation(presentation) {
2498
2530
  if (!presentation) return void 0;
@@ -2504,28 +2536,25 @@ function resolveDocumentPresentation(presentation) {
2504
2536
  }
2505
2537
  return { lineSpacing, textIndentCm, listBlockIndentCm };
2506
2538
  }
2507
- var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2508
2539
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
2509
2540
  function documentPresentationListWrapperStyleParts(resolved) {
2510
2541
  if (!resolved?.listBlockIndentCm) return [];
2511
- return [
2512
- `padding-left:1.25em`,
2513
- `margin-left:${resolved.listBlockIndentCm}cm`
2514
- ];
2542
+ return [`padding-left:1.25em`, `margin-left:${resolved.listBlockIndentCm}cm`];
2515
2543
  }
2516
2544
  function documentPresentationStyleParts(tag, resolved) {
2517
2545
  if (!resolved) return [];
2518
2546
  const parts = [];
2519
- if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
2520
- const pct = Math.round(resolved.lineSpacing * 100);
2521
- parts.push(`line-height:${resolved.lineSpacing}`);
2522
- parts.push(`mso-line-height-alt:${pct}%`);
2523
- }
2524
2547
  if (resolved.textIndentCm !== void 0 && TEXT_INDENT_TAGS.has(tag)) {
2525
2548
  parts.push(`text-indent:${resolved.textIndentCm}cm`);
2526
2549
  }
2527
2550
  return parts;
2528
2551
  }
2552
+ function blockPresentationStyleParts(tag, blockAttributes, resolved) {
2553
+ return [
2554
+ ...blockLineHeightStyleParts(tag, blockAttributes, resolved),
2555
+ ...documentPresentationStyleParts(tag, resolved)
2556
+ ];
2557
+ }
2529
2558
  function joinStyleParts(parts) {
2530
2559
  return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
2531
2560
  }
@@ -2672,6 +2701,7 @@ function deltaToHtml(delta, options = {}) {
2672
2701
  html += renderListItem(
2673
2702
  content,
2674
2703
  listItemAttrs,
2704
+ line.attributes,
2675
2705
  pretty,
2676
2706
  indentLevel,
2677
2707
  hierarchicalNumber,
@@ -2991,17 +3021,14 @@ function getListItemAttributes(attributes) {
2991
3021
  }
2992
3022
  return "";
2993
3023
  }
2994
- function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
3024
+ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
2995
3025
  const indent = pretty ? getIndent(indentLevel) : "";
2996
3026
  const innerContent = content || "<br>";
2997
3027
  let fullAttrs = attrs;
2998
3028
  if (hierarchicalNumber) {
2999
3029
  fullAttrs += ` data-number="${hierarchicalNumber}"`;
3000
3030
  }
3001
- const styleAttr = joinStyleParts(
3002
- documentPresentationStyleParts("li", resolvedDocumentPresentation)
3003
- );
3004
- fullAttrs += styleAttr;
3031
+ fullAttrs += getBlockStyleAttribute("li", blockAttributes, resolvedDocumentPresentation);
3005
3032
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
3006
3033
  return pretty ? html + "\n" : html;
3007
3034
  }
@@ -3013,7 +3040,11 @@ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPrese
3013
3040
  return pretty ? html + "\n" : html;
3014
3041
  }
3015
3042
  function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3016
- const styles = documentPresentationStyleParts(tag, resolvedDocumentPresentation);
3043
+ const styles = blockPresentationStyleParts(
3044
+ tag,
3045
+ attributes,
3046
+ resolvedDocumentPresentation
3047
+ );
3017
3048
  if (attributes) {
3018
3049
  const alignVal = attributes.align;
3019
3050
  if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
@@ -5152,13 +5183,17 @@ export {
5152
5183
  BOX_OVERFLOW_VALUES,
5153
5184
  BlockHandlerRegistry,
5154
5185
  BrowserDOMAdapter,
5186
+ LINE_HEIGHT_BLOCK_TAGS,
5155
5187
  NODE_TYPE,
5156
5188
  NodeDOMAdapter,
5157
5189
  Registry,
5190
+ SCRIDER_LINE_HEIGHT_KEY,
5158
5191
  alertBlockHandler,
5159
5192
  alignFormat,
5160
5193
  backgroundFormat,
5161
5194
  blockFormat,
5195
+ blockLineHeightStyleParts,
5196
+ blockPresentationStyleParts,
5162
5197
  blockquoteFormat,
5163
5198
  boldFormat,
5164
5199
  boxBlockHandler,
@@ -5209,6 +5244,7 @@ export {
5209
5244
  markdownToDeltaSync,
5210
5245
  nodeAdapter,
5211
5246
  normalizeDelta,
5247
+ parseScriderLineHeightMultiplier,
5212
5248
  preloadRemark,
5213
5249
  resolveDocumentPresentation,
5214
5250
  resolveTablePresentation,