@docx4j/core-ts 0.4.0 → 0.6.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 (166) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +34 -3
  3. package/dist/html/convert.mjs +40 -15
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +153 -19
  24. package/dist/model/content/Body.mjs +570 -131
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +202 -19
  27. package/dist/model/content/ContentControl.d.mts +197 -18
  28. package/dist/model/content/ContentControl.mjs +664 -95
  29. package/dist/model/content/Font.d.mts +67 -17
  30. package/dist/model/content/Font.mjs +114 -35
  31. package/dist/model/content/InlinePicture.d.mts +82 -7
  32. package/dist/model/content/InlinePicture.mjs +221 -28
  33. package/dist/model/content/List.mjs +13 -1
  34. package/dist/model/content/Paragraph.d.mts +213 -14
  35. package/dist/model/content/Paragraph.mjs +936 -100
  36. package/dist/model/content/Range.d.mts +242 -11
  37. package/dist/model/content/Range.mjs +975 -119
  38. package/dist/model/content/ResolvedView.d.mts +104 -0
  39. package/dist/model/content/ResolvedView.mjs +596 -0
  40. package/dist/model/content/Table.d.mts +29 -3
  41. package/dist/model/content/Table.mjs +109 -33
  42. package/dist/model/content/TrackedChange.d.mts +301 -16
  43. package/dist/model/content/TrackedChange.mjs +1284 -158
  44. package/dist/model/content/binder.d.mts +2 -1
  45. package/dist/model/content/binder.mjs +48 -1
  46. package/dist/model/content/comments.d.mts +20 -6
  47. package/dist/model/content/comments.mjs +67 -57
  48. package/dist/model/content/generalException.d.mts +18 -0
  49. package/dist/model/content/generalException.mjs +24 -0
  50. package/dist/model/content/index.d.mts +8 -3
  51. package/dist/model/content/index.mjs +7 -2
  52. package/dist/model/content/mathText.d.mts +21 -0
  53. package/dist/model/content/mathText.mjs +267 -0
  54. package/dist/model/content/officeText.d.mts +27 -0
  55. package/dist/model/content/officeText.mjs +74 -0
  56. package/dist/model/content/outline.d.mts +5 -0
  57. package/dist/model/content/outline.mjs +13 -0
  58. package/dist/model/content/placeholders.d.mts +110 -0
  59. package/dist/model/content/placeholders.mjs +253 -0
  60. package/dist/model/content/relationships.d.mts +30 -0
  61. package/dist/model/content/relationships.mjs +133 -0
  62. package/dist/model/content/search.d.mts +72 -0
  63. package/dist/model/content/search.mjs +204 -2
  64. package/dist/model/content/spanEdits.d.mts +159 -0
  65. package/dist/model/content/spanEdits.mjs +728 -0
  66. package/dist/model/content/story.d.mts +44 -0
  67. package/dist/model/content/story.mjs +92 -0
  68. package/dist/model/content/tableColumns.d.mts +1 -1
  69. package/dist/model/content/tableColumns.mjs +108 -80
  70. package/dist/model/content/tableRevisions.d.mts +11 -3
  71. package/dist/model/content/tableRevisions.mjs +72 -42
  72. package/dist/model/content/tableRules.d.mts +30 -0
  73. package/dist/model/content/tableRules.mjs +100 -0
  74. package/dist/model/content/textBoxes.d.mts +18 -0
  75. package/dist/model/content/textBoxes.mjs +105 -0
  76. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  77. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  78. package/dist/model/content/tracking.d.mts +28 -0
  79. package/dist/model/content/tracking.mjs +149 -10
  80. package/dist/model/content/tree.d.mts +212 -13
  81. package/dist/model/content/tree.mjs +356 -35
  82. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  83. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  84. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  85. package/dist/model/customxml/XmlMapping.mjs +11 -0
  86. package/dist/model/customxml/bindings.d.mts +21 -2
  87. package/dist/model/customxml/bindings.mjs +76 -32
  88. package/dist/model/customxml/kinds.d.mts +8 -3
  89. package/dist/model/customxml/kinds.mjs +26 -5
  90. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  91. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  92. package/dist/model/customxml/pictures.d.mts +9 -5
  93. package/dist/model/customxml/pictures.mjs +31 -13
  94. package/dist/model/customxml/xhtml.mjs +8 -2
  95. package/dist/model/fonts/families.generated.mjs +2 -2
  96. package/dist/model/fonts/registry.mjs +7 -1
  97. package/dist/model/fonts/substitutions.generated.mjs +2 -2
  98. package/dist/model/fonts/themes.generated.mjs +1 -1
  99. package/dist/model/index.d.mts +2 -0
  100. package/dist/model/index.mjs +4 -0
  101. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  102. package/dist/model/listnumbering/Emulator.mjs +63 -9
  103. package/dist/model/listnumbering/definitions.mjs +18 -0
  104. package/dist/model/properties/PropertyResolver.d.mts +87 -7
  105. package/dist/model/properties/PropertyResolver.mjs +197 -17
  106. package/dist/model/properties/catalogue.d.mts +32 -4
  107. package/dist/model/properties/catalogue.mjs +115 -36
  108. package/dist/model/properties/log.d.mts +1 -1
  109. package/dist/model/properties/log.mjs +5 -5
  110. package/dist/model/properties/table.d.mts +16 -2
  111. package/dist/model/properties/table.mjs +17 -5
  112. package/dist/model/text/Extractor.d.mts +289 -0
  113. package/dist/model/text/Extractor.mjs +2162 -0
  114. package/dist/model/text/LinkTargets.d.mts +45 -0
  115. package/dist/model/text/LinkTargets.mjs +170 -0
  116. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  117. package/dist/model/text/MarkdownExporter.mjs +255 -0
  118. package/dist/model/text/PlainText.d.mts +29 -0
  119. package/dist/model/text/PlainText.mjs +539 -0
  120. package/dist/model/text/TextContext.d.mts +161 -0
  121. package/dist/model/text/TextContext.mjs +425 -0
  122. package/dist/model/text/TextOptions.d.mts +150 -0
  123. package/dist/model/text/TextOptions.mjs +278 -0
  124. package/dist/model/text/TextResult.d.mts +504 -0
  125. package/dist/model/text/TextResult.mjs +526 -0
  126. package/dist/model/text/Texts.d.mts +99 -0
  127. package/dist/model/text/Texts.mjs +187 -0
  128. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  129. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  130. package/dist/model/text/commonmark.d.mts +121 -0
  131. package/dist/model/text/commonmark.mjs +655 -0
  132. package/dist/model/text/index.d.mts +7 -0
  133. package/dist/model/text/index.mjs +8 -0
  134. package/dist/model/text/normalize.d.mts +8 -0
  135. package/dist/model/text/normalize.mjs +13 -0
  136. package/dist/model/text/outline.d.mts +4 -0
  137. package/dist/model/text/outline.mjs +71 -0
  138. package/dist/office-js/fragment.d.mts +7 -5
  139. package/dist/office-js/fragment.mjs +63 -14
  140. package/dist/office-js/proxy.d.mts +8 -0
  141. package/dist/office-js/proxy.mjs +29 -0
  142. package/dist/office-js/run.mjs +2 -0
  143. package/dist/office-js/supported.generated.mjs +16 -0
  144. package/dist/office-js/toApiScript.mjs +21 -5
  145. package/dist/opc/Load.d.mts +9 -2
  146. package/dist/opc/Save.d.mts +17 -0
  147. package/dist/opc/Save.mjs +12 -2
  148. package/dist/opc/index.d.mts +3 -3
  149. package/dist/opc/index.mjs +2 -2
  150. package/dist/opc/mce/preprocessor.d.mts +88 -7
  151. package/dist/opc/mce/preprocessor.mjs +144 -37
  152. package/dist/opc/mce/understood.d.mts +34 -0
  153. package/dist/opc/mce/understood.mjs +55 -3
  154. package/dist/packages/OpcPackage.d.mts +20 -0
  155. package/dist/packages/OpcPackage.mjs +16 -3
  156. package/dist/packages/WordprocessingMLPackage.d.mts +77 -7
  157. package/dist/packages/WordprocessingMLPackage.mjs +242 -11
  158. package/dist/parts/DefaultXmlPart.mjs +2 -2
  159. package/dist/parts/Part.d.mts +10 -2
  160. package/dist/parts/XmlPart.d.mts +35 -32
  161. package/dist/parts/XmlPart.mjs +107 -107
  162. package/dist/parts/wml/comments.mjs +30 -0
  163. package/dist/parts/wml/index.mjs +12 -0
  164. package/dist/xml/dom.d.mts +7 -0
  165. package/dist/xml/dom.mjs +18 -0
  166. package/package.json +2 -2
