Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doc.js 149KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.doc = factory());
  5. }(this, (function () { 'use strict';
  6. /**
  7. * @param {Doc[]} parts
  8. * @returns Doc
  9. */
  10. function concat(parts) {
  11. // access the internals of a document directly.
  12. // if(parts.length === 1) {
  13. // // If it's a single document, no need to concat it.
  14. // return parts[0];
  15. // }
  16. return {
  17. type: "concat",
  18. parts
  19. };
  20. }
  21. /**
  22. * @param {Doc} contents
  23. * @returns Doc
  24. */
  25. function indent$1(contents) {
  26. return {
  27. type: "indent",
  28. contents
  29. };
  30. }
  31. /**
  32. * @param {number | string} widthOrString
  33. * @param {Doc} contents
  34. * @returns Doc
  35. */
  36. function align(widthOrString, contents) {
  37. return {
  38. type: "align",
  39. contents,
  40. n: widthOrString
  41. };
  42. }
  43. /**
  44. * @param {Doc} contents
  45. * @param {object} [opts] - TBD ???
  46. * @returns Doc
  47. */
  48. function group(contents, opts = {}) {
  49. return {
  50. type: "group",
  51. id: opts.id,
  52. contents,
  53. break: Boolean(opts.shouldBreak),
  54. expandedStates: opts.expandedStates
  55. };
  56. }
  57. /**
  58. * @param {Doc} contents
  59. * @returns Doc
  60. */
  61. function dedentToRoot(contents) {
  62. return align(Number.NEGATIVE_INFINITY, contents);
  63. }
  64. /**
  65. * @param {Doc} contents
  66. * @returns Doc
  67. */
  68. function markAsRoot(contents) {
  69. // @ts-expect-error - TBD ???:
  70. return align({
  71. type: "root"
  72. }, contents);
  73. }
  74. /**
  75. * @param {Doc} contents
  76. * @returns Doc
  77. */
  78. function dedent(contents) {
  79. return align(-1, contents);
  80. }
  81. /**
  82. * @param {Doc[]} states
  83. * @param {object} [opts] - TBD ???
  84. * @returns Doc
  85. */
  86. function conditionalGroup(states, opts) {
  87. return group(states[0], Object.assign(Object.assign({}, opts), {}, {
  88. expandedStates: states
  89. }));
  90. }
  91. /**
  92. * @param {Doc[]} parts
  93. * @returns Doc
  94. */
  95. function fill$1(parts) {
  96. return {
  97. type: "fill",
  98. parts
  99. };
  100. }
  101. /**
  102. * @param {Doc} [breakContents]
  103. * @param {Doc} [flatContents]
  104. * @param {object} [opts] - TBD ???
  105. * @returns Doc
  106. */
  107. function ifBreak(breakContents, flatContents, opts = {}) {
  108. return {
  109. type: "if-break",
  110. breakContents,
  111. flatContents,
  112. groupId: opts.groupId
  113. };
  114. }
  115. /**
  116. * Optimized version of `ifBreak(indent(doc), doc, { groupId: ... })`
  117. * @param {Doc} contents
  118. * @param {{ groupId: symbol, negate?: boolean }} opts
  119. * @returns Doc
  120. */
  121. function indentIfBreak(contents, opts) {
  122. return {
  123. type: "indent-if-break",
  124. contents,
  125. groupId: opts.groupId,
  126. negate: opts.negate
  127. };
  128. }
  129. /**
  130. * @param {Doc} contents
  131. * @returns Doc
  132. */
  133. function lineSuffix(contents) {
  134. return {
  135. type: "line-suffix",
  136. contents
  137. };
  138. }
  139. const lineSuffixBoundary = {
  140. type: "line-suffix-boundary"
  141. };
  142. const breakParent = {
  143. type: "break-parent"
  144. };
  145. const trim$1 = {
  146. type: "trim"
  147. };
  148. const hardlineWithoutBreakParent = {
  149. type: "line",
  150. hard: true
  151. };
  152. const literallineWithoutBreakParent = {
  153. type: "line",
  154. hard: true,
  155. literal: true
  156. };
  157. const line = {
  158. type: "line"
  159. };
  160. const softline = {
  161. type: "line",
  162. soft: true
  163. }; // eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
  164. const hardline = concat([hardlineWithoutBreakParent, breakParent]); // eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
  165. const literalline$1 = concat([literallineWithoutBreakParent, breakParent]);
  166. const cursor$1 = {
  167. type: "cursor",
  168. placeholder: Symbol("cursor")
  169. };
  170. /**
  171. * @param {Doc} sep
  172. * @param {Doc[]} arr
  173. * @returns Doc
  174. */
  175. function join$1(sep, arr) {
  176. const res = [];
  177. for (let i = 0; i < arr.length; i++) {
  178. if (i !== 0) {
  179. res.push(sep);
  180. }
  181. res.push(arr[i]);
  182. } // eslint-disable-next-line prettier-internal-rules/no-doc-builder-concat
  183. return concat(res);
  184. }
  185. /**
  186. * @param {Doc} doc
  187. * @param {number} size
  188. * @param {number} tabWidth
  189. */
  190. function addAlignmentToDoc(doc, size, tabWidth) {
  191. let aligned = doc;
  192. if (size > 0) {
  193. // Use indent to add tabs for all the levels of tabs we need
  194. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  195. aligned = indent$1(aligned);
  196. } // Use align for all the spaces that are needed
  197. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  198. // indentation, so we use -Infinity to reset the indentation to 0
  199. aligned = align(Number.NEGATIVE_INFINITY, aligned);
  200. }
  201. return aligned;
  202. }
  203. function label(label, contents) {
  204. return {
  205. type: "label",
  206. label,
  207. contents
  208. };
  209. }
  210. var docBuilders = {
  211. concat,
  212. join: join$1,
  213. line,
  214. softline,
  215. hardline,
  216. literalline: literalline$1,
  217. group,
  218. conditionalGroup,
  219. fill: fill$1,
  220. lineSuffix,
  221. lineSuffixBoundary,
  222. cursor: cursor$1,
  223. breakParent,
  224. ifBreak,
  225. trim: trim$1,
  226. indent: indent$1,
  227. indentIfBreak,
  228. align,
  229. addAlignmentToDoc,
  230. markAsRoot,
  231. dedentToRoot,
  232. dedent,
  233. hardlineWithoutBreakParent,
  234. literallineWithoutBreakParent,
  235. label
  236. };
  237. var ansiRegex = ({
  238. onlyFirst = false
  239. } = {}) => {
  240. const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  241. return new RegExp(pattern, onlyFirst ? undefined : 'g');
  242. };
  243. var stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  244. /* eslint-disable yoda */
  245. const isFullwidthCodePoint = codePoint => {
  246. if (Number.isNaN(codePoint)) {
  247. return false;
  248. } // Code points are derived from:
  249. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  250. if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
  251. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  252. codePoint === 0x232A || 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || 0x3250 <= codePoint && codePoint <= 0x4DBF || 0x4E00 <= codePoint && codePoint <= 0xA4C6 || 0xA960 <= codePoint && codePoint <= 0xA97C || 0xAC00 <= codePoint && codePoint <= 0xD7A3 || 0xF900 <= codePoint && codePoint <= 0xFAFF || 0xFE10 <= codePoint && codePoint <= 0xFE19 || 0xFE30 <= codePoint && codePoint <= 0xFE6B || 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || 0x1B000 <= codePoint && codePoint <= 0x1B001 || 0x1F200 <= codePoint && codePoint <= 0x1F251 || 0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
  253. return true;
  254. }
  255. return false;
  256. };
  257. var isFullwidthCodePoint_1 = isFullwidthCodePoint;
  258. var _default$1 = isFullwidthCodePoint;
  259. isFullwidthCodePoint_1.default = _default$1;
  260. var emojiRegex = function () {
  261. // https://mths.be/emoji
  262. return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
  263. };
  264. const stringWidth = string => {
  265. if (typeof string !== 'string' || string.length === 0) {
  266. return 0;
  267. }
  268. string = stripAnsi(string);
  269. if (string.length === 0) {
  270. return 0;
  271. }
  272. string = string.replace(emojiRegex(), ' ');
  273. let width = 0;
  274. for (let i = 0; i < string.length; i++) {
  275. const code = string.codePointAt(i); // Ignore control characters
  276. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  277. continue;
  278. } // Ignore combining characters
  279. if (code >= 0x300 && code <= 0x36F) {
  280. continue;
  281. } // Surrogates
  282. if (code > 0xFFFF) {
  283. i++;
  284. }
  285. width += isFullwidthCodePoint_1(code) ? 2 : 1;
  286. }
  287. return width;
  288. };
  289. var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
  290. var _default = stringWidth;
  291. stringWidth_1.default = _default;
  292. var escapeStringRegexp = string => {
  293. if (typeof string !== 'string') {
  294. throw new TypeError('Expected a string');
  295. } // Escape characters with special meaning either inside or outside character sets.
  296. // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
  297. return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
  298. };
  299. const getLast$1 = arr => arr[arr.length - 1];
  300. var getLast_1 = getLast$1;
  301. function _objectWithoutPropertiesLoose(source, excluded) {
  302. if (source == null) return {};
  303. var target = {};
  304. var sourceKeys = Object.keys(source);
  305. var key, i;
  306. for (i = 0; i < sourceKeys.length; i++) {
  307. key = sourceKeys[i];
  308. if (excluded.indexOf(key) >= 0) continue;
  309. target[key] = source[key];
  310. }
  311. return target;
  312. }
  313. function _objectWithoutProperties(source, excluded) {
  314. if (source == null) return {};
  315. var target = _objectWithoutPropertiesLoose(source, excluded);
  316. var key, i;
  317. if (Object.getOwnPropertySymbols) {
  318. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  319. for (i = 0; i < sourceSymbolKeys.length; i++) {
  320. key = sourceSymbolKeys[i];
  321. if (excluded.indexOf(key) >= 0) continue;
  322. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  323. target[key] = source[key];
  324. }
  325. }
  326. return target;
  327. }
  328. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  329. function createCommonjsModule(fn) {
  330. var module = { exports: {} };
  331. return fn(module, module.exports), module.exports;
  332. }
  333. var check = function (it) {
  334. return it && it.Math == Math && it;
  335. };
  336. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  337. var global$2 =
  338. // eslint-disable-next-line es/no-global-this -- safe
  339. check(typeof globalThis == 'object' && globalThis) ||
  340. check(typeof window == 'object' && window) ||
  341. // eslint-disable-next-line no-restricted-globals -- safe
  342. check(typeof self == 'object' && self) ||
  343. check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
  344. // eslint-disable-next-line no-new-func -- fallback
  345. (function () { return this; })() || Function('return this')();
  346. var fails = function (exec) {
  347. try {
  348. return !!exec();
  349. } catch (error) {
  350. return true;
  351. }
  352. };
  353. // Detect IE8's incomplete defineProperty implementation
  354. var descriptors = !fails(function () {
  355. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  356. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  357. });
  358. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  359. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  360. var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
  361. // Nashorn ~ JDK8 bug
  362. var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  363. // `Object.prototype.propertyIsEnumerable` method implementation
  364. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  365. var f$4 = NASHORN_BUG ? function propertyIsEnumerable(V) {
  366. var descriptor = getOwnPropertyDescriptor$1(this, V);
  367. return !!descriptor && descriptor.enumerable;
  368. } : $propertyIsEnumerable;
  369. var objectPropertyIsEnumerable = {
  370. f: f$4
  371. };
  372. var createPropertyDescriptor = function (bitmap, value) {
  373. return {
  374. enumerable: !(bitmap & 1),
  375. configurable: !(bitmap & 2),
  376. writable: !(bitmap & 4),
  377. value: value
  378. };
  379. };
  380. var toString$1 = {}.toString;
  381. var classofRaw = function (it) {
  382. return toString$1.call(it).slice(8, -1);
  383. };
  384. var split = ''.split;
  385. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  386. var indexedObject = fails(function () {
  387. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  388. // eslint-disable-next-line no-prototype-builtins -- safe
  389. return !Object('z').propertyIsEnumerable(0);
  390. }) ? function (it) {
  391. return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
  392. } : Object;
  393. // `RequireObjectCoercible` abstract operation
  394. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  395. var requireObjectCoercible = function (it) {
  396. if (it == undefined) throw TypeError("Can't call method on " + it);
  397. return it;
  398. };
  399. // toObject with fallback for non-array-like ES3 strings
  400. var toIndexedObject = function (it) {
  401. return indexedObject(requireObjectCoercible(it));
  402. };
  403. var isObject = function (it) {
  404. return typeof it === 'object' ? it !== null : typeof it === 'function';
  405. };
  406. var aFunction$1 = function (variable) {
  407. return typeof variable == 'function' ? variable : undefined;
  408. };
  409. var getBuiltIn = function (namespace, method) {
  410. return arguments.length < 2 ? aFunction$1(global$2[namespace]) : global$2[namespace] && global$2[namespace][method];
  411. };
  412. var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
  413. var process = global$2.process;
  414. var Deno = global$2.Deno;
  415. var versions$1 = process && process.versions || Deno && Deno.version;
  416. var v8 = versions$1 && versions$1.v8;
  417. var match, version$1;
  418. if (v8) {
  419. match = v8.split('.');
  420. version$1 = match[0] < 4 ? 1 : match[0] + match[1];
  421. } else if (engineUserAgent) {
  422. match = engineUserAgent.match(/Edge\/(\d+)/);
  423. if (!match || match[1] >= 74) {
  424. match = engineUserAgent.match(/Chrome\/(\d+)/);
  425. if (match) version$1 = match[1];
  426. }
  427. }
  428. var engineV8Version = version$1 && +version$1;
  429. /* eslint-disable es/no-symbol -- required for testing */
  430. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  431. var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
  432. var symbol = Symbol();
  433. // Chrome 38 Symbol has incorrect toString conversion
  434. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  435. return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
  436. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  437. !Symbol.sham && engineV8Version && engineV8Version < 41;
  438. });
  439. /* eslint-disable es/no-symbol -- required for testing */
  440. var useSymbolAsUid = nativeSymbol
  441. && !Symbol.sham
  442. && typeof Symbol.iterator == 'symbol';
  443. var isSymbol = useSymbolAsUid ? function (it) {
  444. return typeof it == 'symbol';
  445. } : function (it) {
  446. var $Symbol = getBuiltIn('Symbol');
  447. return typeof $Symbol == 'function' && Object(it) instanceof $Symbol;
  448. };
  449. // `OrdinaryToPrimitive` abstract operation
  450. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  451. var ordinaryToPrimitive = function (input, pref) {
  452. var fn, val;
  453. if (pref === 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  454. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  455. if (pref !== 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  456. throw TypeError("Can't convert object to primitive value");
  457. };
  458. var setGlobal = function (key, value) {
  459. try {
  460. // eslint-disable-next-line es/no-object-defineproperty -- safe
  461. Object.defineProperty(global$2, key, { value: value, configurable: true, writable: true });
  462. } catch (error) {
  463. global$2[key] = value;
  464. } return value;
  465. };
  466. var SHARED = '__core-js_shared__';
  467. var store$1 = global$2[SHARED] || setGlobal(SHARED, {});
  468. var sharedStore = store$1;
  469. var shared = createCommonjsModule(function (module) {
  470. (module.exports = function (key, value) {
  471. return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
  472. })('versions', []).push({
  473. version: '3.17.3',
  474. mode: 'global',
  475. copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
  476. });
  477. });
  478. // `ToObject` abstract operation
  479. // https://tc39.es/ecma262/#sec-toobject
  480. var toObject = function (argument) {
  481. return Object(requireObjectCoercible(argument));
  482. };
  483. var hasOwnProperty = {}.hasOwnProperty;
  484. var has$1 = Object.hasOwn || function hasOwn(it, key) {
  485. return hasOwnProperty.call(toObject(it), key);
  486. };
  487. var id = 0;
  488. var postfix = Math.random();
  489. var uid = function (key) {
  490. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  491. };
  492. var WellKnownSymbolsStore = shared('wks');
  493. var Symbol$1 = global$2.Symbol;
  494. var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
  495. var wellKnownSymbol = function (name) {
  496. if (!has$1(WellKnownSymbolsStore, name) || !(nativeSymbol || typeof WellKnownSymbolsStore[name] == 'string')) {
  497. if (nativeSymbol && has$1(Symbol$1, name)) {
  498. WellKnownSymbolsStore[name] = Symbol$1[name];
  499. } else {
  500. WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  501. }
  502. } return WellKnownSymbolsStore[name];
  503. };
  504. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  505. // `ToPrimitive` abstract operation
  506. // https://tc39.es/ecma262/#sec-toprimitive
  507. var toPrimitive = function (input, pref) {
  508. if (!isObject(input) || isSymbol(input)) return input;
  509. var exoticToPrim = input[TO_PRIMITIVE];
  510. var result;
  511. if (exoticToPrim !== undefined) {
  512. if (pref === undefined) pref = 'default';
  513. result = exoticToPrim.call(input, pref);
  514. if (!isObject(result) || isSymbol(result)) return result;
  515. throw TypeError("Can't convert object to primitive value");
  516. }
  517. if (pref === undefined) pref = 'number';
  518. return ordinaryToPrimitive(input, pref);
  519. };
  520. // `ToPropertyKey` abstract operation
  521. // https://tc39.es/ecma262/#sec-topropertykey
  522. var toPropertyKey = function (argument) {
  523. var key = toPrimitive(argument, 'string');
  524. return isSymbol(key) ? key : String(key);
  525. };
  526. var document$1 = global$2.document;
  527. // typeof document.createElement is 'object' in old IE
  528. var EXISTS = isObject(document$1) && isObject(document$1.createElement);
  529. var documentCreateElement = function (it) {
  530. return EXISTS ? document$1.createElement(it) : {};
  531. };
  532. // Thank's IE8 for his funny defineProperty
  533. var ie8DomDefine = !descriptors && !fails(function () {
  534. // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
  535. return Object.defineProperty(documentCreateElement('div'), 'a', {
  536. get: function () { return 7; }
  537. }).a != 7;
  538. });
  539. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  540. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  541. // `Object.getOwnPropertyDescriptor` method
  542. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  543. var f$3 = descriptors ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  544. O = toIndexedObject(O);
  545. P = toPropertyKey(P);
  546. if (ie8DomDefine) try {
  547. return $getOwnPropertyDescriptor(O, P);
  548. } catch (error) { /* empty */ }
  549. if (has$1(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
  550. };
  551. var objectGetOwnPropertyDescriptor = {
  552. f: f$3
  553. };
  554. var anObject = function (it) {
  555. if (!isObject(it)) {
  556. throw TypeError(String(it) + ' is not an object');
  557. } return it;
  558. };
  559. // eslint-disable-next-line es/no-object-defineproperty -- safe
  560. var $defineProperty = Object.defineProperty;
  561. // `Object.defineProperty` method
  562. // https://tc39.es/ecma262/#sec-object.defineproperty
  563. var f$2 = descriptors ? $defineProperty : function defineProperty(O, P, Attributes) {
  564. anObject(O);
  565. P = toPropertyKey(P);
  566. anObject(Attributes);
  567. if (ie8DomDefine) try {
  568. return $defineProperty(O, P, Attributes);
  569. } catch (error) { /* empty */ }
  570. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  571. if ('value' in Attributes) O[P] = Attributes.value;
  572. return O;
  573. };
  574. var objectDefineProperty = {
  575. f: f$2
  576. };
  577. var createNonEnumerableProperty = descriptors ? function (object, key, value) {
  578. return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
  579. } : function (object, key, value) {
  580. object[key] = value;
  581. return object;
  582. };
  583. var functionToString = Function.toString;
  584. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  585. if (typeof sharedStore.inspectSource != 'function') {
  586. sharedStore.inspectSource = function (it) {
  587. return functionToString.call(it);
  588. };
  589. }
  590. var inspectSource = sharedStore.inspectSource;
  591. var WeakMap$2 = global$2.WeakMap;
  592. var nativeWeakMap = typeof WeakMap$2 === 'function' && /native code/.test(inspectSource(WeakMap$2));
  593. var keys = shared('keys');
  594. var sharedKey = function (key) {
  595. return keys[key] || (keys[key] = uid(key));
  596. };
  597. var hiddenKeys$1 = {};
  598. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  599. var WeakMap$1 = global$2.WeakMap;
  600. var set, get, has;
  601. var enforce = function (it) {
  602. return has(it) ? get(it) : set(it, {});
  603. };
  604. var getterFor = function (TYPE) {
  605. return function (it) {
  606. var state;
  607. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  608. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  609. } return state;
  610. };
  611. };
  612. if (nativeWeakMap || sharedStore.state) {
  613. var store = sharedStore.state || (sharedStore.state = new WeakMap$1());
  614. var wmget = store.get;
  615. var wmhas = store.has;
  616. var wmset = store.set;
  617. set = function (it, metadata) {
  618. if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  619. metadata.facade = it;
  620. wmset.call(store, it, metadata);
  621. return metadata;
  622. };
  623. get = function (it) {
  624. return wmget.call(store, it) || {};
  625. };
  626. has = function (it) {
  627. return wmhas.call(store, it);
  628. };
  629. } else {
  630. var STATE = sharedKey('state');
  631. hiddenKeys$1[STATE] = true;
  632. set = function (it, metadata) {
  633. if (has$1(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  634. metadata.facade = it;
  635. createNonEnumerableProperty(it, STATE, metadata);
  636. return metadata;
  637. };
  638. get = function (it) {
  639. return has$1(it, STATE) ? it[STATE] : {};
  640. };
  641. has = function (it) {
  642. return has$1(it, STATE);
  643. };
  644. }
  645. var internalState = {
  646. set: set,
  647. get: get,
  648. has: has,
  649. enforce: enforce,
  650. getterFor: getterFor
  651. };
  652. var redefine = createCommonjsModule(function (module) {
  653. var getInternalState = internalState.get;
  654. var enforceInternalState = internalState.enforce;
  655. var TEMPLATE = String(String).split('String');
  656. (module.exports = function (O, key, value, options) {
  657. var unsafe = options ? !!options.unsafe : false;
  658. var simple = options ? !!options.enumerable : false;
  659. var noTargetGet = options ? !!options.noTargetGet : false;
  660. var state;
  661. if (typeof value == 'function') {
  662. if (typeof key == 'string' && !has$1(value, 'name')) {
  663. createNonEnumerableProperty(value, 'name', key);
  664. }
  665. state = enforceInternalState(value);
  666. if (!state.source) {
  667. state.source = TEMPLATE.join(typeof key == 'string' ? key : '');
  668. }
  669. }
  670. if (O === global$2) {
  671. if (simple) O[key] = value;
  672. else setGlobal(key, value);
  673. return;
  674. } else if (!unsafe) {
  675. delete O[key];
  676. } else if (!noTargetGet && O[key]) {
  677. simple = true;
  678. }
  679. if (simple) O[key] = value;
  680. else createNonEnumerableProperty(O, key, value);
  681. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  682. })(Function.prototype, 'toString', function toString() {
  683. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  684. });
  685. });
  686. var ceil = Math.ceil;
  687. var floor$1 = Math.floor;
  688. // `ToInteger` abstract operation
  689. // https://tc39.es/ecma262/#sec-tointeger
  690. var toInteger = function (argument) {
  691. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor$1 : ceil)(argument);
  692. };
  693. var min$1 = Math.min;
  694. // `ToLength` abstract operation
  695. // https://tc39.es/ecma262/#sec-tolength
  696. var toLength = function (argument) {
  697. return argument > 0 ? min$1(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  698. };
  699. var max = Math.max;
  700. var min = Math.min;
  701. // Helper for a popular repeating case of the spec:
  702. // Let integer be ? ToInteger(index).
  703. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  704. var toAbsoluteIndex = function (index, length) {
  705. var integer = toInteger(index);
  706. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  707. };
  708. // `Array.prototype.{ indexOf, includes }` methods implementation
  709. var createMethod = function (IS_INCLUDES) {
  710. return function ($this, el, fromIndex) {
  711. var O = toIndexedObject($this);
  712. var length = toLength(O.length);
  713. var index = toAbsoluteIndex(fromIndex, length);
  714. var value;
  715. // Array#includes uses SameValueZero equality algorithm
  716. // eslint-disable-next-line no-self-compare -- NaN check
  717. if (IS_INCLUDES && el != el) while (length > index) {
  718. value = O[index++];
  719. // eslint-disable-next-line no-self-compare -- NaN check
  720. if (value != value) return true;
  721. // Array#indexOf ignores holes, Array#includes - not
  722. } else for (;length > index; index++) {
  723. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  724. } return !IS_INCLUDES && -1;
  725. };
  726. };
  727. var arrayIncludes = {
  728. // `Array.prototype.includes` method
  729. // https://tc39.es/ecma262/#sec-array.prototype.includes
  730. includes: createMethod(true),
  731. // `Array.prototype.indexOf` method
  732. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  733. indexOf: createMethod(false)
  734. };
  735. var indexOf = arrayIncludes.indexOf;
  736. var objectKeysInternal = function (object, names) {
  737. var O = toIndexedObject(object);
  738. var i = 0;
  739. var result = [];
  740. var key;
  741. for (key in O) !has$1(hiddenKeys$1, key) && has$1(O, key) && result.push(key);
  742. // Don't enum bug & hidden keys
  743. while (names.length > i) if (has$1(O, key = names[i++])) {
  744. ~indexOf(result, key) || result.push(key);
  745. }
  746. return result;
  747. };
  748. // IE8- don't enum bug keys
  749. var enumBugKeys = [
  750. 'constructor',
  751. 'hasOwnProperty',
  752. 'isPrototypeOf',
  753. 'propertyIsEnumerable',
  754. 'toLocaleString',
  755. 'toString',
  756. 'valueOf'
  757. ];
  758. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  759. // `Object.getOwnPropertyNames` method
  760. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  761. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  762. var f$1 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  763. return objectKeysInternal(O, hiddenKeys);
  764. };
  765. var objectGetOwnPropertyNames = {
  766. f: f$1
  767. };
  768. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  769. var f = Object.getOwnPropertySymbols;
  770. var objectGetOwnPropertySymbols = {
  771. f: f
  772. };
  773. // all object keys, includes non-enumerable and symbols
  774. var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  775. var keys = objectGetOwnPropertyNames.f(anObject(it));
  776. var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
  777. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  778. };
  779. var copyConstructorProperties = function (target, source) {
  780. var keys = ownKeys(source);
  781. var defineProperty = objectDefineProperty.f;
  782. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  783. for (var i = 0; i < keys.length; i++) {
  784. var key = keys[i];
  785. if (!has$1(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  786. }
  787. };
  788. var replacement = /#|\.prototype\./;
  789. var isForced = function (feature, detection) {
  790. var value = data[normalize(feature)];
  791. return value == POLYFILL ? true
  792. : value == NATIVE ? false
  793. : typeof detection == 'function' ? fails(detection)
  794. : !!detection;
  795. };
  796. var normalize = isForced.normalize = function (string) {
  797. return String(string).replace(replacement, '.').toLowerCase();
  798. };
  799. var data = isForced.data = {};
  800. var NATIVE = isForced.NATIVE = 'N';
  801. var POLYFILL = isForced.POLYFILL = 'P';
  802. var isForced_1 = isForced;
  803. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  804. /*
  805. options.target - name of the target object
  806. options.global - target is the global object
  807. options.stat - export as static methods of target
  808. options.proto - export as prototype methods of target
  809. options.real - real prototype method for the `pure` version
  810. options.forced - export even if the native feature is available
  811. options.bind - bind methods to the target, required for the `pure` version
  812. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  813. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  814. options.sham - add a flag to not completely full polyfills
  815. options.enumerable - export as enumerable property
  816. options.noTargetGet - prevent calling a getter on target
  817. */
  818. var _export = function (options, source) {
  819. var TARGET = options.target;
  820. var GLOBAL = options.global;
  821. var STATIC = options.stat;
  822. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  823. if (GLOBAL) {
  824. target = global$2;
  825. } else if (STATIC) {
  826. target = global$2[TARGET] || setGlobal(TARGET, {});
  827. } else {
  828. target = (global$2[TARGET] || {}).prototype;
  829. }
  830. if (target) for (key in source) {
  831. sourceProperty = source[key];
  832. if (options.noTargetGet) {
  833. descriptor = getOwnPropertyDescriptor(target, key);
  834. targetProperty = descriptor && descriptor.value;
  835. } else targetProperty = target[key];
  836. FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  837. // contained in target
  838. if (!FORCED && targetProperty !== undefined) {
  839. if (typeof sourceProperty === typeof targetProperty) continue;
  840. copyConstructorProperties(sourceProperty, targetProperty);
  841. }
  842. // add a flag to not completely full polyfills
  843. if (options.sham || (targetProperty && targetProperty.sham)) {
  844. createNonEnumerableProperty(sourceProperty, 'sham', true);
  845. }
  846. // extend global
  847. redefine(target, key, sourceProperty, options);
  848. }
  849. };
  850. // `IsArray` abstract operation
  851. // https://tc39.es/ecma262/#sec-isarray
  852. // eslint-disable-next-line es/no-array-isarray -- safe
  853. var isArray = Array.isArray || function isArray(arg) {
  854. return classofRaw(arg) == 'Array';
  855. };
  856. var aFunction = function (it) {
  857. if (typeof it != 'function') {
  858. throw TypeError(String(it) + ' is not a function');
  859. } return it;
  860. };
  861. // optional / simple context binding
  862. var functionBindContext = function (fn, that, length) {
  863. aFunction(fn);
  864. if (that === undefined) return fn;
  865. switch (length) {
  866. case 0: return function () {
  867. return fn.call(that);
  868. };
  869. case 1: return function (a) {
  870. return fn.call(that, a);
  871. };
  872. case 2: return function (a, b) {
  873. return fn.call(that, a, b);
  874. };
  875. case 3: return function (a, b, c) {
  876. return fn.call(that, a, b, c);
  877. };
  878. }
  879. return function (/* ...args */) {
  880. return fn.apply(that, arguments);
  881. };
  882. };
  883. // `FlattenIntoArray` abstract operation
  884. // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
  885. var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
  886. var targetIndex = start;
  887. var sourceIndex = 0;
  888. var mapFn = mapper ? functionBindContext(mapper, thisArg, 3) : false;
  889. var element;
  890. while (sourceIndex < sourceLen) {
  891. if (sourceIndex in source) {
  892. element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
  893. if (depth > 0 && isArray(element)) {
  894. targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
  895. } else {
  896. if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
  897. target[targetIndex] = element;
  898. }
  899. targetIndex++;
  900. }
  901. sourceIndex++;
  902. }
  903. return targetIndex;
  904. };
  905. var flattenIntoArray_1 = flattenIntoArray;
  906. var SPECIES = wellKnownSymbol('species');
  907. // a part of `ArraySpeciesCreate` abstract operation
  908. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  909. var arraySpeciesConstructor = function (originalArray) {
  910. var C;
  911. if (isArray(originalArray)) {
  912. C = originalArray.constructor;
  913. // cross-realm fallback
  914. if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
  915. else if (isObject(C)) {
  916. C = C[SPECIES];
  917. if (C === null) C = undefined;
  918. }
  919. } return C === undefined ? Array : C;
  920. };
  921. // `ArraySpeciesCreate` abstract operation
  922. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  923. var arraySpeciesCreate = function (originalArray, length) {
  924. return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
  925. };
  926. // `Array.prototype.flatMap` method
  927. // https://tc39.es/ecma262/#sec-array.prototype.flatmap
  928. _export({ target: 'Array', proto: true }, {
  929. flatMap: function flatMap(callbackfn /* , thisArg */) {
  930. var O = toObject(this);
  931. var sourceLen = toLength(O.length);
  932. var A;
  933. aFunction(callbackfn);
  934. A = arraySpeciesCreate(O, 0);
  935. A.length = flattenIntoArray_1(A, O, O, sourceLen, 0, 1, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  936. return A;
  937. }
  938. });
  939. var toString = function (argument) {
  940. if (isSymbol(argument)) throw TypeError('Cannot convert a Symbol value to a string');
  941. return String(argument);
  942. };
  943. // TODO: use something more complex like timsort?
  944. var floor = Math.floor;
  945. var mergeSort = function (array, comparefn) {
  946. var length = array.length;
  947. var middle = floor(length / 2);
  948. return length < 8 ? insertionSort(array, comparefn) : merge(
  949. mergeSort(array.slice(0, middle), comparefn),
  950. mergeSort(array.slice(middle), comparefn),
  951. comparefn
  952. );
  953. };
  954. var insertionSort = function (array, comparefn) {
  955. var length = array.length;
  956. var i = 1;
  957. var element, j;
  958. while (i < length) {
  959. j = i;
  960. element = array[i];
  961. while (j && comparefn(array[j - 1], element) > 0) {
  962. array[j] = array[--j];
  963. }
  964. if (j !== i++) array[j] = element;
  965. } return array;
  966. };
  967. var merge = function (left, right, comparefn) {
  968. var llength = left.length;
  969. var rlength = right.length;
  970. var lindex = 0;
  971. var rindex = 0;
  972. var result = [];
  973. while (lindex < llength || rindex < rlength) {
  974. if (lindex < llength && rindex < rlength) {
  975. result.push(comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]);
  976. } else {
  977. result.push(lindex < llength ? left[lindex++] : right[rindex++]);
  978. }
  979. } return result;
  980. };
  981. var arraySort = mergeSort;
  982. var arrayMethodIsStrict = function (METHOD_NAME, argument) {
  983. var method = [][METHOD_NAME];
  984. return !!method && fails(function () {
  985. // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
  986. method.call(null, argument || function () { throw 1; }, 1);
  987. });
  988. };
  989. var firefox = engineUserAgent.match(/firefox\/(\d+)/i);
  990. var engineFfVersion = !!firefox && +firefox[1];
  991. var engineIsIeOrEdge = /MSIE|Trident/.test(engineUserAgent);
  992. var webkit = engineUserAgent.match(/AppleWebKit\/(\d+)\./);
  993. var engineWebkitVersion = !!webkit && +webkit[1];
  994. var test$1 = [];
  995. var nativeSort = test$1.sort;
  996. // IE8-
  997. var FAILS_ON_UNDEFINED = fails(function () {
  998. test$1.sort(undefined);
  999. });
  1000. // V8 bug
  1001. var FAILS_ON_NULL = fails(function () {
  1002. test$1.sort(null);
  1003. });
  1004. // Old WebKit
  1005. var STRICT_METHOD = arrayMethodIsStrict('sort');
  1006. var STABLE_SORT = !fails(function () {
  1007. // feature detection can be too slow, so check engines versions
  1008. if (engineV8Version) return engineV8Version < 70;
  1009. if (engineFfVersion && engineFfVersion > 3) return;
  1010. if (engineIsIeOrEdge) return true;
  1011. if (engineWebkitVersion) return engineWebkitVersion < 603;
  1012. var result = '';
  1013. var code, chr, value, index;
  1014. // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
  1015. for (code = 65; code < 76; code++) {
  1016. chr = String.fromCharCode(code);
  1017. switch (code) {
  1018. case 66: case 69: case 70: case 72: value = 3; break;
  1019. case 68: case 71: value = 4; break;
  1020. default: value = 2;
  1021. }
  1022. for (index = 0; index < 47; index++) {
  1023. test$1.push({ k: chr + index, v: value });
  1024. }
  1025. }
  1026. test$1.sort(function (a, b) { return b.v - a.v; });
  1027. for (index = 0; index < test$1.length; index++) {
  1028. chr = test$1[index].k.charAt(0);
  1029. if (result.charAt(result.length - 1) !== chr) result += chr;
  1030. }
  1031. return result !== 'DGBEFHACIJK';
  1032. });
  1033. var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
  1034. var getSortCompare = function (comparefn) {
  1035. return function (x, y) {
  1036. if (y === undefined) return -1;
  1037. if (x === undefined) return 1;
  1038. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  1039. return toString(x) > toString(y) ? 1 : -1;
  1040. };
  1041. };
  1042. // `Array.prototype.sort` method
  1043. // https://tc39.es/ecma262/#sec-array.prototype.sort
  1044. _export({ target: 'Array', proto: true, forced: FORCED }, {
  1045. sort: function sort(comparefn) {
  1046. if (comparefn !== undefined) aFunction(comparefn);
  1047. var array = toObject(this);
  1048. if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
  1049. var items = [];
  1050. var arrayLength = toLength(array.length);
  1051. var itemsLength, index;
  1052. for (index = 0; index < arrayLength; index++) {
  1053. if (index in array) items.push(array[index]);
  1054. }
  1055. items = arraySort(items, getSortCompare(comparefn));
  1056. itemsLength = items.length;
  1057. index = 0;
  1058. while (index < itemsLength) array[index] = items[index++];
  1059. while (index < arrayLength) delete array[index++];
  1060. return array;
  1061. }
  1062. });
  1063. var iterators = {};
  1064. var ITERATOR$1 = wellKnownSymbol('iterator');
  1065. var ArrayPrototype = Array.prototype;
  1066. // check on default Array iterator
  1067. var isArrayIteratorMethod = function (it) {
  1068. return it !== undefined && (iterators.Array === it || ArrayPrototype[ITERATOR$1] === it);
  1069. };
  1070. var TO_STRING_TAG$1 = wellKnownSymbol('toStringTag');
  1071. var test = {};
  1072. test[TO_STRING_TAG$1] = 'z';
  1073. var toStringTagSupport = String(test) === '[object z]';
  1074. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  1075. // ES3 wrong here
  1076. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  1077. // fallback for IE11 Script Access Denied error
  1078. var tryGet = function (it, key) {
  1079. try {
  1080. return it[key];
  1081. } catch (error) { /* empty */ }
  1082. };
  1083. // getting tag from ES6+ `Object.prototype.toString`
  1084. var classof = toStringTagSupport ? classofRaw : function (it) {
  1085. var O, tag, result;
  1086. return it === undefined ? 'Undefined' : it === null ? 'Null'
  1087. // @@toStringTag case
  1088. : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG)) == 'string' ? tag
  1089. // builtinTag case
  1090. : CORRECT_ARGUMENTS ? classofRaw(O)
  1091. // ES3 arguments fallback
  1092. : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result;
  1093. };
  1094. var ITERATOR = wellKnownSymbol('iterator');
  1095. var getIteratorMethod = function (it) {
  1096. if (it != undefined) return it[ITERATOR]
  1097. || it['@@iterator']
  1098. || iterators[classof(it)];
  1099. };
  1100. var getIterator = function (it, usingIterator) {
  1101. var iteratorMethod = arguments.length < 2 ? getIteratorMethod(it) : usingIterator;
  1102. if (typeof iteratorMethod != 'function') {
  1103. throw TypeError(String(it) + ' is not iterable');
  1104. } return anObject(iteratorMethod.call(it));
  1105. };
  1106. var iteratorClose = function (iterator, kind, value) {
  1107. var innerResult, innerError;
  1108. anObject(iterator);
  1109. try {
  1110. innerResult = iterator['return'];
  1111. if (innerResult === undefined) {
  1112. if (kind === 'throw') throw value;
  1113. return value;
  1114. }
  1115. innerResult = innerResult.call(iterator);
  1116. } catch (error) {
  1117. innerError = true;
  1118. innerResult = error;
  1119. }
  1120. if (kind === 'throw') throw value;
  1121. if (innerError) throw innerResult;
  1122. anObject(innerResult);
  1123. return value;
  1124. };
  1125. var Result = function (stopped, result) {
  1126. this.stopped = stopped;
  1127. this.result = result;
  1128. };
  1129. var iterate = function (iterable, unboundFunction, options) {
  1130. var that = options && options.that;
  1131. var AS_ENTRIES = !!(options && options.AS_ENTRIES);
  1132. var IS_ITERATOR = !!(options && options.IS_ITERATOR);
  1133. var INTERRUPTED = !!(options && options.INTERRUPTED);
  1134. var fn = functionBindContext(unboundFunction, that, 1 + AS_ENTRIES + INTERRUPTED);
  1135. var iterator, iterFn, index, length, result, next, step;
  1136. var stop = function (condition) {
  1137. if (iterator) iteratorClose(iterator, 'normal', condition);
  1138. return new Result(true, condition);
  1139. };
  1140. var callFn = function (value) {
  1141. if (AS_ENTRIES) {
  1142. anObject(value);
  1143. return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
  1144. } return INTERRUPTED ? fn(value, stop) : fn(value);
  1145. };
  1146. if (IS_ITERATOR) {
  1147. iterator = iterable;
  1148. } else {
  1149. iterFn = getIteratorMethod(iterable);
  1150. if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
  1151. // optimisation for array iterators
  1152. if (isArrayIteratorMethod(iterFn)) {
  1153. for (index = 0, length = toLength(iterable.length); length > index; index++) {
  1154. result = callFn(iterable[index]);
  1155. if (result && result instanceof Result) return result;
  1156. } return new Result(false);
  1157. }
  1158. iterator = getIterator(iterable, iterFn);
  1159. }
  1160. next = iterator.next;
  1161. while (!(step = next.call(iterator)).done) {
  1162. try {
  1163. result = callFn(step.value);
  1164. } catch (error) {
  1165. iteratorClose(iterator, 'throw', error);
  1166. }
  1167. if (typeof result == 'object' && result && result instanceof Result) return result;
  1168. } return new Result(false);
  1169. };
  1170. var createProperty = function (object, key, value) {
  1171. var propertyKey = toPropertyKey(key);
  1172. if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));
  1173. else object[propertyKey] = value;
  1174. };
  1175. // `Object.fromEntries` method
  1176. // https://github.com/tc39/proposal-object-from-entries
  1177. _export({ target: 'Object', stat: true }, {
  1178. fromEntries: function fromEntries(iterable) {
  1179. var obj = {};
  1180. iterate(iterable, function (k, v) {
  1181. createProperty(obj, k, v);
  1182. }, { AS_ENTRIES: true });
  1183. return obj;
  1184. }
  1185. });
  1186. var global$1 = (typeof global$1 !== "undefined" ? global$1 :
  1187. typeof self !== "undefined" ? self :
  1188. typeof window !== "undefined" ? window : {});
  1189. // shim for using process in browser
  1190. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  1191. function defaultSetTimout() {
  1192. throw new Error('setTimeout has not been defined');
  1193. }
  1194. function defaultClearTimeout () {
  1195. throw new Error('clearTimeout has not been defined');
  1196. }
  1197. var cachedSetTimeout = defaultSetTimout;
  1198. var cachedClearTimeout = defaultClearTimeout;
  1199. if (typeof global$1.setTimeout === 'function') {
  1200. cachedSetTimeout = setTimeout;
  1201. }
  1202. if (typeof global$1.clearTimeout === 'function') {
  1203. cachedClearTimeout = clearTimeout;
  1204. }
  1205. function runTimeout(fun) {
  1206. if (cachedSetTimeout === setTimeout) {
  1207. //normal enviroments in sane situations
  1208. return setTimeout(fun, 0);
  1209. }
  1210. // if setTimeout wasn't available but was latter defined
  1211. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1212. cachedSetTimeout = setTimeout;
  1213. return setTimeout(fun, 0);
  1214. }
  1215. try {
  1216. // when when somebody has screwed with setTimeout but no I.E. maddness
  1217. return cachedSetTimeout(fun, 0);
  1218. } catch(e){
  1219. try {
  1220. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1221. return cachedSetTimeout.call(null, fun, 0);
  1222. } catch(e){
  1223. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  1224. return cachedSetTimeout.call(this, fun, 0);
  1225. }
  1226. }
  1227. }
  1228. function runClearTimeout(marker) {
  1229. if (cachedClearTimeout === clearTimeout) {
  1230. //normal enviroments in sane situations
  1231. return clearTimeout(marker);
  1232. }
  1233. // if clearTimeout wasn't available but was latter defined
  1234. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1235. cachedClearTimeout = clearTimeout;
  1236. return clearTimeout(marker);
  1237. }
  1238. try {
  1239. // when when somebody has screwed with setTimeout but no I.E. maddness
  1240. return cachedClearTimeout(marker);
  1241. } catch (e){
  1242. try {
  1243. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1244. return cachedClearTimeout.call(null, marker);
  1245. } catch (e){
  1246. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  1247. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  1248. return cachedClearTimeout.call(this, marker);
  1249. }
  1250. }
  1251. }
  1252. var queue = [];
  1253. var draining = false;
  1254. var currentQueue;
  1255. var queueIndex = -1;
  1256. function cleanUpNextTick() {
  1257. if (!draining || !currentQueue) {
  1258. return;
  1259. }
  1260. draining = false;
  1261. if (currentQueue.length) {
  1262. queue = currentQueue.concat(queue);
  1263. } else {
  1264. queueIndex = -1;
  1265. }
  1266. if (queue.length) {
  1267. drainQueue();
  1268. }
  1269. }
  1270. function drainQueue() {
  1271. if (draining) {
  1272. return;
  1273. }
  1274. var timeout = runTimeout(cleanUpNextTick);
  1275. draining = true;
  1276. var len = queue.length;
  1277. while(len) {
  1278. currentQueue = queue;
  1279. queue = [];
  1280. while (++queueIndex < len) {
  1281. if (currentQueue) {
  1282. currentQueue[queueIndex].run();
  1283. }
  1284. }
  1285. queueIndex = -1;
  1286. len = queue.length;
  1287. }
  1288. currentQueue = null;
  1289. draining = false;
  1290. runClearTimeout(timeout);
  1291. }
  1292. function nextTick(fun) {
  1293. var args = new Array(arguments.length - 1);
  1294. if (arguments.length > 1) {
  1295. for (var i = 1; i < arguments.length; i++) {
  1296. args[i - 1] = arguments[i];
  1297. }
  1298. }
  1299. queue.push(new Item(fun, args));
  1300. if (queue.length === 1 && !draining) {
  1301. runTimeout(drainQueue);
  1302. }
  1303. }
  1304. // v8 likes predictible objects
  1305. function Item(fun, array) {
  1306. this.fun = fun;
  1307. this.array = array;
  1308. }
  1309. Item.prototype.run = function () {
  1310. this.fun.apply(null, this.array);
  1311. };
  1312. var title = 'browser';
  1313. var platform = 'browser';
  1314. var browser = true;
  1315. var env = {};
  1316. var argv = [];
  1317. var version = ''; // empty string to avoid regexp issues
  1318. var versions = {};
  1319. var release = {};
  1320. var config = {};
  1321. function noop() {}
  1322. var on = noop;
  1323. var addListener = noop;
  1324. var once = noop;
  1325. var off = noop;
  1326. var removeListener = noop;
  1327. var removeAllListeners = noop;
  1328. var emit = noop;
  1329. function binding(name) {
  1330. throw new Error('process.binding is not supported');
  1331. }
  1332. function cwd () { return '/' }
  1333. function chdir (dir) {
  1334. throw new Error('process.chdir is not supported');
  1335. }function umask() { return 0; }
  1336. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  1337. var performance = global$1.performance || {};
  1338. var performanceNow =
  1339. performance.now ||
  1340. performance.mozNow ||
  1341. performance.msNow ||
  1342. performance.oNow ||
  1343. performance.webkitNow ||
  1344. function(){ return (new Date()).getTime() };
  1345. // generate timestamp or delta
  1346. // see http://nodejs.org/api/process.html#process_process_hrtime
  1347. function hrtime(previousTimestamp){
  1348. var clocktime = performanceNow.call(performance)*1e-3;
  1349. var seconds = Math.floor(clocktime);
  1350. var nanoseconds = Math.floor((clocktime%1)*1e9);
  1351. if (previousTimestamp) {
  1352. seconds = seconds - previousTimestamp[0];
  1353. nanoseconds = nanoseconds - previousTimestamp[1];
  1354. if (nanoseconds<0) {
  1355. seconds--;
  1356. nanoseconds += 1e9;
  1357. }
  1358. }
  1359. return [seconds,nanoseconds]
  1360. }
  1361. var startTime = new Date();
  1362. function uptime() {
  1363. var currentTime = new Date();
  1364. var dif = currentTime - startTime;
  1365. return dif / 1000;
  1366. }
  1367. var browser$1 = {
  1368. nextTick: nextTick,
  1369. title: title,
  1370. browser: browser,
  1371. env: env,
  1372. argv: argv,
  1373. version: version,
  1374. versions: versions,
  1375. on: on,
  1376. addListener: addListener,
  1377. once: once,
  1378. off: off,
  1379. removeListener: removeListener,
  1380. removeAllListeners: removeAllListeners,
  1381. emit: emit,
  1382. binding: binding,
  1383. cwd: cwd,
  1384. chdir: chdir,
  1385. umask: umask,
  1386. hrtime: hrtime,
  1387. platform: platform,
  1388. release: release,
  1389. config: config,
  1390. uptime: uptime
  1391. };
  1392. const debug = typeof browser$1 === 'object' && browser$1.env && browser$1.env.NODE_DEBUG && /\bsemver\b/i.test(browser$1.env.NODE_DEBUG) ? (...args) => console.error('SEMVER', ...args) : () => {};
  1393. var debug_1 = debug;
  1394. // Note: this is the semver.org version of the spec that it implements
  1395. // Not necessarily the package version of this code.
  1396. const SEMVER_SPEC_VERSION = '2.0.0';
  1397. const MAX_LENGTH$1 = 256;
  1398. const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER ||
  1399. /* istanbul ignore next */
  1400. 9007199254740991; // Max safe segment length for coercion.
  1401. const MAX_SAFE_COMPONENT_LENGTH = 16;
  1402. var constants = {
  1403. SEMVER_SPEC_VERSION,
  1404. MAX_LENGTH: MAX_LENGTH$1,
  1405. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
  1406. MAX_SAFE_COMPONENT_LENGTH
  1407. };
  1408. var re_1 = createCommonjsModule(function (module, exports) {
  1409. const {
  1410. MAX_SAFE_COMPONENT_LENGTH
  1411. } = constants;
  1412. exports = module.exports = {}; // The actual regexps go on exports.re
  1413. const re = exports.re = [];
  1414. const src = exports.src = [];
  1415. const t = exports.t = {};
  1416. let R = 0;
  1417. const createToken = (name, value, isGlobal) => {
  1418. const index = R++;
  1419. debug_1(index, value);
  1420. t[name] = index;
  1421. src[index] = value;
  1422. re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
  1423. }; // The following Regular Expressions can be used for tokenizing,
  1424. // validating, and parsing SemVer version strings.
  1425. // ## Numeric Identifier
  1426. // A single `0`, or a non-zero digit followed by zero or more digits.
  1427. createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
  1428. createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+'); // ## Non-numeric Identifier
  1429. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1430. // more letters, digits, or hyphens.
  1431. createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*'); // ## Main Version
  1432. // Three dot-separated numeric identifiers.
  1433. createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` + `(${src[t.NUMERICIDENTIFIER]})\\.` + `(${src[t.NUMERICIDENTIFIER]})`);
  1434. createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + `(${src[t.NUMERICIDENTIFIERLOOSE]})`); // ## Pre-release Version Identifier
  1435. // A numeric identifier, or a non-numeric identifier.
  1436. createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]}|${src[t.NONNUMERICIDENTIFIER]})`);
  1437. createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]}|${src[t.NONNUMERICIDENTIFIER]})`); // ## Pre-release Version
  1438. // Hyphen, followed by one or more dot-separated pre-release version
  1439. // identifiers.
  1440. createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
  1441. createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`); // ## Build Metadata Identifier
  1442. // Any combination of digits, letters, or hyphens.
  1443. createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+'); // ## Build Metadata
  1444. // Plus sign, followed by one or more period-separated build metadata
  1445. // identifiers.
  1446. createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`); // ## Full Version String
  1447. // A main version, followed optionally by a pre-release version and
  1448. // build metadata.
  1449. // Note that the only major, minor, patch, and pre-release sections of
  1450. // the version string are capturing groups. The build metadata is not a
  1451. // capturing group, because it should not ever be used in version
  1452. // comparison.
  1453. createToken('FULLPLAIN', `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
  1454. createToken('FULL', `^${src[t.FULLPLAIN]}$`); // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1455. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1456. // common in the npm registry.
  1457. createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
  1458. createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
  1459. createToken('GTLT', '((?:<|>)?=?)'); // Something like "2.*" or "1.2.x".
  1460. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1461. // Only the first item is strictly required.
  1462. createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
  1463. createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
  1464. createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` + `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + `(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?` + `)?)?`);
  1465. createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?` + `)?)?`);
  1466. createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
  1467. createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`); // Coercion.
  1468. // Extract anything that could conceivably be a part of a valid semver
  1469. createToken('COERCE', `${'(^|[^\\d])' + '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + `(?:$|[^\\d])`);
  1470. createToken('COERCERTL', src[t.COERCE], true); // Tilde ranges.
  1471. // Meaning is "reasonably at or greater than"
  1472. createToken('LONETILDE', '(?:~>?)');
  1473. createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
  1474. exports.tildeTrimReplace = '$1~';
  1475. createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
  1476. createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`); // Caret ranges.
  1477. // Meaning is "at least and backwards compatible with"
  1478. createToken('LONECARET', '(?:\\^)');
  1479. createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
  1480. exports.caretTrimReplace = '$1^';
  1481. createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
  1482. createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`); // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1483. createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
  1484. createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`); // An expression to strip any whitespace between the gtlt and the thing
  1485. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1486. createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
  1487. exports.comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  1488. // Note that these all use the loose form, because they'll be
  1489. // checked against either the strict or loose comparator form
  1490. // later.
  1491. createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAIN]})` + `\\s*$`);
  1492. createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAINLOOSE]})` + `\\s*$`); // Star ranges basically just allow anything at all.
  1493. createToken('STAR', '(<|>)?=?\\s*\\*'); // >=0.0.0 is like a star
  1494. createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$');
  1495. createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$');
  1496. });
  1497. // parse out just the options we care about so we always get a consistent
  1498. // obj with keys in a consistent order.
  1499. const opts = ['includePrerelease', 'loose', 'rtl'];
  1500. const parseOptions = options => !options ? {} : typeof options !== 'object' ? {
  1501. loose: true
  1502. } : opts.filter(k => options[k]).reduce((options, k) => {
  1503. options[k] = true;
  1504. return options;
  1505. }, {});
  1506. var parseOptions_1 = parseOptions;
  1507. const numeric = /^[0-9]+$/;
  1508. const compareIdentifiers$1 = (a, b) => {
  1509. const anum = numeric.test(a);
  1510. const bnum = numeric.test(b);
  1511. if (anum && bnum) {
  1512. a = +a;
  1513. b = +b;
  1514. }
  1515. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  1516. };
  1517. const rcompareIdentifiers = (a, b) => compareIdentifiers$1(b, a);
  1518. var identifiers = {
  1519. compareIdentifiers: compareIdentifiers$1,
  1520. rcompareIdentifiers
  1521. };
  1522. const {
  1523. MAX_LENGTH,
  1524. MAX_SAFE_INTEGER
  1525. } = constants;
  1526. const {
  1527. re,
  1528. t
  1529. } = re_1;
  1530. const {
  1531. compareIdentifiers
  1532. } = identifiers;
  1533. class SemVer {
  1534. constructor(version, options) {
  1535. options = parseOptions_1(options);
  1536. if (version instanceof SemVer) {
  1537. if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
  1538. return version;
  1539. } else {
  1540. version = version.version;
  1541. }
  1542. } else if (typeof version !== 'string') {
  1543. throw new TypeError(`Invalid Version: ${version}`);
  1544. }
  1545. if (version.length > MAX_LENGTH) {
  1546. throw new TypeError(`version is longer than ${MAX_LENGTH} characters`);
  1547. }
  1548. debug_1('SemVer', version, options);
  1549. this.options = options;
  1550. this.loose = !!options.loose; // this isn't actually relevant for versions, but keep it so that we
  1551. // don't run into trouble passing this.options around.
  1552. this.includePrerelease = !!options.includePrerelease;
  1553. const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
  1554. if (!m) {
  1555. throw new TypeError(`Invalid Version: ${version}`);
  1556. }
  1557. this.raw = version; // these are actually numbers
  1558. this.major = +m[1];
  1559. this.minor = +m[2];
  1560. this.patch = +m[3];
  1561. if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
  1562. throw new TypeError('Invalid major version');
  1563. }
  1564. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
  1565. throw new TypeError('Invalid minor version');
  1566. }
  1567. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
  1568. throw new TypeError('Invalid patch version');
  1569. } // numberify any prerelease numeric ids
  1570. if (!m[4]) {
  1571. this.prerelease = [];
  1572. } else {
  1573. this.prerelease = m[4].split('.').map(id => {
  1574. if (/^[0-9]+$/.test(id)) {
  1575. const num = +id;
  1576. if (num >= 0 && num < MAX_SAFE_INTEGER) {
  1577. return num;
  1578. }
  1579. }
  1580. return id;
  1581. });
  1582. }
  1583. this.build = m[5] ? m[5].split('.') : [];
  1584. this.format();
  1585. }
  1586. format() {
  1587. this.version = `${this.major}.${this.minor}.${this.patch}`;
  1588. if (this.prerelease.length) {
  1589. this.version += `-${this.prerelease.join('.')}`;
  1590. }
  1591. return this.version;
  1592. }
  1593. toString() {
  1594. return this.version;
  1595. }
  1596. compare(other) {
  1597. debug_1('SemVer.compare', this.version, this.options, other);
  1598. if (!(other instanceof SemVer)) {
  1599. if (typeof other === 'string' && other === this.version) {
  1600. return 0;
  1601. }
  1602. other = new SemVer(other, this.options);
  1603. }
  1604. if (other.version === this.version) {
  1605. return 0;
  1606. }
  1607. return this.compareMain(other) || this.comparePre(other);
  1608. }
  1609. compareMain(other) {
  1610. if (!(other instanceof SemVer)) {
  1611. other = new SemVer(other, this.options);
  1612. }
  1613. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  1614. }
  1615. comparePre(other) {
  1616. if (!(other instanceof SemVer)) {
  1617. other = new SemVer(other, this.options);
  1618. } // NOT having a prerelease is > having one
  1619. if (this.prerelease.length && !other.prerelease.length) {
  1620. return -1;
  1621. } else if (!this.prerelease.length && other.prerelease.length) {
  1622. return 1;
  1623. } else if (!this.prerelease.length && !other.prerelease.length) {
  1624. return 0;
  1625. }
  1626. let i = 0;
  1627. do {
  1628. const a = this.prerelease[i];
  1629. const b = other.prerelease[i];
  1630. debug_1('prerelease compare', i, a, b);
  1631. if (a === undefined && b === undefined) {
  1632. return 0;
  1633. } else if (b === undefined) {
  1634. return 1;
  1635. } else if (a === undefined) {
  1636. return -1;
  1637. } else if (a === b) {
  1638. continue;
  1639. } else {
  1640. return compareIdentifiers(a, b);
  1641. }
  1642. } while (++i);
  1643. }
  1644. compareBuild(other) {
  1645. if (!(other instanceof SemVer)) {
  1646. other = new SemVer(other, this.options);
  1647. }
  1648. let i = 0;
  1649. do {
  1650. const a = this.build[i];
  1651. const b = other.build[i];
  1652. debug_1('prerelease compare', i, a, b);
  1653. if (a === undefined && b === undefined) {
  1654. return 0;
  1655. } else if (b === undefined) {
  1656. return 1;
  1657. } else if (a === undefined) {
  1658. return -1;
  1659. } else if (a === b) {
  1660. continue;
  1661. } else {
  1662. return compareIdentifiers(a, b);
  1663. }
  1664. } while (++i);
  1665. } // preminor will bump the version up to the next minor release, and immediately
  1666. // down to pre-release. premajor and prepatch work the same way.
  1667. inc(release, identifier) {
  1668. switch (release) {
  1669. case 'premajor':
  1670. this.prerelease.length = 0;
  1671. this.patch = 0;
  1672. this.minor = 0;
  1673. this.major++;
  1674. this.inc('pre', identifier);
  1675. break;
  1676. case 'preminor':
  1677. this.prerelease.length = 0;
  1678. this.patch = 0;
  1679. this.minor++;
  1680. this.inc('pre', identifier);
  1681. break;
  1682. case 'prepatch':
  1683. // If this is already a prerelease, it will bump to the next version
  1684. // drop any prereleases that might already exist, since they are not
  1685. // relevant at this point.
  1686. this.prerelease.length = 0;
  1687. this.inc('patch', identifier);
  1688. this.inc('pre', identifier);
  1689. break;
  1690. // If the input is a non-prerelease version, this acts the same as
  1691. // prepatch.
  1692. case 'prerelease':
  1693. if (this.prerelease.length === 0) {
  1694. this.inc('patch', identifier);
  1695. }
  1696. this.inc('pre', identifier);
  1697. break;
  1698. case 'major':
  1699. // If this is a pre-major version, bump up to the same major version.
  1700. // Otherwise increment major.
  1701. // 1.0.0-5 bumps to 1.0.0
  1702. // 1.1.0 bumps to 2.0.0
  1703. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  1704. this.major++;
  1705. }
  1706. this.minor = 0;
  1707. this.patch = 0;
  1708. this.prerelease = [];
  1709. break;
  1710. case 'minor':
  1711. // If this is a pre-minor version, bump up to the same minor version.
  1712. // Otherwise increment minor.
  1713. // 1.2.0-5 bumps to 1.2.0
  1714. // 1.2.1 bumps to 1.3.0
  1715. if (this.patch !== 0 || this.prerelease.length === 0) {
  1716. this.minor++;
  1717. }
  1718. this.patch = 0;
  1719. this.prerelease = [];
  1720. break;
  1721. case 'patch':
  1722. // If this is not a pre-release version, it will increment the patch.
  1723. // If it is a pre-release it will bump up to the same patch version.
  1724. // 1.2.0-5 patches to 1.2.0
  1725. // 1.2.0 patches to 1.2.1
  1726. if (this.prerelease.length === 0) {
  1727. this.patch++;
  1728. }
  1729. this.prerelease = [];
  1730. break;
  1731. // This probably shouldn't be used publicly.
  1732. // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
  1733. case 'pre':
  1734. if (this.prerelease.length === 0) {
  1735. this.prerelease = [0];
  1736. } else {
  1737. let i = this.prerelease.length;
  1738. while (--i >= 0) {
  1739. if (typeof this.prerelease[i] === 'number') {
  1740. this.prerelease[i]++;
  1741. i = -2;
  1742. }
  1743. }
  1744. if (i === -1) {
  1745. // didn't increment anything
  1746. this.prerelease.push(0);
  1747. }
  1748. }
  1749. if (identifier) {
  1750. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  1751. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  1752. if (this.prerelease[0] === identifier) {
  1753. if (isNaN(this.prerelease[1])) {
  1754. this.prerelease = [identifier, 0];
  1755. }
  1756. } else {
  1757. this.prerelease = [identifier, 0];
  1758. }
  1759. }
  1760. break;
  1761. default:
  1762. throw new Error(`invalid increment argument: ${release}`);
  1763. }
  1764. this.format();
  1765. this.raw = this.version;
  1766. return this;
  1767. }
  1768. }
  1769. var semver$1 = SemVer;
  1770. const compare = (a, b, loose) => new semver$1(a, loose).compare(new semver$1(b, loose));
  1771. var compare_1 = compare;
  1772. const lt = (a, b, loose) => compare_1(a, b, loose) < 0;
  1773. var lt_1 = lt;
  1774. const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
  1775. var gte_1 = gte;
  1776. var arrayify = (object, keyName) => Object.entries(object).map(([key, value]) => Object.assign({
  1777. [keyName]: key
  1778. }, value));
  1779. var require$$3 = {"version":"2.4.1"};
  1780. var lib = createCommonjsModule(function (module, exports) {
  1781. Object.defineProperty(exports, "__esModule", {
  1782. value: true
  1783. });
  1784. exports.outdent = void 0; // In the absence of a WeakSet or WeakMap implementation, don't break, but don't cache either.
  1785. function noop() {
  1786. var args = [];
  1787. for (var _i = 0; _i < arguments.length; _i++) {
  1788. args[_i] = arguments[_i];
  1789. }
  1790. }
  1791. function createWeakMap() {
  1792. if (typeof WeakMap !== "undefined") {
  1793. return new WeakMap();
  1794. } else {
  1795. return fakeSetOrMap();
  1796. }
  1797. }
  1798. /**
  1799. * Creates and returns a no-op implementation of a WeakMap / WeakSet that never stores anything.
  1800. */
  1801. function fakeSetOrMap() {
  1802. return {
  1803. add: noop,
  1804. delete: noop,
  1805. get: noop,
  1806. set: noop,
  1807. has: function (k) {
  1808. return false;
  1809. }
  1810. };
  1811. } // Safe hasOwnProperty
  1812. var hop = Object.prototype.hasOwnProperty;
  1813. var has = function (obj, prop) {
  1814. return hop.call(obj, prop);
  1815. }; // Copy all own enumerable properties from source to target
  1816. function extend(target, source) {
  1817. for (var prop in source) {
  1818. if (has(source, prop)) {
  1819. target[prop] = source[prop];
  1820. }
  1821. }
  1822. return target;
  1823. }
  1824. var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
  1825. var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
  1826. var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
  1827. var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
  1828. var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
  1829. function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
  1830. // If first interpolated value is a reference to outdent,
  1831. // determine indentation level from the indentation of the interpolated value.
  1832. var indentationLevel = 0;
  1833. var match = strings[0].match(reDetectIndentation);
  1834. if (match) {
  1835. indentationLevel = match[1].length;
  1836. }
  1837. var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
  1838. var reMatchIndent = new RegExp(reSource, "g");
  1839. if (firstInterpolatedValueSetsIndentationLevel) {
  1840. strings = strings.slice(1);
  1841. }
  1842. var newline = options.newline,
  1843. trimLeadingNewline = options.trimLeadingNewline,
  1844. trimTrailingNewline = options.trimTrailingNewline;
  1845. var normalizeNewlines = typeof newline === "string";
  1846. var l = strings.length;
  1847. var outdentedStrings = strings.map(function (v, i) {
  1848. // Remove leading indentation from all lines
  1849. v = v.replace(reMatchIndent, "$1"); // Trim a leading newline from the first string
  1850. if (i === 0 && trimLeadingNewline) {
  1851. v = v.replace(reLeadingNewline, "");
  1852. } // Trim a trailing newline from the last string
  1853. if (i === l - 1 && trimTrailingNewline) {
  1854. v = v.replace(reTrailingNewline, "");
  1855. } // Normalize newlines
  1856. if (normalizeNewlines) {
  1857. v = v.replace(/\r\n|\n|\r/g, function (_) {
  1858. return newline;
  1859. });
  1860. }
  1861. return v;
  1862. });
  1863. return outdentedStrings;
  1864. }
  1865. function concatStringsAndValues(strings, values) {
  1866. var ret = "";
  1867. for (var i = 0, l = strings.length; i < l; i++) {
  1868. ret += strings[i];
  1869. if (i < l - 1) {
  1870. ret += values[i];
  1871. }
  1872. }
  1873. return ret;
  1874. }
  1875. function isTemplateStringsArray(v) {
  1876. return has(v, "raw") && has(v, "length");
  1877. }
  1878. /**
  1879. * It is assumed that opts will not change. If this is a problem, clone your options object and pass the clone to
  1880. * makeInstance
  1881. * @param options
  1882. * @return {outdent}
  1883. */
  1884. function createInstance(options) {
  1885. /** Cache of pre-processed template literal arrays */
  1886. var arrayAutoIndentCache = createWeakMap();
  1887. /**
  1888. * Cache of pre-processed template literal arrays, where first interpolated value is a reference to outdent,
  1889. * before interpolated values are injected.
  1890. */
  1891. var arrayFirstInterpSetsIndentCache = createWeakMap();
  1892. function outdent(stringsOrOptions) {
  1893. var values = [];
  1894. for (var _i = 1; _i < arguments.length; _i++) {
  1895. values[_i - 1] = arguments[_i];
  1896. }
  1897. /* tslint:enable:no-shadowed-variable */
  1898. if (isTemplateStringsArray(stringsOrOptions)) {
  1899. var strings = stringsOrOptions; // Is first interpolated value a reference to outdent, alone on its own line, without any preceding non-whitespace?
  1900. var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]); // Perform outdentation
  1901. var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
  1902. var renderedArray = cache.get(strings);
  1903. if (!renderedArray) {
  1904. renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
  1905. cache.set(strings, renderedArray);
  1906. }
  1907. /** If no interpolated values, skip concatenation step */
  1908. if (values.length === 0) {
  1909. return renderedArray[0];
  1910. }
  1911. /** Concatenate string literals with interpolated values */
  1912. var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
  1913. return rendered;
  1914. } else {
  1915. // Create and return a new instance of outdent with the given options
  1916. return createInstance(extend(extend({}, options), stringsOrOptions || {}));
  1917. }
  1918. }
  1919. var fullOutdent = extend(outdent, {
  1920. string: function (str) {
  1921. return _outdentArray([str], false, options)[0];
  1922. }
  1923. });
  1924. return fullOutdent;
  1925. }
  1926. var defaultOutdent = createInstance({
  1927. trimLeadingNewline: true,
  1928. trimTrailingNewline: true
  1929. });
  1930. exports.outdent = defaultOutdent; // Named exports. Simple and preferred.
  1931. // import outdent from 'outdent';
  1932. exports.default = defaultOutdent;
  1933. {
  1934. // In webpack harmony-modules environments, module.exports is read-only,
  1935. // so we fail gracefully.
  1936. try {
  1937. module.exports = defaultOutdent;
  1938. Object.defineProperty(defaultOutdent, "__esModule", {
  1939. value: true
  1940. });
  1941. defaultOutdent.default = defaultOutdent;
  1942. defaultOutdent.outdent = defaultOutdent;
  1943. } catch (e) {}
  1944. }
  1945. });
  1946. const {
  1947. outdent
  1948. } = lib;
  1949. const CATEGORY_CONFIG = "Config";
  1950. const CATEGORY_EDITOR = "Editor";
  1951. const CATEGORY_FORMAT = "Format";
  1952. const CATEGORY_OTHER = "Other";
  1953. const CATEGORY_OUTPUT = "Output";
  1954. const CATEGORY_GLOBAL = "Global";
  1955. const CATEGORY_SPECIAL = "Special";
  1956. /**
  1957. * @typedef {Object} OptionInfo
  1958. * @property {string} [since] - available since version
  1959. * @property {string} category
  1960. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  1961. * @property {boolean} [array] - indicate it's an array of the specified type
  1962. * @property {OptionValueInfo} [default]
  1963. * @property {OptionRangeInfo} [range] - for type int
  1964. * @property {string} description
  1965. * @property {string} [deprecated] - deprecated since version
  1966. * @property {OptionRedirectInfo} [redirect] - redirect deprecated option
  1967. * @property {(value: any) => boolean} [exception]
  1968. * @property {OptionChoiceInfo[]} [choices] - for type choice
  1969. * @property {string} [cliName]
  1970. * @property {string} [cliCategory]
  1971. * @property {string} [cliDescription]
  1972. *
  1973. * @typedef {number | boolean | string} OptionValue
  1974. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  1975. *
  1976. * @typedef {Object} OptionRedirectInfo
  1977. * @property {string} option
  1978. * @property {OptionValue} value
  1979. *
  1980. * @typedef {Object} OptionRangeInfo
  1981. * @property {number} start - recommended range start
  1982. * @property {number} end - recommended range end
  1983. * @property {number} step - recommended range step
  1984. *
  1985. * @typedef {Object} OptionChoiceInfo
  1986. * @property {boolean | string} value - boolean for the option that is originally boolean type
  1987. * @property {string} description
  1988. * @property {string} [since] - undefined if available since the first version of the option
  1989. * @property {string} [deprecated] - deprecated since version
  1990. * @property {OptionValueInfo} [redirect] - redirect deprecated value
  1991. */
  1992. /** @type {{ [name: string]: OptionInfo }} */
  1993. const options = {
  1994. cursorOffset: {
  1995. since: "1.4.0",
  1996. category: CATEGORY_SPECIAL,
  1997. type: "int",
  1998. default: -1,
  1999. range: {
  2000. start: -1,
  2001. end: Number.POSITIVE_INFINITY,
  2002. step: 1
  2003. },
  2004. description: outdent`
  2005. Print (to stderr) where a cursor at the given position would move to after formatting.
  2006. This option cannot be used with --range-start and --range-end.
  2007. `,
  2008. cliCategory: CATEGORY_EDITOR
  2009. },
  2010. endOfLine: {
  2011. since: "1.15.0",
  2012. category: CATEGORY_GLOBAL,
  2013. type: "choice",
  2014. default: [{
  2015. since: "1.15.0",
  2016. value: "auto"
  2017. }, {
  2018. since: "2.0.0",
  2019. value: "lf"
  2020. }],
  2021. description: "Which end of line characters to apply.",
  2022. choices: [{
  2023. value: "lf",
  2024. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  2025. }, {
  2026. value: "crlf",
  2027. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  2028. }, {
  2029. value: "cr",
  2030. description: "Carriage Return character only (\\r), used very rarely"
  2031. }, {
  2032. value: "auto",
  2033. description: outdent`
  2034. Maintain existing
  2035. (mixed values within one file are normalised by looking at what's used after the first line)
  2036. `
  2037. }]
  2038. },
  2039. filepath: {
  2040. since: "1.4.0",
  2041. category: CATEGORY_SPECIAL,
  2042. type: "path",
  2043. description: "Specify the input filepath. This will be used to do parser inference.",
  2044. cliName: "stdin-filepath",
  2045. cliCategory: CATEGORY_OTHER,
  2046. cliDescription: "Path to the file to pretend that stdin comes from."
  2047. },
  2048. insertPragma: {
  2049. since: "1.8.0",
  2050. category: CATEGORY_SPECIAL,
  2051. type: "boolean",
  2052. default: false,
  2053. description: "Insert @format pragma into file's first docblock comment.",
  2054. cliCategory: CATEGORY_OTHER
  2055. },
  2056. parser: {
  2057. since: "0.0.10",
  2058. category: CATEGORY_GLOBAL,
  2059. type: "choice",
  2060. default: [{
  2061. since: "0.0.10",
  2062. value: "babylon"
  2063. }, {
  2064. since: "1.13.0",
  2065. value: undefined
  2066. }],
  2067. description: "Which parser to use.",
  2068. exception: value => typeof value === "string" || typeof value === "function",
  2069. choices: [{
  2070. value: "flow",
  2071. description: "Flow"
  2072. }, {
  2073. value: "babel",
  2074. since: "1.16.0",
  2075. description: "JavaScript"
  2076. }, {
  2077. value: "babel-flow",
  2078. since: "1.16.0",
  2079. description: "Flow"
  2080. }, {
  2081. value: "babel-ts",
  2082. since: "2.0.0",
  2083. description: "TypeScript"
  2084. }, {
  2085. value: "typescript",
  2086. since: "1.4.0",
  2087. description: "TypeScript"
  2088. }, {
  2089. value: "espree",
  2090. since: "2.2.0",
  2091. description: "JavaScript"
  2092. }, {
  2093. value: "meriyah",
  2094. since: "2.2.0",
  2095. description: "JavaScript"
  2096. }, {
  2097. value: "css",
  2098. since: "1.7.1",
  2099. description: "CSS"
  2100. }, {
  2101. value: "less",
  2102. since: "1.7.1",
  2103. description: "Less"
  2104. }, {
  2105. value: "scss",
  2106. since: "1.7.1",
  2107. description: "SCSS"
  2108. }, {
  2109. value: "json",
  2110. since: "1.5.0",
  2111. description: "JSON"
  2112. }, {
  2113. value: "json5",
  2114. since: "1.13.0",
  2115. description: "JSON5"
  2116. }, {
  2117. value: "json-stringify",
  2118. since: "1.13.0",
  2119. description: "JSON.stringify"
  2120. }, {
  2121. value: "graphql",
  2122. since: "1.5.0",
  2123. description: "GraphQL"
  2124. }, {
  2125. value: "markdown",
  2126. since: "1.8.0",
  2127. description: "Markdown"
  2128. }, {
  2129. value: "mdx",
  2130. since: "1.15.0",
  2131. description: "MDX"
  2132. }, {
  2133. value: "vue",
  2134. since: "1.10.0",
  2135. description: "Vue"
  2136. }, {
  2137. value: "yaml",
  2138. since: "1.14.0",
  2139. description: "YAML"
  2140. }, {
  2141. value: "glimmer",
  2142. since: "2.3.0",
  2143. description: "Ember / Handlebars"
  2144. }, {
  2145. value: "html",
  2146. since: "1.15.0",
  2147. description: "HTML"
  2148. }, {
  2149. value: "angular",
  2150. since: "1.15.0",
  2151. description: "Angular"
  2152. }, {
  2153. value: "lwc",
  2154. since: "1.17.0",
  2155. description: "Lightning Web Components"
  2156. }]
  2157. },
  2158. plugins: {
  2159. since: "1.10.0",
  2160. type: "path",
  2161. array: true,
  2162. default: [{
  2163. value: []
  2164. }],
  2165. category: CATEGORY_GLOBAL,
  2166. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  2167. exception: value => typeof value === "string" || typeof value === "object",
  2168. cliName: "plugin",
  2169. cliCategory: CATEGORY_CONFIG
  2170. },
  2171. pluginSearchDirs: {
  2172. since: "1.13.0",
  2173. type: "path",
  2174. array: true,
  2175. default: [{
  2176. value: []
  2177. }],
  2178. category: CATEGORY_GLOBAL,
  2179. description: outdent`
  2180. Custom directory that contains prettier plugins in node_modules subdirectory.
  2181. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  2182. Multiple values are accepted.
  2183. `,
  2184. exception: value => typeof value === "string" || typeof value === "object",
  2185. cliName: "plugin-search-dir",
  2186. cliCategory: CATEGORY_CONFIG
  2187. },
  2188. printWidth: {
  2189. since: "0.0.0",
  2190. category: CATEGORY_GLOBAL,
  2191. type: "int",
  2192. default: 80,
  2193. description: "The line length where Prettier will try wrap.",
  2194. range: {
  2195. start: 0,
  2196. end: Number.POSITIVE_INFINITY,
  2197. step: 1
  2198. }
  2199. },
  2200. rangeEnd: {
  2201. since: "1.4.0",
  2202. category: CATEGORY_SPECIAL,
  2203. type: "int",
  2204. default: Number.POSITIVE_INFINITY,
  2205. range: {
  2206. start: 0,
  2207. end: Number.POSITIVE_INFINITY,
  2208. step: 1
  2209. },
  2210. description: outdent`
  2211. Format code ending at a given character offset (exclusive).
  2212. The range will extend forwards to the end of the selected statement.
  2213. This option cannot be used with --cursor-offset.
  2214. `,
  2215. cliCategory: CATEGORY_EDITOR
  2216. },
  2217. rangeStart: {
  2218. since: "1.4.0",
  2219. category: CATEGORY_SPECIAL,
  2220. type: "int",
  2221. default: 0,
  2222. range: {
  2223. start: 0,
  2224. end: Number.POSITIVE_INFINITY,
  2225. step: 1
  2226. },
  2227. description: outdent`
  2228. Format code starting at a given character offset.
  2229. The range will extend backwards to the start of the first line containing the selected statement.
  2230. This option cannot be used with --cursor-offset.
  2231. `,
  2232. cliCategory: CATEGORY_EDITOR
  2233. },
  2234. requirePragma: {
  2235. since: "1.7.0",
  2236. category: CATEGORY_SPECIAL,
  2237. type: "boolean",
  2238. default: false,
  2239. description: outdent`
  2240. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  2241. in order for it to be formatted.
  2242. `,
  2243. cliCategory: CATEGORY_OTHER
  2244. },
  2245. tabWidth: {
  2246. type: "int",
  2247. category: CATEGORY_GLOBAL,
  2248. default: 2,
  2249. description: "Number of spaces per indentation level.",
  2250. range: {
  2251. start: 0,
  2252. end: Number.POSITIVE_INFINITY,
  2253. step: 1
  2254. }
  2255. },
  2256. useTabs: {
  2257. since: "1.0.0",
  2258. category: CATEGORY_GLOBAL,
  2259. type: "boolean",
  2260. default: false,
  2261. description: "Indent with tabs instead of spaces."
  2262. },
  2263. embeddedLanguageFormatting: {
  2264. since: "2.1.0",
  2265. category: CATEGORY_GLOBAL,
  2266. type: "choice",
  2267. default: [{
  2268. since: "2.1.0",
  2269. value: "auto"
  2270. }],
  2271. description: "Control how Prettier formats quoted code embedded in the file.",
  2272. choices: [{
  2273. value: "auto",
  2274. description: "Format embedded code if Prettier can automatically identify it."
  2275. }, {
  2276. value: "off",
  2277. description: "Never automatically format embedded code."
  2278. }]
  2279. }
  2280. };
  2281. var coreOptions$1 = {
  2282. CATEGORY_CONFIG,
  2283. CATEGORY_EDITOR,
  2284. CATEGORY_FORMAT,
  2285. CATEGORY_OTHER,
  2286. CATEGORY_OUTPUT,
  2287. CATEGORY_GLOBAL,
  2288. CATEGORY_SPECIAL,
  2289. options
  2290. };
  2291. const _excluded = ["cliName", "cliCategory", "cliDescription"];
  2292. const semver = {
  2293. compare: compare_1,
  2294. lt: lt_1,
  2295. gte: gte_1
  2296. };
  2297. const currentVersion = require$$3.version;
  2298. const coreOptions = coreOptions$1.options;
  2299. /**
  2300. * Strings in `plugins` and `pluginSearchDirs` are handled by a wrapped version
  2301. * of this function created by `withPlugins`. Don't pass them here directly.
  2302. * @param {object} param0
  2303. * @param {(string | object)[]=} param0.plugins Strings are resolved by `withPlugins`.
  2304. * @param {string[]=} param0.pluginSearchDirs Added by `withPlugins`.
  2305. * @param {boolean=} param0.showUnreleased
  2306. * @param {boolean=} param0.showDeprecated
  2307. * @param {boolean=} param0.showInternal
  2308. */
  2309. function getSupportInfo$1({
  2310. plugins = [],
  2311. showUnreleased = false,
  2312. showDeprecated = false,
  2313. showInternal = false
  2314. } = {}) {
  2315. // pre-release version is smaller than the normal version in semver,
  2316. // we need to treat it as the normal one so as to test new features.
  2317. const version = currentVersion.split("-", 1)[0];
  2318. const languages = plugins.flatMap(plugin => plugin.languages || []).filter(filterSince);
  2319. const options = arrayify(Object.assign({}, ...plugins.map(({
  2320. options
  2321. }) => options), coreOptions), "name").filter(option => filterSince(option) && filterDeprecated(option)).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1).map(mapInternal).map(option => {
  2322. option = Object.assign({}, option);
  2323. if (Array.isArray(option.default)) {
  2324. option.default = option.default.length === 1 ? option.default[0].value : option.default.filter(filterSince).sort((info1, info2) => semver.compare(info2.since, info1.since))[0].value;
  2325. }
  2326. if (Array.isArray(option.choices)) {
  2327. option.choices = option.choices.filter(option => filterSince(option) && filterDeprecated(option));
  2328. if (option.name === "parser") {
  2329. collectParsersFromLanguages(option, languages, plugins);
  2330. }
  2331. }
  2332. const pluginDefaults = Object.fromEntries(plugins.filter(plugin => plugin.defaultOptions && plugin.defaultOptions[option.name] !== undefined).map(plugin => [plugin.name, plugin.defaultOptions[option.name]]));
  2333. return Object.assign(Object.assign({}, option), {}, {
  2334. pluginDefaults
  2335. });
  2336. });
  2337. return {
  2338. languages,
  2339. options
  2340. };
  2341. function filterSince(object) {
  2342. return showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  2343. }
  2344. function filterDeprecated(object) {
  2345. return showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  2346. }
  2347. function mapInternal(object) {
  2348. if (showInternal) {
  2349. return object;
  2350. }
  2351. const newObject = _objectWithoutProperties(object, _excluded);
  2352. return newObject;
  2353. }
  2354. }
  2355. function collectParsersFromLanguages(option, languages, plugins) {
  2356. const existingValues = new Set(option.choices.map(choice => choice.value));
  2357. for (const language of languages) {
  2358. if (language.parsers) {
  2359. for (const value of language.parsers) {
  2360. if (!existingValues.has(value)) {
  2361. existingValues.add(value);
  2362. const plugin = plugins.find(plugin => plugin.parsers && plugin.parsers[value]);
  2363. let description = language.name;
  2364. if (plugin && plugin.name) {
  2365. description += ` (plugin: ${plugin.name})`;
  2366. }
  2367. option.choices.push({
  2368. value,
  2369. description
  2370. });
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. var support = {
  2377. getSupportInfo: getSupportInfo$1
  2378. };
  2379. const {
  2380. getSupportInfo
  2381. } = support;
  2382. const notAsciiRegex = /[^\x20-\x7F]/;
  2383. const getPenultimate = arr => arr[arr.length - 2];
  2384. /**
  2385. * @typedef {{backwards?: boolean}} SkipOptions
  2386. */
  2387. /**
  2388. * @param {string | RegExp} chars
  2389. * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2390. */
  2391. function skip(chars) {
  2392. return (text, index, opts) => {
  2393. const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  2394. // to check for failures (did someone say monads?).
  2395. /* istanbul ignore next */
  2396. if (index === false) {
  2397. return false;
  2398. }
  2399. const {
  2400. length
  2401. } = text;
  2402. let cursor = index;
  2403. while (cursor >= 0 && cursor < length) {
  2404. const c = text.charAt(cursor);
  2405. if (chars instanceof RegExp) {
  2406. if (!chars.test(c)) {
  2407. return cursor;
  2408. }
  2409. } else if (!chars.includes(c)) {
  2410. return cursor;
  2411. }
  2412. backwards ? cursor-- : cursor++;
  2413. }
  2414. if (cursor === -1 || cursor === length) {
  2415. // If we reached the beginning or end of the file, return the
  2416. // out-of-bounds cursor. It's up to the caller to handle this
  2417. // correctly. We don't want to indicate `false` though if it
  2418. // actually skipped valid characters.
  2419. return cursor;
  2420. }
  2421. return false;
  2422. };
  2423. }
  2424. /**
  2425. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2426. */
  2427. const skipWhitespace = skip(/\s/);
  2428. /**
  2429. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2430. */
  2431. const skipSpaces = skip(" \t");
  2432. /**
  2433. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2434. */
  2435. const skipToLineEnd = skip(",; \t");
  2436. /**
  2437. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2438. */
  2439. const skipEverythingButNewLine = skip(/[^\n\r]/);
  2440. /**
  2441. * @param {string} text
  2442. * @param {number | false} index
  2443. * @returns {number | false}
  2444. */
  2445. function skipInlineComment(text, index) {
  2446. /* istanbul ignore next */
  2447. if (index === false) {
  2448. return false;
  2449. }
  2450. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  2451. for (let i = index + 2; i < text.length; ++i) {
  2452. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  2453. return i + 2;
  2454. }
  2455. }
  2456. }
  2457. return index;
  2458. }
  2459. /**
  2460. * @param {string} text
  2461. * @param {number | false} index
  2462. * @returns {number | false}
  2463. */
  2464. function skipTrailingComment(text, index) {
  2465. /* istanbul ignore next */
  2466. if (index === false) {
  2467. return false;
  2468. }
  2469. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  2470. return skipEverythingButNewLine(text, index);
  2471. }
  2472. return index;
  2473. } // This one doesn't use the above helper function because it wants to
  2474. // test \r\n in order and `skip` doesn't support ordering and we only
  2475. // want to skip one newline. It's simple to implement.
  2476. /**
  2477. * @param {string} text
  2478. * @param {number | false} index
  2479. * @param {SkipOptions=} opts
  2480. * @returns {number | false}
  2481. */
  2482. function skipNewline(text, index, opts) {
  2483. const backwards = opts && opts.backwards;
  2484. if (index === false) {
  2485. return false;
  2486. }
  2487. const atIndex = text.charAt(index);
  2488. if (backwards) {
  2489. // We already replace `\r\n` with `\n` before parsing
  2490. /* istanbul ignore next */
  2491. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  2492. return index - 2;
  2493. }
  2494. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  2495. return index - 1;
  2496. }
  2497. } else {
  2498. // We already replace `\r\n` with `\n` before parsing
  2499. /* istanbul ignore next */
  2500. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  2501. return index + 2;
  2502. }
  2503. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  2504. return index + 1;
  2505. }
  2506. }
  2507. return index;
  2508. }
  2509. /**
  2510. * @param {string} text
  2511. * @param {number} index
  2512. * @param {SkipOptions=} opts
  2513. * @returns {boolean}
  2514. */
  2515. function hasNewline(text, index, opts = {}) {
  2516. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  2517. const idx2 = skipNewline(text, idx, opts);
  2518. return idx !== idx2;
  2519. }
  2520. /**
  2521. * @param {string} text
  2522. * @param {number} start
  2523. * @param {number} end
  2524. * @returns {boolean}
  2525. */
  2526. function hasNewlineInRange(text, start, end) {
  2527. for (let i = start; i < end; ++i) {
  2528. if (text.charAt(i) === "\n") {
  2529. return true;
  2530. }
  2531. }
  2532. return false;
  2533. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  2534. /**
  2535. * @template N
  2536. * @param {string} text
  2537. * @param {N} node
  2538. * @param {(node: N) => number} locStart
  2539. */
  2540. function isPreviousLineEmpty(text, node, locStart) {
  2541. /** @type {number | false} */
  2542. let idx = locStart(node) - 1;
  2543. idx = skipSpaces(text, idx, {
  2544. backwards: true
  2545. });
  2546. idx = skipNewline(text, idx, {
  2547. backwards: true
  2548. });
  2549. idx = skipSpaces(text, idx, {
  2550. backwards: true
  2551. });
  2552. const idx2 = skipNewline(text, idx, {
  2553. backwards: true
  2554. });
  2555. return idx !== idx2;
  2556. }
  2557. /**
  2558. * @param {string} text
  2559. * @param {number} index
  2560. * @returns {boolean}
  2561. */
  2562. function isNextLineEmptyAfterIndex(text, index) {
  2563. /** @type {number | false} */
  2564. let oldIdx = null;
  2565. /** @type {number | false} */
  2566. let idx = index;
  2567. while (idx !== oldIdx) {
  2568. // We need to skip all the potential trailing inline comments
  2569. oldIdx = idx;
  2570. idx = skipToLineEnd(text, idx);
  2571. idx = skipInlineComment(text, idx);
  2572. idx = skipSpaces(text, idx);
  2573. }
  2574. idx = skipTrailingComment(text, idx);
  2575. idx = skipNewline(text, idx);
  2576. return idx !== false && hasNewline(text, idx);
  2577. }
  2578. /**
  2579. * @template N
  2580. * @param {string} text
  2581. * @param {N} node
  2582. * @param {(node: N) => number} locEnd
  2583. * @returns {boolean}
  2584. */
  2585. function isNextLineEmpty(text, node, locEnd) {
  2586. return isNextLineEmptyAfterIndex(text, locEnd(node));
  2587. }
  2588. /**
  2589. * @param {string} text
  2590. * @param {number} idx
  2591. * @returns {number | false}
  2592. */
  2593. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  2594. /** @type {number | false} */
  2595. let oldIdx = null;
  2596. /** @type {number | false} */
  2597. let nextIdx = idx;
  2598. while (nextIdx !== oldIdx) {
  2599. oldIdx = nextIdx;
  2600. nextIdx = skipSpaces(text, nextIdx);
  2601. nextIdx = skipInlineComment(text, nextIdx);
  2602. nextIdx = skipTrailingComment(text, nextIdx);
  2603. nextIdx = skipNewline(text, nextIdx);
  2604. }
  2605. return nextIdx;
  2606. }
  2607. /**
  2608. * @template N
  2609. * @param {string} text
  2610. * @param {N} node
  2611. * @param {(node: N) => number} locEnd
  2612. * @returns {number | false}
  2613. */
  2614. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  2615. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  2616. }
  2617. /**
  2618. * @template N
  2619. * @param {string} text
  2620. * @param {N} node
  2621. * @param {(node: N) => number} locEnd
  2622. * @returns {string}
  2623. */
  2624. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  2625. return text.charAt( // @ts-expect-error => TBD: can return false, should we define a fallback?
  2626. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  2627. } // Not using, but it's public utils
  2628. /* istanbul ignore next */
  2629. /**
  2630. * @param {string} text
  2631. * @param {number} index
  2632. * @param {SkipOptions=} opts
  2633. * @returns {boolean}
  2634. */
  2635. function hasSpaces(text, index, opts = {}) {
  2636. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  2637. return idx !== index;
  2638. }
  2639. /**
  2640. * @param {string} value
  2641. * @param {number} tabWidth
  2642. * @param {number=} startIndex
  2643. * @returns {number}
  2644. */
  2645. function getAlignmentSize(value, tabWidth, startIndex = 0) {
  2646. let size = 0;
  2647. for (let i = startIndex; i < value.length; ++i) {
  2648. if (value[i] === "\t") {
  2649. // Tabs behave in a way that they are aligned to the nearest
  2650. // multiple of tabWidth:
  2651. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  2652. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  2653. size = size + tabWidth - size % tabWidth;
  2654. } else {
  2655. size++;
  2656. }
  2657. }
  2658. return size;
  2659. }
  2660. /**
  2661. * @param {string} value
  2662. * @param {number} tabWidth
  2663. * @returns {number}
  2664. */
  2665. function getIndentSize(value, tabWidth) {
  2666. const lastNewlineIndex = value.lastIndexOf("\n");
  2667. if (lastNewlineIndex === -1) {
  2668. return 0;
  2669. }
  2670. return getAlignmentSize( // All the leading whitespaces
  2671. value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0], tabWidth);
  2672. }
  2673. /**
  2674. * @typedef {'"' | "'"} Quote
  2675. */
  2676. /**
  2677. *
  2678. * @param {string} raw
  2679. * @param {Quote} preferredQuote
  2680. * @returns {Quote}
  2681. */
  2682. function getPreferredQuote(raw, preferredQuote) {
  2683. // `rawContent` is the string exactly like it appeared in the input source
  2684. // code, without its enclosing quotes.
  2685. const rawContent = raw.slice(1, -1);
  2686. /** @type {{ quote: '"', regex: RegExp }} */
  2687. const double = {
  2688. quote: '"',
  2689. regex: /"/g
  2690. };
  2691. /** @type {{ quote: "'", regex: RegExp }} */
  2692. const single = {
  2693. quote: "'",
  2694. regex: /'/g
  2695. };
  2696. const preferred = preferredQuote === "'" ? single : double;
  2697. const alternate = preferred === single ? double : single;
  2698. let result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  2699. // the string, we might want to enclose with the alternate quote instead, to
  2700. // minimize the number of escaped quotes.
  2701. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  2702. const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  2703. const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  2704. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  2705. }
  2706. return result;
  2707. }
  2708. function printString(raw, options) {
  2709. // `rawContent` is the string exactly like it appeared in the input source
  2710. // code, without its enclosing quotes.
  2711. const rawContent = raw.slice(1, -1);
  2712. /** @type {Quote} */
  2713. const enclosingQuote = options.parser === "json" || options.parser === "json5" && options.quoteProps === "preserve" && !options.singleQuote ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // It might sound unnecessary to use `makeString` even if the string already
  2714. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  2715. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  2716. // sure that we consistently output the minimum amount of escaped quotes.
  2717. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.__embeddedInHtml));
  2718. }
  2719. /**
  2720. * @param {string} rawContent
  2721. * @param {Quote} enclosingQuote
  2722. * @param {boolean=} unescapeUnnecessaryEscapes
  2723. * @returns {string}
  2724. */
  2725. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  2726. const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  2727. const regex = /\\(.)|(["'])/gs; // Escape and unescape single and double quotes as needed to be able to
  2728. // enclose `rawContent` with `enclosingQuote`.
  2729. const newContent = rawContent.replace(regex, (match, escaped, quote) => {
  2730. // If we matched an escape, and the escaped character is a quote of the
  2731. // other type than we intend to enclose the string with, there's no need for
  2732. // it to be escaped, so return it _without_ the backslash.
  2733. if (escaped === otherQuote) {
  2734. return escaped;
  2735. } // If we matched an unescaped quote and it is of the _same_ type as we
  2736. // intend to enclose the string with, it must be escaped, so return it with
  2737. // a backslash.
  2738. if (quote === enclosingQuote) {
  2739. return "\\" + quote;
  2740. }
  2741. if (quote) {
  2742. return quote;
  2743. } // Unescape any unnecessarily escaped character.
  2744. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  2745. return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
  2746. });
  2747. return enclosingQuote + newContent + enclosingQuote;
  2748. }
  2749. function printNumber(rawNumber) {
  2750. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  2751. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  2752. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  2753. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  2754. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  2755. .replace(/\.(?=e|$)/, "");
  2756. }
  2757. /**
  2758. * @param {string} str
  2759. * @param {string} target
  2760. * @returns {number}
  2761. */
  2762. function getMaxContinuousCount(str, target) {
  2763. const results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  2764. if (results === null) {
  2765. return 0;
  2766. }
  2767. return results.reduce((maxCount, result) => Math.max(maxCount, result.length / target.length), 0);
  2768. }
  2769. function getMinNotPresentContinuousCount(str, target) {
  2770. const matches = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  2771. if (matches === null) {
  2772. return 0;
  2773. }
  2774. const countPresent = new Map();
  2775. let max = 0;
  2776. for (const match of matches) {
  2777. const count = match.length / target.length;
  2778. countPresent.set(count, true);
  2779. if (count > max) {
  2780. max = count;
  2781. }
  2782. }
  2783. for (let i = 1; i < max; i++) {
  2784. if (!countPresent.get(i)) {
  2785. return i;
  2786. }
  2787. }
  2788. return max + 1;
  2789. }
  2790. /**
  2791. * @param {string} text
  2792. * @returns {number}
  2793. */
  2794. function getStringWidth$1(text) {
  2795. if (!text) {
  2796. return 0;
  2797. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  2798. if (!notAsciiRegex.test(text)) {
  2799. return text.length;
  2800. }
  2801. return stringWidth_1(text);
  2802. }
  2803. function addCommentHelper(node, comment) {
  2804. const comments = node.comments || (node.comments = []);
  2805. comments.push(comment);
  2806. comment.printed = false;
  2807. comment.nodeDescription = describeNodeForDebugging(node);
  2808. }
  2809. function addLeadingComment(node, comment) {
  2810. comment.leading = true;
  2811. comment.trailing = false;
  2812. addCommentHelper(node, comment);
  2813. }
  2814. function addDanglingComment(node, comment, marker) {
  2815. comment.leading = false;
  2816. comment.trailing = false;
  2817. if (marker) {
  2818. comment.marker = marker;
  2819. }
  2820. addCommentHelper(node, comment);
  2821. }
  2822. function addTrailingComment(node, comment) {
  2823. comment.leading = false;
  2824. comment.trailing = true;
  2825. addCommentHelper(node, comment);
  2826. }
  2827. function inferParserByLanguage(language, options) {
  2828. const {
  2829. languages
  2830. } = getSupportInfo({
  2831. plugins: options.plugins
  2832. });
  2833. const matched = languages.find(({
  2834. name
  2835. }) => name.toLowerCase() === language) || languages.find(({
  2836. aliases
  2837. }) => Array.isArray(aliases) && aliases.includes(language)) || languages.find(({
  2838. extensions
  2839. }) => Array.isArray(extensions) && extensions.includes(`.${language}`));
  2840. return matched && matched.parsers[0];
  2841. }
  2842. function isFrontMatterNode(node) {
  2843. return node && node.type === "front-matter";
  2844. }
  2845. function getShebang(text) {
  2846. if (!text.startsWith("#!")) {
  2847. return "";
  2848. }
  2849. const index = text.indexOf("\n");
  2850. if (index === -1) {
  2851. return text;
  2852. }
  2853. return text.slice(0, index);
  2854. }
  2855. /**
  2856. * @param {any} object
  2857. * @returns {object is Array<any>}
  2858. */
  2859. function isNonEmptyArray(object) {
  2860. return Array.isArray(object) && object.length > 0;
  2861. }
  2862. /**
  2863. * @param {string} description
  2864. * @returns {(node: any) => symbol}
  2865. */
  2866. function createGroupIdMapper(description) {
  2867. const groupIds = new WeakMap();
  2868. return function (node) {
  2869. if (!groupIds.has(node)) {
  2870. groupIds.set(node, Symbol(description));
  2871. }
  2872. return groupIds.get(node);
  2873. };
  2874. }
  2875. function describeNodeForDebugging(node) {
  2876. const nodeType = node.type || node.kind || "(unknown type)";
  2877. let nodeName = String(node.name || node.id && (typeof node.id === "object" ? node.id.name : node.id) || node.key && (typeof node.key === "object" ? node.key.name : node.key) || node.value && (typeof node.value === "object" ? "" : String(node.value)) || node.operator || "");
  2878. if (nodeName.length > 20) {
  2879. nodeName = nodeName.slice(0, 19) + "…";
  2880. }
  2881. return nodeType + (nodeName ? " " + nodeName : "");
  2882. }
  2883. var util = {
  2884. inferParserByLanguage,
  2885. getStringWidth: getStringWidth$1,
  2886. getMaxContinuousCount,
  2887. getMinNotPresentContinuousCount,
  2888. getPenultimate,
  2889. getLast: getLast_1,
  2890. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  2891. getNextNonSpaceNonCommentCharacterIndex,
  2892. getNextNonSpaceNonCommentCharacter,
  2893. skip,
  2894. skipWhitespace,
  2895. skipSpaces,
  2896. skipToLineEnd,
  2897. skipEverythingButNewLine,
  2898. skipInlineComment,
  2899. skipTrailingComment,
  2900. skipNewline,
  2901. isNextLineEmptyAfterIndex,
  2902. isNextLineEmpty,
  2903. isPreviousLineEmpty,
  2904. hasNewline,
  2905. hasNewlineInRange,
  2906. hasSpaces,
  2907. getAlignmentSize,
  2908. getIndentSize,
  2909. getPreferredQuote,
  2910. printString,
  2911. printNumber,
  2912. makeString,
  2913. addLeadingComment,
  2914. addDanglingComment,
  2915. addTrailingComment,
  2916. isFrontMatterNode,
  2917. getShebang,
  2918. isNonEmptyArray,
  2919. createGroupIdMapper
  2920. };
  2921. function guessEndOfLine(text) {
  2922. const index = text.indexOf("\r");
  2923. if (index >= 0) {
  2924. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  2925. }
  2926. return "lf";
  2927. }
  2928. function convertEndOfLineToChars$1(value) {
  2929. switch (value) {
  2930. case "cr":
  2931. return "\r";
  2932. case "crlf":
  2933. return "\r\n";
  2934. default:
  2935. return "\n";
  2936. }
  2937. }
  2938. function countEndOfLineChars(text, eol) {
  2939. let regex;
  2940. /* istanbul ignore else */
  2941. if (eol === "\n") {
  2942. regex = /\n/g;
  2943. } else if (eol === "\r") {
  2944. regex = /\r/g;
  2945. } else if (eol === "\r\n") {
  2946. regex = /\r\n/g;
  2947. } else {
  2948. throw new Error(`Unexpected "eol" ${JSON.stringify(eol)}.`);
  2949. }
  2950. const endOfLines = text.match(regex);
  2951. return endOfLines ? endOfLines.length : 0;
  2952. }
  2953. function normalizeEndOfLine(text) {
  2954. return text.replace(/\r\n?/g, "\n");
  2955. }
  2956. var endOfLine = {
  2957. guessEndOfLine,
  2958. convertEndOfLineToChars: convertEndOfLineToChars$1,
  2959. countEndOfLineChars,
  2960. normalizeEndOfLine
  2961. };
  2962. const {
  2963. literalline,
  2964. join
  2965. } = docBuilders;
  2966. const isConcat$2 = doc => Array.isArray(doc) || doc && doc.type === "concat";
  2967. const getDocParts$2 = doc => {
  2968. if (Array.isArray(doc)) {
  2969. return doc;
  2970. }
  2971. /* istanbul ignore next */
  2972. if (doc.type !== "concat" && doc.type !== "fill") {
  2973. throw new Error("Expect doc type to be `concat` or `fill`.");
  2974. }
  2975. return doc.parts;
  2976. }; // Using a unique object to compare by reference.
  2977. const traverseDocOnExitStackMarker = {};
  2978. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  2979. const docsStack = [doc];
  2980. while (docsStack.length > 0) {
  2981. const doc = docsStack.pop();
  2982. if (doc === traverseDocOnExitStackMarker) {
  2983. onExit(docsStack.pop());
  2984. continue;
  2985. }
  2986. if (onExit) {
  2987. docsStack.push(doc, traverseDocOnExitStackMarker);
  2988. }
  2989. if ( // Should Recurse
  2990. !onEnter || onEnter(doc) !== false) {
  2991. // When there are multiple parts to process,
  2992. // the parts need to be pushed onto the stack in reverse order,
  2993. // so that they are processed in the original order
  2994. // when the stack is popped.
  2995. if (isConcat$2(doc) || doc.type === "fill") {
  2996. const parts = getDocParts$2(doc);
  2997. for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
  2998. docsStack.push(parts[i]);
  2999. }
  3000. } else if (doc.type === "if-break") {
  3001. if (doc.flatContents) {
  3002. docsStack.push(doc.flatContents);
  3003. }
  3004. if (doc.breakContents) {
  3005. docsStack.push(doc.breakContents);
  3006. }
  3007. } else if (doc.type === "group" && doc.expandedStates) {
  3008. if (shouldTraverseConditionalGroups) {
  3009. for (let ic = doc.expandedStates.length, i = ic - 1; i >= 0; --i) {
  3010. docsStack.push(doc.expandedStates[i]);
  3011. }
  3012. } else {
  3013. docsStack.push(doc.contents);
  3014. }
  3015. } else if (doc.contents) {
  3016. docsStack.push(doc.contents);
  3017. }
  3018. }
  3019. }
  3020. }
  3021. function mapDoc(doc, cb) {
  3022. // Within a doc tree, the same subtrees can be found multiple times.
  3023. // E.g., often this happens in conditional groups.
  3024. // As an optimization (those subtrees can be huge) and to maintain the
  3025. // reference structure of the tree, the mapping results are cached in
  3026. // a map and reused.
  3027. const mapped = new Map();
  3028. return rec(doc);
  3029. function rec(doc) {
  3030. if (mapped.has(doc)) {
  3031. return mapped.get(doc);
  3032. }
  3033. const result = process(doc);
  3034. mapped.set(doc, result);
  3035. return result;
  3036. }
  3037. function process(doc) {
  3038. if (Array.isArray(doc)) {
  3039. return cb(doc.map(rec));
  3040. }
  3041. if (doc.type === "concat" || doc.type === "fill") {
  3042. const parts = doc.parts.map(rec);
  3043. return cb(Object.assign(Object.assign({}, doc), {}, {
  3044. parts
  3045. }));
  3046. }
  3047. if (doc.type === "if-break") {
  3048. const breakContents = doc.breakContents && rec(doc.breakContents);
  3049. const flatContents = doc.flatContents && rec(doc.flatContents);
  3050. return cb(Object.assign(Object.assign({}, doc), {}, {
  3051. breakContents,
  3052. flatContents
  3053. }));
  3054. }
  3055. if (doc.type === "group" && doc.expandedStates) {
  3056. const expandedStates = doc.expandedStates.map(rec);
  3057. const contents = expandedStates[0];
  3058. return cb(Object.assign(Object.assign({}, doc), {}, {
  3059. contents,
  3060. expandedStates
  3061. }));
  3062. }
  3063. if (doc.contents) {
  3064. const contents = rec(doc.contents);
  3065. return cb(Object.assign(Object.assign({}, doc), {}, {
  3066. contents
  3067. }));
  3068. }
  3069. return cb(doc);
  3070. }
  3071. }
  3072. function findInDoc(doc, fn, defaultValue) {
  3073. let result = defaultValue;
  3074. let hasStopped = false;
  3075. function findInDocOnEnterFn(doc) {
  3076. const maybeResult = fn(doc);
  3077. if (maybeResult !== undefined) {
  3078. hasStopped = true;
  3079. result = maybeResult;
  3080. }
  3081. if (hasStopped) {
  3082. return false;
  3083. }
  3084. }
  3085. traverseDoc(doc, findInDocOnEnterFn);
  3086. return result;
  3087. }
  3088. function willBreakFn(doc) {
  3089. if (doc.type === "group" && doc.break) {
  3090. return true;
  3091. }
  3092. if (doc.type === "line" && doc.hard) {
  3093. return true;
  3094. }
  3095. if (doc.type === "break-parent") {
  3096. return true;
  3097. }
  3098. }
  3099. function willBreak(doc) {
  3100. return findInDoc(doc, willBreakFn, false);
  3101. }
  3102. function breakParentGroup(groupStack) {
  3103. if (groupStack.length > 0) {
  3104. const parentGroup = getLast_1(groupStack); // Breaks are not propagated through conditional groups because
  3105. // the user is expected to manually handle what breaks.
  3106. if (!parentGroup.expandedStates && !parentGroup.break) {
  3107. // An alternative truthy value allows to distinguish propagated group breaks
  3108. // and not to print them as `group(..., { break: true })` in `--debug-print-doc`.
  3109. parentGroup.break = "propagated";
  3110. }
  3111. }
  3112. return null;
  3113. }
  3114. function propagateBreaks(doc) {
  3115. const alreadyVisitedSet = new Set();
  3116. const groupStack = [];
  3117. function propagateBreaksOnEnterFn(doc) {
  3118. if (doc.type === "break-parent") {
  3119. breakParentGroup(groupStack);
  3120. }
  3121. if (doc.type === "group") {
  3122. groupStack.push(doc);
  3123. if (alreadyVisitedSet.has(doc)) {
  3124. return false;
  3125. }
  3126. alreadyVisitedSet.add(doc);
  3127. }
  3128. }
  3129. function propagateBreaksOnExitFn(doc) {
  3130. if (doc.type === "group") {
  3131. const group = groupStack.pop();
  3132. if (group.break) {
  3133. breakParentGroup(groupStack);
  3134. }
  3135. }
  3136. }
  3137. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  3138. /* shouldTraverseConditionalGroups */
  3139. true);
  3140. }
  3141. function removeLinesFn(doc) {
  3142. // Force this doc into flat mode by statically converting all
  3143. // lines into spaces (or soft lines into nothing). Hard lines
  3144. // should still output because there's too great of a chance
  3145. // of breaking existing assumptions otherwise.
  3146. if (doc.type === "line" && !doc.hard) {
  3147. return doc.soft ? "" : " ";
  3148. }
  3149. if (doc.type === "if-break") {
  3150. return doc.flatContents || "";
  3151. }
  3152. return doc;
  3153. }
  3154. function removeLines(doc) {
  3155. return mapDoc(doc, removeLinesFn);
  3156. }
  3157. const isHardline = (doc, nextDoc) => doc && doc.type === "line" && doc.hard && nextDoc && nextDoc.type === "break-parent";
  3158. function stripDocTrailingHardlineFromDoc(doc) {
  3159. if (!doc) {
  3160. return doc;
  3161. }
  3162. if (isConcat$2(doc) || doc.type === "fill") {
  3163. const parts = getDocParts$2(doc);
  3164. while (parts.length > 1 && isHardline(...parts.slice(-2))) {
  3165. parts.length -= 2;
  3166. }
  3167. if (parts.length > 0) {
  3168. const lastPart = stripDocTrailingHardlineFromDoc(getLast_1(parts));
  3169. parts[parts.length - 1] = lastPart;
  3170. }
  3171. return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
  3172. parts
  3173. });
  3174. }
  3175. switch (doc.type) {
  3176. case "align":
  3177. case "indent":
  3178. case "indent-if-break":
  3179. case "group":
  3180. case "line-suffix":
  3181. case "label":
  3182. {
  3183. const contents = stripDocTrailingHardlineFromDoc(doc.contents);
  3184. return Object.assign(Object.assign({}, doc), {}, {
  3185. contents
  3186. });
  3187. }
  3188. case "if-break":
  3189. {
  3190. const breakContents = stripDocTrailingHardlineFromDoc(doc.breakContents);
  3191. const flatContents = stripDocTrailingHardlineFromDoc(doc.flatContents);
  3192. return Object.assign(Object.assign({}, doc), {}, {
  3193. breakContents,
  3194. flatContents
  3195. });
  3196. }
  3197. }
  3198. return doc;
  3199. }
  3200. function stripTrailingHardline(doc) {
  3201. // HACK remove ending hardline, original PR: #1984
  3202. return stripDocTrailingHardlineFromDoc(cleanDoc(doc));
  3203. }
  3204. function cleanDocFn(doc) {
  3205. switch (doc.type) {
  3206. case "fill":
  3207. if (doc.parts.length === 0 || doc.parts.every(part => part === "")) {
  3208. return "";
  3209. }
  3210. break;
  3211. case "group":
  3212. if (!doc.contents && !doc.id && !doc.break && !doc.expandedStates) {
  3213. return "";
  3214. } // Remove nested only group
  3215. if (doc.contents.type === "group" && doc.contents.id === doc.id && doc.contents.break === doc.break && doc.contents.expandedStates === doc.expandedStates) {
  3216. return doc.contents;
  3217. }
  3218. break;
  3219. case "align":
  3220. case "indent":
  3221. case "indent-if-break":
  3222. case "line-suffix":
  3223. if (!doc.contents) {
  3224. return "";
  3225. }
  3226. break;
  3227. case "if-break":
  3228. if (!doc.flatContents && !doc.breakContents) {
  3229. return "";
  3230. }
  3231. break;
  3232. }
  3233. if (!isConcat$2(doc)) {
  3234. return doc;
  3235. }
  3236. const parts = [];
  3237. for (const part of getDocParts$2(doc)) {
  3238. if (!part) {
  3239. continue;
  3240. }
  3241. const [currentPart, ...restParts] = isConcat$2(part) ? getDocParts$2(part) : [part];
  3242. if (typeof currentPart === "string" && typeof getLast_1(parts) === "string") {
  3243. parts[parts.length - 1] += currentPart;
  3244. } else {
  3245. parts.push(currentPart);
  3246. }
  3247. parts.push(...restParts);
  3248. }
  3249. if (parts.length === 0) {
  3250. return "";
  3251. }
  3252. if (parts.length === 1) {
  3253. return parts[0];
  3254. }
  3255. return Array.isArray(doc) ? parts : Object.assign(Object.assign({}, doc), {}, {
  3256. parts
  3257. });
  3258. } // A safer version of `normalizeDoc`
  3259. // - `normalizeDoc` concat strings and flat "concat" in `fill`, while `cleanDoc` don't
  3260. // - On `concat` object, `normalizeDoc` always return object with `parts`, `cleanDoc` may return strings
  3261. // - `cleanDoc` also remove nested `group`s and empty `fill`/`align`/`indent`/`line-suffix`/`if-break` if possible
  3262. function cleanDoc(doc) {
  3263. return mapDoc(doc, currentDoc => cleanDocFn(currentDoc));
  3264. }
  3265. function normalizeParts(parts) {
  3266. const newParts = [];
  3267. const restParts = parts.filter(Boolean);
  3268. while (restParts.length > 0) {
  3269. const part = restParts.shift();
  3270. if (!part) {
  3271. continue;
  3272. }
  3273. if (isConcat$2(part)) {
  3274. restParts.unshift(...getDocParts$2(part));
  3275. continue;
  3276. }
  3277. if (newParts.length > 0 && typeof getLast_1(newParts) === "string" && typeof part === "string") {
  3278. newParts[newParts.length - 1] += part;
  3279. continue;
  3280. }
  3281. newParts.push(part);
  3282. }
  3283. return newParts;
  3284. }
  3285. function normalizeDoc(doc) {
  3286. return mapDoc(doc, currentDoc => {
  3287. if (Array.isArray(currentDoc)) {
  3288. return normalizeParts(currentDoc);
  3289. }
  3290. if (!currentDoc.parts) {
  3291. return currentDoc;
  3292. }
  3293. return Object.assign(Object.assign({}, currentDoc), {}, {
  3294. parts: normalizeParts(currentDoc.parts)
  3295. });
  3296. });
  3297. }
  3298. function replaceEndOfLine(doc) {
  3299. return mapDoc(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? replaceTextEndOfLine(currentDoc) : currentDoc);
  3300. } // This function need return array
  3301. // TODO: remove `.parts` when we remove `docBuilders.concat()`
  3302. function replaceTextEndOfLine(text, replacement = literalline) {
  3303. return join(replacement, text.split("\n")).parts;
  3304. }
  3305. var docUtils = {
  3306. isConcat: isConcat$2,
  3307. getDocParts: getDocParts$2,
  3308. willBreak,
  3309. traverseDoc,
  3310. findInDoc,
  3311. mapDoc,
  3312. propagateBreaks,
  3313. removeLines,
  3314. stripTrailingHardline,
  3315. normalizeParts,
  3316. normalizeDoc,
  3317. cleanDoc,
  3318. replaceTextEndOfLine,
  3319. replaceEndOfLine
  3320. };
  3321. const {
  3322. getStringWidth,
  3323. getLast
  3324. } = util;
  3325. const {
  3326. convertEndOfLineToChars
  3327. } = endOfLine;
  3328. const {
  3329. fill,
  3330. cursor,
  3331. indent
  3332. } = docBuilders;
  3333. const {
  3334. isConcat: isConcat$1,
  3335. getDocParts: getDocParts$1
  3336. } = docUtils;
  3337. /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
  3338. let groupModeMap;
  3339. const MODE_BREAK = 1;
  3340. const MODE_FLAT = 2;
  3341. function rootIndent() {
  3342. return {
  3343. value: "",
  3344. length: 0,
  3345. queue: []
  3346. };
  3347. }
  3348. function makeIndent(ind, options) {
  3349. return generateInd(ind, {
  3350. type: "indent"
  3351. }, options);
  3352. }
  3353. function makeAlign(indent, widthOrDoc, options) {
  3354. if (widthOrDoc === Number.NEGATIVE_INFINITY) {
  3355. return indent.root || rootIndent();
  3356. }
  3357. if (widthOrDoc < 0) {
  3358. return generateInd(indent, {
  3359. type: "dedent"
  3360. }, options);
  3361. }
  3362. if (!widthOrDoc) {
  3363. return indent;
  3364. }
  3365. if (widthOrDoc.type === "root") {
  3366. return Object.assign(Object.assign({}, indent), {}, {
  3367. root: indent
  3368. });
  3369. }
  3370. const alignType = typeof widthOrDoc === "string" ? "stringAlign" : "numberAlign";
  3371. return generateInd(indent, {
  3372. type: alignType,
  3373. n: widthOrDoc
  3374. }, options);
  3375. }
  3376. function generateInd(ind, newPart, options) {
  3377. const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : [...ind.queue, newPart];
  3378. let value = "";
  3379. let length = 0;
  3380. let lastTabs = 0;
  3381. let lastSpaces = 0;
  3382. for (const part of queue) {
  3383. switch (part.type) {
  3384. case "indent":
  3385. flush();
  3386. if (options.useTabs) {
  3387. addTabs(1);
  3388. } else {
  3389. addSpaces(options.tabWidth);
  3390. }
  3391. break;
  3392. case "stringAlign":
  3393. flush();
  3394. value += part.n;
  3395. length += part.n.length;
  3396. break;
  3397. case "numberAlign":
  3398. lastTabs += 1;
  3399. lastSpaces += part.n;
  3400. break;
  3401. /* istanbul ignore next */
  3402. default:
  3403. throw new Error(`Unexpected type '${part.type}'`);
  3404. }
  3405. }
  3406. flushSpaces();
  3407. return Object.assign(Object.assign({}, ind), {}, {
  3408. value,
  3409. length,
  3410. queue
  3411. });
  3412. function addTabs(count) {
  3413. value += "\t".repeat(count);
  3414. length += options.tabWidth * count;
  3415. }
  3416. function addSpaces(count) {
  3417. value += " ".repeat(count);
  3418. length += count;
  3419. }
  3420. function flush() {
  3421. if (options.useTabs) {
  3422. flushTabs();
  3423. } else {
  3424. flushSpaces();
  3425. }
  3426. }
  3427. function flushTabs() {
  3428. if (lastTabs > 0) {
  3429. addTabs(lastTabs);
  3430. }
  3431. resetLast();
  3432. }
  3433. function flushSpaces() {
  3434. if (lastSpaces > 0) {
  3435. addSpaces(lastSpaces);
  3436. }
  3437. resetLast();
  3438. }
  3439. function resetLast() {
  3440. lastTabs = 0;
  3441. lastSpaces = 0;
  3442. }
  3443. }
  3444. function trim(out) {
  3445. if (out.length === 0) {
  3446. return 0;
  3447. }
  3448. let trimCount = 0; // Trim whitespace at the end of line
  3449. while (out.length > 0 && typeof getLast(out) === "string" && /^[\t ]*$/.test(getLast(out))) {
  3450. trimCount += out.pop().length;
  3451. }
  3452. if (out.length > 0 && typeof getLast(out) === "string") {
  3453. const trimmed = getLast(out).replace(/[\t ]*$/, "");
  3454. trimCount += getLast(out).length - trimmed.length;
  3455. out[out.length - 1] = trimmed;
  3456. }
  3457. return trimCount;
  3458. }
  3459. function fits(next, restCommands, width, options, hasLineSuffix, mustBeFlat) {
  3460. let restIdx = restCommands.length;
  3461. const cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  3462. // backwards for space characters.
  3463. const out = [];
  3464. while (width >= 0) {
  3465. if (cmds.length === 0) {
  3466. if (restIdx === 0) {
  3467. return true;
  3468. }
  3469. cmds.push(restCommands[restIdx - 1]);
  3470. restIdx--;
  3471. continue;
  3472. }
  3473. const [ind, mode, doc] = cmds.pop();
  3474. if (typeof doc === "string") {
  3475. out.push(doc);
  3476. width -= getStringWidth(doc);
  3477. } else if (isConcat$1(doc)) {
  3478. const parts = getDocParts$1(doc);
  3479. for (let i = parts.length - 1; i >= 0; i--) {
  3480. cmds.push([ind, mode, parts[i]]);
  3481. }
  3482. } else {
  3483. switch (doc.type) {
  3484. case "indent":
  3485. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  3486. break;
  3487. case "align":
  3488. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  3489. break;
  3490. case "trim":
  3491. width += trim(out);
  3492. break;
  3493. case "group":
  3494. {
  3495. if (mustBeFlat && doc.break) {
  3496. return false;
  3497. }
  3498. const groupMode = doc.break ? MODE_BREAK : mode;
  3499. cmds.push([ind, groupMode, // The most expanded state takes up the least space on the current line.
  3500. doc.expandedStates && groupMode === MODE_BREAK ? getLast(doc.expandedStates) : doc.contents]);
  3501. if (doc.id) {
  3502. groupModeMap[doc.id] = groupMode;
  3503. }
  3504. break;
  3505. }
  3506. case "fill":
  3507. for (let i = doc.parts.length - 1; i >= 0; i--) {
  3508. cmds.push([ind, mode, doc.parts[i]]);
  3509. }
  3510. break;
  3511. case "if-break":
  3512. case "indent-if-break":
  3513. {
  3514. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  3515. if (groupMode === MODE_BREAK) {
  3516. const breakContents = doc.type === "if-break" ? doc.breakContents : doc.negate ? doc.contents : indent(doc.contents);
  3517. if (breakContents) {
  3518. cmds.push([ind, mode, breakContents]);
  3519. }
  3520. }
  3521. if (groupMode === MODE_FLAT) {
  3522. const flatContents = doc.type === "if-break" ? doc.flatContents : doc.negate ? indent(doc.contents) : doc.contents;
  3523. if (flatContents) {
  3524. cmds.push([ind, mode, flatContents]);
  3525. }
  3526. }
  3527. break;
  3528. }
  3529. case "line":
  3530. switch (mode) {
  3531. // fallthrough
  3532. case MODE_FLAT:
  3533. if (!doc.hard) {
  3534. if (!doc.soft) {
  3535. out.push(" ");
  3536. width -= 1;
  3537. }
  3538. break;
  3539. }
  3540. return true;
  3541. case MODE_BREAK:
  3542. return true;
  3543. }
  3544. break;
  3545. case "line-suffix":
  3546. hasLineSuffix = true;
  3547. break;
  3548. case "line-suffix-boundary":
  3549. if (hasLineSuffix) {
  3550. return false;
  3551. }
  3552. break;
  3553. case "label":
  3554. cmds.push([ind, mode, doc.contents]);
  3555. break;
  3556. }
  3557. }
  3558. }
  3559. return false;
  3560. }
  3561. function printDocToString(doc, options) {
  3562. groupModeMap = {};
  3563. const width = options.printWidth;
  3564. const newLine = convertEndOfLineToChars(options.endOfLine);
  3565. let pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  3566. // while loop which is much faster. The while loop below adds new
  3567. // cmds to the array instead of recursively calling `print`.
  3568. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  3569. const out = [];
  3570. let shouldRemeasure = false;
  3571. let lineSuffix = [];
  3572. while (cmds.length > 0) {
  3573. const [ind, mode, doc] = cmds.pop();
  3574. if (typeof doc === "string") {
  3575. const formatted = newLine !== "\n" ? doc.replace(/\n/g, newLine) : doc;
  3576. out.push(formatted);
  3577. pos += getStringWidth(formatted);
  3578. } else if (isConcat$1(doc)) {
  3579. const parts = getDocParts$1(doc);
  3580. for (let i = parts.length - 1; i >= 0; i--) {
  3581. cmds.push([ind, mode, parts[i]]);
  3582. }
  3583. } else {
  3584. switch (doc.type) {
  3585. case "cursor":
  3586. out.push(cursor.placeholder);
  3587. break;
  3588. case "indent":
  3589. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  3590. break;
  3591. case "align":
  3592. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  3593. break;
  3594. case "trim":
  3595. pos -= trim(out);
  3596. break;
  3597. case "group":
  3598. switch (mode) {
  3599. case MODE_FLAT:
  3600. if (!shouldRemeasure) {
  3601. cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]);
  3602. break;
  3603. }
  3604. // fallthrough
  3605. case MODE_BREAK:
  3606. {
  3607. shouldRemeasure = false;
  3608. const next = [ind, MODE_FLAT, doc.contents];
  3609. const rem = width - pos;
  3610. const hasLineSuffix = lineSuffix.length > 0;
  3611. if (!doc.break && fits(next, cmds, rem, options, hasLineSuffix)) {
  3612. cmds.push(next);
  3613. } else {
  3614. // Expanded states are a rare case where a document
  3615. // can manually provide multiple representations of
  3616. // itself. It provides an array of documents
  3617. // going from the least expanded (most flattened)
  3618. // representation first to the most expanded. If a
  3619. // group has these, we need to manually go through
  3620. // these states and find the first one that fits.
  3621. if (doc.expandedStates) {
  3622. const mostExpanded = getLast(doc.expandedStates);
  3623. if (doc.break) {
  3624. cmds.push([ind, MODE_BREAK, mostExpanded]);
  3625. break;
  3626. } else {
  3627. for (let i = 1; i < doc.expandedStates.length + 1; i++) {
  3628. if (i >= doc.expandedStates.length) {
  3629. cmds.push([ind, MODE_BREAK, mostExpanded]);
  3630. break;
  3631. } else {
  3632. const state = doc.expandedStates[i];
  3633. const cmd = [ind, MODE_FLAT, state];
  3634. if (fits(cmd, cmds, rem, options, hasLineSuffix)) {
  3635. cmds.push(cmd);
  3636. break;
  3637. }
  3638. }
  3639. }
  3640. }
  3641. } else {
  3642. cmds.push([ind, MODE_BREAK, doc.contents]);
  3643. }
  3644. }
  3645. break;
  3646. }
  3647. }
  3648. if (doc.id) {
  3649. groupModeMap[doc.id] = getLast(cmds)[1];
  3650. }
  3651. break;
  3652. // Fills each line with as much code as possible before moving to a new
  3653. // line with the same indentation.
  3654. //
  3655. // Expects doc.parts to be an array of alternating content and
  3656. // whitespace. The whitespace contains the linebreaks.
  3657. //
  3658. // For example:
  3659. // ["I", line, "love", line, "monkeys"]
  3660. // or
  3661. // [{ type: group, ... }, softline, { type: group, ... }]
  3662. //
  3663. // It uses this parts structure to handle three main layout cases:
  3664. // * The first two content items fit on the same line without
  3665. // breaking
  3666. // -> output the first content item and the whitespace "flat".
  3667. // * Only the first content item fits on the line without breaking
  3668. // -> output the first content item "flat" and the whitespace with
  3669. // "break".
  3670. // * Neither content item fits on the line without breaking
  3671. // -> output the first content item and the whitespace with "break".
  3672. case "fill":
  3673. {
  3674. const rem = width - pos;
  3675. const {
  3676. parts
  3677. } = doc;
  3678. if (parts.length === 0) {
  3679. break;
  3680. }
  3681. const [content, whitespace] = parts;
  3682. const contentFlatCmd = [ind, MODE_FLAT, content];
  3683. const contentBreakCmd = [ind, MODE_BREAK, content];
  3684. const contentFits = fits(contentFlatCmd, [], rem, options, lineSuffix.length > 0, true);
  3685. if (parts.length === 1) {
  3686. if (contentFits) {
  3687. cmds.push(contentFlatCmd);
  3688. } else {
  3689. cmds.push(contentBreakCmd);
  3690. }
  3691. break;
  3692. }
  3693. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  3694. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  3695. if (parts.length === 2) {
  3696. if (contentFits) {
  3697. cmds.push(whitespaceFlatCmd, contentFlatCmd);
  3698. } else {
  3699. cmds.push(whitespaceBreakCmd, contentBreakCmd);
  3700. }
  3701. break;
  3702. } // At this point we've handled the first pair (context, separator)
  3703. // and will create a new fill doc for the rest of the content.
  3704. // Ideally we wouldn't mutate the array here but copying all the
  3705. // elements to a new array would make this algorithm quadratic,
  3706. // which is unusable for large arrays (e.g. large texts in JSX).
  3707. parts.splice(0, 2);
  3708. const remainingCmd = [ind, mode, fill(parts)];
  3709. const secondContent = parts[0];
  3710. const firstAndSecondContentFlatCmd = [ind, MODE_FLAT, [content, whitespace, secondContent]];
  3711. const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, options, lineSuffix.length > 0, true);
  3712. if (firstAndSecondContentFits) {
  3713. cmds.push(remainingCmd, whitespaceFlatCmd, contentFlatCmd);
  3714. } else if (contentFits) {
  3715. cmds.push(remainingCmd, whitespaceBreakCmd, contentFlatCmd);
  3716. } else {
  3717. cmds.push(remainingCmd, whitespaceBreakCmd, contentBreakCmd);
  3718. }
  3719. break;
  3720. }
  3721. case "if-break":
  3722. case "indent-if-break":
  3723. {
  3724. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  3725. if (groupMode === MODE_BREAK) {
  3726. const breakContents = doc.type === "if-break" ? doc.breakContents : doc.negate ? doc.contents : indent(doc.contents);
  3727. if (breakContents) {
  3728. cmds.push([ind, mode, breakContents]);
  3729. }
  3730. }
  3731. if (groupMode === MODE_FLAT) {
  3732. const flatContents = doc.type === "if-break" ? doc.flatContents : doc.negate ? indent(doc.contents) : doc.contents;
  3733. if (flatContents) {
  3734. cmds.push([ind, mode, flatContents]);
  3735. }
  3736. }
  3737. break;
  3738. }
  3739. case "line-suffix":
  3740. lineSuffix.push([ind, mode, doc.contents]);
  3741. break;
  3742. case "line-suffix-boundary":
  3743. if (lineSuffix.length > 0) {
  3744. cmds.push([ind, mode, {
  3745. type: "line",
  3746. hard: true
  3747. }]);
  3748. }
  3749. break;
  3750. case "line":
  3751. switch (mode) {
  3752. case MODE_FLAT:
  3753. if (!doc.hard) {
  3754. if (!doc.soft) {
  3755. out.push(" ");
  3756. pos += 1;
  3757. }
  3758. break;
  3759. } else {
  3760. // This line was forced into the output even if we
  3761. // were in flattened mode, so we need to tell the next
  3762. // group that no matter what, it needs to remeasure
  3763. // because the previous measurement didn't accurately
  3764. // capture the entire expression (this is necessary
  3765. // for nested groups)
  3766. shouldRemeasure = true;
  3767. }
  3768. // fallthrough
  3769. case MODE_BREAK:
  3770. if (lineSuffix.length > 0) {
  3771. cmds.push([ind, mode, doc], ...lineSuffix.reverse());
  3772. lineSuffix = [];
  3773. break;
  3774. }
  3775. if (doc.literal) {
  3776. if (ind.root) {
  3777. out.push(newLine, ind.root.value);
  3778. pos = ind.root.length;
  3779. } else {
  3780. out.push(newLine);
  3781. pos = 0;
  3782. }
  3783. } else {
  3784. pos -= trim(out);
  3785. out.push(newLine + ind.value);
  3786. pos = ind.length;
  3787. }
  3788. break;
  3789. }
  3790. break;
  3791. case "label":
  3792. cmds.push([ind, mode, doc.contents]);
  3793. break;
  3794. }
  3795. } // Flush remaining line-suffix contents at the end of the document, in case
  3796. // there is no new line after the line-suffix.
  3797. if (cmds.length === 0 && lineSuffix.length > 0) {
  3798. cmds.push(...lineSuffix.reverse());
  3799. lineSuffix = [];
  3800. }
  3801. }
  3802. const cursorPlaceholderIndex = out.indexOf(cursor.placeholder);
  3803. if (cursorPlaceholderIndex !== -1) {
  3804. const otherCursorPlaceholderIndex = out.indexOf(cursor.placeholder, cursorPlaceholderIndex + 1);
  3805. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  3806. const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  3807. const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  3808. return {
  3809. formatted: beforeCursor + aroundCursor + afterCursor,
  3810. cursorNodeStart: beforeCursor.length,
  3811. cursorNodeText: aroundCursor
  3812. };
  3813. }
  3814. return {
  3815. formatted: out.join("")
  3816. };
  3817. }
  3818. var docPrinter = {
  3819. printDocToString
  3820. };
  3821. const {
  3822. isConcat,
  3823. getDocParts
  3824. } = docUtils;
  3825. function flattenDoc(doc) {
  3826. if (!doc) {
  3827. return "";
  3828. }
  3829. if (isConcat(doc)) {
  3830. const res = [];
  3831. for (const part of getDocParts(doc)) {
  3832. if (isConcat(part)) {
  3833. res.push(...flattenDoc(part).parts);
  3834. } else {
  3835. const flattened = flattenDoc(part);
  3836. if (flattened !== "") {
  3837. res.push(flattened);
  3838. }
  3839. }
  3840. }
  3841. return {
  3842. type: "concat",
  3843. parts: res
  3844. };
  3845. }
  3846. if (doc.type === "if-break") {
  3847. return Object.assign(Object.assign({}, doc), {}, {
  3848. breakContents: flattenDoc(doc.breakContents),
  3849. flatContents: flattenDoc(doc.flatContents)
  3850. });
  3851. }
  3852. if (doc.type === "group") {
  3853. return Object.assign(Object.assign({}, doc), {}, {
  3854. contents: flattenDoc(doc.contents),
  3855. expandedStates: doc.expandedStates && doc.expandedStates.map(flattenDoc)
  3856. });
  3857. }
  3858. if (doc.type === "fill") {
  3859. return {
  3860. type: "fill",
  3861. parts: doc.parts.map(flattenDoc)
  3862. };
  3863. }
  3864. if (doc.contents) {
  3865. return Object.assign(Object.assign({}, doc), {}, {
  3866. contents: flattenDoc(doc.contents)
  3867. });
  3868. }
  3869. return doc;
  3870. }
  3871. function printDocToDebug(doc) {
  3872. /** @type Record<symbol, string> */
  3873. const printedSymbols = Object.create(null);
  3874. /** @type Set<string> */
  3875. const usedKeysForSymbols = new Set();
  3876. return printDoc(flattenDoc(doc));
  3877. function printDoc(doc, index, parentParts) {
  3878. if (typeof doc === "string") {
  3879. return JSON.stringify(doc);
  3880. }
  3881. if (isConcat(doc)) {
  3882. const printed = getDocParts(doc).map(printDoc).filter(Boolean);
  3883. return printed.length === 1 ? printed[0] : `[${printed.join(", ")}]`;
  3884. }
  3885. if (doc.type === "line") {
  3886. const withBreakParent = Array.isArray(parentParts) && parentParts[index + 1] && parentParts[index + 1].type === "break-parent";
  3887. if (doc.literal) {
  3888. return withBreakParent ? "literalline" : "literallineWithoutBreakParent";
  3889. }
  3890. if (doc.hard) {
  3891. return withBreakParent ? "hardline" : "hardlineWithoutBreakParent";
  3892. }
  3893. if (doc.soft) {
  3894. return "softline";
  3895. }
  3896. return "line";
  3897. }
  3898. if (doc.type === "break-parent") {
  3899. const afterHardline = Array.isArray(parentParts) && parentParts[index - 1] && parentParts[index - 1].type === "line" && parentParts[index - 1].hard;
  3900. return afterHardline ? undefined : "breakParent";
  3901. }
  3902. if (doc.type === "trim") {
  3903. return "trim";
  3904. }
  3905. if (doc.type === "indent") {
  3906. return "indent(" + printDoc(doc.contents) + ")";
  3907. }
  3908. if (doc.type === "align") {
  3909. return doc.n === Number.NEGATIVE_INFINITY ? "dedentToRoot(" + printDoc(doc.contents) + ")" : doc.n < 0 ? "dedent(" + printDoc(doc.contents) + ")" : doc.n.type === "root" ? "markAsRoot(" + printDoc(doc.contents) + ")" : "align(" + JSON.stringify(doc.n) + ", " + printDoc(doc.contents) + ")";
  3910. }
  3911. if (doc.type === "if-break") {
  3912. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + (doc.groupId ? (!doc.flatContents ? ', ""' : "") + `, { groupId: ${printGroupId(doc.groupId)} }` : "") + ")";
  3913. }
  3914. if (doc.type === "indent-if-break") {
  3915. const optionsParts = [];
  3916. if (doc.negate) {
  3917. optionsParts.push("negate: true");
  3918. }
  3919. if (doc.groupId) {
  3920. optionsParts.push(`groupId: ${printGroupId(doc.groupId)}`);
  3921. }
  3922. const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
  3923. return `indentIfBreak(${printDoc(doc.contents)}${options})`;
  3924. }
  3925. if (doc.type === "group") {
  3926. const optionsParts = [];
  3927. if (doc.break && doc.break !== "propagated") {
  3928. optionsParts.push("shouldBreak: true");
  3929. }
  3930. if (doc.id) {
  3931. optionsParts.push(`id: ${printGroupId(doc.id)}`);
  3932. }
  3933. const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
  3934. if (doc.expandedStates) {
  3935. return `conditionalGroup([${doc.expandedStates.map(part => printDoc(part)).join(",")}]${options})`;
  3936. }
  3937. return `group(${printDoc(doc.contents)}${options})`;
  3938. }
  3939. if (doc.type === "fill") {
  3940. return `fill([${doc.parts.map(part => printDoc(part)).join(", ")}])`;
  3941. }
  3942. if (doc.type === "line-suffix") {
  3943. return "lineSuffix(" + printDoc(doc.contents) + ")";
  3944. }
  3945. if (doc.type === "line-suffix-boundary") {
  3946. return "lineSuffixBoundary";
  3947. }
  3948. if (doc.type === "label") {
  3949. return `label(${JSON.stringify(doc.label)}, ${printDoc(doc.contents)})`;
  3950. }
  3951. throw new Error("Unknown doc type " + doc.type);
  3952. }
  3953. function printGroupId(id) {
  3954. if (typeof id !== "symbol") {
  3955. return JSON.stringify(String(id));
  3956. }
  3957. if (id in printedSymbols) {
  3958. return printedSymbols[id];
  3959. } // TODO: use Symbol.prototype.description instead of slice once Node 10 is dropped
  3960. const prefix = String(id).slice(7, -1) || "symbol";
  3961. for (let counter = 0;; counter++) {
  3962. const key = prefix + (counter > 0 ? ` #${counter}` : "");
  3963. if (!usedKeysForSymbols.has(key)) {
  3964. usedKeysForSymbols.add(key);
  3965. return printedSymbols[id] = `Symbol.for(${JSON.stringify(key)})`;
  3966. }
  3967. }
  3968. }
  3969. }
  3970. var docDebug = {
  3971. printDocToDebug
  3972. };
  3973. /**
  3974. * @typedef {import("./doc-builders").Doc} Doc
  3975. */
  3976. var document = {
  3977. builders: docBuilders,
  3978. printer: docPrinter,
  3979. utils: docUtils,
  3980. debug: docDebug
  3981. };
  3982. return document;
  3983. })));