doc.js 161 KB

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