@scrider/formatter 1.8.7 → 1.9.1

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
@@ -2,6 +2,50 @@ import { AttributeMap, Op, Delta, InsertOp } from '@scrider/delta';
2
2
  export * from '@scrider/delta';
3
3
  export { InsertOp as ContentOp } from '@scrider/delta';
4
4
 
5
+ /**
6
+ * Document-level metadata (Scrider format extension).
7
+ *
8
+ * Concrete schema for the opaque `scrider-metadata` sibling field defined in
9
+ * `@scrider/delta` (`ScriderDocument`). It carries document-wide defaults ONCE
10
+ * (line spacing, paragraph spacing, indent, heading policy, fonts) instead of
11
+ * duplicating them as block attributes on every `\n`.
12
+ *
13
+ * Layering:
14
+ * - `@scrider/delta` treats the value as opaque `Record<string, unknown>` — it
15
+ * never participates in `length()`, selection indices, OT, or partial copy/paste.
16
+ * - `@scrider/formatter` is the CONTRACT OWNER of this concrete shape.
17
+ * - `@scrider/editor-core` / `@scrider/editor-react` consume it (state, CSS vars,
18
+ * export projection).
19
+ *
20
+ * All fields are optional and additive: extending the interface never changes the
21
+ * op-stream and is backward compatible. Presentation-relevant fields are projected
22
+ * to HTML via {@link documentMetadataToPresentation}; heading/font policy is applied
23
+ * by upstream layers (CSS vars, bake) and is intentionally NOT part of the inline
24
+ * export projection.
25
+ */
26
+ interface ScriderDocumentMetadata {
27
+ /** Line spacing multiplier, e.g. `1.5`. */
28
+ lineSpacing?: number;
29
+ /** Space before plain paragraphs in em, e.g. `0.5`. */
30
+ paragraphSpacingBeforeEm?: number;
31
+ /** Space after plain paragraphs in em, e.g. `0.5`. */
32
+ paragraphSpacingAfterEm?: number;
33
+ /** First-line indent in cm on `<p>` (lists use {@link listBlockIndentCm}). */
34
+ textIndentCm?: number;
35
+ /** Extra left indent in cm on top-level `<ul>`/`<ol>` (shifts marker + text). */
36
+ listBlockIndentCm?: number;
37
+ /** Document heading horizontal alignment policy. */
38
+ headingAlign?: 'left' | 'center' | 'right';
39
+ /** Document heading bold policy. */
40
+ headingBold?: boolean;
41
+ /** Named heading size-grid preset id (schema defined upstream). */
42
+ headingSizeGridPreset?: string;
43
+ /** Default document font family (bare family name, e.g. `Georgia`). */
44
+ defaultFont?: string;
45
+ /** Default document font size as a CSS length, e.g. `12pt`. */
46
+ defaultFontSize?: string;
47
+ }
48
+
5
49
  /**
6
50
  * DOM Adapter Interface
7
51
  *
@@ -192,6 +236,21 @@ interface Format<T = unknown> {
192
236
  * Scope of the format
193
237
  */
194
238
  readonly scope: FormatScope;
239
+ /**
240
+ * Block-level marker for `embed` formats.
241
+ *
242
+ * A block-level embed (e.g. `divider` → `<hr>`) stands on its own line: in
243
+ * Delta it is the `{embed}` op followed by its own paragraph-terminating
244
+ * `\n`, and in HTML it is NOT wrapped in a `<p>`. Inline embeds (image,
245
+ * formula, softBreak…) live inside a paragraph and rely on the surrounding
246
+ * block's `\n`, so they leave this unset.
247
+ *
248
+ * `htmlToDelta` uses this to emit the block `\n` after matching a block-level
249
+ * embed via the registry (otherwise the following content glues onto the
250
+ * embed's line — see the `<hr>` round-trip regression). Ignored for
251
+ * non-embed scopes.
252
+ */
253
+ readonly blockLevel?: boolean;
195
254
  /**
196
255
  * Normalize value to canonical form
197
256
  *
@@ -1431,6 +1490,17 @@ interface ResolvedDocumentPresentation {
1431
1490
  listBlockIndentCm: number | undefined;
1432
1491
  }
1433
1492
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1493
+ /**
1494
+ * Project {@link ScriderDocumentMetadata} onto an HTML {@link DocumentPresentation}
1495
+ * (export / clipboard inline CSS).
1496
+ *
1497
+ * Only presentation-relevant fields are mapped (line/paragraph spacing, indent).
1498
+ * Heading policy (align/bold/size grid) and fonts are applied by upstream layers
1499
+ * (CSS vars in the editor, bake into block/inline attrs) and are deliberately not
1500
+ * part of the inline projection. Returns `undefined` when nothing maps, so callers
1501
+ * can fall back cleanly.
1502
+ */
1503
+ declare function documentMetadataToPresentation(metadata: ScriderDocumentMetadata | undefined): DocumentPresentation | undefined;
1434
1504
  /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1435
