@docx4j/core-ts 0.5.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 (155) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +32 -4
  3. package/dist/html/convert.mjs +2 -1
  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 +145 -23
  24. package/dist/model/content/Body.mjs +509 -141
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +195 -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 +11 -0
  32. package/dist/model/content/InlinePicture.mjs +21 -1
  33. package/dist/model/content/List.mjs +3 -0
  34. package/dist/model/content/Paragraph.d.mts +189 -13
  35. package/dist/model/content/Paragraph.mjs +870 -74
  36. package/dist/model/content/Range.d.mts +227 -12
  37. package/dist/model/content/Range.mjs +785 -59
  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 +172 -13
  43. package/dist/model/content/TrackedChange.mjs +728 -167
  44. package/dist/model/content/comments.d.mts +20 -6
  45. package/dist/model/content/comments.mjs +67 -57
  46. package/dist/model/content/generalException.d.mts +18 -0
  47. package/dist/model/content/generalException.mjs +24 -0
  48. package/dist/model/content/index.d.mts +8 -3
  49. package/dist/model/content/index.mjs +7 -2
  50. package/dist/model/content/mathText.d.mts +21 -0
  51. package/dist/model/content/mathText.mjs +267 -0
  52. package/dist/model/content/officeText.d.mts +27 -0
  53. package/dist/model/content/officeText.mjs +74 -0
  54. package/dist/model/content/outline.d.mts +5 -0
  55. package/dist/model/content/outline.mjs +13 -0
  56. package/dist/model/content/placeholders.d.mts +110 -0
  57. package/dist/model/content/placeholders.mjs +253 -0
  58. package/dist/model/content/search.d.mts +72 -0
  59. package/dist/model/content/search.mjs +204 -2
  60. package/dist/model/content/spanEdits.d.mts +159 -0
  61. package/dist/model/content/spanEdits.mjs +728 -0
  62. package/dist/model/content/story.d.mts +44 -0
  63. package/dist/model/content/story.mjs +92 -0
  64. package/dist/model/content/tableColumns.d.mts +1 -1
  65. package/dist/model/content/tableColumns.mjs +108 -80
  66. package/dist/model/content/tableRevisions.d.mts +11 -3
  67. package/dist/model/content/tableRevisions.mjs +72 -42
  68. package/dist/model/content/tableRules.d.mts +30 -0
  69. package/dist/model/content/tableRules.mjs +100 -0
  70. package/dist/model/content/textBoxes.d.mts +18 -0
  71. package/dist/model/content/textBoxes.mjs +105 -0
  72. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  73. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  74. package/dist/model/content/tracking.d.mts +28 -0
  75. package/dist/model/content/tracking.mjs +149 -10
  76. package/dist/model/content/tree.d.mts +171 -22
  77. package/dist/model/content/tree.mjs +329 -53
  78. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  79. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  80. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  81. package/dist/model/customxml/XmlMapping.mjs +11 -0
  82. package/dist/model/customxml/bindings.d.mts +21 -2
  83. package/dist/model/customxml/bindings.mjs +76 -32
  84. package/dist/model/customxml/kinds.d.mts +8 -3
  85. package/dist/model/customxml/kinds.mjs +26 -5
  86. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  87. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  88. package/dist/model/customxml/pictures.d.mts +4 -3
  89. package/dist/model/customxml/pictures.mjs +18 -6
  90. package/dist/model/customxml/xhtml.mjs +8 -2
  91. package/dist/model/index.d.mts +2 -0
  92. package/dist/model/index.mjs +4 -0
  93. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  94. package/dist/model/listnumbering/Emulator.mjs +63 -9
  95. package/dist/model/properties/PropertyResolver.d.mts +60 -1
  96. package/dist/model/properties/PropertyResolver.mjs +115 -2
  97. package/dist/model/properties/catalogue.d.mts +19 -5
  98. package/dist/model/properties/catalogue.mjs +41 -15
  99. package/dist/model/properties/log.d.mts +1 -1
  100. package/dist/model/properties/log.mjs +5 -5
  101. package/dist/model/properties/table.mjs +4 -2
  102. package/dist/model/text/Extractor.d.mts +289 -0
  103. package/dist/model/text/Extractor.mjs +2162 -0
  104. package/dist/model/text/LinkTargets.d.mts +45 -0
  105. package/dist/model/text/LinkTargets.mjs +170 -0
  106. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  107. package/dist/model/text/MarkdownExporter.mjs +255 -0
  108. package/dist/model/text/PlainText.d.mts +29 -0
  109. package/dist/model/text/PlainText.mjs +539 -0
  110. package/dist/model/text/TextContext.d.mts +161 -0
  111. package/dist/model/text/TextContext.mjs +425 -0
  112. package/dist/model/text/TextOptions.d.mts +150 -0
  113. package/dist/model/text/TextOptions.mjs +278 -0
  114. package/dist/model/text/TextResult.d.mts +504 -0
  115. package/dist/model/text/TextResult.mjs +526 -0
  116. package/dist/model/text/Texts.d.mts +99 -0
  117. package/dist/model/text/Texts.mjs +187 -0
  118. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  119. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  120. package/dist/model/text/commonmark.d.mts +121 -0
  121. package/dist/model/text/commonmark.mjs +655 -0
  122. package/dist/model/text/index.d.mts +7 -0
  123. package/dist/model/text/index.mjs +8 -0
  124. package/dist/model/text/normalize.d.mts +8 -0
  125. package/dist/model/text/normalize.mjs +13 -0
  126. package/dist/model/text/outline.d.mts +4 -0
  127. package/dist/model/text/outline.mjs +71 -0
  128. package/dist/office-js/fragment.d.mts +7 -5
  129. package/dist/office-js/fragment.mjs +63 -14
  130. package/dist/office-js/proxy.d.mts +8 -0
  131. package/dist/office-js/proxy.mjs +29 -0
  132. package/dist/office-js/run.mjs +2 -0
  133. package/dist/office-js/supported.generated.mjs +16 -0
  134. package/dist/office-js/toApiScript.mjs +21 -5
  135. package/dist/opc/Save.d.mts +17 -0
  136. package/dist/opc/Save.mjs +12 -2
  137. package/dist/opc/index.d.mts +3 -3
  138. package/dist/opc/index.mjs +1 -1
  139. package/dist/opc/mce/preprocessor.d.mts +28 -3
  140. package/dist/opc/mce/preprocessor.mjs +4 -4
  141. package/dist/opc/mce/understood.d.mts +30 -6
  142. package/dist/opc/mce/understood.mjs +37 -7
  143. package/dist/packages/OpcPackage.d.mts +13 -0
  144. package/dist/packages/OpcPackage.mjs +1 -0
  145. package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
  146. package/dist/packages/WordprocessingMLPackage.mjs +155 -20
  147. package/dist/parts/DefaultXmlPart.mjs +2 -2
  148. package/dist/parts/Part.d.mts +10 -2
  149. package/dist/parts/XmlPart.d.mts +12 -30
  150. package/dist/parts/XmlPart.mjs +44 -93
  151. package/dist/parts/wml/comments.mjs +30 -0
  152. package/dist/parts/wml/index.mjs +12 -0
  153. package/dist/xml/dom.d.mts +7 -0
  154. package/dist/xml/dom.mjs +18 -0
  155. package/package.json +2 -2
