@scrider/formatter 1.8.6 → 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
  *
@@ -482,6 +541,8 @@ declare class BlockHandlerRegistry {
482
541
 
483
542
  /** Block-level float on extended table host (4.2.10). */
484
543
  type TableBlockFloat = 'left' | 'center' | 'right';
544
+ /** Block position when width is narrower than the line (margin-based, no float). */
545
+ type TableBlockAlign = 'left' | 'center' | 'right' | 'justify';
485
546
  /**
486
547
  * Column alignment options (GFM column-level subset).
487
548
  */
@@ -531,6 +592,8 @@ interface TableBlockData {
531
592
  width?: number;
532
593
  /** Block-level float on host wrapper (4.2.10). */
533
594
  float?: TableBlockFloat;
595
+ /** Block position when width is set (margin-based, no float). */
596
+ blockAlign?: TableBlockAlign;
534
597
  /** Column alignments */
535
598
  colAligns?: (CellAlign | null)[];
536
599
  /** Cells indexed by "row:col" */
@@ -1427,6 +1490,17 @@ interface ResolvedDocumentPresentation {
1427
1490
  listBlockIndentCm: number | undefined;
1428
1491
  }
1429
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;
1430
1504
  /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1431
1505
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1432
1506
  /**
@@ -1545,6 +1619,15 @@ interface DeltaToHtmlOptions {
1545
1619
  * Office/HTML export and clipboard. Does not change Delta.
1546
1620
  */
1547
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;
1548
1631
  /**
1549
1632
  * Cross-origin iframe isolation for embed formats (codeWidget, video iframe).
1550
1633
  * Default: both off — standard third-party iframes load with browser cookies.
@@ -2068,4 +2151,4 @@ declare function collectAdjacentTableLines<T extends {
2068
2151
  */
2069
2152
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2070
2153
 
2071
- 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
  *
@@ -482,6 +541,8 @@ declare class BlockHandlerRegistry {
482
541
 
483
542
  /** Block-level float on extended table host (4.2.10). */
484
543
  type TableBlockFloat = 'left' | 'center' | 'right';
544
+ /** Block position when width is narrower than the line (margin-based, no float). */
545
+ type TableBlockAlign = 'left' | 'center' | 'right' | 'justify';
485
546
  /**
486
547
  * Column alignment options (GFM column-level subset).
487
548
  */
@@ -531,6 +592,8 @@ interface TableBlockData {
531
592
  width?: number;
532
593
  /** Block-level float on host wrapper (4.2.10). */
533
594
  float?: TableBlockFloat;
595
+ /** Block position when width is set (margin-based, no float). */
596
+ blockAlign?: TableBlockAlign;
534
597
  /** Column alignments */
535
598
  colAligns?: (CellAlign | null)[];
536
599
  /** Cells indexed by "row:col" */
@@ -1427,6 +1490,17 @@ interface ResolvedDocumentPresentation {
1427
1490
  listBlockIndentCm: number | undefined;
1428
1491
  }
1429
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;
1430
1504
  /** Document-level styles only (line-height merged via {@link blockLineHeightStyleParts}). */
1431
1505
  declare function documentPresentationStyleParts(tag: string, resolved: ResolvedDocumentPresentation | undefined): string[];
1432
1506
  /**
@@ -1545,6 +1619,15 @@ interface DeltaToHtmlOptions {
1545
1619
  * Office/HTML export and clipboard. Does not change Delta.
1546
1620
  */
1547
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;
1548
1631
  /**
1549
1632
  * Cross-origin iframe isolation for embed formats (codeWidget, video iframe).
1550
1633
  * Default: both off — standard third-party iframes load with browser cookies.
@@ -2068,4 +2151,4 @@ declare function collectAdjacentTableLines<T extends {
2068
2151
  */
2069
2152
  declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
2070
2153
 
2071
- 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
@@ -627,6 +627,7 @@ function toCodeWidgetEmbedUrl(url) {
627
627
  var EXT_TABLE_HOST_ATTR = "data-scrider-ext-table";
628
628
  var EXT_TABLE_HOST_CLASS = "scrider-ext-table-host";
629
629
  var VALID_TABLE_BLOCK_FLOATS = ["left", "center", "right"];
630
+ var VALID_TABLE_BLOCK_ALIGNS = ["left", "center", "right", "justify"];
630
631
  var VALID_CELL_HORIZONTAL_ALIGNS = [
631
632
  "left",
632
633
  "center",
@@ -830,6 +831,12 @@ function parseTableBlockFloat(value) {
830
831
  if (value === "left" || value === "center" || value === "right") return value;
831
832
  return void 0;
832
833
  }
834
+ function parseTableBlockAlign(value) {
835
+ if (value === "left" || value === "center" || value === "right" || value === "justify") {
836
+ return value;
837
+ }
838
+ return void 0;
839
+ }
833
840
  function extractHostBlockWidthPx(host) {
834
841
  const style = host.getAttribute("style") || "";
835
842
  const widthMatch = style.match(/(?:^|;\s*)width:\s*([\d.]+)px/i);
@@ -840,25 +847,34 @@ function extractHostBlockWidthPx(host) {
840
847
  }
841
848
  function enrichTableBlockFromHost(data, host) {
842
849
  const float = parseTableBlockFloat(host.getAttribute("data-float"));
850
+ const blockAlign = parseTableBlockAlign(host.getAttribute("data-block-align"));
843
851
  const width = extractHostBlockWidthPx(host);
844
- if (float == null && width == null) return data;
852
+ if (float == null && blockAlign == null && width == null) return data;
845
853
  const next = { ...data };
846
854
  if (float != null) next.float = float;
855
+ if (blockAlign != null && float == null) next.blockAlign = blockAlign;
847
856
  if (width != null) next.width = width;
848
857
  return next;
849
858
  }
850
859
  function tableNeedsHostWrapper(data) {
851
- return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0;
860
+ return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0 || data.float == null && data.blockAlign != null && VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign);
852
861
  }
853
862
  function renderTableHostWrapperOpen(data, pretty) {
854
863
  const nl = pretty ? "\n" : "";
855
864
  const ind = pretty ? " " : "";
856
865
  const attrs = [`class="${EXT_TABLE_HOST_CLASS}"`, EXT_TABLE_HOST_ATTR];
857
866
  if (data.float) attrs.push(`data-float="${escapeHtml(data.float)}"`);
867
+ if (data.blockAlign && !data.float) {
868
+ attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
869
+ }
858
870
  const styleParts = [];
859
- 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) {
860
874
  styleParts.push(`width: ${Math.round(data.width)}px`);
861
875
  styleParts.push("max-width: 100%");
876
+ } else if (data.blockAlign && !data.float) {
877
+ styleParts.push("width: 100%");
862
878
  }
863
879
  if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
864
880
  return `<div ${attrs.join(" ")}>${nl}${ind}`;
@@ -879,6 +895,9 @@ function isGfmCompatible(data) {
879
895
  if (data.float != null) {
880
896
  return false;
881
897
  }
898
+ if (data.blockAlign != null) {
899
+ return false;
900
+ }
882
901
  for (const cell of Object.values(data.cells)) {
883
902
  if (cell !== null && cell.align !== void 0) return false;
884
903
  }
@@ -1263,6 +1282,9 @@ var tableBlockHandler = {
1263
1282
  if (data.float !== void 0 && !VALID_TABLE_BLOCK_FLOATS.includes(data.float)) {
1264
1283
  return false;
1265
1284
  }
1285
+ if (data.blockAlign !== void 0 && !VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign)) {
1286
+ return false;
1287
+ }
1266
1288
  if (data.colAligns !== void 0) {
1267
1289
  if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
1268
1290
  return false;
@@ -2472,6 +2494,7 @@ var codeWidgetFormat = {
2472
2494
  var dividerFormat = {
2473
2495
  name: "divider",
2474
2496
  scope: "embed",
2497
+ blockLevel: true,
2475
2498
  normalize(value) {
2476
2499
  return !!value;
2477
2500
  },
@@ -3093,6 +3116,26 @@ function resolveDocumentPresentation(presentation) {
3093
3116
  listBlockIndentCm
3094
3117
  };
3095
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
+ }
3096
3139
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
3097
3140
  function documentPresentationListWrapperStyleParts(resolved) {
3098
3141
  if (!resolved?.listBlockIndentCm) return [];
@@ -3278,7 +3321,9 @@ function deltaToHtml(delta, options = {}) {
3278
3321
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
3279
3322
  const blockHandlers = options.blockHandlers;
3280
3323
  const anchorLinks = options.anchorLinks ?? false;
3281
- const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
3324
+ const resolvedDocumentPresentation = resolveDocumentPresentation(
3325
+ options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
3326
+ );
3282
3327
  let html = "";
3283
3328
  let listStack = [];
3284
3329
  let counters = [];
@@ -3916,7 +3961,13 @@ function htmlToDelta(html, options = {}) {
3916
3961
  if (format.match) {
3917
3962
  const result = format.match(node);
3918
3963
  if (result != null) {
3964
+ if (format.blockLevel && !atLineStart) {
3965
+ context.pushNewline();
3966
+ }
3919
3967
  context.pushEmbed({ [format.name]: result.value }, result.attributes);
3968
+ if (format.blockLevel) {
3969
+ context.pushNewline();
3970
+ }
3920
3971
  return;
3921
3972
  }
3922
3973
  }
@@ -3931,6 +3982,9 @@ function htmlToDelta(html, options = {}) {
3931
3982
  return;
3932
3983
  }
3933
3984
  if (tagName === "hr") {
3985
+ if (!atLineStart) {
3986
+ context.pushNewline();
3987
+ }
3934
3988
  context.pushEmbed({ divider: true });
3935
3989
  context.pushNewline();
3936
3990
  return;
@@ -6049,6 +6103,7 @@ export {
6049
6103
  deltaToHtml,
6050
6104
  deltaToMarkdown,
6051
6105
  dividerFormat,
6106
+ documentMetadataToPresentation,
6052
6107
  documentPresentationStyleParts,
6053
6108
  escapeHtml,
6054
6109
  extractBoxOpAttributes,