@folijs/core 0.5.0 → 1.0.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 (202) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/README.md +1 -1
  3. package/dist/document.d.ts +0 -7
  4. package/dist/document.d.ts.map +1 -1
  5. package/dist/document.js +5 -1
  6. package/dist/document.js.map +1 -1
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +8 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal.d.ts +5 -0
  12. package/dist/internal.d.ts.map +1 -0
  13. package/dist/internal.js +7 -0
  14. package/dist/internal.js.map +1 -0
  15. package/dist/model/attrs.d.ts +0 -10
  16. package/dist/model/attrs.d.ts.map +1 -1
  17. package/dist/model/attrs.js +10 -2
  18. package/dist/model/attrs.js.map +1 -1
  19. package/dist/model/content.d.ts +1 -1
  20. package/dist/model/content.d.ts.map +1 -1
  21. package/dist/model/content.js +1 -1
  22. package/dist/model/content.js.map +1 -1
  23. package/dist/model/errors.d.ts +0 -2
  24. package/dist/model/errors.d.ts.map +1 -1
  25. package/dist/model/errors.js +4 -1
  26. package/dist/model/errors.js.map +1 -1
  27. package/dist/model/fragment.d.ts +1 -1
  28. package/dist/model/fragment.d.ts.map +1 -1
  29. package/dist/model/fragment.js +3 -1
  30. package/dist/model/fragment.js.map +1 -1
  31. package/dist/model/mark.d.ts +1 -1
  32. package/dist/model/mark.d.ts.map +1 -1
  33. package/dist/model/mark.js +1 -1
  34. package/dist/model/mark.js.map +1 -1
  35. package/dist/model/node.d.ts +4 -4
  36. package/dist/model/node.d.ts.map +1 -1
  37. package/dist/model/node.js +8 -4
  38. package/dist/model/node.js.map +1 -1
  39. package/dist/model/schema.d.ts +8 -8
  40. package/dist/model/schema.d.ts.map +1 -1
  41. package/dist/model/schema.js +4 -3
  42. package/dist/model/schema.js.map +1 -1
  43. package/dist/schema.d.ts +0 -11
  44. package/dist/schema.d.ts.map +1 -1
  45. package/dist/schema.js +2 -0
  46. package/dist/schema.js.map +1 -1
  47. package/dist/state/attempt.d.ts +1 -3
  48. package/dist/state/attempt.d.ts.map +1 -1
  49. package/dist/state/commands.d.ts +2 -0
  50. package/dist/state/commands.d.ts.map +1 -1
  51. package/dist/state/commands.js +38 -6
  52. package/dist/state/commands.js.map +1 -1
  53. package/dist/state/comments.d.ts +1 -7
  54. package/dist/state/comments.d.ts.map +1 -1
  55. package/dist/state/comments.js +13 -3
  56. package/dist/state/comments.js.map +1 -1
  57. package/dist/state/controls.d.ts +110 -0
  58. package/dist/state/controls.d.ts.map +1 -0
  59. package/dist/state/controls.js +1473 -0
  60. package/dist/state/controls.js.map +1 -0
  61. package/dist/state/editor.d.ts +188 -68
  62. package/dist/state/editor.d.ts.map +1 -1
  63. package/dist/state/editor.js +265 -79
  64. package/dist/state/editor.js.map +1 -1
  65. package/dist/state/fields.d.ts +68 -0
  66. package/dist/state/fields.d.ts.map +1 -0
  67. package/dist/state/fields.js +410 -0
  68. package/dist/state/fields.js.map +1 -0
  69. package/dist/state/fieldupdate.d.ts +132 -0
  70. package/dist/state/fieldupdate.d.ts.map +1 -0
  71. package/dist/state/fieldupdate.js +1575 -0
  72. package/dist/state/fieldupdate.js.map +1 -0
  73. package/dist/state/find.d.ts +66 -0
  74. package/dist/state/find.d.ts.map +1 -0
  75. package/dist/state/find.js +405 -0
  76. package/dist/state/find.js.map +1 -0
  77. package/dist/state/history.d.ts +2 -0
  78. package/dist/state/history.d.ts.map +1 -1
  79. package/dist/state/history.js +44 -7
  80. package/dist/state/history.js.map +1 -1
  81. package/dist/state/index.d.ts +13 -6
  82. package/dist/state/index.d.ts.map +1 -1
  83. package/dist/state/index.js +12 -5
  84. package/dist/state/index.js.map +1 -1
  85. package/dist/state/lists.d.ts +3 -3
  86. package/dist/state/lists.d.ts.map +1 -1
  87. package/dist/state/lists.js.map +1 -1
  88. package/dist/state/mark.d.ts +1 -17
  89. package/dist/state/mark.d.ts.map +1 -1
  90. package/dist/state/mark.js +10 -1
  91. package/dist/state/mark.js.map +1 -1
  92. package/dist/state/navigation.d.ts +70 -0
  93. package/dist/state/navigation.d.ts.map +1 -0
  94. package/dist/state/navigation.js +226 -0
  95. package/dist/state/navigation.js.map +1 -0
  96. package/dist/state/notes.d.ts +84 -0
  97. package/dist/state/notes.d.ts.map +1 -0
  98. package/dist/state/notes.js +451 -0
  99. package/dist/state/notes.js.map +1 -0
  100. package/dist/state/review.d.ts +8 -4
  101. package/dist/state/review.d.ts.map +1 -1
  102. package/dist/state/review.js +134 -18
  103. package/dist/state/review.js.map +1 -1
  104. package/dist/state/sections.d.ts +91 -0
  105. package/dist/state/sections.d.ts.map +1 -0
  106. package/dist/state/sections.js +479 -0
  107. package/dist/state/sections.js.map +1 -0
  108. package/dist/state/state.d.ts +13 -7
  109. package/dist/state/state.d.ts.map +1 -1
  110. package/dist/state/state.js +9 -2
  111. package/dist/state/state.js.map +1 -1
  112. package/dist/state/stories.d.ts +2 -0
  113. package/dist/state/stories.d.ts.map +1 -0
  114. package/dist/state/stories.js +259 -0
  115. package/dist/state/stories.js.map +1 -0
  116. package/dist/state/tables.d.ts +1 -36
  117. package/dist/state/tables.d.ts.map +1 -1
  118. package/dist/state/tables.js +25 -6
  119. package/dist/state/tables.js.map +1 -1
  120. package/dist/state/track.d.ts +1 -6
  121. package/dist/state/track.d.ts.map +1 -1
  122. package/dist/state/track.js +65 -9
  123. package/dist/state/track.js.map +1 -1
  124. package/dist/state/word.d.ts +47 -55
  125. package/dist/state/word.d.ts.map +1 -1
  126. package/dist/state/word.js +306 -19
  127. package/dist/state/word.js.map +1 -1
  128. package/dist/state/wordclip.d.ts +17 -6
  129. package/dist/state/wordclip.d.ts.map +1 -1
  130. package/dist/state/wordclip.js +254 -17
  131. package/dist/state/wordclip.js.map +1 -1
  132. package/dist/state/wordformat.d.ts +1 -86
  133. package/dist/state/wordformat.d.ts.map +1 -1
  134. package/dist/state/wordformat.js +114 -12
  135. package/dist/state/wordformat.js.map +1 -1
  136. package/dist/transform/stepmap.d.ts +0 -2
  137. package/dist/transform/stepmap.d.ts.map +1 -1
  138. package/dist/v3/check.d.ts +0 -25
  139. package/dist/v3/check.d.ts.map +1 -1
  140. package/dist/v3/check.js +35 -7
  141. package/dist/v3/check.js.map +1 -1
  142. package/dist/v3/document.d.ts +135 -10
  143. package/dist/v3/document.d.ts.map +1 -1
  144. package/dist/v3/document.js +192 -38
  145. package/dist/v3/document.js.map +1 -1
  146. package/dist/v3/extensions.d.ts +43 -0
  147. package/dist/v3/extensions.d.ts.map +1 -0
  148. package/dist/v3/extensions.js +154 -0
  149. package/dist/v3/extensions.js.map +1 -0
  150. package/dist/v3/index.d.ts +3 -2
  151. package/dist/v3/index.d.ts.map +1 -1
  152. package/dist/v3/index.js +3 -2
  153. package/dist/v3/index.js.map +1 -1
  154. package/dist/v3/resolve.d.ts +9 -3
  155. package/dist/v3/resolve.d.ts.map +1 -1
  156. package/dist/v3/resolve.js +28 -4
  157. package/dist/v3/resolve.js.map +1 -1
  158. package/dist/v3/schema.d.ts +5 -16
  159. package/dist/v3/schema.d.ts.map +1 -1
  160. package/dist/v3/schema.js +167 -7
  161. package/dist/v3/schema.js.map +1 -1
  162. package/package.json +5 -1
  163. package/src/document.ts +5 -1
  164. package/src/index.ts +330 -4
  165. package/src/internal.ts +50 -0
  166. package/src/model/attrs.ts +10 -2
  167. package/src/model/content.ts +1 -1
  168. package/src/model/errors.ts +4 -1
  169. package/src/model/fragment.ts +2 -1
  170. package/src/model/mark.ts +1 -1
  171. package/src/model/node.ts +6 -4
  172. package/src/model/schema.ts +9 -3
  173. package/src/schema.ts +2 -0
  174. package/src/state/commands.ts +41 -4
  175. package/src/state/comments.ts +12 -3
  176. package/src/state/controls.ts +1612 -0
  177. package/src/state/editor.ts +508 -143
  178. package/src/state/fields.ts +444 -0
  179. package/src/state/fieldupdate.ts +1771 -0
  180. package/src/state/find.ts +518 -0
  181. package/src/state/history.ts +53 -7
  182. package/src/state/index.ts +125 -1
  183. package/src/state/lists.ts +2 -2
  184. package/src/state/mark.ts +10 -1
  185. package/src/state/navigation.ts +305 -0
  186. package/src/state/notes.ts +529 -0
  187. package/src/state/numeric-pictures.word.json +172 -0
  188. package/src/state/review.ts +172 -19
  189. package/src/state/sections.ts +578 -0
  190. package/src/state/state.ts +21 -3
  191. package/src/state/stories.ts +312 -0
  192. package/src/state/tables.ts +29 -7
  193. package/src/state/track.ts +72 -10
  194. package/src/state/word.ts +360 -24
  195. package/src/state/wordclip.ts +282 -32
  196. package/src/state/wordformat.ts +116 -12
  197. package/src/v3/check.ts +35 -7
  198. package/src/v3/document.ts +358 -50
  199. package/src/v3/extensions.ts +201 -0
  200. package/src/v3/index.ts +16 -0
  201. package/src/v3/resolve.ts +38 -9
  202. package/src/v3/schema.ts +174 -7