@@ -0,0 +1,267 @@
1
+ const MATH_RUN = 'org_docx4j_math.CTR';
2
+ const MATH_TEXT = 'org_docx4j_math.CTText';
3
+ const MATH_RUN_TRACK_CHANGE = 'org_docx4j_wml.CTMathRunTrackChange';
4
+ const CONTROL_PROPERTIES = 'org_docx4j_math.CTCtrlPr';
5
+ /** True for an equation at run-holder level: `m:oMath` or `m:oMathPara`. */
6
+ export function isMath(el) {
7
+ var _a;
8
+ const tn = (_a = el.value) === null || _a === void 0 ? void 0 : _a.TYPE_NAME;
9
+ return tn === 'org_docx4j_math.CTOMath' || tn === 'org_docx4j_math.CTOMathPara';
10
+ }
11
+ /**
12
+ * The text of an equation (`m:oMath`, `m:oMathPara`) in a view: the `m:t` of every math run in document
13
+ * order, a revision's runs as the view has them, a structure the view hides (its `m:ctrlPr`'s revision) left out
14
+ * whole, each letter mapped as Word draws it (`mathLetter`).
15
+ */
16
+ export function mathTextOf(math, view = 'accepted') {
17
+ let out = '';
18
+ const hides = (name) => view === 'accepted' ? name === 'del' || name === 'moveFrom' : name === 'ins' || name === 'moveTo';
19
+ const runText = (run) => {
20
+ var _a, _b, _c, _d;
21
+ const rPr = mathRunProperties(run);
22
+ const add = (text) => { out += styled(String(text !== null && text !== void 0 ? text : ''), rPr); };
23
+ for (const o of (_a = run.content) !== null && _a !== void 0 ? _a : []) {
24
+ const el = o;
25
+ const v = el.value;
26
+ if ((v === null || v === void 0 ? void 0 : v.TYPE_NAME) === MATH_RUN_TRACK_CHANGE) {
27
+ if (hides((_b = el.name) === null || _b === void 0 ? void 0 : _b.localPart))
28
+ continue;
29
+ for (const inner of (_c = v.rest) !== null && _c !== void 0 ? _c : []) {
30
+ const iv = inner.value;
31
+ if ((iv === null || iv === void 0 ? void 0 : iv.TYPE_NAME) === MATH_TEXT)
32
+ add(iv.value);
33
+ }
34
+ continue;
35
+ }
36
+ if ((v === null || v === void 0 ? void 0 : v.TYPE_NAME) === MATH_TEXT)
37
+ add(v.value);
38
+ else if ((v === null || v === void 0 ? void 0 : v.TYPE_NAME) === 'org_docx4j_wml.Text' && ((_d = el.name) === null || _d === void 0 ? void 0 : _d.localPart) === 't')
39
+ add(v.value);
40
+ }
41
+ };
42
+ const visit = (value, depth) => {
43
+ if (typeof value !== 'object' || value === null || depth > 64)
44
+ return;
45
+ if (Array.isArray(value)) {
46
+ for (const v of value)
47
+ visit(v, depth + 1);
48
+ return;
49
+ }
50
+ const named = value;
51
+ if (named.name !== undefined && 'value' in named) {
52
+ if (hides(named.name.localPart) && isRevisionValue(named.value))
53
+ return;
54
+ visit(named.value, depth + 1);
55
+ return;
56
+ }
57
+ const tn = value.TYPE_NAME;
58
+ if (tn === MATH_RUN) {
59
+ runText(value);
60
+ return;
61
+ }
62
+ if (isProperties(tn))
63
+ return;
64
+ if (tn !== undefined && tn.startsWith('org_docx4j_math.') && !CONTAINERS.has(tn)) {
65
+ // a structure the view hides, its own m:ctrlPr holding the revision, goes whole (CR-002 section 62.2, F2)
66
+ if (hidesStructure(value, hides))
67
+ return;
68
+ // a structure: `,`, its arguments joined by `-`, `.` (check 51 case 12)
69
+ out += ',';
70
+ argumentsOf(value).forEach((argument, i) => {
71
+ if (i > 0)
72
+ out += '-';
73
+ visit(argument, depth + 1);
74
+ });
75
+ out += '.';
76
+ return;
77
+ }
78
+ for (const key of Object.keys(value)) {
79
+ if (key === 'PARENT' || key === 'TYPE_NAME')
80
+ continue;
81
+ visit(value[key], depth + 1);
82
+ }
83
+ };
84
+ visit(math, 0);
85
+ return out;
86
+ }
87
+ /**
88
+ * True when a structure is inserted or deleted, in Word's form a `w:ins` or `w:del` in the `m:ctrlPr` of its own
89
+ * properties (`m:sSupPr`, `m:fPr`, ...), and the view hides that revision. An argument's own `m:ctrlPr` marks no
90
+ * structure (CR-002 section 51).
91
+ */
92
+ function hidesStructure(structure, hides) {
93
+ var _a;
94
+ for (const key of Object.keys(structure)) {
95
+ if (key === 'PARENT' || key === 'TYPE_NAME')
96
+ continue;
97
+ const properties = structure[key];
98
+ if (!((_a = properties === null || properties === void 0 ? void 0 : properties.TYPE_NAME) === null || _a === void 0 ? void 0 : _a.endsWith('Pr')) || !properties.ctrlPr)
99
+ continue;
100
+ if ((properties.ctrlPr.del && hides('del')) || (properties.ctrlPr.ins && hides('ins')))
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ /** What holds math elements without being a structure: an equation, a display equation, an argument. */
106
+ const CONTAINERS = new Set(['org_docx4j_math.CTOMath', 'org_docx4j_math.CTOMathPara', 'org_docx4j_math.CTOMathArg']);
107
+ /** A math object's properties (`m:fPr`, `m:radPr`, `m:ctrlPr`, ...): no text. */
108
+ function isProperties(tn) {
109
+ return tn !== undefined && tn.startsWith('org_docx4j_math.') && (tn.endsWith('Pr') || tn === CONTROL_PROPERTIES);
110
+ }
111
+ /**
112
+ * A structure's arguments (`m:e`, `m:num`, `m:den`, `m:sub`, `m:sup`, `m:deg`, `m:lim`, `m:fName`) in schema
113
+ * order, a matrix's rows' arguments in turn, and a radical's degree left out where `m:degHide` hides it.
114
+ */
115
+ function argumentsOf(structure) {
116
+ var _a;
117
+ const out = [];
118
+ const degHidden = on((_a = structure.radPr) === null || _a === void 0 ? void 0 : _a.degHide);
119
+ const take = (v) => {
120
+ var _a;
121
+ if (typeof v !== 'object' || v === null)
122
+ return;
123
+ if (Array.isArray(v)) {
124
+ for (const o of v)
125
+ take(o);
126
+ return;
127
+ }
128
+ const named = v;
129
+ const value = (named.name !== undefined && 'value' in named ? named.value : v);
130
+ if ((value === null || value === void 0 ? void 0 : value.TYPE_NAME) === 'org_docx4j_math.CTOMathArg') {
131
+ out.push(value);
132
+ return;
133
+ }
134
+ if (isProperties(value === null || value === void 0 ? void 0 : value.TYPE_NAME))
135
+ return;
136
+ if ((_a = value === null || value === void 0 ? void 0 : value.TYPE_NAME) === null || _a === void 0 ? void 0 : _a.startsWith('org_docx4j_math.')) {
137
+ for (const key of Object.keys(value))
138
+ if (key !== 'PARENT' && key !== 'TYPE_NAME')
139
+ take(value[key]);
140
+ }
141
+ };
142
+ for (const key of Object.keys(structure)) {
143
+ if (key === 'PARENT' || key === 'TYPE_NAME' || (key === 'deg' && degHidden))
144
+ continue;
145
+ take(structure[key]);
146
+ }
147
+ return out;
148
+ }
149
+ /** An `m:` on/off property: present and not `0`, `false` or `off`. */
150
+ function on(property) {
151
+ return property !== undefined && property !== null && property.val !== false && property.val !== 'off' && property.val !== '0' && property.val !== 0;
152
+ }
153
+ /** A `w:ins`, `w:del` or `w:move*` around math runs. */
154
+ function isRevisionValue(value) {
155
+ const tn = value === null || value === void 0 ? void 0 : value.TYPE_NAME;
156
+ return tn === 'org_docx4j_wml.RunIns' || tn === 'org_docx4j_wml.RunDel' || tn === 'org_docx4j_wml.RunTrackChange' || tn === MATH_RUN_TRACK_CHANGE;
157
+ }
158
+ function mathRunProperties(run) {
159
+ var _a, _b, _c;
160
+ for (const o of (_a = run.content) !== null && _a !== void 0 ? _a : []) {
161
+ const v = o.value;
162
+ if ((v === null || v === void 0 ? void 0 : v.TYPE_NAME) === 'org_docx4j_math.CTRPR')
163
+ return { sty: (_b = v.sty) === null || _b === void 0 ? void 0 : _b.val, scr: (_c = v.scr) === null || _c === void 0 ? void 0 : _c.val, nor: on(v.nor) };
164
+ }
165
+ return { nor: false };
166
+ }
167
+ function styled(text, rPr) {
168
+ if (rPr.nor)
169
+ return text; // normal text: as the run's w:rPr draws it (check 51 case 11)
170
+ let out = '';
171
+ for (const c of text)
172
+ out += c === '-' ? '\u2212' : mathLetter(c, rPr.sty, rPr.scr); // a minus sign (check 51 case 6)
173
+ return out;
174
+ }
175
+ // Unicode's Mathematical Alphanumeric Symbols: each alphabet's capital A and small a, its digit zero
176
+ // where it has digits, and its Greek block (capitals, nabla, smalls, then the variants).
177
+ const LATIN = {
178
+ bold: [0x1D400, 0x1D41A], italic: [0x1D434, 0x1D44E], boldItalic: [0x1D468, 0x1D482],
179
+ script: [0x1D49C, 0x1D4B6], boldScript: [0x1D4D0, 0x1D4EA], fraktur: [0x1D504, 0x1D51E],
180
+ doubleStruck: [0x1D538, 0x1D552], boldFraktur: [0x1D56C, 0x1D586], sans: [0x1D5A0, 0x1D5BA],
181
+ sansBold: [0x1D5D4, 0x1D5EE], sansItalic: [0x1D608, 0x1D622], sansBoldItalic: [0x1D63C, 0x1D656],
182
+ monospace: [0x1D670, 0x1D68A],
183
+ };
184
+ const DIGITS = { bold: 0x1D7CE, doubleStruck: 0x1D7D8, sans: 0x1D7E2, sansBold: 0x1D7EC, monospace: 0x1D7F6 };
185
+ const GREEK = { bold: 0x1D6A8, italic: 0x1D6E2, boldItalic: 0x1D71C, sansBold: 0x1D756, sansBoldItalic: 0x1D790 };
186
+ /** The letters Unicode left where they were before the block: the BMP's letterlike symbols. */
187
+ const HOLES = {
188
+ italic: { h: 0x210E },
189
+ script: { B: 0x212C, E: 0x2130, F: 0x2131, H: 0x210B, I: 0x2110, L: 0x2112, M: 0x2133, R: 0x211B, e: 0x212F, g: 0x210A, o: 0x2134 },
190
+ fraktur: { C: 0x212D, H: 0x210C, I: 0x2111, R: 0x211C, Z: 0x2128 },
191
+ doubleStruck: { C: 0x2102, H: 0x210D, N: 0x2115, P: 0x2119, Q: 0x211A, R: 0x211D, Z: 0x2124 },
192
+ };
193
+ /** A Greek letter's place in an alphabet's Greek block of 58. */
194
+ function greekIndex(cp) {
195
+ if (cp >= 0x391 && cp <= 0x3A1)
196
+ return cp - 0x391; // Alpha to Rho
197
+ if (cp === 0x3F4)
198
+ return 17; // capital theta symbol
199
+ if (cp >= 0x3A3 && cp <= 0x3A9)
200
+ return cp - 0x3A3 + 18; // Sigma to Omega
201
+ if (cp === 0x2207)
202
+ return 25; // nabla
203
+ if (cp >= 0x3B1 && cp <= 0x3C9)
204
+ return cp - 0x3B1 + 26; // alpha to omega, final sigma among them
205
+ const variants = { 0x2202: 51, 0x3F5: 52, 0x3D1: 53, 0x3F0: 54, 0x3D5: 55, 0x3F1: 56, 0x3D6: 57 };
206
+ return variants[cp];
207
+ }
208
+ /**
209
+ * A character as Word draws it in a math run with this `m:sty` (`p`, `b`, `i`, `bi`; none is Word's default,
210
+ * italic) and `m:scr` (`roman`, the default, `script`, `fraktur`, `double-struck`, `sans-serif`,
211
+ * `monospace`), as check 51 measured: letters, Greek capitals, small letters and nabla alike, in the
212
+ * alphabet of the style and script; digits upright in the script's family (bold for bold or bold italic,
213
+ * sans-serif under sans-serif, none of their own in script or fraktur); a character no alphabet has is
214
+ * itself.
215
+ */
216
+ export function mathLetter(c, sty, scr) {
217
+ var _a;
218
+ const cp = c.codePointAt(0);
219
+ const bold = sty === 'b' || sty === 'bi';
220
+ const italic = sty === undefined || sty === 'i' || sty === 'bi';
221
+ let alphabet;
222
+ let digits;
223
+ switch (scr !== null && scr !== void 0 ? scr : 'roman') {
224
+ case 'roman':
225
+ alphabet = bold ? (italic ? 'boldItalic' : 'bold') : italic ? 'italic' : undefined;
226
+ digits = bold ? 'bold' : undefined;
227
+ break;
228
+ case 'script':
229
+ alphabet = bold ? 'boldScript' : 'script';
230
+ break;
231
+ case 'fraktur':
232
+ alphabet = bold ? 'boldFraktur' : 'fraktur';
233
+ break;
234
+ case 'double-struck':
235
+ alphabet = 'doubleStruck';
236
+ digits = 'doubleStruck';
237
+ break;
238
+ case 'sans-serif':
239
+ alphabet = bold ? (italic ? 'sansBoldItalic' : 'sansBold') : italic ? 'sansItalic' : 'sans';
240
+ digits = bold ? 'sansBold' : 'sans';
241
+ break;
242
+ case 'monospace':
243
+ alphabet = 'monospace';
244
+ digits = 'monospace';
245
+ break;
246
+ default: alphabet = undefined;
247
+ }
248
+ if (cp >= 0x30 && cp <= 0x39) {
249
+ const zero = digits === undefined ? undefined : DIGITS[digits];
250
+ return zero === undefined ? c : String.fromCodePoint(zero + cp - 0x30);
251
+ }
252
+ if (alphabet === undefined)
253
+ return c;
254
+ const hole = (_a = HOLES[alphabet]) === null || _a === void 0 ? void 0 : _a[c];
255
+ if (hole !== undefined)
256
+ return String.fromCodePoint(hole);
257
+ const latin = LATIN[alphabet];
258
+ if (cp >= 0x41 && cp <= 0x5A)
259
+ return String.fromCodePoint(latin[0] + cp - 0x41);
260
+ if (cp >= 0x61 && cp <= 0x7A)
261
+ return String.fromCodePoint(latin[1] + cp - 0x61);
262
+ const g = greekIndex(cp);
263
+ if (g === undefined)
264
+ return c;
265
+ const base = GREEK[alphabet];
266
+ return base === undefined ? c : String.fromCodePoint(base + g);
267
+ }
@@ -0,0 +1,27 @@
1
+ import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
2
+ import { type Element } from './tree.mjs';
3
+ /** The text without the characters XML 1.0 excludes (E3). */
4
+ export declare function dropExcluded(text: string): string;
5
+ /** True when the text holds a character a writer writes as an element. */
6
+ export declare function holdsElementCharacters(text: string): boolean;
7
+ /**
8
+ * How a writer takes a line feed and a carriage return:
9
+ * - `paragraphs`: a paragraph break each, `\r\n` one (E1: `insertText` and every writer through `Paragraph.splice`);
10
+ * the caller splits the text into lines (`linesOf`);
11
+ * - `one-paragraph`: `\n` and `\r\n` a `w:br`, `\r` a `w:cr` (E2: `insertParagraph`, `Paragraph.text =`), a recorded
12
+ * departure from Word, which writes their escapes as text;
13
+ * - `multi-line`: each a `w:br` (a multi-line plain-text control, or a bound block control of one: section 61 item 3);
14
+ * - `single-line`: none, and no break either (a single-line plain-text control: F3).
15
+ */
16
+ export type LineBreaks = 'paragraphs' | 'one-paragraph' | 'multi-line' | 'single-line';
17
+ /** The text a writer of that kind writes, its line feeds and carriage returns turned into its characters. */
18
+ export declare function forWriter(text: string, lineBreaks: LineBreaks): string;
19
+ /** The text's lines, at each line feed, carriage return or `\r\n` (E1). */
20
+ export declare function linesOf(text: string): string[];
21
+ /** A run's items for a text: a `w:t` for each plain stretch, the element each mapped character reads as. */
22
+ export declare function officeItems(text: string): Element[];
23
+ /**
24
+ * A run of text a writer keeps in one paragraph (E2: `insertParagraph`, `Paragraph.text =`), or in a plain-text control
25
+ * as its kind takes it: the excluded characters dropped, every other character that is an element written as it.
26
+ */
27
+ export declare function oneParagraphRun(text: string, rPr?: wml.RPr, lineBreaks?: LineBreaks): Element<wml.R>;
@@ -0,0 +1,74 @@
1
+ // Office JS's characters written back (CR-002 section 60). The readers give Word's character stream (CR-012 phase 4,
2
+ // `officeItemText`): a `w:br` U+000B, a page break U+000C, a column break U+000E, a `w:cr` U+000D, the non-breaking and
3
+ // optional hyphens U+001E and U+001F, a note reference U+0002. A writer turns each back into the element it reads as
4
+ // (D1, as Word 365's writers do in check 55), drops the characters XML 1.0 excludes (E3: Word drops them too), and
5
+ // takes a line feed or carriage return as its kind of writer does: a paragraph break for `insertText` (E1), a break
6
+ // for `insertParagraph` (E2), a break or nothing in a bound or plain-text control (section 61 item 3, F3).
7
+ import * as el from '@docx4j/generated-objects-ts/el/org_docx4j_wml';
8
+ import { t as textItem, br as breakItem, tab as tabItem } from '@docx4j/generated-objects-ts/builders/wml';
9
+ import { runOf } from './tree.mjs';
10
+ /**
11
+ * The characters XML 1.0 excludes that are no element: U+0002 (a note reference, which no text makes) and the other C0
12
+ * controls but tab, line feed, carriage return and the five that are elements, U+FFFE, U+FFFF and an unpaired surrogate.
13
+ */
14
+ const EXCLUDED = /[\u0000-\u0008\u000F-\u001D￾￿]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
15
+ /** The characters a writer writes as elements: tab, the three breaks, a carriage return, a line feed, the two hyphens. */
16
+ const ELEMENT_CHARACTERS = /[\t\n\r\u000B\u000C\u000E\u001E\u001F]/;
17
+ /** The text without the characters XML 1.0 excludes (E3). */
18
+ export function dropExcluded(text) {
19
+ return text.replace(EXCLUDED, '');
20
+ }
21
+ /** True when the text holds a character a writer writes as an element. */
22
+ export function holdsElementCharacters(text) {
23
+ return ELEMENT_CHARACTERS.test(text);
24
+ }
25
+ /** The text a writer of that kind writes, its line feeds and carriage returns turned into its characters. */
26
+ export function forWriter(text, lineBreaks) {
27
+ switch (lineBreaks) {
28
+ case 'one-paragraph': return text.replace(/\r\n|\n/g, '\u000B');
29
+ case 'multi-line': return text.replace(/\r\n|\r|\n/g, '\u000B');
30
+ case 'single-line': return text.replace(/\r\n|[\r\n\u000B\u000C\u000E]/g, '');
31
+ default: return text;
32
+ }
33
+ }
34
+ /** The text's lines, at each line feed, carriage return or `\r\n` (E1). */
35
+ export function linesOf(text) {
36
+ return text.split(/\r\n|\r|\n/);
37
+ }
38
+ /** The element a character reads as (`officeItemText` in reverse); a line feed a `w:br`. */
39
+ function elementFor(c) {
40
+ switch (c) {
41
+ case '\t': return tabItem();
42
+ case '\u000C': return breakItem('page');
43
+ case '\u000E': return breakItem('column');
44
+ case '\r': return el.cr({});
45
+ case '\u001E': return el.noBreakHyphen({});
46
+ case '\u001F': return el.softHyphen({});
47
+ default: return breakItem(); // U+000B, and a line feed a writer left
48
+ }
49
+ }
50
+ /** A run's items for a text: a `w:t` for each plain stretch, the element each mapped character reads as. */
51
+ export function officeItems(text) {
52
+ const out = [];
53
+ let plain = '';
54
+ for (const c of text) {
55
+ if (ELEMENT_CHARACTERS.test(c)) {
56
+ if (plain !== '')
57
+ out.push(textItem(plain));
58
+ plain = '';
59
+ out.push(elementFor(c));
60
+ }
61
+ else
62
+ plain += c;
63
+ }
64
+ if (plain !== '')
65
+ out.push(textItem(plain));
66
+ return out;
67
+ }
68
+ /**
69
+ * A run of text a writer keeps in one paragraph (E2: `insertParagraph`, `Paragraph.text =`), or in a plain-text control
70
+ * as its kind takes it: the excluded characters dropped, every other character that is an element written as it.
71
+ */
72
+ export function oneParagraphRun(text, rPr, lineBreaks = 'one-paragraph') {
73
+ return runOf(officeItems(forWriter(dropExcluded(text), lineBreaks)), rPr);
74
+ }
@@ -0,0 +1,5 @@
1
+ import type { Body, Outline } from './Body.mjs';
2
+ /** What `Body.outline` asks of the text model: the outline of a body, or of its top-level blocks at these indices, under these options and context. */
3
+ export type OutlineReader = (body: Body, options: unknown, context: unknown, blocks?: readonly number[]) => Promise<Outline>;
4
+ export declare function setOutlineReader(implementation: OutlineReader): void;
5
+ export declare function outlineReader(): OutlineReader;
@@ -0,0 +1,13 @@
1
+ // The outline's reader (CR-012 D3): the text model's, which this module can't import, since the text model
2
+ // imports the content API. The text model registers it (`model/text/outline.mts`), and the package classes
3
+ // load that module, as the comment parts register themselves (CR-002 phase G).
4
+ import { Docx4JException } from '../../opc/exceptions.mjs';
5
+ let reader;
6
+ export function setOutlineReader(implementation) {
7
+ reader = implementation;
8
+ }
9
+ export function outlineReader() {
10
+ if (!reader)
11
+ throw new Docx4JException('The text model is not loaded: import @docx4j/core-ts, @docx4j/core-ts/model or @docx4j/core-ts/packages');
12
+ return reader;
13
+ }
@@ -0,0 +1,110 @@
1
+ import type * as wml from '@docx4j/generated-objects-ts/modules/org_docx4j_wml';
2
+ import { type Element } from './tree.mjs';
3
+ import type { XmlPart } from '../../parts/XmlPart.mjs';
4
+ import type { Part } from '../../parts/Part.mjs';
5
+ /** Word's default placeholder entry, which a control Word makes names (checks 64 to 66). */
6
+ export declare const DEFAULT_PLACEHOLDER_ENTRY = "DefaultPlaceholder_-1854013440";
7
+ /** The default entry's text, as Word 365 writes it. */
8
+ export declare const DEFAULT_PLACEHOLDER_TEXT = "Click or tap here to enter text.";
9
+ /** A default placeholder entry: its name and its text. */
10
+ export interface DefaultEntry {
11
+ name: string;
12
+ text: string;
13
+ }
14
+ /**
15
+ * Word's default placeholder entry for each kind of control that has one, as Word 365 makes them from the Developer tab
16
+ * (Jason's `placeholders.docx`, 2026-10-25; CR-002 section 63.22, as docx4j's CR-063 D8 has it): each in the glossary
17
+ * with the default entry's `w:docPartPr`, its body one run in the Placeholder Text style. A picture, a check box and a
18
+ * repeating section have none; the group, citation, equation, bibliography and `w:docPartObj` kinds are unmeasured.
19
+ */
20
+ export declare const DEFAULT_ENTRIES: {
21
+ readonly text: {
22
+ readonly name: "DefaultPlaceholder_-1854013440";
23
+ readonly text: "Click or tap here to enter text.";
24
+ };
25
+ readonly date: {
26
+ readonly name: "DefaultPlaceholder_-1854013437";
27
+ readonly text: "Click or tap to enter a date.";
28
+ };
29
+ readonly list: {
30
+ readonly name: "DefaultPlaceholder_-1854013438";
31
+ readonly text: "Choose an item.";
32
+ };
33
+ readonly buildingBlock: {
34
+ readonly name: "DefaultPlaceholder_-1854013436";
35
+ readonly text: "Choose a building block.";
36
+ };
37
+ readonly repeatingSectionItem: {
38
+ readonly name: "DefaultPlaceholder_-1854013435";
39
+ readonly text: "Enter any content that you want to repeat, including other content controls. You can also insert this control around table rows in order to repeat parts of a table.";
40
+ };
41
+ };
42
+ /** The default entry Word gives a control of this kind (`DEFAULT_ENTRIES`); undefined for a kind it gives none. */
43
+ export declare function defaultEntryFor(sdtPr: wml.SdtPr | undefined): DefaultEntry | undefined;
44
+ /** The glossary entry a control's `w:placeholder` names; undefined where it names none (the bare form). */
45
+ export declare function placeholderEntryOf(sdtPr: wml.SdtPr | undefined): string | undefined;
46
+ /**
47
+ * Names `entry` in the control's `w:placeholder`, where Word writes it: after `w:id`, before `w:showingPlcHdr` and the
48
+ * binding (check 64's controls, as Word saved them).
49
+ */
50
+ export declare function namePlaceholderEntry(sdtPr: wml.SdtPr, entry: string): void;
51
+ /** A new entry's name, as Word names one: 32 upper-case hex digits, a new GUID's (check 65). */
52
+ export declare function newEntryName(): string;
53
+ /** What a package's glossary gives: an entry's text by name. */
54
+ export interface GlossaryHost {
55
+ getMainDocumentPart(): {
56
+ glossaryDocumentPart: XmlPart<wml.GlossaryDocument> | undefined;
57
+ addTargetPart(part: Part): unknown;
58
+ };
59
+ }
60
+ /**
61
+ * The placeholder entries of a package's glossary: those its glossary document part holds, read privately (the part
62
+ * stays untouched), and those written since, which go into the glossary when the package is saved (`flush`).
63
+ */
64
+ export declare class GlossaryEntries {
65
+ /** Entries by name, as the glossary part was last read; undefined until `load`. */
66
+ private read;
67
+ /** The part they were read from. */
68
+ private source;
69
+ /** Entries to write on save: name, text. */
70
+ private readonly pending;
71
+ /** Reads the glossary's entries, privately; again only where the part changed. */
72
+ load(glossary: XmlPart<wml.GlossaryDocument> | undefined): Promise<void>;
73
+ /**
74
+ * An entry's text, `null` where neither the glossary nor this session holds it, as Office JS reads it (check 65). An
75
+ * entry's paragraphs are a `\r` apart, as a control's are.
76
+ */
77
+ textOf(name: string): string | null;
78
+ /**
79
+ * An entry's body, the blocks of its `w:docPartBody` (not copies), `null` where neither the glossary nor this session
80
+ * holds it; an entry written this session is one paragraph, one run of its text in the Placeholder Text style.
81
+ */
82
+ bodyOf(name: string): Element[] | null;
83
+ /** True once the glossary has been read (`load`): until then an entry it holds reads as missing. */
84
+ get loaded(): boolean;
85
+ private entry;
86
+ /** Whether the glossary holds an entry of this name, or one is waiting to be written. */
87
+ has(name: string): boolean;
88
+ /** An entry to write on save, where the glossary doesn't hold one of that name. */
89
+ require(name: string, text: string): void;
90
+ /** True while entries wait for the save. */
91
+ get waiting(): boolean;
92
+ /** Entries waiting for the save, for a clone. */
93
+ copyTo(target: GlossaryEntries): void;
94
+ /**
95
+ * Writes the waiting entries into the glossary, making it where the file has none (D9 (a): the glossary document
96
+ * part and a styles part holding Placeholder Text, related from it), and puts Placeholder Text into a glossary's
97
+ * styles part that lacks it: an entry whose style its glossary lacks loses it in Word's save (check 65's 65b).
98
+ */
99
+ flush(host: GlossaryHost, make: {
100
+ glossary: () => XmlPart<wml.GlossaryDocument>;
101
+ styles: () => XmlPart<wml.Styles>;
102
+ }): Promise<void>;
103
+ }
104
+ /**
105
+ * What a control shows of an entry (CR-002 section 63.18, as revised by 63.21): a copy of each of its body's paragraphs'
106
+ * run-level content, every run as the glossary holds it. Word brought an entry back so, the control's own run properties
107
+ * not over it (check 68, cases 21 to 24), and doesn't restyle it (check 65's 65b, case 9). The paragraphs' properties stay
108
+ * in the glossary, whose styles they name.
109
+ */
110
+ export declare function entryContentOf(body: Element[]): Element[][];