@@ -3,7 +3,7 @@ import type * as w15 from '@docx4j/generated-objects-ts/modules/org_docx4j_w15';
3
3
  import type * as w16cid from '@docx4j/generated-objects-ts/modules/org_docx4j_w16cid';
4
4
  import type { XmlCalendar } from '@docx4j/generated-objects-ts';
5
5
  import type { XmlPart } from '../../parts/XmlPart.mjs';
6
- import { type Element } from './tree.mjs';
6
+ import { type BranchMode, type HiddenRuns, type Element } from './tree.mjs';
7
7
  import type { Body } from './Body.mjs';
8
8
  import type { Paragraph } from './Paragraph.mjs';
9
9
  import type { Range } from './Range.mjs';
@@ -92,6 +92,14 @@ export interface CommentParts {
92
92
  ensureCommentsEx(): w15.CTCommentsEx;
93
93
  /** Loads and creates the side parts the bookkeeping needs (w15, w16cid; w16cex only if present). */
94
94
  ensureAll(): Promise<CommentParts>;
95
+ /** Loads the side parts the document has, creating none: what removing a comment needs. */
96
+ loadExisting(): Promise<CommentParts>;
97
+ /**
98
+ * Takes the comments part and its commentsExtended, commentsIds and commentsExtensible parts out of
99
+ * the package, with their relationships, and the people part too when `people` is true. A part
100
+ * another relationship still targets stays.
101
+ */
102
+ drop(people: boolean): void;
95
103
  }
