@docx4j/core-ts 0.3.2 → 0.5.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.
Files changed (72) hide show
  1. package/README.md +8 -3
  2. package/dist/html/convert.d.mts +116 -0
  3. package/dist/html/convert.mjs +565 -0
  4. package/dist/html/elements.d.mts +19 -0
  5. package/dist/html/elements.mjs +182 -0
  6. package/dist/html/index.d.mts +2 -0
  7. package/dist/html/index.mjs +4 -0
  8. package/dist/model/content/Body.d.mts +13 -1
  9. package/dist/model/content/Body.mjs +97 -19
  10. package/dist/model/content/Comment.mjs +7 -0
  11. package/dist/model/content/InlinePicture.d.mts +89 -10
  12. package/dist/model/content/InlinePicture.mjs +245 -35
  13. package/dist/model/content/List.mjs +10 -1
  14. package/dist/model/content/Paragraph.d.mts +28 -5
  15. package/dist/model/content/Paragraph.mjs +77 -37
  16. package/dist/model/content/Range.d.mts +18 -2
  17. package/dist/model/content/Range.mjs +194 -64
  18. package/dist/model/content/Table.d.mts +38 -0
  19. package/dist/model/content/Table.mjs +80 -2
  20. package/dist/model/content/TrackedChange.d.mts +129 -3
  21. package/dist/model/content/TrackedChange.mjs +577 -12
  22. package/dist/model/content/binder.d.mts +2 -1
  23. package/dist/model/content/binder.mjs +48 -1
  24. package/dist/model/content/index.d.mts +4 -3
  25. package/dist/model/content/index.mjs +3 -2
  26. package/dist/model/content/relationships.d.mts +30 -0
  27. package/dist/model/content/relationships.mjs +133 -0
  28. package/dist/model/content/stylesFacade.d.mts +4 -2
  29. package/dist/model/content/stylesFacade.mjs +20 -6
  30. package/dist/model/content/tableColumns.d.mts +48 -0
  31. package/dist/model/content/tableColumns.mjs +484 -0
  32. package/dist/model/content/tree.d.mts +52 -2
  33. package/dist/model/content/tree.mjs +48 -3
  34. package/dist/model/customxml/CustomXmlPartCollection.d.mts +6 -1
  35. package/dist/model/customxml/CustomXmlPartCollection.mjs +19 -3
  36. package/dist/model/customxml/bindings.d.mts +5 -2
  37. package/dist/model/customxml/bindings.mjs +21 -6
  38. package/dist/model/customxml/index.d.mts +3 -0
  39. package/dist/model/customxml/index.mjs +3 -0
  40. package/dist/model/customxml/opendope.d.mts +32 -0
  41. package/dist/model/customxml/opendope.mjs +56 -0
  42. package/dist/model/customxml/pictures.d.mts +57 -0
  43. package/dist/model/customxml/pictures.mjs +192 -0
  44. package/dist/model/customxml/xhtml.d.mts +42 -0
  45. package/dist/model/customxml/xhtml.mjs +162 -0
  46. package/dist/model/fonts/families.generated.mjs +2 -2
  47. package/dist/model/fonts/registry.mjs +7 -1
  48. package/dist/model/fonts/substitutions.generated.mjs +2 -2
  49. package/dist/model/fonts/themes.generated.mjs +1 -1
  50. package/dist/model/listnumbering/definitions.mjs +18 -0
  51. package/dist/model/properties/PropertyResolver.d.mts +27 -6
  52. package/dist/model/properties/PropertyResolver.mjs +83 -16
  53. package/dist/model/properties/catalogue.d.mts +15 -1
  54. package/dist/model/properties/catalogue.mjs +80 -27
  55. package/dist/model/properties/table.d.mts +16 -2
  56. package/dist/model/properties/table.mjs +13 -3
  57. package/dist/opc/Load.d.mts +9 -2
  58. package/dist/opc/index.d.mts +2 -2
  59. package/dist/opc/index.mjs +2 -2
  60. package/dist/opc/mce/preprocessor.d.mts +62 -6
  61. package/dist/opc/mce/preprocessor.mjs +142 -35
  62. package/dist/opc/mce/understood.d.mts +10 -0
  63. package/dist/opc/mce/understood.mjs +25 -3
  64. package/dist/packages/OpcPackage.d.mts +7 -0
  65. package/dist/packages/OpcPackage.mjs +15 -3
  66. package/dist/packages/WordprocessingMLPackage.d.mts +35 -2
  67. package/dist/packages/WordprocessingMLPackage.mjs +99 -2
  68. package/dist/parts/XmlPart.d.mts +26 -5
  69. package/dist/parts/XmlPart.mjs +67 -18
  70. package/dist/parts/wml/knownStyles.d.mts +1 -0
  71. package/dist/parts/wml/knownStyles.mjs +2233 -0
  72. package/package.json +7 -2