@@ -76,9 +76,13 @@ function common<T>(values: readonly T[]): T | null {
76
76
 
77
77
  // ---------- paragraph styles ----------
78
78
 
79
+ /** @internal */
79
80
  export type HasEnvelope = Pick<WordContext, "envelope">;
80
81
 
81
- /** The id of the document's style of `type` named `name` (Word's names: "heading 1"), if any. */
82
+ /**
83
+ * The id of the document's style of `type` named `name` (Word's names: "heading 1"), if any.
84
+ * @internal
85
+ */
82
86
  export function styleNamed(
83
87
  context: HasEnvelope,
84
88
  name: string,
@@ -91,7 +95,10 @@ export function styleNamed(
91
95
  );
92
96
  }
93
97
 
94
- /** The id of the default style of `type` (Normal, Default Paragraph Font), if the document has one. */
98
+ /**
99
+ * The id of the default style of `type` (Normal, Default Paragraph Font), if the document has one.
100
+ * @internal
101
+ */
95
102
  export function defaultParagraphStyleOf(
96
103
  context: HasEnvelope,
97
104
  type: StyleJSON["type"] = "paragraph",
@@ -111,8 +118,9 @@ const builtinName = (id: string) =>
111
118
 
112
119
  /**
113
120
  * Word's definition of built-in style `name` ("heading 1"–"heading 9", "List Paragraph",
114
- * "Hyperlink"), as Word adds it to a document the first time it is used (the Word 2013–2019
121
+ * "Hyperlink", "Placeholder Text"), as Word adds it to a document the first time it is used (the Word 2013–2019
115
122
  * template's values; not checked against newer Word).
123
+ * @internal
116
124
  */
117
125
  export function builtinStyle(context: HasEnvelope, name: string): StyleJSON | null {
118
126
  const normal = defaultParagraphStyleOf(context);
@@ -158,6 +166,20 @@ export function builtinStyle(context: HasEnvelope, name: string): StyleJSON | nu
158
166
  ],
159
167
  };
160
168
  }
