@sobree/core 0.1.14 → 0.1.15
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/doc/builders/block.d.ts +8 -0
- package/dist/doc/{builders.d.ts → builders/document.d.ts} +1 -12
- package/dist/doc/builders/index.d.ts +25 -0
- package/dist/doc/builders/inline.d.ts +38 -0
- package/dist/doc/builders/style.d.ts +7 -0
- package/dist/doc/builders/table.d.ts +20 -0
- package/dist/doc/formatting.types.d.ts +9 -49
- package/dist/doc/tableStyle.types.d.ts +43 -0
- package/dist/doc/types.d.ts +4 -2
- package/dist/index.js +2729 -2638
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InlineRun, Paragraph, ParagraphProperties, SectionBreak } from '../types';
|
|
2
|
+
/** A paragraph with the given runs and properties (both optional). */
|
|
3
|
+
export declare function paragraph(runs?: InlineRun[], properties?: ParagraphProperties): Paragraph;
|
|
4
|
+
/** Heading paragraph (`Heading{level}` style, level clamped to 1..6). */
|
|
5
|
+
export declare function heading(level: number, runs?: InlineRun[], properties?: ParagraphProperties): Paragraph;
|
|
6
|
+
/** A section break that switches to `toSectionIndex` in the document's
|
|
7
|
+
* `sections` array for the content that follows. */
|
|
8
|
+
export declare function sectionBreak(toSectionIndex: number): SectionBreak;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import { Block, HeaderFooterRef,
|
|
1
|
+
import { Block, HeaderFooterRef, NamedStyle, PageMargins, PageSize, Paragraph, SectionProperties, SobreeDocument, Table } from '../types';
|
|
2
2
|
/** A new, blank document with an A4 portrait section and the standard styles. */
|
|
3
3
|
export declare function emptyDocument(): SobreeDocument;
|
|
4
4
|
export declare function defaultSection(): SectionProperties;
|
|
5
5
|
export declare function defaultPageSize(): PageSize;
|
|
6
6
|
export declare function defaultMargins(): PageMargins;
|
|
7
|
-
/** A paragraph with no runs and no properties beyond the defaults. */
|
|
8
|
-
export declare function paragraph(runs?: InlineRun[], properties?: ParagraphProperties): Paragraph;
|
|
9
|
-
/** Heading paragraph (`Heading{level}` style, level clamped to 1..6). */
|
|
10
|
-
export declare function heading(level: number, runs?: InlineRun[], extra?: ParagraphProperties): Paragraph;
|
|
11
|
-
/** Plain text run with optional formatting. */
|
|
12
|
-
export declare function text(value: string, properties?: RunProperties): TextRun;
|
|
13
|
-
/** Convenience: emphasised (bold + italic) text run. */
|
|
14
|
-
export declare function emphasis(value: string, properties?: RunProperties): TextRun;
|
|
15
|
-
export declare function strong(value: string, properties?: RunProperties): TextRun;
|
|
16
|
-
export declare function softBreak(): InlineRun;
|
|
17
|
-
export declare function pageBreak(): InlineRun;
|
|
18
7
|
/** Default Word styles every doc declares so headings render correctly.
|
|
19
8
|
*
|
|
20
9
|
* Carries WORD-HARDCODED-DEFAULT typography — i.e. what Word uses
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructors for AST nodes. Two reasons these exist as helpers instead
|
|
3
|
+
* of object literals at every call site:
|
|
4
|
+
* 1. Defaults — A4 paper, an empty cell's placeholder paragraph, equal
|
|
5
|
+
* column widths — without sprinkling magic numbers into caller code.
|
|
6
|
+
* 2. Future schema migration — when a new required field is added, all
|
|
7
|
+
* construction goes through here and the migration is one diff.
|
|
8
|
+
*
|
|
9
|
+
* Conventions across the layer:
|
|
10
|
+
* - The factory is named for the node it builds (`text`, `table`,
|
|
11
|
+
* `tableCell`, `hyperlink`, `sectionBreak`).
|
|
12
|
+
* - Required content is positional; optional formatting is a trailing
|
|
13
|
+
* `properties` argument (a leaf's `RunProperties`, a container's
|
|
14
|
+
* `*Properties`). Many-field nodes (`image`, `table`, `namedStyle`)
|
|
15
|
+
* take a single trailing options object instead.
|
|
16
|
+
* - Measurements keep their native OOXML unit, suffixed (`widthEmu`,
|
|
17
|
+
* `…Twips`), matching the AST.
|
|
18
|
+
*
|
|
19
|
+
* Organised by node category: document / block / inline / table / style.
|
|
20
|
+
*/
|
|
21
|
+
export { appendBlock, defaultMargins, defaultPageSize, defaultSection, defaultStyles, emptyDocument, isParagraph, isTable, makeHeaderFooterRef, } from './document';
|
|
22
|
+
export { heading, paragraph, sectionBreak } from './block';
|
|
23
|
+
export { columnBreak, commentRef, emphasis, field, footnoteRef, hyperlink, image, type ImageOptions, pageBreak, softBreak, strong, tab, text, } from './inline';
|
|
24
|
+
export { type CellProperties, type TableOptions, table, tableCell, tableRow } from './table';
|
|
25
|
+
export { type NamedStyleOptions, namedStyle } from './style';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BreakRun, CommentRefRun, DrawingRun, FieldRun, FootnoteRefRun, HyperlinkRun, InlineRun, RunProperties, TabRun, TextRun } from '../types';
|
|
2
|
+
/** Plain text run with optional formatting. */
|
|
3
|
+
export declare function text(value: string, properties?: RunProperties): TextRun;
|
|
4
|
+
/** Convenience: italic text run. */
|
|
5
|
+
export declare function emphasis(value: string, properties?: RunProperties): TextRun;
|
|
6
|
+
/** Convenience: bold text run. */
|
|
7
|
+
export declare function strong(value: string, properties?: RunProperties): TextRun;
|
|
8
|
+
/** Soft line break inside a paragraph (Shift-Enter). */
|
|
9
|
+
export declare function softBreak(): BreakRun;
|
|
10
|
+
/** Explicit page break. */
|
|
11
|
+
export declare function pageBreak(): BreakRun;
|
|
12
|
+
/** Column break (advances to the next column in a multi-column section). */
|
|
13
|
+
export declare function columnBreak(): BreakRun;
|
|
14
|
+
/** A tab character — advances to the next tab stop. */
|
|
15
|
+
export declare function tab(properties?: RunProperties): TabRun;
|
|
16
|
+
/** A hyperlink wrapping inline children. `href` is an external URL or an
|
|
17
|
+
* internal anchor id (`#bookmark`). */
|
|
18
|
+
export declare function hyperlink(href: string, children: InlineRun[], properties?: RunProperties): HyperlinkRun;
|
|
19
|
+
/** A field run (`PAGE`, `NUMPAGES`, `DATE`, …). `cached` is the preview
|
|
20
|
+
* text shown until a viewer recalculates the field. */
|
|
21
|
+
export declare function field(instruction: string, cached?: string, properties?: RunProperties): FieldRun;
|
|
22
|
+
/** Options for {@link image}. `partPath` references a binary in the
|
|
23
|
+
* document's `rawParts`; the caller is responsible for registering the
|
|
24
|
+
* bytes there (or use the editor's `insertImage`, which does both). */
|
|
25
|
+
export interface ImageOptions {
|
|
26
|
+
widthEmu: number;
|
|
27
|
+
heightEmu: number;
|
|
28
|
+
altText?: string;
|
|
29
|
+
/** Layout mode — defaults to `"inline"` (flows like a tall character). */
|
|
30
|
+
placement?: DrawingRun["placement"];
|
|
31
|
+
verticalAlign?: DrawingRun["verticalAlign"];
|
|
32
|
+
}
|
|
33
|
+
/** An image / drawing run referencing a part in `rawParts`. */
|
|
34
|
+
export declare function image(partPath: string, opts: ImageOptions): DrawingRun;
|
|
35
|
+
/** A footnote reference — `id` keys into `SobreeDocument.footnotes`. */
|
|
36
|
+
export declare function footnoteRef(id: number, properties?: RunProperties): FootnoteRefRun;
|
|
37
|
+
/** A comment reference — `id` keys into `SobreeDocument.comments`. */
|
|
38
|
+
export declare function commentRef(id: number, properties?: RunProperties): CommentRefRun;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NamedStyle } from '../types';
|
|
2
|
+
/** Everything on {@link NamedStyle} except `id` (the positional argument);
|
|
3
|
+
* `type` defaults to `"paragraph"` and `displayName` to the id. */
|
|
4
|
+
export type NamedStyleOptions = Partial<Omit<NamedStyle, "id">>;
|
|
5
|
+
/** A named style. `id` is required; `type` defaults to `"paragraph"` and
|
|
6
|
+
* `displayName` to `id` when not given. */
|
|
7
|
+
export declare function namedStyle(id: string, options?: NamedStyleOptions): NamedStyle;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Block, Table, TableCell, TableProperties, TableRow } from '../types';
|
|
2
|
+
/** A cell's properties — everything on {@link TableCell} except `content`
|
|
3
|
+
* (which is the positional argument). */
|
|
4
|
+
export type CellProperties = Partial<Omit<TableCell, "content">>;
|
|
5
|
+
/** A table cell. `content` defaults to a single empty paragraph (Word
|
|
6
|
+
* requires every cell to hold at least one paragraph). */
|
|
7
|
+
export declare function tableCell(content?: Block[], properties?: CellProperties): TableCell;
|
|
8
|
+
/** A table row. */
|
|
9
|
+
export declare function tableRow(cells: TableCell[], opts?: {
|
|
10
|
+
isHeader?: boolean;
|
|
11
|
+
}): TableRow;
|
|
12
|
+
export interface TableOptions {
|
|
13
|
+
/** Column widths in twips (length = column count). Derived as equal
|
|
14
|
+
* columns from {@link DEFAULT_TABLE_WIDTH_TWIPS} when omitted. */
|
|
15
|
+
grid?: number[];
|
|
16
|
+
properties?: TableProperties;
|
|
17
|
+
}
|
|
18
|
+
/** A table. The column `grid` is taken from `opts.grid`, else derived as
|
|
19
|
+
* equal-width columns from the widest row's column count. */
|
|
20
|
+
export declare function table(rows: TableRow[], opts?: TableOptions): Table;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* formatting.
|
|
2
|
+
* Visual formatting primitives: borders, shading, and cell spacing.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* every AST type from `./types`.
|
|
4
|
+
* Low-level value-types shared across the AST — paragraphs, runs, and
|
|
5
|
+
* tables all paint with these. A dependency-free LEAF: none reference the
|
|
6
|
+
* recursive `Block` document graph, so keeping them here (out of
|
|
7
|
+
* `types.ts`) avoids a circular dependency. `types.ts` imports +
|
|
8
|
+
* re-exports them, so consumers still get every AST type from `./types`.
|
|
10
9
|
*/
|
|
11
10
|
export interface BorderSpec {
|
|
12
11
|
style: "single" | "double" | "dashed" | "dotted" | "thick" | "none";
|
|
@@ -25,6 +24,8 @@ export interface Shading {
|
|
|
25
24
|
/** Pattern foreground `#rrggbb` or `auto`. */
|
|
26
25
|
color?: string;
|
|
27
26
|
}
|
|
27
|
+
/** A table's outer edges plus the inside-horizontal / inside-vertical
|
|
28
|
+
* separators (`<w:tblBorders>`). */
|
|
28
29
|
export interface TableBorders {
|
|
29
30
|
top?: BorderSpec;
|
|
30
31
|
right?: BorderSpec;
|
|
@@ -33,6 +34,7 @@ export interface TableBorders {
|
|
|
33
34
|
insideH?: BorderSpec;
|
|
34
35
|
insideV?: BorderSpec;
|
|
35
36
|
}
|
|
37
|
+
/** A single cell's four edges (`<w:tcBorders>`). */
|
|
36
38
|
export interface TableCellBorders {
|
|
37
39
|
top?: BorderSpec;
|
|
38
40
|
right?: BorderSpec;
|
|
@@ -47,45 +49,3 @@ export interface TableCellMargins {
|
|
|
47
49
|
bottomTwips?: number;
|
|
48
50
|
leftTwips?: number;
|
|
49
51
|
}
|
|
50
|
-
/** `<w:tblLook>` flags. A flag absent ⇒ that conditional format is OFF. */
|
|
51
|
-
export interface TableLook {
|
|
52
|
-
firstRow?: boolean;
|
|
53
|
-
lastRow?: boolean;
|
|
54
|
-
firstColumn?: boolean;
|
|
55
|
-
lastColumn?: boolean;
|
|
56
|
-
/** Row (horizontal) banding active. */
|
|
57
|
-
hBand?: boolean;
|
|
58
|
-
/** Column (vertical) banding active. */
|
|
59
|
-
vBand?: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* A table style's conditional-format regions (`<w:tblStylePr w:type>`).
|
|
63
|
-
* Each names a slice of the table whose cells get extra formatting when
|
|
64
|
-
* the table's `<w:tblLook>` enables it. Resolution precedence (low→high,
|
|
65
|
-
* ECMA-376 §17.7.6): wholeTable → vBands → hBands → first/last column →
|
|
66
|
-
* first/last row → corner cells, then direct cell formatting wins.
|
|
67
|
-
*/
|
|
68
|
-
export type TableConditionalType = "firstRow" | "lastRow" | "firstCol" | "lastCol" | "band1Horz" | "band2Horz" | "band1Vert" | "band2Vert" | "nwCell" | "neCell" | "swCell" | "seCell";
|
|
69
|
-
/** The formatting one region (or the whole-table base) contributes. */
|
|
70
|
-
export interface TableStyleCellFormat {
|
|
71
|
-
shading?: Shading;
|
|
72
|
-
borders?: TableCellBorders;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* A `<w:style w:type="table">` definition: whole-table base formatting +
|
|
76
|
-
* per-region conditional formatting + band sizes. Resolved per cell at
|
|
77
|
-
* render time against the table's `look`.
|
|
78
|
-
*/
|
|
79
|
-
export interface TableStyleDefinition {
|
|
80
|
-
/** Whole-table borders (`<w:tblBorders>` — incl. `insideH`/`insideV`). */
|
|
81
|
-
borders?: TableBorders;
|
|
82
|
-
/** Whole-table base cell shading. */
|
|
83
|
-
shading?: Shading;
|
|
84
|
-
/** Rows per horizontal band (`<w:tblStyleRowBandSize>`, default 1). */
|
|
85
|
-
rowBandSize?: number;
|
|
86
|
-
/** Columns per vertical band (`<w:tblStyleColBandSize>`, default 1). */
|
|
87
|
-
colBandSize?: number;
|
|
88
|
-
/** Whole-table default cell padding (`<w:tblCellMar>` in the style). */
|
|
89
|
-
cellMargins?: TableCellMargins;
|
|
90
|
-
conditional?: Partial<Record<TableConditionalType, TableStyleCellFormat>>;
|
|
91
|
-
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Shading, TableBorders, TableCellBorders, TableCellMargins } from './formatting.types';
|
|
2
|
+
/** `<w:tblLook>` flags. A flag absent ⇒ that conditional format is OFF. */
|
|
3
|
+
export interface TableLook {
|
|
4
|
+
firstRow?: boolean;
|
|
5
|
+
lastRow?: boolean;
|
|
6
|
+
firstColumn?: boolean;
|
|
7
|
+
lastColumn?: boolean;
|
|
8
|
+
/** Row (horizontal) banding active. */
|
|
9
|
+
hBand?: boolean;
|
|
10
|
+
/** Column (vertical) banding active. */
|
|
11
|
+
vBand?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A table style's conditional-format regions (`<w:tblStylePr w:type>`).
|
|
15
|
+
* Each names a slice of the table whose cells get extra formatting when
|
|
16
|
+
* the table's `<w:tblLook>` enables it. Resolution precedence (low→high,
|
|
17
|
+
* ECMA-376 §17.7.6): wholeTable → vBands → hBands → first/last column →
|
|
18
|
+
* first/last row → corner cells, then direct cell formatting wins.
|
|
19
|
+
*/
|
|
20
|
+
export type TableConditionalType = "firstRow" | "lastRow" | "firstCol" | "lastCol" | "band1Horz" | "band2Horz" | "band1Vert" | "band2Vert" | "nwCell" | "neCell" | "swCell" | "seCell";
|
|
21
|
+
/** The formatting one region (or the whole-table base) contributes. */
|
|
22
|
+
export interface TableStyleCellFormat {
|
|
23
|
+
shading?: Shading;
|
|
24
|
+
borders?: TableCellBorders;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A `<w:style w:type="table">` definition: whole-table base formatting +
|
|
28
|
+
* per-region conditional formatting + band sizes. Resolved per cell at
|
|
29
|
+
* render time against the table's `look`.
|
|
30
|
+
*/
|
|
31
|
+
export interface TableStyleDefinition {
|
|
32
|
+
/** Whole-table borders (`<w:tblBorders>` — incl. `insideH`/`insideV`). */
|
|
33
|
+
borders?: TableBorders;
|
|
34
|
+
/** Whole-table base cell shading. */
|
|
35
|
+
shading?: Shading;
|
|
36
|
+
/** Rows per horizontal band (`<w:tblStyleRowBandSize>`, default 1). */
|
|
37
|
+
rowBandSize?: number;
|
|
38
|
+
/** Columns per vertical band (`<w:tblStyleColBandSize>`, default 1). */
|
|
39
|
+
colBandSize?: number;
|
|
40
|
+
/** Whole-table default cell padding (`<w:tblCellMar>` in the style). */
|
|
41
|
+
cellMargins?: TableCellMargins;
|
|
42
|
+
conditional?: Partial<Record<TableConditionalType, TableStyleCellFormat>>;
|
|
43
|
+
}
|
package/dist/doc/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { BorderSpec, Shading, TableBorders, TableCellBorders, TableCellMargins
|
|
1
|
+
import { BorderSpec, Shading, TableBorders, TableCellBorders, TableCellMargins } from './formatting.types';
|
|
2
|
+
import { TableLook, TableStyleDefinition } from './tableStyle.types';
|
|
2
3
|
import { FontDeclaration as _FontDeclaration } from '../fonts/types';
|
|
3
|
-
export type { BorderSpec, Shading, TableBorders, TableCellBorders, TableCellMargins,
|
|
4
|
+
export type { BorderSpec, Shading, TableBorders, TableCellBorders, TableCellMargins, } from './formatting.types';
|
|
5
|
+
export type { TableConditionalType, TableLook, TableStyleCellFormat, TableStyleDefinition, } from './tableStyle.types';
|
|
4
6
|
export interface SobreeDocument {
|
|
5
7
|
/** Top-level body content, in document order. */
|
|
6
8
|
body: Block[];
|