1505
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1436
1506
  /**
@@ -1549,6 +1619,15 @@ interface DeltaToHtmlOptions {
1549
1619
  * Office/HTML export and clipboard. Does not change Delta.
1550
1620
  */
1551
1621
  documentPresentation?: DocumentPresentation;
1622
+ /**
1623
+ * Document-level metadata (Scrider format extension, `scrider-metadata`).
1624
+ *
1625
+ * When {@link documentPresentation} is not provided, the presentation-relevant
1626
+ * fields of this metadata are projected to inline CSS via
1627
+ * `documentMetadataToPresentation` (export/clipboard). An explicit
1628
+ * `documentPresentation` always takes precedence. Does not change Delta.
1629
+ */
1630
+ documentMetadata?: ScriderDocumentMetadata;
1552
1631
  /**
1553
1632
  * Cross-origin iframe isolation for embed formats (codeWidget, video iframe).
1554
1633
  * Default: both off — standard third-party iframes load with browser cookies.
@@ -2072,4 +2151,4 @@ declare function collectAdjacentTableLines<T extends {
2072
2151
  */
2073
2152
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2074
2153
 
2075
- 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 CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, 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, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
2154
+ 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 CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type ScriderDocumentMetadata, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,50 @@ import { AttributeMap, Op, Delta, InsertOp } from '@scrider/delta';
2
2
  export * from '@scrider/delta';
3
3
  export { InsertOp as ContentOp } from '@scrider/delta';
4
4
 
5
+ /**
6
+ * Document-level metadata (Scrider format extension).
7
+ *
8
+ * Concrete schema for the opaque `scrider-metadata` sibling field defined in
9
+ * `@scrider/delta` (`ScriderDocument`). It carries document-wide defaults ONCE
10
+ * (line spacing, paragraph spacing, indent, heading policy, fonts) instead of
11
+ * duplicating them as block attributes on every `\n`.
12
+ *
13
+ * Layering:
14
+ * - `@scrider/delta` treats the value as opaque `Record<string, unknown>` — it
15
+ * never participates in `length()`, selection indices, OT, or partial copy/paste.
16
+ * - `@scrider/formatter` is the CONTRACT OWNER of this concrete shape.
17
+ * - `@scrider/editor-core` / `@scrider/editor-react` consume it (state, CSS vars,
18
+ * export projection).
19
+ *
20
+ * All fields are optional and additive: extending the interface never changes the
21
+ * op-stream and is backward compatible. Presentation-relevant fields are projected
22
+ * to HTML via {@link documentMetadataToPresentation}; heading/font policy is applied
23
+ * by upstream layers (CSS vars, bake) and is intentionally NOT part of the inline
24
+ * export projection.
25
+ */
26
+ interface ScriderDocumentMetadata {
27
+ /** Line spacing multiplier, e.g. `1.5`. */
28
+ lineSpacing?: number;
29
+ /** Space before plain paragraphs in em, e.g. `0.5`. */
30
+ paragraphSpacingBeforeEm?: number;
31
+ /** Space after plain paragraphs in em, e.g. `0.5`. */
32
+ paragraphSpacingAfterEm?: number;
33
+ /** First-line indent in cm on `<p>` (lists use {@link listBlockIndentCm}). */
34
+ textIndentCm?: number;
35
+ /** Extra left indent in cm on top-level `<ul>`/`<ol>` (shifts marker + text). */
36
+ listBlockIndentCm?: number;
37
+ /** Document heading horizontal alignment policy. */
38
+ headingAlign?: 'left' | 'center' | 'right';
39
+ /** Document heading bold policy. */
40
+ headingBold?: boolean;
41
+ /** Named heading size-grid preset id (schema defined upstream). */
42
+ headingSizeGridPreset?: string;
43
+ /** Default document font family (bare family name, e.g. `Georgia`). */
44
+ defaultFont?: string;
45
+ /** Default document font size as a CSS length, e.g. `12pt`. */
46
+ defaultFontSize?: string;
47
+ }
48
+
5
49
  /**
6
50
  * DOM Adapter Interface
7
51
  *
@@ -192,6 +236,21 @@ interface Format<T = unknown> {
192
236
  * Scope of the format
193
237
  */
