@docx4j/core-ts 0.3.1 → 0.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/README.md +3 -1
- package/dist/html/convert.d.mts +116 -0
- package/dist/html/convert.mjs +541 -0
- package/dist/html/elements.d.mts +19 -0
- package/dist/html/elements.mjs +182 -0
- package/dist/html/index.d.mts +2 -0
- package/dist/html/index.mjs +4 -0
- package/dist/model/content/Body.mjs +9 -1
- package/dist/model/content/ContentControl.d.mts +5 -1
- package/dist/model/content/ContentControl.mjs +18 -5
- package/dist/model/content/InlinePicture.d.mts +18 -3
- package/dist/model/content/InlinePicture.mjs +44 -7
- package/dist/model/content/Paragraph.d.mts +11 -11
- package/dist/model/content/Paragraph.mjs +30 -43
- package/dist/model/content/Range.mjs +3 -2
- package/dist/model/content/Table.d.mts +38 -0
- package/dist/model/content/Table.mjs +80 -2
- package/dist/model/content/index.d.mts +2 -1
- package/dist/model/content/index.mjs +2 -1
- package/dist/model/content/stylesFacade.d.mts +4 -2
- package/dist/model/content/stylesFacade.mjs +23 -6
- package/dist/model/content/tableColumns.d.mts +48 -0
- package/dist/model/content/tableColumns.mjs +484 -0
- package/dist/model/content/tracking.d.mts +14 -0
- package/dist/model/content/tracking.mjs +19 -10
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +6 -1
- package/dist/model/customxml/CustomXmlPartCollection.mjs +19 -3
- package/dist/model/customxml/XmlMapping.d.mts +20 -4
- package/dist/model/customxml/XmlMapping.mjs +44 -6
- package/dist/model/customxml/bindings.d.mts +13 -3
- package/dist/model/customxml/bindings.mjs +38 -7
- package/dist/model/customxml/index.d.mts +4 -1
- package/dist/model/customxml/index.mjs +4 -1
- package/dist/model/customxml/insert.d.mts +10 -0
- package/dist/model/customxml/insert.mjs +13 -0
- package/dist/model/customxml/opendope.d.mts +32 -0
- package/dist/model/customxml/opendope.mjs +56 -0
- package/dist/model/customxml/pictures.d.mts +54 -0
- package/dist/model/customxml/pictures.mjs +186 -0
- package/dist/model/customxml/xhtml.d.mts +42 -0
- package/dist/model/customxml/xhtml.mjs +162 -0
- package/dist/model/fonts/RunFontSelector.d.mts +8 -1
- package/dist/model/fonts/RunFontSelector.mjs +6 -5
- package/dist/model/properties/PropertyResolver.d.mts +110 -10
- package/dist/model/properties/PropertyResolver.mjs +300 -31
- package/dist/model/properties/index.d.mts +3 -0
- package/dist/model/properties/index.mjs +2 -0
- package/dist/model/properties/table.d.mts +155 -0
- package/dist/model/properties/table.mjs +315 -0
- package/dist/model/properties/tableStyleConditions.d.mts +101 -0
- package/dist/model/properties/tableStyleConditions.mjs +296 -0
- package/dist/packages/WordprocessingMLPackage.mjs +1 -0
- package/dist/parts/wml/knownStyles.d.mts +1 -0
- package/dist/parts/wml/knownStyles.mjs +2233 -0
- package/dist/parts/wml/placeholderStyle.d.mts +3 -0
- package/dist/parts/wml/placeholderStyle.mjs +13 -0
- package/package.json +7 -2
|
@@ -6,7 +6,7 @@ import { ContentControl } from './ContentControl.mjs';
|
|
|
6
6
|
import { sdt as sdtOf, nextSdtId, applyRunOptions, t as textElement } from '@docx4j/generated-objects-ts/builders/wml';
|
|
7
7
|
import { hyperlink as hyperlinkOf } from '@docx4j/generated-objects-ts/el/org_docx4j_wml';
|
|
8
8
|
import { Namespaces } from '../../parts/Namespaces.mjs';
|
|
9
|
-
import { controlIdScope, sdtKindFor } from '../customxml/insert.mjs';
|
|
9
|
+
import { controlIdScope, sdtKindFor, declareSdtExtensions } from '../customxml/insert.mjs';
|
|
10
10
|
import { contentOf } from './ooxml.mjs';
|
|
11
11
|
import { markHolderInserted } from './tracking.mjs';
|
|
12
12
|
import { searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
|
|
@@ -74,7 +74,7 @@ export class Range {
|
|
|
74
74
|
};
|
|
75
75
|
if ((options === null || options === void 0 ? void 0 : options.direct) === true)
|
|
76
76
|
return new Font(holders, () => this.paragraph.fontTracking());
|
|
77
|
-
return new Font(holders, () => this.paragraph.fontTracking(), (rPr) => this.paragraph.parentBody.propertyResolver.getEffectiveRPr(rPr, this.paragraph.p.pPr), (rPr) => { var _a; return (_a = runFontSelectorOf(this.paragraph.parentBody.package_)) === null || _a === void 0 ? void 0 : _a.asciiFontName(rPr); });
|
|
77
|
+
return new Font(holders, () => this.paragraph.fontTracking(), (rPr) => this.paragraph.parentBody.propertyResolver.getEffectiveRPr(rPr, this.paragraph.p.pPr, this.paragraph.cellContext), (rPr) => { var _a; return (_a = runFontSelectorOf(this.paragraph.parentBody.package_)) === null || _a === void 0 ? void 0 : _a.asciiFontName(rPr); });
|
|
78
78
|
}
|
|
79
79
|
/** The runs the span covers (a run partly inside counts). */
|
|
80
80
|
get runs() {
|
|
@@ -215,6 +215,7 @@ export class Range {
|
|
|
215
215
|
// The control is built empty first: `sdt` refuses a kind that cannot be run-level (a repeating
|
|
216
216
|
// section), and that refusal must come before any run is split.
|
|
217
217
|
const sdt = sdtOf([], { kind: sdtKindFor(kind), id: nextSdtId(controlIdScope(body)), form: 'run' });
|
|
218
|
+
declareSdtExtensions(body, sdt);
|
|
218
219
|
if (this.start === this.end) {
|
|
219
220
|
paragraph.insertItemsAt(this.start, [sdt]);
|
|
220
221
|
return new ContentControl(sdt, containerOf(sdt, paragraph), body);
|
|
@@ -4,6 +4,7 @@ import type { Body } from './Body.mjs';
|
|
|
4
4
|
import type { Paragraph } from './Paragraph.mjs';
|
|
5
5
|
import type { Range } from './Range.mjs';
|
|
6
6
|
import { type ChangeTracker } from './tracking.mjs';
|
|
7
|
+
import { type TableLayoutMode } from './tableColumns.mjs';
|
|
7
8
|
/**
|
|
8
9
|
* A subset of Office JS `Word.Table` over a `w:tbl`. Rows are read through row-level content
|
|
9
10
|
* controls (an OpenDoPE repeat wraps its `w:tr` in a `w:sdt`), so `rows` is what Word shows.
|
|
@@ -51,6 +52,30 @@ export declare class Table {
|
|
|
51
52
|
* tracks changes the rows stay and take a `w:trPr/w:del` instead (CR-002 phase F).
|
|
52
53
|
*/
|
|
53
54
|
deleteRows(rowIndex: number, rowCount?: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Adds columns at the start or the end (Office JS `Table.addColumns`), the new cells taking the
|
|
57
|
+
* properties and width of the column beside them - the one to the right of the boundary when
|
|
58
|
+
* there is one, else the left - in the table's layout mode as Word 365 writes it (CR-002 section
|
|
59
|
+
* 42, checks 39 and 40): fixed copies the width and grows the table past the margin, AutoFit to
|
|
60
|
+
* window rescales the grid and writes the cells' percentages again, AutoFit to contents stays
|
|
61
|
+
* automatic. `values` is by row, then by new column. Returns the new cells per row, an extension
|
|
62
|
+
* (Office JS returns nothing); a row whose skipped columns grew instead has none. Tracked, the
|
|
63
|
+
* table change is recorded as Office JS records one and the new cells' text is an insertion.
|
|
64
|
+
*/
|
|
65
|
+
addColumns(location: 'Start' | 'End', columnCount: number, values?: string[][]): TableCell[][];
|
|
66
|
+
/**
|
|
67
|
+
* Removes `columnCount` grid columns from `columnIndex` (one by default; Office JS
|
|
68
|
+
* `Table.deleteColumns`): a cell covering only those columns goes, one spanning further shrinks.
|
|
69
|
+
* Tracked, the cells still go and the table change is recorded, as Office JS's deletion leaves
|
|
70
|
+
* it (section 42.3; check 40c; Word's own is not tracked at all, known issues entry 2).
|
|
71
|
+
*/
|
|
72
|
+
deleteColumns(columnIndex: number, columnCount?: number): void;
|
|
73
|
+
/** Which of Word's three layout modes the table is in: fixed, AutoFit to window, or AutoFit to contents (extension). */
|
|
74
|
+
get layoutMode(): TableLayoutMode;
|
|
75
|
+
/** The section's text width in twips, for the window mode and a percentage width. */
|
|
76
|
+
textWidth(): number;
|
|
77
|
+
/** Views of new cells, row by row. */
|
|
78
|
+
cellViewsOf(cells: Element<wml.Tc>[][]): TableCell[][];
|
|
54
79
|
/** Removes the table from its container; tracked, every row is marked deleted instead. */
|
|
55
80
|
delete(): void;
|
|
56
81
|
/** The package's change tracker while `changeTrackingMode` is on (CR-002 phase F). */
|
|
@@ -118,7 +143,20 @@ export declare class TableCell {
|
|
|
118
143
|
insertText(text: string, location: 'Start' | 'End' | 'Replace'): Range;
|
|
119
144
|
/** The cell width in points (w:tcW in twips), as Office JS reports it; 0 when it is not a fixed width. */
|
|
120
145
|
get width(): number;
|
|
146
|
+
/**
|
|
147
|
+
* Written in the form the cell states, else its table, else twips (CR-002 section 42.2 item 4): a
|
|
148
|
+
* cell in percent takes the points as a share of the section's text width; `auto` becomes twips,
|
|
149
|
+
* a stated width being what was asked for.
|
|
150
|
+
*/
|
|
121
151
|
set width(points: number);
|
|
152
|
+
/**
|
|
153
|
+
* New columns before or after this cell (Office JS `TableCell.insertColumns`), the new cells
|
|
154
|
+
* taking this cell's properties and width, as `Table.addColumns` does. Returns the new cells per
|
|
155
|
+
* row (extension).
|
|
156
|
+
*/
|
|
157
|
+
insertColumns(location: 'Before' | 'After', columnCount: number, values?: string[][]): TableCell[][];
|
|
158
|
+
/** Removes the grid columns this cell covers (Office JS `TableCell.deleteColumn`); tracked as `Table.deleteColumns` is. */
|
|
159
|
+
deleteColumn(): void;
|
|
122
160
|
/** Office JS TableCell.columnWidth, the same value. */
|
|
123
161
|
get columnWidth(): number;
|
|
124
162
|
set columnWidth(points: number);
|
|
@@ -4,6 +4,7 @@ import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
|
4
4
|
import { typeNameOf, childrenOf, linkParents, textOf, rowsOf, cellsOf } from './tree.mjs';
|
|
5
5
|
import { builtInOf, idOfBuiltIn, styleNameOf, styleIdOf } from './styles.mjs';
|
|
6
6
|
import { trackInsertedBlocks } from './tracking.mjs';
|
|
7
|
+
import { insertGridColumns, deleteGridColumns, gridRangeOf, textWidthTwips, widthTypeOf, layoutModeOf } from './tableColumns.mjs';
|
|
7
8
|
/** The default table width in twips (A4 with 2.54 cm margins), as the objects package's `tbl` builder uses. */
|
|
8
9
|
const DEFAULT_WIDTH = 9026;
|
|
9
10
|
const TWIPS_PER_POINT = 20;
|
|
@@ -128,6 +129,51 @@ export class Table {
|
|
|
128
129
|
row.container.splice(i, 1);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Adds columns at the start or the end (Office JS `Table.addColumns`), the new cells taking the
|
|
134
|
+
* properties and width of the column beside them - the one to the right of the boundary when
|
|
135
|
+
* there is one, else the left - in the table's layout mode as Word 365 writes it (CR-002 section
|
|
136
|
+
* 42, checks 39 and 40): fixed copies the width and grows the table past the margin, AutoFit to
|
|
137
|
+
* window rescales the grid and writes the cells' percentages again, AutoFit to contents stays
|
|
138
|
+
* automatic. `values` is by row, then by new column. Returns the new cells per row, an extension
|
|
139
|
+
* (Office JS returns nothing); a row whose skipped columns grew instead has none. Tracked, the
|
|
140
|
+
* table change is recorded as Office JS records one and the new cells' text is an insertion.
|
|
141
|
+
*/
|
|
142
|
+
addColumns(location, columnCount, values) {
|
|
143
|
+
const at = location === 'Start' ? 0 : this.columnWidths().length;
|
|
144
|
+
const inserted = insertGridColumns(this.tbl, this.textWidth(), at, columnCount, values, this.changeTracker);
|
|
145
|
+
return this.cellViewsOf(inserted.cells);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Removes `columnCount` grid columns from `columnIndex` (one by default; Office JS
|
|
149
|
+
* `Table.deleteColumns`): a cell covering only those columns goes, one spanning further shrinks.
|
|
150
|
+
* Tracked, the cells still go and the table change is recorded, as Office JS's deletion leaves
|
|
151
|
+
* it (section 42.3; check 40c; Word's own is not tracked at all, known issues entry 2).
|
|
152
|
+
*/
|
|
153
|
+
deleteColumns(columnIndex, columnCount = 1) {
|
|
154
|
+
var _a, _b, _c;
|
|
155
|
+
deleteGridColumns(this.tbl, this.textWidth(), columnIndex, columnCount, this.changeTracker);
|
|
156
|
+
if (((_c = (_b = (_a = this.tbl.tblGrid) === null || _a === void 0 ? void 0 : _a.gridCol) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) === 0 || rowsOf(this.tbl).every((row) => cellsOf(row.element.value).length === 0))
|
|
157
|
+
this.delete();
|
|
158
|
+
}
|
|
159
|
+
/** Which of Word's three layout modes the table is in: fixed, AutoFit to window, or AutoFit to contents (extension). */
|
|
160
|
+
get layoutMode() {
|
|
161
|
+
return layoutModeOf(this.tbl);
|
|
162
|
+
}
|
|
163
|
+
/** The section's text width in twips, for the window mode and a percentage width. */
|
|
164
|
+
textWidth() {
|
|
165
|
+
return textWidthTwips(this.parentBody.container);
|
|
166
|
+
}
|
|
167
|
+
/** Views of new cells, row by row. */
|
|
168
|
+
cellViewsOf(cells) {
|
|
169
|
+
const rows = this.rows;
|
|
170
|
+
return cells.map((rowCells, i) => {
|
|
171
|
+
const row = rows[i];
|
|
172
|
+
if (!row || rowCells.length === 0)
|
|
173
|
+
return [];
|
|
174
|
+
return row.cells.filter((cell) => rowCells.includes(cell.element));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
131
177
|
/** Removes the table from its container; tracked, every row is marked deleted instead. */
|
|
132
178
|
delete() {
|
|
133
179
|
const tracker = this.changeTracker;
|
|
@@ -311,12 +357,44 @@ export class TableCell {
|
|
|
311
357
|
const w = (_a = this.tc.tcPr) === null || _a === void 0 ? void 0 : _a.tcW;
|
|
312
358
|
return (w === null || w === void 0 ? void 0 : w.type) === 'dxa' ? ((_b = w.w) !== null && _b !== void 0 ? _b : 0) / TWIPS_PER_POINT : 0;
|
|
313
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Written in the form the cell states, else its table, else twips (CR-002 section 42.2 item 4): a
|
|
362
|
+
* cell in percent takes the points as a share of the section's text width; `auto` becomes twips,
|
|
363
|
+
* a stated width being what was asked for.
|
|
364
|
+
*/
|
|
314
365
|
set width(points) {
|
|
315
366
|
var _a, _b;
|
|
316
367
|
var _c, _d;
|
|
368
|
+
const twips = Math.round(points * TWIPS_PER_POINT);
|
|
317
369
|
const tcW = ((_b = (_d = ((_a = (_c = this.tc).tcPr) !== null && _a !== void 0 ? _a : (_c.tcPr = {}))).tcW) !== null && _b !== void 0 ? _b : (_d.tcW = {}));
|
|
318
|
-
|
|
319
|
-
|
|
370
|
+
if (widthTypeOf(this.tc, this.parentTable.tbl) === 'pct') {
|
|
371
|
+
tcW.w = Math.round((twips * 5000) / this.parentTable.textWidth());
|
|
372
|
+
tcW.type = 'pct';
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
tcW.w = twips;
|
|
376
|
+
tcW.type = 'dxa';
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* New columns before or after this cell (Office JS `TableCell.insertColumns`), the new cells
|
|
381
|
+
* taking this cell's properties and width, as `Table.addColumns` does. Returns the new cells per
|
|
382
|
+
* row (extension).
|
|
383
|
+
*/
|
|
384
|
+
insertColumns(location, columnCount, values) {
|
|
385
|
+
const range = gridRangeOf(this.parentRow.tr, this.tc);
|
|
386
|
+
if (!range)
|
|
387
|
+
throw new Docx4JException('This cell is not in its row');
|
|
388
|
+
const table = this.parentTable;
|
|
389
|
+
const inserted = insertGridColumns(table.tbl, table.textWidth(), location === 'Before' ? range.start : range.end, columnCount, values, table.changeTracker);
|
|
390
|
+
return table.cellViewsOf(inserted.cells);
|
|
391
|
+
}
|
|
392
|
+
/** Removes the grid columns this cell covers (Office JS `TableCell.deleteColumn`); tracked as `Table.deleteColumns` is. */
|
|
393
|
+
deleteColumn() {
|
|
394
|
+
const range = gridRangeOf(this.parentRow.tr, this.tc);
|
|
395
|
+
if (!range)
|
|
396
|
+
throw new Docx4JException('This cell is not in its row');
|
|
397
|
+
this.parentTable.deleteColumns(range.start, range.end - range.start);
|
|
320
398
|
}
|
|
321
399
|
/** Office JS TableCell.columnWidth, the same value. */
|
|
322
400
|
get columnWidth() {
|
|
@@ -7,7 +7,8 @@ export { List, ListItem, ListItemNotFoundError, NumberingFacade, listsOf, listLa
|
|
|
7
7
|
export { type Author, type CommentContent, type CommentOptions, type CommentEntry, type CommentParts, type CommentPartsAccess, type CommentsExtensible, type CommentMarker, COMMENT_TEXT_STYLE, COMMENT_REFERENCE_STYLE, markersOf, markersOfParagraph, commentIdsOf } from './comments.mjs';
|
|
8
8
|
export { Font, type UnderlineType, type RPrHolder, type FontTracking } from './Font.mjs';
|
|
9
9
|
export { Table, TableRow, TableCell, cellOf } from './Table.mjs';
|
|
10
|
-
export {
|
|
10
|
+
export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf, type TableLayoutMode, type ColumnInsertion } from './tableColumns.mjs';
|
|
11
|
+
export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu, type ImageFormat, type ImageInfo, type InlinePictureOptions, type NewPicture, type NewImagePart } from './InlinePicture.mjs';
|
|
11
12
|
export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS, type ContentControlType, type ContentControlForm, type ContentControlAppearance } from './ContentControl.mjs';
|
|
12
13
|
export { contentOf, isFlatOpc, rewriteRelationshipIds, type OoxmlOptions } from './ooxml.mjs';
|
|
13
14
|
export { type SearchOptions, searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
|
|
@@ -9,7 +9,8 @@ export { List, ListItem, ListItemNotFoundError, NumberingFacade, listsOf, listLa
|
|
|
9
9
|
export { COMMENT_TEXT_STYLE, COMMENT_REFERENCE_STYLE, markersOf, markersOfParagraph, commentIdsOf } from './comments.mjs';
|
|
10
10
|
export { Font } from './Font.mjs';
|
|
11
11
|
export { Table, TableRow, TableCell, cellOf } from './Table.mjs';
|
|
12
|
-
export {
|
|
12
|
+
export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf } from './tableColumns.mjs';
|
|
13
|
+
export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu } from './InlinePicture.mjs';
|
|
13
14
|
export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS } from './ContentControl.mjs';
|
|
14
15
|
export { contentOf, isFlatOpc, rewriteRelationshipIds } from './ooxml.mjs';
|
|
15
16
|
export { searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
|
|
@@ -23,8 +23,10 @@ export declare class StylesFacade {
|
|
|
23
23
|
*
|
|
24
24
|
* A style already in the document is left exactly as it is - the document's own definition wins
|
|
25
25
|
* over the default, always, since a consumer must not silently restyle a document it was asked to
|
|
26
|
-
* add a footnote to. An id
|
|
27
|
-
*
|
|
26
|
+
* add a footnote to. An id none of the sources carry - the defaults, the nine spliceable styles,
|
|
27
|
+
* the comment and placeholder styles, and Word's built-ins from docx4j's `KnownStyles.xml`
|
|
28
|
+
* (section 41) - throws a `Docx4JException` naming it: the caller asked for a definition nothing
|
|
29
|
+
* here has, and inventing one would be worse than saying so.
|
|
28
30
|
* The whole closure is worked out before anything is written, so a call that throws has changed
|
|
29
31
|
* nothing (CR-002 section 31).
|
|
30
32
|
*
|
|
@@ -4,12 +4,17 @@ import { parseXml } from '../../xml/dom.mjs';
|
|
|
4
4
|
import { DEFAULT_STYLES_XML } from '../../parts/wml/defaultStyles.mjs';
|
|
5
5
|
import { SPLICEABLE_STYLES_XML } from '../../parts/wml/spliceableStyles.mjs';
|
|
6
6
|
import { commentStyles } from '../../parts/wml/commentStyles.mjs';
|
|
7
|
+
import { placeholderStyle } from '../../parts/wml/placeholderStyle.mjs';
|
|
8
|
+
import { KNOWN_STYLES_XML } from '../../parts/wml/knownStyles.mjs';
|
|
7
9
|
import { Docx4JException } from '../../opc/exceptions.mjs';
|
|
8
10
|
/**
|
|
9
11
|
* Where a definition is looked up, unmarshalled once and never handed out (a copy is spliced in):
|
|
10
12
|
* the defaults `createPackage()` writes, and then the nine styles docx4j's own `styles.xml` carries
|
|
11
13
|
* **commented out** - which is why a created document has no `FootnoteText` although the file
|
|
12
|
-
* appears to contain one, and why this facade exists (CR-002 section 22.2)
|
|
14
|
+
* appears to contain one, and why this facade exists (CR-002 section 22.2) - with Word's two comment
|
|
15
|
+
* styles and its `PlaceholderText` after them, and last Word's 164 built-ins as docx4j's
|
|
16
|
+
* `KnownStyles.xml` carries them (CR-002 section 41: `Heading5`, `Quote`, `HTMLCode`, ...), the
|
|
17
|
+
* list numbering some of them name dropped, since no numbering definition comes with them.
|
|
13
18
|
*/
|
|
14
19
|
let sources;
|
|
15
20
|
function styleSources() {
|
|
@@ -17,8 +22,18 @@ function styleSources() {
|
|
|
17
22
|
const read = async (xml) => { var _a; return (_a = (await unmarshalNode(parseXml(xml))).value.style) !== null && _a !== void 0 ? _a : []; };
|
|
18
23
|
const defaults = await read(DEFAULT_STYLES_XML);
|
|
19
24
|
// and Word's two comment styles, which the comment parts add when they are made, for a caller
|
|
20
|
-
// that makes the comment itself (CR-002 section 37)
|
|
21
|
-
|
|
25
|
+
// that makes the comment itself (CR-002 section 37), and Word's PlaceholderText, which a
|
|
26
|
+
// placeholder run names (CR-002 section 40); then the known styles (section 41), each without
|
|
27
|
+
// the w:numPr the file left on the headings and list styles: it names a w:numId of the document
|
|
28
|
+
// the file was taken from, which the document being spliced into need not have, and a heading
|
|
29
|
+
// spliced with it would join a list that is not there (the editor's copy drops it the same way)
|
|
30
|
+
const known = (await read(KNOWN_STYLES_XML)).map((style) => {
|
|
31
|
+
var _a;
|
|
32
|
+
if ((_a = style.pPr) === null || _a === void 0 ? void 0 : _a.numPr)
|
|
33
|
+
delete style.pPr.numPr;
|
|
34
|
+
return style;
|
|
35
|
+
});
|
|
36
|
+
return { defaults, all: [...defaults, ...(await read(SPLICEABLE_STYLES_XML)), ...commentStyles(), placeholderStyle(), ...known] };
|
|
22
37
|
})()));
|
|
23
38
|
}
|
|
24
39
|
/**
|
|
@@ -39,8 +54,10 @@ export class StylesFacade {
|
|
|
39
54
|
*
|
|
40
55
|
* A style already in the document is left exactly as it is - the document's own definition wins
|
|
41
56
|
* over the default, always, since a consumer must not silently restyle a document it was asked to
|
|
42
|
-
* add a footnote to. An id
|
|
43
|
-
*
|
|
57
|
+
* add a footnote to. An id none of the sources carry - the defaults, the nine spliceable styles,
|
|
58
|
+
* the comment and placeholder styles, and Word's built-ins from docx4j's `KnownStyles.xml`
|
|
59
|
+
* (section 41) - throws a `Docx4JException` naming it: the caller asked for a definition nothing
|
|
60
|
+
* here has, and inventing one would be worse than saying so.
|
|
44
61
|
* The whole closure is worked out before anything is written, so a call that throws has changed
|
|
45
62
|
* nothing (CR-002 section 31).
|
|
46
63
|
*
|
|
@@ -102,7 +119,7 @@ function closureOf(wanted, present, source) {
|
|
|
102
119
|
seen.add(id);
|
|
103
120
|
const template = source.find((s) => s.styleId === id);
|
|
104
121
|
if (template === undefined) {
|
|
105
|
-
throw new Docx4JException(`No definition to splice for the style ${id}: neither docx4j's default styles, the nine it comments out
|
|
122
|
+
throw new Docx4JException(`No definition to splice for the style ${id}: neither docx4j's default styles, the nine it comments out, the two comment styles, PlaceholderText nor Word's built-ins in docx4j's KnownStyles.xml carry one. Define it yourself on the styles part.`);
|
|
106
123
|
}
|
|
107
124
|
// what it is based on and linked to must be there too, and before it reads better in the part
|
|
108
125
|
for (const dependency of [(_a = template.basedOn) === null || _a === void 0 ? void 0 : _a.val, (_b = template.link) === null || _b === void 0 ? void 0 : _b.val]) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
|
|
2
|
+
import { type Element } from './tree.mjs';
|
|
3
|
+
import { type ChangeTracker } from './tracking.mjs';
|
|
4
|
+
/** The default text width in twips (A4 with 2.54 cm margins), as the objects package's `tbl` builder uses. */
|
|
5
|
+
export declare const DEFAULT_TEXT_WIDTH = 9026;
|
|
6
|
+
export type TableLayoutMode = 'fixed' | 'window' | 'contents';
|
|
7
|
+
/** Which of Word's three layout modes a table is in, read as Word's Table Properties reads the file. */
|
|
8
|
+
export declare function layoutModeOf(tbl: wml.Tbl): TableLayoutMode;
|
|
9
|
+
/** The section's text width in twips: the page less its margins and gutter, else the default. */
|
|
10
|
+
export declare function textWidthTwips(container: {
|
|
11
|
+
sectPr?: wml.SectPr;
|
|
12
|
+
} | undefined): number;
|
|
13
|
+
/** The grid's column widths in twips; a table without a `w:tblGrid` gets one from its first row (equal columns over the text width when the cells state none). */
|
|
14
|
+
export declare function gridWidthsOf(tbl: wml.Tbl, textWidth: number): number[];
|
|
15
|
+
/** The form a cell's width takes: its own `w:tcW` type, else the table's `w:tblW` type, else twips (section 42.2 item 4). */
|
|
16
|
+
export declare function widthTypeOf(tc: wml.Tc | undefined, tbl: wml.Tbl): string;
|
|
17
|
+
export interface ColumnInsertion {
|
|
18
|
+
/** The new cells per row, in row order; a row whose spanning cell was widened, or whose skipped columns grew, has none. */
|
|
19
|
+
cells: Element<wml.Tc>[][];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Inserts `count` grid columns at `gridIndex` (0 to the column count). The new column copies the
|
|
23
|
+
* width of the column to the right of the boundary when there is one, else the left (check 40:
|
|
24
|
+
* Insert Right in a narrow cell beside a wide one took the wide width; Insert Right in a spanning
|
|
25
|
+
* cell took the column after it), and each row's new cell takes the properties of the cell on the
|
|
26
|
+
* same side, less its span and merges. A cell spanning the boundary keeps its span and the new
|
|
27
|
+
* cell goes before it (check 40b1); a row's `w:gridBefore` or `w:gridAfter` covering the boundary
|
|
28
|
+
* grows instead. `values` is by row, then by new column. While changes are tracked the table
|
|
29
|
+
* change is recorded as Word's Office JS records one (check 40c): the old properties, every
|
|
30
|
+
* cell's properties - the new cells' as made - the grid as it is after, and the new cells' text in
|
|
31
|
+
* a `w:ins`, with no mark insertion.
|
|
32
|
+
*/
|
|
33
|
+
export declare function insertGridColumns(tbl: wml.Tbl, textWidth: number, gridIndex: number, count: number, values: string[][] | undefined, tracker: ChangeTracker | undefined): ColumnInsertion;
|
|
34
|
+
/**
|
|
35
|
+
* Removes `count` grid columns from `columnIndex`: a cell covering only removed columns goes, one
|
|
36
|
+
* spanning further shrinks, a row's skipped columns shrink; the grid loses the columns, a `w:tblW`
|
|
37
|
+
* in twips loses their width, and in window mode the grid is rescaled to the width it had and the
|
|
38
|
+
* cells' percentages written again. While changes are tracked the cells still go, untracked, as
|
|
39
|
+
* Word's own Delete Columns and Office JS's `deleteColumns` leave them (known issues, entry 2;
|
|
40
|
+
* check 40c), and the table change is recorded as Office JS records it: the old properties, the
|
|
41
|
+
* remaining cells' properties, the grid as it is after.
|
|
42
|
+
*/
|
|
43
|
+
export declare function deleteGridColumns(tbl: wml.Tbl, textWidth: number, columnIndex: number, count: number, tracker: ChangeTracker | undefined): void;
|
|
44
|
+
/** The grid columns a cell covers: its start and the one past its end. */
|
|
45
|
+
export declare function gridRangeOf(tr: wml.Tr, tc: wml.Tc): {
|
|
46
|
+
start: number;
|
|
47
|
+
end: number;
|
|
48
|
+
} | undefined;
|