@scrider/formatter 1.3.6 → 1.4.0

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
@@ -1294,17 +1294,20 @@ declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
1295
  /**
1296
1296
  * Document-level HTML presentation for deltaToHtml (clipboard, export).
1297
- * Not stored in Delta — mirrors editor Settings (line spacing, first-line indent).
1297
+ * Not stored in Delta — mirrors editor Settings (line spacing, indents).
1298
1298
  */
1299
1299
  interface DocumentPresentation {
1300
1300
  /** Line spacing multiplier, e.g. 1.5 */
1301
1301
  lineSpacing?: number;
1302
- /** First-line indent in centimeters, e.g. 1.25 */
1302
+ /** First-line indent in cm on `<p>` and `<li>` (wrapped / soft-break lines unchanged). */
1303
1303
  textIndentCm?: number;
1304
+ /** Extra left padding on top-level `<ul>`/`<ol>` — shifts marker + text as a block. */
1305
+ listBlockIndentCm?: number;
1304
1306
  }
1305
1307
  interface ResolvedDocumentPresentation {
1306
1308
  lineSpacing: number | undefined;
1307
1309
  textIndentCm: number | undefined;
1310
+ listBlockIndentCm: number | undefined;
1308
1311
  }
1309
1312
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1310
1313
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
package/dist/index.d.ts CHANGED
@@ -1294,17 +1294,20 @@ declare function cloneDelta(delta: Delta): Delta;
1294
1294
 
1295
1295
  /**
1296
1296
  * Document-level HTML presentation for deltaToHtml (clipboard, export).
1297
- * Not stored in Delta — mirrors editor Settings (line spacing, first-line indent).
1297
+ * Not stored in Delta — mirrors editor Settings (line spacing, indents).
1298
1298
  */
1299
1299
  interface DocumentPresentation {
1300
1300
  /** Line spacing multiplier, e.g. 1.5 */
1301
1301
  lineSpacing?: number;
1302
- /** First-line indent in centimeters, e.g. 1.25 */
1302
+ /** First-line indent in cm on `<p>` and `<li>` (wrapped / soft-break lines unchanged). */
1303
1303
  textIndentCm?: number;
1304
+ /** Extra left padding on top-level `<ul>`/`<ol>` — shifts marker + text as a block. */
1305
+ listBlockIndentCm?: number;
1304
1306
  }
1305
1307
  interface ResolvedDocumentPresentation {
1306
1308
  lineSpacing: number | undefined;
1307
1309
  textIndentCm: number | undefined;
1310
+ listBlockIndentCm: number | undefined;
1308
1311
  }
1309
1312
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1310
1313
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
package/dist/index.js CHANGED
@@ -2498,11 +2498,18 @@ function resolveDocumentPresentation(presentation) {
2498
2498
  if (!presentation) return void 0;
2499
2499
  const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
2500
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 };
2501
+ const listBlockIndentCm = typeof presentation.listBlockIndentCm === "number" && presentation.listBlockIndentCm > 0 ? presentation.listBlockIndentCm : void 0;
2502
+ if (lineSpacing === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
2503
+ return void 0;
2504
+ }
2505
+ return { lineSpacing, textIndentCm, listBlockIndentCm };
2503
2506
  }
2504
2507
  var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2505
2508
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p", "li"]);
2509
+ function documentPresentationListWrapperStyleParts(resolved) {
2510
+ if (!resolved?.listBlockIndentCm) return [];
2511
+ return [`padding-left:calc(1.5em + ${resolved.listBlockIndentCm}cm)`];
2512
+ }
2506
2513
  function documentPresentationStyleParts(tag, resolved) {
2507
2514
  if (!resolved) return [];
2508
2515
  const parts = [];
@@ -2627,7 +2634,13 @@ function deltaToHtml(delta, options = {}) {
2627
2634
  continue;
2628
2635
  }
2629
2636
  if (isList) {
2630
- html += handleListOpen(listStack, listType, indent, pretty);
2637
+ html += handleListOpen(
2638
+ listStack,
2639
+ listType,
2640
+ indent,
2641
+ pretty,
2642
+ resolvedDocumentPresentation
2643
+ );
2631
2644
  if (hierarchicalNumbers && listType === "ordered") {
2632
2645
  if (counters.length > indent + 1) {
2633
2646
  counters = counters.slice(0, indent + 1);
@@ -2906,9 +2919,13 @@ function renderCodeBlock(codeLines, language, embedRenderers, pretty, blockHandl
2906
2919
  </code></pre>`;
2907
2920
  return pretty ? html + "\n" : html;
2908
2921
  }
2909
- function handleListOpen(stack, listType, indent, pretty) {
2922
+ function handleListOpen(stack, listType, indent, pretty, resolvedDocumentPresentation) {
2910
2923
  let html = "";
2911
2924
  const wrapperTag = LIST_WRAPPER_TAGS[listType] || "ul";
2925
+ const openWrapperTag = () => {
2926
+ const styleAttr = stack.length === 0 ? joinStyleParts(documentPresentationListWrapperStyleParts(resolvedDocumentPresentation)) : "";
2927
+ return `<${wrapperTag}${styleAttr}>`;
2928
+ };
2912
2929
  while (stack.length > 0) {
2913
2930
  const last = stack[stack.length - 1];
2914
2931
  if (!last || last.indent <= indent) break;
@@ -2935,7 +2952,7 @@ function handleListOpen(stack, listType, indent, pretty) {
2935
2952
  const currentIndent = last ? last.indent + 1 : 0;
2936
2953
  if (currentIndent > indent) break;
2937
2954
  if (pretty) html += getIndent(stack.length);
2938
- html += `<${wrapperTag}>`;
2955
+ html += openWrapperTag();
2939
2956
  if (pretty) html += "\n";
2940
2957
  stack.push({ type: listType, indent: currentIndent });
2941
2958
  if (currentIndent >= indent) break;
@@ -2943,7 +2960,7 @@ function handleListOpen(stack, listType, indent, pretty) {
2943
2960
  const current = stack[stack.length - 1];
2944
2961
  if (!current || current.indent < indent) {
2945
2962
  if (pretty) html += getIndent(stack.length);
2946
- html += `<${wrapperTag}>`;
2963
+ html += openWrapperTag();
2947
2964
  if (pretty) html += "\n";
2948
2965
  stack.push({ type: listType, indent });
2949
2966
  }