pretierr 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/LICENSE +4379 -0
  2. package/README.md +109 -0
  3. package/bin/prettier.cjs +64 -0
  4. package/doc.d.ts +243 -0
  5. package/doc.js +1319 -0
  6. package/doc.mjs +1291 -0
  7. package/index.cjs +648 -0
  8. package/index.d.ts +941 -0
  9. package/index.mjs +22795 -0
  10. package/internal/cli.mjs +3884 -0
  11. package/package.json +206 -0
  12. package/plugins/acorn.d.ts +6 -0
  13. package/plugins/acorn.js +15 -0
  14. package/plugins/acorn.mjs +15 -0
  15. package/plugins/angular.d.ts +8 -0
  16. package/plugins/angular.js +1 -0
  17. package/plugins/angular.mjs +1 -0
  18. package/plugins/babel.d.ts +18 -0
  19. package/plugins/babel.js +15 -0
  20. package/plugins/babel.mjs +15 -0
  21. package/plugins/estree.d.ts +1 -0
  22. package/plugins/estree.js +36 -0
  23. package/plugins/estree.mjs +36 -0
  24. package/plugins/flow.d.ts +5 -0
  25. package/plugins/flow.js +19 -0
  26. package/plugins/flow.mjs +19 -0
  27. package/plugins/glimmer.d.ts +5 -0
  28. package/plugins/glimmer.js +30 -0
  29. package/plugins/glimmer.mjs +30 -0
  30. package/plugins/graphql.d.ts +5 -0
  31. package/plugins/graphql.js +29 -0
  32. package/plugins/graphql.mjs +29 -0
  33. package/plugins/html.d.ts +8 -0
  34. package/plugins/html.js +22 -0
  35. package/plugins/html.mjs +22 -0
  36. package/plugins/markdown.d.ts +7 -0
  37. package/plugins/markdown.js +62 -0
  38. package/plugins/markdown.mjs +62 -0
  39. package/plugins/meriyah.d.ts +5 -0
  40. package/plugins/meriyah.js +4 -0
  41. package/plugins/meriyah.mjs +4 -0
  42. package/plugins/postcss.d.ts +7 -0
  43. package/plugins/postcss.js +52 -0
  44. package/plugins/postcss.mjs +52 -0
  45. package/plugins/typescript.d.ts +5 -0
  46. package/plugins/typescript.js +20 -0
  47. package/plugins/typescript.mjs +20 -0
  48. package/plugins/yaml.d.ts +5 -0
  49. package/plugins/yaml.js +161 -0
  50. package/plugins/yaml.mjs +161 -0
  51. package/standalone.d.ts +33 -0
  52. package/standalone.js +35 -0
  53. package/standalone.mjs +35 -0
  54. package/te24xjoq.cjs +1 -0
