@docx4j/core-ts 0.1.0 → 0.1.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.
Files changed (168) hide show
  1. package/README.md +410 -10
  2. package/dist/model/content/Body.d.mts +109 -4
  3. package/dist/model/content/Body.mjs +300 -29
  4. package/dist/model/content/Comment.d.mts +78 -0
  5. package/dist/model/content/Comment.mjs +429 -0
  6. package/dist/model/content/ContentControl.d.mts +173 -0
  7. package/dist/model/content/ContentControl.mjs +638 -0
  8. package/dist/model/content/Font.d.mts +48 -8
  9. package/dist/model/content/Font.mjs +55 -13
  10. package/dist/model/content/InlinePicture.d.mts +103 -0
  11. package/dist/model/content/InlinePicture.mjs +361 -0
  12. package/dist/model/content/List.d.mts +253 -0
  13. package/dist/model/content/List.mjs +778 -0
  14. package/dist/model/content/Paragraph.d.mts +213 -16
  15. package/dist/model/content/Paragraph.mjs +611 -57
  16. package/dist/model/content/Range.d.mts +48 -4
  17. package/dist/model/content/Range.mjs +161 -4
  18. package/dist/model/content/Table.d.mts +130 -0
  19. package/dist/model/content/Table.mjs +429 -0
  20. package/dist/model/content/TrackedChange.d.mts +96 -0
  21. package/dist/model/content/TrackedChange.mjs +352 -0
  22. package/dist/model/content/comments.d.mts +122 -0
  23. package/dist/model/content/comments.mjs +248 -0
  24. package/dist/model/content/index.d.mts +13 -3
  25. package/dist/model/content/index.mjs +15 -3
  26. package/dist/model/content/ooxml.d.mts +17 -0
  27. package/dist/model/content/ooxml.mjs +214 -0
  28. package/dist/model/content/styles.d.mts +21 -0
  29. package/dist/model/content/styles.mjs +86 -0
  30. package/dist/model/content/tracking.d.mts +104 -0
  31. package/dist/model/content/tracking.mjs +313 -0
  32. package/dist/model/content/tree.d.mts +56 -9
  33. package/dist/model/content/tree.mjs +104 -31
  34. package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
  35. package/dist/model/customxml/CustomXmlPart.mjs +415 -0
  36. package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
  37. package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
  38. package/dist/model/customxml/XmlMapping.d.mts +46 -0
  39. package/dist/model/customxml/XmlMapping.mjs +98 -0
  40. package/dist/model/customxml/bindings.d.mts +41 -0
  41. package/dist/model/customxml/bindings.mjs +230 -0
  42. package/dist/model/customxml/index.d.mts +7 -0
  43. package/dist/model/customxml/index.mjs +9 -0
  44. package/dist/model/customxml/insert.d.mts +20 -0
  45. package/dist/model/customxml/insert.mjs +22 -0
  46. package/dist/model/customxml/kinds.d.mts +103 -0
  47. package/dist/model/customxml/kinds.mjs +267 -0
  48. package/dist/model/customxml/xpath.d.mts +52 -0
  49. package/dist/model/customxml/xpath.mjs +205 -0
  50. package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
  51. package/dist/model/fonts/CJKToEnglish.mjs +16 -0
  52. package/dist/model/fonts/FontFallback.d.mts +58 -0
  53. package/dist/model/fonts/FontFallback.mjs +219 -0
  54. package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
  55. package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
  56. package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
  57. package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
  58. package/dist/model/fonts/Mapper.d.mts +190 -0
  59. package/dist/model/fonts/Mapper.mjs +481 -0
  60. package/dist/model/fonts/PhysicalFont.d.mts +34 -0
  61. package/dist/model/fonts/PhysicalFont.mjs +62 -0
  62. package/dist/model/fonts/RunFontSelector.d.mts +194 -0
  63. package/dist/model/fonts/RunFontSelector.mjs +441 -0
  64. package/dist/model/fonts/ThemeFonts.d.mts +17 -0
  65. package/dist/model/fonts/ThemeFonts.mjs +76 -0
  66. package/dist/model/fonts/defaultTheme.d.mts +37 -0
  67. package/dist/model/fonts/defaultTheme.mjs +57 -0
  68. package/dist/model/fonts/families.generated.d.mts +11 -0
  69. package/dist/model/fonts/families.generated.mjs +17 -0
  70. package/dist/model/fonts/fontsInUse.d.mts +39 -0
  71. package/dist/model/fonts/fontsInUse.mjs +183 -0
  72. package/dist/model/fonts/index.d.mts +14 -0
  73. package/dist/model/fonts/index.mjs +29 -0
  74. package/dist/model/fonts/lookup.d.mts +5 -0
  75. package/dist/model/fonts/lookup.mjs +12 -0
  76. package/dist/model/fonts/registry.d.mts +31 -0
  77. package/dist/model/fonts/registry.mjs +103 -0
  78. package/dist/model/fonts/scripts.d.mts +2 -0
  79. package/dist/model/fonts/scripts.mjs +78 -0
  80. package/dist/model/fonts/substitutions.generated.d.mts +30 -0
  81. package/dist/model/fonts/substitutions.generated.mjs +12 -0
  82. package/dist/model/fonts/themes.generated.d.mts +6 -0
  83. package/dist/model/fonts/themes.generated.mjs +11 -0
  84. package/dist/model/index.d.mts +5 -0
  85. package/dist/model/index.mjs +13 -1
  86. package/dist/model/listnumbering/Emulator.d.mts +187 -0
  87. package/dist/model/listnumbering/Emulator.mjs +332 -0
  88. package/dist/model/listnumbering/definitions.d.mts +251 -0
  89. package/dist/model/listnumbering/definitions.mjs +571 -0
  90. package/dist/model/listnumbering/formats.d.mts +25 -0
  91. package/dist/model/listnumbering/formats.mjs +320 -0
  92. package/dist/model/listnumbering/index.d.mts +4 -0
  93. package/dist/model/listnumbering/index.mjs +15 -0
  94. package/dist/model/listnumbering/state.d.mts +97 -0
  95. package/dist/model/listnumbering/state.mjs +179 -0
  96. package/dist/model/properties/PropertyResolver.d.mts +216 -0
  97. package/dist/model/properties/PropertyResolver.mjs +524 -0
  98. package/dist/model/properties/catalogue.d.mts +179 -0
  99. package/dist/model/properties/catalogue.mjs +860 -0
  100. package/dist/model/properties/index.d.mts +4 -0
  101. package/dist/model/properties/index.mjs +9 -0
  102. package/dist/model/properties/log.d.mts +7 -0
  103. package/dist/model/properties/log.mjs +25 -0
  104. package/dist/model/properties/styleUtil.d.mts +112 -0
  105. package/dist/model/properties/styleUtil.mjs +359 -0
  106. package/dist/node/index.d.mts +1 -0
  107. package/dist/node/index.mjs +12 -0
  108. package/dist/office-js/document.d.mts +111 -0
  109. package/dist/office-js/document.mjs +267 -0
  110. package/dist/office-js/enums.d.mts +187 -0
  111. package/dist/office-js/enums.mjs +176 -0
  112. package/dist/office-js/errors.d.mts +29 -0
  113. package/dist/office-js/errors.mjs +39 -0
  114. package/dist/office-js/extras.d.mts +5 -0
  115. package/dist/office-js/extras.mjs +29 -0
  116. package/dist/office-js/fragment.d.mts +10 -0
  117. package/dist/office-js/fragment.mjs +23 -0
  118. package/dist/office-js/index.d.mts +183 -0
  119. package/dist/office-js/index.mjs +54 -0
  120. package/dist/office-js/proxy.d.mts +72 -0
  121. package/dist/office-js/proxy.mjs +279 -0
  122. package/dist/office-js/run.d.mts +32 -0
  123. package/dist/office-js/run.mjs +66 -0
  124. package/dist/office-js/supported.d.mts +7 -0
  125. package/dist/office-js/supported.generated.d.mts +1 -0
  126. package/dist/office-js/supported.generated.mjs +235 -0
  127. package/dist/office-js/supported.mjs +53 -0
  128. package/dist/office-js/toApiScript.d.mts +25 -0
  129. package/dist/office-js/toApiScript.mjs +394 -0
  130. package/dist/opc/ContentTypes.d.mts +1 -0
  131. package/dist/opc/ContentTypes.mjs +1 -0
  132. package/dist/opc/DirectoryPartStore.d.mts +47 -0
  133. package/dist/opc/DirectoryPartStore.mjs +123 -0
  134. package/dist/opc/exceptions.d.mts +30 -0
  135. package/dist/opc/exceptions.mjs +38 -0
  136. package/dist/opc/index.d.mts +1 -1
  137. package/dist/opc/index.mjs +1 -1
  138. package/dist/packages/OpcPackage.d.mts +19 -1
  139. package/dist/packages/OpcPackage.mjs +29 -0
  140. package/dist/packages/PresentationMLPackage.d.mts +71 -1
  141. package/dist/packages/PresentationMLPackage.mjs +179 -0
  142. package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
  143. package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
  144. package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
  145. package/dist/packages/WordprocessingMLPackage.mjs +309 -2
  146. package/dist/packages/index.d.mts +1 -1
  147. package/dist/packages/index.mjs +1 -1
  148. package/dist/parts/DefaultXmlPart.d.mts +18 -0
  149. package/dist/parts/DefaultXmlPart.mjs +34 -5
  150. package/dist/parts/PartRegistry.mjs +1 -0
  151. package/dist/parts/XmlPart.d.mts +33 -0
  152. package/dist/parts/XmlPart.mjs +105 -2
  153. package/dist/parts/pml/defaults.d.mts +6 -0
  154. package/dist/parts/pml/defaults.mjs +53 -0
  155. package/dist/parts/pml/index.d.mts +66 -3
  156. package/dist/parts/pml/index.mjs +206 -7
  157. package/dist/parts/pml/placeholders.d.mts +71 -0
  158. package/dist/parts/pml/placeholders.mjs +141 -0
  159. package/dist/parts/sml/index.d.mts +19 -1
  160. package/dist/parts/sml/index.mjs +60 -1
  161. package/dist/parts/wml/comments.d.mts +1 -0
  162. package/dist/parts/wml/comments.mjs +179 -0
  163. package/dist/parts/wml/defaultNumbering.d.mts +1 -0
  164. package/dist/parts/wml/defaultNumbering.mjs +216 -0
  165. package/dist/parts/wml/index.d.mts +121 -0
  166. package/dist/parts/wml/index.mjs +291 -0
  167. package/dist/xml/dom.mjs +1 -2
  168. package/package.json +25 -4
