doc.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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. // dist/doc.js
  24. var require_doc = __commonJS({
  25. "dist/doc.js"(exports, module) {
  26. var __getOwnPropNames2 = Object.getOwnPropertyNames;
  27. var __esm = (fn, res) => function __init() {
  28. return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
  29. };
  30. var __commonJS2 = (cb, mod) => function __require() {
  31. return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = {
  32. exports: {}
  33. }).exports, mod), mod.exports;
  34. };
  35. var init_define_process = __esm({
  36. "<define:process>"() {
  37. }
  38. });
  39. var require_doc_builders = __commonJS2({
  40. "src/document/doc-builders.js"(exports2, module2) {
  41. "use strict";
  42. init_define_process();
  43. function concat(parts) {
  44. if (false) {
  45. for (const part of parts) {
  46. assertDoc(part);
  47. }
  48. }
  49. return {
  50. type: "concat",
  51. parts
  52. };
  53. }
  54. function indent(contents) {
  55. if (false) {
  56. assertDoc(contents);
  57. }
  58. return {
  59. type: "indent",
  60. contents
  61. };
  62. }
  63. function align(widthOrString, contents) {
  64. if (false) {
  65. assertDoc(contents);
  66. }
  67. return {
  68. type: "align",
  69. contents,
  70. n: widthOrString
  71. };
  72. }
  73. function group(contents) {
  74. let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  75. if (false) {
  76. assertDoc(contents);
  77. }
  78. return {
  79. type: "group",
  80. id: opts.id,
  81. contents,
  82. break: Boolean(opts.shouldBreak),
  83. expandedStates: opts.expandedStates
  84. };
  85. }
  86. function dedentToRoot(contents) {
  87. return align(Number.NEGATIVE_INFINITY, contents);
  88. }
  89. function markAsRoot(contents) {
  90. return align({
  91. type: "root"
  92. }, contents);
  93. }
  94. function dedent(contents) {
  95. return align(-1, contents);
  96. }
  97. function conditionalGroup(states, opts) {
  98. return group(states[0], Object.assign(Object.assign({}, opts), {}, {
  99. expandedStates: states
  100. }));
  101. }
  102. function fill(parts) {
  103. if (false) {
  104. for (const part of parts) {
  105. assertDoc(part);
  106. }
  107. }
  108. return {
  109. type: "fill",
  110. parts
  111. };
  112. }
  113. function ifBreak(breakContents, flatContents) {
  114. let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
  115. if (false) {
  116. if (breakContents) {
  117. assertDoc(breakContents);
  118. }
  119. if (flatContents) {
  120. assertDoc(flatContents);
  121. }
  122. }
  123. return {
  124. type: "if-break",
  125. breakContents,
  126. flatContents,
  127. groupId: opts.groupId
  128. };
  129. }
  130. function indentIfBreak(contents, opts) {
  131. return {
  132. type: "indent-if-break",
  133. contents,
  134. groupId: opts.groupId,
  135. negate: opts.negate
  136. };
  137. }
  138. function lineSuffix(contents) {
  139. if (false) {
  140. assertDoc(contents);
  141. }
  142. return {
  143. type: "line-suffix",
  144. contents
  145. };
  146. }
  147. var lineSuffixBoundary = {
  148. type: "line-suffix-boundary"
  149. };
  150. var breakParent = {
  151. type: "break-parent"
  152. };
  153. var trim = {
  154. type: "trim"
  155. };
  156. var hardlineWithoutBreakParent = {
  157. type: "line",
  158. hard: true
  159. };
  160. var literallineWithoutBreakParent = {
  161. type: "line",
  162. hard: true,
  163. literal: true
  164. };
  165. var line = {
  166. type: "line"
  167. };
  168. var softline = {
  169. type: "line",
  170. soft: true
  171. };
  172. var hardline = concat([hardlineWithoutBreakParent, breakParent]);
  173. var literalline = concat([literallineWithoutBreakParent, breakParent]);
  174. var cursor = {
  175. type: "cursor",
  176. placeholder: Symbol("cursor")
  177. };
  178. function join(sep, arr) {
  179. const res = [];
  180. for (let i = 0; i < arr.length; i++) {
  181. if (i !== 0) {
  182. res.push(sep);
  183. }
  184. res.push(arr[i]);
  185. }
  186. return concat(res);
  187. }
  188. function addAlignmentToDoc(doc, size, tabWidth) {
  189. let aligned = doc;
  190. if (size > 0) {
  191. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  192. aligned = indent(aligned);
  193. }
  194. aligned = align(size % tabWidth, aligned);
  195. aligned = align(Number.NEGATIVE_INFINITY, aligned);
  196. }
  197. return aligned;
  198. }
  199. function label(label2, contents) {
  200. return {
  201. type: "label",
  202. label: label2,
  203. contents
  204. };
  205. }
  206. module2.exports = {
  207. concat,
  208. join,
  209. line,
  210. softline,
  211. hardline,
  212. literalline,
  213. group,
  214. conditionalGroup,
  215. fill,
  216. lineSuffix,
  217. lineSuffixBoundary,
  218. cursor,
  219. breakParent,
  220. ifBreak,
  221. trim,
  222. indent,
  223. indentIfBreak,
  224. align,
  225. addAlignmentToDoc,
  226. markAsRoot,
  227. dedentToRoot,
  228. dedent,
  229. hardlineWithoutBreakParent,
  230. literallineWithoutBreakParent,
  231. label
  232. };
  233. }
  234. });
  235. var require_end_of_line = __commonJS2({
  236. "src/common/end-of-line.js"(exports2, module2) {
  237. "use strict";
  238. init_define_process();
  239. function guessEndOfLine(text) {
  240. const index = text.indexOf("\r");
  241. if (index >= 0) {
  242. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  243. }
  244. return "lf";
  245. }
  246. function convertEndOfLineToChars(value) {
  247. switch (value) {
  248. case "cr":
  249. return "\r";
  250. case "crlf":
  251. return "\r\n";
  252. default:
  253. return "\n";
  254. }
  255. }
  256. function countEndOfLineChars(text, eol) {
  257. let regex;
  258. switch (eol) {
  259. case "\n":
  260. regex = /\n/g;
  261. break;
  262. case "\r":
  263. regex = /\r/g;
  264. break;
  265. case "\r\n":
  266. regex = /\r\n/g;
  267. break;
  268. default:
  269. throw new Error('Unexpected "eol" '.concat(JSON.stringify(eol), "."));
  270. }
  271. const endOfLines = text.match(regex);
  272. return endOfLines ? endOfLines.length : 0;
  273. }
  274. function normalizeEndOfLine(text) {
  275. return text.replace(/\r\n?/g, "\n");
  276. }
  277. module2.exports = {
  278. guessEndOfLine,
  279. convertEndOfLineToChars,
  280. countEndOfLineChars,
  281. normalizeEndOfLine
  282. };
  283. }
  284. });
  285. var require_get_last = __commonJS2({
  286. "src/utils/get-last.js"(exports2, module2) {
  287. "use strict";
  288. init_define_process();
  289. var getLast = (arr) => arr[arr.length - 1];
  290. module2.exports = getLast;
  291. }
  292. });
  293. var require_string_width = __commonJS2({
  294. "vendors/string-width.js"(exports2, module2) {
  295. init_define_process();
  296. var __create = Object.create;
  297. var __defProp = Object.defineProperty;
  298. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  299. var __getOwnPropNames22 = Object.getOwnPropertyNames;
  300. var __getProtoOf = Object.getPrototypeOf;
  301. var __hasOwnProp = Object.prototype.hasOwnProperty;
  302. var __commonJS22 = (cb, mod) => function __require() {
  303. return mod || (0, cb[__getOwnPropNames22(cb)[0]])((mod = {
  304. exports: {}
  305. }).exports, mod), mod.exports;
  306. };
  307. var __export = (target, all) => {
  308. for (var name in all)
  309. __defProp(target, name, {
  310. get: all[name],
  311. enumerable: true
  312. });
  313. };
  314. var __copyProps = (to, from, except, desc) => {
  315. if (from && typeof from === "object" || typeof from === "function") {
  316. for (let key of __getOwnPropNames22(from))
  317. if (!__hasOwnProp.call(to, key) && key !== except)
  318. __defProp(to, key, {
  319. get: () => from[key],
  320. enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
  321. });
  322. }
  323. return to;
  324. };
  325. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
  326. value: mod,
  327. enumerable: true
  328. }) : target, mod));
  329. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", {
  330. value: true
  331. }), mod);
  332. var require_emoji_regex = __commonJS22({
  333. "node_modules/emoji-regex/index.js"(exports3, module22) {
  334. "use strict";
  335. module22.exports = function() {
  336. 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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D83D[\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\uDD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DD1C\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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\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
  337. };
  338. }
  339. });
  340. var string_width_exports = {};
  341. __export(string_width_exports, {
  342. default: () => stringWidth
  343. });
  344. module2.exports = __toCommonJS(string_width_exports);
  345. function ansiRegex() {
  346. let {
  347. onlyFirst = false
  348. } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
  349. 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("|");
  350. return new RegExp(pattern, onlyFirst ? void 0 : "g");
  351. }
  352. function stripAnsi(string) {
  353. if (typeof string !== "string") {
  354. throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
  355. }
  356. return string.replace(ansiRegex(), "");
  357. }
  358. function isFullwidthCodePoint(codePoint) {
  359. if (!Number.isInteger(codePoint)) {
  360. return false;
  361. }
  362. 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);
  363. }
  364. var import_emoji_regex = __toESM(require_emoji_regex(), 1);
  365. function stringWidth(string) {
  366. if (typeof string !== "string" || string.length === 0) {
  367. return 0;
  368. }
  369. string = stripAnsi(string);
  370. if (string.length === 0) {
  371. return 0;
  372. }
  373. string = string.replace((0, import_emoji_regex.default)(), " ");
  374. let width = 0;
  375. for (let index = 0; index < string.length; index++) {
  376. const codePoint = string.codePointAt(index);
  377. if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
  378. continue;
  379. }
  380. if (codePoint >= 768 && codePoint <= 879) {
  381. continue;
  382. }
  383. if (codePoint > 65535) {
  384. index++;
  385. }
  386. width += isFullwidthCodePoint(codePoint) ? 2 : 1;
  387. }
  388. return width;
  389. }
  390. }
  391. });
  392. var require_get_string_width = __commonJS2({
  393. "src/utils/get-string-width.js"(exports2, module2) {
  394. "use strict";
  395. init_define_process();
  396. var stringWidth = require_string_width().default;
  397. var notAsciiRegex = /[^\x20-\x7F]/;
  398. function getStringWidth(text) {
  399. if (!text) {
  400. return 0;
  401. }
  402. if (!notAsciiRegex.test(text)) {
  403. return text.length;
  404. }
  405. return stringWidth(text);
  406. }
  407. module2.exports = getStringWidth;
  408. }
  409. });
  410. var require_doc_utils = __commonJS2({
  411. "src/document/doc-utils.js"(exports2, module2) {
  412. "use strict";
  413. init_define_process();
  414. var getLast = require_get_last();
  415. var {
  416. literalline,
  417. join
  418. } = require_doc_builders();
  419. var isConcat = (doc) => Array.isArray(doc) || doc && doc.type === "concat";
  420. var getDocParts = (doc) => {
  421. if (Array.isArray(doc)) {
  422. return doc;
  423. }
  424. if (doc.type !== "concat" && doc.type !== "fill") {
  425. throw new Error("Expect doc type to be `concat` or `fill`.");
  426. }
  427. return doc.parts;
  428. };
  429. var traverseDocOnExitStackMarker = {};
  430. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  431. const docsStack = [doc];
  432. while (docsStack.length > 0) {
  433. const doc2 = docsStack.pop();
  434. if (doc2 === traverseDocOnExitStackMarker) {
  435. onExit(docsStack.pop());
  436. continue;
  437. }
  438. if (onExit) {
  439. docsStack.push(doc2, traverseDocOnExitStackMarker);
  440. }
  441. if (!onEnter || onEnter(doc2) !== false) {
  442. if (isConcat(doc2) || doc2.type === "fill") {
  443. const parts = getDocParts(doc2);
  444. for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
  445. docsStack.push(parts[i]);
  446. }
  447. } else if (doc2.type === "if-break") {
  448. if (doc2.flatContents) {
  449. docsStack.push(doc2.flatContents);
  450. }
  451. if (doc2.breakContents) {
  452. docsStack.push(doc2.breakContents);
  453. }
  454. } else if (doc2.type === "group" && doc2.expandedStates) {
  455. if (shouldTraverseConditionalGroups) {
  456. for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
  457. docsStack.push(doc2.expandedStates[i]);
  458. }
  459. } else {
  460. docsStack.push(doc2.contents);
  461. }
  462. } else if (doc2.contents) {
  463. docsStack.push(doc2.contents);
  464. }
  465. }
  466. }
  467. }
  468. function mapDoc(doc, cb) {
  469. const mapped = /* @__PURE__ */ new Map();
  470. return rec(doc);
  471. function rec(doc2) {
  472. if (mapped.has(doc2)) {
  473. return mapped.get(doc2);
  474. }
  475. const result = process2(doc2);
  476. mapped.set(doc2, result);
  477. return result;
  478. }
  479. function process2(doc2) {
  480. if (Array.isArray(doc2)) {
  481. return cb(doc2.map(rec));
  482. }
  483. if (doc2.type === "concat" || doc2.type === "fill") {
  484. const parts = doc2.parts.map(rec);
  485. return cb(Object.assign(Object.assign({}, doc2), {}, {
  486. parts
  487. }));
  488. }
  489. if (doc2.type === "if-break") {
  490. const breakContents = doc2.breakContents && rec(doc2.breakContents);
  491. const flatContents = doc2.flatContents && rec(doc2.flatContents);
  492. return cb(Object.assign(Object.assign({}, doc2), {}, {
  493. breakContents,
  494. flatContents
  495. }));
  496. }
  497. if (doc2.type === "group" && doc2.expandedStates) {
  498. const expandedStates = doc2.expandedStates.map(rec);
  499. const contents = expandedStates[0];
  500. return cb(Object.assign(Object.assign({}, doc2), {}, {
  501. contents,
  502. expandedStates
  503. }));
  504. }
  505. if (doc2.contents) {
  506. const contents = rec(doc2.contents);
  507. return cb(Object.assign(Object.assign({}, doc2), {}, {
  508. contents
  509. }));
  510. }
  511. return cb(doc2);
  512. }
  513. }
  514. function findInDoc(doc, fn, defaultValue) {
  515. let result = defaultValue;
  516. let hasStopped = false;
  517. function findInDocOnEnterFn(doc2) {
  518. const maybeResult = fn(doc2);
  519. if (maybeResult !== void 0) {
  520. hasStopped = true;
  521. result = maybeResult;
  522. }
  523. if (hasStopped) {
  524. return false;
  525. }
  526. }
  527. traverseDoc(doc, findInDocOnEnterFn);
  528. return result;
  529. }
  530. function willBreakFn(doc) {
  531. if (doc.type === "group" && doc.break) {
  532. return true;
  533. }
  534. if (doc.type === "line" && doc.hard) {
  535. return true;
  536. }
  537. if (doc.type === "break-parent") {
  538. return true;
  539. }
  540. }
  541. function willBreak(doc) {
  542. return findInDoc(doc, willBreakFn, false);
  543. }
  544. function breakParentGroup(groupStack) {
  545. if (groupStack.length > 0) {
  546. const parentGroup = getLast(groupStack);
  547. if (!parentGroup.expandedStates && !parentGroup.break) {
  548. parentGroup.break = "propagated";
  549. }
  550. }
  551. return null;
  552. }
  553. function propagateBreaks(doc) {
  554. const alreadyVisitedSet = /* @__PURE__ */ new Set();
  555. const groupStack = [];
  556. function propagateBreaksOnEnterFn(doc2) {
  557. if (doc2.type === "break-parent") {
  558. breakParentGroup(groupStack);
  559. }
  560. if (doc2.type === "group") {
  561. groupStack.push(doc2);
  562. if (alreadyVisitedSet.has(doc2)) {
  563. return false;
  564. }
  565. alreadyVisitedSet.add(doc2);
  566. }
  567. }
  568. function propagateBreaksOnExitFn(doc2) {
  569. if (doc2.type === "group") {
  570. const group = groupStack.pop();
  571. if (group.break) {
  572. breakParentGroup(groupStack);
  573. }
  574. }
  575. }
  576. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn, true);
  577. }
  578. function removeLinesFn(doc) {
  579. if (doc.type === "line" && !doc.hard) {
  580. return doc.soft ? "" : " ";
  581. }
  582. if (doc.type === "if-break") {
  583. return doc.flatContents || "";
  584. }
  585. return doc;
  586. }
  587. function removeLines(doc) {
  588. return mapDoc(doc, removeLinesFn);
  589. }
  590. var isHardline = (doc, nextDoc) => doc && doc.type === "line" && doc.hard && nextDoc && nextDoc.type === "break-parent";
  591. function stripDocTrailingHardlineFromDoc(doc) {
  592. if (!doc) {
  593. return doc;
  594. }
  595. if (isConcat(doc) || doc.type === "fill") {
  596. const parts = getDocParts(doc);
  597. while (parts.length > 1 && isHardline(...parts.slice(-2))) {
  598. parts.length -= 2;
  599. }
  600. if (parts.length > 0) {
  601. const lastPart = stripDocTrailingHardlineFromDoc(getLast(parts));
  602. parts[parts.length - 1] = lastPart;
  603. }
  604. return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
  605. parts
  606. });
  607. }
  608. switch (doc.type) {
  609. case "align":
  610. case "indent":
  611. case "indent-if-break":
  612. case "group":
  613. case "line-suffix":
  614. case "label": {
  615. const contents = stripDocTrailingHardlineFromDoc(doc.contents);
  616. return Object.assign(Object.assign({}, doc), {}, {
  617. contents
  618. });
  619. }
  620. case "if-break": {
  621. const breakContents = stripDocTrailingHardlineFromDoc(doc.breakContents);
  622. const flatContents = stripDocTrailingHardlineFromDoc(doc.flatContents);
  623. return Object.assign(Object.assign({}, doc), {}, {
  624. breakContents,
  625. flatContents
  626. });
  627. }
  628. }
  629. return doc;
  630. }
  631. function stripTrailingHardline(doc) {
  632. return stripDocTrailingHardlineFromDoc(cleanDoc(doc));
  633. }
  634. function cleanDocFn(doc) {
  635. switch (doc.type) {
  636. case "fill":
  637. if (doc.parts.every((part) => part === "")) {
  638. return "";
  639. }
  640. break;
  641. case "group":
  642. if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) {
  643. return "";
  644. }
  645. if (doc.contents.type === "group" && doc.contents.id === doc.id && doc.contents.break === doc.break && doc.contents.expandedStates === doc.expandedStates) {
  646. return doc.contents;
  647. }
  648. break;
  649. case "align":
  650. case "indent":
  651. case "indent-if-break":
  652. case "line-suffix":
  653. if (!doc.contents) {
  654. return "";
  655. }
  656. break;
  657. case "if-break":
  658. if (!doc.flatContents && !doc.breakContents) {
  659. return "";
  660. }
  661. break;
  662. }
  663. if (!isConcat(doc)) {
  664. return doc;
  665. }
  666. const parts = [];
  667. for (const part of getDocParts(doc)) {
  668. if (!part) {
  669. continue;
  670. }
  671. const [currentPart, ...restParts] = isConcat(part) ? getDocParts(part) : [part];
  672. if (typeof currentPart === "string" && typeof getLast(parts) === "string") {
  673. parts[parts.length - 1] += currentPart;
  674. } else {
  675. parts.push(currentPart);
  676. }
  677. parts.push(...restParts);
  678. }
  679. if (parts.length === 0) {
  680. return "";
  681. }
  682. if (parts.length === 1) {
  683. return parts[0];
  684. }
  685. return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
  686. parts
  687. });
  688. }
  689. function cleanDoc(doc) {
  690. return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
  691. }
  692. function normalizeParts(parts) {
  693. const newParts = [];
  694. const restParts = parts.filter(Boolean);
  695. while (restParts.length > 0) {
  696. const part = restParts.shift();
  697. if (!part) {
  698. continue;
  699. }
  700. if (isConcat(part)) {
  701. restParts.unshift(...getDocParts(part));
  702. continue;
  703. }
  704. if (newParts.length > 0 && typeof getLast(newParts) === "string" && typeof part === "string") {
  705. newParts[newParts.length - 1] += part;
  706. continue;
  707. }
  708. newParts.push(part);
  709. }
  710. return newParts;
  711. }
  712. function normalizeDoc(doc) {
  713. return mapDoc(doc, (currentDoc) => {
  714. if (Array.isArray(currentDoc)) {
  715. return normalizeParts(currentDoc);
  716. }
  717. if (!currentDoc.parts) {
  718. return currentDoc;
  719. }
  720. return Object.assign(Object.assign({}, currentDoc), {}, {
  721. parts: normalizeParts(currentDoc.parts)
  722. });
  723. });
  724. }
  725. function replaceEndOfLine(doc) {
  726. return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" && currentDoc.includes("\n") ? replaceTextEndOfLine(currentDoc) : currentDoc);
  727. }
  728. function replaceTextEndOfLine(text) {
  729. let replacement = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : literalline;
  730. return join(replacement, text.split("\n")).parts;
  731. }
  732. function canBreakFn(doc) {
  733. if (doc.type === "line") {
  734. return true;
  735. }
  736. }
  737. function canBreak(doc) {
  738. return findInDoc(doc, canBreakFn, false);
  739. }
  740. module2.exports = {
  741. isConcat,
  742. getDocParts,
  743. willBreak,
  744. traverseDoc,
  745. findInDoc,
  746. mapDoc,
  747. propagateBreaks,
  748. removeLines,
  749. stripTrailingHardline,
  750. normalizeParts,
  751. normalizeDoc,
  752. cleanDoc,
  753. replaceTextEndOfLine,
  754. replaceEndOfLine,
  755. canBreak
  756. };
  757. }
  758. });
  759. var require_doc_printer = __commonJS2({
  760. "src/document/doc-printer.js"(exports2, module2) {
  761. "use strict";
  762. init_define_process();
  763. var {
  764. convertEndOfLineToChars
  765. } = require_end_of_line();
  766. var getLast = require_get_last();
  767. var getStringWidth = require_get_string_width();
  768. var {
  769. fill,
  770. cursor,
  771. indent
  772. } = require_doc_builders();
  773. var {
  774. isConcat,
  775. getDocParts
  776. } = require_doc_utils();
  777. var groupModeMap;
  778. var MODE_BREAK = 1;
  779. var MODE_FLAT = 2;
  780. function rootIndent() {
  781. return {
  782. value: "",
  783. length: 0,
  784. queue: []
  785. };
  786. }
  787. function makeIndent(ind, options) {
  788. return generateInd(ind, {
  789. type: "indent"
  790. }, options);
  791. }
  792. function makeAlign(indent2, widthOrDoc, options) {
  793. if (widthOrDoc === Number.NEGATIVE_INFINITY) {
  794. return indent2.root || rootIndent();
  795. }
  796. if (widthOrDoc < 0) {
  797. return generateInd(indent2, {
  798. type: "dedent"
  799. }, options);
  800. }
  801. if (!widthOrDoc) {
  802. return indent2;
  803. }
  804. if (widthOrDoc.type === "root") {
  805. return Object.assign(Object.assign({}, indent2), {}, {
  806. root: indent2
  807. });
  808. }
  809. const alignType = typeof widthOrDoc === "string" ? "stringAlign" : "numberAlign";
  810. return generateInd(indent2, {
  811. type: alignType,
  812. n: widthOrDoc
  813. }, options);
  814. }
  815. function generateInd(ind, newPart, options) {
  816. const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : [...ind.queue, newPart];
  817. let value = "";
  818. let length = 0;
  819. let lastTabs = 0;
  820. let lastSpaces = 0;
  821. for (const part of queue) {
  822. switch (part.type) {
  823. case "indent":
  824. flush();
  825. if (options.useTabs) {
  826. addTabs(1);
  827. } else {
  828. addSpaces(options.tabWidth);
  829. }
  830. break;
  831. case "stringAlign":
  832. flush();
  833. value += part.n;
  834. length += part.n.length;
  835. break;
  836. case "numberAlign":
  837. lastTabs += 1;
  838. lastSpaces += part.n;
  839. break;
  840. default:
  841. throw new Error("Unexpected type '".concat(part.type, "'"));
  842. }
  843. }
  844. flushSpaces();
  845. return Object.assign(Object.assign({}, ind), {}, {
  846. value,
  847. length,
  848. queue
  849. });
  850. function addTabs(count) {
  851. value += " ".repeat(count);
  852. length += options.tabWidth * count;
  853. }
  854. function addSpaces(count) {
  855. value += " ".repeat(count);
  856. length += count;
  857. }
  858. function flush() {
  859. if (options.useTabs) {
  860. flushTabs();
  861. } else {
  862. flushSpaces();
  863. }
  864. }
  865. function flushTabs() {
  866. if (lastTabs > 0) {
  867. addTabs(lastTabs);
  868. }
  869. resetLast();
  870. }
  871. function flushSpaces() {
  872. if (lastSpaces > 0) {
  873. addSpaces(lastSpaces);
  874. }
  875. resetLast();
  876. }
  877. function resetLast() {
  878. lastTabs = 0;
  879. lastSpaces = 0;
  880. }
  881. }
  882. function trim(out) {
  883. if (out.length === 0) {
  884. return 0;
  885. }
  886. let trimCount = 0;
  887. while (out.length > 0 && typeof getLast(out) === "string" && /^[\t ]*$/.test(getLast(out))) {
  888. trimCount += out.pop().length;
  889. }
  890. if (out.length > 0 && typeof getLast(out) === "string") {
  891. const trimmed = getLast(out).replace(/[\t ]*$/, "");
  892. trimCount += getLast(out).length - trimmed.length;
  893. out[out.length - 1] = trimmed;
  894. }
  895. return trimCount;
  896. }
  897. function fits(next, restCommands, width, options, hasLineSuffix, mustBeFlat) {
  898. let restIdx = restCommands.length;
  899. const cmds = [next];
  900. const out = [];
  901. while (width >= 0) {
  902. if (cmds.length === 0) {
  903. if (restIdx === 0) {
  904. return true;
  905. }
  906. cmds.push(restCommands[restIdx - 1]);
  907. restIdx--;
  908. continue;
  909. }
  910. const [ind, mode, doc] = cmds.pop();
  911. if (typeof doc === "string") {
  912. out.push(doc);
  913. width -= getStringWidth(doc);
  914. } else if (isConcat(doc)) {
  915. const parts = getDocParts(doc);
  916. for (let i = parts.length - 1; i >= 0; i--) {
  917. cmds.push([ind, mode, parts[i]]);
  918. }
  919. } else {
  920. switch (doc.type) {
  921. case "indent":
  922. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  923. break;
  924. case "align":
  925. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  926. break;
  927. case "trim":
  928. width += trim(out);
  929. break;
  930. case "group": {
  931. if (mustBeFlat && doc.break) {
  932. return false;
  933. }
  934. const groupMode = doc.break ? MODE_BREAK : mode;
  935. cmds.push([ind, groupMode, doc.expandedStates && groupMode === MODE_BREAK ? getLast(doc.expandedStates) : doc.contents]);
  936. if (doc.id) {
  937. groupModeMap[doc.id] = groupMode;
  938. }
  939. break;
  940. }
  941. case "fill":
  942. for (let i = doc.parts.length - 1; i >= 0; i--) {
  943. cmds.push([ind, mode, doc.parts[i]]);
  944. }
  945. break;
  946. case "if-break":
  947. case "indent-if-break": {
  948. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  949. if (groupMode === MODE_BREAK) {
  950. const breakContents = doc.type === "if-break" ? doc.breakContents : doc.negate ? doc.contents : indent(doc.contents);
  951. if (breakContents) {
  952. cmds.push([ind, mode, breakContents]);
  953. }
  954. }
  955. if (groupMode === MODE_FLAT) {
  956. const flatContents = doc.type === "if-break" ? doc.flatContents : doc.negate ? indent(doc.contents) : doc.contents;
  957. if (flatContents) {
  958. cmds.push([ind, mode, flatContents]);
  959. }
  960. }
  961. break;
  962. }
  963. case "line":
  964. switch (mode) {
  965. case MODE_FLAT:
  966. if (!doc.hard) {
  967. if (!doc.soft) {
  968. out.push(" ");
  969. width -= 1;
  970. }
  971. break;
  972. }
  973. return true;
  974. case MODE_BREAK:
  975. return true;
  976. }
  977. break;
  978. case "line-suffix":
  979. hasLineSuffix = true;
  980. break;
  981. case "line-suffix-boundary":
  982. if (hasLineSuffix) {
  983. return false;
  984. }
  985. break;
  986. case "label":
  987. cmds.push([ind, mode, doc.contents]);
  988. break;
  989. }
  990. }
  991. }
  992. return false;
  993. }
  994. function printDocToString(doc, options) {
  995. groupModeMap = {};
  996. const width = options.printWidth;
  997. const newLine = convertEndOfLineToChars(options.endOfLine);
  998. let pos = 0;
  999. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  1000. const out = [];
  1001. let shouldRemeasure = false;
  1002. let lineSuffix = [];
  1003. while (cmds.length > 0) {
  1004. const [ind, mode, doc2] = cmds.pop();
  1005. if (typeof doc2 === "string") {
  1006. const formatted = newLine !== "\n" ? doc2.replace(/\n/g, newLine) : doc2;
  1007. out.push(formatted);
  1008. pos += getStringWidth(formatted);
  1009. } else if (isConcat(doc2)) {
  1010. const parts = getDocParts(doc2);
  1011. for (let i = parts.length - 1; i >= 0; i--) {
  1012. cmds.push([ind, mode, parts[i]]);
  1013. }
  1014. } else {
  1015. switch (doc2.type) {
  1016. case "cursor":
  1017. out.push(cursor.placeholder);
  1018. break;
  1019. case "indent":
  1020. cmds.push([makeIndent(ind, options), mode, doc2.contents]);
  1021. break;
  1022. case "align":
  1023. cmds.push([makeAlign(ind, doc2.n, options), mode, doc2.contents]);
  1024. break;
  1025. case "trim":
  1026. pos -= trim(out);
  1027. break;
  1028. case "group":
  1029. switch (mode) {
  1030. case MODE_FLAT:
  1031. if (!shouldRemeasure) {
  1032. cmds.push([ind, doc2.break ? MODE_BREAK : MODE_FLAT, doc2.contents]);
  1033. break;
  1034. }
  1035. case MODE_BREAK: {
  1036. shouldRemeasure = false;
  1037. const next = [ind, MODE_FLAT, doc2.contents];
  1038. const rem = width - pos;
  1039. const hasLineSuffix = lineSuffix.length > 0;
  1040. if (!doc2.break && fits(next, cmds, rem, options, hasLineSuffix)) {
  1041. cmds.push(next);
  1042. } else {
  1043. if (doc2.expandedStates) {
  1044. const mostExpanded = getLast(doc2.expandedStates);
  1045. if (doc2.break) {
  1046. cmds.push([ind, MODE_BREAK, mostExpanded]);
  1047. break;
  1048. } else {
  1049. for (let i = 1; i < doc2.expandedStates.length + 1; i++) {
  1050. if (i >= doc2.expandedStates.length) {
  1051. cmds.push([ind, MODE_BREAK, mostExpanded]);
  1052. break;
  1053. } else {
  1054. const state = doc2.expandedStates[i];
  1055. const cmd = [ind, MODE_FLAT, state];
  1056. if (fits(cmd, cmds, rem, options, hasLineSuffix)) {
  1057. cmds.push(cmd);
  1058. break;
  1059. }
  1060. }
  1061. }
  1062. }
  1063. } else {
  1064. cmds.push([ind, MODE_BREAK, doc2.contents]);
  1065. }
  1066. }
  1067. break;
  1068. }
  1069. }
  1070. if (doc2.id) {
  1071. groupModeMap[doc2.id] = getLast(cmds)[1];
  1072. }
  1073. break;
  1074. case "fill": {
  1075. const rem = width - pos;
  1076. const {
  1077. parts
  1078. } = doc2;
  1079. if (parts.length === 0) {
  1080. break;
  1081. }
  1082. const [content, whitespace] = parts;
  1083. const contentFlatCmd = [ind, MODE_FLAT, content];
  1084. const contentBreakCmd = [ind, MODE_BREAK, content];
  1085. const contentFits = fits(contentFlatCmd, [], rem, options, lineSuffix.length > 0, true);
  1086. if (parts.length === 1) {
  1087. if (contentFits) {
  1088. cmds.push(contentFlatCmd);
  1089. } else {
  1090. cmds.push(contentBreakCmd);
  1091. }
  1092. break;
  1093. }
  1094. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  1095. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  1096. if (parts.length === 2) {
  1097. if (contentFits) {
  1098. cmds.push(whitespaceFlatCmd, contentFlatCmd);
  1099. } else {
  1100. cmds.push(whitespaceBreakCmd, contentBreakCmd);
  1101. }
  1102. break;
  1103. }
  1104. parts.splice(0, 2);
  1105. const remainingCmd = [ind, mode, fill(parts)];
  1106. const secondContent = parts[0];
  1107. const firstAndSecondContentFlatCmd = [ind, MODE_FLAT, [content, whitespace, secondContent]];
  1108. const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, options, lineSuffix.length > 0, true);
  1109. if (firstAndSecondContentFits) {
  1110. cmds.push(remainingCmd, whitespaceFlatCmd, contentFlatCmd);
  1111. } else if (contentFits) {
  1112. cmds.push(remainingCmd, whitespaceBreakCmd, contentFlatCmd);
  1113. } else {
  1114. cmds.push(remainingCmd, whitespaceBreakCmd, contentBreakCmd);
  1115. }
  1116. break;
  1117. }
  1118. case "if-break":
  1119. case "indent-if-break": {
  1120. const groupMode = doc2.groupId ? groupModeMap[doc2.groupId] : mode;
  1121. if (groupMode === MODE_BREAK) {
  1122. const breakContents = doc2.type === "if-break" ? doc2.breakContents : doc2.negate ? doc2.contents : indent(doc2.contents);
  1123. if (breakContents) {
  1124. cmds.push([ind, mode, breakContents]);
  1125. }
  1126. }
  1127. if (groupMode === MODE_FLAT) {
  1128. const flatContents = doc2.type === "if-break" ? doc2.flatContents : doc2.negate ? indent(doc2.contents) : doc2.contents;
  1129. if (flatContents) {
  1130. cmds.push([ind, mode, flatContents]);
  1131. }
  1132. }
  1133. break;
  1134. }
  1135. case "line-suffix":
  1136. lineSuffix.push([ind, mode, doc2.contents]);
  1137. break;
  1138. case "line-suffix-boundary":
  1139. if (lineSuffix.length > 0) {
  1140. cmds.push([ind, mode, {
  1141. type: "line",
  1142. hard: true
  1143. }]);
  1144. }
  1145. break;
  1146. case "line":
  1147. switch (mode) {
  1148. case MODE_FLAT:
  1149. if (!doc2.hard) {
  1150. if (!doc2.soft) {
  1151. out.push(" ");
  1152. pos += 1;
  1153. }
  1154. break;
  1155. } else {
  1156. shouldRemeasure = true;
  1157. }
  1158. case MODE_BREAK:
  1159. if (lineSuffix.length > 0) {
  1160. cmds.push([ind, mode, doc2], ...lineSuffix.reverse());
  1161. lineSuffix = [];
  1162. break;
  1163. }
  1164. if (doc2.literal) {
  1165. if (ind.root) {
  1166. out.push(newLine, ind.root.value);
  1167. pos = ind.root.length;
  1168. } else {
  1169. out.push(newLine);
  1170. pos = 0;
  1171. }
  1172. } else {
  1173. pos -= trim(out);
  1174. out.push(newLine + ind.value);
  1175. pos = ind.length;
  1176. }
  1177. break;
  1178. }
  1179. break;
  1180. case "label":
  1181. cmds.push([ind, mode, doc2.contents]);
  1182. break;
  1183. default:
  1184. }
  1185. }
  1186. if (cmds.length === 0 && lineSuffix.length > 0) {
  1187. cmds.push(...lineSuffix.reverse());
  1188. lineSuffix = [];
  1189. }
  1190. }
  1191. const cursorPlaceholderIndex = out.indexOf(cursor.placeholder);
  1192. if (cursorPlaceholderIndex !== -1) {
  1193. const otherCursorPlaceholderIndex = out.indexOf(cursor.placeholder, cursorPlaceholderIndex + 1);
  1194. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  1195. const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  1196. const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  1197. return {
  1198. formatted: beforeCursor + aroundCursor + afterCursor,
  1199. cursorNodeStart: beforeCursor.length,
  1200. cursorNodeText: aroundCursor
  1201. };
  1202. }
  1203. return {
  1204. formatted: out.join("")
  1205. };
  1206. }
  1207. module2.exports = {
  1208. printDocToString
  1209. };
  1210. }
  1211. });
  1212. var require_doc_debug = __commonJS2({
  1213. "src/document/doc-debug.js"(exports2, module2) {
  1214. "use strict";
  1215. init_define_process();
  1216. var {
  1217. isConcat,
  1218. getDocParts
  1219. } = require_doc_utils();
  1220. function flattenDoc(doc) {
  1221. if (!doc) {
  1222. return "";
  1223. }
  1224. if (isConcat(doc)) {
  1225. const res = [];
  1226. for (const part of getDocParts(doc)) {
  1227. if (isConcat(part)) {
  1228. res.push(...flattenDoc(part).parts);
  1229. } else {
  1230. const flattened = flattenDoc(part);
  1231. if (flattened !== "") {
  1232. res.push(flattened);
  1233. }
  1234. }
  1235. }
  1236. return {
  1237. type: "concat",
  1238. parts: res
  1239. };
  1240. }
  1241. if (doc.type === "if-break") {
  1242. return Object.assign(Object.assign({}, doc), {}, {
  1243. breakContents: flattenDoc(doc.breakContents),
  1244. flatContents: flattenDoc(doc.flatContents)
  1245. });
  1246. }
  1247. if (doc.type === "group") {
  1248. return Object.assign(Object.assign({}, doc), {}, {
  1249. contents: flattenDoc(doc.contents),
  1250. expandedStates: doc.expandedStates && doc.expandedStates.map(flattenDoc)
  1251. });
  1252. }
  1253. if (doc.type === "fill") {
  1254. return {
  1255. type: "fill",
  1256. parts: doc.parts.map(flattenDoc)
  1257. };
  1258. }
  1259. if (doc.contents) {
  1260. return Object.assign(Object.assign({}, doc), {}, {
  1261. contents: flattenDoc(doc.contents)
  1262. });
  1263. }
  1264. return doc;
  1265. }
  1266. function printDocToDebug(doc) {
  1267. const printedSymbols = /* @__PURE__ */ Object.create(null);
  1268. const usedKeysForSymbols = /* @__PURE__ */ new Set();
  1269. return printDoc(flattenDoc(doc));
  1270. function printDoc(doc2, index, parentParts) {
  1271. if (typeof doc2 === "string") {
  1272. return JSON.stringify(doc2);
  1273. }
  1274. if (isConcat(doc2)) {
  1275. const printed = getDocParts(doc2).map(printDoc).filter(Boolean);
  1276. return printed.length === 1 ? printed[0] : "[".concat(printed.join(", "), "]");
  1277. }
  1278. if (doc2.type === "line") {
  1279. const withBreakParent = Array.isArray(parentParts) && parentParts[index + 1] && parentParts[index + 1].type === "break-parent";
  1280. if (doc2.literal) {
  1281. return withBreakParent ? "literalline" : "literallineWithoutBreakParent";
  1282. }
  1283. if (doc2.hard) {
  1284. return withBreakParent ? "hardline" : "hardlineWithoutBreakParent";
  1285. }
  1286. if (doc2.soft) {
  1287. return "softline";
  1288. }
  1289. return "line";
  1290. }
  1291. if (doc2.type === "break-parent") {
  1292. const afterHardline = Array.isArray(parentParts) && parentParts[index - 1] && parentParts[index - 1].type === "line" && parentParts[index - 1].hard;
  1293. return afterHardline ? void 0 : "breakParent";
  1294. }
  1295. if (doc2.type === "trim") {
  1296. return "trim";
  1297. }
  1298. if (doc2.type === "indent") {
  1299. return "indent(" + printDoc(doc2.contents) + ")";
  1300. }
  1301. if (doc2.type === "align") {
  1302. 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) + ")";
  1303. }
  1304. if (doc2.type === "if-break") {
  1305. return "ifBreak(" + printDoc(doc2.breakContents) + (doc2.flatContents ? ", " + printDoc(doc2.flatContents) : "") + (doc2.groupId ? (!doc2.flatContents ? ', ""' : "") + ", { groupId: ".concat(printGroupId(doc2.groupId), " }") : "") + ")";
  1306. }
  1307. if (doc2.type === "indent-if-break") {
  1308. const optionsParts = [];
  1309. if (doc2.negate) {
  1310. optionsParts.push("negate: true");
  1311. }
  1312. if (doc2.groupId) {
  1313. optionsParts.push("groupId: ".concat(printGroupId(doc2.groupId)));
  1314. }
  1315. const options = optionsParts.length > 0 ? ", { ".concat(optionsParts.join(", "), " }") : "";
  1316. return "indentIfBreak(".concat(printDoc(doc2.contents)).concat(options, ")");
  1317. }
  1318. if (doc2.type === "group") {
  1319. const optionsParts = [];
  1320. if (doc2.break && doc2.break !== "propagated") {
  1321. optionsParts.push("shouldBreak: true");
  1322. }
  1323. if (doc2.id) {
  1324. optionsParts.push("id: ".concat(printGroupId(doc2.id)));
  1325. }
  1326. const options = optionsParts.length > 0 ? ", { ".concat(optionsParts.join(", "), " }") : "";
  1327. if (doc2.expandedStates) {
  1328. return "conditionalGroup([".concat(doc2.expandedStates.map((part) => printDoc(part)).join(","), "]").concat(options, ")");
  1329. }
  1330. return "group(".concat(printDoc(doc2.contents)).concat(options, ")");
  1331. }
  1332. if (doc2.type === "fill") {
  1333. return "fill([".concat(doc2.parts.map((part) => printDoc(part)).join(", "), "])");
  1334. }
  1335. if (doc2.type === "line-suffix") {
  1336. return "lineSuffix(" + printDoc(doc2.contents) + ")";
  1337. }
  1338. if (doc2.type === "line-suffix-boundary") {
  1339. return "lineSuffixBoundary";
  1340. }
  1341. if (doc2.type === "label") {
  1342. return "label(".concat(JSON.stringify(doc2.label), ", ").concat(printDoc(doc2.contents), ")");
  1343. }
  1344. throw new Error("Unknown doc type " + doc2.type);
  1345. }
  1346. function printGroupId(id) {
  1347. if (typeof id !== "symbol") {
  1348. return JSON.stringify(String(id));
  1349. }
  1350. if (id in printedSymbols) {
  1351. return printedSymbols[id];
  1352. }
  1353. const prefix = String(id).slice(7, -1) || "symbol";
  1354. for (let counter = 0; ; counter++) {
  1355. const key = prefix + (counter > 0 ? " #".concat(counter) : "");
  1356. if (!usedKeysForSymbols.has(key)) {
  1357. usedKeysForSymbols.add(key);
  1358. return printedSymbols[id] = "Symbol.for(".concat(JSON.stringify(key), ")");
  1359. }
  1360. }
  1361. }
  1362. }
  1363. module2.exports = {
  1364. printDocToDebug
  1365. };
  1366. }
  1367. });
  1368. init_define_process();
  1369. module.exports = {
  1370. builders: require_doc_builders(),
  1371. printer: require_doc_printer(),
  1372. utils: require_doc_utils(),
  1373. debug: require_doc_debug()
  1374. };
  1375. }
  1376. });
  1377. "use strict";
  1378. return require_doc();
  1379. });