1 | (function (factory) {
|
2 | if (typeof exports === "object" && typeof module === "object") {
|
3 | module.exports = factory();
|
4 | } else if (typeof define === "function" && define.amd) {
|
5 | define(factory);
|
6 | } else {
|
7 | var root =
|
8 | typeof globalThis !== "undefined"
|
9 | ? globalThis
|
10 | : typeof global !== "undefined"
|
11 | ? global
|
12 | : typeof self !== "undefined"
|
13 | ? self
|
14 | : this || {};
|
15 | root.doc = factory();
|
16 | }
|
17 | })(function() {
|
18 | "use strict";
|
19 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
20 | var __commonJS = (cb, mod) => function __require() {
|
21 | return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
22 | };
|
23 |
|
24 |
|
25 | var require_doc_js_umd = __commonJS({
|
26 | "dist/_doc.js.umd.js"(exports, module) {
|
27 | var __create = Object.create;
|
28 | var __defProp = Object.defineProperty;
|
29 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
30 | var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
31 | var __getProtoOf = Object.getPrototypeOf;
|
32 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
33 | var __esm = (fn, res) => function __init() {
|
34 | return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
|
35 | };
|
36 | var __commonJS2 = (cb, mod) => function __require() {
|
37 | return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = {
|
38 | exports: {}
|
39 | }).exports, mod), mod.exports;
|
40 | };
|
41 | var __export = (target, all) => {
|
42 | for (var name in all)
|
43 | __defProp(target, name, {
|
44 | get: all[name],
|
45 | enumerable: true
|
46 | });
|
47 | };
|
48 | var __copyProps = (to, from, except, desc) => {
|
49 | if (from && typeof from === "object" || typeof from === "function") {
|
50 | for (let key of __getOwnPropNames2(from))
|
51 | if (!__hasOwnProp.call(to, key) && key !== except)
|
52 | __defProp(to, key, {
|
53 | get: () => from[key],
|
54 | enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
55 | });
|
56 | }
|
57 | return to;
|
58 | };
|
59 | var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
60 | value: mod,
|
61 | enumerable: true
|
62 | }) : target, mod));
|
63 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", {
|
64 | value: true
|
65 | }), mod);
|
66 | var init_define_process = __esm({
|
67 | "<define:process>"() {
|
68 | }
|
69 | });
|
70 | var require_doc_builders = __commonJS2({
|
71 | "src/document/doc-builders.js"(exports2, module2) {
|
72 | "use strict";
|
73 | init_define_process();
|
74 | function concat(parts) {
|
75 | if (false) {
|
76 | for (const part of parts) {
|
77 | assertDoc(part);
|
78 | }
|
79 | }
|
80 | return {
|
81 | type: "concat",
|
82 | parts
|
83 | };
|
84 | }
|
85 | function indent(contents) {
|
86 | if (false) {
|
87 | assertDoc(contents);
|
88 | }
|
89 | return {
|
90 | type: "indent",
|
91 | contents
|
92 | };
|
93 | }
|
94 | function align(widthOrString, contents) {
|
95 | if (false) {
|
96 | assertDoc(contents);
|
97 | }
|
98 | return {
|
99 | type: "align",
|
100 | contents,
|
101 | n: widthOrString
|
102 | };
|
103 | }
|
104 | function group(contents) {
|
105 | let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
106 | if (false) {
|
107 | assertDoc(contents);
|
108 | }
|
109 | return {
|
110 | type: "group",
|
111 | id: opts.id,
|
112 | contents,
|
113 | break: Boolean(opts.shouldBreak),
|
114 | expandedStates: opts.expandedStates
|
115 | };
|
116 | }
|
117 | function dedentToRoot(contents) {
|
118 | return align(Number.NEGATIVE_INFINITY, contents);
|
119 | }
|
120 | function markAsRoot(contents) {
|
121 | return align({
|
122 | type: "root"
|
123 | }, contents);
|
124 | }
|
125 | function dedent(contents) {
|
126 | return align(-1, contents);
|
127 | }
|
128 | function conditionalGroup(states, opts) {
|
129 | return group(states[0], Object.assign(Object.assign({}, opts), {}, {
|
130 | expandedStates: states
|
131 | }));
|
132 | }
|
133 | function fill(parts) {
|
134 | if (false) {
|
135 | for (const part of parts) {
|
136 | assertDoc(part);
|
137 | }
|
138 | }
|
139 | return {
|
140 | type: "fill",
|
141 | parts
|
142 | };
|
143 | }
|
144 | function ifBreak(breakContents, flatContents) {
|
145 | let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
146 | if (false) {
|
147 | if (breakContents) {
|
148 | assertDoc(breakContents);
|
149 | }
|
150 | if (flatContents) {
|
151 | assertDoc(flatContents);
|
152 | }
|
153 | }
|
154 | return {
|
155 | type: "if-break",
|
156 | breakContents,
|
157 | flatContents,
|
158 | groupId: opts.groupId
|
159 | };
|
160 | }
|
161 | function indentIfBreak(contents, opts) {
|
162 | return {
|
163 | type: "indent-if-break",
|
164 | contents,
|
165 | groupId: opts.groupId,
|
166 | negate: opts.negate
|
167 | };
|
168 | }
|
169 | function lineSuffix(contents) {
|
170 | if (false) {
|
171 | assertDoc(contents);
|
172 | }
|
173 | return {
|
174 | type: "line-suffix",
|
175 | contents
|
176 | };
|
177 | }
|
178 | var lineSuffixBoundary = {
|
179 | type: "line-suffix-boundary"
|
180 | };
|
181 | var breakParent = {
|
182 | type: "break-parent"
|
183 | };
|
184 | var trim = {
|
185 | type: "trim"
|
186 | };
|
187 | var hardlineWithoutBreakParent = {
|
188 | type: "line",
|
189 | hard: true
|
190 | };
|
191 | var literallineWithoutBreakParent = {
|
192 | type: "line",
|
193 | hard: true,
|
194 | literal: true
|
195 | };
|
196 | var line = {
|
197 | type: "line"
|
198 | };
|
199 | var softline = {
|
200 | type: "line",
|
201 | soft: true
|
202 | };
|
203 | var hardline = concat([hardlineWithoutBreakParent, breakParent]);
|
204 | var literalline = concat([literallineWithoutBreakParent, breakParent]);
|
205 | var cursor = {
|
206 | type: "cursor",
|
207 | placeholder: Symbol("cursor")
|
208 | };
|
209 | function join(sep, arr) {
|
210 | const res = [];
|
211 | for (let i = 0; i < arr.length; i++) {
|
212 | if (i !== 0) {
|
213 | res.push(sep);
|
214 | }
|
215 | res.push(arr[i]);
|
216 | }
|
217 | return concat(res);
|
218 | }
|
219 | function addAlignmentToDoc(doc, size, tabWidth) {
|
220 | let aligned = doc;
|
221 | if (size > 0) {
|
222 | for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
|
223 | aligned = indent(aligned);
|
224 | }
|
225 | aligned = align(size % tabWidth, aligned);
|
226 | aligned = align(Number.NEGATIVE_INFINITY, aligned);
|
227 | }
|
228 | return aligned;
|
229 | }
|
230 | function label(label2, contents) {
|
231 | return {
|
232 | type: "label",
|
233 | label: label2,
|
234 | contents
|
235 | };
|
236 | }
|
237 | module2.exports = {
|
238 | concat,
|
239 | join,
|
240 | line,
|
241 | softline,
|
242 | hardline,
|
243 | literalline,
|
244 | group,
|
245 | conditionalGroup,
|
246 | fill,
|
247 | lineSuffix,
|
248 | lineSuffixBoundary,
|
249 | cursor,
|
250 | breakParent,
|
251 | ifBreak,
|
252 | trim,
|
253 | indent,
|
254 | indentIfBreak,
|
255 | align,
|
256 | addAlignmentToDoc,
|
257 | markAsRoot,
|
258 | dedentToRoot,
|
259 | dedent,
|
260 | hardlineWithoutBreakParent,
|
261 | literallineWithoutBreakParent,
|
262 | label
|
263 | };
|
264 | }
|
265 | });
|
266 | var require_end_of_line = __commonJS2({
|
267 | "src/common/end-of-line.js"(exports2, module2) {
|
268 | "use strict";
|
269 | init_define_process();
|
270 | function guessEndOfLine(text) {
|
271 | const index = text.indexOf("\r");
|
272 | if (index >= 0) {
|
273 | return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
|
274 | }
|
275 | return "lf";
|
276 | }
|
277 | function convertEndOfLineToChars(value) {
|
278 | switch (value) {
|
279 | case "cr":
|
280 | return "\r";
|
281 | case "crlf":
|
282 | return "\r\n";
|
283 | default:
|
284 | return "\n";
|
285 | }
|
286 | }
|
287 | function countEndOfLineChars(text, eol) {
|
288 | let regex;
|
289 | switch (eol) {
|
290 | case "\n":
|
291 | regex = /\n/g;
|
292 | break;
|
293 | case "\r":
|
294 | regex = /\r/g;
|
295 | break;
|
296 | case "\r\n":
|
297 | regex = /\r\n/g;
|
298 | break;
|
299 | default:
|
300 | throw new Error(`Unexpected "eol" ${JSON.stringify(eol)}.`);
|
301 | }
|
302 | const endOfLines = text.match(regex);
|
303 | return endOfLines ? endOfLines.length : 0;
|
304 | }
|
305 | function normalizeEndOfLine(text) {
|
306 | return text.replace(/\r\n?/g, "\n");
|
307 | }
|
308 | module2.exports = {
|
309 | guessEndOfLine,
|
310 | convertEndOfLineToChars,
|
311 | countEndOfLineChars,
|
312 | normalizeEndOfLine
|
313 | };
|
314 | }
|
315 | });
|
316 | var require_get_last = __commonJS2({
|
317 | "src/utils/get-last.js"(exports2, module2) {
|
318 | "use strict";
|
319 | init_define_process();
|
320 | var getLast = (arr) => arr[arr.length - 1];
|
321 | module2.exports = getLast;
|
322 | }
|
323 | });
|
324 | function ansiRegex() {
|
325 | let {
|
326 | onlyFirst = false
|
327 | } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
328 | const pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");
|
329 | return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
330 | }
|
331 | var init_ansi_regex = __esm({
|
332 | "node_modules/strip-ansi/node_modules/ansi-regex/index.js"() {
|
333 | init_define_process();
|
334 | }
|
335 | });
|
336 | function stripAnsi(string) {
|
337 | if (typeof string !== "string") {
|
338 | throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
339 | }
|
340 | return string.replace(ansiRegex(), "");
|
341 | }
|
342 | var init_strip_ansi = __esm({
|
343 | "node_modules/strip-ansi/index.js"() {
|
344 | init_define_process();
|
345 | init_ansi_regex();
|
346 | }
|
347 | });
|
348 | function isFullwidthCodePoint(codePoint) {
|
349 | if (!Number.isInteger(codePoint)) {
|
350 | return false;
|
351 | }
|
352 | return codePoint >= 4352 && (codePoint <= 4447 || codePoint === 9001 || codePoint === 9002 || 11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || 12880 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65131 || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 262141);
|
353 | }
|
354 | var init_is_fullwidth_code_point = __esm({
|
355 | "node_modules/is-fullwidth-code-point/index.js"() {
|
356 | init_define_process();
|
357 | }
|
358 | });
|
359 | var require_emoji_regex = __commonJS2({
|
360 | "node_modules/emoji-regex/index.js"(exports2, module2) {
|
361 | "use strict";
|
362 | init_define_process();
|
363 | module2.exports = function() {
|
364 | return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\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|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\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]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\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-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
365 | };
|
366 | }
|
367 | });
|
368 | var string_width_exports = {};
|
369 | __export(string_width_exports, {
|
370 | default: () => stringWidth
|
371 | });
|
372 | function stringWidth(string) {
|
373 | if (typeof string !== "string" || string.length === 0) {
|
374 | return 0;
|
375 | }
|
376 | string = stripAnsi(string);
|
377 | if (string.length === 0) {
|
378 | return 0;
|
379 | }
|
380 | string = string.replace((0, import_emoji_regex.default)(), " ");
|
381 | let width = 0;
|
382 | for (let index = 0; index < string.length; index++) {
|
383 | const codePoint = string.codePointAt(index);
|
384 | if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
385 | continue;
|
386 | }
|
387 | if (codePoint >= 768 && codePoint <= 879) {
|
388 | continue;
|
389 | }
|
390 | if (codePoint > 65535) {
|
391 | index++;
|
392 | }
|
393 | width += isFullwidthCodePoint(codePoint) ? 2 : 1;
|
394 | }
|
395 | return width;
|
396 | }
|
397 | var import_emoji_regex;
|
398 | var init_string_width = __esm({
|
399 | "node_modules/string-width/index.js"() {
|
400 | init_define_process();
|
401 | init_strip_ansi();
|
402 | init_is_fullwidth_code_point();
|
403 | import_emoji_regex = __toESM(require_emoji_regex());
|
404 | }
|
405 | });
|
406 | var require_get_string_width = __commonJS2({
|
407 | "src/utils/get-string-width.js"(exports2, module2) {
|
408 | "use strict";
|
409 | init_define_process();
|
410 | var stringWidth2 = (init_string_width(), __toCommonJS(string_width_exports)).default;
|
411 | var notAsciiRegex = /[^\x20-\x7F]/;
|
412 | function getStringWidth(text) {
|
413 | if (!text) {
|
414 | return 0;
|
415 | }
|
416 | if (!notAsciiRegex.test(text)) {
|
417 | return text.length;
|
418 | }
|
419 | return stringWidth2(text);
|
420 | }
|
421 | module2.exports = getStringWidth;
|
422 | }
|
423 | });
|
424 | var require_doc_utils = __commonJS2({
|
425 | "src/document/doc-utils.js"(exports2, module2) {
|
426 | "use strict";
|
427 | init_define_process();
|
428 | var getLast = require_get_last();
|
429 | var {
|
430 | literalline,
|
431 | join
|
432 | } = require_doc_builders();
|
433 | var isConcat = (doc) => Array.isArray(doc) || doc && doc.type === "concat";
|
434 | var getDocParts = (doc) => {
|
435 | if (Array.isArray(doc)) {
|
436 | return doc;
|
437 | }
|
438 | if (doc.type !== "concat" && doc.type !== "fill") {
|
439 | throw new Error("Expect doc type to be `concat` or `fill`.");
|
440 | }
|
441 | return doc.parts;
|
442 | };
|
443 | var traverseDocOnExitStackMarker = {};
|
444 | function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
|
445 | const docsStack = [doc];
|
446 | while (docsStack.length > 0) {
|
447 | const doc2 = docsStack.pop();
|
448 | if (doc2 === traverseDocOnExitStackMarker) {
|
449 | onExit(docsStack.pop());
|
450 | continue;
|
451 | }
|
452 | if (onExit) {
|
453 | docsStack.push(doc2, traverseDocOnExitStackMarker);
|
454 | }
|
455 | if (!onEnter || onEnter(doc2) !== false) {
|
456 | if (isConcat(doc2) || doc2.type === "fill") {
|
457 | const parts = getDocParts(doc2);
|
458 | for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
|
459 | docsStack.push(parts[i]);
|
460 | }
|
461 | } else if (doc2.type === "if-break") {
|
462 | if (doc2.flatContents) {
|
463 | docsStack.push(doc2.flatContents);
|
464 | }
|
465 | if (doc2.breakContents) {
|
466 | docsStack.push(doc2.breakContents);
|
467 | }
|
468 | } else if (doc2.type === "group" && doc2.expandedStates) {
|
469 | if (shouldTraverseConditionalGroups) {
|
470 | for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
|
471 | docsStack.push(doc2.expandedStates[i]);
|
472 | }
|
473 | } else {
|
474 | docsStack.push(doc2.contents);
|
475 | }
|
476 | } else if (doc2.contents) {
|
477 | docsStack.push(doc2.contents);
|
478 | }
|
479 | }
|
480 | }
|
481 | }
|
482 | function mapDoc(doc, cb) {
|
483 | const mapped = new Map();
|
484 | return rec(doc);
|
485 | function rec(doc2) {
|
486 | if (mapped.has(doc2)) {
|
487 | return mapped.get(doc2);
|
488 | }
|
489 | const result = process2(doc2);
|
490 | mapped.set(doc2, result);
|
491 | return result;
|
492 | }
|
493 | function process2(doc2) {
|
494 | if (Array.isArray(doc2)) {
|
495 | return cb(doc2.map(rec));
|
496 | }
|
497 | if (doc2.type === "concat" || doc2.type === "fill") {
|
498 | const parts = doc2.parts.map(rec);
|
499 | return cb(Object.assign(Object.assign({}, doc2), {}, {
|
500 | parts
|
501 | }));
|
502 | }
|
503 | if (doc2.type === "if-break") {
|
504 | const breakContents = doc2.breakContents && rec(doc2.breakContents);
|
505 | const flatContents = doc2.flatContents && rec(doc2.flatContents);
|
506 | return cb(Object.assign(Object.assign({}, doc2), {}, {
|
507 | breakContents,
|
508 | flatContents
|
509 | }));
|
510 | }
|
511 | if (doc2.type === "group" && doc2.expandedStates) {
|
512 | const expandedStates = doc2.expandedStates.map(rec);
|
513 | const contents = expandedStates[0];
|
514 | return cb(Object.assign(Object.assign({}, doc2), {}, {
|
515 | contents,
|
516 | expandedStates
|
517 | }));
|
518 | }
|
519 | if (doc2.contents) {
|
520 | const contents = rec(doc2.contents);
|
521 | return cb(Object.assign(Object.assign({}, doc2), {}, {
|
522 | contents
|
523 | }));
|
524 | }
|
525 | return cb(doc2);
|
526 | }
|
527 | }
|
528 | function findInDoc(doc, fn, defaultValue) {
|
529 | let result = defaultValue;
|
530 | let hasStopped = false;
|
531 | function findInDocOnEnterFn(doc2) {
|
532 | const maybeResult = fn(doc2);
|
533 | if (maybeResult !== void 0) {
|
534 | hasStopped = true;
|
535 | result = maybeResult;
|
536 | }
|
537 | if (hasStopped) {
|
538 | return false;
|
539 | }
|
540 | }
|
541 | traverseDoc(doc, findInDocOnEnterFn);
|
542 | return result;
|
543 | }
|
544 | function willBreakFn(doc) {
|
545 | if (doc.type === "group" && doc.break) {
|
546 | return true;
|
547 | }
|
548 | if (doc.type === "line" && doc.hard) {
|
549 | return true;
|
550 | }
|
551 | if (doc.type === "break-parent") {
|
552 | return true;
|
553 | }
|
554 | }
|
555 | function willBreak(doc) {
|
556 | return findInDoc(doc, willBreakFn, false);
|
557 | }
|
558 | function breakParentGroup(groupStack) {
|
559 | if (groupStack.length > 0) {
|
560 | const parentGroup = getLast(groupStack);
|
561 | if (!parentGroup.expandedStates && !parentGroup.break) {
|
562 | parentGroup.break = "propagated";
|
563 | }
|
564 | }
|
565 | return null;
|
566 | }
|
567 | function propagateBreaks(doc) {
|
568 | const alreadyVisitedSet = new Set();
|
569 | const groupStack = [];
|
570 | function propagateBreaksOnEnterFn(doc2) {
|
571 | if (doc2.type === "break-parent") {
|
572 | breakParentGroup(groupStack);
|
573 | }
|
574 | if (doc2.type === "group") {
|
575 | groupStack.push(doc2);
|
576 | if (alreadyVisitedSet.has(doc2)) {
|
577 | return false;
|
578 | }
|
579 | alreadyVisitedSet.add(doc2);
|
580 | }
|
581 | }
|
582 | function propagateBreaksOnExitFn(doc2) {
|
583 | if (doc2.type === "group") {
|
584 | const group = groupStack.pop();
|
585 | if (group.break) {
|
586 | breakParentGroup(groupStack);
|
587 | }
|
588 | }
|
589 | }
|
590 | traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn, true);
|
591 | }
|
592 | function removeLinesFn(doc) {
|
593 | if (doc.type === "line" && !doc.hard) {
|
594 | return doc.soft ? "" : " ";
|
595 | }
|
596 | if (doc.type === "if-break") {
|
597 | return doc.flatContents || "";
|
598 | }
|
599 | return doc;
|
600 | }
|
601 | function removeLines(doc) {
|
602 | return mapDoc(doc, removeLinesFn);
|
603 | }
|
604 | var isHardline = (doc, nextDoc) => doc && doc.type === "line" && doc.hard && nextDoc && nextDoc.type === "break-parent";
|
605 | function stripDocTrailingHardlineFromDoc(doc) {
|
606 | if (!doc) {
|
607 | return doc;
|
608 | }
|
609 | if (isConcat(doc) || doc.type === "fill") {
|
610 | const parts = getDocParts(doc);
|
611 | while (parts.length > 1 && isHardline(...parts.slice(-2))) {
|
612 | parts.length -= 2;
|
613 | }
|
614 | if (parts.length > 0) {
|
615 | const lastPart = stripDocTrailingHardlineFromDoc(getLast(parts));
|
616 | parts[parts.length - 1] = lastPart;
|
617 | }
|
618 | return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
|
619 | parts
|
620 | });
|
621 | }
|
622 | switch (doc.type) {
|
623 | case "align":
|
624 | case "indent":
|
625 | case "indent-if-break":
|
626 | case "group":
|
627 | case "line-suffix":
|
628 | case "label": {
|
629 | const contents = stripDocTrailingHardlineFromDoc(doc.contents);
|
630 | return Object.assign(Object.assign({}, doc), {}, {
|
631 | contents
|
632 | });
|
633 | }
|
634 | case "if-break": {
|
635 | const breakContents = stripDocTrailingHardlineFromDoc(doc.breakContents);
|
636 | const flatContents = stripDocTrailingHardlineFromDoc(doc.flatContents);
|
637 | return Object.assign(Object.assign({}, doc), {}, {
|
638 | breakContents,
|
639 | flatContents
|
640 | });
|
641 | }
|
642 | }
|
643 | return doc;
|
644 | }
|
645 | function stripTrailingHardline(doc) {
|
646 | return stripDocTrailingHardlineFromDoc(cleanDoc(doc));
|
647 | }
|
648 | function cleanDocFn(doc) {
|
649 | switch (doc.type) {
|
650 | case "fill":
|
651 | if (doc.parts.every((part) => part === "")) {
|
652 | return "";
|
653 | }
|
654 | break;
|
655 | case "group":
|
656 | if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) {
|
657 | return "";
|
658 | }
|
659 | if (doc.contents.type === "group" && doc.contents.id === doc.id && doc.contents.break === doc.break && doc.contents.expandedStates === doc.expandedStates) {
|
660 | return doc.contents;
|
661 | }
|
662 | break;
|
663 | case "align":
|
664 | case "indent":
|
665 | case "indent-if-break":
|
666 | case "line-suffix":
|
667 | if (!doc.contents) {
|
668 | return "";
|
669 | }
|
670 | break;
|
671 | case "if-break":
|
672 | if (!doc.flatContents && !doc.breakContents) {
|
673 | return "";
|
674 | }
|
675 | break;
|
676 | }
|
677 | if (!isConcat(doc)) {
|
678 | return doc;
|
679 | }
|
680 | const parts = [];
|
681 | for (const part of getDocParts(doc)) {
|
682 | if (!part) {
|
683 | continue;
|
684 | }
|
685 | const [currentPart, ...restParts] = isConcat(part) ? getDocParts(part) : [part];
|
686 | if (typeof currentPart === "string" && typeof getLast(parts) === "string") {
|
687 | parts[parts.length - 1] += currentPart;
|
688 | } else {
|
689 | parts.push(currentPart);
|
690 | }
|
691 | parts.push(...restParts);
|
692 | }
|
693 | if (parts.length === 0) {
|
694 | return "";
|
695 | }
|
696 | if (parts.length === 1) {
|
697 | return parts[0];
|
698 | }
|
699 | return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
|
700 | parts
|
701 | });
|
702 | }
|
703 | function cleanDoc(doc) {
|
704 | return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
|
705 | }
|
706 | function normalizeParts(parts) {
|
707 | const newParts = [];
|
708 | const restParts = parts.filter(Boolean);
|
709 | while (restParts.length > 0) {
|
710 | const part = restParts.shift();
|
711 | if (!part) {
|
712 | continue;
|
713 | }
|
714 | if (isConcat(part)) {
|
715 | restParts.unshift(...getDocParts(part));
|
716 | continue;
|
717 | }
|
718 | if (newParts.length > 0 && typeof getLast(newParts) === "string" && typeof part === "string") {
|
719 | newParts[newParts.length - 1] += part;
|
720 | continue;
|
721 | }
|
722 | newParts.push(part);
|
723 | }
|
724 | return newParts;
|
725 | }
|
726 | function normalizeDoc(doc) {
|
727 | return mapDoc(doc, (currentDoc) => {
|
728 | if (Array.isArray(currentDoc)) {
|
729 | return normalizeParts(currentDoc);
|
730 | }
|
731 | if (!currentDoc.parts) {
|
732 | return currentDoc;
|
733 | }
|
734 | return Object.assign(Object.assign({}, currentDoc), {}, {
|
735 | parts: normalizeParts(currentDoc.parts)
|
736 | });
|
737 | });
|
738 | }
|
739 | function replaceEndOfLine(doc) {
|
740 | return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" && currentDoc.includes("\n") ? replaceTextEndOfLine(currentDoc) : currentDoc);
|
741 | }
|
742 | function replaceTextEndOfLine(text) {
|
743 | let replacement = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : literalline;
|
744 | return join(replacement, text.split("\n")).parts;
|
745 | }
|
746 | function canBreakFn(doc) {
|
747 | if (doc.type === "line") {
|
748 | return true;
|
749 | }
|
750 | }
|
751 | function canBreak(doc) {
|
752 | return findInDoc(doc, canBreakFn, false);
|
753 | }
|
754 | module2.exports = {
|
755 | isConcat,
|
756 | getDocParts,
|
757 | willBreak,
|
758 | traverseDoc,
|
759 | findInDoc,
|
760 | mapDoc,
|
761 | propagateBreaks,
|
762 | removeLines,
|
763 | stripTrailingHardline,
|
764 | normalizeParts,
|
765 | normalizeDoc,
|
766 | cleanDoc,
|
767 | replaceTextEndOfLine,
|
768 | replaceEndOfLine,
|
769 | canBreak
|
770 | };
|
771 | }
|
772 | });
|
773 | var require_doc_printer = __commonJS2({
|
774 | "src/document/doc-printer.js"(exports2, module2) {
|
775 | "use strict";
|
776 | init_define_process();
|
777 | var {
|
778 | convertEndOfLineToChars
|
779 | } = require_end_of_line();
|
780 | var getLast = require_get_last();
|
781 | var getStringWidth = require_get_string_width();
|
782 | var {
|
783 | fill,
|
784 | cursor,
|
785 | indent
|
786 | } = require_doc_builders();
|
787 | var {
|
788 | isConcat,
|
789 | getDocParts
|
790 | } = require_doc_utils();
|
791 | var groupModeMap;
|
792 | var MODE_BREAK = 1;
|
793 | var MODE_FLAT = 2;
|
794 | function rootIndent() {
|
795 | return {
|
796 | value: "",
|
797 | length: 0,
|
798 | queue: []
|
799 | };
|
800 | }
|
801 | function makeIndent(ind, options) {
|
802 | return generateInd(ind, {
|
803 | type: "indent"
|
804 | }, options);
|
805 | }
|
806 | function makeAlign(indent2, widthOrDoc, options) {
|
807 | if (widthOrDoc === Number.NEGATIVE_INFINITY) {
|
808 | return indent2.root || rootIndent();
|
809 | }
|
810 | if (widthOrDoc < 0) {
|
811 | return generateInd(indent2, {
|
812 | type: "dedent"
|
813 | }, options);
|
814 | }
|
815 | if (!widthOrDoc) {
|
816 | return indent2;
|
817 | }
|
818 | if (widthOrDoc.type === "root") {
|
819 | return Object.assign(Object.assign({}, indent2), {}, {
|
820 | root: indent2
|
821 | });
|
822 | }
|
823 | const alignType = typeof widthOrDoc === "string" ? "stringAlign" : "numberAlign";
|
824 | return generateInd(indent2, {
|
825 | type: alignType,
|
826 | n: widthOrDoc
|
827 | }, options);
|
828 | }
|
829 | function generateInd(ind, newPart, options) {
|
830 | const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : [...ind.queue, newPart];
|
831 | let value = "";
|
832 | let length = 0;
|
833 | let lastTabs = 0;
|
834 | let lastSpaces = 0;
|
835 | for (const part of queue) {
|
836 | switch (part.type) {
|
837 | case "indent":
|
838 | flush();
|
839 | if (options.useTabs) {
|
840 | addTabs(1);
|
841 | } else {
|
842 | addSpaces(options.tabWidth);
|
843 | }
|
844 | break;
|
845 | case "stringAlign":
|
846 | flush();
|
847 | value += part.n;
|
848 | length += part.n.length;
|
849 | break;
|
850 | case "numberAlign":
|
851 | lastTabs += 1;
|
852 | lastSpaces += part.n;
|
853 | break;
|
854 | default:
|
855 | throw new Error(`Unexpected type '${part.type}'`);
|
856 | }
|
857 | }
|
858 | flushSpaces();
|
859 | return Object.assign(Object.assign({}, ind), {}, {
|
860 | value,
|
861 | length,
|
862 | queue
|
863 | });
|
864 | function addTabs(count) {
|
865 | value += " ".repeat(count);
|
866 | length += options.tabWidth * count;
|
867 | }
|
868 | function addSpaces(count) {
|
869 | value += " ".repeat(count);
|
870 | length += count;
|
871 | }
|
872 | function flush() {
|
873 | if (options.useTabs) {
|
874 | flushTabs();
|
875 | } else {
|
876 | flushSpaces();
|
877 | }
|
878 | }
|
879 | function flushTabs() {
|
880 | if (lastTabs > 0) {
|
881 | addTabs(lastTabs);
|
882 | }
|
883 | resetLast();
|
884 | }
|
885 | function flushSpaces() {
|
886 | if (lastSpaces > 0) {
|
887 | addSpaces(lastSpaces);
|
888 | }
|
889 | resetLast();
|
890 | }
|
891 | function resetLast() {
|
892 | lastTabs = 0;
|
893 | lastSpaces = 0;
|
894 | }
|
895 | }
|
896 | function trim(out) {
|
897 | if (out.length === 0) {
|
898 | return 0;
|
899 | }
|
900 | let trimCount = 0;
|
901 | while (out.length > 0 && typeof getLast(out) === "string" && /^[\t ]*$/.test(getLast(out))) {
|
902 | trimCount += out.pop().length;
|
903 | }
|
904 | if (out.length > 0 && typeof getLast(out) === "string") {
|
905 | const trimmed = getLast(out).replace(/[\t ]*$/, "");
|
906 | trimCount += getLast(out).length - trimmed.length;
|
907 | out[out.length - 1] = trimmed;
|
908 | }
|
909 | return trimCount;
|
910 | }
|
911 | function fits(next, restCommands, width, hasLineSuffix, mustBeFlat) {
|
912 | let restIdx = restCommands.length;
|
913 | const cmds = [next];
|
914 | const out = [];
|
915 | while (width >= 0) {
|
916 | if (cmds.length === 0) {
|
917 | if (restIdx === 0) {
|
918 | return true;
|
919 | }
|
920 | cmds.push(restCommands[--restIdx]);
|
921 | continue;
|
922 | }
|
923 | const {
|
924 | mode,
|
925 | doc
|
926 | } = cmds.pop();
|
927 | if (typeof doc === "string") {
|
928 | out.push(doc);
|
929 | width -= getStringWidth(doc);
|
930 | } else if (isConcat(doc) || doc.type === "fill") {
|
931 | const parts = getDocParts(doc);
|
932 | for (let i = parts.length - 1; i >= 0; i--) {
|
933 | cmds.push({
|
934 | mode,
|
935 | doc: parts[i]
|
936 | });
|
937 | }
|
938 | } else {
|
939 | switch (doc.type) {
|
940 | case "indent":
|
941 | case "align":
|
942 | case "indent-if-break":
|
943 | case "label":
|
944 | cmds.push({
|
945 | mode,
|
946 | doc: doc.contents
|
947 | });
|
948 | break;
|
949 | case "trim":
|
950 | width += trim(out);
|
951 | break;
|
952 | case "group": {
|
953 | if (mustBeFlat && doc.break) {
|
954 | return false;
|
955 | }
|
956 | const groupMode = doc.break ? MODE_BREAK : mode;
|
957 | const contents = doc.expandedStates && groupMode === MODE_BREAK ? getLast(doc.expandedStates) : doc.contents;
|
958 | cmds.push({
|
959 | mode: groupMode,
|
960 | doc: contents
|
961 | });
|
962 | break;
|
963 | }
|
964 | case "if-break": {
|
965 | const groupMode = doc.groupId ? groupModeMap[doc.groupId] || MODE_FLAT : mode;
|
966 | const contents = groupMode === MODE_BREAK ? doc.breakContents : doc.flatContents;
|
967 | if (contents) {
|
968 | cmds.push({
|
969 | mode,
|
970 | doc: contents
|
971 | });
|
972 | }
|
973 | break;
|
974 | }
|
975 | case "line":
|
976 | if (mode === MODE_BREAK || doc.hard) {
|
977 | return true;
|
978 | }
|
979 | if (!doc.soft) {
|
980 | out.push(" ");
|
981 | width--;
|
982 | }
|
983 | break;
|
984 | case "line-suffix":
|
985 | hasLineSuffix = true;
|
986 | break;
|
987 | case "line-suffix-boundary":
|
988 | if (hasLineSuffix) {
|
989 | return false;
|
990 | }
|
991 | break;
|
992 | }
|
993 | }
|
994 | }
|
995 | return false;
|
996 | }
|
997 | function printDocToString(doc, options) {
|
998 | groupModeMap = {};
|
999 | const width = options.printWidth;
|
1000 | const newLine = convertEndOfLineToChars(options.endOfLine);
|
1001 | let pos = 0;
|
1002 | const cmds = [{
|
1003 | ind: rootIndent(),
|
1004 | mode: MODE_BREAK,
|
1005 | doc
|
1006 | }];
|
1007 | const out = [];
|
1008 | let shouldRemeasure = false;
|
1009 | const lineSuffix = [];
|
1010 | while (cmds.length > 0) {
|
1011 | const {
|
1012 | ind,
|
1013 | mode,
|
1014 | doc: doc2
|
1015 | } = cmds.pop();
|
1016 | if (typeof doc2 === "string") {
|
1017 | const formatted = newLine !== "\n" ? doc2.replace(/\n/g, newLine) : doc2;
|
1018 | out.push(formatted);
|
1019 | pos += getStringWidth(formatted);
|
1020 | } else if (isConcat(doc2)) {
|
1021 | const parts = getDocParts(doc2);
|
1022 | for (let i = parts.length - 1; i >= 0; i--) {
|
1023 | cmds.push({
|
1024 | ind,
|
1025 | mode,
|
1026 | doc: parts[i]
|
1027 | });
|
1028 | }
|
1029 | } else {
|
1030 | switch (doc2.type) {
|
1031 | case "cursor":
|
1032 | out.push(cursor.placeholder);
|
1033 | break;
|
1034 | case "indent":
|
1035 | cmds.push({
|
1036 | ind: makeIndent(ind, options),
|
1037 | mode,
|
1038 | doc: doc2.contents
|
1039 | });
|
1040 | break;
|
1041 | case "align":
|
1042 | cmds.push({
|
1043 | ind: makeAlign(ind, doc2.n, options),
|
1044 | mode,
|
1045 | doc: doc2.contents
|
1046 | });
|
1047 | break;
|
1048 | case "trim":
|
1049 | pos -= trim(out);
|
1050 | break;
|
1051 | case "group":
|
1052 | switch (mode) {
|
1053 | case MODE_FLAT:
|
1054 | if (!shouldRemeasure) {
|
1055 | cmds.push({
|
1056 | ind,
|
1057 | mode: doc2.break ? MODE_BREAK : MODE_FLAT,
|
1058 | doc: doc2.contents
|
1059 | });
|
1060 | break;
|
1061 | }
|
1062 | case MODE_BREAK: {
|
1063 | shouldRemeasure = false;
|
1064 | const next = {
|
1065 | ind,
|
1066 | mode: MODE_FLAT,
|
1067 | doc: doc2.contents
|
1068 | };
|
1069 | const rem = width - pos;
|
1070 | const hasLineSuffix = lineSuffix.length > 0;
|
1071 | if (!doc2.break && fits(next, cmds, rem, hasLineSuffix)) {
|
1072 | cmds.push(next);
|
1073 | } else {
|
1074 | if (doc2.expandedStates) {
|
1075 | const mostExpanded = getLast(doc2.expandedStates);
|
1076 | if (doc2.break) {
|
1077 | cmds.push({
|
1078 | ind,
|
1079 | mode: MODE_BREAK,
|
1080 | doc: mostExpanded
|
1081 | });
|
1082 | break;
|
1083 | } else {
|
1084 | for (let i = 1; i < doc2.expandedStates.length + 1; i++) {
|
1085 | if (i >= doc2.expandedStates.length) {
|
1086 | cmds.push({
|
1087 | ind,
|
1088 | mode: MODE_BREAK,
|
1089 | doc: mostExpanded
|
1090 | });
|
1091 | break;
|
1092 | } else {
|
1093 | const state = doc2.expandedStates[i];
|
1094 | const cmd = {
|
1095 | ind,
|
1096 | mode: MODE_FLAT,
|
1097 | doc: state
|
1098 | };
|
1099 | if (fits(cmd, cmds, rem, hasLineSuffix)) {
|
1100 | cmds.push(cmd);
|
1101 | break;
|
1102 | }
|
1103 | }
|
1104 | }
|
1105 | }
|
1106 | } else {
|
1107 | cmds.push({
|
1108 | ind,
|
1109 | mode: MODE_BREAK,
|
1110 | doc: doc2.contents
|
1111 | });
|
1112 | }
|
1113 | }
|
1114 | break;
|
1115 | }
|
1116 | }
|
1117 | if (doc2.id) {
|
1118 | groupModeMap[doc2.id] = getLast(cmds).mode;
|
1119 | }
|
1120 | break;
|
1121 | case "fill": {
|
1122 | const rem = width - pos;
|
1123 | const {
|
1124 | parts
|
1125 | } = doc2;
|
1126 | if (parts.length === 0) {
|
1127 | break;
|
1128 | }
|
1129 | const [content, whitespace] = parts;
|
1130 | const contentFlatCmd = {
|
1131 | ind,
|
1132 | mode: MODE_FLAT,
|
1133 | doc: content
|
1134 | };
|
1135 | const contentBreakCmd = {
|
1136 | ind,
|
1137 | mode: MODE_BREAK,
|
1138 | doc: content
|
1139 | };
|
1140 | const contentFits = fits(contentFlatCmd, [], rem, lineSuffix.length > 0, true);
|
1141 | if (parts.length === 1) {
|
1142 | if (contentFits) {
|
1143 | cmds.push(contentFlatCmd);
|
1144 | } else {
|
1145 | cmds.push(contentBreakCmd);
|
1146 | }
|
1147 | break;
|
1148 | }
|
1149 | const whitespaceFlatCmd = {
|
1150 | ind,
|
1151 | mode: MODE_FLAT,
|
1152 | doc: whitespace
|
1153 | };
|
1154 | const whitespaceBreakCmd = {
|
1155 | ind,
|
1156 | mode: MODE_BREAK,
|
1157 | doc: whitespace
|
1158 | };
|
1159 | if (parts.length === 2) {
|
1160 | if (contentFits) {
|
1161 | cmds.push(whitespaceFlatCmd, contentFlatCmd);
|
1162 | } else {
|
1163 | cmds.push(whitespaceBreakCmd, contentBreakCmd);
|
1164 | }
|
1165 | break;
|
1166 | }
|
1167 | parts.splice(0, 2);
|
1168 | const remainingCmd = {
|
1169 | ind,
|
1170 | mode,
|
1171 | doc: fill(parts)
|
1172 | };
|
1173 | const secondContent = parts[0];
|
1174 | const firstAndSecondContentFlatCmd = {
|
1175 | ind,
|
1176 | mode: MODE_FLAT,
|
1177 | doc: [content, whitespace, secondContent]
|
1178 | };
|
1179 | const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, lineSuffix.length > 0, true);
|
1180 | if (firstAndSecondContentFits) {
|
1181 | cmds.push(remainingCmd, whitespaceFlatCmd, contentFlatCmd);
|
1182 | } else if (contentFits) {
|
1183 | cmds.push(remainingCmd, whitespaceBreakCmd, contentFlatCmd);
|
1184 | } else {
|
1185 | cmds.push(remainingCmd, whitespaceBreakCmd, contentBreakCmd);
|
1186 | }
|
1187 | break;
|
1188 | }
|
1189 | case "if-break":
|
1190 | case "indent-if-break": {
|
1191 | const groupMode = doc2.groupId ? groupModeMap[doc2.groupId] : mode;
|
1192 | if (groupMode === MODE_BREAK) {
|
1193 | const breakContents = doc2.type === "if-break" ? doc2.breakContents : doc2.negate ? doc2.contents : indent(doc2.contents);
|
1194 | if (breakContents) {
|
1195 | cmds.push({
|
1196 | ind,
|
1197 | mode,
|
1198 | doc: breakContents
|
1199 | });
|
1200 | }
|
1201 | }
|
1202 | if (groupMode === MODE_FLAT) {
|
1203 | const flatContents = doc2.type === "if-break" ? doc2.flatContents : doc2.negate ? indent(doc2.contents) : doc2.contents;
|
1204 | if (flatContents) {
|
1205 | cmds.push({
|
1206 | ind,
|
1207 | mode,
|
1208 | doc: flatContents
|
1209 | });
|
1210 | }
|
1211 | }
|
1212 | break;
|
1213 | }
|
1214 | case "line-suffix":
|
1215 | lineSuffix.push({
|
1216 | ind,
|
1217 | mode,
|
1218 | doc: doc2.contents
|
1219 | });
|
1220 | break;
|
1221 | case "line-suffix-boundary":
|
1222 | if (lineSuffix.length > 0) {
|
1223 | cmds.push({
|
1224 | ind,
|
1225 | mode,
|
1226 | doc: {
|
1227 | type: "line",
|
1228 | hard: true
|
1229 | }
|
1230 | });
|
1231 | }
|
1232 | break;
|
1233 | case "line":
|
1234 | switch (mode) {
|
1235 | case MODE_FLAT:
|
1236 | if (!doc2.hard) {
|
1237 | if (!doc2.soft) {
|
1238 | out.push(" ");
|
1239 | pos += 1;
|
1240 | }
|
1241 | break;
|
1242 | } else {
|
1243 | shouldRemeasure = true;
|
1244 | }
|
1245 | case MODE_BREAK:
|
1246 | if (lineSuffix.length > 0) {
|
1247 | cmds.push({
|
1248 | ind,
|
1249 | mode,
|
1250 | doc: doc2
|
1251 | }, ...lineSuffix.reverse());
|
1252 | lineSuffix.length = 0;
|
1253 | break;
|
1254 | }
|
1255 | if (doc2.literal) {
|
1256 | if (ind.root) {
|
1257 | out.push(newLine, ind.root.value);
|
1258 | pos = ind.root.length;
|
1259 | } else {
|
1260 | out.push(newLine);
|
1261 | pos = 0;
|
1262 | }
|
1263 | } else {
|
1264 | pos -= trim(out);
|
1265 | out.push(newLine + ind.value);
|
1266 | pos = ind.length;
|
1267 | }
|
1268 | break;
|
1269 | }
|
1270 | break;
|
1271 | case "label":
|
1272 | cmds.push({
|
1273 | ind,
|
1274 | mode,
|
1275 | doc: doc2.contents
|
1276 | });
|
1277 | break;
|
1278 | default:
|
1279 | }
|
1280 | }
|
1281 | if (cmds.length === 0 && lineSuffix.length > 0) {
|
1282 | cmds.push(...lineSuffix.reverse());
|
1283 | lineSuffix.length = 0;
|
1284 | }
|
1285 | }
|
1286 | const cursorPlaceholderIndex = out.indexOf(cursor.placeholder);
|
1287 | if (cursorPlaceholderIndex !== -1) {
|
1288 | const otherCursorPlaceholderIndex = out.indexOf(cursor.placeholder, cursorPlaceholderIndex + 1);
|
1289 | const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
|
1290 | const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
|
1291 | const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
|
1292 | return {
|
1293 | formatted: beforeCursor + aroundCursor + afterCursor,
|
1294 | cursorNodeStart: beforeCursor.length,
|
1295 | cursorNodeText: aroundCursor
|
1296 | };
|
1297 | }
|
1298 | return {
|
1299 | formatted: out.join("")
|
1300 | };
|
1301 | }
|
1302 | module2.exports = {
|
1303 | printDocToString
|
1304 | };
|
1305 | }
|
1306 | });
|
1307 | var require_doc_debug = __commonJS2({
|
1308 | "src/document/doc-debug.js"(exports2, module2) {
|
1309 | "use strict";
|
1310 | init_define_process();
|
1311 | var {
|
1312 | isConcat,
|
1313 | getDocParts
|
1314 | } = require_doc_utils();
|
1315 | function flattenDoc(doc) {
|
1316 | if (!doc) {
|
1317 | return "";
|
1318 | }
|
1319 | if (isConcat(doc)) {
|
1320 | const res = [];
|
1321 | for (const part of getDocParts(doc)) {
|
1322 | if (isConcat(part)) {
|
1323 | res.push(...flattenDoc(part).parts);
|
1324 | } else {
|
1325 | const flattened = flattenDoc(part);
|
1326 | if (flattened !== "") {
|
1327 | res.push(flattened);
|
1328 | }
|
1329 | }
|
1330 | }
|
1331 | return {
|
1332 | type: "concat",
|
1333 | parts: res
|
1334 | };
|
1335 | }
|
1336 | if (doc.type === "if-break") {
|
1337 | return Object.assign(Object.assign({}, doc), {}, {
|
1338 | breakContents: flattenDoc(doc.breakContents),
|
1339 | flatContents: flattenDoc(doc.flatContents)
|
1340 | });
|
1341 | }
|
1342 | if (doc.type === "group") {
|
1343 | return Object.assign(Object.assign({}, doc), {}, {
|
1344 | contents: flattenDoc(doc.contents),
|
1345 | expandedStates: doc.expandedStates && doc.expandedStates.map(flattenDoc)
|
1346 | });
|
1347 | }
|
1348 | if (doc.type === "fill") {
|
1349 | return {
|
1350 | type: "fill",
|
1351 | parts: doc.parts.map(flattenDoc)
|
1352 | };
|
1353 | }
|
1354 | if (doc.contents) {
|
1355 | return Object.assign(Object.assign({}, doc), {}, {
|
1356 | contents: flattenDoc(doc.contents)
|
1357 | });
|
1358 | }
|
1359 | return doc;
|
1360 | }
|
1361 | function printDocToDebug(doc) {
|
1362 | const printedSymbols = Object.create(null);
|
1363 | const usedKeysForSymbols = new Set();
|
1364 | return printDoc(flattenDoc(doc));
|
1365 | function printDoc(doc2, index, parentParts) {
|
1366 | if (typeof doc2 === "string") {
|
1367 | return JSON.stringify(doc2);
|
1368 | }
|
1369 | if (isConcat(doc2)) {
|
1370 | const printed = getDocParts(doc2).map(printDoc).filter(Boolean);
|
1371 | return printed.length === 1 ? printed[0] : `[${printed.join(", ")}]`;
|
1372 | }
|
1373 | if (doc2.type === "line") {
|
1374 | const withBreakParent = Array.isArray(parentParts) && parentParts[index + 1] && parentParts[index + 1].type === "break-parent";
|
1375 | if (doc2.literal) {
|
1376 | return withBreakParent ? "literalline" : "literallineWithoutBreakParent";
|
1377 | }
|
1378 | if (doc2.hard) {
|
1379 | return withBreakParent ? "hardline" : "hardlineWithoutBreakParent";
|
1380 | }
|
1381 | if (doc2.soft) {
|
1382 | return "softline";
|
1383 | }
|
1384 | return "line";
|
1385 | }
|
1386 | if (doc2.type === "break-parent") {
|
1387 | const afterHardline = Array.isArray(parentParts) && parentParts[index - 1] && parentParts[index - 1].type === "line" && parentParts[index - 1].hard;
|
1388 | return afterHardline ? void 0 : "breakParent";
|
1389 | }
|
1390 | if (doc2.type === "trim") {
|
1391 | return "trim";
|
1392 | }
|
1393 | if (doc2.type === "indent") {
|
1394 | return "indent(" + printDoc(doc2.contents) + ")";
|
1395 | }
|
1396 | if (doc2.type === "align") {
|
1397 | return doc2.n === Number.NEGATIVE_INFINITY ? "dedentToRoot(" + printDoc(doc2.contents) + ")" : doc2.n < 0 ? "dedent(" + printDoc(doc2.contents) + ")" : doc2.n.type === "root" ? "markAsRoot(" + printDoc(doc2.contents) + ")" : "align(" + JSON.stringify(doc2.n) + ", " + printDoc(doc2.contents) + ")";
|
1398 | }
|
1399 | if (doc2.type === "if-break") {
|
1400 | return "ifBreak(" + printDoc(doc2.breakContents) + (doc2.flatContents ? ", " + printDoc(doc2.flatContents) : "") + (doc2.groupId ? (!doc2.flatContents ? ', ""' : "") + `, { groupId: ${printGroupId(doc2.groupId)} }` : "") + ")";
|
1401 | }
|
1402 | if (doc2.type === "indent-if-break") {
|
1403 | const optionsParts = [];
|
1404 | if (doc2.negate) {
|
1405 | optionsParts.push("negate: true");
|
1406 | }
|
1407 | if (doc2.groupId) {
|
1408 | optionsParts.push(`groupId: ${printGroupId(doc2.groupId)}`);
|
1409 | }
|
1410 | const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
|
1411 | return `indentIfBreak(${printDoc(doc2.contents)}${options})`;
|
1412 | }
|
1413 | if (doc2.type === "group") {
|
1414 | const optionsParts = [];
|
1415 | if (doc2.break && doc2.break !== "propagated") {
|
1416 | optionsParts.push("shouldBreak: true");
|
1417 | }
|
1418 | if (doc2.id) {
|
1419 | optionsParts.push(`id: ${printGroupId(doc2.id)}`);
|
1420 | }
|
1421 | const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
|
1422 | if (doc2.expandedStates) {
|
1423 | return `conditionalGroup([${doc2.expandedStates.map((part) => printDoc(part)).join(",")}]${options})`;
|
1424 | }
|
1425 | return `group(${printDoc(doc2.contents)}${options})`;
|
1426 | }
|
1427 | if (doc2.type === "fill") {
|
1428 | return `fill([${doc2.parts.map((part) => printDoc(part)).join(", ")}])`;
|
1429 | }
|
1430 | if (doc2.type === "line-suffix") {
|
1431 | return "lineSuffix(" + printDoc(doc2.contents) + ")";
|
1432 | }
|
1433 | if (doc2.type === "line-suffix-boundary") {
|
1434 | return "lineSuffixBoundary";
|
1435 | }
|
1436 | if (doc2.type === "label") {
|
1437 | return `label(${JSON.stringify(doc2.label)}, ${printDoc(doc2.contents)})`;
|
1438 | }
|
1439 | throw new Error("Unknown doc type " + doc2.type);
|
1440 | }
|
1441 | function printGroupId(id) {
|
1442 | if (typeof id !== "symbol") {
|
1443 | return JSON.stringify(String(id));
|
1444 | }
|
1445 | if (id in printedSymbols) {
|
1446 | return printedSymbols[id];
|
1447 | }
|
1448 | const prefix = String(id).slice(7, -1) || "symbol";
|
1449 | for (let counter = 0; ; counter++) {
|
1450 | const key = prefix + (counter > 0 ? ` #${counter}` : "");
|
1451 | if (!usedKeysForSymbols.has(key)) {
|
1452 | usedKeysForSymbols.add(key);
|
1453 | return printedSymbols[id] = `Symbol.for(${JSON.stringify(key)})`;
|
1454 | }
|
1455 | }
|
1456 | }
|
1457 | }
|
1458 | module2.exports = {
|
1459 | printDocToDebug
|
1460 | };
|
1461 | }
|
1462 | });
|
1463 | init_define_process();
|
1464 | module.exports = {
|
1465 | builders: require_doc_builders(),
|
1466 | printer: require_doc_printer(),
|
1467 | utils: require_doc_utils(),
|
1468 | debug: require_doc_debug()
|
1469 | };
|
1470 | }
|
1471 | });
|
1472 | return require_doc_js_umd();
|
1473 | }); |
\ | No newline at end of file |