12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340 |
- (function (factory) {
- function interopModuleDefault() {
- var module = factory();
- return module.default || module;
- }
- if (typeof exports === "object" && typeof module === "object") {
- module.exports = interopModuleDefault();
- } else if (typeof define === "function" && define.amd) {
- define(interopModuleDefault);
- } else {
- var root =
- typeof globalThis !== "undefined"
- ? globalThis
- : typeof global !== "undefined"
- ? global
- : typeof self !== "undefined"
- ? self
- : this || {};
- root.doc = interopModuleDefault();
- }
- })(function() {
- "use strict";
- var __defProp = Object.defineProperty;
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
- var __getOwnPropNames = Object.getOwnPropertyNames;
- var __hasOwnProp = Object.prototype.hasOwnProperty;
- var __export = (target, all) => {
- for (var name in all)
- __defProp(target, name, { get: all[name], enumerable: true });
- };
- var __copyProps = (to, from, except, desc) => {
- if (from && typeof from === "object" || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
- }
- return to;
- };
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
- // src/document/public.js
- var public_exports = {};
- __export(public_exports, {
- builders: () => builders,
- printer: () => printer,
- utils: () => utils
- });
- // src/document/constants.js
- var DOC_TYPE_STRING = "string";
- var DOC_TYPE_ARRAY = "array";
- var DOC_TYPE_CURSOR = "cursor";
- var DOC_TYPE_INDENT = "indent";
- var DOC_TYPE_ALIGN = "align";
- var DOC_TYPE_TRIM = "trim";
- var DOC_TYPE_GROUP = "group";
- var DOC_TYPE_FILL = "fill";
- var DOC_TYPE_IF_BREAK = "if-break";
- var DOC_TYPE_INDENT_IF_BREAK = "indent-if-break";
- var DOC_TYPE_LINE_SUFFIX = "line-suffix";
- var DOC_TYPE_LINE_SUFFIX_BOUNDARY = "line-suffix-boundary";
- var DOC_TYPE_LINE = "line";
- var DOC_TYPE_LABEL = "label";
- var DOC_TYPE_BREAK_PARENT = "break-parent";
- var VALID_OBJECT_DOC_TYPES = /* @__PURE__ */ new Set([
- DOC_TYPE_CURSOR,
- DOC_TYPE_INDENT,
- DOC_TYPE_ALIGN,
- DOC_TYPE_TRIM,
- DOC_TYPE_GROUP,
- DOC_TYPE_FILL,
- DOC_TYPE_IF_BREAK,
- DOC_TYPE_INDENT_IF_BREAK,
- DOC_TYPE_LINE_SUFFIX,
- DOC_TYPE_LINE_SUFFIX_BOUNDARY,
- DOC_TYPE_LINE,
- DOC_TYPE_LABEL,
- DOC_TYPE_BREAK_PARENT
- ]);
- // src/document/utils/get-doc-type.js
- function getDocType(doc) {
- if (typeof doc === "string") {
- return DOC_TYPE_STRING;
- }
- if (Array.isArray(doc)) {
- return DOC_TYPE_ARRAY;
- }
- if (!doc) {
- return;
- }
- const { type } = doc;
- if (VALID_OBJECT_DOC_TYPES.has(type)) {
- return type;
- }
- }
- var get_doc_type_default = getDocType;
- // src/document/invalid-doc-error.js
- var disjunctionListFormat = (list) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(list);
- function getDocErrorMessage(doc) {
- const type = doc === null ? "null" : typeof doc;
- if (type !== "string" && type !== "object") {
- return `Unexpected doc '${type}',
- Expected it to be 'string' or 'object'.`;
- }
- if (get_doc_type_default(doc)) {
- throw new Error("doc is valid.");
- }
- const objectType = Object.prototype.toString.call(doc);
- if (objectType !== "[object Object]") {
- return `Unexpected doc '${objectType}'.`;
- }
- const EXPECTED_TYPE_VALUES = disjunctionListFormat(
- [...VALID_OBJECT_DOC_TYPES].map((type2) => `'${type2}'`)
- );
- return `Unexpected doc.type '${doc.type}'.
- Expected it to be ${EXPECTED_TYPE_VALUES}.`;
- }
- var InvalidDocError = class extends Error {
- name = "InvalidDocError";
- constructor(doc) {
- super(getDocErrorMessage(doc));
- this.doc = doc;
- }
- };
- var invalid_doc_error_default = InvalidDocError;
- // src/document/utils/traverse-doc.js
- var traverseDocOnExitStackMarker = {};
- function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
- const docsStack = [doc];
- while (docsStack.length > 0) {
- const doc2 = docsStack.pop();
- if (doc2 === traverseDocOnExitStackMarker) {
- onExit(docsStack.pop());
- continue;
- }
- if (onExit) {
- docsStack.push(doc2, traverseDocOnExitStackMarker);
- }
- const docType = get_doc_type_default(doc2);
- if (!docType) {
- throw new invalid_doc_error_default(doc2);
- }
- if ((onEnter == null ? void 0 : onEnter(doc2)) === false) {
- continue;
- }
- switch (docType) {
- case DOC_TYPE_ARRAY:
- case DOC_TYPE_FILL: {
- const parts = docType === DOC_TYPE_ARRAY ? doc2 : doc2.parts;
- for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
- docsStack.push(parts[i]);
- }
- break;
- }
- case DOC_TYPE_IF_BREAK:
- docsStack.push(doc2.flatContents, doc2.breakContents);
- break;
- case DOC_TYPE_GROUP:
- if (shouldTraverseConditionalGroups && doc2.expandedStates) {
- for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
- docsStack.push(doc2.expandedStates[i]);
- }
- } else {
- docsStack.push(doc2.contents);
- }
- break;
- case DOC_TYPE_ALIGN:
- case DOC_TYPE_INDENT:
- case DOC_TYPE_INDENT_IF_BREAK:
- case DOC_TYPE_LABEL:
- case DOC_TYPE_LINE_SUFFIX:
- docsStack.push(doc2.contents);
- break;
- case DOC_TYPE_STRING:
- case DOC_TYPE_CURSOR:
- case DOC_TYPE_TRIM:
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- case DOC_TYPE_LINE:
- case DOC_TYPE_BREAK_PARENT:
- break;
- default:
- throw new invalid_doc_error_default(doc2);
- }
- }
- }
- var traverse_doc_default = traverseDoc;
- // src/document/utils/assert-doc.js
- var noop = () => {
- };
- var assertDoc = true ? noop : function(doc) {
- traverse_doc_default(doc, (doc2) => {
- if (checked.has(doc2)) {
- return false;
- }
- if (typeof doc2 !== "string") {
- checked.add(doc2);
- }
- });
- };
- var assertDocArray = true ? noop : function(docs, optional = false) {
- if (optional && !docs) {
- return;
- }
- if (!Array.isArray(docs)) {
- throw new TypeError("Unexpected doc array.");
- }
- for (const doc of docs) {
- assertDoc(doc);
- }
- };
- // src/document/builders.js
- function indent(contents) {
- assertDoc(contents);
- return { type: DOC_TYPE_INDENT, contents };
- }
- function align(widthOrString, contents) {
- assertDoc(contents);
- return { type: DOC_TYPE_ALIGN, contents, n: widthOrString };
- }
- function group(contents, opts = {}) {
- assertDoc(contents);
- assertDocArray(
- opts.expandedStates,
- /* optional */
- true
- );
- return {
- type: DOC_TYPE_GROUP,
- id: opts.id,
- contents,
- break: Boolean(opts.shouldBreak),
- expandedStates: opts.expandedStates
- };
- }
- function dedentToRoot(contents) {
- return align(Number.NEGATIVE_INFINITY, contents);
- }
- function markAsRoot(contents) {
- return align({ type: "root" }, contents);
- }
- function dedent(contents) {
- return align(-1, contents);
- }
- function conditionalGroup(states, opts) {
- return group(states[0], { ...opts, expandedStates: states });
- }
- function fill(parts) {
- assertDocArray(parts);
- return { type: DOC_TYPE_FILL, parts };
- }
- function ifBreak(breakContents, flatContents = "", opts = {}) {
- assertDoc(breakContents);
- if (flatContents !== "") {
- assertDoc(flatContents);
- }
- return {
- type: DOC_TYPE_IF_BREAK,
- breakContents,
- flatContents,
- groupId: opts.groupId
- };
- }
- function indentIfBreak(contents, opts) {
- assertDoc(contents);
- return {
- type: DOC_TYPE_INDENT_IF_BREAK,
- contents,
- groupId: opts.groupId,
- negate: opts.negate
- };
- }
- function lineSuffix(contents) {
- assertDoc(contents);
- return { type: DOC_TYPE_LINE_SUFFIX, contents };
- }
- var lineSuffixBoundary = { type: DOC_TYPE_LINE_SUFFIX_BOUNDARY };
- var breakParent = { type: DOC_TYPE_BREAK_PARENT };
- var trim = { type: DOC_TYPE_TRIM };
- var hardlineWithoutBreakParent = { type: DOC_TYPE_LINE, hard: true };
- var literallineWithoutBreakParent = {
- type: DOC_TYPE_LINE,
- hard: true,
- literal: true
- };
- var line = { type: DOC_TYPE_LINE };
- var softline = { type: DOC_TYPE_LINE, soft: true };
- var hardline = [hardlineWithoutBreakParent, breakParent];
- var literalline = [literallineWithoutBreakParent, breakParent];
- var cursor = { type: DOC_TYPE_CURSOR };
- function join(separator, docs) {
- assertDoc(separator);
- assertDocArray(docs);
- const parts = [];
- for (let i = 0; i < docs.length; i++) {
- if (i !== 0) {
- parts.push(separator);
- }
- parts.push(docs[i]);
- }
- return parts;
- }
- function addAlignmentToDoc(doc, size, tabWidth) {
- assertDoc(doc);
- let aligned = doc;
- if (size > 0) {
- for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
- aligned = indent(aligned);
- }
- aligned = align(size % tabWidth, aligned);
- aligned = align(Number.NEGATIVE_INFINITY, aligned);
- }
- return aligned;
- }
- function label(label2, contents) {
- assertDoc(contents);
- return label2 ? { type: DOC_TYPE_LABEL, label: label2, contents } : contents;
- }
- // scripts/build/shims/at.js
- var at = (isOptionalObject, object, index) => {
- if (isOptionalObject && (object === void 0 || object === null)) {
- return;
- }
- if (Array.isArray(object) || typeof object === "string") {
- return object[index < 0 ? object.length + index : index];
- }
- return object.at(index);
- };
- var at_default = at;
- // scripts/build/shims/string-replace-all.js
- var stringReplaceAll = (isOptionalObject, original, pattern, replacement) => {
- if (isOptionalObject && (original === void 0 || original === null)) {
- return;
- }
- if (original.replaceAll) {
- return original.replaceAll(pattern, replacement);
- }
- if (pattern.global) {
- return original.replace(pattern, replacement);
- }
- return original.split(pattern).join(replacement);
- };
- var string_replace_all_default = stringReplaceAll;
- // src/common/end-of-line.js
- function convertEndOfLineToChars(value) {
- switch (value) {
- case "cr":
- return "\r";
- case "crlf":
- return "\r\n";
- default:
- return "\n";
- }
- }
- // node_modules/emoji-regex/index.mjs
- var emoji_regex_default = () => {
- 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;
- };
- // node_modules/eastasianwidth/eastasianwidth.js
- var eastasianwidth_default = {
- eastAsianWidth(character) {
- var x = character.charCodeAt(0);
- var y = character.length == 2 ? character.charCodeAt(1) : 0;
- var codePoint = x;
- if (55296 <= x && x <= 56319 && 56320 <= y && y <= 57343) {
- x &= 1023;
- y &= 1023;
- codePoint = x << 10 | y;
- codePoint += 65536;
- }
- if (12288 == codePoint || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510) {
- return "F";
- }
- 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) {
- return "W";
- }
- return "N";
- }
- };
- // src/utils/get-string-width.js
- var notAsciiRegex = /[^\x20-\x7F]/;
- function getStringWidth(text) {
- if (!text) {
- return 0;
- }
- if (!notAsciiRegex.test(text)) {
- return text.length;
- }
- text = text.replace(emoji_regex_default(), " ");
- let width = 0;
- for (const character of text) {
- const codePoint = character.codePointAt(0);
- if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
- continue;
- }
- if (codePoint >= 768 && codePoint <= 879) {
- continue;
- }
- const code = eastasianwidth_default.eastAsianWidth(character);
- width += code === "F" || code === "W" ? 2 : 1;
- }
- return width;
- }
- var get_string_width_default = getStringWidth;
- // src/document/utils.js
- var getDocParts = (doc) => {
- if (Array.isArray(doc)) {
- return doc;
- }
- if (doc.type !== DOC_TYPE_FILL) {
- throw new Error(`Expect doc to be 'array' or '${DOC_TYPE_FILL}'.`);
- }
- return doc.parts;
- };
- function mapDoc(doc, cb) {
- if (typeof doc === "string") {
- return cb(doc);
- }
- const mapped = /* @__PURE__ */ new Map();
- return rec(doc);
- function rec(doc2) {
- if (mapped.has(doc2)) {
- return mapped.get(doc2);
- }
- const result = process2(doc2);
- mapped.set(doc2, result);
- return result;
- }
- function process2(doc2) {
- switch (get_doc_type_default(doc2)) {
- case DOC_TYPE_ARRAY:
- return cb(doc2.map(rec));
- case DOC_TYPE_FILL:
- return cb({
- ...doc2,
- parts: doc2.parts.map(rec)
- });
- case DOC_TYPE_IF_BREAK:
- return cb({
- ...doc2,
- breakContents: rec(doc2.breakContents),
- flatContents: rec(doc2.flatContents)
- });
- case DOC_TYPE_GROUP: {
- let {
- expandedStates,
- contents
- } = doc2;
- if (expandedStates) {
- expandedStates = expandedStates.map(rec);
- contents = expandedStates[0];
- } else {
- contents = rec(contents);
- }
- return cb({
- ...doc2,
- contents,
- expandedStates
- });
- }
- case DOC_TYPE_ALIGN:
- case DOC_TYPE_INDENT:
- case DOC_TYPE_INDENT_IF_BREAK:
- case DOC_TYPE_LABEL:
- case DOC_TYPE_LINE_SUFFIX:
- return cb({
- ...doc2,
- contents: rec(doc2.contents)
- });
- case DOC_TYPE_STRING:
- case DOC_TYPE_CURSOR:
- case DOC_TYPE_TRIM:
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- case DOC_TYPE_LINE:
- case DOC_TYPE_BREAK_PARENT:
- return cb(doc2);
- default:
- throw new invalid_doc_error_default(doc2);
- }
- }
- }
- function findInDoc(doc, fn, defaultValue) {
- let result = defaultValue;
- let shouldSkipFurtherProcessing = false;
- function findInDocOnEnterFn(doc2) {
- if (shouldSkipFurtherProcessing) {
- return false;
- }
- const maybeResult = fn(doc2);
- if (maybeResult !== void 0) {
- shouldSkipFurtherProcessing = true;
- result = maybeResult;
- }
- }
- traverse_doc_default(doc, findInDocOnEnterFn);
- return result;
- }
- function willBreakFn(doc) {
- if (doc.type === DOC_TYPE_GROUP && doc.break) {
- return true;
- }
- if (doc.type === DOC_TYPE_LINE && doc.hard) {
- return true;
- }
- if (doc.type === DOC_TYPE_BREAK_PARENT) {
- return true;
- }
- }
- function willBreak(doc) {
- return findInDoc(doc, willBreakFn, false);
- }
- function breakParentGroup(groupStack) {
- if (groupStack.length > 0) {
- const parentGroup = at_default(
- /* isOptionalObject*/
- false,
- groupStack,
- -1
- );
- if (!parentGroup.expandedStates && !parentGroup.break) {
- parentGroup.break = "propagated";
- }
- }
- return null;
- }
- function propagateBreaks(doc) {
- const alreadyVisitedSet = /* @__PURE__ */ new Set();
- const groupStack = [];
- function propagateBreaksOnEnterFn(doc2) {
- if (doc2.type === DOC_TYPE_BREAK_PARENT) {
- breakParentGroup(groupStack);
- }
- if (doc2.type === DOC_TYPE_GROUP) {
- groupStack.push(doc2);
- if (alreadyVisitedSet.has(doc2)) {
- return false;
- }
- alreadyVisitedSet.add(doc2);
- }
- }
- function propagateBreaksOnExitFn(doc2) {
- if (doc2.type === DOC_TYPE_GROUP) {
- const group2 = groupStack.pop();
- if (group2.break) {
- breakParentGroup(groupStack);
- }
- }
- }
- traverse_doc_default(
- doc,
- propagateBreaksOnEnterFn,
- propagateBreaksOnExitFn,
- /* shouldTraverseConditionalGroups */
- true
- );
- }
- function removeLinesFn(doc) {
- if (doc.type === DOC_TYPE_LINE && !doc.hard) {
- return doc.soft ? "" : " ";
- }
- if (doc.type === DOC_TYPE_IF_BREAK) {
- return doc.flatContents;
- }
- return doc;
- }
- function removeLines(doc) {
- return mapDoc(doc, removeLinesFn);
- }
- function stripTrailingHardlineFromParts(parts) {
- parts = [...parts];
- while (parts.length >= 2 && at_default(
- /* isOptionalObject*/
- false,
- parts,
- -2
- ).type === DOC_TYPE_LINE && at_default(
- /* isOptionalObject*/
- false,
- parts,
- -1
- ).type === DOC_TYPE_BREAK_PARENT) {
- parts.length -= 2;
- }
- if (parts.length > 0) {
- const lastPart = stripTrailingHardlineFromDoc(at_default(
- /* isOptionalObject*/
- false,
- parts,
- -1
- ));
- parts[parts.length - 1] = lastPart;
- }
- return parts;
- }
- function stripTrailingHardlineFromDoc(doc) {
- switch (get_doc_type_default(doc)) {
- case DOC_TYPE_ALIGN:
- case DOC_TYPE_INDENT:
- case DOC_TYPE_INDENT_IF_BREAK:
- case DOC_TYPE_GROUP:
- case DOC_TYPE_LINE_SUFFIX:
- case DOC_TYPE_LABEL: {
- const contents = stripTrailingHardlineFromDoc(doc.contents);
- return {
- ...doc,
- contents
- };
- }
- case DOC_TYPE_IF_BREAK:
- return {
- ...doc,
- breakContents: stripTrailingHardlineFromDoc(doc.breakContents),
- flatContents: stripTrailingHardlineFromDoc(doc.flatContents)
- };
- case DOC_TYPE_FILL:
- return {
- ...doc,
- parts: stripTrailingHardlineFromParts(doc.parts)
- };
- case DOC_TYPE_ARRAY:
- return stripTrailingHardlineFromParts(doc);
- case DOC_TYPE_STRING:
- return doc.replace(/[\n\r]*$/, "");
- case DOC_TYPE_CURSOR:
- case DOC_TYPE_TRIM:
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- case DOC_TYPE_LINE:
- case DOC_TYPE_BREAK_PARENT:
- break;
- default:
- throw new invalid_doc_error_default(doc);
- }
- return doc;
- }
- function stripTrailingHardline(doc) {
- return stripTrailingHardlineFromDoc(cleanDoc(doc));
- }
- function cleanDocFn(doc) {
- switch (get_doc_type_default(doc)) {
- case DOC_TYPE_FILL:
- if (doc.parts.every((part) => part === "")) {
- return "";
- }
- break;
- case DOC_TYPE_GROUP:
- if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) {
- return "";
- }
- if (doc.contents.type === DOC_TYPE_GROUP && doc.contents.id === doc.id && doc.contents.break === doc.break && doc.contents.expandedStates === doc.expandedStates) {
- return doc.contents;
- }
- break;
- case DOC_TYPE_ALIGN:
- case DOC_TYPE_INDENT:
- case DOC_TYPE_INDENT_IF_BREAK:
- case DOC_TYPE_LINE_SUFFIX:
- if (!doc.contents) {
- return "";
- }
- break;
- case DOC_TYPE_IF_BREAK:
- if (!doc.flatContents && !doc.breakContents) {
- return "";
- }
- break;
- case DOC_TYPE_ARRAY: {
- const parts = [];
- for (const part of doc) {
- if (!part) {
- continue;
- }
- const [currentPart, ...restParts] = Array.isArray(part) ? part : [part];
- if (typeof currentPart === "string" && typeof at_default(
- /* isOptionalObject*/
- false,
- parts,
- -1
- ) === "string") {
- parts[parts.length - 1] += currentPart;
- } else {
- parts.push(currentPart);
- }
- parts.push(...restParts);
- }
- if (parts.length === 0) {
- return "";
- }
- if (parts.length === 1) {
- return parts[0];
- }
- return parts;
- }
- case DOC_TYPE_STRING:
- case DOC_TYPE_CURSOR:
- case DOC_TYPE_TRIM:
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- case DOC_TYPE_LINE:
- case DOC_TYPE_LABEL:
- case DOC_TYPE_BREAK_PARENT:
- break;
- default:
- throw new invalid_doc_error_default(doc);
- }
- return doc;
- }
- function cleanDoc(doc) {
- return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
- }
- function replaceEndOfLine(doc, replacement = literalline) {
- return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" ? join(replacement, currentDoc.split("\n")) : currentDoc);
- }
- function canBreakFn(doc) {
- if (doc.type === DOC_TYPE_LINE) {
- return true;
- }
- }
- function canBreak(doc) {
- return findInDoc(doc, canBreakFn, false);
- }
- // src/document/printer.js
- var MODE_BREAK = Symbol("MODE_BREAK");
- var MODE_FLAT = Symbol("MODE_FLAT");
- var CURSOR_PLACEHOLDER = Symbol("cursor");
- function rootIndent() {
- return {
- value: "",
- length: 0,
- queue: []
- };
- }
- function makeIndent(ind, options) {
- return generateInd(ind, {
- type: "indent"
- }, options);
- }
- function makeAlign(indent2, widthOrDoc, options) {
- if (widthOrDoc === Number.NEGATIVE_INFINITY) {
- return indent2.root || rootIndent();
- }
- if (widthOrDoc < 0) {
- return generateInd(indent2, {
- type: "dedent"
- }, options);
- }
- if (!widthOrDoc) {
- return indent2;
- }
- if (widthOrDoc.type === "root") {
- return {
- ...indent2,
- root: indent2
- };
- }
- const alignType = typeof widthOrDoc === "string" ? "stringAlign" : "numberAlign";
- return generateInd(indent2, {
- type: alignType,
- n: widthOrDoc
- }, options);
- }
- function generateInd(ind, newPart, options) {
- const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : [...ind.queue, newPart];
- let value = "";
- let length = 0;
- let lastTabs = 0;
- let lastSpaces = 0;
- for (const part of queue) {
- switch (part.type) {
- case "indent":
- flush();
- if (options.useTabs) {
- addTabs(1);
- } else {
- addSpaces(options.tabWidth);
- }
- break;
- case "stringAlign":
- flush();
- value += part.n;
- length += part.n.length;
- break;
- case "numberAlign":
- lastTabs += 1;
- lastSpaces += part.n;
- break;
- default:
- throw new Error(`Unexpected type '${part.type}'`);
- }
- }
- flushSpaces();
- return {
- ...ind,
- value,
- length,
- queue
- };
- function addTabs(count) {
- value += " ".repeat(count);
- length += options.tabWidth * count;
- }
- function addSpaces(count) {
- value += " ".repeat(count);
- length += count;
- }
- function flush() {
- if (options.useTabs) {
- flushTabs();
- } else {
- flushSpaces();
- }
- }
- function flushTabs() {
- if (lastTabs > 0) {
- addTabs(lastTabs);
- }
- resetLast();
- }
- function flushSpaces() {
- if (lastSpaces > 0) {
- addSpaces(lastSpaces);
- }
- resetLast();
- }
- function resetLast() {
- lastTabs = 0;
- lastSpaces = 0;
- }
- }
- function trim2(out) {
- let trimCount = 0;
- let cursorCount = 0;
- let outIndex = out.length;
- outer:
- while (outIndex--) {
- const last = out[outIndex];
- if (last === CURSOR_PLACEHOLDER) {
- cursorCount++;
- continue;
- }
- if (false) {
- throw new Error(`Unexpected value in trim: '${typeof last}'`);
- }
- for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
- const char = last[charIndex];
- if (char === " " || char === " ") {
- trimCount++;
- } else {
- out[outIndex] = last.slice(0, charIndex + 1);
- break outer;
- }
- }
- }
- if (trimCount > 0 || cursorCount > 0) {
- out.length = outIndex + 1;
- while (cursorCount-- > 0) {
- out.push(CURSOR_PLACEHOLDER);
- }
- }
- return trimCount;
- }
- function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat) {
- if (width === Number.POSITIVE_INFINITY) {
- return true;
- }
- let restIdx = restCommands.length;
- const cmds = [next];
- const out = [];
- while (width >= 0) {
- if (cmds.length === 0) {
- if (restIdx === 0) {
- return true;
- }
- cmds.push(restCommands[--restIdx]);
- continue;
- }
- const {
- mode,
- doc
- } = cmds.pop();
- switch (get_doc_type_default(doc)) {
- case DOC_TYPE_STRING:
- out.push(doc);
- width -= get_string_width_default(doc);
- break;
- case DOC_TYPE_ARRAY:
- case DOC_TYPE_FILL: {
- const parts = getDocParts(doc);
- for (let i = parts.length - 1; i >= 0; i--) {
- cmds.push({
- mode,
- doc: parts[i]
- });
- }
- break;
- }
- case DOC_TYPE_INDENT:
- case DOC_TYPE_ALIGN:
- case DOC_TYPE_INDENT_IF_BREAK:
- case DOC_TYPE_LABEL:
- cmds.push({
- mode,
- doc: doc.contents
- });
- break;
- case DOC_TYPE_TRIM:
- width += trim2(out);
- break;
- case DOC_TYPE_GROUP: {
- if (mustBeFlat && doc.break) {
- return false;
- }
- const groupMode = doc.break ? MODE_BREAK : mode;
- const contents = doc.expandedStates && groupMode === MODE_BREAK ? at_default(
- /* isOptionalObject*/
- false,
- doc.expandedStates,
- -1
- ) : doc.contents;
- cmds.push({
- mode: groupMode,
- doc: contents
- });
- break;
- }
- case DOC_TYPE_IF_BREAK: {
- const groupMode = doc.groupId ? groupModeMap[doc.groupId] || MODE_FLAT : mode;
- const contents = groupMode === MODE_BREAK ? doc.breakContents : doc.flatContents;
- if (contents) {
- cmds.push({
- mode,
- doc: contents
- });
- }
- break;
- }
- case DOC_TYPE_LINE:
- if (mode === MODE_BREAK || doc.hard) {
- return true;
- }
- if (!doc.soft) {
- out.push(" ");
- width--;
- }
- break;
- case DOC_TYPE_LINE_SUFFIX:
- hasLineSuffix = true;
- break;
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- if (hasLineSuffix) {
- return false;
- }
- break;
- }
- }
- return false;
- }
- function printDocToString(doc, options) {
- const groupModeMap = {};
- const width = options.printWidth;
- const newLine = convertEndOfLineToChars(options.endOfLine);
- let pos = 0;
- const cmds = [{
- ind: rootIndent(),
- mode: MODE_BREAK,
- doc
- }];
- const out = [];
- let shouldRemeasure = false;
- const lineSuffix2 = [];
- let printedCursorCount = 0;
- propagateBreaks(doc);
- while (cmds.length > 0) {
- const {
- ind,
- mode,
- doc: doc2
- } = cmds.pop();
- switch (get_doc_type_default(doc2)) {
- case DOC_TYPE_STRING: {
- const formatted = newLine !== "\n" ? string_replace_all_default(
- /* isOptionalObject*/
- false,
- doc2,
- "\n",
- newLine
- ) : doc2;
- out.push(formatted);
- if (cmds.length > 0) {
- pos += get_string_width_default(formatted);
- }
- break;
- }
- case DOC_TYPE_ARRAY:
- for (let i = doc2.length - 1; i >= 0; i--) {
- cmds.push({
- ind,
- mode,
- doc: doc2[i]
- });
- }
- break;
- case DOC_TYPE_CURSOR:
- if (printedCursorCount >= 2) {
- throw new Error("There are too many 'cursor' in doc.");
- }
- out.push(CURSOR_PLACEHOLDER);
- printedCursorCount++;
- break;
- case DOC_TYPE_INDENT:
- cmds.push({
- ind: makeIndent(ind, options),
- mode,
- doc: doc2.contents
- });
- break;
- case DOC_TYPE_ALIGN:
- cmds.push({
- ind: makeAlign(ind, doc2.n, options),
- mode,
- doc: doc2.contents
- });
- break;
- case DOC_TYPE_TRIM:
- pos -= trim2(out);
- break;
- case DOC_TYPE_GROUP:
- switch (mode) {
- case MODE_FLAT:
- if (!shouldRemeasure) {
- cmds.push({
- ind,
- mode: doc2.break ? MODE_BREAK : MODE_FLAT,
- doc: doc2.contents
- });
- break;
- }
- case MODE_BREAK: {
- shouldRemeasure = false;
- const next = {
- ind,
- mode: MODE_FLAT,
- doc: doc2.contents
- };
- const rem = width - pos;
- const hasLineSuffix = lineSuffix2.length > 0;
- if (!doc2.break && fits(next, cmds, rem, hasLineSuffix, groupModeMap)) {
- cmds.push(next);
- } else {
- if (doc2.expandedStates) {
- const mostExpanded = at_default(
- /* isOptionalObject*/
- false,
- doc2.expandedStates,
- -1
- );
- if (doc2.break) {
- cmds.push({
- ind,
- mode: MODE_BREAK,
- doc: mostExpanded
- });
- break;
- } else {
- for (let i = 1; i < doc2.expandedStates.length + 1; i++) {
- if (i >= doc2.expandedStates.length) {
- cmds.push({
- ind,
- mode: MODE_BREAK,
- doc: mostExpanded
- });
- break;
- } else {
- const state = doc2.expandedStates[i];
- const cmd = {
- ind,
- mode: MODE_FLAT,
- doc: state
- };
- if (fits(cmd, cmds, rem, hasLineSuffix, groupModeMap)) {
- cmds.push(cmd);
- break;
- }
- }
- }
- }
- } else {
- cmds.push({
- ind,
- mode: MODE_BREAK,
- doc: doc2.contents
- });
- }
- }
- break;
- }
- }
- if (doc2.id) {
- groupModeMap[doc2.id] = at_default(
- /* isOptionalObject*/
- false,
- cmds,
- -1
- ).mode;
- }
- break;
- case DOC_TYPE_FILL: {
- const rem = width - pos;
- const {
- parts
- } = doc2;
- if (parts.length === 0) {
- break;
- }
- const [content, whitespace] = parts;
- const contentFlatCmd = {
- ind,
- mode: MODE_FLAT,
- doc: content
- };
- const contentBreakCmd = {
- ind,
- mode: MODE_BREAK,
- doc: content
- };
- const contentFits = fits(contentFlatCmd, [], rem, lineSuffix2.length > 0, groupModeMap, true);
- if (parts.length === 1) {
- if (contentFits) {
- cmds.push(contentFlatCmd);
- } else {
- cmds.push(contentBreakCmd);
- }
- break;
- }
- const whitespaceFlatCmd = {
- ind,
- mode: MODE_FLAT,
- doc: whitespace
- };
- const whitespaceBreakCmd = {
- ind,
- mode: MODE_BREAK,
- doc: whitespace
- };
- if (parts.length === 2) {
- if (contentFits) {
- cmds.push(whitespaceFlatCmd, contentFlatCmd);
- } else {
- cmds.push(whitespaceBreakCmd, contentBreakCmd);
- }
- break;
- }
- parts.splice(0, 2);
- const remainingCmd = {
- ind,
- mode,
- doc: fill(parts)
- };
- const secondContent = parts[0];
- const firstAndSecondContentFlatCmd = {
- ind,
- mode: MODE_FLAT,
- doc: [content, whitespace, secondContent]
- };
- const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, lineSuffix2.length > 0, groupModeMap, true);
- if (firstAndSecondContentFits) {
- cmds.push(remainingCmd, whitespaceFlatCmd, contentFlatCmd);
- } else if (contentFits) {
- cmds.push(remainingCmd, whitespaceBreakCmd, contentFlatCmd);
- } else {
- cmds.push(remainingCmd, whitespaceBreakCmd, contentBreakCmd);
- }
- break;
- }
- case DOC_TYPE_IF_BREAK:
- case DOC_TYPE_INDENT_IF_BREAK: {
- const groupMode = doc2.groupId ? groupModeMap[doc2.groupId] : mode;
- if (groupMode === MODE_BREAK) {
- const breakContents = doc2.type === DOC_TYPE_IF_BREAK ? doc2.breakContents : doc2.negate ? doc2.contents : indent(doc2.contents);
- if (breakContents) {
- cmds.push({
- ind,
- mode,
- doc: breakContents
- });
- }
- }
- if (groupMode === MODE_FLAT) {
- const flatContents = doc2.type === DOC_TYPE_IF_BREAK ? doc2.flatContents : doc2.negate ? indent(doc2.contents) : doc2.contents;
- if (flatContents) {
- cmds.push({
- ind,
- mode,
- doc: flatContents
- });
- }
- }
- break;
- }
- case DOC_TYPE_LINE_SUFFIX:
- lineSuffix2.push({
- ind,
- mode,
- doc: doc2.contents
- });
- break;
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
- if (lineSuffix2.length > 0) {
- cmds.push({
- ind,
- mode,
- doc: hardlineWithoutBreakParent
- });
- }
- break;
- case DOC_TYPE_LINE:
- switch (mode) {
- case MODE_FLAT:
- if (!doc2.hard) {
- if (!doc2.soft) {
- out.push(" ");
- pos += 1;
- }
- break;
- } else {
- shouldRemeasure = true;
- }
- case MODE_BREAK:
- if (lineSuffix2.length > 0) {
- cmds.push({
- ind,
- mode,
- doc: doc2
- }, ...lineSuffix2.reverse());
- lineSuffix2.length = 0;
- break;
- }
- if (doc2.literal) {
- if (ind.root) {
- out.push(newLine, ind.root.value);
- pos = ind.root.length;
- } else {
- out.push(newLine);
- pos = 0;
- }
- } else {
- pos -= trim2(out);
- out.push(newLine + ind.value);
- pos = ind.length;
- }
- break;
- }
- break;
- case DOC_TYPE_LABEL:
- cmds.push({
- ind,
- mode,
- doc: doc2.contents
- });
- break;
- case DOC_TYPE_BREAK_PARENT:
- break;
- default:
- throw new invalid_doc_error_default(doc2);
- }
- if (cmds.length === 0 && lineSuffix2.length > 0) {
- cmds.push(...lineSuffix2.reverse());
- lineSuffix2.length = 0;
- }
- }
- const cursorPlaceholderIndex = out.indexOf(CURSOR_PLACEHOLDER);
- if (cursorPlaceholderIndex !== -1) {
- const otherCursorPlaceholderIndex = out.indexOf(CURSOR_PLACEHOLDER, cursorPlaceholderIndex + 1);
- const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
- const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
- const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
- return {
- formatted: beforeCursor + aroundCursor + afterCursor,
- cursorNodeStart: beforeCursor.length,
- cursorNodeText: aroundCursor
- };
- }
- return {
- formatted: out.join("")
- };
- }
- // src/document/public.js
- var builders = {
- join,
- line,
- softline,
- hardline,
- literalline,
- group,
- conditionalGroup,
- fill,
- lineSuffix,
- lineSuffixBoundary,
- cursor,
- breakParent,
- ifBreak,
- trim,
- indent,
- indentIfBreak,
- align,
- addAlignmentToDoc,
- markAsRoot,
- dedentToRoot,
- dedent,
- hardlineWithoutBreakParent,
- literallineWithoutBreakParent,
- label,
- // TODO: Remove this in v4
- concat: (parts) => parts
- };
- var printer = { printDocToString };
- var utils = {
- willBreak,
- traverseDoc: traverse_doc_default,
- findInDoc,
- mapDoc,
- removeLines,
- stripTrailingHardline,
- replaceEndOfLine,
- canBreak
- };
- return __toCommonJS(public_exports);
- });
|