@@ -0,0 +1,39 @@
1
+ // The errors the Word shim throws (CR-002 section 3.10). Office JS raises OfficeExtension.Error
2
+ // with a `code` from Word.ErrorCodes; these carry the same codes so that add-in code which
3
+ // branches on `error.code` behaves the same here.
4
+ /**
5
+ * A member of the Word API that this package does not implement. The message names the class and
6
+ * the member, so an add-in's unsupported call fails at the call with something actionable:
7
+ * `Word.Paragraph.getNextOrNullObject is not supported by @docx4j/core-ts`.
8
+ */
9
+ export class NotSupportedError extends Error {
10
+ constructor(
11
+ /** The Word class, as Office JS names it ('Paragraph', 'Body', 'RequestContext'). */
12
+ className,
13
+ /** The member that was read, written or called. */
14
+ member, detail) {
15
+ super(`Word.${className}.${member} is not supported by @docx4j/core-ts${detail ? `: ${detail}` : ''}`);
16
+ this.className = className;
17
+ this.member = member;
18
+ /** Word.ErrorCodes.notImplemented. */
19
+ this.code = 'NotImplemented';
20
+ this.name = 'NotSupportedError';
21
+ }
22
+ }
23
+ /** Nothing matched: `getFirst()` on an empty collection, or a member of a null object. */
24
+ export class ItemNotFoundError extends Error {
25
+ constructor(message) {
26
+ super(message);
27
+ /** Word.ErrorCodes.itemNotFound. */
28
+ this.code = 'ItemNotFound';
29
+ this.name = 'ItemNotFoundError';
30
+ }
31
+ }
32
+ /** A result read before `context.sync()` resolved it (Office JS: ValueNotLoaded). */
33
+ export class ValueNotLoadedError extends Error {
34
+ constructor(message = 'The value is not loaded yet; await context.sync() first') {
35
+ super(message);
36
+ this.code = 'ValueNotLoaded';
37
+ this.name = 'ValueNotLoadedError';
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ /** A member the shim adds: called with the view and the call's arguments. */
2
+ export type ExtraMember = (target: never, ...args: never[]) => unknown;
3
+ /** By Word class name, then member name. */
4
+ export type ExtraMembers = Readonly<Record<string, Readonly<Record<string, ExtraMember>>>>;
5
+ export declare const EXTRA_MEMBERS: ExtraMembers;
@@ -0,0 +1,29 @@
1
+ // Members the shim adds over a view, per Word class (CR-002 section 3.10). The views keep to what
2
+ // the content API promises (section 3.12), so `getOoxml()`, which needs the package, lives here
3
+ // rather than on `Body`; the proxy offers these only when the view itself has no such member, so
4
+ // a later phase that implements one on the view wins without a change here.
5
+ import { xmlOfRange } from './fragment.mjs';
6
+ /**
7
+ * `body.getOoxml()` is Office JS's whole-document flat OPC package, which is exactly
8
+ * `OpcPackage.saveFlatOpc()`; a body with no package (a fragment) gives its part's XML.
9
+ */
10
+ function bodyOoxml(body) {
11
+ const pkg = body.package_;
12
+ if (pkg)
13
+ return pkg.saveFlatOpc();
14
+ return body.getXml();
15
+ }
16
+ export const EXTRA_MEMBERS = {
17
+ Body: {
18
+ getOoxml: (body) => bodyOoxml(body),
19
+ },
20
+ Paragraph: {
21
+ // Word wraps a paragraph in a pkg:package with the styles it needs; that is CR-002 phase C's
22
+ // insertOoxml work, so this is the bare `w:p` fragment (which `insertXml` takes back).
23
+ getOoxml: (paragraph) => paragraph.getXml(),
24
+ },
25
+ Range: {
26
+ getOoxml: (range) => xmlOfRange(range),
27
+ getXml: (range) => xmlOfRange(range),
28
+ },
29
+ };
@@ -0,0 +1,10 @@
1
+ import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
2
+ import type { Range } from '../model/content/Range.mjs';
3
+ import type { Element } from '../model/content/tree.mjs';
4
+ /**
5
+ * A detached `w:p` holding exactly the range's text, with the runs and their formatting. The
6
+ * paragraph is copied first, so the document is untouched.
7
+ */
8
+ export declare function paragraphElementOfRange(range: Range): Element<wml.P>;
9
+ /** The range as a `w:p` fragment (extension; Office JS wraps a range in a pkg:package). */
10
+ export declare function xmlOfRange(range: Range): Promise<string>;
@@ -0,0 +1,23 @@
1
+ // Marshalling a view back to a fragment: what `getOoxml()` and `toApiScript`'s fallback need.
2
+ // A `w:p` copy holding only a range's text is the one piece the views do not offer (Range has no
3
+ // element of its own: it is a span of the paragraph's text).
4
+ import { deepCopy, marshalString } from '@docx4j/generated-objects-ts';
5
+ import { Paragraph } from '../model/content/Paragraph.mjs';
6
+ /**
7
+ * A detached `w:p` holding exactly the range's text, with the runs and their formatting. The
8
+ * paragraph is copied first, so the document is untouched.
9
+ */
10
+ export function paragraphElementOfRange(range) {
11
+ const copy = deepCopy(range.paragraph.element);
12
+ const view = new Paragraph(copy, [copy], range.paragraph.parentBody);
13
+ const length = view.text.length;
14
+ if (range.end < length)
15
+ view.splice(range.end, length, '');
16
+ if (range.start > 0)
17
+ view.splice(0, range.start, '');
18
+ return copy;
19
+ }
20
+ /** The range as a `w:p` fragment (extension; Office JS wraps a range in a pkg:package). */
21
+ export function xmlOfRange(range) {
22
+ return marshalString(paragraphElementOfRange(range));
23
+ }
@@ -0,0 +1,183 @@
1
+ import { run, RequestContext, type RunOptions, type TrackedObjects } from './run.mjs';
2
+ import { Document, DocumentProperties } from './document.mjs';
3
+ import { supported, SUBSET_MEMBERS } from './supported.mjs';
4
+ import { ClientResult, unwrap, nullObject, Wrapper, type Collection, type PendingSink } from './proxy.mjs';
5
+ import { NotSupportedError, ItemNotFoundError, ValueNotLoadedError } from './errors.mjs';
6
+ import { toApiScript, type ApiScriptOptions, type ApiScriptTarget } from './toApiScript.mjs';
7
+ import { InsertLocation, Alignment, UnderlineType, ChangeTrackingMode, BreakType, ContentControlType, Style, ErrorCodes, SearchOptions, ListLevelType, ListNumbering, ListBullet, type InsertLocationValue, type ChangeTrackingModeValue, type BreakTypeValue, type ContentControlTypeValue, type StyleValue, type AlignmentValue, type UnderlineTypeValue, type ListLevelTypeValue, type ListNumberingValue, type ListBulletValue } from './enums.mjs';
8
+ export { run, RequestContext, Document, DocumentProperties, ClientResult, unwrap, nullObject, Wrapper, toApiScript, supported, SUBSET_MEMBERS };
9
+ export { NotSupportedError, ItemNotFoundError, ValueNotLoadedError };
10
+ export { InsertLocation, Alignment, UnderlineType, ChangeTrackingMode, BreakType, ContentControlType, Style, ErrorCodes, SearchOptions };
11
+ export { ListLevelType, ListNumbering, ListBullet };
12
+ export type { RunOptions, TrackedObjects, Collection, PendingSink, ApiScriptOptions, ApiScriptTarget, InsertLocationValue, ChangeTrackingModeValue, BreakTypeValue, ContentControlTypeValue, StyleValue, AlignmentValue, UnderlineTypeValue, ListLevelTypeValue, ListNumberingValue, ListBulletValue, };
13
+ /**
14
+ * The `Word` namespace an add-in script expects: `Word.run`, the enums, and `Word.supported`, the
15
+ * `Class.member` strings this package implements (so a tool can check a script before running it).
16
+ * `Word.run` takes the package first, since there is no host document.
17
+ */
18
+ export declare const Word: Readonly<{
19
+ run: typeof run;
20
+ supported: ReadonlySet<string>;
21
+ InsertLocation: Readonly<{
22
+ readonly before: "Before";
23
+ readonly after: "After";
24
+ readonly start: "Start";
25
+ readonly end: "End";
26
+ readonly replace: "Replace";
27
+ }>;
28
+ Alignment: Readonly<{
29
+ readonly unknown: "Unknown";
30
+ readonly left: "Left";
31
+ readonly centered: "Centered";
32
+ readonly right: "Right";
33
+ readonly justified: "Justified";
34
+ }>;
35
+ UnderlineType: Readonly<{
36
+ readonly mixed: "Mixed";
37
+ readonly none: "None";
38
+ readonly single: "Single";
39
+ readonly word: "Word";
40
+ readonly double: "Double";
41
+ readonly thick: "Thick";
42
+ readonly dotted: "Dotted";
43
+ readonly dottedHeavy: "DottedHeavy";
44
+ readonly dashLine: "DashLine";
45
+ readonly dashLineHeavy: "DashLineHeavy";
46
+ readonly dashLineLong: "DashLineLong";
47
+ readonly dashLineLongHeavy: "DashLineLongHeavy";
48
+ readonly dotDashLine: "DotDashLine";
49
+ readonly dotDashLineHeavy: "DotDashLineHeavy";
50
+ readonly twoDotDashLine: "TwoDotDashLine";
51
+ readonly twoDotDashLineHeavy: "TwoDotDashLineHeavy";
52
+ readonly wave: "Wave";
53
+ readonly waveHeavy: "WaveHeavy";
54
+ readonly waveDouble: "WaveDouble";
55
+ }>;
56
+ ChangeTrackingMode: Readonly<{
57
+ readonly off: "Off";
58
+ readonly trackAll: "TrackAll";
59
+ readonly trackMineOnly: "TrackMineOnly";
60
+ }>;
61
+ BreakType: Readonly<{
62
+ readonly page: "Page";
63
+ readonly next: "Next";
64
+ readonly sectionNext: "SectionNext";
65
+ readonly sectionContinuous: "SectionContinuous";
66
+ readonly sectionEven: "SectionEven";
67
+ readonly sectionOdd: "SectionOdd";
68
+ readonly line: "Line";
69
+ }>;
70
+ ContentControlType: Readonly<{
71
+ readonly unknown: "Unknown";
72
+ readonly richText: "RichText";
73
+ readonly plainText: "PlainText";
74
+ readonly picture: "Picture";
75
+ readonly datePicker: "DatePicker";
76
+ readonly comboBox: "ComboBox";
77
+ readonly dropDownList: "DropDownList";
78
+ readonly checkBox: "CheckBox";
79
+ readonly repeatingSection: "RepeatingSection";
80
+ readonly repeatingSectionItem: "RepeatingSectionItem";
81
+ readonly group: "Group";
82
+ readonly buildingBlockGallery: "BuildingBlockGallery";
83
+ readonly citation: "Citation";
84
+ readonly bibliography: "Bibliography";
85
+ readonly equation: "Equation";
86
+ }>;
87
+ ListLevelType: Readonly<{
88
+ readonly bullet: "Bullet";
89
+ readonly number: "Number";
90
+ readonly picture: "Picture";
91
+ }>;
92
+ ListNumbering: Readonly<{
93
+ readonly none: "None";
94
+ readonly arabic: "Arabic";
95
+ readonly upperRoman: "UpperRoman";
96
+ readonly lowerRoman: "LowerRoman";
97
+ readonly upperLetter: "UpperLetter";
98
+ readonly lowerLetter: "LowerLetter";
99
+ }>;
100
+ ListBullet: Readonly<{
101
+ readonly custom: "Custom";
102
+ readonly solid: "Solid";
103
+ readonly hollow: "Hollow";
104
+ readonly square: "Square";
105
+ readonly diamonds: "Diamonds";
106
+ readonly arrow: "Arrow";
107
+ readonly checkmark: "Checkmark";
108
+ }>;
109
+ Style: Readonly<{
110
+ readonly other: "Other";
111
+ readonly normal: "Normal";
112
+ readonly heading1: "Heading1";
113
+ readonly heading2: "Heading2";
114
+ readonly heading3: "Heading3";
115
+ readonly heading4: "Heading4";
116
+ readonly heading5: "Heading5";
117
+ readonly heading6: "Heading6";
118
+ readonly heading7: "Heading7";
119
+ readonly heading8: "Heading8";
120
+ readonly heading9: "Heading9";
121
+ readonly toc1: "Toc1";
122
+ readonly toc2: "Toc2";
123
+ readonly toc3: "Toc3";
124
+ readonly toc4: "Toc4";
125
+ readonly toc5: "Toc5";
126
+ readonly toc6: "Toc6";
127
+ readonly toc7: "Toc7";
128
+ readonly toc8: "Toc8";
129
+ readonly toc9: "Toc9";
130
+ readonly footnoteText: "FootnoteText";
131
+ readonly header: "Header";
132
+ readonly footer: "Footer";
133
+ readonly caption: "Caption";
134
+ readonly footnoteReference: "FootnoteReference";
135
+ readonly endnoteReference: "EndnoteReference";
136
+ readonly endnoteText: "EndnoteText";
137
+ readonly title: "Title";
138
+ readonly subtitle: "Subtitle";
139
+ readonly hyperlink: "Hyperlink";
140
+ readonly strong: "Strong";
141
+ readonly emphasis: "Emphasis";
142
+ readonly noSpacing: "NoSpacing";
143
+ readonly listParagraph: "ListParagraph";
144
+ readonly quote: "Quote";
145
+ readonly intenseQuote: "IntenseQuote";
146
+ readonly subtleEmphasis: "SubtleEmphasis";
147
+ readonly intenseEmphasis: "IntenseEmphasis";
148
+ readonly subtleReference: "SubtleReference";
149
+ readonly intenseReference: "IntenseReference";
150
+ readonly bookTitle: "BookTitle";
151
+ readonly bibliography: "Bibliography";
152
+ readonly tocHeading: "TocHeading";
153
+ readonly tableGrid: "TableGrid";
154
+ readonly plainTable1: "PlainTable1";
155
+ readonly plainTable2: "PlainTable2";
156
+ readonly plainTable3: "PlainTable3";
157
+ readonly plainTable4: "PlainTable4";
158
+ readonly plainTable5: "PlainTable5";
159
+ readonly gridTable1Light: "GridTable1Light";
160
+ readonly listTable1Light: "ListTable1Light";
161
+ }>;
162
+ ErrorCodes: Readonly<{
163
+ readonly accessDenied: "AccessDenied";
164
+ readonly generalException: "GeneralException";
165
+ readonly invalidArgument: "InvalidArgument";
166
+ readonly itemNotFound: "ItemNotFound";
167
+ readonly notAllowed: "NotAllowed";
168
+ readonly notImplemented: "NotImplemented";
169
+ readonly searchDialogIsOpen: "SearchDialogIsOpen";
170
+ readonly searchStringInvalidOrTooLong: "SearchStringInvalidOrTooLong";
171
+ }>;
172
+ SearchOptions: Readonly<{
173
+ newObject(): SearchOptions;
174
+ }>;
175
+ ClientResult: typeof ClientResult;
176
+ RequestContext: typeof RequestContext;
177
+ Document: typeof Document;
178
+ DocumentProperties: typeof DocumentProperties;
179
+ NotSupportedError: typeof NotSupportedError;
180
+ ItemNotFoundError: typeof ItemNotFoundError;
181
+ ValueNotLoadedError: typeof ValueNotLoadedError;
182
+ unwrap: typeof unwrap;
183
+ }>;
@@ -0,0 +1,54 @@
1
+ // `@docx4j/core-ts/office-js`: the `Word` shim of CR-002 section 3.10.
2
+ //
3
+ // The content API is a structural subset of Office JS's Word types (section 3.4); this makes that
4
+ // executable, so an add-in's `Word.run` callback runs against a package here, in Node or in a
5
+ // browser, with the saved docx as the assertion. It is deliberately not part of the root export:
6
+ // an add-in bundle that wants only the content API never pulls the proxies in.
7
+ //
8
+ // import { Word } from '@docx4j/core-ts/office-js';
9
+ // await Word.run(pkg, async (context) => {
10
+ // const paragraphs = context.document.body.paragraphs;
11
+ // paragraphs.load('text');
12
+ // await context.sync();
13
+ // paragraphs.items[0].font.bold = true;
14
+ // });
15
+ import { run, RequestContext } from './run.mjs';
16
+ import { Document, DocumentProperties } from './document.mjs';
17
+ import { supported, SUBSET_MEMBERS } from './supported.mjs';
18
+ import { ClientResult, unwrap, nullObject, Wrapper } from './proxy.mjs';
19
+ import { NotSupportedError, ItemNotFoundError, ValueNotLoadedError } from './errors.mjs';
20
+ import { toApiScript } from './toApiScript.mjs';
21
+ import { InsertLocation, Alignment, UnderlineType, ChangeTrackingMode, BreakType, ContentControlType, Style, ErrorCodes, SearchOptions, ListLevelType, ListNumbering, ListBullet, } from './enums.mjs';
22
+ export { run, RequestContext, Document, DocumentProperties, ClientResult, unwrap, nullObject, Wrapper, toApiScript, supported, SUBSET_MEMBERS };
23
+ export { NotSupportedError, ItemNotFoundError, ValueNotLoadedError };
24
+ export { InsertLocation, Alignment, UnderlineType, ChangeTrackingMode, BreakType, ContentControlType, Style, ErrorCodes, SearchOptions };
25
+ export { ListLevelType, ListNumbering, ListBullet };
26
+ /**
27
+ * The `Word` namespace an add-in script expects: `Word.run`, the enums, and `Word.supported`, the
28
+ * `Class.member` strings this package implements (so a tool can check a script before running it).
29
+ * `Word.run` takes the package first, since there is no host document.
30
+ */
31
+ export const Word = Object.freeze({
32
+ run,
33
+ supported,
34
+ InsertLocation,
35
+ Alignment,
36
+ UnderlineType,
37
+ ChangeTrackingMode,
38
+ BreakType,
39
+ ContentControlType,
40
+ ListLevelType,
41
+ ListNumbering,
42
+ ListBullet,
43
+ Style,
44
+ ErrorCodes,
45
+ SearchOptions,
46
+ ClientResult,
47
+ RequestContext,
48
+ Document,
49
+ DocumentProperties,
50
+ NotSupportedError,
51
+ ItemNotFoundError,
52
+ ValueNotLoadedError,
53
+ unwrap,
54
+ });
@@ -0,0 +1,72 @@
1
+ import type { ExtraMembers } from './extras.mjs';
2
+ /**
3
+ * The result of an asynchronous call, as Office JS hands one out: `value` after `context.sync()`.
4
+ * It is also awaitable (an extension), so that `await body.insertXml(...)`, which is how the
5
+ * content API and `toApiScript`'s output read, keeps its order through the shim.
6
+ */
7
+ export declare class ClientResult<T = unknown> {
8
+ /** The call this is the result of ('getOoxml'), for the error message. */
9
+ readonly member: string;
10
+ private loaded;
11
+ private result;
12
+ private promise;
13
+ constructor(
14
+ /** The call this is the result of ('getOoxml'), for the error message. */
15
+ member?: string);
16
+ /** @internal the underlying call, which `context.sync()` awaits and `then` delegates to. */
17
+ attach(promise: Promise<T>): void;
18
+ /** Awaiting the result resolves to the value, without waiting for the next sync. */
19
+ then<R1 = T, R2 = never>(onFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null, onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
20
+ /** The value; throws until `context.sync()` has resolved it, as Office JS does. */
21
+ get value(): T;
22
+ /** @internal filled by the context when the underlying promise settles. */
23
+ resolveWith(value: T): void;
24
+ /** True once `context.sync()` has filled it. */
25
+ get isLoaded(): boolean;
26
+ toJSON(): {
27
+ value: T | undefined;
28
+ };
29
+ }
30
+ /** A collection, as the subset types describe one: an array that also answers Office JS's collection members. */
31
+ export interface Collection<T> extends Array<T> {
32
+ /** Office JS's collection property; the same array. */
33
+ readonly items: T[];
34
+ getFirst(): T;
35
+ getFirstOrNullObject(): T;
36
+ getLast(): T;
37
+ getLastOrNullObject(): T;
38
+ getCount(): ClientResult<number>;
39
+ }
40
+ /** What a context must offer the wrapper: somewhere to park the promise of an asynchronous call. */
41
+ export interface PendingSink {
42
+ /** @internal */
43
+ enqueue(promise: Promise<unknown>): void;
44
+ }
45
+ /** The target behind a proxy the shim handed out; anything else is returned as it is. */
46
+ export declare function unwrap<T>(value: T): T;
47
+ /**
48
+ * A null object: `isNullObject` is true and every other member throws, as Office JS's
49
+ * `*OrNullObject` results do.
50
+ */
51
+ export declare function nullObject<T>(className: string): T;
52
+ /**
53
+ * Wraps the views of one `Word.run` in proxies. One wrapper per context, so that the same view
54
+ * gives the same proxy and object identity holds within a batch, as it does in Office JS.
55
+ */
56
+ export declare class Wrapper {
57
+ private readonly context;
58
+ /** Members the shim adds over a view (`getOoxml`), consulted only when the view has none. */
59
+ private readonly extras;
60
+ private readonly cache;
61
+ constructor(context: PendingSink,
62
+ /** Members the shim adds over a view (`getOoxml`), consulted only when the view has none. */
63
+ extras?: ExtraMembers);
64
+ /** Wraps whatever a member returned: a view, an array of views, a promise, or a plain value. */
65
+ value(value: unknown, member?: string): unknown;
66
+ /** The proxy over one view. */
67
+ object<T extends object>(view: T, className?: string): T;
68
+ /** The result of a call: a promise becomes a ClientResult the next sync() fills. */
69
+ result(value: unknown, member: string): unknown;
70
+ /** An array of views as an Office JS collection: the array, plus `items` and the getters. */
71
+ collection<T>(items: T[], member?: string): T[];
72
+ }