doc.js 50 KB

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