96
104
  /** How the content API reaches the comment parts; implemented and registered by `src/parts/wml/comments.mts`. */
97
105
  export interface CommentPartsAccess {
@@ -130,11 +138,13 @@ export interface CommentMarker {
130
138
  }
131
139
  /**
132
140
  * Every comment marker under a container (a body, a cell, a paragraph), in document order.
133
- * Deleted content (`w:del`) is not entered, as the text model does not enter it either.
141
+ * Deleted content (`w:del`) is not entered, as the text model does not enter it either. A kept
142
+ * `mc:AlternateContent` at block, row or cell level is read as `mode` says (CR-013 phase 2): a reader's
143
+ * walk takes its selected branch, an edit's (`removeMarkers`, the ids) every branch.
134
144
  */
135
- export declare function markersOf(container: object): CommentMarker[];
136
- /** The markers of one paragraph, with their offsets in its text. */
137
- export declare function markersOfParagraph(element: Element<wml.P>, container: Element[]): CommentMarker[];
145
+ export declare function markersOf(container: object, hidden?: (p: wml.P) => HiddenRuns, mode?: BranchMode): CommentMarker[];
146
+ /** The markers of one paragraph, with their offsets in its text (`Paragraph.text` where `hidden` is its `hiddenRuns()`). */
147
+ export declare function markersOfParagraph(element: Element<wml.P>, container: Element[], hidden?: HiddenRuns): CommentMarker[];
138
148
  /** The comment ids under a container, in document order, first occurrence first. */
139
149
  export declare function commentIdsOf(container: object): number[];
140
150
  /** Removes every marker of a comment from a body, and the reference run when nothing is left in it. */
@@ -143,7 +153,11 @@ export declare function removeMarkers(container: object, id: number): void;
143
153
  export declare function nextCommentId(comments: wml.Comments, container: object): number;
144
154
  /** An 8 hex digit id, as Word writes `w14:paraId` and `w16cid:durableId` (never 0, high bit clear). */
145
155
  export declare function randomHexId(taken: (id: string) => boolean): string;
146
- /** The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. */
156
+ /**
157
+ * The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. A kept
158
+ * `mc:AlternateContent` before any paragraph is read in its selected branch, as Word reads it (CR-013
159
+ * phase 3; docx4j's `Trees.lastParaId` looks into the branch the same way).
160
+ */
147
161
  export declare function commentParaId(comment: wml.Comments.Comment): string | undefined;
148
162
  /** True when a paragraph id is already used by a comment or by a paragraph of the document. */
149
163
  export declare function paraIdTaken(parts: CommentParts, container: object, id: string): boolean;
@@ -1,5 +1,5 @@
1
1
  import { Docx4JException } from '../../opc/exceptions.mjs';
2
- import { typeNameOf, childrenOf, runItemsOf, itemTextOf, revisionKindOf, RUN_HOLDERS } from './tree.mjs';
2
+ import { typeNameOf, childrenOf, segmentsOf, rowsOf, cellsOf, branchesOf, selectedBranchOf, ALTERNATE_CONTENT } from './tree.mjs';
3
3
  /** The style Word gives a comment's paragraphs. */
4
4
  export const COMMENT_TEXT_STYLE = 'CommentText';
5
5
  /** The character style of the annotation reference run, in the comment and in the body. */
@@ -34,64 +34,51 @@ const COMMENT_RANGE_END = 'org_docx4j_wml.CommentRangeEnd';
34
34
  const COMMENT_REFERENCE = 'org_docx4j_wml.R.CommentReference';
35
35
  /**
36
36
  * Every comment marker under a container (a body, a cell, a paragraph), in document order.
37
- * Deleted content (`w:del`) is not entered, as the text model does not enter it either.
37
+ * Deleted content (`w:del`) is not entered, as the text model does not enter it either. A kept
38
+ * `mc:AlternateContent` at block, row or cell level is read as `mode` says (CR-013 phase 2): a reader's
39
+ * walk takes its selected branch, an edit's (`removeMarkers`, the ids) every branch.
38
40
  */
39
- export function markersOf(container) {
41
+ export function markersOf(container, hidden, mode = 'read') {
40
42
  const out = [];
41
- collect(out, container);
43
+ collect(out, container, undefined, hidden, mode);
42
44
  return out;
43
45
  }
44
- /** The markers of one paragraph, with their offsets in its text. */
45
- export function markersOfParagraph(element, container) {
46
+ /** The markers of one paragraph, with their offsets in its text (`Paragraph.text` where `hidden` is its `hiddenRuns()`). */
47
+ export function markersOfParagraph(element, container, hidden) {
46
48
  const out = [];
47
- collect(out, undefined, { element, container });
49
+ collect(out, undefined, { element, container }, hidden === undefined ? undefined : () => hidden);
48
50
  return out;
49
51
  }
50
- function collect(out, container, paragraph) {
52
+ /**
53
+ * The walk behind both. A paragraph's markers are found by the same walk as its text (`segmentsOf`, in
54
+ * the accepted view: a `w:ins` and a `w:moveTo` hold text and markers, a `w:del` and a `w:moveFrom` hold
55
+ * neither), so that each offset is one in `Paragraph.text`, hidden runs left out where `hidden` says
56
+ * which they are, and a kept `mc:AlternateContent`'s selected branch read (CR-012 phase 4).
57
+ */
58
+ function collect(out, container, paragraph, hidden, mode = 'read') {
51
59
  var _a;
52
60
  const visitParagraph = (element, blockContainer) => {
53
- let pos = 0;
54
- const visitRuns = (items) => {
55
- var _a, _b, _c;
56
- if (!items)
57
- return;
58
- for (const el of items) {
61
+ segmentsOf(element.value, {
62
+ hidden: hidden === null || hidden === void 0 ? void 0 : hidden(element.value),
63
+ visit: (el, at, owner, run) => {
59
64
  const tn = typeNameOf(el);
60
- if (tn === 'org_docx4j_wml.R') {
61
- const content = (_a = el.value.content) !== null && _a !== void 0 ? _a : [];
62
- for (const item of content) {
63
- if (typeNameOf(item) === COMMENT_REFERENCE) {
64
- out.push({
65
- id: item.value.id, kind: 'reference', item, owner: content,
66
- run: el, runOwner: items, paragraph: element, paragraphContainer: blockContainer, offset: pos,
67
- });
68
- }
69
- else
70
- pos += (_c = (_b = itemTextOf(item)) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
71
- }
65
+ if (tn === COMMENT_REFERENCE && run) {
66
+ out.push({
67
+ id: el.value.id, kind: 'reference', item: el, owner,
68
+ run: run.element, runOwner: run.owner, paragraph: element, paragraphContainer: blockContainer, offset: at,
69
+ });
72
70
  }
73
71
  else if (tn === COMMENT_RANGE_START || tn === COMMENT_RANGE_END) {
74
72
  out.push({
75
73
  id: el.value.id, kind: tn === COMMENT_RANGE_START ? 'start' : 'end',
76
- item: el, owner: items, paragraph: element, paragraphContainer: blockContainer, offset: pos,
74
+ item: el, owner, paragraph: element, paragraphContainer: blockContainer, offset: at,
77
75
  });
78
76
  }
79
- else if (tn !== undefined && RUN_HOLDERS.has(tn)) {
80
- visitRuns(runItemsOf(el.value));
81
- }
82
- else {
83
- // the accepted view, which is what the offsets are in: a w:ins and a w:moveTo hold text
84
- // and markers, a w:del and a w:moveFrom hold neither (CR-002 phase F)
85
- const kind = revisionKindOf(el);
86
- if (kind === 'ins' || kind === 'moveTo')
87
- visitRuns(runItemsOf(el.value));
88
- }
89
- }
90
- };
91
- visitRuns(runItemsOf(element.value));
77
+ },
78
+ });
92
79
  };
93
80
  const visitBlocks = (items) => {
94
- var _a, _b, _c;
81
+ var _a, _b;
95
82
  for (const el of items) {
96
83
  const tn = typeNameOf(el);
97
84
  if (tn === 'org_docx4j_wml.P')
@@ -101,10 +88,14 @@ function collect(out, container, paragraph) {
101
88
  }
102
89
  else if (typeof el.value === 'object' && el.value !== null) {
103
90
  if (tn === 'org_docx4j_wml.Tbl') {
104
- for (const row of (_a = childrenOf(el.value)) !== null && _a !== void 0 ? _a : []) {
105
- for (const cell of (_b = childrenOf(row.value)) !== null && _b !== void 0 ? _b : [])
106
- visitBlocks((_c = childrenOf(cell.value)) !== null && _c !== void 0 ? _c : []);
107
- }
91
+ for (const row of rowsOf(el.value, mode))
92
+ for (const cell of cellsOf(row.element.value, mode))
93
+ visitBlocks((_a = childrenOf(cell.element.value)) !== null && _a !== void 0 ? _a : []);
94
+ }
95
+ else if (tn === ALTERNATE_CONTENT) {
96
+ const ac = el.value;
97
+ for (const branch of mode === 'every' ? branchesOf(ac) : [(_b = selectedBranchOf(ac)) !== null && _b !== void 0 ? _b : []])
98
+ visitBlocks(branch);
108
99
  }
109
100
  else {
110
101
  const children = childrenOf(el.value);
@@ -133,7 +124,7 @@ export function commentIdsOf(container) {
133
124
  /** Removes every marker of a comment from a body, and the reference run when nothing is left in it. */
134
125
  export function removeMarkers(container, id) {
135
126
  var _a;
136
- for (const marker of markersOf(container)) {
127
+ for (const marker of markersOf(container, undefined, 'every')) {
137
128
  if (marker.id !== id)
138
129
  continue;
139
130
  const i = marker.owner.indexOf(marker.item);
@@ -157,7 +148,7 @@ export function nextCommentId(comments, container) {
157
148
  for (const c of (_a = comments.comment) !== null && _a !== void 0 ? _a : [])
158
149
  if (typeof c.id === 'number' && c.id > max)
159
150
  max = c.id;
160
- for (const m of markersOf(container))
151
+ for (const m of markersOf(container, undefined, 'every'))
161
152
  if (m.id > max)
162
153
  max = m.id;
163
154
  return max + 1;
@@ -171,13 +162,28 @@ export function randomHexId(taken) {
171
162
  }
172
163
  throw new Docx4JException('Could not allocate a paragraph id');
173
164
  }
174
- /** The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. */
165
+ /**
166
+ * The `w14:paraId` of a comment's first paragraph: the key of its w15 and w16cid entries. A kept
167
+ * `mc:AlternateContent` before any paragraph is read in its selected branch, as Word reads it (CR-013
168
+ * phase 3; docx4j's `Trees.lastParaId` looks into the branch the same way).
169
+ */
175
170
  export function commentParaId(comment) {
176
- var _a;
177
- for (const el of (_a = comment.content) !== null && _a !== void 0 ? _a : [])
178
- if (typeNameOf(el) === 'org_docx4j_wml.P')
179
- return el.value.paraId;
180
- return undefined;
171
+ var _a, _b;
172
+ const first = (items) => {
173
+ var _a;
174
+ for (const el of items) {
175
+ const tn = typeNameOf(el);
176
+ if (tn === 'org_docx4j_wml.P')
177
+ return el.value.paraId;
178
+ if (tn === ALTERNATE_CONTENT) {
179
+ const found = first((_a = selectedBranchOf(el.value)) !== null && _a !== void 0 ? _a : []);
180
+ if (found !== null)
181
+ return found;
182
+ }
183
+ }
184
+ return null;
185
+ };
186
+ return (_b = first(((_a = comment.content) !== null && _a !== void 0 ? _a : []))) !== null && _b !== void 0 ? _b : undefined;
181
187
  }
182
188
  /** True when a paragraph id is already used by a comment or by a paragraph of the document. */
183
189
  export function paraIdTaken(parts, container, id) {
@@ -189,7 +195,7 @@ export function paraIdTaken(parts, container, id) {
189
195
  }
190
196
  let found = false;
191
197
  const visit = (items) => {
192
- var _a, _b, _c;
198
+ var _a;
193
199
  for (const el of items) {
194
200
  const tn = typeNameOf(el);
195
201
  if (tn === 'org_docx4j_wml.P') {
@@ -198,9 +204,13 @@ export function paraIdTaken(parts, container, id) {
198
204
  }
199
205
  else if (typeof el.value === 'object' && el.value !== null) {
200
206
  if (tn === 'org_docx4j_wml.Tbl') {
201
- for (const row of (_a = childrenOf(el.value)) !== null && _a !== void 0 ? _a : [])
202
- for (const cell of (_b = childrenOf(row.value)) !== null && _b !== void 0 ? _b : [])
203
- visit((_c = childrenOf(cell.value)) !== null && _c !== void 0 ? _c : []);
207
+ for (const row of rowsOf(el.value, 'every'))
208
+ for (const cell of cellsOf(row.element.value, 'every'))
209
+ visit((_a = childrenOf(cell.element.value)) !== null && _a !== void 0 ? _a : []);
210
+ }
211
+ else if (tn === ALTERNATE_CONTENT) {
212
+ for (const branch of branchesOf(el.value))
213
+ visit(branch); // an id is every branch's (CR-013)
204
214
  }
205
215
  else {
206
216
  const children = childrenOf(el.value);
@@ -0,0 +1,18 @@
1
+ import { Docx4JException } from '../../opc/exceptions.mjs';
2
+ /**
3
+ * What Office JS throws where the host refuses an operation it has no answer for: its `code`, so that
4
+ * add-in code branching on `error.code` behaves the same here (check 19: a hyperlink set on an empty range;
5
+ * check 52: a range starting or ending inside a table deleted or replaced).
6
+ */
7
+ export declare class GeneralException extends Docx4JException {
8
+ readonly code = "GeneralException";
9
+ constructor(message: string);
10
+ }
11
+ /**
12
+ * What Office JS throws for an argument it won't take (`InvalidArgument`): its `code`, as `GeneralException` carries its
13
+ * own (check 56: `insertTable` into a bound block content control).
14
+ */
15
+ export declare class InvalidArgument extends Docx4JException {
16
+ readonly code = "InvalidArgument";
17
+ constructor(message: string);
18
+ }
@@ -0,0 +1,24 @@
1
+ import { Docx4JException } from '../../opc/exceptions.mjs';
2
+ /**
3
+ * What Office JS throws where the host refuses an operation it has no answer for: its `code`, so that
4
+ * add-in code branching on `error.code` behaves the same here (check 19: a hyperlink set on an empty range;
5
+ * check 52: a range starting or ending inside a table deleted or replaced).
6
+ */
7
+ export class GeneralException extends Docx4JException {
8
+ constructor(message) {
9
+ super(message);
10
+ this.code = 'GeneralException';
11
+ this.name = 'GeneralException';
12
+ }
13
+ }
14
+ /**
15
+ * What Office JS throws for an argument it won't take (`InvalidArgument`): its `code`, as `GeneralException` carries its
16
+ * own (check 56: `insertTable` into a bound block content control).
17
+ */
18
+ export class InvalidArgument extends Docx4JException {
19
+ constructor(message) {
20
+ super(message);
21
+ this.code = 'InvalidArgument';
22
+ this.name = 'InvalidArgument';
23
+ }
24
+ }
@@ -7,13 +7,18 @@ 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 { endsWithParagraph, endWithParagraph } from './tableRules.mjs';
10
11
  export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf, type TableLayoutMode, type ColumnInsertion } from './tableColumns.mjs';
11
12
  export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu, type ImageFormat, type ImageInfo, type InlinePictureOptions, type NewPicture, type NewImagePart } from './InlinePicture.mjs';
12
13
  export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS, type ContentControlType, type ContentControlForm, type ContentControlAppearance } from './ContentControl.mjs';
13
14
  export { contentOf, isFlatOpc, rewriteRelationshipIds, type OoxmlOptions } from './ooxml.mjs';
14
- export { type SearchOptions, searchPattern, findAll, matchesOf, expandReplacement } from './search.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';
15
+ export { type SearchOptions, searchPattern, findAll, matchesOf, expandReplacement, officeMatches, type OfficeMatch, type SearchSegment } from './search.mjs';
16
+ export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, officeItemText, hiddenRunsOf, type TextSegment, type Located, type TextView, type TextViewOptions, type SegmentOptions, type HiddenRuns, type AlternateLocation, type RevisionKind, type RevisionHolder } from './tree.mjs';
17
+ export { mathTextOf, mathLetter } from './mathText.mjs';
18
+ export { textBoxesOf, type AnchoredBox } from './textBoxes.mjs';
19
+ export { ResolvedView } from './ResolvedView.mjs';
20
+ export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext, type TrackedChangeType, type TrackedChangeKind, type TrackedChangeTarget, type NoteRemovals } from './TrackedChange.mjs';
21
+ export type { TrackedChangeFilter, TrackedChangeSelection } from './trackedChangeFilter.mjs';
17
22
  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';
18
23
  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';
19
24
  export { StylesFacade, type StylePackageLike } from './stylesFacade.mjs';
@@ -9,13 +9,18 @@ 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
+ // Word's rule for what a cell holds (CR-002 section 55; docx4j's TableRules)
13
+ export { endsWithParagraph, endWithParagraph } from './tableRules.mjs';
12
14
  export { layoutModeOf, textWidthTwips, gridWidthsOf, widthTypeOf, insertGridColumns, deleteGridColumns, gridRangeOf } from './tableColumns.mjs';
13
15
  export { InlinePicture, imageInfoOf, naturalSizeEmu, addImage, addImagePart, writableWidthEmu } from './InlinePicture.mjs';
14
16
  export { ContentControl, collectControls, collectRunControls, W14_NS, W15_NS } from './ContentControl.mjs';
15
17
  export { contentOf, isFlatOpc, rewriteRelationshipIds } from './ooxml.mjs';
16
- export { searchPattern, findAll, matchesOf, expandReplacement } from './search.mjs';
17
- export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf } from './tree.mjs';
18
+ export { searchPattern, findAll, matchesOf, expandReplacement, officeMatches } from './search.mjs';
19
+ export { segmentsOf, runsOf, runItemsOf, selectedBranchOf, isAlternateContent, childrenOf, rowsOf, cellsOf, BLOCK_LEVEL_TYPES, SDT_TYPES, runOf, paragraphOf, textOfView, revisionKindOf, officeItemText, hiddenRunsOf } from './tree.mjs';
20
+ export { mathTextOf, mathLetter } from './mathText.mjs';
21
+ export { textBoxesOf } from './textBoxes.mjs';
18
22
  // change tracking (CR-002 phase F)
23
+ export { ResolvedView } from './ResolvedView.mjs';
19
24
  export { TrackedChange, trackedChangesOfParagraph, trackedChangesOfRow, joinWithNext } from './TrackedChange.mjs';
20
25
  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';
21
26
  // The objects package's builders, re-exported so that one import serves the content API and the tree it works on.
@@ -0,0 +1,21 @@
1
+ import type { Element } from '@docx4j/generated-objects-ts/builders/wml';
2
+ /** The two views a paragraph's text is read in. */
3
+ type View = 'accepted' | 'original';
4
+ /** True for an equation at run-holder level: `m:oMath` or `m:oMathPara`. */
5
+ export declare function isMath(el: Element): boolean;
6
+ /**
7
+ * The text of an equation (`m:oMath`, `m:oMathPara`) in a view: the `m:t` of every math run in document
8
+ * order, a revision's runs as the view has them, a structure the view hides (its `m:ctrlPr`'s revision) left out
9
+ * whole, each letter mapped as Word draws it (`mathLetter`).
10
+ */
11
+ export declare function mathTextOf(math: unknown, view?: View): string;
12
+ /**
13
+ * A character as Word draws it in a math run with this `m:sty` (`p`, `b`, `i`, `bi`; none is Word's default,
14
+ * italic) and `m:scr` (`roman`, the default, `script`, `fraktur`, `double-struck`, `sans-serif`,
15
+ * `monospace`), as check 51 measured: letters, Greek capitals, small letters and nabla alike, in the
16
+ * alphabet of the style and script; digits upright in the script's family (bold for bold or bold italic,
17
+ * sans-serif under sans-serif, none of their own in script or fraktur); a character no alphabet has is
18
+ * itself.
19
+ */
20
+ export declare function mathLetter(c: string, sty: string | undefined, scr: string | undefined): string;
21
+ export {};
@@ -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
+ }