194
238
  readonly scope: FormatScope;
239
+ /**
240
+ * Block-level marker for `embed` formats.
241
+ *
242
+ * A block-level embed (e.g. `divider` → `<hr>`) stands on its own line: in
243
+ * Delta it is the `{embed}` op followed by its own paragraph-terminating
244
+ * `\n`, and in HTML it is NOT wrapped in a `<p>`. Inline embeds (image,
245
+ * formula, softBreak…) live inside a paragraph and rely on the surrounding
246
+ * block's `\n`, so they leave this unset.
247
+ *
248
+ * `htmlToDelta` uses this to emit the block `\n` after matching a block-level
249
+ * embed via the registry (otherwise the following content glues onto the
250
+ * embed's line — see the `<hr>` round-trip regression). Ignored for
251
+ * non-embed scopes.
252
+ */
253
+ readonly blockLevel?: boolean;
195
254
  /**
196
255
  * Normalize value to canonical form
197
256
  *
@@ -1431,6 +1490,17 @@ interface ResolvedDocumentPresentation {
1431
1490
  listBlockIndentCm: number | undefined;
1432
1491
  }
1433
1492
  declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
1493
+ /**
1494
+ * Project {@link ScriderDocumentMetadata} onto an HTML {@link DocumentPresentation}
1495
+ * (export / clipboard inline CSS).
1496
+ *
1497
+ * Only presentation-relevant fields are mapped (line/paragraph spacing, indent).
1498
+ * Heading policy (align/bold/size grid) and fonts are applied by upstream layers
1499
+ * (CSS vars in the editor, bake into block/inline attrs) and are deliberately not
1500
+ * part of the inline projection. Returns `undefined` when nothing maps, so callers
1501
+ * can fall back cleanly.
1502
+ */
1503
+ declare function documentMetadataToPresentation(metadata: ScriderDocumentMetadata | undefined): DocumentPresentation | undefined;
1434
1504
  /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1435
1505
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1436
1506
  /**
@@ -1549,6 +1619,15 @@ interface DeltaToHtmlOptions {
1549
1619
  * Office/HTML export and clipboard. Does not change Delta.
1550
1620
  */
1551
1621
  documentPresentation?: DocumentPresentation;
1622
+ /**
1623
+ * Document-level metadata (Scrider format extension, `scrider-metadata`).
1624
+ *
1625
+ * When {@link documentPresentation} is not provided, the presentation-relevant
1626
+ * fields of this metadata are projected to inline CSS via
1627
+ * `documentMetadataToPresentation` (export/clipboard). An explicit
1628
+ * `documentPresentation` always takes precedence. Does not change Delta.
1629
+ */
1630
+ documentMetadata?: ScriderDocumentMetadata;
1552
1631
  /**
1553
1632
  * Cross-origin iframe isolation for embed formats (codeWidget, video iframe).
1554
1633
  * Default: both off — standard third-party iframes load with browser cookies.
@@ -2072,4 +2151,4 @@ declare function collectAdjacentTableLines<T extends {
2072
2151
  */
2073
2152
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2074
2153
 
2075
- 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 CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, 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, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
2154
+ 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 CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, type SanitizeOptions, type ScriderDocumentMetadata, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.js CHANGED
@@ -868,10 +868,12 @@ function renderTableHostWrapperOpen(data, pretty) {
868
868
  attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
869
869
  }
870
870
  const styleParts = [];