package/doc.mjs ADDED
@@ -0,0 +1,1291 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/document/public.js
8
+ var public_exports = {};
9
+ __export(public_exports, {
10
+ builders: () => builders,
11
+ printer: () => printer,
12
+ utils: () => utils
13
+ });
14
+
15
+ // src/document/constants.js
16
+ var DOC_TYPE_STRING = "string";
17
+ var DOC_TYPE_ARRAY = "array";
18
+ var DOC_TYPE_CURSOR = "cursor";
19
+ var DOC_TYPE_INDENT = "indent";
20
+ var DOC_TYPE_ALIGN = "align";
21
+ var DOC_TYPE_TRIM = "trim";
22
+ var DOC_TYPE_GROUP = "group";
23
+ var DOC_TYPE_FILL = "fill";
24
+ var DOC_TYPE_IF_BREAK = "if-break";
25
+ var DOC_TYPE_INDENT_IF_BREAK = "indent-if-break";
26
+ var DOC_TYPE_LINE_SUFFIX = "line-suffix";
27
+ var DOC_TYPE_LINE_SUFFIX_BOUNDARY = "line-suffix-boundary";
28
+ var DOC_TYPE_LINE = "line";
29
+ var DOC_TYPE_LABEL = "label";
30
+ var DOC_TYPE_BREAK_PARENT = "break-parent";
31
+ var VALID_OBJECT_DOC_TYPES = /* @__PURE__ */ new Set([
32
+ DOC_TYPE_CURSOR,
33
+ DOC_TYPE_INDENT,
34
+ DOC_TYPE_ALIGN,
35
+ DOC_TYPE_TRIM,
36
+ DOC_TYPE_GROUP,
37
+ DOC_TYPE_FILL,
38
+ DOC_TYPE_IF_BREAK,
39
+ DOC_TYPE_INDENT_IF_BREAK,
40
+ DOC_TYPE_LINE_SUFFIX,
41
+ DOC_TYPE_LINE_SUFFIX_BOUNDARY,
42
+ DOC_TYPE_LINE,
43
+ DOC_TYPE_LABEL,
44
+ DOC_TYPE_BREAK_PARENT
45
+ ]);
46
+
47
+ // src/document/utils/get-doc-type.js
48
+ function getDocType(doc) {
49
+ if (typeof doc === "string") {
50
+ return DOC_TYPE_STRING;
51
+ }
52
+ if (Array.isArray(doc)) {
53
+ return DOC_TYPE_ARRAY;
54
+ }
55
+ if (!doc) {
56
+ return;
57
+ }
58
+ const { type } = doc;
59
+ if (VALID_OBJECT_DOC_TYPES.has(type)) {
60
+ return type;
61
+ }
62
+ }
63
+ var get_doc_type_default = getDocType;
64
+
65
+ // src/document/invalid-doc-error.js
66
+ var disjunctionListFormat = (list) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(list);
67
+ function getDocErrorMessage(doc) {
68
+ const type = doc === null ? "null" : typeof doc;
69
+ if (type !== "string" && type !== "object") {
70
+ return `Unexpected doc '${type}',
71
+ Expected it to be 'string' or 'object'.`;
72
+ }
73
+ if (get_doc_type_default(doc)) {
74
+ throw new Error("doc is valid.");
75
+ }
76
+ const objectType = Object.prototype.toString.call(doc);
77
+ if (objectType !== "[object Object]") {
78
+ return `Unexpected doc '${objectType}'.`;
79
+ }
80
+ const EXPECTED_TYPE_VALUES = disjunctionListFormat(
81
+ [...VALID_OBJECT_DOC_TYPES].map((type2) => `'${type2}'`)
82
+ );
83
+ return `Unexpected doc.type '${doc.type}'.
84
+ Expected it to be ${EXPECTED_TYPE_VALUES}.`;
85
+ }
86
+ var InvalidDocError = class extends Error {
87
+ name = "InvalidDocError";
88
+ constructor(doc) {
89
+ super(getDocErrorMessage(doc));
90
+ this.doc = doc;
91
+ }
92
+ };
93
+ var invalid_doc_error_default = InvalidDocError;
94
+
95
+ // src/document/utils/traverse-doc.js
96
+ var traverseDocOnExitStackMarker = {};
97
+ function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
98
+ const docsStack = [doc];
99
+ while (docsStack.length > 0) {
100
+ const doc2 = docsStack.pop();
101
+ if (doc2 === traverseDocOnExitStackMarker) {
102
+ onExit(docsStack.pop());
103
+ continue;
104
+ }
105
+ if (onExit) {
106
+ docsStack.push(doc2, traverseDocOnExitStackMarker);
107
+ }
108
+ const docType = get_doc_type_default(doc2);
109
+ if (!docType) {
110
+ throw new invalid_doc_error_default(doc2);
111
+ }
112
+ if ((onEnter == null ? void 0 : onEnter(doc2)) === false) {
113
+ continue;
114
+ }
115
+ switch (docType) {
116
+ case DOC_TYPE_ARRAY:
117
+ case DOC_TYPE_FILL: {
118
+ const parts = docType === DOC_TYPE_ARRAY ? doc2 : doc2.parts;
119
+ for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
120
+ docsStack.push(parts[i]);
121
+ }
122
+ break;
123
+ }
124
+ case DOC_TYPE_IF_BREAK:
125
+ docsStack.push(doc2.flatContents, doc2.breakContents);
126
+ break;
127
+ case DOC_TYPE_GROUP:
128
+ if (shouldTraverseConditionalGroups && doc2.expandedStates) {
129
+ for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
130
+ docsStack.push(doc2.expandedStates[i]);
131
+ }
132
+ } else {
133
+ docsStack.push(doc2.contents);
134
+ }
135
+ break;
136
+ case DOC_TYPE_ALIGN:
137
+ case DOC_TYPE_INDENT:
138
+ case DOC_TYPE_INDENT_IF_BREAK:
139
+ case DOC_TYPE_LABEL:
140
+ case DOC_TYPE_LINE_SUFFIX:
141
+ docsStack.push(doc2.contents);
142
+ break;
143
+ case DOC_TYPE_STRING:
144
+ case DOC_TYPE_CURSOR:
145
+ case DOC_TYPE_TRIM:
146
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
147
+ case DOC_TYPE_LINE:
148
+ case DOC_TYPE_BREAK_PARENT:
149
+ break;
150
+ default:
151
+ throw new invalid_doc_error_default(doc2);
152
+ }
153
+ }
154
+ }
155
+ var traverse_doc_default = traverseDoc;
156
+
157
+ // src/document/utils/assert-doc.js
158
+ var noop = () => {
159
+ };
160
+ var assertDoc = true ? noop : function(doc) {
161
+ traverse_doc_default(doc, (doc2) => {
162
+ if (checked.has(doc2)) {
163
+ return false;
164
+ }
165
+ if (typeof doc2 !== "string") {
166
+ checked.add(doc2);
167
+ }
168
+ });
169
+ };
170
+ var assertDocArray = true ? noop : function(docs, optional = false) {
171
+ if (optional && !docs) {
172
+ return;
173
+ }
174
+ if (!Array.isArray(docs)) {
175
+ throw new TypeError("Unexpected doc array.");
176
+ }
177
+ for (const doc of docs) {
178
+ assertDoc(doc);
179
+ }
180
+ };
181
+
182
+ // src/document/builders.js
183
+ function indent(contents) {
184
+ assertDoc(contents);
185
+ return { type: DOC_TYPE_INDENT, contents };
186
+ }
187
+ function align(widthOrString, contents) {
188
+ assertDoc(contents);
189
+ return { type: DOC_TYPE_ALIGN, contents, n: widthOrString };
190
+ }
191
+ function group(contents, opts = {}) {
192
+ assertDoc(contents);
193
+ assertDocArray(
194
+ opts.expandedStates,
195
+ /* optional */
196
+ true
197
+ );
198
+ return {
199
+ type: DOC_TYPE_GROUP,
200
+ id: opts.id,
201
+ contents,
202
+ break: Boolean(opts.shouldBreak),
203
+ expandedStates: opts.expandedStates
204
+ };
205
+ }
206
+ function dedentToRoot(contents) {
207
+ return align(Number.NEGATIVE_INFINITY, contents);
208
+ }
209
+ function markAsRoot(contents) {
210
+ return align({ type: "root" }, contents);
211
+ }
212
+ function dedent(contents) {
213
+ return align(-1, contents);
214
+ }
215
+ function conditionalGroup(states, opts) {
216
+ return group(states[0], { ...opts, expandedStates: states });
217
+ }
218
+ function fill(parts) {
219
+ assertDocArray(parts);
220
+ return { type: DOC_TYPE_FILL, parts };
221
+ }
222
+ function ifBreak(breakContents, flatContents = "", opts = {}) {
223
+ assertDoc(breakContents);
224
+ if (flatContents !== "") {
225
+ assertDoc(flatContents);
226
+ }
227
+ return {
228
+ type: DOC_TYPE_IF_BREAK,
229
+ breakContents,
230
+ flatContents,
231
+ groupId: opts.groupId
232
+ };
233
+ }
234
+ function indentIfBreak(contents, opts) {
235
+ assertDoc(contents);
236
+ return {
237
+ type: DOC_TYPE_INDENT_IF_BREAK,
238
+ contents,
239
+ groupId: opts.groupId,
240
+ negate: opts.negate
241
+ };
242
+ }
243
+ function lineSuffix(contents) {
244
+ assertDoc(contents);
245
+ return { type: DOC_TYPE_LINE_SUFFIX, contents };
246
+ }
247
+ var lineSuffixBoundary = { type: DOC_TYPE_LINE_SUFFIX_BOUNDARY };
248
+ var breakParent = { type: DOC_TYPE_BREAK_PARENT };
249
+ var trim = { type: DOC_TYPE_TRIM };
250
+ var hardlineWithoutBreakParent = { type: DOC_TYPE_LINE, hard: true };
251
+ var literallineWithoutBreakParent = {
252
+ type: DOC_TYPE_LINE,
253
+ hard: true,
254
+ literal: true
255
+ };
256
+ var line = { type: DOC_TYPE_LINE };
257
+ var softline = { type: DOC_TYPE_LINE, soft: true };
258
+ var hardline = [hardlineWithoutBreakParent, breakParent];
259
+ var literalline = [literallineWithoutBreakParent, breakParent];
260
+ var cursor = { type: DOC_TYPE_CURSOR };
261
+ function join(separator, docs) {
262
+ assertDoc(separator);
263
+ assertDocArray(docs);
264
+ const parts = [];
265
+ for (let i = 0; i < docs.length; i++) {
266
+ if (i !== 0) {
267
+ parts.push(separator);
268
+ }
269
+ parts.push(docs[i]);
270
+ }
271
+ return parts;
272
+ }
273
+ function addAlignmentToDoc(doc, size, tabWidth) {
274
+ assertDoc(doc);
275
+ let aligned = doc;
276
+ if (size > 0) {
277
+ for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
278
+ aligned = indent(aligned);
279
+ }
280
+ aligned = align(size % tabWidth, aligned);
281
+ aligned = align(Number.NEGATIVE_INFINITY, aligned);
282
+ }
283
+ return aligned;
284
+ }
285
+ function label(label2, contents) {
286
+ assertDoc(contents);
287
+ return label2 ? { type: DOC_TYPE_LABEL, label: label2, contents } : contents;
288
+ }
289
+
290
+ // scripts/build/shims/at.js
291
+ var at = (isOptionalObject, object, index) => {
292
+ if (isOptionalObject && (object === void 0 || object === null)) {
293
+ return;
294
+ }
295
+ if (Array.isArray(object) || typeof object === "string") {
296
+ return object[index < 0 ? object.length + index : index];
297
+ }
298
+ return object.at(index);
299
+ };
300
+ var at_default = at;
301
+
302
+ // scripts/build/shims/string-replace-all.js
303
+ var stringReplaceAll = (isOptionalObject, original, pattern, replacement) => {
304
+ if (isOptionalObject && (original === void 0 || original === null)) {
305
+ return;
306
+ }
307
+ if (original.replaceAll) {
308
+ return original.replaceAll(pattern, replacement);
309
+ }
310
+ if (pattern.global) {
311
+ return original.replace(pattern, replacement);
312
+ }
313
+ return original.split(pattern).join(replacement);
314
+ };
315
+ var string_replace_all_default = stringReplaceAll;
316
+
317
+ // src/common/end-of-line.js
318
+ function convertEndOfLineToChars(value) {
319
+ switch (value) {
320
+ case "cr":
321
+ return "\r";
322
+ case "crlf":
323
+ return "\r\n";
324
+ default:
325
+ return "\n";
326
+ }
327
+ }
328
+
329
+ // node_modules/emoji-regex/index.mjs
330
+ var emoji_regex_default = () => {
331
+ return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
332
+ };
333
+
334
+ // node_modules/get-east-asian-width/lookup.js
335
+ function isFullWidth(x) {
336
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
337
+ }
338
+ function isWide(x) {
339
+ return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9800 && x <= 9811 || x === 9855 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 19968 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101632 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129672 || x >= 129680 && x <= 129725 || x >= 129727 && x <= 129733 || x >= 129742 && x <= 129755 || x >= 129760 && x <= 129768 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
340
+ }
341
+
342
+ // node_modules/get-east-asian-width/index.js
343
+ var _isNarrowWidth = (codePoint) => !(isFullWidth(codePoint) || isWide(codePoint));
344
+
345
+ // src/utils/get-string-width.js
346
+ var notAsciiRegex = /[^\x20-\x7F]/u;
347
+ function getStringWidth(text) {
348
+ if (!text) {
349
+ return 0;
350
+ }
351
+ if (!notAsciiRegex.test(text)) {
352
+ return text.length;
353
+ }
354
+ text = text.replace(emoji_regex_default(), " ");
355
+ let width = 0;
356
+ for (const character of text) {
357
+ const codePoint = character.codePointAt(0);
358
+ if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
359
+ continue;
360
+ }
361
+ if (codePoint >= 768 && codePoint <= 879) {
362
+ continue;
363
+ }
364
+ width += _isNarrowWidth(codePoint) ? 1 : 2;
365
+ }
366
+ return width;
367
+ }
368
+ var get_string_width_default = getStringWidth;
369
+
370
+ // src/document/utils.js
371
+ function mapDoc(doc, cb) {
372
+ if (typeof doc === "string") {
373
+ return cb(doc);
374
+ }
375
+ const mapped = /* @__PURE__ */ new Map();
376
+ return rec(doc);
377
+ function rec(doc2) {
378
+ if (mapped.has(doc2)) {
379
+ return mapped.get(doc2);
380
+ }
381
+ const result = process2(doc2);
382
+ mapped.set(doc2, result);
383
+ return result;
384
+ }
385
+ function process2(doc2) {
386
+ switch (get_doc_type_default(doc2)) {
387
+ case DOC_TYPE_ARRAY:
388
+ return cb(doc2.map(rec));
389
+ case DOC_TYPE_FILL:
390
+ return cb({
391
+ ...doc2,
392
+ parts: doc2.parts.map(rec)
393
+ });
394
+ case DOC_TYPE_IF_BREAK:
395
+ return cb({
396
+ ...doc2,
397
+ breakContents: rec(doc2.breakContents),
398
+ flatContents: rec(doc2.flatContents)
399
+ });
400
+ case DOC_TYPE_GROUP: {
401
+ let {
402
+ expandedStates,
403
+ contents
404
+ } = doc2;
405
+ if (expandedStates) {
406
+ expandedStates = expandedStates.map(rec);
407
+ contents = expandedStates[0];
408
+ } else {
409
+ contents = rec(contents);
410
+ }
411
+ return cb({
412
+ ...doc2,
413
+ contents,
414
+ expandedStates
415
+ });
416
+ }
417
+ case DOC_TYPE_ALIGN:
418
+ case DOC_TYPE_INDENT:
419
+ case DOC_TYPE_INDENT_IF_BREAK:
420
+ case DOC_TYPE_LABEL:
421
+ case DOC_TYPE_LINE_SUFFIX:
422
+ return cb({
423
+ ...doc2,
424
+ contents: rec(doc2.contents)
425
+ });
426
+ case DOC_TYPE_STRING:
427
+ case DOC_TYPE_CURSOR:
428
+ case DOC_TYPE_TRIM:
429
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
430
+ case DOC_TYPE_LINE:
431
+ case DOC_TYPE_BREAK_PARENT:
432
+ return cb(doc2);
433
+ default:
434
+ throw new invalid_doc_error_default(doc2);
435
+ }
436
+ }
437
+ }
438
+ function findInDoc(doc, fn, defaultValue) {
439
+ let result = defaultValue;
440
+ let shouldSkipFurtherProcessing = false;
441
+ function findInDocOnEnterFn(doc2) {
442
+ if (shouldSkipFurtherProcessing) {
443
+ return false;
444
+ }
445
+ const maybeResult = fn(doc2);
446
+ if (maybeResult !== void 0) {
447
+ shouldSkipFurtherProcessing = true;
448
+ result = maybeResult;
449
+ }
450
+ }
451
+ traverse_doc_default(doc, findInDocOnEnterFn);
452
+ return result;
453
+ }
454
+ function willBreakFn(doc) {
455
+ if (doc.type === DOC_TYPE_GROUP && doc.break) {
456
+ return true;
457
+ }
458
+ if (doc.type === DOC_TYPE_LINE && doc.hard) {
459
+ return true;
460
+ }
461
+ if (doc.type === DOC_TYPE_BREAK_PARENT) {
462
+ return true;
463
+ }
464
+ }
465
+ function willBreak(doc) {
466
+ return findInDoc(doc, willBreakFn, false);
467
+ }
468
+ function breakParentGroup(groupStack) {
469
+ if (groupStack.length > 0) {
470
+ const parentGroup = at_default(
471
+ /* isOptionalObject */
472
+ false,
473
+ groupStack,
474
+ -1
475
+ );
476
+ if (!parentGroup.expandedStates && !parentGroup.break) {
477
+ parentGroup.break = "propagated";
478
+ }
479
+ }
480
+ return null;
481
+ }
482
+ function propagateBreaks(doc) {
483
+ const alreadyVisitedSet = /* @__PURE__ */ new Set();
484
+ const groupStack = [];
485
+ function propagateBreaksOnEnterFn(doc2) {
486
+ if (doc2.type === DOC_TYPE_BREAK_PARENT) {
487
+ breakParentGroup(groupStack);
488
+ }
489
+ if (doc2.type === DOC_TYPE_GROUP) {
490
+ groupStack.push(doc2);
491
+ if (alreadyVisitedSet.has(doc2)) {
492
+ return false;
493
+ }
494
+ alreadyVisitedSet.add(doc2);
495
+ }
496
+ }
497
+ function propagateBreaksOnExitFn(doc2) {
498
+ if (doc2.type === DOC_TYPE_GROUP) {
499
+ const group2 = groupStack.pop();
500
+ if (group2.break) {
501
+ breakParentGroup(groupStack);
502
+ }
503
+ }
504
+ }
505
+ traverse_doc_default(
506
+ doc,
507
+ propagateBreaksOnEnterFn,
508
+ propagateBreaksOnExitFn,
509
+ /* shouldTraverseConditionalGroups */
510
+ true
511
+ );
512
+ }
513
+ function removeLinesFn(doc) {
514
+ if (doc.type === DOC_TYPE_LINE && !doc.hard) {
515
+ return doc.soft ? "" : " ";
516
+ }
517
+ if (doc.type === DOC_TYPE_IF_BREAK) {
518
+ return doc.flatContents;
519
+ }
520
+ return doc;
521
+ }
522
+ function removeLines(doc) {
523
+ return mapDoc(doc, removeLinesFn);
524
+ }
525
+ function stripTrailingHardlineFromParts(parts) {
526
+ parts = [...parts];
527
+ while (parts.length >= 2 && at_default(
528
+ /* isOptionalObject */
529
+ false,
530
+ parts,
531
+ -2
532
+ ).type === DOC_TYPE_LINE && at_default(
533
+ /* isOptionalObject */
534
+ false,
535
+ parts,
536
+ -1
537
+ ).type === DOC_TYPE_BREAK_PARENT) {
538
+ parts.length -= 2;
539
+ }
540
+ if (parts.length > 0) {
541
+ const lastPart = stripTrailingHardlineFromDoc(at_default(
542
+ /* isOptionalObject */
543
+ false,
544
+ parts,
545
+ -1
546
+ ));
547
+ parts[parts.length - 1] = lastPart;
548
+ }
549
+ return parts;
550
+ }
551
+ function stripTrailingHardlineFromDoc(doc) {
552
+ switch (get_doc_type_default(doc)) {
553
+ case DOC_TYPE_INDENT:
554
+ case DOC_TYPE_INDENT_IF_BREAK:
555
+ case DOC_TYPE_GROUP:
556
+ case DOC_TYPE_LINE_SUFFIX:
557
+ case DOC_TYPE_LABEL: {
558
+ const contents = stripTrailingHardlineFromDoc(doc.contents);
559
+ return {
560
+ ...doc,
561
+ contents
562
+ };
563
+ }
564
+ case DOC_TYPE_IF_BREAK:
565
+ return {
566
+ ...doc,
567
+ breakContents: stripTrailingHardlineFromDoc(doc.breakContents),
568
+ flatContents: stripTrailingHardlineFromDoc(doc.flatContents)
569
+ };
570
+ case DOC_TYPE_FILL:
571
+ return {
572
+ ...doc,
573
+ parts: stripTrailingHardlineFromParts(doc.parts)
574
+ };
575
+ case DOC_TYPE_ARRAY:
576
+ return stripTrailingHardlineFromParts(doc);
577
+ case DOC_TYPE_STRING:
578
+ return doc.replace(/[\n\r]*$/u, "");
579
+ case DOC_TYPE_ALIGN:
580
+ case DOC_TYPE_CURSOR:
581
+ case DOC_TYPE_TRIM:
582
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
583
+ case DOC_TYPE_LINE:
584
+ case DOC_TYPE_BREAK_PARENT:
585
+ break;
586
+ default:
587
+ throw new invalid_doc_error_default(doc);
588
+ }
589
+ return doc;
590
+ }
591
+ function stripTrailingHardline(doc) {
592
+ return stripTrailingHardlineFromDoc(cleanDoc(doc));
593
+ }
594
+ function cleanDocFn(doc) {
595
+ switch (get_doc_type_default(doc)) {
596
+ case DOC_TYPE_FILL:
597
+ if (doc.parts.every((part) => part === "")) {
598
+ return "";
599
+ }
600
+ break;
601
+ case DOC_TYPE_GROUP:
602
+ if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) {
603
+ return "";
604
+ }
605
+ if (doc.contents.type === DOC_TYPE_GROUP && doc.contents.id === doc.id && doc.contents.break === doc.break && doc.contents.expandedStates === doc.expandedStates) {
606
+ return doc.contents;
607
+ }
608
+ break;
609
+ case DOC_TYPE_ALIGN:
610
+ case DOC_TYPE_INDENT:
611
+ case DOC_TYPE_INDENT_IF_BREAK:
612
+ case DOC_TYPE_LINE_SUFFIX:
613
+ if (!doc.contents) {
614
+ return "";
615
+ }
616
+ break;
617
+ case DOC_TYPE_IF_BREAK:
618
+ if (!doc.flatContents && !doc.breakContents) {
619
+ return "";
620
+ }
621
+ break;
622
+ case DOC_TYPE_ARRAY: {
623
+ const parts = [];
624
+ for (const part of doc) {
625
+ if (!part) {
626
+ continue;
627
+ }
628
+ const [currentPart, ...restParts] = Array.isArray(part) ? part : [part];
629
+ if (typeof currentPart === "string" && typeof at_default(
630
+ /* isOptionalObject */
631
+ false,
632
+ parts,
633
+ -1
634
+ ) === "string") {
635
+ parts[parts.length - 1] += currentPart;
636
+ } else {
637
+ parts.push(currentPart);
638
+ }
639
+ parts.push(...restParts);
640
+ }
641
+ if (parts.length === 0) {
642
+ return "";
643
+ }
644
+ if (parts.length === 1) {
645
+ return parts[0];
646
+ }
647
+ return parts;
648
+ }
649
+ case DOC_TYPE_STRING:
650
+ case DOC_TYPE_CURSOR:
651
+ case DOC_TYPE_TRIM:
652
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
653
+ case DOC_TYPE_LINE:
654
+ case DOC_TYPE_LABEL:
655
+ case DOC_TYPE_BREAK_PARENT:
656
+ break;
657
+ default:
658
+ throw new invalid_doc_error_default(doc);
659
+ }
660
+ return doc;
661
+ }
662
+ function cleanDoc(doc) {
663
+ return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
664
+ }
665
+ function replaceEndOfLine(doc, replacement = literalline) {
666
+ return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" ? join(replacement, currentDoc.split("\n")) : currentDoc);
667
+ }
668
+ function canBreakFn(doc) {
669
+ if (doc.type === DOC_TYPE_LINE) {
670
+ return true;
671
+ }
672
+ }
673
+ function canBreak(doc) {
674
+ return findInDoc(doc, canBreakFn, false);
675
+ }
676
+
677
+ // src/document/printer.js
678
+ var MODE_BREAK = Symbol("MODE_BREAK");
679
+ var MODE_FLAT = Symbol("MODE_FLAT");
680
+ var CURSOR_PLACEHOLDER = Symbol("cursor");
681
+ function rootIndent() {
682
+ return {
683
+ value: "",
684
+ length: 0,
685
+ queue: []
686
+ };
687
+ }
688
+ function makeIndent(ind, options) {
689
+ return generateInd(ind, {
690
+ type: "indent"
691
+ }, options);
692
+ }
693
+ function makeAlign(indent2, widthOrDoc, options) {
694
+ if (widthOrDoc === Number.NEGATIVE_INFINITY) {
695
+ return indent2.root || rootIndent();
696
+ }
697
+ if (widthOrDoc < 0) {
698
+ return generateInd(indent2, {
699
+ type: "dedent"
700
+ }, options);
701
+ }
702
+ if (!widthOrDoc) {
703
+ return indent2;
704
+ }
705
+ if (widthOrDoc.type === "root") {
706
+ return {
707
+ ...indent2,
708
+ root: indent2
709
+ };
710
+ }
711
+ const alignType = typeof widthOrDoc === "string" ? "stringAlign" : "numberAlign";
712
+ return generateInd(indent2, {
713
+ type: alignType,
714
+ n: widthOrDoc
715
+ }, options);
716
+ }
717
+ function generateInd(ind, newPart, options) {
718
+ const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : [...ind.queue, newPart];
719
+ let value = "";
720
+ let length = 0;
721
+ let lastTabs = 0;
722
+ let lastSpaces = 0;
723
+ for (const part of queue) {
724
+ switch (part.type) {
725
+ case "indent":
726
+ flush();
727
+ if (options.useTabs) {
728
+ addTabs(1);
729
+ } else {
730
+ addSpaces(options.tabWidth);
731
+ }
732
+ break;
733
+ case "stringAlign":
734
+ flush();
735
+ value += part.n;
736
+ length += part.n.length;
737
+ break;
738
+ case "numberAlign":
739
+ lastTabs += 1;
740
+ lastSpaces += part.n;
741
+ break;
742
+ default:
743
+ throw new Error(`Unexpected type '${part.type}'`);
744
+ }
745
+ }
746
+ flushSpaces();
747
+ return {
748
+ ...ind,
749
+ value,
750
+ length,
751
+ queue
752
+ };
753
+ function addTabs(count) {
754
+ value += " ".repeat(count);
755
+ length += options.tabWidth * count;
756
+ }
757
+ function addSpaces(count) {
758
+ value += " ".repeat(count);
759
+ length += count;
760
+ }
761
+ function flush() {
762
+ if (options.useTabs) {
763
+ flushTabs();
764
+ } else {
765
+ flushSpaces();
766
+ }
767
+ }
768
+ function flushTabs() {
769
+ if (lastTabs > 0) {
770
+ addTabs(lastTabs);
771
+ }
772
+ resetLast();
773
+ }
774
+ function flushSpaces() {
775
+ if (lastSpaces > 0) {
776
+ addSpaces(lastSpaces);
777
+ }
778
+ resetLast();
779
+ }
780
+ function resetLast() {
781
+ lastTabs = 0;
782
+ lastSpaces = 0;
783
+ }
784
+ }
785
+ function trim2(out) {
786
+ let trimCount = 0;
787
+ let cursorCount = 0;
788
+ let outIndex = out.length;
789
+ outer: while (outIndex--) {
790
+ const last = out[outIndex];
791
+ if (last === CURSOR_PLACEHOLDER) {
792
+ cursorCount++;
793
+ continue;
794
+ }
795
+ if (false) {
796
+ throw new Error(`Unexpected value in trim: '${typeof last}'`);
797
+ }
798
+ for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
799
+ const char = last[charIndex];
800
+ if (char === " " || char === " ") {
801
+ trimCount++;
802
+ } else {
803
+ out[outIndex] = last.slice(0, charIndex + 1);
804
+ break outer;
805
+ }
806
+ }
807
+ }
808
+ if (trimCount > 0 || cursorCount > 0) {
809
+ out.length = outIndex + 1;
810
+ while (cursorCount-- > 0) {
811
+ out.push(CURSOR_PLACEHOLDER);
812
+ }
813
+ }
814
+ return trimCount;
815
+ }
816
+ function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat) {
817
+ if (width === Number.POSITIVE_INFINITY) {
818
+ return true;
819
+ }
820
+ let restIdx = restCommands.length;
821
+ const cmds = [next];
822
+ const out = [];
823
+ while (width >= 0) {
824
+ if (cmds.length === 0) {
825
+ if (restIdx === 0) {
826
+ return true;
827
+ }
828
+ cmds.push(restCommands[--restIdx]);
829
+ continue;
830
+ }
831
+ const {
832
+ mode,
833
+ doc
834
+ } = cmds.pop();
835
+ const docType = get_doc_type_default(doc);
836
+ switch (docType) {
837
+ case DOC_TYPE_STRING:
838
+ out.push(doc);
839
+ width -= get_string_width_default(doc);
840
+ break;
841
+ case DOC_TYPE_ARRAY:
842
+ case DOC_TYPE_FILL: {
843
+ const parts = docType === DOC_TYPE_ARRAY ? doc : doc.parts;
844
+ for (let i = parts.length - 1; i >= 0; i--) {
845
+ cmds.push({
846
+ mode,
847
+ doc: parts[i]
848
+ });
849
+ }
850
+ break;
851
+ }
852
+ case DOC_TYPE_INDENT:
853
+ case DOC_TYPE_ALIGN:
854
+ case DOC_TYPE_INDENT_IF_BREAK:
855
+ case DOC_TYPE_LABEL:
856
+ cmds.push({
857
+ mode,
858
+ doc: doc.contents
859
+ });
860
+ break;
861
+ case DOC_TYPE_TRIM:
862
+ width += trim2(out);
863
+ break;
864
+ case DOC_TYPE_GROUP: {
865
+ if (mustBeFlat && doc.break) {
866
+ return false;
867
+ }
868
+ const groupMode = doc.break ? MODE_BREAK : mode;
869
+ const contents = doc.expandedStates && groupMode === MODE_BREAK ? at_default(
870
+ /* isOptionalObject */
871
+ false,
872
+ doc.expandedStates,
873
+ -1
874
+ ) : doc.contents;
875
+ cmds.push({
876
+ mode: groupMode,
877
+ doc: contents
878
+ });
879
+ break;
880
+ }
881
+ case DOC_TYPE_IF_BREAK: {
882
+ const groupMode = doc.groupId ? groupModeMap[doc.groupId] || MODE_FLAT : mode;
883
+ const contents = groupMode === MODE_BREAK ? doc.breakContents : doc.flatContents;
884
+ if (contents) {
885
+ cmds.push({
886
+ mode,
887
+ doc: contents
888
+ });
889
+ }
890
+ break;
891
+ }
892
+ case DOC_TYPE_LINE:
893
+ if (mode === MODE_BREAK || doc.hard) {
894
+ return true;
895
+ }
896
+ if (!doc.soft) {
897
+ out.push(" ");
898
+ width--;
899
+ }
900
+ break;
901
+ case DOC_TYPE_LINE_SUFFIX:
902
+ hasLineSuffix = true;
903
+ break;
904
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
905
+ if (hasLineSuffix) {
906
+ return false;
907
+ }
908
+ break;
909
+ }
910
+ }
911
+ return false;
912
+ }
913
+ function printDocToString(doc, options) {
914
+ const groupModeMap = {};
915
+ const width = options.printWidth;
916
+ const newLine = convertEndOfLineToChars(options.endOfLine);
917
+ let pos = 0;
918
+ const cmds = [{
919
+ ind: rootIndent(),
920
+ mode: MODE_BREAK,
921
+ doc
922
+ }];
923
+ const out = [];
924
+ let shouldRemeasure = false;
925
+ const lineSuffix2 = [];
926
+ let printedCursorCount = 0;
927
+ propagateBreaks(doc);
928
+ while (cmds.length > 0) {
929
+ const {
930
+ ind,
931
+ mode,
932
+ doc: doc2
933
+ } = cmds.pop();
934
+ switch (get_doc_type_default(doc2)) {
935
+ case DOC_TYPE_STRING: {
936
+ const formatted = newLine !== "\n" ? string_replace_all_default(
937
+ /* isOptionalObject */
938
+ false,
939
+ doc2,
940
+ "\n",
941
+ newLine
942
+ ) : doc2;
943
+ out.push(formatted);
944
+ if (cmds.length > 0) {
945
+ pos += get_string_width_default(formatted);
946
+ }
947
+ break;
948
+ }
949
+ case DOC_TYPE_ARRAY:
950
+ for (let i = doc2.length - 1; i >= 0; i--) {
951
+ cmds.push({
952
+ ind,
953
+ mode,
954
+ doc: doc2[i]
955
+ });
956
+ }
957
+ break;
958
+ case DOC_TYPE_CURSOR:
959
+ if (printedCursorCount >= 2) {
960
+ throw new Error("There are too many 'cursor' in doc.");
961
+ }
962
+ out.push(CURSOR_PLACEHOLDER);
963
+ printedCursorCount++;
964
+ break;
965
+ case DOC_TYPE_INDENT:
966
+ cmds.push({
967
+ ind: makeIndent(ind, options),
968
+ mode,
969
+ doc: doc2.contents
970
+ });
971
+ break;
972
+ case DOC_TYPE_ALIGN:
973
+ cmds.push({
974
+ ind: makeAlign(ind, doc2.n, options),
975
+ mode,
976
+ doc: doc2.contents
977
+ });
978
+ break;
979
+ case DOC_TYPE_TRIM:
980
+ pos -= trim2(out);
981
+ break;
982
+ case DOC_TYPE_GROUP:
983
+ switch (mode) {
984
+ case MODE_FLAT:
985
+ if (!shouldRemeasure) {
986
+ cmds.push({
987
+ ind,
988
+ mode: doc2.break ? MODE_BREAK : MODE_FLAT,
989
+ doc: doc2.contents
990
+ });
991
+ break;
992
+ }
993
+ case MODE_BREAK: {
994
+ shouldRemeasure = false;
995
+ const next = {
996
+ ind,
997
+ mode: MODE_FLAT,
998
+ doc: doc2.contents
999
+ };
1000
+ const rem = width - pos;
1001
+ const hasLineSuffix = lineSuffix2.length > 0;
1002
+ if (!doc2.break && fits(next, cmds, rem, hasLineSuffix, groupModeMap)) {
1003
+ cmds.push(next);
1004
+ } else {
1005
+ if (doc2.expandedStates) {
1006
+ const mostExpanded = at_default(
1007
+ /* isOptionalObject */
1008
+ false,
1009
+ doc2.expandedStates,
1010
+ -1
1011
+ );
1012
+ if (doc2.break) {
1013
+ cmds.push({
1014
+ ind,
1015
+ mode: MODE_BREAK,
1016
+ doc: mostExpanded
1017
+ });
1018
+ break;
1019
+ } else {
1020
+ for (let i = 1; i < doc2.expandedStates.length + 1; i++) {
1021
+ if (i >= doc2.expandedStates.length) {
1022
+ cmds.push({
1023
+ ind,
1024
+ mode: MODE_BREAK,
1025
+ doc: mostExpanded
1026
+ });
1027
+ break;
1028
+ } else {
1029
+ const state = doc2.expandedStates[i];
1030
+ const cmd = {
1031
+ ind,
1032
+ mode: MODE_FLAT,
1033
+ doc: state
1034
+ };
1035
+ if (fits(cmd, cmds, rem, hasLineSuffix, groupModeMap)) {
1036
+ cmds.push(cmd);
1037
+ break;
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ } else {
1043
+ cmds.push({
1044
+ ind,
1045
+ mode: MODE_BREAK,
1046
+ doc: doc2.contents
1047
+ });
1048
+ }
1049
+ }
1050
+ break;
1051
+ }
1052
+ }
1053
+ if (doc2.id) {
1054
+ groupModeMap[doc2.id] = at_default(
1055
+ /* isOptionalObject */
1056
+ false,
1057
+ cmds,
1058
+ -1
1059
+ ).mode;
1060
+ }
1061
+ break;
1062
+ case DOC_TYPE_FILL: {
1063
+ const rem = width - pos;
1064
+ const {
1065
+ parts
1066
+ } = doc2;
1067
+ if (parts.length === 0) {
1068
+ break;
1069
+ }
1070
+ const [content, whitespace] = parts;
1071
+ const contentFlatCmd = {
1072
+ ind,
1073
+ mode: MODE_FLAT,
1074
+ doc: content
1075
+ };
1076
+ const contentBreakCmd = {
1077
+ ind,
1078
+ mode: MODE_BREAK,
1079
+ doc: content
1080
+ };
1081
+ const contentFits = fits(contentFlatCmd, [], rem, lineSuffix2.length > 0, groupModeMap, true);
1082
+ if (parts.length === 1) {
1083
+ if (contentFits) {
1084
+ cmds.push(contentFlatCmd);
1085
+ } else {
1086
+ cmds.push(contentBreakCmd);
1087
+ }
1088
+ break;
1089
+ }
1090
+ const whitespaceFlatCmd = {
1091
+ ind,
1092
+ mode: MODE_FLAT,
1093
+ doc: whitespace
1094
+ };
1095
+ const whitespaceBreakCmd = {
1096
+ ind,
1097
+ mode: MODE_BREAK,
1098
+ doc: whitespace
1099
+ };
1100
+ if (parts.length === 2) {
1101
+ if (contentFits) {
1102
+ cmds.push(whitespaceFlatCmd, contentFlatCmd);
1103
+ } else {
1104
+ cmds.push(whitespaceBreakCmd, contentBreakCmd);
1105
+ }
1106
+ break;
1107
+ }
1108
+ parts.splice(0, 2);
1109
+ const remainingCmd = {
1110
+ ind,
1111
+ mode,
1112
+ doc: fill(parts)
1113
+ };
1114
+ const secondContent = parts[0];
1115
+ const firstAndSecondContentFlatCmd = {
1116
+ ind,
1117
+ mode: MODE_FLAT,
1118
+ doc: [content, whitespace, secondContent]
1119
+ };
1120
+ const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, lineSuffix2.length > 0, groupModeMap, true);
1121
+ if (firstAndSecondContentFits) {
1122
+ cmds.push(remainingCmd, whitespaceFlatCmd, contentFlatCmd);
1123
+ } else if (contentFits) {
1124
+ cmds.push(remainingCmd, whitespaceBreakCmd, contentFlatCmd);
1125
+ } else {
1126
+ cmds.push(remainingCmd, whitespaceBreakCmd, contentBreakCmd);
1127
+ }
1128
+ break;
1129
+ }
1130
+ case DOC_TYPE_IF_BREAK:
1131
+ case DOC_TYPE_INDENT_IF_BREAK: {
1132
+ const groupMode = doc2.groupId ? groupModeMap[doc2.groupId] : mode;
1133
+ if (groupMode === MODE_BREAK) {
1134
+ const breakContents = doc2.type === DOC_TYPE_IF_BREAK ? doc2.breakContents : doc2.negate ? doc2.contents : indent(doc2.contents);
1135
+ if (breakContents) {
1136
+ cmds.push({
1137
+ ind,
1138
+ mode,
1139
+ doc: breakContents
1140
+ });
1141
+ }
1142
+ }
1143
+ if (groupMode === MODE_FLAT) {
1144
+ const flatContents = doc2.type === DOC_TYPE_IF_BREAK ? doc2.flatContents : doc2.negate ? indent(doc2.contents) : doc2.contents;
1145
+ if (flatContents) {
1146
+ cmds.push({
1147
+ ind,
1148
+ mode,
1149
+ doc: flatContents
1150
+ });
1151
+ }
1152
+ }
1153
+ break;
1154
+ }
1155
+ case DOC_TYPE_LINE_SUFFIX:
1156
+ lineSuffix2.push({
1157
+ ind,
1158
+ mode,
1159
+ doc: doc2.contents
1160
+ });
1161
+ break;
1162
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
1163
+ if (lineSuffix2.length > 0) {
1164
+ cmds.push({
1165
+ ind,
1166
+ mode,
1167
+ doc: hardlineWithoutBreakParent
1168
+ });
1169
+ }
1170
+ break;
1171
+ case DOC_TYPE_LINE:
1172
+ switch (mode) {
1173
+ case MODE_FLAT:
1174
+ if (!doc2.hard) {
1175
+ if (!doc2.soft) {
1176
+ out.push(" ");
1177
+ pos += 1;
1178
+ }
1179
+ break;
1180
+ } else {
1181
+ shouldRemeasure = true;
1182
+ }
1183
+ case MODE_BREAK:
1184
+ if (lineSuffix2.length > 0) {
1185
+ cmds.push({
1186
+ ind,
1187
+ mode,
1188
+ doc: doc2
1189
+ }, ...lineSuffix2.reverse());
1190
+ lineSuffix2.length = 0;
1191
+ break;
1192
+ }
1193
+ if (doc2.literal) {
1194
+ if (ind.root) {
1195
+ out.push(newLine, ind.root.value);
1196
+ pos = ind.root.length;
1197
+ } else {
1198
+ out.push(newLine);
1199
+ pos = 0;
1200
+ }
1201
+ } else {
1202
+ pos -= trim2(out);
1203
+ out.push(newLine + ind.value);
1204
+ pos = ind.length;
1205
+ }
1206
+ break;
1207
+ }
1208
+ break;
1209
+ case DOC_TYPE_LABEL:
1210
+ cmds.push({
1211
+ ind,
1212
+ mode,
1213
+ doc: doc2.contents
1214
+ });
1215
+ break;
1216
+ case DOC_TYPE_BREAK_PARENT:
1217
+ break;
1218
+ default:
1219
+ throw new invalid_doc_error_default(doc2);
1220
+ }
1221
+ if (cmds.length === 0 && lineSuffix2.length > 0) {
1222
+ cmds.push(...lineSuffix2.reverse());
1223
+ lineSuffix2.length = 0;
1224
+ }
1225
+ }
1226
+ const cursorPlaceholderIndex = out.indexOf(CURSOR_PLACEHOLDER);
1227
+ if (cursorPlaceholderIndex !== -1) {
1228
+ const otherCursorPlaceholderIndex = out.indexOf(CURSOR_PLACEHOLDER, cursorPlaceholderIndex + 1);
1229
+ const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
1230
+ const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
1231
+ const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
1232
+ return {
1233
+ formatted: beforeCursor + aroundCursor + afterCursor,
1234
+ cursorNodeStart: beforeCursor.length,
1235
+ cursorNodeText: aroundCursor
1236
+ };
1237
+ }
1238
+ return {
1239
+ formatted: out.join("")
1240
+ };
1241
+ }
1242
+
1243
+ // src/document/public.js
1244
+ var builders = {
1245
+ join,
1246
+ line,
1247
+ softline,
1248
+ hardline,
1249
+ literalline,
1250
+ group,
1251
+ conditionalGroup,
1252
+ fill,
1253
+ lineSuffix,
1254
+ lineSuffixBoundary,
1255
+ cursor,
1256
+ breakParent,
1257
+ ifBreak,
1258
+ trim,
1259
+ indent,
1260
+ indentIfBreak,
1261
+ align,
1262
+ addAlignmentToDoc,
1263
+ markAsRoot,
1264
+ dedentToRoot,
1265
+ dedent,
1266
+ hardlineWithoutBreakParent,
1267
+ literallineWithoutBreakParent,
1268
+ label,
1269
+ // TODO: Remove this in v4
1270
+ concat: (parts) => parts
1271
+ };
1272
+ var printer = { printDocToString };
1273
+ var utils = {
1274
+ willBreak,
1275
+ traverseDoc: traverse_doc_default,
1276
+ findInDoc,
1277
+ mapDoc,
1278
+ removeLines,
1279
+ stripTrailingHardline,
1280
+ replaceEndOfLine,
1281
+ canBreak
1282
+ };
1283
+
1284
+ // with-default-export:src/document/public.js
1285
+ var public_default = public_exports;
1286
+ export {
1287
+ builders,
1288
+ public_default as default,
1289
+ printer,
1290
+ utils
1291
+ };