169
+ const contents = /^toc ([1-9])$/.exec(name)?.[1];
170
+ if (contents) {
171
+ // Word indents each level by the default font's size (11 pt: 220 twips).
172
+ const size = context.envelope.defaults.run?.find((m) => m.type === "fontSize")?.attrs?.value;
173
+ const indent = (Number(contents) - 1) * (typeof size === "number" ? size * 10 : 220);
174
+ return {
175
+ id: `TOC${contents}`,
176
+ type: "paragraph",
177
+ name,
178
+ ...based,
179
+ ...(normal ? { next: normal } : {}),
180
+ paragraph: { spacing: { after: 100 }, ...(indent ? { indent: { left: indent } } : {}) },
181
+ };
182
+ }
161
183
  if (name === "List Paragraph")
162
184
  return {
163
185
  id: "ListParagraph",
@@ -188,6 +210,52 @@ export function builtinStyle(context: HasEnvelope, name: string): StyleJSON | nu
188
210
  },
189
211
  };
190
212
  }
213
+ const note = /^(foot|end)note (text|reference)$/.exec(name);
214
+ const textChar = /^(Foot|End)note Text Char$/.exec(name);
215
+ if (note || textChar) {
216
+ // Word's: 10 pt text without space after, and a superscript reference.
217
+ const font = defaultParagraphStyleOf(context, "character");
218
+ const fontBased = font ? { basedOn: font } : {};
219
+ const size = { type: "fontSize", attrs: { value: 20, complexScript: 20 } };
220
+ const stem =
221
+ (note?.[1] ?? textChar?.[1] ?? "").toLowerCase() === "foot" ? "Footnote" : "Endnote";
222
+ if (textChar)
223
+ return {
224
+ id: `${stem}TextChar`,
225
+ type: "character",
226
+ name,
227
+ ...fontBased,
228
+ link: `${stem}Text`,
229
+ run: [size],
230
+ };
231
+ if (note?.[2] === "reference")
232
+ return {
233
+ id: `${stem}Reference`,
234
+ type: "character",
235
+ name,
236
+ ...fontBased,
237
+ run: [{ type: "verticalAlign", attrs: { value: "superscript" } }],
238
+ };
239
+ return {
240
+ id: `${stem}Text`,
241
+ type: "paragraph",
242
+ name,
243
+ ...based,
244
+ link: `${stem}TextChar`,
245
+ paragraph: { spacing: { after: 0, line: 240, lineRule: "auto" } },
246
+ run: [size],
247
+ };
248
+ }
249
+ if (name === "Placeholder Text") {
250
+ const font = defaultParagraphStyleOf(context, "character");
251
+ return {
252
+ id: "PlaceholderText",
253
+ type: "character",
254
+ name,
255
+ ...(font ? { basedOn: font } : {}),
256
+ run: [{ type: "color", attrs: { value: "666666" } }],
257
+ };
258
+ }
191
259
  if (name === "Hyperlink") {
192
260
  const font = defaultParagraphStyleOf(context, "character");
193
261
  return {
@@ -207,6 +275,7 @@ export function builtinStyle(context: HasEnvelope, name: string): StyleJSON | nu
207
275
  /**
208
276
  * The id of the document's style named `name`, adding Word's built-in definition when the
209
277
  * document does not have it yet (with the envelope that has it; unchanged if it was there).
278
+ * @internal
210
279
  */
211
280
  export function ensureStyle(
212
281
  context: HasEnvelope,
@@ -277,6 +346,7 @@ export function setParagraphStyle(id: string): Command {
277
346
  /**
278
347
  * Puts the selected paragraphs in the paragraph style named `name` ("heading 2"), adding Word's
279
348
  * definition of a built-in one the document does not have yet.
349
+ * @internal
280
350
  */
281
351
  export function setStyleNamed(name: string): Command {
282
352
  return (state, dispatch) => {
@@ -463,6 +533,7 @@ export const HIGHLIGHT_HEX: Readonly<Record<string, string>> = {
463
533
  /**
464
534
  * Text color on a v3 document (`#rrggbb`); null is Word's "Automatic": no direct color, or an
465
535
  * explicit `auto` where a style colors the text.
536
+ * @internal
466
537
  */
467
538
  export function setWordTextColor(color: string | null): Command {
468
539
  return setRunMark("color", (_existing, inherited, type) => {
@@ -476,6 +547,7 @@ export function setWordTextColor(color: string | null): Command {
476
547
  * other as shading; null removes the highlight (an explicit `none` where a style highlights)
477
548
  * and a plain shading fill, the kind a color outside Word's highlights gives. Patterned shading
478
549
  * stays, and picking a highlight keeps any shading (Word's highlight and shading are apart).
550
+ * @internal
479
551
  */
480
552
  export function setWordHighlight(color: string | null): Command {
481
553
  return (state, dispatch) => {
@@ -533,12 +605,18 @@ function chain(
533
605
  return true;
534
606
  }
535
607
 
536
- /** The text color the selection shows (`#rrggbb`; null: automatic, or mixed). */
608
+ /**
609
+ * The text color the selection shows (`#rrggbb`; null: automatic, or mixed).
610
+ * @internal
611
+ */
537
612
  export function wordTextColorAt(state: EditorState): string | null {
538
613
  return runValueAt(state, (run) => (run.color ? `#${run.color.toLowerCase()}` : null));
539
614
  }
540
615
 
541
- /** The highlight (or shading) the selection shows (`#rrggbb`), or null. */
616
+ /**
617
+ * The highlight (or shading) the selection shows (`#rrggbb`), or null.
618
+ * @internal
619
+ */
542
620
  export function wordHighlightAt(state: EditorState): string | null {
543
621
  return runValueAt(state, (run) =>
544
622
  run.highlight
@@ -584,7 +662,10 @@ function direct(
584
662
  return shows(inherited) ? without : { ...node.attrs, [key]: value };
585
663
  }
586
664
 
587
- /** Aligns the selected paragraphs (`setAlign` on a v3 document). */
665
+ /**
666
+ * Aligns the selected paragraphs (`setAlign` on a v3 document).
667
+ * @internal
668
+ */
588
669
  export function setWordAlign(align: Alignment): Command {
589
670
  return (state, dispatch) => {
590
671
  const context = wordContext(state);
@@ -601,7 +682,10 @@ export function setWordAlign(align: Alignment): Command {
601
682
  };
602
683
  }
603
684
 
604
- /** The alignment all selected paragraphs show (`alignAt` on a v3 document). */
685
+ /**
686
+ * The alignment all selected paragraphs show (`alignAt` on a v3 document).
687
+ * @internal
688
+ */
605
689
  export function wordAlignAt(state: EditorState): Alignment | null {
606
690
  const context = wordContext(state);
607
691
  if (!context) return null;
@@ -740,7 +824,10 @@ function kindOf(context: WordContext, attrs: Attrs): ListKind | null {
740
824
  return format === "bullet" ? "bulletList" : "orderedList";
741
825
  }
742
826
 
743
- /** The kind of list all selected paragraphs are in, or null (none, or mixed). */
827
+ /**
828
+ * The kind of list all selected paragraphs are in, or null (none, or mixed).
829
+ * @internal
830
+ */
744
831
  export function wordListKindAt(state: EditorState): ListKind | null {
745
832
  const context = wordContext(state);
746
833
  if (!context) return null;
@@ -757,7 +844,10 @@ function withoutNumbering(context: WordContext, node: Node): Attrs {
757
844
  return { ...base, style, numbering: styled ? { id: 0 } : null };
758
845
  }
759
846
 
760
- /** Word's levels for a new list: bullets (Symbol, Courier New, Wingdings) or numbers. */
847
+ /**
848
+ * Word's levels for a new list: bullets (Symbol, Courier New, Wingdings) or numbers.
849
+ * @internal
850
+ */
761
851
  export function levels(kind: ListKind): NumberingLevelJSON[] {
762
852
  const bullets = [
763
853
  ["", "Symbol"],
@@ -861,6 +951,7 @@ function newList(envelope: WordEnvelope, kind: ListKind): { id: number; envelope
861
951
  * them out; otherwise numbers them as `kind` (a numbered paragraph keeps its level). A list of
862
952
  * that kind right before the selection goes on; otherwise a new one starts. Paragraphs in the
863
953
  * default style go to "List Paragraph" where the document has it, as in Word.
954
+ * @internal
864
955
  */
865
956
  export function toggleWordList(kind: ListKind): Command {
866
957
  return (state, dispatch) => {
@@ -872,7 +963,10 @@ export function toggleWordList(kind: ListKind): Command {
872
963
  };
873
964
  }
874
965
 
875
- /** Numbers the selected paragraphs as a list of `kind` (`wrapInList` on a v3 document). */
966
+ /**
967
+ * Numbers the selected paragraphs as a list of `kind` (`wrapInList` on a v3 document).
968
+ * @internal
969
+ */
876
970
  export function wrapInWordList(kind: ListKind): Command {
877
971
  return (state, dispatch) => {
878
972
  const context = wordContext(state);
@@ -930,6 +1024,7 @@ function caretInList(state: EditorState, context: WordContext, atStart: boolean)
930
1024
  * Tab on a v3 document: at the start of a numbered paragraph, one level deeper; over several
931
1025
  * paragraphs, indents them (list levels, half-inch stops), as Word does. Elsewhere it does not
932
1026
  * apply (Tab types a tab).
1027
+ * @internal
933
1028
  */
934
1029
  export const sinkWordList: Command = (state, dispatch) => {
935
1030
  const context = wordContext(state);
@@ -938,7 +1033,10 @@ export const sinkWordList: Command = (state, dispatch) => {
938
1033
  return changeIndent(1)(state, dispatch);
939
1034
  };
940
1035
 
941
- /** Shift+Tab in a list on a v3 document: one level up (out of the list at the top). */
1036
+ /**
1037
+ * Shift+Tab in a list on a v3 document: one level up (out of the list at the top).
1038
+ * @internal
1039
+ */
942
1040
  export const liftWordList: Command = (state, dispatch) => {
943
1041
  const context = wordContext(state);
944
1042
  if (!context) return false;
@@ -951,6 +1049,7 @@ export const liftWordList: Command = (state, dispatch) => {
951
1049
  /**
952
1050
  * Enter in an empty numbered paragraph on a v3 document: one level up, or at the top level ends
953
1051
  * the list there, as in Word.
1052
+ * @internal
954
1053
  */
955
1054
  export const endWordList: Command = (state, dispatch) => {
956
1055
  const context = wordContext(state);
@@ -962,6 +1061,7 @@ export const endWordList: Command = (state, dispatch) => {
962
1061
  /**
963
1062
  * Backspace at the start of a numbered paragraph on a v3 document: removes its number, keeping
964
1063
  * the text where it was (the level's indent as the paragraph's own); the next Backspace joins.
1064
+ * @internal
965
1065
  */
966
1066
  export const removeWordListNumber: Command = (state, dispatch) => {
967
1067
  const context = wordContext(state);
@@ -981,6 +1081,7 @@ export const removeWordListNumber: Command = (state, dispatch) => {
981
1081
  /**
982
1082
  * Gives newly linked text Word's "Hyperlink" character style (blue, underlined), adding Word's
983
1083
  * definition where the document does not have it yet.
1084
+ * @internal
984
1085
  */
985
1086
  export function styleLink(tr: Transaction, state: EditorState, from: number, to: number): void {
986
1087
  const context = wordContext(state);
@@ -991,7 +1092,10 @@ export function styleLink(tr: Transaction, state: EditorState, from: number, to:
991
1092
  if (style.envelope !== context.envelope) withEnvelope(tr, style.envelope);
992
1093
  }
993
1094
 
994
- /** Takes the "Hyperlink" character style off text whose link is removed. */
1095
+ /**
1096
+ * Takes the "Hyperlink" character style off text whose link is removed.
1097
+ * @internal
1098
+ */
995
1099
  export function unstyleLink(tr: Transaction, state: EditorState, from: number, to: number): void {
996
1100
  const context = wordContext(state);
997
1101
  const type = state.schema.marks.characterStyle;
package/src/v3/check.ts CHANGED
@@ -7,12 +7,15 @@
7
7
 
8
8
  export type Check = (value: unknown) => string | undefined;
9
9
 
10
+ /** @internal */
10
11
  export function isRecord(value: unknown): value is Record<string, unknown> {
11
12
  return typeof value === "object" && value !== null && !Array.isArray(value);
12
13
  }
13
14
 
15
+ /** @internal */
14
16
  export const bool: Check = (v) => (typeof v === "boolean" ? undefined : "must be true or false");
15
17
 
18
+ /** @internal */
16
19
  export const int =
17
20
  (min: number, max: number): Check =>
18
21
  (v) =>
@@ -20,7 +23,10 @@ export const int =
20
23
  ? undefined
21
24
  : `must be an integer from ${min} to ${max}`;
22
25
 
23
- /** A string of at most `max` characters, empty allowed (Word's ST_String: authors, initials). */
26
+ /**
27
+ * A string of at most `max` characters, empty allowed (Word's ST_String: authors, initials).
28
+ * @internal
29
+ */
24
30
  export const str =
25
31
  (max = 255): Check =>
26
32
  (v) =>
@@ -28,7 +34,10 @@ export const str =
28
34
  ? undefined
29
35
  : `must be a string of at most ${max} characters`;
30
36
 
31
- /** A non-empty string: ids and names things are referenced by. */
37
+ /**
38
+ * A non-empty string: ids and names things are referenced by.
39
+ * @internal
40
+ */
32
41
  export const text =
33
42
  (max = 255): Check =>
34
43
  (v) =>
@@ -36,35 +45,51 @@ export const text =
36
45
  ? undefined
37
46
  : `must be a non-empty string of at most ${max} characters`;
38
47
 
48
+ /** @internal */
39
49
  export const oneOf =
40
50
  (values: readonly string[]): Check =>
41
51
  (v) =>
42
52
  values.includes(v as string) ? undefined : `must be one of ${values.join(", ")}`;
43
53
 
44
- /** A token of one of Word's long enumerations (border styles, number formats…). */
54
+ /**
55
+ * A token of one of Word's long enumerations (border styles, number formats…).
56
+ * @internal
57
+ */
45
58
  export const token: Check = (v) =>
46
59
  typeof v === "string" && /^[A-Za-z][A-Za-z0-9-]{0,63}$/.test(v)
47
60
  ? undefined
48
61
  : "must be a Word token";
49
62
 
50
- /** `RRGGBB` (any case, as Word writes it) or `auto`. */
63
+ /**
64
+ * `RRGGBB` (any case, as Word writes it) or `auto`.
65
+ * @internal
66
+ */
51
67
  export const color: Check = (v) =>
52
68
  typeof v === "string" && /^([0-9A-Fa-f]{6}|auto)$/.test(v) ? undefined : "must be RRGGBB or auto";
53
69
 
54
- /** An ISO 8601 date-time, as Word stores revision and comment dates. */
70
+ /**
71
+ * An ISO 8601 date-time, as Word stores revision and comment dates.
72
+ * @internal
73
+ */
55
74
  export const date: Check = (v) =>
56
75
  typeof v === "string" &&
57
76
  /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/.test(v)
58
77
  ? undefined
59
78
  : "must be an ISO 8601 date-time";
60
79
 
61
- /** Verbatim XML kept for export: never parsed by the engine. */
80
+ /**
81
+ * Verbatim XML kept for export: never parsed by the engine.
82
+ * @internal
83
+ */
62
84
  export const xml: Check = (v) =>
63
85
  typeof v === "string" && v.length > 0 && v.length <= 16_777_216
64
86
  ? undefined
65
87
  : "must be an XML string";
66
88
 
67
- /** An element's own attributes Foli does not model, by qualified name (`w14:paraId`). */
89
+ /**
90
+ * An element's own attributes Foli does not model, by qualified name (`w14:paraId`).
91
+ * @internal
92
+ */
68
93
  export const attributes: Check = (v) => {
69
94
  if (!isRecord(v)) return "must be an object";
70
95
  const entries = Object.entries(v);
@@ -78,11 +103,13 @@ export const attributes: Check = (v) => {
78
103
  return undefined;
79
104
  };
80
105
 
106
+ /** @internal */
81
107
  export const nullable =
82
108
  (check: Check): Check =>
83
109
  (v) =>
84
110
  v === null ? undefined : check(v);
85
111
 
112
+ /** @internal */
86
113
  export const listOf =
87
114
  (check: Check, max = 100_000): Check =>
88
115
  (v) => {
@@ -98,6 +125,7 @@ export const listOf =
98
125
  /**
99
126
  * An object with only the given keys, each optional unless listed in `required`. Unless
100
127
  * `allowEmpty`, at least one key is present (an empty object means "not set": use null).
128
+ * @internal
101
129
  */
102
130
  export const shape =
103
131
  (