871
- if (data.width != null && data.width > 0) {
871
+ if (data.blockAlign === "justify" && !data.float) {
872
+ styleParts.push("width: 100%");
873
+ } else if (data.width != null && data.width > 0) {
872
874
  styleParts.push(`width: ${Math.round(data.width)}px`);
873
875
  styleParts.push("max-width: 100%");
874
- } else if (data.blockAlign === "justify" && !data.float) {
876
+ } else if (data.blockAlign && !data.float) {
875
877
  styleParts.push("width: 100%");
876
878
  }
877
879
  if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
@@ -2492,6 +2494,7 @@ var codeWidgetFormat = {
2492
2494
  var dividerFormat = {
2493
2495
  name: "divider",
2494
2496
  scope: "embed",
2497
+ blockLevel: true,
2495
2498
  normalize(value) {
2496
2499
  return !!value;
2497
2500
  },
@@ -3113,6 +3116,26 @@ function resolveDocumentPresentation(presentation) {
3113
3116
  listBlockIndentCm
3114
3117
  };
3115
3118
  }
3119
+ function documentMetadataToPresentation(metadata) {
3120
+ if (!metadata) return void 0;
3121
+ const presentation = {};
3122
+ if (typeof metadata.lineSpacing === "number") {
3123
+ presentation.lineSpacing = metadata.lineSpacing;
3124
+ }
3125
+ if (typeof metadata.paragraphSpacingBeforeEm === "number") {
3126
+ presentation.paragraphSpacingBeforeEm = metadata.paragraphSpacingBeforeEm;
3127
+ }
3128
+ if (typeof metadata.paragraphSpacingAfterEm === "number") {
3129
+ presentation.paragraphSpacingAfterEm = metadata.paragraphSpacingAfterEm;
3130
+ }
3131
+ if (typeof metadata.textIndentCm === "number") {
3132
+ presentation.textIndentCm = metadata.textIndentCm;
3133
+ }
3134
+ if (typeof metadata.listBlockIndentCm === "number") {
3135
+ presentation.listBlockIndentCm = metadata.listBlockIndentCm;
3136
+ }
3137
+ return Object.keys(presentation).length > 0 ? presentation : void 0;
3138
+ }
3116
3139
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
3117
3140
  function documentPresentationListWrapperStyleParts(resolved) {
3118
3141
  if (!resolved?.listBlockIndentCm) return [];
@@ -3298,7 +3321,9 @@ function deltaToHtml(delta, options = {}) {
3298
3321
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
3299
3322
  const blockHandlers = options.blockHandlers;
3300
3323
  const anchorLinks = options.anchorLinks ?? false;
3301
- const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
3324
+ const resolvedDocumentPresentation = resolveDocumentPresentation(
3325
+ options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
3326
+ );
3302
3327
  let html = "";
3303
3328
  let listStack = [];
3304
3329
  let counters = [];
@@ -3936,7 +3961,13 @@ function htmlToDelta(html, options = {}) {
3936
3961
  if (format.match) {
3937
3962
  const result = format.match(node);
3938
3963
  if (result != null) {
3964
+ if (format.blockLevel && !atLineStart) {
3965
+ context.pushNewline();
3966
+ }
3939
3967
  context.pushEmbed({ [format.name]: result.value }, result.attributes);
3968
+ if (format.blockLevel) {
3969
+ context.pushNewline();
3970
+ }
3940
3971
  return;
3941
3972
  }
3942
3973
  }
@@ -3951,6 +3982,9 @@ function htmlToDelta(html, options = {}) {
3951
3982
  return;
3952
3983
  }
3953
3984
  if (tagName === "hr") {
3985
+ if (!atLineStart) {
3986
+ context.pushNewline();
3987
+ }
3954
3988
  context.pushEmbed({ divider: true });
3955
3989
  context.pushNewline();
3956
3990
  return;
@@ -6069,6 +6103,7 @@ export {
6069
6103
  deltaToHtml,
6070
6104
  deltaToMarkdown,
6071
6105
  dividerFormat,
6106
+ documentMetadataToPresentation,
6072
6107
  documentPresentationStyleParts,
6073
6108
  escapeHtml,
6074
6109
  extractBoxOpAttributes,