@@ -10,7 +10,8 @@ export interface Bound {
10
10
  * The tree object: for an element, what a walk of the typed tree would hand you at that path,
11
11
  * never a `{ name, value }` wrapper; for an attribute or a text node, the object of the element
12
12
  * that owns it. Undefined for an element the model does not build - a wildcard child is its own
13
- * object, so this is undefined only above the root or for a node the marshal did not report.
13
+ * object, and so is each element inside one (the node at the same place in the tree), so this is
14
+ * undefined only above the root or for a node the marshal did not report.
14
15
  */
15
16
  object: unknown;
16
17
  /** Set when an attribute was selected: its qualified name on `object`'s element. */
@@ -33,11 +33,12 @@ export async function bindSnapshot(element) {
33
33
  /** Turns selected nodes into `Bound`s against a snapshot, with one path cache for them all. */
34
34
  export function boundsOf(nodes, snapshot) {
35
35
  const paths = new Paths();
36
+ const indexes = new Map();
36
37
  return nodes.map((node) => {
37
38
  const owner = owningElement(node);
38
39
  const bound = {
39
40
  node,
40
- object: owner === undefined ? undefined : snapshot.objects.get(owner),
41
+ object: owner === undefined ? undefined : objectOf(owner, snapshot.objects, indexes),
41
42
  path: paths.of(node),
42
43
  };
43
44
  if (node.nodeType === 2)
@@ -45,6 +46,49 @@ export function boundsOf(nodes, snapshot) {
45
46
  return bound;
46
47
  });
47
48
  }
49
+ /**
50
+ * The tree object behind a snapshot element. The marshal reports a wildcard child's imported copy
51
+ * but nothing inside it, so an element there maps to the node at the same place under the original:
52
+ * the copy is deep, so the child positions agree. Since CR-010 phase 4 a kept branch's DrawingML is
53
+ * DOM from the branch down (an `xdr:graphicFrame`, a `p:sp`), and a selection lands inside it.
54
+ * Below a typed ancestor an unreported element stays unmapped.
55
+ */
56
+ function objectOf(element, objects, indexes) {
57
+ if (objects.has(element))
58
+ return objects.get(element);
59
+ const path = [];
60
+ let at = element;
61
+ while (!objects.has(at)) {
62
+ path.push(at);
63
+ const parent = at.parentNode;
64
+ if (parent === null || parent.nodeType !== 1)
65
+ return undefined;
66
+ at = parent;
67
+ }
68
+ let node = objects.get(at);
69
+ if (!isNode(node))
70
+ return undefined;
71
+ for (let k = path.length - 1; k >= 0; k--) {
72
+ node = node.childNodes[childIndex(path[k], indexes)];
73
+ if (node === undefined || node === null)
74
+ return undefined;
75
+ }
76
+ return node;
77
+ }
78
+ /** A node's position among its parent's child nodes, each parent's counted once. */
79
+ function childIndex(node, indexes) {
80
+ var _a;
81
+ const parent = node.parentNode;
82
+ let index = indexes.get(parent);
83
+ if (index === undefined) {
84
+ index = new Map();
85
+ let i = 0;
86
+ for (let child = parent.firstChild; child; child = child.nextSibling)
87
+ index.set(child, i++);
88
+ indexes.set(parent, index);
89
+ }
90
+ return (_a = index.get(node)) !== null && _a !== void 0 ? _a : -1;
91
+ }
48
92
  /**
49
93
  * The element an XPath result belongs to: itself for an element, its owner for an attribute, its
50
94
  * parent for a text, comment or processing-instruction node. A document node has none.
@@ -123,6 +167,9 @@ class Paths {
123
167
  return (_b = positions.get(element)) !== null && _b !== void 0 ? _b : 0;
124
168
  }
125
169
  }
170
+ function isNode(node) {
171
+ return typeof node === 'object' && node !== null && typeof node.nodeType === 'number';
172
+ }
126
173
  function isElement(node) {
127
174
  return typeof node === 'object' && node !== null && node.nodeType === 1;
128
175
  }
@@ -7,12 +7,13 @@ 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 { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, writableWidthEmu, type ImageFormat, type ImageInfo, type InlinePictureOptions, type NewPicture } from './InlinePicture.mjs';
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';
14
- export { segmentsOf, runsOf, runItemsOf, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, type TextSegment, type Located, type TextView, type TextViewOptions, type RevisionKind, type RevisionHolder } from './tree.mjs';
15
- export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext, type TrackedChangeType, type TrackedChangeTarget } from './TrackedChange.mjs';
15
+ export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, type TextSegment, type Located, type TextView, type TextViewOptions, type RevisionKind, type RevisionHolder } from './tree.mjs';
16
+ export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext, type TrackedChangeType, type TrackedChangeTarget, type NoteRemovals } from './TrackedChange.mjs';
16
17
  export { ChangeTracker, trackerOf, calendarOf, dateOf, wordCalendarOf, revisionDateOf, copyRPr, markDeleted, markInserted, highestAnnotationId, MARKUP_TYPES, toDeletedText, toRestoredText, restoreRPr, restorePPr, trackInsertedParagraph, trackInsertedTable, trackInsertedBlocks, wrapNewRuns, wrapInsertedRuns, paraRPrOf, rowPrOf, pruneParagraphProperties, type ChangeTrackingMode, type TrackingHost, type TrackingScope, type TrackedPart, } from './tracking.mjs';
17
18
  export { wml, wmlOne, p, r, t, br, tab, tbl, tr, tc, sdt, sdtPr, nextSdtId, sdtProperty, sdtKindOf, inlinePicture, rPrToElements, rPrFromElements, textOf, walk, walkAll, find, linkParents, applyRunOptions, readRunOptions, UNDERLINE_TO_WML, isElement, typeNameOf, W_NS, type Element, type Wrapper, type WmlOptions, type Raw, type Interpolated, type RunOptions, type RunFormatting, type ParagraphOptions, type TableOptions, type CellOptions, type SdtKind, type SdtForm, type SdtOptions } from '@docx4j/generated-objects-ts/builders/wml';
18
19
  export { StylesFacade, type StylePackageLike } from './stylesFacade.mjs';
@@ -9,11 +9,12 @@ 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 { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, writableWidthEmu } from './InlinePicture.mjs';
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';
16
- export { segmentsOf, runsOf, runItemsOf, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf } from './tree.mjs';
17
+ export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf } from './tree.mjs';
17
18
  // change tracking (CR-002 phase F)
18
19
  export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext } from './TrackedChange.mjs';
19
20
  export { ChangeTracker, trackerOf, calendarOf, dateOf, wordCalendarOf, revisionDateOf, copyRPr, markDeleted, markInserted, highestAnnotationId, MARKUP_TYPES, toDeletedText, toRestoredText, restoreRPr, restorePPr, trackInsertedParagraph, trackInsertedTable, trackInsertedBlocks, wrapNewRuns, wrapInsertedRuns, paraRPrOf, rowPrOf, pruneParagraphProperties, } from './tracking.mjs';
@@ -0,0 +1,30 @@
1
+ import type { Part } from '../../parts/Part.mjs';
2
+ /**
3
+ * Adds to `into` every relationship id a tree references: the `r:` attributes of its typed objects (read
4
+ * off the model's mapping, as docx4j reads its fields' `@XmlAttribute`), those kept in an
5
+ * `otherAttributes` map, and those of any DOM it holds.
6
+ */
7
+ export declare function relationshipIdsIn(tree: unknown, into: Set<string>): void;
8
+ /**
9
+ * The relationships of `part` among `candidates` that nothing left in the part references are removed,
10
+ * and the part each targeted when no relationship in the package targets it any more, with what that
11
+ * part alone related to (`RelationshipsPart.removeParts`). A part not unmarshalled can't be read for
12
+ * what still references, so nothing is removed from it.
13
+ */
14
+ export declare function dropRelationshipsUnused(part: Part, candidates: Set<string>): void;
15
+ /**
16
+ * Relationship ids, by the name of the part they belong to, that content removed outside a
17
+ * resolution referenced: a picture deleted with tracking off, or taken back from its author's own
18
+ * insertion. They are settled when the package is saved rather than at once, so that content put
19
+ * back in the meantime (a cut and a paste of the same drawing) keeps its relationship.
20
+ */
21
+ export type RelationshipRemovals = Map<string, Set<string>>;
22
+ /** Queues `ids` of `part` for `flushPendingRelationshipRemovals`. */
23
+ export declare function queueRelationshipRemovals(pending: RelationshipRemovals | undefined, part: Part | undefined, ids: Iterable<string>): void;
24
+ /** What `flushPendingRelationshipRemovals` needs of the package. */
25
+ interface PartsHost {
26
+ getPart(name: string): Part | undefined;
27
+ }
28
+ /** Settles the queued ids against each part as it now stands (`dropRelationshipsUnused`); then `pending` is empty. */
29
+ export declare function flushPendingRelationshipRemovals(pkg: PartsHost, pending: RelationshipRemovals): void;
30
+ export {};
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The relationships content references, and the removal of those nothing references any more
3
+ * (CR-002 section 46, docx4j CR-043's D7): shared by the tracked-change resolution
4
+ * (`TrackedChange.mts`) and the pictures (`InlinePicture.delete`, section 47).
5
+ */
6
+ import { getContextSync } from '@docx4j/generated-objects-ts';
7
+ const R_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
8
+ /** Per type, the properties that are attributes in the relationships namespace (`r:id`, `r:embed`, `r:link`, ...). */
9
+ const relationshipAttributes = new Map();
10
+ function relationshipAttributesOf(typeName) {
11
+ var _a, _b;
12
+ let names = relationshipAttributes.get(typeName);
13
+ if (names)
14
+ return names;
15
+ const found = [];
16
+ let info;
17
+ try {
18
+ info = getContextSync().getTypeInfoByName(typeName);
19
+ }
20
+ catch {
21
+ info = undefined;
22
+ }
23
+ for (let ti = info; ti; ti = ti.baseTypeInfo) {
24
+ for (const property of (_a = ti.properties) !== null && _a !== void 0 ? _a : []) {
25
+ if (((_b = property.attributeName) === null || _b === void 0 ? void 0 : _b.namespaceURI) === R_NS && property.name)
26
+ found.push(property.name);
27
+ }
28
+ }
29
+ relationshipAttributes.set(typeName, names = found);
30
+ return names;
31
+ }
32
+ /**
33
+ * Adds to `into` every relationship id a tree references: the `r:` attributes of its typed objects (read
34
+ * off the model's mapping, as docx4j reads its fields' `@XmlAttribute`), those kept in an
35
+ * `otherAttributes` map, and those of any DOM it holds.
36
+ */
37
+ export function relationshipIdsIn(tree, into) {
38
+ const seen = new Set();
39
+ const visitDom = (node) => {
40
+ if (node.nodeType !== 1)
41
+ return;
42
+ const attributes = node.attributes;
43
+ for (let i = 0; i < attributes.length; i++) {
44
+ const a = attributes[i];
45
+ if (a.namespaceURI === R_NS && a.value)
46
+ into.add(a.value);
47
+ }
48
+ for (let c = node.firstChild; c; c = c.nextSibling)
49
+ visitDom(c);
50
+ };
51
+ const visit = (o) => {
52
+ if (typeof o !== 'object' || o === null || seen.has(o))
53
+ return;
54
+ seen.add(o);
55
+ if (Array.isArray(o)) {
56
+ for (const item of o)
57
+ visit(item);
58
+ return;
59
+ }
60
+ if (typeof o.nodeType === 'number') {
61
+ visitDom(o);
62
+ return;
63
+ }
64
+ const record = o;
65
+ const typeName = record.TYPE_NAME;
66
+ if (typeof typeName === 'string') {
67
+ for (const name of relationshipAttributesOf(typeName)) {
68
+ const value = record[name];
69
+ if (typeof value === 'string' && value)
70
+ into.add(value);
71
+ }
72
+ }
73
+ const other = record.otherAttributes;
74
+ if (other && typeof other === 'object') {
75
+ for (const [key, value] of Object.entries(other))
76
+ if (key.startsWith(`{${R_NS}}`) && typeof value === 'string')
77
+ into.add(value);
78
+ }
79
+ for (const key in record)
80
+ if (key !== 'PARENT' && key !== 'otherAttributes')
81
+ visit(record[key]);
82
+ };
83
+ visit(tree);
84
+ }
85
+ /**
86
+ * The relationships of `part` among `candidates` that nothing left in the part references are removed,
87
+ * and the part each targeted when no relationship in the package targets it any more, with what that
88
+ * part alone related to (`RelationshipsPart.removeParts`). A part not unmarshalled can't be read for
89
+ * what still references, so nothing is removed from it.
90
+ */
91
+ export function dropRelationshipsUnused(part, candidates) {
92
+ var _a, _b;
93
+ const rels = part.relationshipsPart;
94
+ const contents = part.isUnmarshalled
95
+ ? part.contents : undefined;
96
+ if (!rels || contents === undefined)
97
+ return;
98
+ const used = new Set();
99
+ relationshipIdsIn(contents, used);
100
+ for (const id of candidates) {
101
+ if (used.has(id))
102
+ continue;
103
+ const rel = rels.getRelationshipById(id);
104
+ if (!rel)
105
+ continue;
106
+ const target = rels.getPart(rel);
107
+ rels.removeRelationship(rel);
108
+ if (target && target.sourceRelationships.length === 0) {
109
+ (_a = target.relationshipsPart) === null || _a === void 0 ? void 0 : _a.removeParts();
110
+ (_b = target.package) === null || _b === void 0 ? void 0 : _b.parts.remove(target.partName);
111
+ }
112
+ }
113
+ }
114
+ /** Queues `ids` of `part` for `flushPendingRelationshipRemovals`. */
115
+ export function queueRelationshipRemovals(pending, part, ids) {
116
+ if (!pending || !part)
117
+ return;
118
+ let set = pending.get(part.partName.name);
119
+ for (const id of ids) {
120
+ if (!set)
121
+ pending.set(part.partName.name, set = new Set());
122
+ set.add(id);
123
+ }
124
+ }
125
+ /** Settles the queued ids against each part as it now stands (`dropRelationshipsUnused`); then `pending` is empty. */
126
+ export function flushPendingRelationshipRemovals(pkg, pending) {
127
+ for (const [name, ids] of pending) {
128
+ const part = pkg.getPart(name);
129
+ if (part)
130
+ dropRelationshipsUnused(part, ids);
131
+ }
132
+ pending.clear();
133
+ }
@@ -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 the defaults do not carry throws a `Docx4JException` naming it: the
27
- * caller asked for a definition nothing here has, and inventing one would be worse than saying so.
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
  *
@@ -5,13 +5,16 @@ 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
7
  import { placeholderStyle } from '../../parts/wml/placeholderStyle.mjs';
8
+ import { KNOWN_STYLES_XML } from '../../parts/wml/knownStyles.mjs';
8
9
  import { Docx4JException } from '../../opc/exceptions.mjs';
9
10
  /**
10
11
  * Where a definition is looked up, unmarshalled once and never handed out (a copy is spliced in):
11
12
  * the defaults `createPackage()` writes, and then the nine styles docx4j's own `styles.xml` carries
12
13
  * **commented out** - which is why a created document has no `FootnoteText` although the file
13
14
  * appears to contain one, and why this facade exists (CR-002 section 22.2) - with Word's two comment
14
- * styles and its `PlaceholderText` after them.
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.
15
18
  */
16
19
  let sources;
17
20
  function styleSources() {
@@ -20,8 +23,17 @@ function styleSources() {
20
23
  const defaults = await read(DEFAULT_STYLES_XML);
21
24
  // and Word's two comment styles, which the comment parts add when they are made, for a caller
22
25
  // that makes the comment itself (CR-002 section 37), and Word's PlaceholderText, which a
23
- // placeholder run names (CR-002 section 40)
24
- return { defaults, all: [...defaults, ...(await read(SPLICEABLE_STYLES_XML)), ...commentStyles(), placeholderStyle()] };
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] };
25
37
  })()));
26
38
  }
27
39
  /**
@@ -42,8 +54,10 @@ export class StylesFacade {
42
54
  *
43
55
  * A style already in the document is left exactly as it is - the document's own definition wins
44
56
  * over the default, always, since a consumer must not silently restyle a document it was asked to
45
- * add a footnote to. An id the defaults do not carry throws a `Docx4JException` naming it: the
46
- * caller asked for a definition nothing here has, and inventing one would be worse than saying so.
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.
47
61
  * The whole closure is worked out before anything is written, so a call that throws has changed
48
62
  * nothing (CR-002 section 31).
49
63
  *
@@ -105,7 +119,7 @@ function closureOf(wanted, present, source) {
105
119
  seen.add(id);
106
120
  const template = source.find((s) => s.styleId === id);
107
121
  if (template === undefined) {
108
- 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 nor PlaceholderText carry one. Define it yourself on the styles part.`);
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.`);
109
123
  }
110
124
  // what it is based on and linked to must be there too, and before it reads better in the part
111
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;