index.js 966 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066
  1. var vu = Object.defineProperty;
  2. var Tu = (i, a, e) => a in i ? vu(i, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[a] = e;
  3. var A = (i, a, e) => Tu(i, typeof a != "symbol" ? a + "" : a, e);
  4. import { ObjectMatrix as Ce, CommandType as Ie, Tools as Xe, AbsoluteRefType as we, RANGE_TYPE as Ze, createIdentifier as lt, Disposable as Me, IUniverInstanceService as Js, LRUMap as Bu, hashAlgorithm as Iu, moveRangeByOffset as ea, isValidRange as Fu, isFormulaString as bt, isFormulaId as Lt, Rectangle as Ha, cellToRange as ku, Inject as Ve, UniverInstanceType as Dr, LocaleService as $u, LocaleType as Mr, numfmt as gt, BuildTextUtils as Yu, isRealNum as Q, CellValueType as yt, toDisposable as Hu, Injector as ki, sortRules as Gu, RTree as As, requestImmediateMacroTask as Qu, IConfigService as ta, ICommandService as br, BooleanNumber as Wu, DataStreamTreeTokenType as ve, Optional as qu, Plugin as Ku, merge as Xu, touchDependencies as ts } from "@univerjs/core";
  5. import { Subject as ur } from "rxjs";
  6. import { DataSyncPrimaryController as Zu } from "@univerjs/rpc";
  7. var er = /* @__PURE__ */ ((i) => (i.FALSE = "FALSE", i.TRUE = "TRUE", i))(er || {}), xt = /* @__PURE__ */ ((i) => (i[i.SUCCESS = 0] = "SUCCESS", i[i.ERROR = 1] = "ERROR", i))(xt || {}), it = /* @__PURE__ */ ((i) => (i[i.FRONT = 0] = "FRONT", i[i.BACK = 1] = "BACK", i))(it || {});
  8. function zu(i, a, e, t, r) {
  9. for (let n = 0, s = i.length; n < s; n++) {
  10. const o = i[n];
  11. if (a !== o.unitId || e !== o.sheetId)
  12. continue;
  13. const { startRow: u, startColumn: c, endRow: l, endColumn: f } = o.range;
  14. if (t >= u && t <= l && r >= c && r <= f)
  15. return !0;
  16. }
  17. return !1;
  18. }
  19. var m = /* @__PURE__ */ ((i) => (i.DIV_BY_ZERO = "#DIV/0!", i.NAME = "#NAME?", i.VALUE = "#VALUE!", i.NUM = "#NUM!", i.NA = "#N/A", i.CYCLE = "#CYCLE!", i.REF = "#REF!", i.SPILL = "#SPILL!", i.CALC = "#CALC!", i.ERROR = "#ERROR!", i.CONNECT = "#GETTING_DATA", i.NULL = "#NULL!", i))(m || {});
  20. const yr = new Set(Object.values(m)), Ga = [...new Set(Object.values(m).map((i) => i.length))];
  21. var Ju = /* @__PURE__ */ ((i) => (i[i.Financial = 0] = "Financial", i[i.Date = 1] = "Date", i[i.Math = 2] = "Math", i[i.Statistical = 3] = "Statistical", i[i.Lookup = 4] = "Lookup", i[i.Database = 5] = "Database", i[i.Text = 6] = "Text", i[i.Logical = 7] = "Logical", i[i.Information = 8] = "Information", i[i.Engineering = 9] = "Engineering", i[i.Cube = 10] = "Cube", i[i.Compatibility = 11] = "Compatibility", i[i.Web = 12] = "Web", i[i.Array = 13] = "Array", i[i.Univer = 14] = "Univer", i[i.User = 15] = "User", i[i.DefinedName = 16] = "DefinedName", i))(Ju || {}), X = /* @__PURE__ */ ((i) => (i.PLUS = "+", i.MINUS = "-", i.MULTIPLY = "*", i.DIVIDED = "/", i.CONCATENATE = "&", i.POWER = "^", i.EQUALS = "=", i.NOT_EQUAL = "<>", i.GREATER_THAN = ">", i.GREATER_THAN_OR_EQUAL = ">=", i.LESS_THAN = "<", i.LESS_THAN_OR_EQUAL = "<=", i))(X || {}), $ = /* @__PURE__ */ ((i) => (i.EQUALS = "=", i.NOT_EQUAL = "<>", i.GREATER_THAN = ">", i.GREATER_THAN_OR_EQUAL = ">=", i.LESS_THAN = "<", i.LESS_THAN_OR_EQUAL = "<=", i))($ || {});
  22. const Jr = /* @__PURE__ */ new Map([
  23. ["<>", 4],
  24. ["<", 4],
  25. [">=", 4],
  26. ["=", 4],
  27. [">", 4],
  28. ["<=", 4],
  29. ["&", 3],
  30. ["+", 2],
  31. ["-", 2],
  32. ["/", 1],
  33. ["*", 1],
  34. ["^", 0]
  35. ]), Dt = new Set(Jr.keys()), ec = /* @__PURE__ */ new Set([
  36. "=",
  37. "<>",
  38. ">",
  39. ">=",
  40. "<",
  41. "<="
  42. /* LESS_THAN_OR_EQUAL */
  43. ]);
  44. var K = /* @__PURE__ */ ((i) => (i.OPEN_BRACKET = "(", i.CLOSE_BRACKET = ")", i.COMMA = ",", i.SINGLE_QUOTATION = "'", i.DOUBLE_QUOTATION = '"', i.OPEN_BRACES = "{", i.CLOSE_BRACES = "}", i.COLON = ":", i.OPEN_SQUARE_BRACKET = "[", i.CLOSE_SQUARE_BRACKET = "]", i))(K || {}), ze = /* @__PURE__ */ ((i) => (i.PERCENTAGE = "%", i.POUND = "#", i))(ze || {});
  45. const rs = /* @__PURE__ */ new Set([
  46. "%",
  47. "#"
  48. /* POUND */
  49. ]);
  50. var Oe = /* @__PURE__ */ ((i) => (i.AT = "@", i.MINUS = "-", i.PLUS = "+", i))(Oe || {});
  51. const tc = " ", $i = [
  52. ...Object.values($),
  53. ...Object.values(X),
  54. ...Object.values(K),
  55. ...Object.values(ze),
  56. ...Object.values(Oe)
  57. ];
  58. function en(i) {
  59. return $i.includes(i);
  60. }
  61. function rc(i) {
  62. for (const a of $i)
  63. if (i.indexOf(a) > -1)
  64. return !0;
  65. return !1;
  66. }
  67. function Ib(i) {
  68. return i[0] === "'" && i[i.length - 1] === "'" ? i.substring(1, i.length - 1) : i;
  69. }
  70. function Fb(i) {
  71. return en(i) && i !== K.CLOSE_BRACES && i !== K.CLOSE_BRACKET && i !== K.SINGLE_QUOTATION && i !== K.DOUBLE_QUOTATION || i === " ";
  72. }
  73. const nc = /* @__PURE__ */ new Set([
  74. X.PLUS,
  75. X.MINUS,
  76. X.MULTIPLY,
  77. X.DIVIDED,
  78. X.CONCATENATE,
  79. X.POWER,
  80. X.EQUALS,
  81. X.NOT_EQUAL,
  82. X.GREATER_THAN,
  83. X.GREATER_THAN_OR_EQUAL,
  84. X.LESS_THAN,
  85. X.LESS_THAN_OR_EQUAL,
  86. K.OPEN_BRACKET,
  87. K.COMMA,
  88. K.COLON,
  89. K.OPEN_BRACES,
  90. K.OPEN_SQUARE_BRACKET
  91. ]);
  92. function sc(i) {
  93. return nc.has(i);
  94. }
  95. const ac = /* @__PURE__ */ new Set([
  96. X.PLUS,
  97. X.MINUS,
  98. X.MULTIPLY,
  99. X.DIVIDED,
  100. X.CONCATENATE,
  101. X.POWER,
  102. X.EQUALS,
  103. X.NOT_EQUAL,
  104. X.GREATER_THAN,
  105. X.GREATER_THAN_OR_EQUAL,
  106. X.LESS_THAN,
  107. X.LESS_THAN_OR_EQUAL,
  108. K.OPEN_BRACKET,
  109. K.COMMA,
  110. K.COLON,
  111. K.OPEN_BRACES,
  112. K.OPEN_SQUARE_BRACKET,
  113. ze.PERCENTAGE,
  114. ze.POUND
  115. ]);
  116. function ic(i) {
  117. return ac.has(i);
  118. }
  119. function oc(i) {
  120. const a = {};
  121. return Object.keys(i).forEach((e) => {
  122. const t = i[e];
  123. if (t == null)
  124. return !0;
  125. a[e] == null && (a[e] = {}), Object.keys(t).forEach((r) => {
  126. const n = t[r];
  127. a[e][r] = new Ce(n);
  128. });
  129. }), a;
  130. }
  131. function uc(i) {
  132. const a = {};
  133. for (const e in i) {
  134. const t = i[e];
  135. if (t != null) {
  136. a[e] == null && (a[e] = {});
  137. for (const r in t) {
  138. const n = t[r], s = {};
  139. n.forValue((o, u, c) => {
  140. s[o] === void 0 && (s[o] = {}), s[o][u] = c;
  141. }), a[e][r] = s;
  142. }
  143. }
  144. }
  145. return a;
  146. }
  147. const Yi = '\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]', Qa = new RegExp(Yi), cc = "((?![\\[\\]\\/?*\\\\]).)*!", Tt = "$", ra = "\\s*?:\\s*?", cn = "[A-Za-z]+", ln = "[1-9][0-9]*", Rr = `'?(${Yi})?(${cc})?'?`, Es = `\\${Tt}?${cn}\\${Tt}?${ln}`, lc = `^(${Oe.AT})?${Rr}${Es}${ra}${Es}$`, Wa = new RegExp(lc), fc = `^${Rr}\\s*?${Es}(${ze.POUND})?$`, qa = new RegExp(fc), hc = `^${Rr}\\${Tt}?${ln}${ra}\\${Tt}?${ln}$`, Ka = new RegExp(hc), mc = `^${Rr}\\${Tt}?${cn}${ra}\\${Tt}?${cn}$`, Xa = new RegExp(mc), gc = `^${Rr}\\s*?\\${Tt}?${ln}$`, Za = new RegExp(gc), dc = `^${Rr}\\s*?\\${Tt}?${cn}$`, za = new RegExp(dc), Cc = "{.*?}", Ja = new RegExp(Cc, "g");
  148. function vr(i) {
  149. return qa.lastIndex = 0, qa.test(i);
  150. }
  151. function _c(i) {
  152. return Wa.lastIndex = 0, Wa.test(i);
  153. }
  154. function Hi(i) {
  155. return Ka.lastIndex = 0, Ka.test(i);
  156. }
  157. function Gi(i) {
  158. return Xa.lastIndex = 0, Xa.test(i);
  159. }
  160. function Qi(i) {
  161. return Za.lastIndex = 0, Za.test(i);
  162. }
  163. function Wi(i) {
  164. return za.lastIndex = 0, za.test(i);
  165. }
  166. function Ac(i) {
  167. return Ja.lastIndex = 0, Ja.test(i);
  168. }
  169. function Ec(i) {
  170. return vr(i) || _c(i) || Hi(i) || Gi(i);
  171. }
  172. const bc = {
  173. id: "formula.mutation.register-function",
  174. type: Ie.MUTATION,
  175. handler: () => !0
  176. }, bs = {
  177. id: "formula.mutation.set-array-formula-data",
  178. type: Ie.MUTATION,
  179. handler: (i, a) => !0
  180. }, yc = /[^0-9]/g, Rc = /[^A-Za-z]/g;
  181. function tn(i) {
  182. let a = i[0] === "$";
  183. const e = i.substring(1);
  184. let t = e.indexOf("$") > -1;
  185. return Xe.isStringNumber(e) && a && !t && (a = !1, t = !0), a && t ? we.ALL : a ? we.COLUMN : t ? we.ROW : we.NONE;
  186. }
  187. function kb(i) {
  188. const a = i.split("!");
  189. a.length > 1 && (i = a[a.length - 1]);
  190. const e = i.split(":");
  191. return e.length > 1 ? {
  192. startAbsoluteRefType: tn(e[0]),
  193. endAbsoluteRefType: tn(e[1])
  194. } : { startAbsoluteRefType: tn(e[0]) };
  195. }
  196. function ei(i = we.NONE) {
  197. let a = "", e = "";
  198. return i === we.ROW ? a = "$" : i === we.COLUMN ? e = "$" : i === we.ALL && (a = "$", e = "$"), {
  199. rowAbsoluteString: a,
  200. columnAbsoluteString: e
  201. };
  202. }
  203. function fr(i) {
  204. const {
  205. startColumn: a,
  206. startRow: e,
  207. endColumn: t,
  208. endRow: r,
  209. startAbsoluteRefType: n,
  210. endAbsoluteRefType: s,
  211. rangeType: o = Ze.NORMAL
  212. } = i, u = ei(n), c = ei(s);
  213. if (o === Ze.ROW || o === Ze.ALL) {
  214. const h = `${u.rowAbsoluteString}${e + 1}`, d = `${c.rowAbsoluteString}${r + 1}`;
  215. return `${h}:${d}`;
  216. }
  217. if (o === Ze.COLUMN) {
  218. const h = `${u.columnAbsoluteString}${Xe.chatAtABC(a)}`, d = `${c.columnAbsoluteString}${Xe.chatAtABC(t)}`;
  219. return `${h}:${d}`;
  220. }
  221. const l = `${u.columnAbsoluteString}${Xe.chatAtABC(a)}${u.rowAbsoluteString}${e + 1}`, f = `${c.columnAbsoluteString}${Xe.chatAtABC(t)}${c.rowAbsoluteString}${r + 1}`;
  222. return l === f ? l : `${l}:${f}`;
  223. }
  224. function pc(i, a) {
  225. return `${Ki(i)}!${fr(a)}`;
  226. }
  227. function Vc(i, a, e) {
  228. return Rs(i) || Rs(a) ? `'[${ps(i)}]${ps(a)}'!${fr(e)}` : `[${i}]${a}!${fr(e)}`;
  229. }
  230. function ys(i) {
  231. const { unitId: a, sheetName: e, range: t } = i;
  232. return a != null && a.length > 0 && e != null && e.length > 0 ? Vc(a, e, t) : e != null && e.length > 0 ? pc(e, t) : fr(t);
  233. }
  234. function ns(i) {
  235. const a = Number.parseInt(i.replace(yc, "")) - 1, e = Xe.ABCatNum(i.replace(Rc, "")), t = tn(i);
  236. return {
  237. row: a,
  238. column: e,
  239. absoluteRefType: t
  240. };
  241. }
  242. function na(i) {
  243. const a = Qa.exec(i);
  244. let e = "";
  245. a != null && (e = a[0].trim(), e = ti(e.slice(1, e.length - 1)), i = i.replace(Qa, ""));
  246. const t = i.indexOf("!");
  247. let r = "", n = "";
  248. return t > -1 ? (r = i.substring(0, t), r[0] === "'" && r[r.length - 1] === "'" && (r = r.substring(1, r.length - 1)), r = ti(r), n = i.substring(t + 1)) : n = i, {
  249. refBody: n,
  250. sheetName: r,
  251. unitId: e
  252. };
  253. }
  254. function fn(i) {
  255. const { refBody: a, sheetName: e, unitId: t } = na(i), r = a.indexOf(":");
  256. if (r === -1) {
  257. const _ = ns(a), C = _.row, E = _.column, b = _.absoluteRefType;
  258. return {
  259. unitId: t,
  260. sheetName: e,
  261. range: {
  262. startRow: C,
  263. startColumn: E,
  264. endRow: C,
  265. endColumn: E,
  266. startAbsoluteRefType: b,
  267. endAbsoluteRefType: b
  268. }
  269. };
  270. }
  271. const n = a.substring(0, r), s = a.substring(r + 1), o = ns(n), u = ns(s), c = o.row > u.row ? u.row : o.row, l = o.column > u.column ? u.column : o.column, f = o.row > u.row ? o.row : u.row, h = o.column > u.column ? o.column : u.column;
  272. let d = Ze.NORMAL;
  273. return Number.isNaN(c) && Number.isNaN(f) ? d = Ze.COLUMN : Number.isNaN(l) && Number.isNaN(h) && (d = Ze.ROW), {
  274. unitId: t,
  275. sheetName: e,
  276. range: {
  277. startRow: c,
  278. startColumn: l,
  279. endRow: f,
  280. endColumn: h,
  281. startAbsoluteRefType: o.absoluteRefType,
  282. endAbsoluteRefType: u.absoluteRefType,
  283. rangeType: d
  284. }
  285. };
  286. }
  287. const Nc = ["LOG10"];
  288. function rn(i) {
  289. const a = qi(i);
  290. if (!Ec(a) || Nc.includes(a.toUpperCase().trim()))
  291. return !1;
  292. const { range: e } = fn(a);
  293. return !(e.endColumn >= 16384);
  294. }
  295. function qi(i) {
  296. const a = [];
  297. let e = !1;
  298. for (let t = 0, r = i.length; t < r; t++) {
  299. const n = i[t];
  300. if (n === tc && !e)
  301. a.push(n);
  302. else {
  303. if (!e && (n === Oe.AT || n === Oe.MINUS || n === Oe.PLUS))
  304. continue;
  305. a.push(n), e = !0;
  306. }
  307. }
  308. return a.join("");
  309. }
  310. function $b(i, a) {
  311. const e = (i == null ? void 0 : i.split(",")) || [];
  312. return i === "" || e.length === 0 ? [] : Oc(i) ? e.map((n) => {
  313. const s = fn(n);
  314. return {
  315. unitId: s.unitId,
  316. sheetId: a(s.sheetName),
  317. range: s.range,
  318. sheetName: s.sheetName
  319. };
  320. }) : [];
  321. }
  322. function Oc(i) {
  323. return ((i == null ? void 0 : i.split(",")) || []).every((e) => rn(e.trim()));
  324. }
  325. function Rs(i) {
  326. return i.length === 0 ? !1 : !!(rc(i) || Mc(i) || wc(i) || Dc(i) || /[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?()]/.test(i));
  327. }
  328. function Ki(i) {
  329. return Rs(i) ? `'${ps(i)}'` : i;
  330. }
  331. function ps(i) {
  332. return i.replace(/'/g, "''");
  333. }
  334. function ti(i) {
  335. return i.replace(/''/g, "'");
  336. }
  337. function Mc(i) {
  338. const a = i.match(/[1-9][0-9]{0,6}/);
  339. return /^[A-Z]+[1-9][0-9]{0,6}$/.test(i) && a !== null;
  340. }
  341. function wc(i) {
  342. return /^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(i);
  343. }
  344. function Dc(i) {
  345. return !new RegExp("^\\p{Letter}", "u").test(i.charAt(0));
  346. }
  347. var Sc = Object.defineProperty, Pc = Object.getOwnPropertyDescriptor, Lc = (i, a, e, t) => {
  348. for (var r = t > 1 ? void 0 : t ? Pc(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  349. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  350. return t && r && Sc(a, e, r), r;
  351. }, xc = (i, a) => (e, t) => a(e, t, i);
  352. let Vs = class extends Me {
  353. constructor(a) {
  354. super();
  355. // 18.2.6 definedNames (Defined Names)
  356. A(this, "_definedNameMap", {});
  357. A(this, "_update$", new ur());
  358. A(this, "update$", this._update$.asObservable());
  359. A(this, "_currentRange", {
  360. unitId: "",
  361. sheetId: "",
  362. range: {
  363. startRow: 0,
  364. endRow: 0,
  365. startColumn: 0,
  366. endColumn: 0
  367. }
  368. });
  369. A(this, "_currentRange$", new ur());
  370. A(this, "currentRange$", this._currentRange$.asObservable());
  371. A(this, "_focusRange$", new ur());
  372. A(this, "focusRange$", this._focusRange$.asObservable());
  373. this._univerInstanceService = a;
  374. }
  375. dispose() {
  376. this._definedNameMap = {};
  377. }
  378. getWorksheetByRef(a, e) {
  379. var r;
  380. const { sheetName: t } = na(e);
  381. return (r = this._univerInstanceService.getUnit(a)) == null ? void 0 : r.getSheetBySheetName(t);
  382. }
  383. focusRange(a, e) {
  384. const t = this.getValueById(a, e);
  385. t != null && this._focusRange$.next({ ...t, unitId: a });
  386. }
  387. setCurrentRange(a) {
  388. this._currentRange = a, this._currentRange$.next(a);
  389. }
  390. getCurrentRange() {
  391. return this._currentRange;
  392. }
  393. getCurrentRangeForString() {
  394. return fr(this._currentRange.range);
  395. }
  396. registerDefinedNames(a, e) {
  397. this._definedNameMap[a] = e, this._update();
  398. }
  399. registerDefinedName(a, e) {
  400. this._definedNameMap[a] == null && (this._definedNameMap[a] = {}), this._definedNameMap[a][e.id] = e, this._update();
  401. }
  402. removeDefinedName(a, e) {
  403. var t;
  404. (t = this._definedNameMap[a]) == null || delete t[e], this._update();
  405. }
  406. removeUnitDefinedName(a) {
  407. delete this._definedNameMap[a], this._update();
  408. }
  409. getDefinedNameMap(a) {
  410. return this._definedNameMap[a];
  411. }
  412. getValueByName(a, e) {
  413. var r;
  414. const t = this._definedNameMap[a];
  415. return t == null ? null : (r = Array.from(Object.values(t)).filter((n) => n.name === e)) == null ? void 0 : r[0];
  416. }
  417. getValueById(a, e) {
  418. var t;
  419. return (t = this._definedNameMap[a]) == null ? void 0 : t[e];
  420. }
  421. hasDefinedName(a) {
  422. return this._definedNameMap[a] == null ? !1 : (Array.from(Object.values(this._definedNameMap[a])).length || 0) !== 0;
  423. }
  424. _update() {
  425. this._update$.next(null);
  426. }
  427. };
  428. Vs = Lc([
  429. xc(0, Js)
  430. ], Vs);
  431. const pr = lt("univer.formula.defined-names.service"), Yb = (i, a) => {
  432. const { unitId: e, id: t } = a;
  433. return {
  434. ...i.get(pr).getValueById(e, t),
  435. unitId: e
  436. };
  437. }, sa = {
  438. id: "formula.mutation.set-defined-name",
  439. type: Ie.MUTATION,
  440. handler: (i, a) => {
  441. if (a == null)
  442. return !1;
  443. const e = i.get(pr), { id: t, unitId: r, name: n, formulaOrRefString: s, comment: o, hidden: u, localSheetId: c } = a;
  444. return e.registerDefinedName(r, {
  445. id: t,
  446. name: n.trim(),
  447. formulaOrRefString: s.trim(),
  448. comment: o == null ? void 0 : o.trim(),
  449. hidden: u,
  450. localSheetId: c
  451. }), !0;
  452. }
  453. }, Xi = {
  454. id: "formula.mutation.remove-defined-name",
  455. type: Ie.MUTATION,
  456. handler: (i, a) => {
  457. if (a == null)
  458. return !1;
  459. const e = i.get(pr), { unitId: t, id: r } = a;
  460. return e.removeDefinedName(t, r), !0;
  461. }
  462. }, aa = {
  463. id: "formula.mutation.set-feature-calculation",
  464. type: Ie.MUTATION,
  465. handler: () => !0
  466. }, ia = {
  467. id: "formula.mutation.remove-feature-calculation",
  468. type: Ie.MUTATION,
  469. handler: () => !0
  470. }, Zi = {
  471. id: "formula.mutation.set-formula-calculation-start",
  472. type: Ie.MUTATION,
  473. handler: () => !0
  474. }, zi = {
  475. id: "formula.mutation.set-formula-calculation-stop",
  476. type: Ie.MUTATION,
  477. handler: () => !0
  478. }, Ns = {
  479. id: "formula.mutation.set-formula-calculation-notification",
  480. type: Ie.MUTATION,
  481. handler: () => !0
  482. }, Ji = {
  483. id: "formula.mutation.set-formula-calculation-result",
  484. type: Ie.MUTATION,
  485. handler: () => !0
  486. }, eo = {
  487. id: "formula.mutation.set-formula-data",
  488. type: Ie.MUTATION,
  489. handler: (i, a) => !0
  490. }, oa = {
  491. id: "formula.mutation.set-other-formula",
  492. type: Ie.MUTATION,
  493. handler: () => !0
  494. }, ua = {
  495. id: "formula.mutation.remove-other-formula",
  496. type: Ie.MUTATION,
  497. handler: () => !0
  498. }, jc = {
  499. id: "formula.mutation.set-super-table",
  500. type: Ie.MUTATION,
  501. handler: () => !0
  502. }, Uc = {
  503. id: "formula.mutation.remove-super-table",
  504. type: Ie.MUTATION,
  505. handler: () => !0
  506. }, to = {
  507. id: "formula.mutation.set-super-table-option",
  508. type: Ie.MUTATION,
  509. handler: () => !0
  510. };
  511. class Vt {
  512. constructor(a) {
  513. A(this, "_cache");
  514. this._cache = new Bu(a);
  515. }
  516. set(a, e) {
  517. const t = this._hash(a);
  518. this._cache.set(t, e);
  519. }
  520. get(a) {
  521. const e = this._hash(a);
  522. return this._cache.get(e);
  523. }
  524. clear() {
  525. this._cache.clear();
  526. }
  527. _hash(a) {
  528. return a.length <= 64 ? a : Iu(a).toString();
  529. }
  530. }
  531. const ht = "P_1", Ut = "R_1", hr = "L_1", Tr = "LR_1", ro = "LO_1", vc = "LET", Sr = "LAMBDA", Tc = "CUBE", Bc = /* @__PURE__ */ new Set(["RAND", "RANDBETWEEN", "NOW", "TODAY"]), Os = new Vt(1e5);
  532. function mr(i) {
  533. const a = Os.get(i);
  534. if (a)
  535. return a;
  536. const e = fn(i);
  537. return Os.set(i, e), fn(i);
  538. }
  539. function Ic() {
  540. Os.clear();
  541. }
  542. var $e = /* @__PURE__ */ ((i) => (i[i.NORMAL = 0] = "NORMAL", i[i.NUMBER = 1] = "NUMBER", i[i.STRING = 2] = "STRING", i[i.FUNCTION = 3] = "FUNCTION", i[i.REFERENCE = 4] = "REFERENCE", i[i.ARRAY = 5] = "ARRAY", i[i.DEFINED_NAME = 6] = "DEFINED_NAME", i))($e || {});
  543. function ri(i) {
  544. let a = "";
  545. for (const e of i)
  546. typeof e == "string" ? a += e : a += e.token;
  547. return a;
  548. }
  549. class ae {
  550. constructor() {
  551. A(this, "_parent");
  552. A(this, "_token", Ut);
  553. A(this, "_children", []);
  554. A(this, "_lambdaId");
  555. A(this, "_functionDefinitionPrivacyVar");
  556. A(this, "_lambdaParameter", "");
  557. A(this, "_startIndex", -1);
  558. A(this, "_endIndex", -1);
  559. A(this, "_definedNames", []);
  560. }
  561. dispose() {
  562. var a;
  563. this._children.forEach((e) => {
  564. typeof e != "string" && e.dispose();
  565. }), (a = this._functionDefinitionPrivacyVar) == null || a.clear(), this._functionDefinitionPrivacyVar = null, this._children = [], this._parent = null, this._definedNames = [];
  566. }
  567. getDefinedNames() {
  568. return this._definedNames;
  569. }
  570. getStartIndex() {
  571. return this._startIndex;
  572. }
  573. getLambdaId() {
  574. return this._lambdaId;
  575. }
  576. setLambdaId(a) {
  577. this._lambdaId = a;
  578. }
  579. getFunctionDefinitionPrivacyVar() {
  580. return this._functionDefinitionPrivacyVar;
  581. }
  582. setLambdaPrivacyVar(a) {
  583. this._functionDefinitionPrivacyVar = a;
  584. }
  585. getLambdaParameter() {
  586. return this._lambdaParameter;
  587. }
  588. setLambdaParameter(a) {
  589. this._lambdaParameter = a;
  590. }
  591. getParent() {
  592. return this._parent;
  593. }
  594. setParent(a) {
  595. this._parent = a;
  596. }
  597. getChildren() {
  598. return this._children;
  599. }
  600. setChildren(a) {
  601. this._children = a;
  602. }
  603. addChildren(a) {
  604. this._children.push(a);
  605. }
  606. addChildrenFirst(a) {
  607. this._children.unshift(a);
  608. }
  609. getToken() {
  610. return this._token;
  611. }
  612. setToken(a) {
  613. this._token = a;
  614. }
  615. setIndex(a, e) {
  616. this._startIndex = a, this._endIndex = e;
  617. }
  618. setDefinedNames(a) {
  619. this._definedNames = a;
  620. }
  621. hasDefinedNames() {
  622. return this._definedNames.length > 0;
  623. }
  624. replaceChild(a, e) {
  625. const t = this._getIndexInParent(a);
  626. t != null && (this.getChildren().splice(t, 1, e), e.setParent(this));
  627. }
  628. changeToParent(a) {
  629. const e = this.getParent();
  630. e && e.removeChild(this), this.setParent(a), a.getChildren().push(this);
  631. }
  632. removeChild(a) {
  633. const e = this._getIndexInParent(a);
  634. e != null && this.getChildren().splice(e, 1);
  635. }
  636. serialize() {
  637. const a = this.getToken(), e = this.getChildren(), t = [], r = e.length;
  638. for (let n = 0; n < r; n++) {
  639. const s = e[n];
  640. s instanceof ae ? t.push(s.serialize()) : t.push(s);
  641. }
  642. return {
  643. token: a,
  644. st: this._startIndex,
  645. ed: this._endIndex,
  646. children: t
  647. };
  648. }
  649. _getIndexInParent(a) {
  650. const e = this.getChildren(), t = e.length;
  651. for (let r = 0; r < t; r++)
  652. if (e[r] === a)
  653. return r;
  654. }
  655. }
  656. const no = 2e3, ss = new Vt(no), as = new Vt(no);
  657. class ca extends Me {
  658. constructor() {
  659. super(...arguments);
  660. A(this, "_currentLexerNode", new ae());
  661. A(this, "_upLevel", 0);
  662. A(this, "_segment", "");
  663. A(this, "_bracketState", []);
  664. // ()
  665. A(this, "_squareBracketState", 0);
  666. A(this, "_bracesState", 0);
  667. // {}
  668. A(this, "_singleQuotationState", 0);
  669. // ''
  670. A(this, "_doubleQuotationState", 0);
  671. // ""
  672. A(this, "_lambdaState", !1);
  673. // Lambda
  674. A(this, "_colonState", !1);
  675. // :
  676. A(this, "_formulaErrorCount", 0);
  677. A(this, "_tableBracketState", !1);
  678. }
  679. // Table3[[#All],[Column1]:[Column2]]
  680. dispose() {
  681. this._resetTemp(), this._currentLexerNode.dispose(), ss.clear(), as.clear();
  682. }
  683. getUpLevel() {
  684. return this._upLevel;
  685. }
  686. isColonClose() {
  687. return this._colonState === !1;
  688. }
  689. isColonOpen() {
  690. return this._colonState === !0;
  691. }
  692. isDoubleQuotationClose() {
  693. return this._doubleQuotationState === 0;
  694. }
  695. isLambdaOpen() {
  696. return this._lambdaState === !0;
  697. }
  698. isLambdaClose() {
  699. return this._lambdaState === !1;
  700. }
  701. isSingleQuotationClose() {
  702. return this._singleQuotationState === 0;
  703. }
  704. isBracesClose() {
  705. return this._bracesState === 0;
  706. }
  707. isBracketClose() {
  708. return this._bracketState.length === 0;
  709. }
  710. isSquareBracketClose() {
  711. return this._squareBracketState === 0;
  712. }
  713. getCurrentLexerNode() {
  714. return this._currentLexerNode;
  715. }
  716. getFunctionAndParameter(e, t) {
  717. const r = this._getCurrentParamIndex(e, t);
  718. if (r == null || r === m.VALUE)
  719. return;
  720. const n = r[0];
  721. if (typeof n == "string")
  722. return;
  723. let s = n.getParent(), o = n;
  724. for (; s; ) {
  725. const u = s.getToken();
  726. if (u !== ht && !en(u) && s.getStartIndex() !== -1) {
  727. const c = s.getChildren().indexOf(o);
  728. return {
  729. functionName: u,
  730. paramIndex: c
  731. };
  732. }
  733. o = s, s = s.getParent();
  734. }
  735. }
  736. /**
  737. * Estimate the number of right brackets that need to be automatically added to the end of the formula.
  738. * @param formulaString
  739. */
  740. checkIfAddBracket(e) {
  741. let t = 0, r = e.length - 1, n = e[r];
  742. for (; (n === K.CLOSE_BRACKET || n === " ") && r >= 0; )
  743. n === K.CLOSE_BRACKET && t++, n = e[--r];
  744. const s = this._getCurrentParamIndex(e, e.length - 2);
  745. if (s == null || s === m.VALUE)
  746. return 0;
  747. const o = s[0];
  748. if (typeof o == "string")
  749. return 0;
  750. let u = o.getParent(), c = 0;
  751. for (s[1] === K.OPEN_BRACKET && c++; u; ) {
  752. const l = u.getToken();
  753. l !== ht && l !== K.COLON && u.getStartIndex() !== -1 && l.toUpperCase() !== Sr && (t === 0 ? c += 1 : t--), u = u.getParent();
  754. }
  755. return c;
  756. }
  757. sequenceNodesBuilder(e) {
  758. const t = as.get(e);
  759. if (t)
  760. return [...t];
  761. const r = this._getSequenceArray(e);
  762. if (r.length === 0)
  763. return;
  764. const n = this.getSequenceNode(r);
  765. return as.set(e, [...n]), n;
  766. }
  767. convertRefersToAbsolute(e, t, r, n = "") {
  768. const s = this.sequenceNodesBuilder(e);
  769. if (s == null)
  770. return e;
  771. let o = "";
  772. e.substring(0, 1) === X.EQUALS && (o = X.EQUALS);
  773. for (let u = 0, c = s.length; u < c; u++) {
  774. const l = s[u];
  775. if (typeof l != "string" && l.nodeType === $e.REFERENCE) {
  776. const { token: f, endIndex: h } = l, d = mr(f);
  777. if (d == null)
  778. continue;
  779. const { range: _, sheetName: C, unitId: E } = d, b = {
  780. ..._,
  781. startAbsoluteRefType: t,
  782. endAbsoluteRefType: r
  783. }, R = ys({
  784. range: b,
  785. unitId: E,
  786. sheetName: C || n
  787. }), p = R.length - f.length;
  788. s[u] = {
  789. ...l,
  790. token: R,
  791. endIndex: h + p
  792. };
  793. for (let N = u + 1; N < c; N++) {
  794. const M = s[N];
  795. typeof M != "string" && (M.startIndex += p, M.endIndex += p);
  796. }
  797. }
  798. }
  799. return `${o}${ri(s)}`;
  800. }
  801. moveFormulaRefOffset(e, t, r, n = !1) {
  802. const s = this.sequenceNodesBuilder(e);
  803. if (s == null)
  804. return e;
  805. const o = [];
  806. for (let u = 0, c = s.length; u < c; u++) {
  807. const l = s[u];
  808. if (typeof l == "string" || l.nodeType !== $e.REFERENCE) {
  809. o.push(l);
  810. continue;
  811. }
  812. const { token: f } = l, h = mr(f), { sheetName: d, unitId: _ } = h;
  813. let C = h.range;
  814. if (!n && C.startAbsoluteRefType === we.ALL && C.endAbsoluteRefType === we.ALL) {
  815. o.push(l);
  816. continue;
  817. } else
  818. C = ea(C, t, r, n);
  819. let E = "";
  820. Fu(C) ? E = ys({
  821. range: C,
  822. unitId: _,
  823. sheetName: d
  824. }) : E = m.REF, o.push({
  825. ...l,
  826. token: E
  827. });
  828. }
  829. return `=${ri(o)}`;
  830. }
  831. /**
  832. * univer-pro/issues/1684
  833. * =sum({}{})
  834. */
  835. _formulaSpellCheck() {
  836. if (this._currentLexerNode.getChildren().length === 0)
  837. return !0;
  838. const e = this._currentLexerNode.getChildren()[0];
  839. return !!(e instanceof ae || Dt.has(e) || rs.has(e) || e === Oe.AT || e === K.COMMA || e === K.COLON || e === K.OPEN_BRACKET);
  840. }
  841. // eslint-disable-next-line complexity
  842. getSequenceNode(e) {
  843. const t = [];
  844. let r = !1;
  845. for (let n = 0, s = e.length; n < s; n++) {
  846. const o = e[n], u = e[n - 1], { segment: c, currentString: l } = o;
  847. if (l === K.DOUBLE_QUOTATION && (r = !0), (c !== "" || n === 0) && n !== s - 1) {
  848. t.push(l);
  849. continue;
  850. }
  851. let f = (u == null ? void 0 : u.segment) || "";
  852. const h = n - f.length;
  853. let d = n - 1;
  854. const _ = n - 1;
  855. if (n === s - 1 && this._isLastMergeString(l) && (f += l, d += 1), f === "" || Jr.has(f)) {
  856. t.push(l);
  857. continue;
  858. }
  859. const C = f.trim(), E = qi(C);
  860. r === !0 && C[C.length - 1] === K.DOUBLE_QUOTATION && C[0] !== K.OPEN_BRACES ? (r = !1, this._processPushSequenceNode(t, $e.STRING, f, h, d, _)) : vr(E) && rn(E) ? this._processPushSequenceNode(t, $e.REFERENCE, f, h, d, _) : Xe.isStringNumber(C) ? this._processPushSequenceNode(t, $e.NUMBER, f, h, d, _) : C.length > 0 && this._processPushSequenceNode(t, $e.FUNCTION, f, h, d, _), (n !== s - 1 || !this._isLastMergeString(l)) && t.push(l);
  861. }
  862. return this._mergeSequenceNodeReference(t);
  863. }
  864. _processPushSequenceNode(e, t, r, n, s, o) {
  865. this._pushSequenceNode(
  866. e,
  867. {
  868. nodeType: t,
  869. token: r,
  870. startIndex: n,
  871. endIndex: s
  872. },
  873. o
  874. );
  875. }
  876. _getCurrentParamIndex(e, t) {
  877. return this._nodeMaker(e, void 0, t);
  878. }
  879. _isLastMergeString(e) {
  880. return e === K.DOUBLE_QUOTATION || Xe.isStringNumber(e) || !en(e);
  881. }
  882. /**
  883. * Merge array and handle ref operations
  884. *
  885. */
  886. _mergeSequenceNodeReference(e) {
  887. const t = [], r = e.length;
  888. let n = 0;
  889. for (; n < r; ) {
  890. const s = e[n];
  891. if (typeof s == "string") {
  892. const o = e[n - 1];
  893. if (s.trim() === K.CLOSE_BRACES && o != null && typeof o != "string" && o.nodeType === $e.FUNCTION && o.token.trim().substring(0, 1) === K.OPEN_BRACES) {
  894. o.nodeType = $e.ARRAY, o.token += s, o.endIndex += s.length, n++;
  895. continue;
  896. }
  897. t.push(s);
  898. } else {
  899. const o = e[n + 1], u = e[n + 2];
  900. o === K.COLON && typeof s != "string" && u != null && typeof u != "string" && rn((s.token + o + u.token).trim()) && (s.nodeType = $e.REFERENCE, s.token += o + u.token, s.endIndex = u.endIndex, n += 2), t.push(s);
  901. }
  902. n++;
  903. }
  904. return this._minusSplitSequenceNode(t);
  905. }
  906. /**
  907. * =-A1 Separate the negative sign from the ref string.
  908. */
  909. _minusSplitSequenceNode(e) {
  910. const t = [];
  911. for (const r of e) {
  912. if (typeof r != "string") {
  913. const s = r.token.match(/^(\s*([-@+]\s*)+)(.*)$/);
  914. if (s) {
  915. const o = s[1], u = s[3];
  916. if (rn(u.trim())) {
  917. const c = o.length, l = r.startIndex, f = r.startIndex + c - 1, h = {
  918. nodeType: $e.NORMAL,
  919. // Use appropriate nodeType for operators
  920. token: o,
  921. startIndex: l,
  922. endIndex: f
  923. }, d = {
  924. nodeType: $e.REFERENCE,
  925. token: u,
  926. startIndex: f + 1,
  927. endIndex: r.endIndex
  928. };
  929. t.push(h), t.push(d);
  930. continue;
  931. }
  932. }
  933. }
  934. t.push(r);
  935. }
  936. return t;
  937. }
  938. _pushSequenceNode(e, t, r) {
  939. const n = r - t.startIndex + 1;
  940. e.splice(e.length - n, n, t);
  941. }
  942. nodeMakerTest(e) {
  943. return this._nodeMaker(e);
  944. }
  945. treeBuilder(e, t = !0, r, n) {
  946. if (t === !0) {
  947. const h = ss.get(e), d = n == null ? void 0 : n(e);
  948. if (h && !d)
  949. return h;
  950. }
  951. this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Ut);
  952. const s = [];
  953. let o = this._nodeMaker(e, s);
  954. if (o === m.VALUE || s.length === 0)
  955. return o;
  956. let u = !1, c = "", l = [];
  957. if (r) {
  958. const { hasDefinedName: h, sequenceString: d, definedNames: _ } = r(s);
  959. u = h, c = d, l = _;
  960. }
  961. if (u && (this._resetCurrentLexerNode(), this._currentLexerNode.setToken(Ut), o = this._nodeMaker(`=${c}`), o === m.VALUE))
  962. return o;
  963. const f = this._getTopNode(this._currentLexerNode);
  964. if (f && (this._currentLexerNode = f), t) {
  965. if (!this._suffixExpressionHandler(this._currentLexerNode))
  966. return m.VALUE;
  967. ss.set(e, this._currentLexerNode);
  968. }
  969. return u && this._currentLexerNode.setDefinedNames(l), this._currentLexerNode;
  970. }
  971. // eslint-disable-next-line complexity
  972. _suffixExpressionHandler(e) {
  973. var u;
  974. const t = e.getChildren();
  975. if (!t)
  976. return !1;
  977. const r = t.length, n = [], s = [];
  978. let o = !0;
  979. for (let c = 0; c < r; c++) {
  980. const l = t[c];
  981. if (l instanceof ae)
  982. o = this._suffixExpressionHandler(l), n.push(l);
  983. else {
  984. const f = l.trim();
  985. if (f === "")
  986. continue;
  987. if (Dt.has(f)) {
  988. if (f === X.PLUS && this._deletePlusForPreNode(t[c - 1]))
  989. continue;
  990. if (f !== X.PLUS && f !== X.MINUS && this._deletePlusForPreNode(t[c - 1]))
  991. return !1;
  992. for (; s.length > 0; ) {
  993. const h = (u = s[s.length - 1]) == null ? void 0 : u.trim();
  994. if (!h || h === K.OPEN_BRACKET)
  995. break;
  996. const d = Jr.get(h), _ = Jr.get(f);
  997. if (!d || !_)
  998. break;
  999. if (_ >= d)
  1000. n.push(s.pop());
  1001. else
  1002. break;
  1003. }
  1004. s.push(l);
  1005. } else if (f === K.OPEN_BRACKET)
  1006. s.push(l);
  1007. else if (f === K.CLOSE_BRACKET)
  1008. this._processSuffixExpressionCloseBracket(n, s, t, c);
  1009. else {
  1010. if (this._checkCloseBracket(t[c - 1]))
  1011. return !1;
  1012. n.push(l);
  1013. }
  1014. }
  1015. }
  1016. return o ? this._processSuffixExpressionRemain(n, s, e) : !1;
  1017. }
  1018. _processSuffixExpressionRemain(e, t, r) {
  1019. const n = e.length, s = e[n - 1];
  1020. for (; t.length > 0; ) {
  1021. const o = t.pop();
  1022. if (!(s instanceof ae) && (o === K.OPEN_BRACKET || o === K.CLOSE_BRACKET))
  1023. return !1;
  1024. e.push(o);
  1025. }
  1026. return r.setChildren(e), !0;
  1027. }
  1028. _processSuffixExpressionCloseBracket(e, t, r, n) {
  1029. var s;
  1030. if (this._checkOpenBracket(r[n - 1]) || this._checkOperator(r[n - 1]))
  1031. return !1;
  1032. for (; t.length > 0; ) {
  1033. const o = (s = t[t.length - 1]) == null ? void 0 : s.trim();
  1034. if (!o)
  1035. break;
  1036. if (o === K.OPEN_BRACKET) {
  1037. t.pop();
  1038. break;
  1039. }
  1040. e.push(t.pop());
  1041. }
  1042. }
  1043. _checkCloseBracket(e) {
  1044. return e === K.CLOSE_BRACKET || e instanceof ae;
  1045. }
  1046. _checkOpenBracket(e) {
  1047. return e === K.OPEN_BRACKET;
  1048. }
  1049. _checkOperator(e) {
  1050. return e == null || e instanceof ae ? !1 : Dt.has(e);
  1051. }
  1052. _deletePlusForPreNode(e) {
  1053. if (e == null)
  1054. return !0;
  1055. if (!(e instanceof ae)) {
  1056. const t = e.trim();
  1057. if (Dt.has(t) || t === K.OPEN_BRACKET)
  1058. return !0;
  1059. }
  1060. return !1;
  1061. }
  1062. _resetCurrentLexerNode() {
  1063. this._currentLexerNode = new ae();
  1064. }
  1065. _resetSegment() {
  1066. this._segment = "";
  1067. }
  1068. _openBracket(e = 0) {
  1069. this._bracketState.push(e);
  1070. }
  1071. _closeBracket() {
  1072. this._bracketState.pop();
  1073. }
  1074. _openSquareBracket() {
  1075. this._squareBracketState += 1;
  1076. }
  1077. _closeSquareBracket() {
  1078. this._squareBracketState -= 1;
  1079. }
  1080. _getCurrentBracket() {
  1081. const e = this._bracketState;
  1082. return e[e.length - 1];
  1083. }
  1084. _changeCurrentBracket(e) {
  1085. const t = this._bracketState;
  1086. t[t.length - 1] = e;
  1087. }
  1088. _openBraces() {
  1089. this._bracesState += 1;
  1090. }
  1091. _closeBraces() {
  1092. this._bracesState -= 1;
  1093. }
  1094. _openSingleQuotation() {
  1095. this._singleQuotationState += 1;
  1096. }
  1097. _closeSingleQuotation() {
  1098. this._singleQuotationState -= 1;
  1099. }
  1100. _openDoubleQuotation() {
  1101. this._doubleQuotationState += 1;
  1102. }
  1103. _closeDoubleQuotation() {
  1104. this._doubleQuotationState -= 1;
  1105. }
  1106. _openLambda() {
  1107. this._lambdaState = !0;
  1108. }
  1109. _closeLambda() {
  1110. this._lambdaState = !1;
  1111. }
  1112. _openColon(e) {
  1113. this._upLevel = e, this._colonState = !0;
  1114. }
  1115. _closeColon() {
  1116. this._upLevel = 0, this._colonState = !1;
  1117. }
  1118. _isTableBracket() {
  1119. return this._tableBracketState;
  1120. }
  1121. _openTableBracket() {
  1122. this._tableBracketState = !0;
  1123. }
  1124. _closeTableBracket() {
  1125. this._tableBracketState = !1;
  1126. }
  1127. _formalErrorOccurred() {
  1128. this._formulaErrorCount += 1;
  1129. }
  1130. _hasFormalError() {
  1131. return this._formulaErrorCount > 0;
  1132. }
  1133. _getLastChildCurrentLexerNode() {
  1134. const e = this._currentLexerNode.getChildren();
  1135. if (e && e.length > 0) {
  1136. const t = e[e.length - 1];
  1137. if (t instanceof ae)
  1138. return t;
  1139. }
  1140. return !1;
  1141. }
  1142. _getLastChildCurrent() {
  1143. const e = this._currentLexerNode.getChildren();
  1144. return e && e.length > 0 ? e[e.length - 1] : !1;
  1145. }
  1146. _setParentCurrentLexerNode() {
  1147. const e = this._currentLexerNode.getParent();
  1148. return e ? (this._currentLexerNode = e, !0) : !1;
  1149. }
  1150. _setAncestorCurrentLexerNode() {
  1151. var r, n, s, o, u, c;
  1152. const e = (r = this._currentLexerNode) == null ? void 0 : r.getParent();
  1153. let t = !1;
  1154. if (e && e.getToken() === hr) {
  1155. if ((n = e == null ? void 0 : e.getParent()) != null && n.getParent()) {
  1156. const l = (o = (s = this._currentLexerNode.getParent()) == null ? void 0 : s.getParent()) == null ? void 0 : o.getParent();
  1157. l && (this._currentLexerNode = l), t = !0;
  1158. }
  1159. } else if (e != null && e.getParent()) {
  1160. const l = (u = this._currentLexerNode.getParent()) == null ? void 0 : u.getParent();
  1161. l && (this._currentLexerNode = l), t = !0;
  1162. }
  1163. for (let l = 0; l < this._upLevel; l++) {
  1164. const f = (c = this._currentLexerNode) == null ? void 0 : c.getParent();
  1165. f && (this._currentLexerNode = f), this._currentLexerNode ? t = !0 : t = !1;
  1166. }
  1167. return t;
  1168. }
  1169. _segmentCount() {
  1170. return this._segment.trim().length;
  1171. }
  1172. _pushSegment(e) {
  1173. this._segment += e;
  1174. }
  1175. _pushNodeToChildren(e, t = !1) {
  1176. let r = e;
  1177. if (r !== "") {
  1178. const n = this._currentLexerNode.getChildren();
  1179. if (!(r instanceof ae) && this.isColonOpen()) {
  1180. const s = new ae();
  1181. s.setToken(r), s.setParent(this._currentLexerNode), r = s;
  1182. }
  1183. t ? n.unshift(r) : n.push(r);
  1184. }
  1185. this.isColonOpen() && (this._setAncestorCurrentLexerNode(), this._closeColon());
  1186. }
  1187. _setCurrentLexerNode(e, t = !1) {
  1188. this._pushNodeToChildren(e, t), e.setParent(this._currentLexerNode), this._currentLexerNode = e;
  1189. }
  1190. _newAndPushCurrentLexerNode(e, t, r = !1) {
  1191. const n = new ae();
  1192. n.setToken(e), n.setIndex(t - e.length, t - 1), this._setCurrentLexerNode(n, r);
  1193. }
  1194. _getTopNode(e) {
  1195. let t = e;
  1196. for (; t != null && t.getParent(); )
  1197. t = t.getParent();
  1198. return t;
  1199. }
  1200. _removeLastChild() {
  1201. this._currentLexerNode.getChildren().splice(-1);
  1202. }
  1203. /**
  1204. * fix univer-pro/issues/2447
  1205. * =1/3+
  1206. * =+
  1207. * =sum(A1+)
  1208. */
  1209. _formulaErrorLastTokenCheck(e, t) {
  1210. const r = this._findPreviousToken(e, t) || "", n = e.length - 1 === t;
  1211. if (!n && this._isOperatorToken(r) || n && sc(r))
  1212. return !0;
  1213. if (rs.has(r)) {
  1214. const s = this._findSecondLastNonSpaceToken(e, t);
  1215. if (s == null || ic(s))
  1216. return !0;
  1217. }
  1218. return !1;
  1219. }
  1220. _findPreviousToken(e, t) {
  1221. let r = t;
  1222. for (; r >= 0; ) {
  1223. const n = e[r];
  1224. if (n !== " ")
  1225. return n;
  1226. r--;
  1227. }
  1228. }
  1229. _findSecondLastNonSpaceToken(e, t) {
  1230. let r = t, n = 0;
  1231. for (; r >= 0; ) {
  1232. const s = e[r];
  1233. if (s !== " " && (n++, n === 2))
  1234. return s;
  1235. r--;
  1236. }
  1237. return null;
  1238. }
  1239. _findNextToken(e, t) {
  1240. let r = t;
  1241. for (; r >= 0; ) {
  1242. const n = e[r];
  1243. if (n !== " ")
  1244. return n;
  1245. r++;
  1246. }
  1247. }
  1248. _unexpectedEndingTokenExcludeOperator(e) {
  1249. return (
  1250. // OPERATOR_TOKEN_SET.has(prevString) ||
  1251. e === K.OPEN_BRACKET || e === K.COMMA || e === X.EQUALS || e === ""
  1252. );
  1253. }
  1254. _unexpectedEndingToken(e) {
  1255. return !!(this._isOperatorToken(e) || this._unexpectedEndingTokenExcludeOperator(e));
  1256. }
  1257. _isOperatorToken(e) {
  1258. return !!Dt.has(e);
  1259. }
  1260. _getSequenceArray(e) {
  1261. const t = [];
  1262. return this._nodeMaker(e, t), t;
  1263. }
  1264. _resetTemp() {
  1265. this._currentLexerNode = new ae(), this._upLevel = 0, this._segment = "", this._bracketState = [], this._bracesState = 0, this._singleQuotationState = 0, this._doubleQuotationState = 0, this._lambdaState = !1, this._colonState = !1, this._formulaErrorCount = 0;
  1266. }
  1267. _checkErrorState() {
  1268. return !!(this._bracketState.length > 0 || this._bracesState > 0 || this._singleQuotationState > 0 || this._doubleQuotationState > 0 || this._hasFormalError());
  1269. }
  1270. _checkSimilarErrorToken(e, t, r) {
  1271. let n = t;
  1272. if (e !== ze.POUND)
  1273. return !0;
  1274. let s = r[++n];
  1275. for (; s === " "; )
  1276. s = r[++n];
  1277. return !!en(s);
  1278. }
  1279. _checkIfErrorObject(e, t) {
  1280. return !!this._findErrorObject(e, t);
  1281. }
  1282. _findErrorObject(e, t) {
  1283. for (let r = 0; r < Ga.length; r++) {
  1284. const n = Ga[r], s = t.slice(e, e + n).join("").toUpperCase();
  1285. if (yr.has(s))
  1286. return s;
  1287. }
  1288. }
  1289. // eslint-disable-next-line max-lines-per-function, complexity
  1290. _nodeMaker(e, t, r) {
  1291. let n = e.replace(/\r\n$/, "").replace(/\r/g, " ").replace(/\n/g, " ");
  1292. n.substring(0, 1) === X.EQUALS && (n = n.substring(1));
  1293. const s = n.split(""), o = s.length;
  1294. let u = 0;
  1295. for (this._resetTemp(), this._formulaErrorLastTokenCheck(s, o - 1) && this._formalErrorOccurred(); u < o; ) {
  1296. const c = s[u];
  1297. if (r === u)
  1298. return [this._currentLexerNode, c];
  1299. if (c === ze.POUND && this.isSingleQuotationClose() && this.isDoubleQuotationClose() && this.isBracesClose() && this.isSquareBracketClose() && this._checkIfErrorObject(u, s)) {
  1300. const l = this._findErrorObject(u, s);
  1301. if (l == null)
  1302. return m.VALUE;
  1303. this._pushNodeToChildren(l);
  1304. for (let f = 0; f < l.length; f++) {
  1305. const h = s[u];
  1306. this._pushSegment(h), this._addSequenceArray(t, h, u), u++;
  1307. }
  1308. this._resetSegment();
  1309. continue;
  1310. } else if (c === K.OPEN_BRACKET && this.isSingleQuotationClose() && this.isDoubleQuotationClose())
  1311. if (this._segmentCount() > 0 || this.isLambdaOpen()) {
  1312. this.isLambdaClose() && (this._newAndPushCurrentLexerNode(this._segment, u), this._resetSegment()), this._openBracket(
  1313. 1
  1314. /* FUNCTION */
  1315. ), this._closeLambda();
  1316. const l = s[u + 1];
  1317. if (l && l === K.CLOSE_BRACKET) {
  1318. if (!this._setParentCurrentLexerNode() && u !== o - 1)
  1319. return m.VALUE;
  1320. this._addSequenceArray(t, c, u), u++, this._addSequenceArray(t, l, u), u++, this._closeBracket();
  1321. continue;
  1322. } else l && this._newAndPushCurrentLexerNode(ht, u);
  1323. } else
  1324. this._pushNodeToChildren(c), this._openBracket(
  1325. 0
  1326. /* NORMAL */
  1327. ), this._resetSegment();
  1328. else if (c === K.CLOSE_BRACKET && this.isSingleQuotationClose() && this.isDoubleQuotationClose()) {
  1329. this._formulaErrorLastTokenCheck(s, u - 1) && this._formalErrorOccurred(), this._pushNodeToChildren(this._segment), this._resetSegment();
  1330. const l = this._getCurrentBracket();
  1331. if (l === 0)
  1332. this._pushNodeToChildren(c);
  1333. else if (l === 1) {
  1334. const f = s[u + 1];
  1335. if (f && f === K.OPEN_BRACKET) {
  1336. if (!this._setParentCurrentLexerNode() && u !== o - 1)
  1337. return m.VALUE;
  1338. this._newAndPushCurrentLexerNode(hr, u, !0), this._openLambda();
  1339. } else if (!this._setAncestorCurrentLexerNode() && u !== o - 1)
  1340. return m.VALUE;
  1341. } else
  1342. return m.VALUE;
  1343. this._closeBracket();
  1344. } else if (c === K.OPEN_BRACES && this.isSingleQuotationClose() && this.isDoubleQuotationClose()) {
  1345. if (this._pushSegment(c), this._openBraces(), !this._formulaSpellCheck())
  1346. return m.VALUE;
  1347. } else if (c === K.CLOSE_BRACES && this.isSingleQuotationClose() && this.isDoubleQuotationClose())
  1348. this._pushSegment(c), this._pushNodeToChildren(this._segment), this._resetSegment(), this._closeBraces();
  1349. else if (c === K.OPEN_SQUARE_BRACKET && this.isSingleQuotationClose() && this.isDoubleQuotationClose())
  1350. this._segment.length > 0 && this._openTableBracket(), this._pushSegment(c), this._openSquareBracket();
  1351. else if (c === K.CLOSE_SQUARE_BRACKET && this.isSingleQuotationClose() && this.isDoubleQuotationClose())
  1352. this._closeSquareBracket(), this.isSquareBracketClose() ? (this._pushSegment(c), this._isTableBracket() && (this._pushNodeToChildren(this._segment), this._resetSegment()), this._closeTableBracket()) : this._pushSegment(c);
  1353. else if (c === K.DOUBLE_QUOTATION && this.isSingleQuotationClose() && this.isSquareBracketClose()) {
  1354. if (this.isDoubleQuotationClose())
  1355. this._openDoubleQuotation();
  1356. else {
  1357. const l = s[u + 1];
  1358. l && l === K.DOUBLE_QUOTATION ? u++ : this._closeDoubleQuotation();
  1359. }
  1360. this._pushSegment(c);
  1361. } else if (c === K.SINGLE_QUOTATION && this.isDoubleQuotationClose()) {
  1362. if (this.isSingleQuotationClose())
  1363. this._openSingleQuotation(), this._segmentCount() === 0 && this._resetSegment();
  1364. else {
  1365. const l = s[u + 1];
  1366. if (l && l === K.SINGLE_QUOTATION) {
  1367. this._pushSegment(c), this._addSequenceArray(t, c, u), u++, this._pushSegment(l), this._addSequenceArray(t, l, u), u++;
  1368. continue;
  1369. } else
  1370. this._closeSingleQuotation();
  1371. }
  1372. this._pushSegment(c);
  1373. } else if (c === K.COMMA && this.isSingleQuotationClose() && this.isDoubleQuotationClose() && this.isBracesClose() && this.isSquareBracketClose()) {
  1374. this._formulaErrorLastTokenCheck(s, u - 1) && this._formalErrorOccurred();
  1375. const l = this._getCurrentBracket();
  1376. if (l === 1 || l == null) {
  1377. if (this._pushNodeToChildren(this._segment), this._resetSegment(), !this._setParentCurrentLexerNode() && u !== o - 1 && l != null)
  1378. return m.VALUE;
  1379. this._newAndPushCurrentLexerNode(ht, u);
  1380. } else {
  1381. const f = new ae();
  1382. f.setToken(Tc);
  1383. const h = new ae();
  1384. h.setToken(ht), h.changeToParent(f);
  1385. const d = this._currentLexerNode.getParent();
  1386. if (d && d.getToken() === K.COLON) {
  1387. const _ = d.getParent();
  1388. if (!_)
  1389. return m.VALUE;
  1390. d.changeToParent(h), _.setChildren([]), f.changeToParent(_);
  1391. } else
  1392. return m.VALUE;
  1393. this._changeCurrentBracket(
  1394. 1
  1395. /* FUNCTION */
  1396. ), this._pushNodeToChildren(this._segment), this._resetSegment(), this._currentLexerNode = f, this._newAndPushCurrentLexerNode(ht, u);
  1397. }
  1398. } else if (c === K.COLON && this.isSingleQuotationClose() && this.isDoubleQuotationClose() && this.isBracesClose() && this.isSquareBracketClose()) {
  1399. const l = new ae();
  1400. l.setToken(c);
  1401. const f = new ae();
  1402. f.setToken(ht), f.setParent(l);
  1403. const h = new ae();
  1404. h.setToken(ht), h.setParent(l), l.getChildren().push(f, h);
  1405. let d = l, _ = 0;
  1406. if (this._segmentCount() > 0) {
  1407. let C, E, b = 0;
  1408. const R = this._segment.trim(), p = R[0], N = R[1];
  1409. if (p === Oe.MINUS && (C = new ae(), C.setToken(Oe.MINUS), b++), (p === Oe.AT || N === Oe.AT) && (E = new ae(), E.setToken(Oe.AT), C && (C.addChildren(E), E.setParent(C)), b++), b > 0 && (this._segment = R.slice(b)), _ = b, E)
  1410. if (E.addChildren(l), l.setParent(E), E.getParent()) {
  1411. const w = E.getParent();
  1412. w && (d = w);
  1413. } else
  1414. d = E;
  1415. else C && (d = C, C.addChildren(l), l.setParent(C));
  1416. const M = new ae();
  1417. M.setToken(this._segment), M.setParent(f), f.getChildren().push(M), this._resetSegment();
  1418. } else {
  1419. const C = this._getLastChildCurrentLexerNode();
  1420. C && C.changeToParent(f);
  1421. }
  1422. this._setCurrentLexerNode(d), this._currentLexerNode = h, this._openColon(_);
  1423. } else if (rs.has(c) && this._checkSimilarErrorToken(c, u, s) && this.isSingleQuotationClose() && this.isDoubleQuotationClose() && this.isSquareBracketClose() && this.isBracesClose()) {
  1424. this._pushNodeToChildren(this._segment);
  1425. const l = new ae();
  1426. l.setToken(c);
  1427. const f = this._getLastChildCurrent();
  1428. f instanceof ae ? f.changeToParent(l) : f !== !1 && (l.getChildren().push(f), this._removeLastChild()), this._pushNodeToChildren(l), l.setParent(this._currentLexerNode), this._resetSegment();
  1429. } else if (Dt.has(c) && this.isSingleQuotationClose() && this.isDoubleQuotationClose() && this.isSquareBracketClose() && this.isBracesClose()) {
  1430. let l = this._segment.trim();
  1431. if (c === X.MINUS && l === "") {
  1432. const f = this._findPreviousToken(s, u - 1) || "", h = this._findNextToken(s, u + 1) || "";
  1433. if (this._unexpectedEndingTokenExcludeOperator(f) && this._isOperatorToken(h)) {
  1434. this._pushNodeToChildren("0"), this._pushNodeToChildren(X.MINUS), this._addSequenceArray(t, c, u), this._resetSegment(), u++;
  1435. continue;
  1436. } else if (this._unexpectedEndingToken(f))
  1437. if (h === X.PLUS) {
  1438. this._pushSegment(X.MINUS), this._addSequenceArray(t, c, u), this._addSequenceArray(t, X.PLUS, u + 1), u += 2;
  1439. continue;
  1440. } else {
  1441. this._pushSegment(X.MINUS), this._addSequenceArray(t, c, u), u++;
  1442. continue;
  1443. }
  1444. } else if (this._segment.length > 0 && this._isScientificNotation(s, u, c)) {
  1445. this._pushSegment(c), this._addSequenceArray(t, c, u), u++;
  1446. continue;
  1447. } else this._segment.length > 0 && l === "" ? l = this._segment : (this._pushNodeToChildren(this._segment), l = "");
  1448. if (c === X.LESS_THAN || c === X.GREATER_THAN) {
  1449. const f = s[u + 1];
  1450. if (f && Dt.has(c + f)) {
  1451. this._pushNodeToChildren(l + c + f), this._resetSegment(), this._addSequenceArray(t, c, u), u++, this._addSequenceArray(t, f, u), u++;
  1452. continue;
  1453. } else
  1454. this._pushNodeToChildren(l + c);
  1455. } else
  1456. this._pushNodeToChildren(l + c);
  1457. this._resetSegment();
  1458. } else
  1459. this._pushSegment(c);
  1460. this._addSequenceArray(t, c, u), u++;
  1461. }
  1462. if (this._pushNodeToChildren(this._segment), this._checkErrorState())
  1463. return m.VALUE;
  1464. }
  1465. _isScientificNotation(e, t, r) {
  1466. const n = e[t - 2];
  1467. if (n && Number.isNaN(Number(n)) || !(r === X.MINUS || r === X.PLUS))
  1468. return !1;
  1469. const s = e[t + 1];
  1470. if (s && Number.isNaN(Number(s)))
  1471. return !1;
  1472. const o = e[t - 1];
  1473. return o && o.toUpperCase() === "E";
  1474. }
  1475. _addSequenceArray(e, t, r) {
  1476. e == null || e.push({
  1477. segment: this._segment,
  1478. currentString: t,
  1479. cur: r,
  1480. currentLexerNode: this._currentLexerNode
  1481. });
  1482. }
  1483. }
  1484. function Fc(i, a, e, t, r, n, s) {
  1485. const o = (s == null ? void 0 : s.f) || "", u = (s == null ? void 0 : s.si) || "", c = bt(o), l = Lt(u), f = i.getValue(r, n), h = (f == null ? void 0 : f.f) || "", d = (f == null ? void 0 : f.si) || "";
  1486. function _() {
  1487. var C;
  1488. if (bt(h) && Lt(d)) {
  1489. const E = (C = e == null ? void 0 : e[d]) == null ? void 0 : C.f;
  1490. E ? t.set(d, E) : t.set(d, h);
  1491. }
  1492. }
  1493. c && l ? (d !== u && _(), i.setValue(r, n, {
  1494. f: o,
  1495. si: u
  1496. }), e[u] = { f: o, r, c: n }, a.setValue(r, n, {
  1497. f: o,
  1498. si: u
  1499. })) : c && !l ? (h !== o && _(), i.setValue(r, n, {
  1500. f: o
  1501. }), a.setValue(r, n, {
  1502. f: o
  1503. })) : !c && l ? (d !== u && _(), i.setValue(r, n, {
  1504. f: "",
  1505. si: u
  1506. })) : !c && !l && i.getValue(r, n) && (_(), i.realDeleteValue(r, n), a.setValue(r, n, null));
  1507. }
  1508. function kc(i, a, e, t) {
  1509. const r = i == null ? void 0 : i.getValue(e, t);
  1510. if (r == null)
  1511. return !0;
  1512. const n = [];
  1513. i.forValue((l, f, h) => {
  1514. l === e && f === t || Ha.intersects(h, r) && n.push(h);
  1515. });
  1516. const { startRow: s, startColumn: o, endRow: u, endColumn: c } = r;
  1517. for (let l = s; l <= u; l++)
  1518. for (let f = o; f <= c; f++) {
  1519. let h = !1;
  1520. const d = ku(l, f);
  1521. n.some((_) => Ha.contains(_, d) ? (h = !0, !0) : !1), h || a.realDeleteValue(l, f);
  1522. }
  1523. }
  1524. var $c = Object.defineProperty, Yc = Object.getOwnPropertyDescriptor, Hc = (i, a, e, t) => {
  1525. for (var r = t > 1 ? void 0 : t ? Yc(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  1526. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  1527. return t && r && $c(a, e, r), r;
  1528. }, ni = (i, a) => (e, t) => a(e, t, i);
  1529. let Pr = class extends Me {
  1530. constructor(a, e) {
  1531. super();
  1532. A(this, "_arrayFormulaRange", {});
  1533. A(this, "_arrayFormulaCellData", {});
  1534. this._univerInstanceService = a, this._lexerTreeBuilder = e;
  1535. }
  1536. dispose() {
  1537. super.dispose(), this._arrayFormulaRange = {}, this._arrayFormulaCellData = {};
  1538. }
  1539. clearPreviousArrayFormulaCellData(a) {
  1540. Object.keys(a).forEach((e) => {
  1541. const t = a[e];
  1542. if (t == null)
  1543. return !0;
  1544. Object.keys(t).forEach((r) => {
  1545. var c, l, f, h;
  1546. const n = t[r], s = (l = (c = this._arrayFormulaRange) == null ? void 0 : c[e]) == null ? void 0 : l[r];
  1547. if (s == null)
  1548. return !0;
  1549. const o = new Ce(s);
  1550. let u = new Ce();
  1551. ((f = this._arrayFormulaCellData[e]) == null ? void 0 : f[r]) != null && (u = new Ce(
  1552. (h = this._arrayFormulaCellData[e]) == null ? void 0 : h[r]
  1553. )), n.forValue((d, _) => {
  1554. const C = o.getValue(d, _);
  1555. if (C == null)
  1556. return !0;
  1557. const { startRow: E, startColumn: b, endRow: R, endColumn: p } = C;
  1558. for (let N = E; N <= R; N++)
  1559. for (let M = b; M <= p; M++)
  1560. u.setValue(N, M, null);
  1561. o.realDeleteValue(d, _);
  1562. }), this._arrayFormulaCellData[e] && (this._arrayFormulaCellData[e][r] = u.getData());
  1563. });
  1564. });
  1565. }
  1566. mergeArrayFormulaCellData(a) {
  1567. Object.keys(a).forEach((e) => {
  1568. const t = a[e];
  1569. if (t == null)
  1570. return !0;
  1571. this._arrayFormulaRange[e] == null && (this._arrayFormulaRange[e] = {}), this._arrayFormulaCellData[e] == null && (this._arrayFormulaCellData[e] = {}), Object.keys(t).forEach((r) => {
  1572. var u, c;
  1573. const n = t[r], s = new Ce((u = this._arrayFormulaRange[e]) == null ? void 0 : u[r]), o = new Ce((c = this._arrayFormulaCellData[e]) == null ? void 0 : c[r]);
  1574. n.forValue((l, f) => {
  1575. const h = s == null ? void 0 : s.getValue(l, f);
  1576. if (h == null)
  1577. return !0;
  1578. const { startRow: d, startColumn: _, endRow: C, endColumn: E } = h;
  1579. for (let b = d; b <= C; b++)
  1580. for (let R = _; R <= E; R++)
  1581. o.setValue(b, R, null);
  1582. }), n.forValue((l, f, h) => {
  1583. o.setValue(l, f, h);
  1584. }), this._arrayFormulaCellData[e] && (this._arrayFormulaCellData[e][r] = o.getData());
  1585. });
  1586. });
  1587. }
  1588. getFormulaData() {
  1589. const a = {}, e = this._univerInstanceService.getAllUnitsForType(Dr.UNIVER_SHEET);
  1590. return e.length === 0 || e.forEach((t) => {
  1591. const r = t.getUnitId();
  1592. a[r] = {}, t.getSheets().forEach((s) => {
  1593. const o = s.getCellMatrix(), u = s.getSheetId();
  1594. si(a, r, u, o);
  1595. });
  1596. }), a;
  1597. }
  1598. getSheetFormulaData(a, e) {
  1599. const t = {}, r = this._univerInstanceService.getUnit(a);
  1600. if (r == null)
  1601. return {};
  1602. t[a] = {};
  1603. const n = r.getSheetBySheetId(e);
  1604. if (n == null)
  1605. return {};
  1606. const s = n.getCellMatrix();
  1607. return si(t, a, e, s), t[a][e];
  1608. }
  1609. getArrayFormulaRange() {
  1610. return this._arrayFormulaRange;
  1611. }
  1612. setArrayFormulaRange(a) {
  1613. this._arrayFormulaRange = a;
  1614. }
  1615. getArrayFormulaCellData() {
  1616. return this._arrayFormulaCellData;
  1617. }
  1618. setArrayFormulaCellData(a) {
  1619. this._arrayFormulaCellData = a;
  1620. }
  1621. mergeArrayFormulaRange(a) {
  1622. Object.keys(a).forEach((e) => {
  1623. const t = a[e];
  1624. if (t == null)
  1625. return !0;
  1626. this._arrayFormulaRange[e] || (this._arrayFormulaRange[e] = {}), Object.keys(t).forEach((r) => {
  1627. var o;
  1628. const n = new Ce(t[r]), s = new Ce((o = this._arrayFormulaRange[e]) == null ? void 0 : o[r]);
  1629. n.forValue((u, c, l) => {
  1630. s.setValue(u, c, l);
  1631. }), this._arrayFormulaRange[e] && (this._arrayFormulaRange[e][r] = s.getData());
  1632. });
  1633. });
  1634. }
  1635. deleteArrayFormulaRange(a, e, t, r) {
  1636. var o;
  1637. const n = (o = this._arrayFormulaRange[a]) == null ? void 0 : o[e];
  1638. if (n == null)
  1639. return;
  1640. const s = new Ce(n);
  1641. s.getValue(t, r) && (s.realDeleteValue(t, r), this._arrayFormulaRange[a] && (this._arrayFormulaRange[a][e] = s.getData()));
  1642. }
  1643. getCalculateData() {
  1644. const a = this._univerInstanceService.getAllUnitsForType(Dr.UNIVER_SHEET), e = {}, t = {};
  1645. for (const r of a) {
  1646. const n = r.getUnitId(), s = r.getSheets(), o = {}, u = {};
  1647. for (const c of s) {
  1648. const l = c.getSheetId(), f = c.getConfig();
  1649. o[l] = {
  1650. cellData: new Ce(f.cellData),
  1651. rowCount: f.rowCount,
  1652. columnCount: f.columnCount,
  1653. rowData: f.rowData,
  1654. columnData: f.columnData,
  1655. defaultRowHeight: f.defaultRowHeight,
  1656. defaultColumnWidth: f.defaultColumnWidth
  1657. }, u[c.getName()] = c.getSheetId();
  1658. }
  1659. e[n] = o, t[n] = u;
  1660. }
  1661. return {
  1662. allUnitData: e,
  1663. unitSheetNameMap: t
  1664. };
  1665. }
  1666. updateFormulaData(a, e, t) {
  1667. const r = new Ce(t), n = this._getSheetFormulaIdMap(a, e), s = /* @__PURE__ */ new Map(), o = this.getFormulaData();
  1668. o[a] == null && (o[a] = {});
  1669. const u = o[a];
  1670. u[e] == null && (u[e] = {});
  1671. const c = new Ce(u[e] || {}), l = new Ce();
  1672. return r.forValue((f, h, d) => {
  1673. Fc(c, l, n, s, f, h, d);
  1674. }), c.forValue((f, h, d) => {
  1675. const _ = (d == null ? void 0 : d.f) || "", C = (d == null ? void 0 : d.si) || "";
  1676. if (Lt(C)) {
  1677. const E = n == null ? void 0 : n[C], b = s.get(C);
  1678. if (E && !bt(_)) {
  1679. const R = E.f, p = h - E.c, N = f - E.r;
  1680. c.setValue(f, h, { f: R, si: C, x: p, y: N }), l.setValue(f, h, { f: R, si: C, x: p, y: N });
  1681. } else if (typeof b == "string") {
  1682. const R = (d == null ? void 0 : d.x) || 0, p = (d == null ? void 0 : d.y) || 0, N = this._lexerTreeBuilder.moveFormulaRefOffset(b, R, p);
  1683. s.set(C, { r: f, c: h, f: N }), c.setValue(f, h, { f: N, si: C }), l.setValue(f, h, { f: N, si: C });
  1684. } else if (typeof b == "object") {
  1685. const R = h - b.c, p = f - b.r;
  1686. c.setValue(f, h, { f: b.f, si: C, x: R, y: p }), l.setValue(f, h, { f: b.f, si: C, x: R, y: p });
  1687. }
  1688. }
  1689. }), l.getMatrix();
  1690. }
  1691. updateArrayFormulaRange(a, e, t) {
  1692. var o;
  1693. const r = (o = this._arrayFormulaRange[a]) == null ? void 0 : o[e];
  1694. if (!r) return;
  1695. const n = new Ce(r);
  1696. new Ce(t).forValue((u, c, l) => {
  1697. n.realDeleteValue(u, c);
  1698. });
  1699. }
  1700. updateArrayFormulaCellData(a, e, t) {
  1701. var c, l;
  1702. const r = (c = this._arrayFormulaRange[a]) == null ? void 0 : c[e];
  1703. if (!r) return;
  1704. const n = new Ce(r), s = (l = this._arrayFormulaCellData[a]) == null ? void 0 : l[e];
  1705. if (!s) return;
  1706. const o = new Ce(s);
  1707. new Ce(t).forValue((f, h, d) => {
  1708. kc(n, o, f, h);
  1709. });
  1710. }
  1711. getFormulaStringByCell(a, e, t, r) {
  1712. const n = this._univerInstanceService.getUnit(r);
  1713. if (n == null)
  1714. return null;
  1715. const s = n.getSheetBySheetId(t);
  1716. if (s == null)
  1717. return null;
  1718. const o = s.getCellMatrix(), u = o.getValue(a, e);
  1719. if (u == null)
  1720. return null;
  1721. const { f: c, si: l } = u;
  1722. if (bt(c))
  1723. return c;
  1724. if (Lt(l)) {
  1725. let f = null;
  1726. return o.forValue((h, d, _) => {
  1727. if (_ == null)
  1728. return !0;
  1729. const { f: C, si: E } = _;
  1730. if (bt(C) && l === E)
  1731. return f = this._lexerTreeBuilder.moveFormulaRefOffset(
  1732. C,
  1733. e - d,
  1734. a - h
  1735. ), !1;
  1736. }), f;
  1737. }
  1738. return null;
  1739. }
  1740. /**
  1741. * Function to get all formula ranges
  1742. * @returns
  1743. */
  1744. getFormulaDirtyRanges() {
  1745. const a = this.getFormulaData(), e = [];
  1746. for (const t in a) {
  1747. const r = a[t];
  1748. if (!r) continue;
  1749. const n = this._univerInstanceService.getUnit(t);
  1750. if (n)
  1751. for (const s in r) {
  1752. const o = r[s];
  1753. if (!o) continue;
  1754. const u = n.getSheetBySheetId(s);
  1755. if (!u) continue;
  1756. const c = {};
  1757. for (const l of Object.keys(o)) {
  1758. const f = Number(l);
  1759. for (const h in o[f]) {
  1760. const d = Number(h), _ = u.getCellRaw(f, d), C = bt(_ == null ? void 0 : _.f) || Lt(_ == null ? void 0 : _.si), E = (_ == null ? void 0 : _.v) === void 0;
  1761. if (!(C && E)) continue;
  1762. c[d] || (c[d] = []);
  1763. const b = c[d].slice(-1)[0];
  1764. b && b.endRow === f - 1 ? b.endRow = f : c[d].push({ startRow: f, endRow: f });
  1765. }
  1766. }
  1767. for (const l in c) {
  1768. const f = c[l];
  1769. for (let h = 0; h < f.length; h++) {
  1770. const d = f[h];
  1771. e.push({
  1772. unitId: t,
  1773. sheetId: s,
  1774. range: {
  1775. rangeType: Ze.NORMAL,
  1776. startRow: d.startRow,
  1777. endRow: d.endRow,
  1778. // Use endRow as the inclusive end row
  1779. startColumn: Number(l),
  1780. endColumn: Number(l)
  1781. }
  1782. });
  1783. }
  1784. }
  1785. }
  1786. }
  1787. return e;
  1788. }
  1789. _getSheetFormulaIdMap(a, e) {
  1790. const t = {}, r = this._univerInstanceService.getUnit(a);
  1791. if (r == null)
  1792. return t;
  1793. const n = r.getSheetBySheetId(e);
  1794. return n == null || n.getCellMatrix().forValue((o, u, c) => {
  1795. if (c == null)
  1796. return !0;
  1797. const { f: l, si: f } = c;
  1798. bt(l) && Lt(f) && (t[f] = { f: l, r: o, c: u });
  1799. }), t;
  1800. }
  1801. };
  1802. Pr = Hc([
  1803. ni(0, Js),
  1804. ni(1, Ve(ca))
  1805. ], Pr);
  1806. function si(i, a, e, t) {
  1807. i[a] || (i[a] = {}), i[a][e] || (i[a][e] = {});
  1808. const r = /* @__PURE__ */ new Map(), n = new Ce(i[a][e]);
  1809. t.forValue((o, u, c) => {
  1810. const l = (c == null ? void 0 : c.f) || "", f = (c == null ? void 0 : c.si) || "", h = bt(l), d = Lt(f);
  1811. h && d ? (n.setValue(o, u, {
  1812. f: l,
  1813. si: f
  1814. }), r.set(f, { f: l, r: o, c: u })) : h && !d ? n.setValue(o, u, {
  1815. f: l
  1816. }) : !h && d && n.setValue(o, u, {
  1817. f: "",
  1818. si: f
  1819. });
  1820. }), n.forValue((o, u, c) => {
  1821. const l = (c == null ? void 0 : c.f) || "", f = (c == null ? void 0 : c.si) || "";
  1822. if (Lt(f) && !bt(l)) {
  1823. const h = r.get(f);
  1824. if (h) {
  1825. const d = h.f, _ = u - h.c, C = o - h.r;
  1826. n.setValue(o, u, { f: d, si: f, x: _, y: C });
  1827. } else
  1828. n.realDeleteValue(o, u);
  1829. }
  1830. });
  1831. const s = n.getMatrix();
  1832. return {
  1833. [a]: {
  1834. [e]: s
  1835. }
  1836. };
  1837. }
  1838. const Gc = class Ms {
  1839. /**
  1840. * Accept two comparable values and creates new instance of interval
  1841. * Predicate Interval.comparable_less(low, high) supposed to return true on these values
  1842. * @param low
  1843. * @param high
  1844. */
  1845. constructor(a, e) {
  1846. this.low = a, this.high = e;
  1847. }
  1848. /**
  1849. * Clone interval
  1850. * @returns {Interval}
  1851. */
  1852. clone() {
  1853. return new Ms(this.low, this.high);
  1854. }
  1855. /**
  1856. * Propery max returns clone of this interval
  1857. * @returns {Interval}
  1858. */
  1859. get max() {
  1860. return this.clone();
  1861. }
  1862. /**
  1863. * Predicate returns true is this interval less than other interval
  1864. * @param other_interval
  1865. * @returns {boolean}
  1866. */
  1867. less_than(a) {
  1868. return this.low < a.low || this.low === a.low && this.high < a.high;
  1869. }
  1870. /**
  1871. * Predicate returns true is this interval equals to other interval
  1872. * @param other_interval
  1873. * @returns {boolean}
  1874. */
  1875. equal_to(a) {
  1876. return this.low === a.low && this.high === a.high;
  1877. }
  1878. /**
  1879. * Predicate returns true if this interval intersects other interval
  1880. * @param other_interval
  1881. * @returns {boolean}
  1882. */
  1883. intersect(a) {
  1884. return !this.not_intersect(a);
  1885. }
  1886. /**
  1887. * Predicate returns true if this interval does not intersect other interval
  1888. * @param other_interval
  1889. * @returns {boolean}
  1890. */
  1891. not_intersect(a) {
  1892. return this.high < a.low || a.high < this.low;
  1893. }
  1894. /**
  1895. * Returns new interval merged with other interval
  1896. * @param {Interval} other_interval - Other interval to merge with
  1897. * @returns {Interval}
  1898. */
  1899. merge(a) {
  1900. return new Ms(
  1901. this.low === void 0 ? a.low : this.low < a.low ? this.low : a.low,
  1902. this.high === void 0 ? a.high : this.high > a.high ? this.high : a.high
  1903. );
  1904. }
  1905. /**
  1906. * Returns how key should return
  1907. */
  1908. output() {
  1909. return [this.low, this.high];
  1910. }
  1911. /**
  1912. * Function returns maximum between two comparable values
  1913. * @param interval1
  1914. * @param interval2
  1915. * @returns {Interval}
  1916. */
  1917. static comparable_max(a, e) {
  1918. return a.merge(e);
  1919. }
  1920. /**
  1921. * Predicate returns true if first value less than second value
  1922. * @param val1
  1923. * @param val2
  1924. * @returns {boolean}
  1925. */
  1926. static comparable_less_than(a, e) {
  1927. return a < e;
  1928. }
  1929. }, je = 0, Ae = 1;
  1930. class Ht {
  1931. constructor(a = void 0, e = void 0, t = null, r = null, n = null, s = Ae) {
  1932. if (this.left = t, this.right = r, this.parent = n, this.color = s, this.item = { key: a, value: e }, a && a instanceof Array && a.length === 2 && !Number.isNaN(a[0]) && !Number.isNaN(a[1])) {
  1933. let [o, u] = a;
  1934. o > u && ([o, u] = [u, o]), this.item.key = new Gc(o, u);
  1935. }
  1936. this.max = this.item.key ? this.item.key.max : void 0;
  1937. }
  1938. isNil() {
  1939. return this.item.key === void 0 && this.item.value === void 0 && this.left === null && this.right === null && this.color === Ae;
  1940. }
  1941. _value_less_than(a) {
  1942. return this.item.value && a.item.value && this.item.value.less_than ? this.item.value.less_than(a.item.value) : this.item.value < a.item.value;
  1943. }
  1944. less_than(a) {
  1945. return this.item.value === this.item.key && a.item.value === a.item.key ? this.item.key.less_than(a.item.key) : this.item.key.less_than(a.item.key) || this.item.key.equal_to(a.item.key) && this._value_less_than(a);
  1946. }
  1947. _value_equal(a) {
  1948. return this.item.value && a.item.value && this.item.value.equal_to ? this.item.value.equal_to(a.item.value) : this.item.value === a.item.value;
  1949. }
  1950. equal_to(a) {
  1951. return this.item.value === this.item.key && a.item.value === a.item.key ? this.item.key.equal_to(a.item.key) : this.item.key.equal_to(a.item.key) && this._value_equal(a);
  1952. }
  1953. intersect(a) {
  1954. return this.item.key.intersect(a.item.key);
  1955. }
  1956. copy_data(a) {
  1957. this.item.key = a.item.key, this.item.value = a.item.value;
  1958. }
  1959. update_max() {
  1960. if (this.max = this.item.key ? this.item.key.max : void 0, this.right && this.right.max) {
  1961. const a = this.item.key.constructor.comparable_max;
  1962. this.max = a(this.max, this.right.max);
  1963. }
  1964. if (this.left && this.left.max) {
  1965. const a = this.item.key.constructor.comparable_max;
  1966. this.max = a(this.max, this.left.max);
  1967. }
  1968. }
  1969. // Other_node does not intersect any node of left subtree, if this.left.max < other_node.item.key.low
  1970. not_intersect_left_subtree(a) {
  1971. const e = this.item.key.constructor.comparable_less_than;
  1972. let t = this.left.max.high !== void 0 ? this.left.max.high : this.left.max;
  1973. return e(t, a.item.key.low);
  1974. }
  1975. // Other_node does not intersect right subtree if other_node.item.key.high < this.right.key.low
  1976. not_intersect_right_subtree(a) {
  1977. const e = this.item.key.constructor.comparable_less_than;
  1978. let t = this.right.max.low !== void 0 ? this.right.max.low : this.right.item.key.low;
  1979. return e(a.item.key.high, t);
  1980. }
  1981. }
  1982. class la {
  1983. /**
  1984. * Construct new empty instance of IntervalTree
  1985. */
  1986. constructor() {
  1987. this.root = null, this.nil_node = new Ht();
  1988. }
  1989. /**
  1990. * Returns number of items stored in the interval tree
  1991. * @returns {number}
  1992. */
  1993. get size() {
  1994. let a = 0;
  1995. return this.tree_walk(this.root, () => a++), a;
  1996. }
  1997. /**
  1998. * Returns array of sorted keys in the ascending order
  1999. * @returns {Array}
  2000. */
  2001. get keys() {
  2002. let a = [];
  2003. return this.tree_walk(this.root, (e) => a.push(
  2004. e.item.key.output ? e.item.key.output() : e.item.key
  2005. )), a;
  2006. }
  2007. /**
  2008. * Return array of values in the ascending keys order
  2009. * @returns {Array}
  2010. */
  2011. get values() {
  2012. let a = [];
  2013. return this.tree_walk(this.root, (e) => a.push(e.item.value)), a;
  2014. }
  2015. /**
  2016. * Returns array of items (<key,value> pairs) in the ascended keys order
  2017. * @returns {Array}
  2018. */
  2019. get items() {
  2020. let a = [];
  2021. return this.tree_walk(this.root, (e) => a.push({
  2022. key: e.item.key.output ? e.item.key.output() : e.item.key,
  2023. value: e.item.value
  2024. })), a;
  2025. }
  2026. /**
  2027. * Returns true if tree is empty
  2028. * @returns {boolean}
  2029. */
  2030. isEmpty() {
  2031. return this.root == null || this.root === this.nil_node;
  2032. }
  2033. /**
  2034. * Clear tree
  2035. */
  2036. clear() {
  2037. this.root = null;
  2038. }
  2039. /**
  2040. * Insert new item into interval tree
  2041. * @param {Interval} key - interval object or array of two numbers [low, high]
  2042. * @param {any} value - value representing any object (optional)
  2043. * @returns {Node} returns reference to inserted node as an object {key:interval, value: value}
  2044. */
  2045. insert(a, e = a) {
  2046. if (a === void 0) return;
  2047. let t = new Ht(a, e, this.nil_node, this.nil_node, null, je);
  2048. return this.tree_insert(t), this.recalc_max(t), t;
  2049. }
  2050. /**
  2051. * Returns true if item {key,value} exist in the tree
  2052. * @param {Interval} key - interval correspondent to keys stored in the tree
  2053. * @param {any} value - value object to be checked
  2054. * @returns {boolean} true if item {key, value} exist in the tree, false otherwise
  2055. */
  2056. exist(a, e = a) {
  2057. let t = new Ht(a, e);
  2058. return !!this.tree_search(this.root, t);
  2059. }
  2060. /**
  2061. * Remove entry {key, value} from the tree
  2062. * @param {Interval} key - interval correspondent to keys stored in the tree
  2063. * @param {any} value - value object
  2064. * @returns {boolean} true if item {key, value} deleted, false if not found
  2065. */
  2066. remove(a, e = a) {
  2067. let t = new Ht(a, e), r = this.tree_search(this.root, t);
  2068. return r && this.tree_delete(r), r;
  2069. }
  2070. /**
  2071. * Returns array of entry values which keys intersect with given interval <br/>
  2072. * If no values stored in the tree, returns array of keys which intersect given interval
  2073. * @param {Interval} interval - search interval, or tuple [low, high]
  2074. * @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
  2075. * @returns {Array}
  2076. */
  2077. search(a, e = (t, r) => t === r ? r.output() : t) {
  2078. let t = new Ht(a), r = [];
  2079. return this.tree_search_interval(this.root, t, r), r.map((n) => e(n.item.value, n.item.key));
  2080. }
  2081. /**
  2082. * Returns true if intersection between given and any interval stored in the tree found
  2083. * @param {Interval} interval - search interval or tuple [low, high]
  2084. * @returns {boolean}
  2085. */
  2086. intersect_any(a) {
  2087. let e = new Ht(a);
  2088. return this.tree_find_any_interval(this.root, e);
  2089. }
  2090. /**
  2091. * Tree visitor. For each node implement a callback function. <br/>
  2092. * Method calls a callback function with two parameters (key, value)
  2093. * @param visitor(key,value) - function to be called for each tree item
  2094. */
  2095. forEach(a) {
  2096. this.tree_walk(this.root, (e) => a(e.item.key, e.item.value));
  2097. }
  2098. /**
  2099. * Value Mapper. Walk through every node and map node value to another value
  2100. * @param callback(value,key) - function to be called for each tree item
  2101. */
  2102. map(a) {
  2103. const e = new la();
  2104. return this.tree_walk(this.root, (t) => e.insert(t.item.key, a(t.item.value, t.item.key))), e;
  2105. }
  2106. /**
  2107. * @param {Interval} interval - optional if the iterator is intended to start from the beginning
  2108. * @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
  2109. * @returns {Iterator}
  2110. */
  2111. *iterate(a, e = (t, r) => t === r ? r.output() : t) {
  2112. let t;
  2113. for (a ? t = this.tree_search_nearest_forward(this.root, new Ht(a)) : this.root && (t = this.local_minimum(this.root)); t; )
  2114. yield e(t.item.value, t.item.key), t = this.tree_successor(t);
  2115. }
  2116. recalc_max(a) {
  2117. let e = a;
  2118. for (; e.parent != null; )
  2119. e.parent.update_max(), e = e.parent;
  2120. }
  2121. tree_insert(a) {
  2122. let e = this.root, t = null;
  2123. if (this.root == null || this.root === this.nil_node)
  2124. this.root = a;
  2125. else {
  2126. for (; e !== this.nil_node; )
  2127. t = e, a.less_than(e) ? e = e.left : e = e.right;
  2128. a.parent = t, a.less_than(t) ? t.left = a : t.right = a;
  2129. }
  2130. this.insert_fixup(a);
  2131. }
  2132. // After insertion insert_node may have red-colored parent, and this is a single possible violation
  2133. // Go upwords to the root and re-color until violation will be resolved
  2134. insert_fixup(a) {
  2135. let e, t;
  2136. for (e = a; e !== this.root && e.parent.color === je; )
  2137. e.parent === e.parent.parent.left ? (t = e.parent.parent.right, t.color === je ? (e.parent.color = Ae, t.color = Ae, e.parent.parent.color = je, e = e.parent.parent) : (e === e.parent.right && (e = e.parent, this.rotate_left(e)), e.parent.color = Ae, e.parent.parent.color = je, this.rotate_right(e.parent.parent))) : (t = e.parent.parent.left, t.color === je ? (e.parent.color = Ae, t.color = Ae, e.parent.parent.color = je, e = e.parent.parent) : (e === e.parent.left && (e = e.parent, this.rotate_right(e)), e.parent.color = Ae, e.parent.parent.color = je, this.rotate_left(e.parent.parent)));
  2138. this.root.color = Ae;
  2139. }
  2140. tree_delete(a) {
  2141. let e, t;
  2142. a.left === this.nil_node || a.right === this.nil_node ? e = a : e = this.tree_successor(a), e.left !== this.nil_node ? t = e.left : t = e.right, t.parent = e.parent, e === this.root ? this.root = t : (e === e.parent.left ? e.parent.left = t : e.parent.right = t, e.parent.update_max()), this.recalc_max(t), e !== a && (a.copy_data(e), a.update_max(), this.recalc_max(a)), /*fix_node != this.nil_node && */
  2143. e.color === Ae && this.delete_fixup(t);
  2144. }
  2145. delete_fixup(a) {
  2146. let e = a, t;
  2147. for (; e !== this.root && e.parent != null && e.color === Ae; )
  2148. e === e.parent.left ? (t = e.parent.right, t.color === je && (t.color = Ae, e.parent.color = je, this.rotate_left(e.parent), t = e.parent.right), t.left.color === Ae && t.right.color === Ae ? (t.color = je, e = e.parent) : (t.right.color === Ae && (t.color = je, t.left.color = Ae, this.rotate_right(t), t = e.parent.right), t.color = e.parent.color, e.parent.color = Ae, t.right.color = Ae, this.rotate_left(e.parent), e = this.root)) : (t = e.parent.left, t.color === je && (t.color = Ae, e.parent.color = je, this.rotate_right(e.parent), t = e.parent.left), t.left.color === Ae && t.right.color === Ae ? (t.color = je, e = e.parent) : (t.left.color === Ae && (t.color = je, t.right.color = Ae, this.rotate_left(t), t = e.parent.left), t.color = e.parent.color, e.parent.color = Ae, t.left.color = Ae, this.rotate_right(e.parent), e = this.root));
  2149. e.color = Ae;
  2150. }
  2151. tree_search(a, e) {
  2152. if (!(a == null || a === this.nil_node))
  2153. return e.equal_to(a) ? a : e.less_than(a) ? this.tree_search(a.left, e) : this.tree_search(a.right, e);
  2154. }
  2155. tree_search_nearest_forward(a, e) {
  2156. let t, r = a;
  2157. for (; r && r !== this.nil_node; )
  2158. r.less_than(e) ? r.intersect(e) ? (t = r, r = r.left) : r = r.right : ((!t || r.less_than(t)) && (t = r), r = r.left);
  2159. return t || null;
  2160. }
  2161. // Original search_interval method; container res support push() insertion
  2162. // Search all intervals intersecting given one
  2163. tree_search_interval(a, e, t) {
  2164. a != null && a !== this.nil_node && (a.left !== this.nil_node && !a.not_intersect_left_subtree(e) && this.tree_search_interval(a.left, e, t), a.intersect(e) && t.push(a), a.right !== this.nil_node && !a.not_intersect_right_subtree(e) && this.tree_search_interval(a.right, e, t));
  2165. }
  2166. tree_find_any_interval(a, e) {
  2167. let t = !1;
  2168. return a != null && a !== this.nil_node && (a.left !== this.nil_node && !a.not_intersect_left_subtree(e) && (t = this.tree_find_any_interval(a.left, e)), t || (t = a.intersect(e)), !t && a.right !== this.nil_node && !a.not_intersect_right_subtree(e) && (t = this.tree_find_any_interval(a.right, e))), t;
  2169. }
  2170. local_minimum(a) {
  2171. let e = a;
  2172. for (; e.left != null && e.left !== this.nil_node; )
  2173. e = e.left;
  2174. return e;
  2175. }
  2176. // not in use
  2177. local_maximum(a) {
  2178. let e = a;
  2179. for (; e.right != null && e.right !== this.nil_node; )
  2180. e = e.right;
  2181. return e;
  2182. }
  2183. tree_successor(a) {
  2184. let e, t, r;
  2185. if (a.right !== this.nil_node)
  2186. e = this.local_minimum(a.right);
  2187. else {
  2188. for (t = a, r = a.parent; r != null && r.right === t; )
  2189. t = r, r = r.parent;
  2190. e = r;
  2191. }
  2192. return e;
  2193. }
  2194. // | right-rotate(T,y) |
  2195. // y ---------------. x
  2196. // / \ / \
  2197. // x c left-rotate(T,x) a y
  2198. // / \ <--------------- / \
  2199. // a b b c
  2200. rotate_left(a) {
  2201. let e = a.right;
  2202. a.right = e.left, e.left !== this.nil_node && (e.left.parent = a), e.parent = a.parent, a === this.root ? this.root = e : a === a.parent.left ? a.parent.left = e : a.parent.right = e, e.left = a, a.parent = e, a != null && a !== this.nil_node && a.update_max(), e = a.parent, e != null && e !== this.nil_node && e.update_max();
  2203. }
  2204. rotate_right(a) {
  2205. let e = a.left;
  2206. a.left = e.right, e.right !== this.nil_node && (e.right.parent = a), e.parent = a.parent, a === this.root ? this.root = e : a === a.parent.left ? a.parent.left = e : a.parent.right = e, e.right = a, a.parent = e, a !== null && a !== this.nil_node && a.update_max(), e = a.parent, e != null && e !== this.nil_node && e.update_max();
  2207. }
  2208. tree_walk(a, e) {
  2209. a != null && a !== this.nil_node && (this.tree_walk(a.left, e), e(a), this.tree_walk(a.right, e));
  2210. }
  2211. /* Return true if all red nodes have exactly two black child nodes */
  2212. testRedBlackProperty() {
  2213. let a = !0;
  2214. return this.tree_walk(this.root, function(e) {
  2215. e.color === je && (e.left.color === Ae && e.right.color === Ae || (a = !1));
  2216. }), a;
  2217. }
  2218. /* Throw error if not every path from root to bottom has same black height */
  2219. testBlackHeightProperty(a) {
  2220. let e = 0, t = 0, r = 0;
  2221. if (a.color === Ae && e++, a.left !== this.nil_node ? t = this.testBlackHeightProperty(a.left) : t = 1, a.right !== this.nil_node ? r = this.testBlackHeightProperty(a.right) : r = 1, t !== r)
  2222. throw new Error("Red-black height property violated");
  2223. return e += t, e;
  2224. }
  2225. }
  2226. class Qc {
  2227. constructor() {
  2228. /**
  2229. * {
  2230. * unitId:{
  2231. * sheetId:{
  2232. * 'columnIndex': {
  2233. * 10:[1,3,4,5],
  2234. * 5:[2,6,11,22]
  2235. * }
  2236. * }
  2237. * }
  2238. * }
  2239. */
  2240. A(this, "_cache", /* @__PURE__ */ new Map());
  2241. A(this, "_continueBuildingCache", /* @__PURE__ */ new Map());
  2242. }
  2243. set(a, e, t, r, n) {
  2244. if (!this.shouldContinueBuildingCache(a, e, t, n))
  2245. return;
  2246. let s = this._cache.get(a);
  2247. s == null && (s = /* @__PURE__ */ new Map(), this._cache.set(a, s));
  2248. let o = s.get(e);
  2249. o == null && (o = /* @__PURE__ */ new Map(), s.set(e, o));
  2250. let u = o.get(t);
  2251. u == null && (u = /* @__PURE__ */ new Map(), o.set(t, u));
  2252. let c = u.get(r);
  2253. c == null && (c = /* @__PURE__ */ new Set(), u.set(r, c)), c.add(n);
  2254. }
  2255. getCellValuePositions(a, e, t) {
  2256. var r, n;
  2257. return (n = (r = this._cache.get(a)) == null ? void 0 : r.get(e)) == null ? void 0 : n.get(t);
  2258. }
  2259. getCellPositions(a, e, t, r, n) {
  2260. var o, u, c;
  2261. const s = (c = (u = (o = this._cache.get(a)) == null ? void 0 : o.get(e)) == null ? void 0 : u.get(t)) == null ? void 0 : c.get(r);
  2262. return s && [...s].filter((l) => n.some(([f, h]) => l >= f && l <= h));
  2263. }
  2264. setContinueBuildingCache(a, e, t, r, n) {
  2265. if (t === -1 || r === -1 || n === -1)
  2266. return;
  2267. let s = this._continueBuildingCache.get(a);
  2268. s == null && (s = /* @__PURE__ */ new Map(), this._continueBuildingCache.set(a, s));
  2269. let o = s.get(e);
  2270. o == null && (o = /* @__PURE__ */ new Map(), s.set(e, o));
  2271. let u = o.get(t);
  2272. if (u == null) {
  2273. u = new la(), u.insert([r, n]), o.set(t, u);
  2274. return;
  2275. }
  2276. this._handleNewInterval(u, r, n);
  2277. }
  2278. shouldContinueBuildingCache(a, e, t, r) {
  2279. var o, u;
  2280. if (t === -1 || r === -1)
  2281. return !1;
  2282. const n = (u = (o = this._continueBuildingCache.get(a)) == null ? void 0 : o.get(e)) == null ? void 0 : u.get(t);
  2283. return n ? n.search([r, r]).length === 0 : !0;
  2284. }
  2285. canUseCache(a, e, t, r, n) {
  2286. var f, h;
  2287. const s = (h = (f = this._continueBuildingCache.get(a)) == null ? void 0 : f.get(e)) == null ? void 0 : h.get(t);
  2288. if (t === -1 || r === -1 || n === -1 || !s)
  2289. return {
  2290. rowsInCache: [],
  2291. rowsNotInCache: []
  2292. };
  2293. const o = s.search([r, n]);
  2294. if (o.length === 0)
  2295. return {
  2296. rowsInCache: [],
  2297. rowsNotInCache: []
  2298. };
  2299. o.sort((d, _) => d[0] - _[0]);
  2300. const u = [], c = [];
  2301. let l = r;
  2302. for (let d = 0; d < o.length; d++) {
  2303. const [_, C] = o[d];
  2304. if (l >= _) {
  2305. if (n <= C) {
  2306. u.push([l, n]);
  2307. break;
  2308. }
  2309. u.push([l, C]), l = C + 1, d === o.length - 1 && l <= n && c.push([l, n]);
  2310. } else {
  2311. if (n > C) {
  2312. u.push([_, C]), c.push([l, _ - 1]), l = C + 1, d === o.length - 1 && l <= n && c.push([l, n]);
  2313. continue;
  2314. }
  2315. u.push([_, n]), c.push([l, _ - 1]);
  2316. }
  2317. }
  2318. return {
  2319. rowsInCache: u,
  2320. rowsNotInCache: c
  2321. };
  2322. }
  2323. clear() {
  2324. this._cache.clear(), this._continueBuildingCache.clear();
  2325. }
  2326. _handleNewInterval(a, e, t) {
  2327. let r = a.search([e, t]);
  2328. if (r.length === 0) {
  2329. const o = [e - 1 < 0 ? 0 : e - 1, t + 1];
  2330. if (r = a.search(o), r.length === 0) {
  2331. a.insert([e, t]);
  2332. return;
  2333. }
  2334. }
  2335. let n = e, s = t;
  2336. for (const o of r)
  2337. n = Math.min(n, o[0]), s = Math.max(s, o[1]), a.remove(o);
  2338. a.insert([n, s]);
  2339. }
  2340. }
  2341. const St = new Qc(), fa = "engine-formula.config", so = 1, Hb = "CYCLE_REFERENCE_COUNT", ai = {};
  2342. var Wc = Object.defineProperty, qc = Object.getOwnPropertyDescriptor, Kc = (i, a, e, t) => {
  2343. for (var r = t > 1 ? void 0 : t ? qc(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  2344. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  2345. return t && r && Wc(a, e, r), r;
  2346. }, ii = (i, a) => (e, t) => a(e, t, i);
  2347. let ws = class extends Me {
  2348. constructor(a, e) {
  2349. super();
  2350. A(this, "_unitData", {});
  2351. A(this, "_unitStylesData", {});
  2352. A(this, "_arrayFormulaCellData", {});
  2353. A(this, "_arrayFormulaRange", {});
  2354. A(this, "_formulaData", {});
  2355. A(this, "_sheetNameMap", {});
  2356. A(this, "_forceCalculate", !1);
  2357. A(this, "_clearDependencyTreeCache", {});
  2358. A(this, "_dirtyRanges", []);
  2359. A(this, "_dirtyNameMap", {});
  2360. A(this, "_dirtyDefinedNameMap", {});
  2361. A(this, "_dirtyUnitFeatureMap", {});
  2362. A(this, "_dirtyUnitOtherFormulaMap", {});
  2363. A(this, "_excludedCell");
  2364. A(this, "_sheetIdToNameMap", {});
  2365. A(this, "_executeUnitId", "");
  2366. A(this, "_executeSubUnitId", "");
  2367. this._univerInstanceService = a, this._localeService = e;
  2368. }
  2369. dispose() {
  2370. this._unitData = {}, this._unitStylesData = {}, this._formulaData = {}, this._arrayFormulaCellData = {}, this._arrayFormulaRange = {}, this._sheetNameMap = {}, this._dirtyRanges = [], this._dirtyNameMap = {}, this._dirtyDefinedNameMap = {}, this._dirtyUnitFeatureMap = {}, this._excludedCell = {}, this._sheetIdToNameMap = {}, this._dirtyUnitOtherFormulaMap = {};
  2371. }
  2372. getExecuteUnitId() {
  2373. return this._executeUnitId;
  2374. }
  2375. getExecuteSubUnitId() {
  2376. return this._executeSubUnitId;
  2377. }
  2378. setExecuteUnitId(a) {
  2379. this._executeUnitId = a;
  2380. }
  2381. setExecuteSubUnitId(a) {
  2382. this._executeSubUnitId = a;
  2383. }
  2384. getExcludedRange() {
  2385. return this._excludedCell;
  2386. }
  2387. getUnitData() {
  2388. return this._unitData;
  2389. }
  2390. getUnitStylesData() {
  2391. return this._unitStylesData;
  2392. }
  2393. getFormulaData() {
  2394. return this._formulaData;
  2395. }
  2396. getArrayFormulaCellData() {
  2397. return this._arrayFormulaCellData;
  2398. }
  2399. getArrayFormulaRange() {
  2400. return this._arrayFormulaRange;
  2401. }
  2402. getSheetNameMap() {
  2403. return this._sheetNameMap;
  2404. }
  2405. isForceCalculate() {
  2406. return this._forceCalculate;
  2407. }
  2408. getDirtyRanges() {
  2409. return this._dirtyRanges;
  2410. }
  2411. getDirtyNameMap() {
  2412. return this._dirtyNameMap;
  2413. }
  2414. getDirtyDefinedNameMap() {
  2415. return this._dirtyDefinedNameMap;
  2416. }
  2417. getDirtyUnitFeatureMap() {
  2418. return this._dirtyUnitFeatureMap;
  2419. }
  2420. getDirtyUnitOtherFormulaMap() {
  2421. return this._dirtyUnitOtherFormulaMap;
  2422. }
  2423. getSheetName(a, e) {
  2424. return this._sheetIdToNameMap[a] == null ? "" : this._sheetIdToNameMap[a][e] || "";
  2425. }
  2426. getClearDependencyTreeCache() {
  2427. return this._clearDependencyTreeCache;
  2428. }
  2429. getLocale() {
  2430. return this._localeService.getCurrentLocale();
  2431. }
  2432. getSheetsInfo() {
  2433. const a = this._univerInstanceService.getCurrentUnitForType(Dr.UNIVER_SHEET), { id: e, sheetOrder: t } = a.getSnapshot();
  2434. return {
  2435. sheetOrder: t,
  2436. sheetNameMap: this._sheetIdToNameMap[e]
  2437. };
  2438. }
  2439. getSheetRowColumnCount(a, e) {
  2440. const t = this._univerInstanceService.getUnit(a), r = t == null ? void 0 : t.getSheetBySheetId(e), n = r == null ? void 0 : r.getSnapshot();
  2441. if (!n)
  2442. return { rowCount: 0, columnCount: 0 };
  2443. const { rowCount: s, columnCount: o } = n;
  2444. return { rowCount: s, columnCount: o };
  2445. }
  2446. load(a) {
  2447. if (a.allUnitData && a.unitSheetNameMap && a.unitStylesData)
  2448. this._unitData = a.allUnitData, this._unitStylesData = a.unitStylesData, this._sheetNameMap = a.unitSheetNameMap;
  2449. else {
  2450. const { allUnitData: e, unitSheetNameMap: t, unitStylesData: r } = this._loadSheetData();
  2451. this._unitData = e, this._unitStylesData = r, this._sheetNameMap = t;
  2452. }
  2453. this._formulaData = a.formulaData, this._arrayFormulaCellData = oc(a.arrayFormulaCellData), this._arrayFormulaRange = a.arrayFormulaRange, this._forceCalculate = a.forceCalculate, this._clearDependencyTreeCache = a.clearDependencyTreeCache || {}, this._dirtyRanges = a.dirtyRanges, this._dirtyNameMap = a.dirtyNameMap, this._dirtyDefinedNameMap = a.dirtyDefinedNameMap, this._dirtyUnitFeatureMap = a.dirtyUnitFeatureMap, this._dirtyUnitOtherFormulaMap = a.dirtyUnitOtherFormulaMap, this._excludedCell = a.excludedCell, this._mergeNameMap(this._sheetNameMap, this._dirtyNameMap);
  2454. }
  2455. getDirtyData() {
  2456. return {
  2457. forceCalculation: this._forceCalculate,
  2458. dirtyRanges: this._dirtyRanges,
  2459. dirtyNameMap: this._dirtyNameMap,
  2460. dirtyDefinedNameMap: this._dirtyDefinedNameMap,
  2461. dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
  2462. dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
  2463. clearDependencyTreeCache: this._clearDependencyTreeCache
  2464. };
  2465. }
  2466. loadDirtyRangesAndExcludedCell(a, e) {
  2467. this._dirtyRanges = a, this._excludedCell = e, this._dirtyNameMap = {};
  2468. }
  2469. registerUnitData(a) {
  2470. this._unitData = a;
  2471. }
  2472. registerFormulaData(a) {
  2473. this._formulaData = a;
  2474. }
  2475. registerSheetNameMap(a) {
  2476. this._sheetNameMap = a;
  2477. }
  2478. // private _loadOtherFormulaData() {
  2479. // const unitAllDoc = this._univerInstanceService.getAllUniverDocsInstance();
  2480. // const unitAllSlide = this._univerInstanceService.getAllUniverSlidesInstance();
  2481. // const otherFormulaData: IOtherFormulaData = {};
  2482. // for (const documentDataModel of unitAllDoc) {
  2483. // const unitId = documentDataModel.getUnitId();
  2484. // if (otherFormulaData[unitId] == null) {
  2485. // otherFormulaData[unitId] = {};
  2486. // }
  2487. // if (otherFormulaData[unitId][DEFAULT_DOCUMENT_SUB_COMPONENT_ID] == null) {
  2488. // otherFormulaData[unitId][DEFAULT_DOCUMENT_SUB_COMPONENT_ID] = {};
  2489. // }
  2490. // const subComponent = otherFormulaData[unitId][DEFAULT_DOCUMENT_SUB_COMPONENT_ID];
  2491. // const customRanges = documentDataModel.getBody()?.customRanges;
  2492. // if (customRanges == null) {
  2493. // continue;
  2494. // }
  2495. // for (const customRange of customRanges) {
  2496. // subComponent[customRange.rangeId] = {
  2497. // f: customRange.endIndex.toString(),
  2498. // };
  2499. // }
  2500. // }
  2501. // for (const slide of unitAllSlide) {
  2502. // const unitId = slide.getUnitId();
  2503. // if (otherFormulaData[unitId] == null) {
  2504. // otherFormulaData[unitId] = {};
  2505. // }
  2506. // if (otherFormulaData[unitId][DEFAULT_DOCUMENT_SUB_COMPONENT_ID] == null) {
  2507. // otherFormulaData[unitId][DEFAULT_DOCUMENT_SUB_COMPONENT_ID] = {};
  2508. // }
  2509. // const pages = slide.getPages();
  2510. // if (pages == null) {
  2511. // continue;
  2512. // }
  2513. // const pageIds = Object.keys(pages);
  2514. // for (const pageId of pageIds) {
  2515. // const page = pages[pageId];
  2516. // const subComponent = otherFormulaData[unitId][pageId];
  2517. // const pageElements = page.pageElements;
  2518. // if (pageElements == null) {
  2519. // continue;
  2520. // }
  2521. // const pageElementIds = Object.keys(pageElements);
  2522. // for (const pageElementId of pageElementIds) {
  2523. // const pageElement = pageElements[pageElementId];
  2524. // subComponent[pageElementId] = {
  2525. // f: pageElement.title,
  2526. // };
  2527. // }
  2528. // }
  2529. // }
  2530. // return otherFormulaData;
  2531. // }
  2532. _mergeNameMap(a, e) {
  2533. Object.keys(e).forEach((t) => {
  2534. e[t] && Object.keys(e[t]).forEach((r) => {
  2535. a[t] == null && (a[t] = {}), a[t][e[t][r]] = r;
  2536. });
  2537. }), this._sheetIdToNameMap = {}, Object.keys(a).forEach((t) => {
  2538. Object.keys(a[t]).forEach((r) => {
  2539. this._sheetIdToNameMap[t] == null && (this._sheetIdToNameMap[t] = {}), this._sheetIdToNameMap[t][a[t][r]] = r;
  2540. });
  2541. });
  2542. }
  2543. _loadSheetData() {
  2544. const a = this._univerInstanceService.getAllUnitsForType(Dr.UNIVER_SHEET), e = this._univerInstanceService.getCurrentUnitForType(Dr.UNIVER_SHEET), t = e == null ? void 0 : e.getActiveSheet();
  2545. this._executeUnitId = e == null ? void 0 : e.getUnitId(), this._executeSubUnitId = t == null ? void 0 : t.getSheetId();
  2546. const r = {}, n = {}, s = {};
  2547. for (const o of a) {
  2548. const u = o.getUnitId(), c = o.getSheets(), l = {}, f = {};
  2549. for (const h of c) {
  2550. const d = h.getSheetId(), _ = h.getConfig();
  2551. l[d] = {
  2552. cellData: new Ce(_.cellData),
  2553. rowCount: _.rowCount,
  2554. columnCount: _.columnCount,
  2555. rowData: _.rowData,
  2556. columnData: _.columnData,
  2557. defaultRowHeight: _.defaultRowHeight,
  2558. defaultColumnWidth: _.defaultColumnWidth
  2559. }, f[h.getName()] = h.getSheetId();
  2560. }
  2561. r[u] = l, n[u] = o.getStyles(), s[u] = f;
  2562. }
  2563. return {
  2564. allUnitData: r,
  2565. unitStylesData: n,
  2566. unitSheetNameMap: s
  2567. };
  2568. }
  2569. };
  2570. ws = Kc([
  2571. ii(0, Js),
  2572. ii(1, Ve($u))
  2573. ], ws);
  2574. const Ft = lt(
  2575. "univer.formula.current-data.service"
  2576. );
  2577. var Xc = Object.defineProperty, Zc = Object.getOwnPropertyDescriptor, zc = (i, a, e, t) => {
  2578. for (var r = t > 1 ? void 0 : t ? Zc(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  2579. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  2580. return t && r && Xc(a, e, r), r;
  2581. }, is = (i, a) => (e, t) => a(e, t, i);
  2582. let gr = class extends Me {
  2583. constructor(i, a, e) {
  2584. super(), this._definedNamesService = i, this._lexerTreeBuilder = a, this._formulaCurrentConfigService = e;
  2585. }
  2586. treeBuilder(i, a = !0) {
  2587. return this._lexerTreeBuilder.treeBuilder(i, a, this._injectDefinedName.bind(this), this._simpleCheckDefinedName.bind(this));
  2588. }
  2589. _simpleCheckDefinedName(i) {
  2590. const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
  2591. if (e != null && a[e] != null) {
  2592. const t = Object.keys(a[e]);
  2593. for (let r = 0, n = t.length; r < n; r++) {
  2594. const s = t[r];
  2595. if (i.indexOf(s) > -1)
  2596. return !0;
  2597. }
  2598. }
  2599. return !1;
  2600. }
  2601. _checkDefinedNameDirty(i) {
  2602. const a = this._formulaCurrentConfigService.getDirtyDefinedNameMap(), e = this._formulaCurrentConfigService.getExecuteUnitId();
  2603. if (e != null && a[e] != null) {
  2604. const t = Object.keys(a[e]);
  2605. for (let r = 0, n = t.length; r < n; r++)
  2606. if (t[r] === i)
  2607. return !0;
  2608. }
  2609. return !1;
  2610. }
  2611. _injectDefinedName(i) {
  2612. const a = this._formulaCurrentConfigService.getExecuteUnitId();
  2613. if (a == null)
  2614. return {
  2615. sequenceString: "",
  2616. hasDefinedName: !1,
  2617. definedNames: []
  2618. };
  2619. const e = this._lexerTreeBuilder.getSequenceNode(i);
  2620. let t = "", r = !1;
  2621. const n = [];
  2622. for (let s = 0, o = e.length; s < o; s++) {
  2623. const u = e[s];
  2624. if (typeof u == "string") {
  2625. t += u;
  2626. continue;
  2627. }
  2628. const { nodeType: c, token: l } = u;
  2629. if (c === $e.REFERENCE || c === $e.FUNCTION) {
  2630. const f = this._definedNamesService.getValueByName(a, l);
  2631. if (f) {
  2632. let h = f.formulaOrRefString;
  2633. h.substring(0, 1) === X.EQUALS && (h = h.substring(1)), t += h, n.push(f.name), r = !0;
  2634. } else this._checkDefinedNameDirty(l) ? (t += m.NAME, r = !0, n.push(l)) : t += l;
  2635. } else
  2636. t += l;
  2637. }
  2638. return {
  2639. sequenceString: t,
  2640. hasDefinedName: r,
  2641. definedNames: n
  2642. };
  2643. }
  2644. };
  2645. gr = zc([
  2646. is(0, pr),
  2647. is(1, Ve(ca)),
  2648. is(2, Ft)
  2649. ], gr);
  2650. function nn(i) {
  2651. if (i == null)
  2652. return !0;
  2653. const { v: a, f: e, si: t, p: r } = i;
  2654. return !(!(a == null || typeof a == "string" && a.length === 0) || e != null && e.length > 0 || t != null && t.length > 0 || r != null);
  2655. }
  2656. function ao(i, a, e, t, r) {
  2657. var s;
  2658. const n = Object.keys(r);
  2659. for (const o of n) {
  2660. const u = r[o], c = (s = u == null ? void 0 : u[t]) == null ? void 0 : s[e];
  2661. if (c == null)
  2662. continue;
  2663. const l = c.getValue(i, a);
  2664. if (l != null)
  2665. return l;
  2666. }
  2667. }
  2668. const Jc = [
  2669. "$",
  2670. "£",
  2671. "¥",
  2672. "¤",
  2673. "֏",
  2674. "؋",
  2675. "৳",
  2676. "฿",
  2677. "៛",
  2678. "₡",
  2679. "₦",
  2680. "₩",
  2681. "₪",
  2682. "₫",
  2683. "€",
  2684. "₭",
  2685. "₮",
  2686. "₱",
  2687. "₲",
  2688. "₴",
  2689. "₸",
  2690. "₹",
  2691. "₺",
  2692. "₼",
  2693. "₽",
  2694. "₾",
  2695. "₿"
  2696. ], el = {
  2697. currency: 2,
  2698. date: 4,
  2699. datetime: 5,
  2700. error: 11,
  2701. fraction: 7,
  2702. general: 0,
  2703. grouped: 11,
  2704. number: 1,
  2705. percent: 6,
  2706. scientific: 8,
  2707. text: 9,
  2708. time: 5,
  2709. unknown: 11
  2710. /* Custom */
  2711. };
  2712. function Gb(i, a, e) {
  2713. var u, c;
  2714. if (i == null || a == null)
  2715. return a;
  2716. const t = (e == null ? void 0 : e.getStyleByCell(i)) || i.s, r = (e == null ? void 0 : e.getStyleByCell(a)) || a.s;
  2717. if (t == null || r == null || typeof t != "object" || typeof r != "object")
  2718. return a;
  2719. const n = (u = t == null ? void 0 : t.n) == null ? void 0 : u.pattern, s = (c = r == null ? void 0 : r.n) == null ? void 0 : c.pattern;
  2720. if (n == null || s == null)
  2721. return a;
  2722. const o = n || s;
  2723. return r.n.pattern = o, a;
  2724. }
  2725. const Ds = new Vt(1e5);
  2726. function oi(i) {
  2727. const a = Ds.get(i);
  2728. if (a !== void 0)
  2729. return a;
  2730. const e = rl(i);
  2731. return Ds.set(i, e), e;
  2732. }
  2733. function tl() {
  2734. Ds.clear();
  2735. }
  2736. function rl(i) {
  2737. if (nl(i))
  2738. return 3;
  2739. const a = gt.getInfo(i).type || "unknown";
  2740. return el[a];
  2741. }
  2742. function nl(i) {
  2743. return !!Jc.find((a) => i.includes(a)) && i.startsWith("_(");
  2744. }
  2745. function Wr(i, a, e) {
  2746. if (i === "")
  2747. return a;
  2748. if (a === "")
  2749. return i;
  2750. const t = oi(i), r = oi(a);
  2751. return e === X.PLUS || e === X.MINUS ? t === 4 && r === 4 || t === 11 && r === 11 ? "" : a : e === X.MULTIPLY || e === X.DIVIDED ? t === 6 && r === 6 || t === 7 && r === 7 || t === 8 && r === 8 || t === 9 && r === 9 ? a : "" : i || a;
  2752. }
  2753. const sl = /* @__PURE__ */ new Map([
  2754. [Mr.EN_US, "$"],
  2755. // [LocaleType.JA_JP, '¥'],
  2756. [Mr.RU_RU, "₽"],
  2757. [Mr.VI_VN, "₫"],
  2758. [Mr.ZH_CN, "¥"],
  2759. [Mr.ZH_TW, "NT$"]
  2760. ]);
  2761. function ui(i) {
  2762. return sl.get(i) || "$";
  2763. }
  2764. function Ke(i, a = 2) {
  2765. let e = a;
  2766. a > 127 && (e = 127);
  2767. let t = "";
  2768. return e > 0 && (t = `.${"0".repeat(e)}`), `"${ui(i)}"#,##0${t}_);[Red]("${ui(i)}"#,##0${t})`;
  2769. }
  2770. function al(i, a, e = 2) {
  2771. return gt.format(Ke(i, e), a);
  2772. }
  2773. const ha = new Vt(1e5);
  2774. function il(i) {
  2775. let a = i;
  2776. a.startsWith('"') && a.endsWith('"') && (a = a.slice(1, -1));
  2777. const e = ha.get(a);
  2778. if (e)
  2779. return {
  2780. isNumberPattern: !0,
  2781. value: e.value,
  2782. pattern: e.pattern
  2783. };
  2784. const t = gt.parseNumber(a);
  2785. if (t && t.z)
  2786. return os(a, t.v, t.z);
  2787. const r = gt.parseDate(a);
  2788. if (r && r.z)
  2789. return os(a, r.v, r.z);
  2790. const n = gt.parseTime(a);
  2791. return n && n.z ? os(a, n.v, n.z) : {
  2792. isNumberPattern: !1
  2793. };
  2794. }
  2795. function os(i, a, e) {
  2796. return ha.set(i, {
  2797. value: a,
  2798. pattern: e
  2799. }), {
  2800. isNumberPattern: !0,
  2801. value: a,
  2802. pattern: e
  2803. };
  2804. }
  2805. function ol() {
  2806. ha.clear();
  2807. }
  2808. class jn {
  2809. constructor() {
  2810. A(this, "pattern", "");
  2811. }
  2812. dispose() {
  2813. }
  2814. getPattern() {
  2815. return this.pattern;
  2816. }
  2817. /**
  2818. * Only used in NumberValueObject
  2819. * @param pattern
  2820. */
  2821. setPattern(a) {
  2822. this.pattern = a;
  2823. }
  2824. isError() {
  2825. return !1;
  2826. }
  2827. isAsyncObject() {
  2828. return !1;
  2829. }
  2830. isAsyncArrayObject() {
  2831. return !1;
  2832. }
  2833. isReferenceObject() {
  2834. return !1;
  2835. }
  2836. isArray() {
  2837. return !1;
  2838. }
  2839. isValueObject() {
  2840. return !1;
  2841. }
  2842. isEqualType(a) {
  2843. return !1;
  2844. }
  2845. }
  2846. class kt extends jn {
  2847. constructor(a) {
  2848. super(), this._rawValue = a;
  2849. }
  2850. isValueObject() {
  2851. return !0;
  2852. }
  2853. toUnitRange() {
  2854. return {
  2855. range: {
  2856. startColumn: -1,
  2857. startRow: -1,
  2858. endRow: -1,
  2859. endColumn: -1
  2860. },
  2861. sheetId: "",
  2862. unitId: ""
  2863. };
  2864. }
  2865. getValue() {
  2866. return 0;
  2867. }
  2868. getArrayValue() {
  2869. return [];
  2870. }
  2871. setValue(a) {
  2872. }
  2873. setArrayValue(a) {
  2874. }
  2875. isCube() {
  2876. return !1;
  2877. }
  2878. isString() {
  2879. return !1;
  2880. }
  2881. isNumber() {
  2882. return !1;
  2883. }
  2884. isBoolean() {
  2885. return !1;
  2886. }
  2887. isLambda() {
  2888. return !1;
  2889. }
  2890. isError() {
  2891. return !1;
  2892. }
  2893. isNull() {
  2894. return !1;
  2895. }
  2896. sum() {
  2897. return g.create(m.VALUE);
  2898. }
  2899. max() {
  2900. return g.create(m.VALUE);
  2901. }
  2902. min() {
  2903. return g.create(m.VALUE);
  2904. }
  2905. count() {
  2906. return g.create(m.VALUE);
  2907. }
  2908. countA() {
  2909. return g.create(m.VALUE);
  2910. }
  2911. countBlank() {
  2912. return g.create(m.VALUE);
  2913. }
  2914. getNegative() {
  2915. return g.create(m.VALUE);
  2916. }
  2917. getReciprocal() {
  2918. return g.create(m.VALUE);
  2919. }
  2920. plus(a) {
  2921. return g.create(m.VALUE);
  2922. }
  2923. minus(a) {
  2924. return g.create(m.VALUE);
  2925. }
  2926. multiply(a) {
  2927. return g.create(m.VALUE);
  2928. }
  2929. divided(a) {
  2930. return g.create(m.VALUE);
  2931. }
  2932. mod(a) {
  2933. return g.create(m.VALUE);
  2934. }
  2935. /**
  2936. * return every value in the array after the callback function, excluding the error value
  2937. * @param callbackFn
  2938. * @returns
  2939. */
  2940. map(a) {
  2941. return g.create(m.NAME);
  2942. }
  2943. /**
  2944. * return every value in the array after the callback function
  2945. * @param callbackFn
  2946. * @returns
  2947. */
  2948. mapValue(a) {
  2949. return g.create(m.NAME);
  2950. }
  2951. compare(a, e, t = !1) {
  2952. return g.create(m.NAME);
  2953. }
  2954. isEqual(a) {
  2955. return this.compare(a, $.EQUALS);
  2956. }
  2957. isNotEqual(a) {
  2958. return this.compare(a, $.NOT_EQUAL);
  2959. }
  2960. isGreaterThanOrEqual(a) {
  2961. return this.compare(a, $.GREATER_THAN_OR_EQUAL);
  2962. }
  2963. isLessThanOrEqual(a) {
  2964. return this.compare(a, $.LESS_THAN_OR_EQUAL);
  2965. }
  2966. isLessThan(a) {
  2967. return this.compare(a, $.LESS_THAN);
  2968. }
  2969. isGreaterThan(a) {
  2970. return this.compare(a, $.GREATER_THAN);
  2971. }
  2972. concatenateFront(a) {
  2973. return g.create(m.NAME);
  2974. }
  2975. concatenateBack(a) {
  2976. return g.create(m.NAME);
  2977. }
  2978. plusBy(a) {
  2979. return g.create(m.VALUE);
  2980. }
  2981. minusBy(a) {
  2982. return g.create(m.VALUE);
  2983. }
  2984. multiplyBy(a) {
  2985. return g.create(m.VALUE);
  2986. }
  2987. dividedBy(a) {
  2988. return g.create(m.VALUE);
  2989. }
  2990. modInverse(a) {
  2991. return g.create(m.VALUE);
  2992. }
  2993. compareBy(a, e) {
  2994. return g.create(m.NAME);
  2995. }
  2996. concatenate(a, e = it.FRONT) {
  2997. let t = this.getValue().toString();
  2998. if (typeof a == "string")
  2999. e === it.FRONT ? t = a + t : t += a;
  3000. else if (typeof a == "number")
  3001. e === it.FRONT ? t = a.toString() + t : t += a.toString();
  3002. else if (typeof a == "boolean") {
  3003. const r = a ? "TRUE" : "FALSE";
  3004. e === it.FRONT ? t = r + t : t += r;
  3005. }
  3006. return t;
  3007. }
  3008. pow(a) {
  3009. return g.create(m.VALUE);
  3010. }
  3011. powInverse(a) {
  3012. return g.create(m.VALUE);
  3013. }
  3014. sqrt() {
  3015. return g.create(m.VALUE);
  3016. }
  3017. cbrt() {
  3018. return g.create(m.VALUE);
  3019. }
  3020. cos() {
  3021. return g.create(m.VALUE);
  3022. }
  3023. cosh() {
  3024. return g.create(m.VALUE);
  3025. }
  3026. acos() {
  3027. return g.create(m.VALUE);
  3028. }
  3029. acosh() {
  3030. return g.create(m.VALUE);
  3031. }
  3032. sin() {
  3033. return g.create(m.VALUE);
  3034. }
  3035. sinh() {
  3036. return g.create(m.VALUE);
  3037. }
  3038. asin() {
  3039. return g.create(m.VALUE);
  3040. }
  3041. asinh() {
  3042. return g.create(m.VALUE);
  3043. }
  3044. tan() {
  3045. return g.create(m.VALUE);
  3046. }
  3047. tanh() {
  3048. return g.create(m.VALUE);
  3049. }
  3050. atan() {
  3051. return g.create(m.VALUE);
  3052. }
  3053. atan2(a) {
  3054. return g.create(m.VALUE);
  3055. }
  3056. atan2Inverse(a) {
  3057. return g.create(m.VALUE);
  3058. }
  3059. atanh() {
  3060. return g.create(m.VALUE);
  3061. }
  3062. /**
  3063. * Calculate the mean of the entire array.
  3064. *
  3065. * reference https://numpy.org/doc/stable/reference/generated/numpy.mean.html#numpy.mean
  3066. *
  3067. */
  3068. mean() {
  3069. return this;
  3070. }
  3071. /**
  3072. * Calculate the median of the entire array.
  3073. *
  3074. * reference https://numpy.org/doc/stable/reference/generated/numpy.median.html
  3075. *
  3076. */
  3077. median() {
  3078. return this;
  3079. }
  3080. /**
  3081. * Calculate the variance of the entire array.
  3082. *
  3083. * reference https://numpy.org/doc/stable/reference/generated/numpy.var.html
  3084. */
  3085. var() {
  3086. return this;
  3087. }
  3088. /**
  3089. * Calculate the standard deviation of the entire array.
  3090. *
  3091. * reference https://numpy.org/doc/stable/reference/generated/numpy.std.html
  3092. */
  3093. std() {
  3094. return this;
  3095. }
  3096. log() {
  3097. return g.create(m.VALUE);
  3098. }
  3099. log10() {
  3100. return g.create(m.VALUE);
  3101. }
  3102. exp() {
  3103. return g.create(m.VALUE);
  3104. }
  3105. abs() {
  3106. return g.create(m.VALUE);
  3107. }
  3108. round(a) {
  3109. return g.create(m.VALUE);
  3110. }
  3111. roundInverse(a) {
  3112. return g.create(m.VALUE);
  3113. }
  3114. floor(a) {
  3115. return g.create(m.VALUE);
  3116. }
  3117. floorInverse(a) {
  3118. return g.create(m.VALUE);
  3119. }
  3120. ceil(a) {
  3121. return g.create(m.VALUE);
  3122. }
  3123. ceilInverse(a) {
  3124. return g.create(m.VALUE);
  3125. }
  3126. convertToNumberObjectValue() {
  3127. return g.create(m.VALUE);
  3128. }
  3129. convertToBooleanObjectValue() {
  3130. return g.create(m.VALUE);
  3131. }
  3132. }
  3133. const ul = 1e3, ci = new Vt(ul);
  3134. class g extends kt {
  3135. constructor(a, e = "") {
  3136. super(a), this._errorType = a, this._errorContent = e;
  3137. }
  3138. static create(a, e = "") {
  3139. const t = `${a}-${e}`, r = ci.get(t);
  3140. if (r)
  3141. return r;
  3142. const n = new g(a, e);
  3143. return ci.set(t, n), n;
  3144. }
  3145. getValue() {
  3146. return this._errorType;
  3147. }
  3148. getErrorType() {
  3149. return this._errorType;
  3150. }
  3151. getErrorContent() {
  3152. return this._errorContent;
  3153. }
  3154. isEqualType(a) {
  3155. return a.getErrorType() === this.getErrorType();
  3156. }
  3157. isError() {
  3158. return !0;
  3159. }
  3160. }
  3161. function cl(i) {
  3162. if (i === null)
  3163. return 0;
  3164. if (i != null && i.p) {
  3165. const a = i == null ? void 0 : i.p.body;
  3166. if (a == null)
  3167. return 0;
  3168. const e = a.dataStream;
  3169. return Yu.transform.getPlainText(e);
  3170. }
  3171. return (i == null ? void 0 : i.v) || 0;
  3172. }
  3173. var Wt = /* @__PURE__ */ ((i) => (i[i.MIN = 0] = "MIN", i[i.MAX = 1] = "MAX", i))(Wt || {}), Pe = /* @__PURE__ */ ((i) => (i[i.NORMAL = 0] = "NORMAL", i[i.MIN = 1] = "MIN", i[i.MAX = 2] = "MAX", i))(Pe || {});
  3174. function hn() {
  3175. return Intl && Intl.Collator ? new Intl.Collator(void 0, { numeric: !1 }).compare : (i, a) => i.localeCompare(a);
  3176. }
  3177. function ll(i) {
  3178. return i.indexOf("*") > -1 || i.indexOf("?") > -1;
  3179. }
  3180. function us(i, a) {
  3181. const e = hl(a).replace(/~?[*?]/g, (r) => r.startsWith("~") ? `\\${r.substring(1)}` : r === "*" ? ".*" : r === "?" ? "." : r);
  3182. return new RegExp(`^${e}$`).test(i);
  3183. }
  3184. function li(i) {
  3185. return i.replace(/~?[*?]/g, (a) => a.startsWith("~") ? a.substring(1) : " ");
  3186. }
  3187. function fl(i, a, e) {
  3188. let t = !1;
  3189. switch (e) {
  3190. case $.EQUALS:
  3191. t = us(i, a);
  3192. break;
  3193. case $.NOT_EQUAL:
  3194. t = !us(i, a);
  3195. break;
  3196. case $.GREATER_THAN:
  3197. case $.GREATER_THAN_OR_EQUAL:
  3198. t = us(i, a) || i > li(a);
  3199. break;
  3200. case $.LESS_THAN:
  3201. case $.LESS_THAN_OR_EQUAL:
  3202. t = i < li(a);
  3203. break;
  3204. }
  3205. return t;
  3206. }
  3207. function hl(i) {
  3208. return i.replace(/[.+^${}()|[\]\\]/g, "\\$&");
  3209. }
  3210. function Ss(i) {
  3211. switch (i) {
  3212. case 1:
  3213. return 2;
  3214. case 0:
  3215. return 0;
  3216. case -1:
  3217. return 1;
  3218. default:
  3219. return 0;
  3220. }
  3221. }
  3222. function Ps(i) {
  3223. return i === -2 ? 1 : 0;
  3224. }
  3225. function ma(i) {
  3226. let a;
  3227. switch (i) {
  3228. case $.EQUALS:
  3229. a = $.EQUALS;
  3230. break;
  3231. case $.GREATER_THAN:
  3232. a = $.LESS_THAN;
  3233. break;
  3234. case $.GREATER_THAN_OR_EQUAL:
  3235. a = $.LESS_THAN_OR_EQUAL;
  3236. break;
  3237. case $.LESS_THAN:
  3238. a = $.GREATER_THAN;
  3239. break;
  3240. case $.LESS_THAN_OR_EQUAL:
  3241. a = $.GREATER_THAN_OR_EQUAL;
  3242. break;
  3243. case $.NOT_EQUAL:
  3244. a = $.NOT_EQUAL;
  3245. break;
  3246. }
  3247. return a;
  3248. }
  3249. /*!
  3250. * decimal.js v10.4.3
  3251. * An arbitrary-precision Decimal type for JavaScript.
  3252. * https://github.com/MikeMcl/decimal.js
  3253. * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
  3254. * MIT Licence
  3255. */
  3256. var Ls = 9e15, $t = 1e9, xs = "0123456789abcdef", mn = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058", gn = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789", js = {
  3257. // These values must be integers within the stated ranges (inclusive).
  3258. // Most of these values can be changed at run-time using the `Decimal.config` method.
  3259. // The maximum number of significant digits of the result of a calculation or base conversion.
  3260. // E.g. `Decimal.config({ precision: 20 });`
  3261. precision: 20,
  3262. // 1 to MAX_DIGITS
  3263. // The rounding mode used when rounding to `precision`.
  3264. //
  3265. // ROUND_UP 0 Away from zero.
  3266. // ROUND_DOWN 1 Towards zero.
  3267. // ROUND_CEIL 2 Towards +Infinity.
  3268. // ROUND_FLOOR 3 Towards -Infinity.
  3269. // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
  3270. // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
  3271. // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
  3272. // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
  3273. // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
  3274. //
  3275. // E.g.
  3276. // `Decimal.rounding = 4;`
  3277. // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
  3278. rounding: 4,
  3279. // 0 to 8
  3280. // The modulo mode used when calculating the modulus: a mod n.
  3281. // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
  3282. // The remainder (r) is calculated as: r = a - n * q.
  3283. //
  3284. // UP 0 The remainder is positive if the dividend is negative, else is negative.
  3285. // DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
  3286. // FLOOR 3 The remainder has the same sign as the divisor (Python %).
  3287. // HALF_EVEN 6 The IEEE 754 remainder function.
  3288. // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
  3289. //
  3290. // Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
  3291. // division (9) are commonly used for the modulus operation. The other rounding modes can also
  3292. // be used, but they may not give useful results.
  3293. modulo: 1,
  3294. // 0 to 9
  3295. // The exponent value at and beneath which `toString` returns exponential notation.
  3296. // JavaScript numbers: -7
  3297. toExpNeg: -7,
  3298. // 0 to -EXP_LIMIT
  3299. // The exponent value at and above which `toString` returns exponential notation.
  3300. // JavaScript numbers: 21
  3301. toExpPos: 21,
  3302. // 0 to EXP_LIMIT
  3303. // The minimum exponent value, beneath which underflow to zero occurs.
  3304. // JavaScript numbers: -324 (5e-324)
  3305. minE: -9e15,
  3306. // -1 to -EXP_LIMIT
  3307. // The maximum exponent value, above which overflow to Infinity occurs.
  3308. // JavaScript numbers: 308 (1.7976931348623157e+308)
  3309. maxE: Ls,
  3310. // 1 to EXP_LIMIT
  3311. // Whether to use cryptographically-secure random number generation, if available.
  3312. crypto: !1
  3313. // true/false
  3314. }, io, Rt, ue = !0, Un = "[DecimalError] ", Bt = Un + "Invalid argument: ", oo = Un + "Precision limit exceeded", uo = Un + "crypto unavailable", co = "[object Decimal]", Be = Math.floor, Le = Math.pow, ml = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i, gl = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i, dl = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i, lo = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, ut = 1e7, te = 7, Cl = 9007199254740991, _l = mn.length - 1, Us = gn.length - 1, B = { toStringTag: co };
  3315. B.absoluteValue = B.abs = function() {
  3316. var i = new this.constructor(this);
  3317. return i.s < 0 && (i.s = 1), J(i);
  3318. };
  3319. B.ceil = function() {
  3320. return J(new this.constructor(this), this.e + 1, 2);
  3321. };
  3322. B.clampedTo = B.clamp = function(i, a) {
  3323. var e, t = this, r = t.constructor;
  3324. if (i = new r(i), a = new r(a), !i.s || !a.s) return new r(NaN);
  3325. if (i.gt(a)) throw Error(Bt + a);
  3326. return e = t.cmp(i), e < 0 ? i : t.cmp(a) > 0 ? a : new r(t);
  3327. };
  3328. B.comparedTo = B.cmp = function(i) {
  3329. var a, e, t, r, n = this, s = n.d, o = (i = new n.constructor(i)).d, u = n.s, c = i.s;
  3330. if (!s || !o)
  3331. return !u || !c ? NaN : u !== c ? u : s === o ? 0 : !s ^ u < 0 ? 1 : -1;
  3332. if (!s[0] || !o[0]) return s[0] ? u : o[0] ? -c : 0;
  3333. if (u !== c) return u;
  3334. if (n.e !== i.e) return n.e > i.e ^ u < 0 ? 1 : -1;
  3335. for (t = s.length, r = o.length, a = 0, e = t < r ? t : r; a < e; ++a)
  3336. if (s[a] !== o[a]) return s[a] > o[a] ^ u < 0 ? 1 : -1;
  3337. return t === r ? 0 : t > r ^ u < 0 ? 1 : -1;
  3338. };
  3339. B.cosine = B.cos = function() {
  3340. var i, a, e = this, t = e.constructor;
  3341. return e.d ? e.d[0] ? (i = t.precision, a = t.rounding, t.precision = i + Math.max(e.e, e.sd()) + te, t.rounding = 1, e = Al(t, Co(t, e)), t.precision = i, t.rounding = a, J(Rt == 2 || Rt == 3 ? e.neg() : e, i, a, !0)) : new t(1) : new t(NaN);
  3342. };
  3343. B.cubeRoot = B.cbrt = function() {
  3344. var i, a, e, t, r, n, s, o, u, c, l = this, f = l.constructor;
  3345. if (!l.isFinite() || l.isZero()) return new f(l);
  3346. for (ue = !1, n = l.s * Le(l.s * l, 1 / 3), !n || Math.abs(n) == 1 / 0 ? (e = Ue(l.d), i = l.e, (n = (i - e.length + 1) % 3) && (e += n == 1 || n == -2 ? "0" : "00"), n = Le(e, 1 / 3), i = Be((i + 1) / 3) - (i % 3 == (i < 0 ? -1 : 2)), n == 1 / 0 ? e = "5e" + i : (e = n.toExponential(), e = e.slice(0, e.indexOf("e") + 1) + i), t = new f(e), t.s = l.s) : t = new f(n.toString()), s = (i = f.precision) + 3; ; )
  3347. if (o = t, u = o.times(o).times(o), c = u.plus(l), t = pe(c.plus(l).times(o), c.plus(u), s + 2, 1), Ue(o.d).slice(0, s) === (e = Ue(t.d)).slice(0, s))
  3348. if (e = e.slice(s - 3, s + 1), e == "9999" || !r && e == "4999") {
  3349. if (!r && (J(o, i + 1, 0), o.times(o).times(o).eq(l))) {
  3350. t = o;
  3351. break;
  3352. }
  3353. s += 4, r = 1;
  3354. } else {
  3355. (!+e || !+e.slice(1) && e.charAt(0) == "5") && (J(t, i + 1, 1), a = !t.times(t).times(t).eq(l));
  3356. break;
  3357. }
  3358. return ue = !0, J(t, i, f.rounding, a);
  3359. };
  3360. B.decimalPlaces = B.dp = function() {
  3361. var i, a = this.d, e = NaN;
  3362. if (a) {
  3363. if (i = a.length - 1, e = (i - Be(this.e / te)) * te, i = a[i], i) for (; i % 10 == 0; i /= 10) e--;
  3364. e < 0 && (e = 0);
  3365. }
  3366. return e;
  3367. };
  3368. B.dividedBy = B.div = function(i) {
  3369. return pe(this, new this.constructor(i));
  3370. };
  3371. B.dividedToIntegerBy = B.divToInt = function(i) {
  3372. var a = this, e = a.constructor;
  3373. return J(pe(a, new e(i), 0, 1, 1), e.precision, e.rounding);
  3374. };
  3375. B.equals = B.eq = function(i) {
  3376. return this.cmp(i) === 0;
  3377. };
  3378. B.floor = function() {
  3379. return J(new this.constructor(this), this.e + 1, 3);
  3380. };
  3381. B.greaterThan = B.gt = function(i) {
  3382. return this.cmp(i) > 0;
  3383. };
  3384. B.greaterThanOrEqualTo = B.gte = function(i) {
  3385. var a = this.cmp(i);
  3386. return a == 1 || a === 0;
  3387. };
  3388. B.hyperbolicCosine = B.cosh = function() {
  3389. var i, a, e, t, r, n = this, s = n.constructor, o = new s(1);
  3390. if (!n.isFinite()) return new s(n.s ? 1 / 0 : NaN);
  3391. if (n.isZero()) return o;
  3392. e = s.precision, t = s.rounding, s.precision = e + Math.max(n.e, n.sd()) + 4, s.rounding = 1, r = n.d.length, r < 32 ? (i = Math.ceil(r / 3), a = (1 / Tn(4, i)).toString()) : (i = 16, a = "2.3283064365386962890625e-10"), n = dr(s, 1, n.times(a), new s(1), !0);
  3393. for (var u, c = i, l = new s(8); c--; )
  3394. u = n.times(n), n = o.minus(u.times(l.minus(u.times(l))));
  3395. return J(n, s.precision = e, s.rounding = t, !0);
  3396. };
  3397. B.hyperbolicSine = B.sinh = function() {
  3398. var i, a, e, t, r = this, n = r.constructor;
  3399. if (!r.isFinite() || r.isZero()) return new n(r);
  3400. if (a = n.precision, e = n.rounding, n.precision = a + Math.max(r.e, r.sd()) + 4, n.rounding = 1, t = r.d.length, t < 3)
  3401. r = dr(n, 2, r, r, !0);
  3402. else {
  3403. i = 1.4 * Math.sqrt(t), i = i > 16 ? 16 : i | 0, r = r.times(1 / Tn(5, i)), r = dr(n, 2, r, r, !0);
  3404. for (var s, o = new n(5), u = new n(16), c = new n(20); i--; )
  3405. s = r.times(r), r = r.times(o.plus(s.times(u.times(s).plus(c))));
  3406. }
  3407. return n.precision = a, n.rounding = e, J(r, a, e, !0);
  3408. };
  3409. B.hyperbolicTangent = B.tanh = function() {
  3410. var i, a, e = this, t = e.constructor;
  3411. return e.isFinite() ? e.isZero() ? new t(e) : (i = t.precision, a = t.rounding, t.precision = i + 7, t.rounding = 1, pe(e.sinh(), e.cosh(), t.precision = i, t.rounding = a)) : new t(e.s);
  3412. };
  3413. B.inverseCosine = B.acos = function() {
  3414. var i, a = this, e = a.constructor, t = a.abs().cmp(1), r = e.precision, n = e.rounding;
  3415. return t !== -1 ? t === 0 ? a.isNeg() ? ot(e, r, n) : new e(0) : new e(NaN) : a.isZero() ? ot(e, r + 4, n).times(0.5) : (e.precision = r + 6, e.rounding = 1, a = a.asin(), i = ot(e, r + 4, n).times(0.5), e.precision = r, e.rounding = n, i.minus(a));
  3416. };
  3417. B.inverseHyperbolicCosine = B.acosh = function() {
  3418. var i, a, e = this, t = e.constructor;
  3419. return e.lte(1) ? new t(e.eq(1) ? 0 : NaN) : e.isFinite() ? (i = t.precision, a = t.rounding, t.precision = i + Math.max(Math.abs(e.e), e.sd()) + 4, t.rounding = 1, ue = !1, e = e.times(e).minus(1).sqrt().plus(e), ue = !0, t.precision = i, t.rounding = a, e.ln()) : new t(e);
  3420. };
  3421. B.inverseHyperbolicSine = B.asinh = function() {
  3422. var i, a, e = this, t = e.constructor;
  3423. return !e.isFinite() || e.isZero() ? new t(e) : (i = t.precision, a = t.rounding, t.precision = i + 2 * Math.max(Math.abs(e.e), e.sd()) + 6, t.rounding = 1, ue = !1, e = e.times(e).plus(1).sqrt().plus(e), ue = !0, t.precision = i, t.rounding = a, e.ln());
  3424. };
  3425. B.inverseHyperbolicTangent = B.atanh = function() {
  3426. var i, a, e, t, r = this, n = r.constructor;
  3427. return r.isFinite() ? r.e >= 0 ? new n(r.abs().eq(1) ? r.s / 0 : r.isZero() ? r : NaN) : (i = n.precision, a = n.rounding, t = r.sd(), Math.max(t, i) < 2 * -r.e - 1 ? J(new n(r), i, a, !0) : (n.precision = e = t - r.e, r = pe(r.plus(1), new n(1).minus(r), e + i, 1), n.precision = i + 4, n.rounding = 1, r = r.ln(), n.precision = i, n.rounding = a, r.times(0.5))) : new n(NaN);
  3428. };
  3429. B.inverseSine = B.asin = function() {
  3430. var i, a, e, t, r = this, n = r.constructor;
  3431. return r.isZero() ? new n(r) : (a = r.abs().cmp(1), e = n.precision, t = n.rounding, a !== -1 ? a === 0 ? (i = ot(n, e + 4, t).times(0.5), i.s = r.s, i) : new n(NaN) : (n.precision = e + 6, n.rounding = 1, r = r.div(new n(1).minus(r.times(r)).sqrt().plus(1)).atan(), n.precision = e, n.rounding = t, r.times(2)));
  3432. };
  3433. B.inverseTangent = B.atan = function() {
  3434. var i, a, e, t, r, n, s, o, u, c = this, l = c.constructor, f = l.precision, h = l.rounding;
  3435. if (c.isFinite()) {
  3436. if (c.isZero())
  3437. return new l(c);
  3438. if (c.abs().eq(1) && f + 4 <= Us)
  3439. return s = ot(l, f + 4, h).times(0.25), s.s = c.s, s;
  3440. } else {
  3441. if (!c.s) return new l(NaN);
  3442. if (f + 4 <= Us)
  3443. return s = ot(l, f + 4, h).times(0.5), s.s = c.s, s;
  3444. }
  3445. for (l.precision = o = f + 10, l.rounding = 1, e = Math.min(28, o / te + 2 | 0), i = e; i; --i) c = c.div(c.times(c).plus(1).sqrt().plus(1));
  3446. for (ue = !1, a = Math.ceil(o / te), t = 1, u = c.times(c), s = new l(c), r = c; i !== -1; )
  3447. if (r = r.times(u), n = s.minus(r.div(t += 2)), r = r.times(u), s = n.plus(r.div(t += 2)), s.d[a] !== void 0) for (i = a; s.d[i] === n.d[i] && i--; ) ;
  3448. return e && (s = s.times(2 << e - 1)), ue = !0, J(s, l.precision = f, l.rounding = h, !0);
  3449. };
  3450. B.isFinite = function() {
  3451. return !!this.d;
  3452. };
  3453. B.isInteger = B.isInt = function() {
  3454. return !!this.d && Be(this.e / te) > this.d.length - 2;
  3455. };
  3456. B.isNaN = function() {
  3457. return !this.s;
  3458. };
  3459. B.isNegative = B.isNeg = function() {
  3460. return this.s < 0;
  3461. };
  3462. B.isPositive = B.isPos = function() {
  3463. return this.s > 0;
  3464. };
  3465. B.isZero = function() {
  3466. return !!this.d && this.d[0] === 0;
  3467. };
  3468. B.lessThan = B.lt = function(i) {
  3469. return this.cmp(i) < 0;
  3470. };
  3471. B.lessThanOrEqualTo = B.lte = function(i) {
  3472. return this.cmp(i) < 1;
  3473. };
  3474. B.logarithm = B.log = function(i) {
  3475. var a, e, t, r, n, s, o, u, c = this, l = c.constructor, f = l.precision, h = l.rounding, d = 5;
  3476. if (i == null)
  3477. i = new l(10), a = !0;
  3478. else {
  3479. if (i = new l(i), e = i.d, i.s < 0 || !e || !e[0] || i.eq(1)) return new l(NaN);
  3480. a = i.eq(10);
  3481. }
  3482. if (e = c.d, c.s < 0 || !e || !e[0] || c.eq(1))
  3483. return new l(e && !e[0] ? -1 / 0 : c.s != 1 ? NaN : e ? 0 : 1 / 0);
  3484. if (a)
  3485. if (e.length > 1)
  3486. n = !0;
  3487. else {
  3488. for (r = e[0]; r % 10 === 0; ) r /= 10;
  3489. n = r !== 1;
  3490. }
  3491. if (ue = !1, o = f + d, s = jt(c, o), t = a ? dn(l, o + 10) : jt(i, o), u = pe(s, t, o, 1), Lr(u.d, r = f, h))
  3492. do
  3493. if (o += 10, s = jt(c, o), t = a ? dn(l, o + 10) : jt(i, o), u = pe(s, t, o, 1), !n) {
  3494. +Ue(u.d).slice(r + 1, r + 15) + 1 == 1e14 && (u = J(u, f + 1, 0));
  3495. break;
  3496. }
  3497. while (Lr(u.d, r += 10, h));
  3498. return ue = !0, J(u, f, h);
  3499. };
  3500. B.minus = B.sub = function(i) {
  3501. var a, e, t, r, n, s, o, u, c, l, f, h, d = this, _ = d.constructor;
  3502. if (i = new _(i), !d.d || !i.d)
  3503. return !d.s || !i.s ? i = new _(NaN) : d.d ? i.s = -i.s : i = new _(i.d || d.s !== i.s ? d : NaN), i;
  3504. if (d.s != i.s)
  3505. return i.s = -i.s, d.plus(i);
  3506. if (c = d.d, h = i.d, o = _.precision, u = _.rounding, !c[0] || !h[0]) {
  3507. if (h[0]) i.s = -i.s;
  3508. else if (c[0]) i = new _(d);
  3509. else return new _(u === 3 ? -0 : 0);
  3510. return ue ? J(i, o, u) : i;
  3511. }
  3512. if (e = Be(i.e / te), l = Be(d.e / te), c = c.slice(), n = l - e, n) {
  3513. for (f = n < 0, f ? (a = c, n = -n, s = h.length) : (a = h, e = l, s = c.length), t = Math.max(Math.ceil(o / te), s) + 2, n > t && (n = t, a.length = 1), a.reverse(), t = n; t--; ) a.push(0);
  3514. a.reverse();
  3515. } else {
  3516. for (t = c.length, s = h.length, f = t < s, f && (s = t), t = 0; t < s; t++)
  3517. if (c[t] != h[t]) {
  3518. f = c[t] < h[t];
  3519. break;
  3520. }
  3521. n = 0;
  3522. }
  3523. for (f && (a = c, c = h, h = a, i.s = -i.s), s = c.length, t = h.length - s; t > 0; --t) c[s++] = 0;
  3524. for (t = h.length; t > n; ) {
  3525. if (c[--t] < h[t]) {
  3526. for (r = t; r && c[--r] === 0; ) c[r] = ut - 1;
  3527. --c[r], c[t] += ut;
  3528. }
  3529. c[t] -= h[t];
  3530. }
  3531. for (; c[--s] === 0; ) c.pop();
  3532. for (; c[0] === 0; c.shift()) --e;
  3533. return c[0] ? (i.d = c, i.e = vn(c, e), ue ? J(i, o, u) : i) : new _(u === 3 ? -0 : 0);
  3534. };
  3535. B.modulo = B.mod = function(i) {
  3536. var a, e = this, t = e.constructor;
  3537. return i = new t(i), !e.d || !i.s || i.d && !i.d[0] ? new t(NaN) : !i.d || e.d && !e.d[0] ? J(new t(e), t.precision, t.rounding) : (ue = !1, t.modulo == 9 ? (a = pe(e, i.abs(), 0, 3, 1), a.s *= i.s) : a = pe(e, i, 0, t.modulo, 1), a = a.times(i), ue = !0, e.minus(a));
  3538. };
  3539. B.naturalExponential = B.exp = function() {
  3540. return vs(this);
  3541. };
  3542. B.naturalLogarithm = B.ln = function() {
  3543. return jt(this);
  3544. };
  3545. B.negated = B.neg = function() {
  3546. var i = new this.constructor(this);
  3547. return i.s = -i.s, J(i);
  3548. };
  3549. B.plus = B.add = function(i) {
  3550. var a, e, t, r, n, s, o, u, c, l, f = this, h = f.constructor;
  3551. if (i = new h(i), !f.d || !i.d)
  3552. return !f.s || !i.s ? i = new h(NaN) : f.d || (i = new h(i.d || f.s === i.s ? f : NaN)), i;
  3553. if (f.s != i.s)
  3554. return i.s = -i.s, f.minus(i);
  3555. if (c = f.d, l = i.d, o = h.precision, u = h.rounding, !c[0] || !l[0])
  3556. return l[0] || (i = new h(f)), ue ? J(i, o, u) : i;
  3557. if (n = Be(f.e / te), t = Be(i.e / te), c = c.slice(), r = n - t, r) {
  3558. for (r < 0 ? (e = c, r = -r, s = l.length) : (e = l, t = n, s = c.length), n = Math.ceil(o / te), s = n > s ? n + 1 : s + 1, r > s && (r = s, e.length = 1), e.reverse(); r--; ) e.push(0);
  3559. e.reverse();
  3560. }
  3561. for (s = c.length, r = l.length, s - r < 0 && (r = s, e = l, l = c, c = e), a = 0; r; )
  3562. a = (c[--r] = c[r] + l[r] + a) / ut | 0, c[r] %= ut;
  3563. for (a && (c.unshift(a), ++t), s = c.length; c[--s] == 0; ) c.pop();
  3564. return i.d = c, i.e = vn(c, t), ue ? J(i, o, u) : i;
  3565. };
  3566. B.precision = B.sd = function(i) {
  3567. var a, e = this;
  3568. if (i !== void 0 && i !== !!i && i !== 1 && i !== 0) throw Error(Bt + i);
  3569. return e.d ? (a = fo(e.d), i && e.e + 1 > a && (a = e.e + 1)) : a = NaN, a;
  3570. };
  3571. B.round = function() {
  3572. var i = this, a = i.constructor;
  3573. return J(new a(i), i.e + 1, a.rounding);
  3574. };
  3575. B.sine = B.sin = function() {
  3576. var i, a, e = this, t = e.constructor;
  3577. return e.isFinite() ? e.isZero() ? new t(e) : (i = t.precision, a = t.rounding, t.precision = i + Math.max(e.e, e.sd()) + te, t.rounding = 1, e = bl(t, Co(t, e)), t.precision = i, t.rounding = a, J(Rt > 2 ? e.neg() : e, i, a, !0)) : new t(NaN);
  3578. };
  3579. B.squareRoot = B.sqrt = function() {
  3580. var i, a, e, t, r, n, s = this, o = s.d, u = s.e, c = s.s, l = s.constructor;
  3581. if (c !== 1 || !o || !o[0])
  3582. return new l(!c || c < 0 && (!o || o[0]) ? NaN : o ? s : 1 / 0);
  3583. for (ue = !1, c = Math.sqrt(+s), c == 0 || c == 1 / 0 ? (a = Ue(o), (a.length + u) % 2 == 0 && (a += "0"), c = Math.sqrt(a), u = Be((u + 1) / 2) - (u < 0 || u % 2), c == 1 / 0 ? a = "5e" + u : (a = c.toExponential(), a = a.slice(0, a.indexOf("e") + 1) + u), t = new l(a)) : t = new l(c.toString()), e = (u = l.precision) + 3; ; )
  3584. if (n = t, t = n.plus(pe(s, n, e + 2, 1)).times(0.5), Ue(n.d).slice(0, e) === (a = Ue(t.d)).slice(0, e))
  3585. if (a = a.slice(e - 3, e + 1), a == "9999" || !r && a == "4999") {
  3586. if (!r && (J(n, u + 1, 0), n.times(n).eq(s))) {
  3587. t = n;
  3588. break;
  3589. }
  3590. e += 4, r = 1;
  3591. } else {
  3592. (!+a || !+a.slice(1) && a.charAt(0) == "5") && (J(t, u + 1, 1), i = !t.times(t).eq(s));
  3593. break;
  3594. }
  3595. return ue = !0, J(t, u, l.rounding, i);
  3596. };
  3597. B.tangent = B.tan = function() {
  3598. var i, a, e = this, t = e.constructor;
  3599. return e.isFinite() ? e.isZero() ? new t(e) : (i = t.precision, a = t.rounding, t.precision = i + 10, t.rounding = 1, e = e.sin(), e.s = 1, e = pe(e, new t(1).minus(e.times(e)).sqrt(), i + 10, 0), t.precision = i, t.rounding = a, J(Rt == 2 || Rt == 4 ? e.neg() : e, i, a, !0)) : new t(NaN);
  3600. };
  3601. B.times = B.mul = function(i) {
  3602. var a, e, t, r, n, s, o, u, c, l = this, f = l.constructor, h = l.d, d = (i = new f(i)).d;
  3603. if (i.s *= l.s, !h || !h[0] || !d || !d[0])
  3604. return new f(!i.s || h && !h[0] && !d || d && !d[0] && !h ? NaN : !h || !d ? i.s / 0 : i.s * 0);
  3605. for (e = Be(l.e / te) + Be(i.e / te), u = h.length, c = d.length, u < c && (n = h, h = d, d = n, s = u, u = c, c = s), n = [], s = u + c, t = s; t--; ) n.push(0);
  3606. for (t = c; --t >= 0; ) {
  3607. for (a = 0, r = u + t; r > t; )
  3608. o = n[r] + d[t] * h[r - t - 1] + a, n[r--] = o % ut | 0, a = o / ut | 0;
  3609. n[r] = (n[r] + a) % ut | 0;
  3610. }
  3611. for (; !n[--s]; ) n.pop();
  3612. return a ? ++e : n.shift(), i.d = n, i.e = vn(n, e), ue ? J(i, f.precision, f.rounding) : i;
  3613. };
  3614. B.toBinary = function(i, a) {
  3615. return ga(this, 2, i, a);
  3616. };
  3617. B.toDecimalPlaces = B.toDP = function(i, a) {
  3618. var e = this, t = e.constructor;
  3619. return e = new t(e), i === void 0 ? e : (He(i, 0, $t), a === void 0 ? a = t.rounding : He(a, 0, 8), J(e, i + e.e + 1, a));
  3620. };
  3621. B.toExponential = function(i, a) {
  3622. var e, t = this, r = t.constructor;
  3623. return i === void 0 ? e = Ct(t, !0) : (He(i, 0, $t), a === void 0 ? a = r.rounding : He(a, 0, 8), t = J(new r(t), i + 1, a), e = Ct(t, !0, i + 1)), t.isNeg() && !t.isZero() ? "-" + e : e;
  3624. };
  3625. B.toFixed = function(i, a) {
  3626. var e, t, r = this, n = r.constructor;
  3627. return i === void 0 ? e = Ct(r) : (He(i, 0, $t), a === void 0 ? a = n.rounding : He(a, 0, 8), t = J(new n(r), i + r.e + 1, a), e = Ct(t, !1, i + t.e + 1)), r.isNeg() && !r.isZero() ? "-" + e : e;
  3628. };
  3629. B.toFraction = function(i) {
  3630. var a, e, t, r, n, s, o, u, c, l, f, h, d = this, _ = d.d, C = d.constructor;
  3631. if (!_) return new C(d);
  3632. if (c = e = new C(1), t = u = new C(0), a = new C(t), n = a.e = fo(_) - d.e - 1, s = n % te, a.d[0] = Le(10, s < 0 ? te + s : s), i == null)
  3633. i = n > 0 ? a : c;
  3634. else {
  3635. if (o = new C(i), !o.isInt() || o.lt(c)) throw Error(Bt + o);
  3636. i = o.gt(a) ? n > 0 ? a : c : o;
  3637. }
  3638. for (ue = !1, o = new C(Ue(_)), l = C.precision, C.precision = n = _.length * te * 2; f = pe(o, a, 0, 1, 1), r = e.plus(f.times(t)), r.cmp(i) != 1; )
  3639. e = t, t = r, r = c, c = u.plus(f.times(r)), u = r, r = a, a = o.minus(f.times(r)), o = r;
  3640. return r = pe(i.minus(e), t, 0, 1, 1), u = u.plus(r.times(c)), e = e.plus(r.times(t)), u.s = c.s = d.s, h = pe(c, t, n, 1).minus(d).abs().cmp(pe(u, e, n, 1).minus(d).abs()) < 1 ? [c, t] : [u, e], C.precision = l, ue = !0, h;
  3641. };
  3642. B.toHexadecimal = B.toHex = function(i, a) {
  3643. return ga(this, 16, i, a);
  3644. };
  3645. B.toNearest = function(i, a) {
  3646. var e = this, t = e.constructor;
  3647. if (e = new t(e), i == null) {
  3648. if (!e.d) return e;
  3649. i = new t(1), a = t.rounding;
  3650. } else {
  3651. if (i = new t(i), a === void 0 ? a = t.rounding : He(a, 0, 8), !e.d) return i.s ? e : i;
  3652. if (!i.d)
  3653. return i.s && (i.s = e.s), i;
  3654. }
  3655. return i.d[0] ? (ue = !1, e = pe(e, i, 0, a, 1).times(i), ue = !0, J(e)) : (i.s = e.s, e = i), e;
  3656. };
  3657. B.toNumber = function() {
  3658. return +this;
  3659. };
  3660. B.toOctal = function(i, a) {
  3661. return ga(this, 8, i, a);
  3662. };
  3663. B.toPower = B.pow = function(i) {
  3664. var a, e, t, r, n, s, o = this, u = o.constructor, c = +(i = new u(i));
  3665. if (!o.d || !i.d || !o.d[0] || !i.d[0]) return new u(Le(+o, c));
  3666. if (o = new u(o), o.eq(1)) return o;
  3667. if (t = u.precision, n = u.rounding, i.eq(1)) return J(o, t, n);
  3668. if (a = Be(i.e / te), a >= i.d.length - 1 && (e = c < 0 ? -c : c) <= Cl)
  3669. return r = ho(u, o, e, t), i.s < 0 ? new u(1).div(r) : J(r, t, n);
  3670. if (s = o.s, s < 0) {
  3671. if (a < i.d.length - 1) return new u(NaN);
  3672. if (i.d[a] & 1 || (s = 1), o.e == 0 && o.d[0] == 1 && o.d.length == 1)
  3673. return o.s = s, o;
  3674. }
  3675. return e = Le(+o, c), a = e == 0 || !isFinite(e) ? Be(c * (Math.log("0." + Ue(o.d)) / Math.LN10 + o.e + 1)) : new u(e + "").e, a > u.maxE + 1 || a < u.minE - 1 ? new u(a > 0 ? s / 0 : 0) : (ue = !1, u.rounding = o.s = 1, e = Math.min(12, (a + "").length), r = vs(i.times(jt(o, t + e)), t), r.d && (r = J(r, t + 5, 1), Lr(r.d, t, n) && (a = t + 10, r = J(vs(i.times(jt(o, a + e)), a), a + 5, 1), +Ue(r.d).slice(t + 1, t + 15) + 1 == 1e14 && (r = J(r, t + 1, 0)))), r.s = s, ue = !0, u.rounding = n, J(r, t, n));
  3676. };
  3677. B.toPrecision = function(i, a) {
  3678. var e, t = this, r = t.constructor;
  3679. return i === void 0 ? e = Ct(t, t.e <= r.toExpNeg || t.e >= r.toExpPos) : (He(i, 1, $t), a === void 0 ? a = r.rounding : He(a, 0, 8), t = J(new r(t), i, a), e = Ct(t, i <= t.e || t.e <= r.toExpNeg, i)), t.isNeg() && !t.isZero() ? "-" + e : e;
  3680. };
  3681. B.toSignificantDigits = B.toSD = function(i, a) {
  3682. var e = this, t = e.constructor;
  3683. return i === void 0 ? (i = t.precision, a = t.rounding) : (He(i, 1, $t), a === void 0 ? a = t.rounding : He(a, 0, 8)), J(new t(e), i, a);
  3684. };
  3685. B.toString = function() {
  3686. var i = this, a = i.constructor, e = Ct(i, i.e <= a.toExpNeg || i.e >= a.toExpPos);
  3687. return i.isNeg() && !i.isZero() ? "-" + e : e;
  3688. };
  3689. B.truncated = B.trunc = function() {
  3690. return J(new this.constructor(this), this.e + 1, 1);
  3691. };
  3692. B.valueOf = B.toJSON = function() {
  3693. var i = this, a = i.constructor, e = Ct(i, i.e <= a.toExpNeg || i.e >= a.toExpPos);
  3694. return i.isNeg() ? "-" + e : e;
  3695. };
  3696. function Ue(i) {
  3697. var a, e, t, r = i.length - 1, n = "", s = i[0];
  3698. if (r > 0) {
  3699. for (n += s, a = 1; a < r; a++)
  3700. t = i[a] + "", e = te - t.length, e && (n += Pt(e)), n += t;
  3701. s = i[a], t = s + "", e = te - t.length, e && (n += Pt(e));
  3702. } else if (s === 0)
  3703. return "0";
  3704. for (; s % 10 === 0; ) s /= 10;
  3705. return n + s;
  3706. }
  3707. function He(i, a, e) {
  3708. if (i !== ~~i || i < a || i > e)
  3709. throw Error(Bt + i);
  3710. }
  3711. function Lr(i, a, e, t) {
  3712. var r, n, s, o;
  3713. for (n = i[0]; n >= 10; n /= 10) --a;
  3714. return --a < 0 ? (a += te, r = 0) : (r = Math.ceil((a + 1) / te), a %= te), n = Le(10, te - a), o = i[r] % n | 0, t == null ? a < 3 ? (a == 0 ? o = o / 100 | 0 : a == 1 && (o = o / 10 | 0), s = e < 4 && o == 99999 || e > 3 && o == 49999 || o == 5e4 || o == 0) : s = (e < 4 && o + 1 == n || e > 3 && o + 1 == n / 2) && (i[r + 1] / n / 100 | 0) == Le(10, a - 2) - 1 || (o == n / 2 || o == 0) && (i[r + 1] / n / 100 | 0) == 0 : a < 4 ? (a == 0 ? o = o / 1e3 | 0 : a == 1 ? o = o / 100 | 0 : a == 2 && (o = o / 10 | 0), s = (t || e < 4) && o == 9999 || !t && e > 3 && o == 4999) : s = ((t || e < 4) && o + 1 == n || !t && e > 3 && o + 1 == n / 2) && (i[r + 1] / n / 1e3 | 0) == Le(10, a - 3) - 1, s;
  3715. }
  3716. function sn(i, a, e) {
  3717. for (var t, r = [0], n, s = 0, o = i.length; s < o; ) {
  3718. for (n = r.length; n--; ) r[n] *= a;
  3719. for (r[0] += xs.indexOf(i.charAt(s++)), t = 0; t < r.length; t++)
  3720. r[t] > e - 1 && (r[t + 1] === void 0 && (r[t + 1] = 0), r[t + 1] += r[t] / e | 0, r[t] %= e);
  3721. }
  3722. return r.reverse();
  3723. }
  3724. function Al(i, a) {
  3725. var e, t, r;
  3726. if (a.isZero()) return a;
  3727. t = a.d.length, t < 32 ? (e = Math.ceil(t / 3), r = (1 / Tn(4, e)).toString()) : (e = 16, r = "2.3283064365386962890625e-10"), i.precision += e, a = dr(i, 1, a.times(r), new i(1));
  3728. for (var n = e; n--; ) {
  3729. var s = a.times(a);
  3730. a = s.times(s).minus(s).times(8).plus(1);
  3731. }
  3732. return i.precision -= e, a;
  3733. }
  3734. var pe = /* @__PURE__ */ function() {
  3735. function i(t, r, n) {
  3736. var s, o = 0, u = t.length;
  3737. for (t = t.slice(); u--; )
  3738. s = t[u] * r + o, t[u] = s % n | 0, o = s / n | 0;
  3739. return o && t.unshift(o), t;
  3740. }
  3741. function a(t, r, n, s) {
  3742. var o, u;
  3743. if (n != s)
  3744. u = n > s ? 1 : -1;
  3745. else
  3746. for (o = u = 0; o < n; o++)
  3747. if (t[o] != r[o]) {
  3748. u = t[o] > r[o] ? 1 : -1;
  3749. break;
  3750. }
  3751. return u;
  3752. }
  3753. function e(t, r, n, s) {
  3754. for (var o = 0; n--; )
  3755. t[n] -= o, o = t[n] < r[n] ? 1 : 0, t[n] = o * s + t[n] - r[n];
  3756. for (; !t[0] && t.length > 1; ) t.shift();
  3757. }
  3758. return function(t, r, n, s, o, u) {
  3759. var c, l, f, h, d, _, C, E, b, R, p, N, M, w, D, S, P, U, x, F, W = t.constructor, ne = t.s == r.s ? 1 : -1, z = t.d, G = r.d;
  3760. if (!z || !z[0] || !G || !G[0])
  3761. return new W(
  3762. // Return NaN if either NaN, or both Infinity or 0.
  3763. !t.s || !r.s || (z ? G && z[0] == G[0] : !G) ? NaN : (
  3764. // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
  3765. z && z[0] == 0 || !G ? ne * 0 : ne / 0
  3766. )
  3767. );
  3768. for (u ? (d = 1, l = t.e - r.e) : (u = ut, d = te, l = Be(t.e / d) - Be(r.e / d)), x = G.length, P = z.length, b = new W(ne), R = b.d = [], f = 0; G[f] == (z[f] || 0); f++) ;
  3769. if (G[f] > (z[f] || 0) && l--, n == null ? (w = n = W.precision, s = W.rounding) : o ? w = n + (t.e - r.e) + 1 : w = n, w < 0)
  3770. R.push(1), _ = !0;
  3771. else {
  3772. if (w = w / d + 2 | 0, f = 0, x == 1) {
  3773. for (h = 0, G = G[0], w++; (f < P || h) && w--; f++)
  3774. D = h * u + (z[f] || 0), R[f] = D / G | 0, h = D % G | 0;
  3775. _ = h || f < P;
  3776. } else {
  3777. for (h = u / (G[0] + 1) | 0, h > 1 && (G = i(G, h, u), z = i(z, h, u), x = G.length, P = z.length), S = x, p = z.slice(0, x), N = p.length; N < x; ) p[N++] = 0;
  3778. F = G.slice(), F.unshift(0), U = G[0], G[1] >= u / 2 && ++U;
  3779. do
  3780. h = 0, c = a(G, p, x, N), c < 0 ? (M = p[0], x != N && (M = M * u + (p[1] || 0)), h = M / U | 0, h > 1 ? (h >= u && (h = u - 1), C = i(G, h, u), E = C.length, N = p.length, c = a(C, p, E, N), c == 1 && (h--, e(C, x < E ? F : G, E, u))) : (h == 0 && (c = h = 1), C = G.slice()), E = C.length, E < N && C.unshift(0), e(p, C, N, u), c == -1 && (N = p.length, c = a(G, p, x, N), c < 1 && (h++, e(p, x < N ? F : G, N, u))), N = p.length) : c === 0 && (h++, p = [0]), R[f++] = h, c && p[0] ? p[N++] = z[S] || 0 : (p = [z[S]], N = 1);
  3781. while ((S++ < P || p[0] !== void 0) && w--);
  3782. _ = p[0] !== void 0;
  3783. }
  3784. R[0] || R.shift();
  3785. }
  3786. if (d == 1)
  3787. b.e = l, io = _;
  3788. else {
  3789. for (f = 1, h = R[0]; h >= 10; h /= 10) f++;
  3790. b.e = f + l * d - 1, J(b, o ? n + b.e + 1 : n, s, _);
  3791. }
  3792. return b;
  3793. };
  3794. }();
  3795. function J(i, a, e, t) {
  3796. var r, n, s, o, u, c, l, f, h, d = i.constructor;
  3797. e: if (a != null) {
  3798. if (f = i.d, !f) return i;
  3799. for (r = 1, o = f[0]; o >= 10; o /= 10) r++;
  3800. if (n = a - r, n < 0)
  3801. n += te, s = a, l = f[h = 0], u = l / Le(10, r - s - 1) % 10 | 0;
  3802. else if (h = Math.ceil((n + 1) / te), o = f.length, h >= o)
  3803. if (t) {
  3804. for (; o++ <= h; ) f.push(0);
  3805. l = u = 0, r = 1, n %= te, s = n - te + 1;
  3806. } else
  3807. break e;
  3808. else {
  3809. for (l = o = f[h], r = 1; o >= 10; o /= 10) r++;
  3810. n %= te, s = n - te + r, u = s < 0 ? 0 : l / Le(10, r - s - 1) % 10 | 0;
  3811. }
  3812. if (t = t || a < 0 || f[h + 1] !== void 0 || (s < 0 ? l : l % Le(10, r - s - 1)), c = e < 4 ? (u || t) && (e == 0 || e == (i.s < 0 ? 3 : 2)) : u > 5 || u == 5 && (e == 4 || t || e == 6 && // Check whether the digit to the left of the rounding digit is odd.
  3813. (n > 0 ? s > 0 ? l / Le(10, r - s) : 0 : f[h - 1]) % 10 & 1 || e == (i.s < 0 ? 8 : 7)), a < 1 || !f[0])
  3814. return f.length = 0, c ? (a -= i.e + 1, f[0] = Le(10, (te - a % te) % te), i.e = -a || 0) : f[0] = i.e = 0, i;
  3815. if (n == 0 ? (f.length = h, o = 1, h--) : (f.length = h + 1, o = Le(10, te - n), f[h] = s > 0 ? (l / Le(10, r - s) % Le(10, s) | 0) * o : 0), c)
  3816. for (; ; )
  3817. if (h == 0) {
  3818. for (n = 1, s = f[0]; s >= 10; s /= 10) n++;
  3819. for (s = f[0] += o, o = 1; s >= 10; s /= 10) o++;
  3820. n != o && (i.e++, f[0] == ut && (f[0] = 1));
  3821. break;
  3822. } else {
  3823. if (f[h] += o, f[h] != ut) break;
  3824. f[h--] = 0, o = 1;
  3825. }
  3826. for (n = f.length; f[--n] === 0; ) f.pop();
  3827. }
  3828. return ue && (i.e > d.maxE ? (i.d = null, i.e = NaN) : i.e < d.minE && (i.e = 0, i.d = [0])), i;
  3829. }
  3830. function Ct(i, a, e) {
  3831. if (!i.isFinite()) return go(i);
  3832. var t, r = i.e, n = Ue(i.d), s = n.length;
  3833. return a ? (e && (t = e - s) > 0 ? n = n.charAt(0) + "." + n.slice(1) + Pt(t) : s > 1 && (n = n.charAt(0) + "." + n.slice(1)), n = n + (i.e < 0 ? "e" : "e+") + i.e) : r < 0 ? (n = "0." + Pt(-r - 1) + n, e && (t = e - s) > 0 && (n += Pt(t))) : r >= s ? (n += Pt(r + 1 - s), e && (t = e - r - 1) > 0 && (n = n + "." + Pt(t))) : ((t = r + 1) < s && (n = n.slice(0, t) + "." + n.slice(t)), e && (t = e - s) > 0 && (r + 1 === s && (n += "."), n += Pt(t))), n;
  3834. }
  3835. function vn(i, a) {
  3836. var e = i[0];
  3837. for (a *= te; e >= 10; e /= 10) a++;
  3838. return a;
  3839. }
  3840. function dn(i, a, e) {
  3841. if (a > _l)
  3842. throw ue = !0, e && (i.precision = e), Error(oo);
  3843. return J(new i(mn), a, 1, !0);
  3844. }
  3845. function ot(i, a, e) {
  3846. if (a > Us) throw Error(oo);
  3847. return J(new i(gn), a, e, !0);
  3848. }
  3849. function fo(i) {
  3850. var a = i.length - 1, e = a * te + 1;
  3851. if (a = i[a], a) {
  3852. for (; a % 10 == 0; a /= 10) e--;
  3853. for (a = i[0]; a >= 10; a /= 10) e++;
  3854. }
  3855. return e;
  3856. }
  3857. function Pt(i) {
  3858. for (var a = ""; i--; ) a += "0";
  3859. return a;
  3860. }
  3861. function ho(i, a, e, t) {
  3862. var r, n = new i(1), s = Math.ceil(t / te + 4);
  3863. for (ue = !1; ; ) {
  3864. if (e % 2 && (n = n.times(a), hi(n.d, s) && (r = !0)), e = Be(e / 2), e === 0) {
  3865. e = n.d.length - 1, r && n.d[e] === 0 && ++n.d[e];
  3866. break;
  3867. }
  3868. a = a.times(a), hi(a.d, s);
  3869. }
  3870. return ue = !0, n;
  3871. }
  3872. function fi(i) {
  3873. return i.d[i.d.length - 1] & 1;
  3874. }
  3875. function mo(i, a, e) {
  3876. for (var t, r = new i(a[0]), n = 0; ++n < a.length; )
  3877. if (t = new i(a[n]), t.s)
  3878. r[e](t) && (r = t);
  3879. else {
  3880. r = t;
  3881. break;
  3882. }
  3883. return r;
  3884. }
  3885. function vs(i, a) {
  3886. var e, t, r, n, s, o, u, c = 0, l = 0, f = 0, h = i.constructor, d = h.rounding, _ = h.precision;
  3887. if (!i.d || !i.d[0] || i.e > 17)
  3888. return new h(i.d ? i.d[0] ? i.s < 0 ? 0 : 1 / 0 : 1 : i.s ? i.s < 0 ? 0 : i : NaN);
  3889. for (a == null ? (ue = !1, u = _) : u = a, o = new h(0.03125); i.e > -2; )
  3890. i = i.times(o), f += 5;
  3891. for (t = Math.log(Le(2, f)) / Math.LN10 * 2 + 5 | 0, u += t, e = n = s = new h(1), h.precision = u; ; ) {
  3892. if (n = J(n.times(i), u, 1), e = e.times(++l), o = s.plus(pe(n, e, u, 1)), Ue(o.d).slice(0, u) === Ue(s.d).slice(0, u)) {
  3893. for (r = f; r--; ) s = J(s.times(s), u, 1);
  3894. if (a == null)
  3895. if (c < 3 && Lr(s.d, u - t, d, c))
  3896. h.precision = u += 10, e = n = o = new h(1), l = 0, c++;
  3897. else
  3898. return J(s, h.precision = _, d, ue = !0);
  3899. else
  3900. return h.precision = _, s;
  3901. }
  3902. s = o;
  3903. }
  3904. }
  3905. function jt(i, a) {
  3906. var e, t, r, n, s, o, u, c, l, f, h, d = 1, _ = 10, C = i, E = C.d, b = C.constructor, R = b.rounding, p = b.precision;
  3907. if (C.s < 0 || !E || !E[0] || !C.e && E[0] == 1 && E.length == 1)
  3908. return new b(E && !E[0] ? -1 / 0 : C.s != 1 ? NaN : E ? 0 : C);
  3909. if (a == null ? (ue = !1, l = p) : l = a, b.precision = l += _, e = Ue(E), t = e.charAt(0), Math.abs(n = C.e) < 15e14) {
  3910. for (; t < 7 && t != 1 || t == 1 && e.charAt(1) > 3; )
  3911. C = C.times(i), e = Ue(C.d), t = e.charAt(0), d++;
  3912. n = C.e, t > 1 ? (C = new b("0." + e), n++) : C = new b(t + "." + e.slice(1));
  3913. } else
  3914. return c = dn(b, l + 2, p).times(n + ""), C = jt(new b(t + "." + e.slice(1)), l - _).plus(c), b.precision = p, a == null ? J(C, p, R, ue = !0) : C;
  3915. for (f = C, u = s = C = pe(C.minus(1), C.plus(1), l, 1), h = J(C.times(C), l, 1), r = 3; ; ) {
  3916. if (s = J(s.times(h), l, 1), c = u.plus(pe(s, new b(r), l, 1)), Ue(c.d).slice(0, l) === Ue(u.d).slice(0, l))
  3917. if (u = u.times(2), n !== 0 && (u = u.plus(dn(b, l + 2, p).times(n + ""))), u = pe(u, new b(d), l, 1), a == null)
  3918. if (Lr(u.d, l - _, R, o))
  3919. b.precision = l += _, c = s = C = pe(f.minus(1), f.plus(1), l, 1), h = J(C.times(C), l, 1), r = o = 1;
  3920. else
  3921. return J(u, b.precision = p, R, ue = !0);
  3922. else
  3923. return b.precision = p, u;
  3924. u = c, r += 2;
  3925. }
  3926. }
  3927. function go(i) {
  3928. return String(i.s * i.s / 0);
  3929. }
  3930. function Ts(i, a) {
  3931. var e, t, r;
  3932. for ((e = a.indexOf(".")) > -1 && (a = a.replace(".", "")), (t = a.search(/e/i)) > 0 ? (e < 0 && (e = t), e += +a.slice(t + 1), a = a.substring(0, t)) : e < 0 && (e = a.length), t = 0; a.charCodeAt(t) === 48; t++) ;
  3933. for (r = a.length; a.charCodeAt(r - 1) === 48; --r) ;
  3934. if (a = a.slice(t, r), a) {
  3935. if (r -= t, i.e = e = e - t - 1, i.d = [], t = (e + 1) % te, e < 0 && (t += te), t < r) {
  3936. for (t && i.d.push(+a.slice(0, t)), r -= te; t < r; ) i.d.push(+a.slice(t, t += te));
  3937. a = a.slice(t), t = te - a.length;
  3938. } else
  3939. t -= r;
  3940. for (; t--; ) a += "0";
  3941. i.d.push(+a), ue && (i.e > i.constructor.maxE ? (i.d = null, i.e = NaN) : i.e < i.constructor.minE && (i.e = 0, i.d = [0]));
  3942. } else
  3943. i.e = 0, i.d = [0];
  3944. return i;
  3945. }
  3946. function El(i, a) {
  3947. var e, t, r, n, s, o, u, c, l;
  3948. if (a.indexOf("_") > -1) {
  3949. if (a = a.replace(/(\d)_(?=\d)/g, "$1"), lo.test(a)) return Ts(i, a);
  3950. } else if (a === "Infinity" || a === "NaN")
  3951. return +a || (i.s = NaN), i.e = NaN, i.d = null, i;
  3952. if (gl.test(a))
  3953. e = 16, a = a.toLowerCase();
  3954. else if (ml.test(a))
  3955. e = 2;
  3956. else if (dl.test(a))
  3957. e = 8;
  3958. else
  3959. throw Error(Bt + a);
  3960. for (n = a.search(/p/i), n > 0 ? (u = +a.slice(n + 1), a = a.substring(2, n)) : a = a.slice(2), n = a.indexOf("."), s = n >= 0, t = i.constructor, s && (a = a.replace(".", ""), o = a.length, n = o - n, r = ho(t, new t(e), n, n * 2)), c = sn(a, e, ut), l = c.length - 1, n = l; c[n] === 0; --n) c.pop();
  3961. return n < 0 ? new t(i.s * 0) : (i.e = vn(c, l), i.d = c, ue = !1, s && (i = pe(i, r, o * 4)), u && (i = i.times(Math.abs(u) < 54 ? Le(2, u) : L.pow(2, u))), ue = !0, i);
  3962. }
  3963. function bl(i, a) {
  3964. var e, t = a.d.length;
  3965. if (t < 3)
  3966. return a.isZero() ? a : dr(i, 2, a, a);
  3967. e = 1.4 * Math.sqrt(t), e = e > 16 ? 16 : e | 0, a = a.times(1 / Tn(5, e)), a = dr(i, 2, a, a);
  3968. for (var r, n = new i(5), s = new i(16), o = new i(20); e--; )
  3969. r = a.times(a), a = a.times(n.plus(r.times(s.times(r).minus(o))));
  3970. return a;
  3971. }
  3972. function dr(i, a, e, t, r) {
  3973. var n, s, o, u, c = i.precision, l = Math.ceil(c / te);
  3974. for (ue = !1, u = e.times(e), o = new i(t); ; ) {
  3975. if (s = pe(o.times(u), new i(a++ * a++), c, 1), o = r ? t.plus(s) : t.minus(s), t = pe(s.times(u), new i(a++ * a++), c, 1), s = o.plus(t), s.d[l] !== void 0) {
  3976. for (n = l; s.d[n] === o.d[n] && n--; ) ;
  3977. if (n == -1) break;
  3978. }
  3979. n = o, o = t, t = s, s = n;
  3980. }
  3981. return ue = !0, s.d.length = l + 1, s;
  3982. }
  3983. function Tn(i, a) {
  3984. for (var e = i; --a; ) e *= i;
  3985. return e;
  3986. }
  3987. function Co(i, a) {
  3988. var e, t = a.s < 0, r = ot(i, i.precision, 1), n = r.times(0.5);
  3989. if (a = a.abs(), a.lte(n))
  3990. return Rt = t ? 4 : 1, a;
  3991. if (e = a.divToInt(r), e.isZero())
  3992. Rt = t ? 3 : 2;
  3993. else {
  3994. if (a = a.minus(e.times(r)), a.lte(n))
  3995. return Rt = fi(e) ? t ? 2 : 3 : t ? 4 : 1, a;
  3996. Rt = fi(e) ? t ? 1 : 4 : t ? 3 : 2;
  3997. }
  3998. return a.minus(r).abs();
  3999. }
  4000. function ga(i, a, e, t) {
  4001. var r, n, s, o, u, c, l, f, h, d = i.constructor, _ = e !== void 0;
  4002. if (_ ? (He(e, 1, $t), t === void 0 ? t = d.rounding : He(t, 0, 8)) : (e = d.precision, t = d.rounding), !i.isFinite())
  4003. l = go(i);
  4004. else {
  4005. for (l = Ct(i), s = l.indexOf("."), _ ? (r = 2, a == 16 ? e = e * 4 - 3 : a == 8 && (e = e * 3 - 2)) : r = a, s >= 0 && (l = l.replace(".", ""), h = new d(1), h.e = l.length - s, h.d = sn(Ct(h), 10, r), h.e = h.d.length), f = sn(l, 10, r), n = u = f.length; f[--u] == 0; ) f.pop();
  4006. if (!f[0])
  4007. l = _ ? "0p+0" : "0";
  4008. else {
  4009. if (s < 0 ? n-- : (i = new d(i), i.d = f, i.e = n, i = pe(i, h, e, t, 0, r), f = i.d, n = i.e, c = io), s = f[e], o = r / 2, c = c || f[e + 1] !== void 0, c = t < 4 ? (s !== void 0 || c) && (t === 0 || t === (i.s < 0 ? 3 : 2)) : s > o || s === o && (t === 4 || c || t === 6 && f[e - 1] & 1 || t === (i.s < 0 ? 8 : 7)), f.length = e, c)
  4010. for (; ++f[--e] > r - 1; )
  4011. f[e] = 0, e || (++n, f.unshift(1));
  4012. for (u = f.length; !f[u - 1]; --u) ;
  4013. for (s = 0, l = ""; s < u; s++) l += xs.charAt(f[s]);
  4014. if (_) {
  4015. if (u > 1)
  4016. if (a == 16 || a == 8) {
  4017. for (s = a == 16 ? 4 : 3, --u; u % s; u++) l += "0";
  4018. for (f = sn(l, r, a), u = f.length; !f[u - 1]; --u) ;
  4019. for (s = 1, l = "1."; s < u; s++) l += xs.charAt(f[s]);
  4020. } else
  4021. l = l.charAt(0) + "." + l.slice(1);
  4022. l = l + (n < 0 ? "p" : "p+") + n;
  4023. } else if (n < 0) {
  4024. for (; ++n; ) l = "0" + l;
  4025. l = "0." + l;
  4026. } else if (++n > u) for (n -= u; n--; ) l += "0";
  4027. else n < u && (l = l.slice(0, n) + "." + l.slice(n));
  4028. }
  4029. l = (a == 16 ? "0x" : a == 2 ? "0b" : a == 8 ? "0o" : "") + l;
  4030. }
  4031. return i.s < 0 ? "-" + l : l;
  4032. }
  4033. function hi(i, a) {
  4034. if (i.length > a)
  4035. return i.length = a, !0;
  4036. }
  4037. function yl(i) {
  4038. return new this(i).abs();
  4039. }
  4040. function Rl(i) {
  4041. return new this(i).acos();
  4042. }
  4043. function pl(i) {
  4044. return new this(i).acosh();
  4045. }
  4046. function Vl(i, a) {
  4047. return new this(i).plus(a);
  4048. }
  4049. function Nl(i) {
  4050. return new this(i).asin();
  4051. }
  4052. function Ol(i) {
  4053. return new this(i).asinh();
  4054. }
  4055. function Ml(i) {
  4056. return new this(i).atan();
  4057. }
  4058. function wl(i) {
  4059. return new this(i).atanh();
  4060. }
  4061. function Dl(i, a) {
  4062. i = new this(i), a = new this(a);
  4063. var e, t = this.precision, r = this.rounding, n = t + 4;
  4064. return !i.s || !a.s ? e = new this(NaN) : !i.d && !a.d ? (e = ot(this, n, 1).times(a.s > 0 ? 0.25 : 0.75), e.s = i.s) : !a.d || i.isZero() ? (e = a.s < 0 ? ot(this, t, r) : new this(0), e.s = i.s) : !i.d || a.isZero() ? (e = ot(this, n, 1).times(0.5), e.s = i.s) : a.s < 0 ? (this.precision = n, this.rounding = 1, e = this.atan(pe(i, a, n, 1)), a = ot(this, n, 1), this.precision = t, this.rounding = r, e = i.s < 0 ? e.minus(a) : e.plus(a)) : e = this.atan(pe(i, a, n, 1)), e;
  4065. }
  4066. function Sl(i) {
  4067. return new this(i).cbrt();
  4068. }
  4069. function Pl(i) {
  4070. return J(i = new this(i), i.e + 1, 2);
  4071. }
  4072. function Ll(i, a, e) {
  4073. return new this(i).clamp(a, e);
  4074. }
  4075. function xl(i) {
  4076. if (!i || typeof i != "object") throw Error(Un + "Object expected");
  4077. var a, e, t, r = i.defaults === !0, n = [
  4078. "precision",
  4079. 1,
  4080. $t,
  4081. "rounding",
  4082. 0,
  4083. 8,
  4084. "toExpNeg",
  4085. -9e15,
  4086. 0,
  4087. "toExpPos",
  4088. 0,
  4089. Ls,
  4090. "maxE",
  4091. 0,
  4092. Ls,
  4093. "minE",
  4094. -9e15,
  4095. 0,
  4096. "modulo",
  4097. 0,
  4098. 9
  4099. ];
  4100. for (a = 0; a < n.length; a += 3)
  4101. if (e = n[a], r && (this[e] = js[e]), (t = i[e]) !== void 0)
  4102. if (Be(t) === t && t >= n[a + 1] && t <= n[a + 2]) this[e] = t;
  4103. else throw Error(Bt + e + ": " + t);
  4104. if (e = "crypto", r && (this[e] = js[e]), (t = i[e]) !== void 0)
  4105. if (t === !0 || t === !1 || t === 0 || t === 1)
  4106. if (t)
  4107. if (typeof crypto < "u" && crypto && (crypto.getRandomValues || crypto.randomBytes))
  4108. this[e] = !0;
  4109. else
  4110. throw Error(uo);
  4111. else
  4112. this[e] = !1;
  4113. else
  4114. throw Error(Bt + e + ": " + t);
  4115. return this;
  4116. }
  4117. function jl(i) {
  4118. return new this(i).cos();
  4119. }
  4120. function Ul(i) {
  4121. return new this(i).cosh();
  4122. }
  4123. function _o(i) {
  4124. var a, e, t;
  4125. function r(n) {
  4126. var s, o, u, c = this;
  4127. if (!(c instanceof r)) return new r(n);
  4128. if (c.constructor = r, mi(n)) {
  4129. c.s = n.s, ue ? !n.d || n.e > r.maxE ? (c.e = NaN, c.d = null) : n.e < r.minE ? (c.e = 0, c.d = [0]) : (c.e = n.e, c.d = n.d.slice()) : (c.e = n.e, c.d = n.d ? n.d.slice() : n.d);
  4130. return;
  4131. }
  4132. if (u = typeof n, u === "number") {
  4133. if (n === 0) {
  4134. c.s = 1 / n < 0 ? -1 : 1, c.e = 0, c.d = [0];
  4135. return;
  4136. }
  4137. if (n < 0 ? (n = -n, c.s = -1) : c.s = 1, n === ~~n && n < 1e7) {
  4138. for (s = 0, o = n; o >= 10; o /= 10) s++;
  4139. ue ? s > r.maxE ? (c.e = NaN, c.d = null) : s < r.minE ? (c.e = 0, c.d = [0]) : (c.e = s, c.d = [n]) : (c.e = s, c.d = [n]);
  4140. return;
  4141. } else if (n * 0 !== 0) {
  4142. n || (c.s = NaN), c.e = NaN, c.d = null;
  4143. return;
  4144. }
  4145. return Ts(c, n.toString());
  4146. } else if (u !== "string")
  4147. throw Error(Bt + n);
  4148. return (o = n.charCodeAt(0)) === 45 ? (n = n.slice(1), c.s = -1) : (o === 43 && (n = n.slice(1)), c.s = 1), lo.test(n) ? Ts(c, n) : El(c, n);
  4149. }
  4150. if (r.prototype = B, r.ROUND_UP = 0, r.ROUND_DOWN = 1, r.ROUND_CEIL = 2, r.ROUND_FLOOR = 3, r.ROUND_HALF_UP = 4, r.ROUND_HALF_DOWN = 5, r.ROUND_HALF_EVEN = 6, r.ROUND_HALF_CEIL = 7, r.ROUND_HALF_FLOOR = 8, r.EUCLID = 9, r.config = r.set = xl, r.clone = _o, r.isDecimal = mi, r.abs = yl, r.acos = Rl, r.acosh = pl, r.add = Vl, r.asin = Nl, r.asinh = Ol, r.atan = Ml, r.atanh = wl, r.atan2 = Dl, r.cbrt = Sl, r.ceil = Pl, r.clamp = Ll, r.cos = jl, r.cosh = Ul, r.div = vl, r.exp = Tl, r.floor = Bl, r.hypot = Il, r.ln = Fl, r.log = kl, r.log10 = Yl, r.log2 = $l, r.max = Hl, r.min = Gl, r.mod = Ql, r.mul = Wl, r.pow = ql, r.random = Kl, r.round = Xl, r.sign = Zl, r.sin = zl, r.sinh = Jl, r.sqrt = ef, r.sub = tf, r.sum = rf, r.tan = nf, r.tanh = sf, r.trunc = af, i === void 0 && (i = {}), i && i.defaults !== !0)
  4151. for (t = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"], a = 0; a < t.length; ) i.hasOwnProperty(e = t[a++]) || (i[e] = this[e]);
  4152. return r.config(i), r;
  4153. }
  4154. function vl(i, a) {
  4155. return new this(i).div(a);
  4156. }
  4157. function Tl(i) {
  4158. return new this(i).exp();
  4159. }
  4160. function Bl(i) {
  4161. return J(i = new this(i), i.e + 1, 3);
  4162. }
  4163. function Il() {
  4164. var i, a, e = new this(0);
  4165. for (ue = !1, i = 0; i < arguments.length; )
  4166. if (a = new this(arguments[i++]), a.d)
  4167. e.d && (e = e.plus(a.times(a)));
  4168. else {
  4169. if (a.s)
  4170. return ue = !0, new this(1 / 0);
  4171. e = a;
  4172. }
  4173. return ue = !0, e.sqrt();
  4174. }
  4175. function mi(i) {
  4176. return i instanceof L || i && i.toStringTag === co || !1;
  4177. }
  4178. function Fl(i) {
  4179. return new this(i).ln();
  4180. }
  4181. function kl(i, a) {
  4182. return new this(i).log(a);
  4183. }
  4184. function $l(i) {
  4185. return new this(i).log(2);
  4186. }
  4187. function Yl(i) {
  4188. return new this(i).log(10);
  4189. }
  4190. function Hl() {
  4191. return mo(this, arguments, "lt");
  4192. }
  4193. function Gl() {
  4194. return mo(this, arguments, "gt");
  4195. }
  4196. function Ql(i, a) {
  4197. return new this(i).mod(a);
  4198. }
  4199. function Wl(i, a) {
  4200. return new this(i).mul(a);
  4201. }
  4202. function ql(i, a) {
  4203. return new this(i).pow(a);
  4204. }
  4205. function Kl(i) {
  4206. var a, e, t, r, n = 0, s = new this(1), o = [];
  4207. if (i === void 0 ? i = this.precision : He(i, 1, $t), t = Math.ceil(i / te), this.crypto)
  4208. if (crypto.getRandomValues)
  4209. for (a = crypto.getRandomValues(new Uint32Array(t)); n < t; )
  4210. r = a[n], r >= 429e7 ? a[n] = crypto.getRandomValues(new Uint32Array(1))[0] : o[n++] = r % 1e7;
  4211. else if (crypto.randomBytes) {
  4212. for (a = crypto.randomBytes(t *= 4); n < t; )
  4213. r = a[n] + (a[n + 1] << 8) + (a[n + 2] << 16) + ((a[n + 3] & 127) << 24), r >= 214e7 ? crypto.randomBytes(4).copy(a, n) : (o.push(r % 1e7), n += 4);
  4214. n = t / 4;
  4215. } else
  4216. throw Error(uo);
  4217. else for (; n < t; ) o[n++] = Math.random() * 1e7 | 0;
  4218. for (t = o[--n], i %= te, t && i && (r = Le(10, te - i), o[n] = (t / r | 0) * r); o[n] === 0; n--) o.pop();
  4219. if (n < 0)
  4220. e = 0, o = [0];
  4221. else {
  4222. for (e = -1; o[0] === 0; e -= te) o.shift();
  4223. for (t = 1, r = o[0]; r >= 10; r /= 10) t++;
  4224. t < te && (e -= te - t);
  4225. }
  4226. return s.e = e, s.d = o, s;
  4227. }
  4228. function Xl(i) {
  4229. return J(i = new this(i), i.e + 1, this.rounding);
  4230. }
  4231. function Zl(i) {
  4232. return i = new this(i), i.d ? i.d[0] ? i.s : 0 * i.s : i.s || NaN;
  4233. }
  4234. function zl(i) {
  4235. return new this(i).sin();
  4236. }
  4237. function Jl(i) {
  4238. return new this(i).sinh();
  4239. }
  4240. function ef(i) {
  4241. return new this(i).sqrt();
  4242. }
  4243. function tf(i, a) {
  4244. return new this(i).sub(a);
  4245. }
  4246. function rf() {
  4247. var i = 0, a = arguments, e = new this(a[i]);
  4248. for (ue = !1; e.s && ++i < a.length; ) e = e.plus(a[i]);
  4249. return ue = !0, J(e, this.precision, this.rounding);
  4250. }
  4251. function nf(i) {
  4252. return new this(i).tan();
  4253. }
  4254. function sf(i) {
  4255. return new this(i).tanh();
  4256. }
  4257. function af(i) {
  4258. return J(i = new this(i), i.e + 1, 1);
  4259. }
  4260. B[Symbol.for("nodejs.util.inspect.custom")] = B.toString;
  4261. B[Symbol.toStringTag] = "Decimal";
  4262. var L = B.constructor = _o(js);
  4263. mn = new L(mn);
  4264. gn = new L(gn);
  4265. function of(i, a) {
  4266. const e = i + a;
  4267. return Number.isSafeInteger(e) ? e : new L(i).add(a).toNumber();
  4268. }
  4269. function uf(i, a) {
  4270. const e = i - a;
  4271. return Number.isSafeInteger(e) ? e : new L(i).sub(a).toNumber();
  4272. }
  4273. function Vr(i, a) {
  4274. const e = i * a;
  4275. return Number.isSafeInteger(e) ? e : new L(i).mul(a).toNumber();
  4276. }
  4277. function cf(i, a) {
  4278. const e = i / a;
  4279. return Number.isSafeInteger(e) ? e : new L(i).div(a).toNumber();
  4280. }
  4281. function vt(i, a) {
  4282. const e = 10 ** Math.trunc(a), t = Bn(i, e);
  4283. return Math.round(Vr(i, e) + t) / e;
  4284. }
  4285. function We(i, a) {
  4286. const e = 10 ** Math.trunc(a), t = Bn(i, e);
  4287. return Math.floor(Vr(i, e) + t) / e;
  4288. }
  4289. function Ye(i, a) {
  4290. const e = 10 ** Math.trunc(a), t = Bn(i, e);
  4291. return Math.ceil(Vr(i, e) - t) / e;
  4292. }
  4293. function Bn(i, a) {
  4294. return Number.EPSILON * Math.max(1, Math.abs(Vr(i, a)));
  4295. }
  4296. function gi(i, a) {
  4297. return i - a * Math.floor(i / a);
  4298. }
  4299. function lf(i, a) {
  4300. return i ** a;
  4301. }
  4302. function ff(i) {
  4303. return Math.sqrt(i);
  4304. }
  4305. function di(i, a) {
  4306. return i === a;
  4307. }
  4308. function hf(i, a) {
  4309. return i > a;
  4310. }
  4311. function mf(i, a) {
  4312. return i >= a;
  4313. }
  4314. function gf(i, a) {
  4315. return i < a;
  4316. }
  4317. function df(i, a) {
  4318. return i <= a;
  4319. }
  4320. function Ci(i, a = 15) {
  4321. return Number.parseFloat(i.toPrecision(a));
  4322. }
  4323. function Cf(i, a, e = Number.EPSILON) {
  4324. return Math.abs(i - a) < e;
  4325. }
  4326. function _f(i, a = 12, e = 1e-10) {
  4327. const t = Ci(i, a);
  4328. return Cf(i, t, e) ? t : Ci(i);
  4329. }
  4330. function Af(i) {
  4331. return i - Math.trunc(i);
  4332. }
  4333. const xn = class xn extends kt {
  4334. static create() {
  4335. return this._instance = this._instance || new xn(0), this._instance;
  4336. }
  4337. isNull() {
  4338. return !0;
  4339. }
  4340. plus(a) {
  4341. return y.create(0).plus(a);
  4342. }
  4343. minus(a) {
  4344. return y.create(0).minus(a);
  4345. }
  4346. multiply(a) {
  4347. return y.create(0).multiply(a);
  4348. }
  4349. divided(a) {
  4350. return y.create(0).divided(a);
  4351. }
  4352. mod(a) {
  4353. return y.create(0).mod(a);
  4354. }
  4355. compare(a, e) {
  4356. return a.isString() ? j.create("").compare(a, e) : a.isBoolean() ? T.create(!1).compare(a, e) : y.create(0).compare(a, e);
  4357. }
  4358. concatenateFront(a) {
  4359. return a.isArray() ? a.concatenateBack(j.create("")) : j.create(this.concatenate(a.getValue(), it.FRONT));
  4360. }
  4361. concatenateBack(a) {
  4362. return a.isArray() ? a.concatenateFront(j.create("")) : j.create(this.concatenate(a.getValue(), it.BACK));
  4363. }
  4364. plusBy(a) {
  4365. return y.create(0).plusBy(a);
  4366. }
  4367. minusBy(a) {
  4368. return y.create(0).minusBy(a);
  4369. }
  4370. multiplyBy(a) {
  4371. return y.create(0).multiplyBy(a);
  4372. }
  4373. dividedBy(a) {
  4374. return y.create(0).dividedBy(a);
  4375. }
  4376. compareBy(a, e) {
  4377. return typeof a == "string" ? j.create("").compareBy(a, e) : typeof a == "boolean" ? T.create(!1).compareBy(a, e) : y.create(0).compareBy(a, e);
  4378. }
  4379. pow(a) {
  4380. return y.create(0).pow(a);
  4381. }
  4382. sqrt() {
  4383. return y.create(0).sqrt();
  4384. }
  4385. cbrt() {
  4386. return y.create(0).cbrt();
  4387. }
  4388. cos() {
  4389. return y.create(0).cos();
  4390. }
  4391. cosh() {
  4392. return y.create(0).cosh();
  4393. }
  4394. acos() {
  4395. return y.create(0).acos();
  4396. }
  4397. acosh() {
  4398. return y.create(0).acosh();
  4399. }
  4400. sin() {
  4401. return y.create(0).sin();
  4402. }
  4403. sinh() {
  4404. return y.create(0).sinh();
  4405. }
  4406. asin() {
  4407. return y.create(0).asin();
  4408. }
  4409. asinh() {
  4410. return y.create(0).asinh();
  4411. }
  4412. tan() {
  4413. return y.create(0).tan();
  4414. }
  4415. tanh() {
  4416. return y.create(0).tanh();
  4417. }
  4418. atan() {
  4419. return y.create(0).atan();
  4420. }
  4421. atan2(a) {
  4422. return y.create(0).atan2(a);
  4423. }
  4424. atanh() {
  4425. return y.create(0).atanh();
  4426. }
  4427. log() {
  4428. return g.create(m.NUM);
  4429. }
  4430. log10() {
  4431. return g.create(m.NUM);
  4432. }
  4433. exp() {
  4434. return y.create(0).exp();
  4435. }
  4436. abs() {
  4437. return y.create(0).abs();
  4438. }
  4439. round(a) {
  4440. return y.create(0).round(a);
  4441. }
  4442. floor(a) {
  4443. return y.create(0).floor(a);
  4444. }
  4445. ceil(a) {
  4446. return y.create(0).ceil(a);
  4447. }
  4448. convertToNumberObjectValue() {
  4449. return y.create(0);
  4450. }
  4451. convertToBooleanObjectValue() {
  4452. return T.create(!1);
  4453. }
  4454. };
  4455. A(xn, "_instance");
  4456. let ie = xn;
  4457. const qt = class qt extends kt {
  4458. constructor(e) {
  4459. super(e);
  4460. A(this, "_value", !1);
  4461. this._value = e;
  4462. }
  4463. static create(e) {
  4464. return e ? (this._instanceTrue = this._instanceTrue || new qt(!0), this._instanceTrue) : (this._instanceFalse = this._instanceFalse || new qt(!1), this._instanceFalse);
  4465. }
  4466. getValue() {
  4467. return this._value;
  4468. }
  4469. isBoolean() {
  4470. return !0;
  4471. }
  4472. getNegative() {
  4473. const e = this.getValue();
  4474. let t = 0;
  4475. return e && (t = 1), y.create(-t);
  4476. }
  4477. getReciprocal() {
  4478. return this.getValue() ? y.create(1) : g.create(m.DIV_BY_ZERO);
  4479. }
  4480. plus(e) {
  4481. return this._convertToNumber().plus(e);
  4482. }
  4483. minus(e) {
  4484. return this._convertToNumber().minus(e);
  4485. }
  4486. multiply(e) {
  4487. return this._convertToNumber().multiply(e);
  4488. }
  4489. divided(e) {
  4490. return this._convertToNumber().divided(e);
  4491. }
  4492. mod(e) {
  4493. return this._convertToNumber().mod(e);
  4494. }
  4495. compare(e, t) {
  4496. return e.isArray() ? e.compare(this, ma(t)) : e.isNull() ? this._convertToNumber().compare(e, t) : this.compareBy(e.getValue(), t);
  4497. }
  4498. compareBy(e, t) {
  4499. let r = !1;
  4500. if (typeof e == "string" || typeof e == "number")
  4501. r = this._compareString(t);
  4502. else if (typeof e == "boolean") {
  4503. const n = y.create(e ? 1 : 0);
  4504. return this._convertToNumber().compare(n, t);
  4505. }
  4506. return qt.create(r);
  4507. }
  4508. _compareString(e) {
  4509. switch (e) {
  4510. case $.GREATER_THAN:
  4511. case $.GREATER_THAN_OR_EQUAL:
  4512. return !0;
  4513. case $.EQUALS:
  4514. case $.LESS_THAN:
  4515. case $.LESS_THAN_OR_EQUAL:
  4516. case $.NOT_EQUAL:
  4517. return !1;
  4518. }
  4519. }
  4520. concatenateFront(e) {
  4521. return this._convertToNumber().concatenateFront(e);
  4522. }
  4523. concatenateBack(e) {
  4524. return this._convertToNumber().concatenateBack(e);
  4525. }
  4526. _convertToNumber() {
  4527. const e = this.getValue();
  4528. let t = 0;
  4529. return e && (t = 1), y.create(t);
  4530. }
  4531. pow(e) {
  4532. return this._convertToNumber().pow(e);
  4533. }
  4534. sqrt() {
  4535. return this._convertToNumber().sqrt();
  4536. }
  4537. cbrt() {
  4538. return this._convertToNumber().cbrt();
  4539. }
  4540. cos() {
  4541. return this._convertToNumber().cos();
  4542. }
  4543. cosh() {
  4544. return this._convertToNumber().cosh();
  4545. }
  4546. acos() {
  4547. return this._convertToNumber().acos();
  4548. }
  4549. acosh() {
  4550. return this._convertToNumber().acosh();
  4551. }
  4552. sin() {
  4553. return this._convertToNumber().sin();
  4554. }
  4555. sinh() {
  4556. return this._convertToNumber().sinh();
  4557. }
  4558. asin() {
  4559. return this._convertToNumber().asin();
  4560. }
  4561. asinh() {
  4562. return this._convertToNumber().asinh();
  4563. }
  4564. tan() {
  4565. return this._convertToNumber().tan();
  4566. }
  4567. tanh() {
  4568. return this._convertToNumber().tanh();
  4569. }
  4570. atan() {
  4571. return this._convertToNumber().atan();
  4572. }
  4573. atan2(e) {
  4574. return this._convertToNumber().atan2(e);
  4575. }
  4576. atanh() {
  4577. return this._convertToNumber().atanh();
  4578. }
  4579. log() {
  4580. return this._convertToNumber().log();
  4581. }
  4582. log10() {
  4583. return this._convertToNumber().log10();
  4584. }
  4585. exp() {
  4586. return this._convertToNumber().exp();
  4587. }
  4588. abs() {
  4589. return this._convertToNumber().abs();
  4590. }
  4591. round(e) {
  4592. return this._convertToNumber().round(e);
  4593. }
  4594. floor(e) {
  4595. return this._convertToNumber().floor(e);
  4596. }
  4597. ceil(e) {
  4598. return this._convertToNumber().ceil(e);
  4599. }
  4600. convertToNumberObjectValue() {
  4601. return Fn(this.getValue());
  4602. }
  4603. convertToBooleanObjectValue() {
  4604. return this;
  4605. }
  4606. };
  4607. A(qt, "_instanceTrue"), A(qt, "_instanceFalse");
  4608. let T = qt;
  4609. class y extends kt {
  4610. constructor(e) {
  4611. super(e);
  4612. A(this, "_value", 0);
  4613. this._value = Number(e);
  4614. }
  4615. static create(e, t = "") {
  4616. const r = new y(e);
  4617. return t && r.setPattern(t), r;
  4618. }
  4619. getValue() {
  4620. return this._value;
  4621. }
  4622. setValue(e) {
  4623. this._value = e;
  4624. }
  4625. isNumber() {
  4626. return !0;
  4627. }
  4628. getNegative() {
  4629. return y.create(0).minus(this);
  4630. }
  4631. getReciprocal() {
  4632. return y.create(1).divided(this);
  4633. }
  4634. plus(e) {
  4635. if (e.isArray())
  4636. return e.plus(this);
  4637. let t = this.plusBy(e.getValue());
  4638. if (t.isError())
  4639. return t;
  4640. const r = Wr(this.getPattern(), e.getPattern(), X.PLUS);
  4641. return t = y.create(Number(t.getValue()), r), t;
  4642. }
  4643. equalZero() {
  4644. return this._value === 0;
  4645. }
  4646. minus(e) {
  4647. if (e.isArray()) {
  4648. const n = e.getNegative();
  4649. return n.isError() ? n : n.plus(this);
  4650. }
  4651. let t = this.minusBy(e.getValue());
  4652. if (t.isError())
  4653. return t;
  4654. const r = Wr(this.getPattern(), e.getPattern(), X.MINUS);
  4655. return t = y.create(Number(t.getValue()), r), t;
  4656. }
  4657. multiply(e) {
  4658. if (e.isArray())
  4659. return e.multiply(this);
  4660. let t = this.multiplyBy(e.getValue());
  4661. if (t.isError())
  4662. return t;
  4663. const r = Wr(this.getPattern(), e.getPattern(), X.MULTIPLY);
  4664. return t = y.create(Number(t.getValue()), r), t;
  4665. }
  4666. divided(e) {
  4667. if (e.isArray()) {
  4668. const n = e.getReciprocal();
  4669. return n.isError() ? n : n.multiply(this);
  4670. }
  4671. let t = this.dividedBy(e.getValue());
  4672. if (t.isError())
  4673. return t;
  4674. const r = Wr(this.getPattern(), e.getPattern(), X.DIVIDED);
  4675. return t = y.create(Number(t.getValue()), r), t;
  4676. }
  4677. mod(e) {
  4678. if (e.isArray())
  4679. return e.modInverse(this);
  4680. const t = this.getValue(), r = e.getValue();
  4681. if (e.isNull())
  4682. return g.create(m.DIV_BY_ZERO);
  4683. if (typeof r == "string")
  4684. return g.create(m.VALUE);
  4685. if (typeof r == "number") {
  4686. if (r === 0)
  4687. return g.create(m.DIV_BY_ZERO);
  4688. if (!Number.isFinite(t) || !Number.isFinite(r) || Math.abs(r) * 11259e8 <= Math.abs(t))
  4689. return g.create(m.NUM);
  4690. const n = gi(t, r);
  4691. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4692. }
  4693. if (typeof r == "boolean") {
  4694. const n = r ? 1 : 0;
  4695. return n === 0 ? g.create(m.DIV_BY_ZERO) : y.create(gi(t, n));
  4696. }
  4697. return this;
  4698. }
  4699. concatenateFront(e) {
  4700. return e.isArray() ? e.concatenateBack(this) : j.create(this.concatenate(e.getValue(), it.FRONT));
  4701. }
  4702. concatenateBack(e) {
  4703. return e.isArray() ? e.concatenateFront(this) : j.create(this.concatenate(e.getValue(), it.BACK));
  4704. }
  4705. compare(e, t) {
  4706. return e.isArray() ? e.compare(this, ma(t)) : this.compareBy(e.getValue(), t);
  4707. }
  4708. plusBy(e) {
  4709. const t = +this.getValue(), r = +e;
  4710. if (Number.isNaN(t) || Number.isNaN(r))
  4711. return g.create(m.VALUE);
  4712. if (!Number.isFinite(t) || !Number.isFinite(r))
  4713. return g.create(m.NUM);
  4714. const n = of(t, r);
  4715. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4716. }
  4717. minusBy(e) {
  4718. const t = +this.getValue(), r = +e;
  4719. if (Number.isNaN(t) || Number.isNaN(r))
  4720. return g.create(m.VALUE);
  4721. if (!Number.isFinite(t) || !Number.isFinite(r))
  4722. return g.create(m.NUM);
  4723. const n = uf(t, r);
  4724. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4725. }
  4726. multiplyBy(e) {
  4727. const t = +this.getValue(), r = +e;
  4728. if (Number.isNaN(t) || Number.isNaN(r))
  4729. return g.create(m.VALUE);
  4730. if (!Number.isFinite(t) || !Number.isFinite(r))
  4731. return g.create(m.NUM);
  4732. const n = Vr(t, r);
  4733. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4734. }
  4735. dividedBy(e) {
  4736. const t = +this.getValue(), r = +e;
  4737. if (Number.isNaN(t) || Number.isNaN(r))
  4738. return g.create(m.VALUE);
  4739. if (!Number.isFinite(t) || !Number.isFinite(r))
  4740. return g.create(m.NUM);
  4741. if (r === 0)
  4742. return g.create(m.DIV_BY_ZERO);
  4743. const n = cf(t, r);
  4744. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4745. }
  4746. compareBy(e, t) {
  4747. const r = this.getValue();
  4748. let n = !1;
  4749. return typeof e == "string" ? n = this._compareString(t) : typeof e == "number" ? n = this._compareNumber(r, e, t) : typeof e == "boolean" && (n = this._compareBoolean(t)), T.create(n);
  4750. }
  4751. _compareString(e) {
  4752. switch (e) {
  4753. case $.EQUALS:
  4754. case $.GREATER_THAN:
  4755. case $.GREATER_THAN_OR_EQUAL:
  4756. return !1;
  4757. case $.LESS_THAN:
  4758. case $.LESS_THAN_OR_EQUAL:
  4759. case $.NOT_EQUAL:
  4760. return !0;
  4761. }
  4762. }
  4763. _compareNumber(e, t, r) {
  4764. return !Number.isFinite(e) || !Number.isFinite(t) ? this._compareInfinity(e, t, r) : this._compareFiniteNumber(e, t, r);
  4765. }
  4766. _compareFiniteNumber(e, t, r) {
  4767. switch (r) {
  4768. case $.EQUALS:
  4769. return di(e, t);
  4770. case $.GREATER_THAN:
  4771. return hf(e, t);
  4772. case $.GREATER_THAN_OR_EQUAL:
  4773. return mf(e, t);
  4774. case $.LESS_THAN:
  4775. return gf(e, t);
  4776. case $.LESS_THAN_OR_EQUAL:
  4777. return df(e, t);
  4778. case $.NOT_EQUAL:
  4779. return !di(e, t);
  4780. }
  4781. }
  4782. _compareBoolean(e) {
  4783. switch (e) {
  4784. case $.EQUALS:
  4785. case $.GREATER_THAN:
  4786. case $.GREATER_THAN_OR_EQUAL:
  4787. return !1;
  4788. case $.LESS_THAN:
  4789. case $.LESS_THAN_OR_EQUAL:
  4790. case $.NOT_EQUAL:
  4791. return !0;
  4792. }
  4793. }
  4794. pow(e) {
  4795. if (e.isArray())
  4796. return e.powInverse(this);
  4797. if (this.isError())
  4798. return this;
  4799. const t = this.getValue();
  4800. let r = e;
  4801. if (e.isString() && (r = e.convertToNumberObjectValue()), r.isError())
  4802. return r;
  4803. const n = +r.getValue();
  4804. if (Number.isNaN(n))
  4805. return g.create(m.VALUE);
  4806. if (!Number.isFinite(t) || !Number.isFinite(n))
  4807. return g.create(m.NUM);
  4808. if (t === 0)
  4809. return n < 0 ? g.create(m.DIV_BY_ZERO) : n === 0 ? g.create(m.NUM) : y.create(0);
  4810. const s = lf(t, n);
  4811. return Number.isFinite(s) ? y.create(s) : g.create(m.NUM);
  4812. }
  4813. sqrt() {
  4814. const e = this.getValue();
  4815. if (!Number.isFinite(e))
  4816. return g.create(m.NUM);
  4817. const t = ff(e);
  4818. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4819. }
  4820. cbrt() {
  4821. const e = this.getValue();
  4822. if (!Number.isFinite(e))
  4823. return g.create(m.NUM);
  4824. const t = Math.cbrt(e);
  4825. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4826. }
  4827. cos() {
  4828. const e = this.getValue();
  4829. if (!Number.isFinite(e))
  4830. return g.create(m.NUM);
  4831. const t = Math.cos(e);
  4832. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4833. }
  4834. cosh() {
  4835. const e = this.getValue();
  4836. if (!Number.isFinite(e))
  4837. return g.create(m.NUM);
  4838. const t = Math.cosh(e);
  4839. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4840. }
  4841. acos() {
  4842. const e = this.getValue();
  4843. if (!Number.isFinite(e))
  4844. return g.create(m.NUM);
  4845. const t = Math.acos(e);
  4846. return Number.isNaN(t) ? g.create(m.NUM) : y.create(t);
  4847. }
  4848. acosh() {
  4849. const e = this.getValue();
  4850. if (!Number.isFinite(e))
  4851. return g.create(m.NUM);
  4852. const t = Math.acosh(e);
  4853. return Number.isNaN(t) ? g.create(m.NUM) : y.create(t);
  4854. }
  4855. sin() {
  4856. const e = this.getValue();
  4857. if (!Number.isFinite(e))
  4858. return g.create(m.NUM);
  4859. const t = Math.sin(e);
  4860. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4861. }
  4862. sinh() {
  4863. const e = this.getValue();
  4864. if (!Number.isFinite(e))
  4865. return g.create(m.NUM);
  4866. const t = Math.sinh(e);
  4867. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4868. }
  4869. asin() {
  4870. const e = this.getValue();
  4871. if (!Number.isFinite(e))
  4872. return g.create(m.NUM);
  4873. const t = Math.asin(e);
  4874. return Number.isNaN(t) ? g.create(m.NUM) : y.create(t);
  4875. }
  4876. asinh() {
  4877. const e = this.getValue();
  4878. if (!Number.isFinite(e))
  4879. return g.create(m.NUM);
  4880. const t = Math.asinh(e);
  4881. return Number.isNaN(t) ? g.create(m.NUM) : y.create(t);
  4882. }
  4883. tan() {
  4884. const e = this.getValue();
  4885. if (!Number.isFinite(e))
  4886. return g.create(m.NUM);
  4887. const t = Math.tan(e);
  4888. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4889. }
  4890. tanh() {
  4891. const e = this.getValue();
  4892. if (!Number.isFinite(e))
  4893. return g.create(m.NUM);
  4894. const t = Math.tanh(e);
  4895. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4896. }
  4897. atan() {
  4898. const e = this.getValue();
  4899. if (!Number.isFinite(e))
  4900. return g.create(m.NUM);
  4901. const t = Math.atan(e);
  4902. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4903. }
  4904. atan2(e) {
  4905. if (e.isArray())
  4906. return e.atan2Inverse(this);
  4907. const t = this.getValue(), r = e.getValue();
  4908. if (typeof r == "string")
  4909. return g.create(m.VALUE);
  4910. if (typeof r == "number") {
  4911. if (!Number.isFinite(t) || !Number.isFinite(r))
  4912. return g.create(m.NUM);
  4913. if (t === 0 && r === 0)
  4914. return g.create(m.DIV_BY_ZERO);
  4915. const n = Math.atan2(t, r);
  4916. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4917. }
  4918. return typeof r == "boolean" ? y.create(Math.atan2(t, r ? 1 : 0)) : this;
  4919. }
  4920. atanh() {
  4921. const e = this.getValue();
  4922. if (!Number.isFinite(e))
  4923. return g.create(m.NUM);
  4924. const t = Math.atanh(e);
  4925. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4926. }
  4927. log() {
  4928. const e = this.getValue();
  4929. if (typeof e == "number" && e <= 0 || !Number.isFinite(e))
  4930. return g.create(m.NUM);
  4931. const t = Math.log(e);
  4932. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4933. }
  4934. log10() {
  4935. const e = this.getValue();
  4936. if (typeof e == "number" && e <= 0 || !Number.isFinite(e))
  4937. return g.create(m.NUM);
  4938. const t = Math.log10(e);
  4939. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4940. }
  4941. exp() {
  4942. const e = this.getValue();
  4943. if (!Number.isFinite(e))
  4944. return g.create(m.NUM);
  4945. const t = Math.exp(e);
  4946. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4947. }
  4948. abs() {
  4949. const e = this.getValue();
  4950. if (!Number.isFinite(e))
  4951. return g.create(m.NUM);
  4952. const t = Math.abs(e);
  4953. return Number.isFinite(t) ? y.create(t) : g.create(m.NUM);
  4954. }
  4955. round(e) {
  4956. if (e.isArray())
  4957. return e.roundInverse(this);
  4958. const t = this.getValue(), r = e.getValue();
  4959. if (typeof r == "string")
  4960. return g.create(m.VALUE);
  4961. if (typeof r == "number") {
  4962. if (!Number.isFinite(t) || !Number.isFinite(r))
  4963. return g.create(m.NUM);
  4964. const n = t < 0 ? -vt(Math.abs(t), r) : vt(t, r);
  4965. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4966. }
  4967. return typeof r == "boolean" ? y.create(vt(t, r ? 1 : 0)) : this;
  4968. }
  4969. floor(e) {
  4970. if (e.isArray())
  4971. return e.floorInverse(this);
  4972. const t = this.getValue(), r = e.getValue();
  4973. if (typeof r == "string")
  4974. return g.create(m.VALUE);
  4975. if (typeof r == "number") {
  4976. if (!Number.isFinite(t) || !Number.isFinite(r))
  4977. return g.create(m.NUM);
  4978. const n = t < 0 ? -We(Math.abs(t), r) : We(t, r);
  4979. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4980. }
  4981. return typeof r == "boolean" ? y.create(We(t, r ? 1 : 0)) : this;
  4982. }
  4983. ceil(e) {
  4984. if (e.isArray())
  4985. return e.ceilInverse(this);
  4986. const t = this.getValue(), r = e.getValue();
  4987. if (typeof r == "string")
  4988. return g.create(m.VALUE);
  4989. if (typeof r == "number") {
  4990. if (!Number.isFinite(t) || !Number.isFinite(r))
  4991. return g.create(m.NUM);
  4992. const n = t < 0 ? -Ye(Math.abs(t), r) : Ye(t, r);
  4993. return Number.isFinite(n) ? y.create(n) : g.create(m.NUM);
  4994. }
  4995. return typeof r == "boolean" ? y.create(Ye(t, r ? 1 : 0)) : this;
  4996. }
  4997. convertToNumberObjectValue() {
  4998. return this;
  4999. }
  5000. convertToBooleanObjectValue() {
  5001. return In(!0);
  5002. }
  5003. _compareInfinity(e, t, r) {
  5004. let n = !1;
  5005. switch (r) {
  5006. case $.EQUALS:
  5007. n = e === t;
  5008. break;
  5009. case $.GREATER_THAN:
  5010. n = e > t;
  5011. break;
  5012. case $.GREATER_THAN_OR_EQUAL:
  5013. n = e >= t;
  5014. break;
  5015. case $.LESS_THAN:
  5016. n = e < t;
  5017. break;
  5018. case $.LESS_THAN_OR_EQUAL:
  5019. n = e <= t;
  5020. break;
  5021. case $.NOT_EQUAL:
  5022. n = e !== t;
  5023. break;
  5024. }
  5025. return n;
  5026. }
  5027. }
  5028. const Ef = 1e5, _i = new Vt(Ef);
  5029. class j extends kt {
  5030. constructor(e) {
  5031. super(e);
  5032. A(this, "_value");
  5033. this._value = e;
  5034. }
  5035. static create(e) {
  5036. const t = _i.get(e);
  5037. if (t)
  5038. return t;
  5039. const r = new j(e);
  5040. return _i.set(e, r), r;
  5041. }
  5042. getValue() {
  5043. return this._value;
  5044. }
  5045. isString() {
  5046. return !0;
  5047. }
  5048. concatenateFront(e) {
  5049. return e.isArray() ? e.concatenateBack(this) : j.create(this.concatenate(e.getValue(), it.FRONT));
  5050. }
  5051. concatenateBack(e) {
  5052. return e.isArray() ? e.concatenateFront(this) : j.create(this.concatenate(e.getValue(), it.BACK));
  5053. }
  5054. plus(e) {
  5055. return this.convertToNumberObjectValue().plus(e);
  5056. }
  5057. minus(e) {
  5058. return this.convertToNumberObjectValue().minus(e);
  5059. }
  5060. multiply(e) {
  5061. return this.convertToNumberObjectValue().multiply(e);
  5062. }
  5063. divided(e) {
  5064. return this.convertToNumberObjectValue().divided(e);
  5065. }
  5066. compare(e, t, r) {
  5067. return e.isArray() ? e.compare(this, ma(t), r) : this.compareBy(e.getValue(), t, r);
  5068. }
  5069. compareBy(e, t, r = !1) {
  5070. let n = this.getValue(), s = !1;
  5071. if (typeof e == "string") {
  5072. let o = e;
  5073. if (r || (n = n.toLocaleLowerCase(), o = o.toLocaleLowerCase()), ll(o))
  5074. return this._checkWildcard(o, t);
  5075. s = this._compareString(n, o, t);
  5076. } else typeof e == "number" ? s = this._compareNumber(t) : typeof e == "boolean" && (s = this._compareBoolean(t));
  5077. return T.create(s);
  5078. }
  5079. _compareString(e, t, r) {
  5080. switch (r) {
  5081. case $.EQUALS:
  5082. return e === t;
  5083. case $.GREATER_THAN:
  5084. return e > t;
  5085. case $.GREATER_THAN_OR_EQUAL:
  5086. return e >= t;
  5087. case $.LESS_THAN:
  5088. return e < t;
  5089. case $.LESS_THAN_OR_EQUAL:
  5090. return e <= t;
  5091. case $.NOT_EQUAL:
  5092. return e !== t;
  5093. }
  5094. }
  5095. _compareNumber(e) {
  5096. switch (e) {
  5097. case $.NOT_EQUAL:
  5098. case $.GREATER_THAN:
  5099. case $.GREATER_THAN_OR_EQUAL:
  5100. return !0;
  5101. case $.EQUALS:
  5102. case $.LESS_THAN:
  5103. case $.LESS_THAN_OR_EQUAL:
  5104. return !1;
  5105. }
  5106. }
  5107. _compareBoolean(e) {
  5108. switch (e) {
  5109. case $.EQUALS:
  5110. case $.GREATER_THAN:
  5111. case $.GREATER_THAN_OR_EQUAL:
  5112. return !1;
  5113. case $.LESS_THAN:
  5114. case $.LESS_THAN_OR_EQUAL:
  5115. case $.NOT_EQUAL:
  5116. return !0;
  5117. }
  5118. }
  5119. convertToNumberObjectValue() {
  5120. return Fn(this.getValue());
  5121. }
  5122. convertToBooleanObjectValue() {
  5123. return T.create(!0);
  5124. }
  5125. _checkWildcard(e, t) {
  5126. const r = this.getValue().toLocaleLowerCase(), n = fl(r, e, t);
  5127. return T.create(n);
  5128. }
  5129. }
  5130. function In(i) {
  5131. if (typeof i == "boolean")
  5132. return T.create(i);
  5133. let a = !1;
  5134. if (typeof i == "string") {
  5135. const e = i.toLocaleUpperCase();
  5136. e === er.TRUE ? a = !0 : e === er.FALSE && (a = !1);
  5137. } else
  5138. i === 1 ? a = !0 : a = !1;
  5139. return T.create(a);
  5140. }
  5141. function bf(i) {
  5142. let a = i.toString();
  5143. return a.charAt(0) === '"' && a.charAt(a.length - 1) === '"' && (a = a.slice(1, -1), a = a.replace(/""/g, '"')), j.create(a);
  5144. }
  5145. function Fn(i, a = "") {
  5146. if (typeof i == "boolean") {
  5147. let e = 0;
  5148. return i && (e = 1), y.create(e, a);
  5149. } else {
  5150. if (typeof i == "number")
  5151. return Number.isFinite(i) ? y.create(i, a) : g.create(m.NUM);
  5152. if (Q(i))
  5153. return y.create(Number(i), a);
  5154. }
  5155. return g.create(m.VALUE);
  5156. }
  5157. function yf(i) {
  5158. return "";
  5159. }
  5160. function Ao(i = []) {
  5161. const a = [];
  5162. for (let e = 0; e < i.length; e++) {
  5163. const t = i[e];
  5164. a[e] == null && (a[e] = []);
  5165. for (let r = 0; r < t.length; r++) {
  5166. const n = t[r];
  5167. a[e][r] = pt.create(n);
  5168. }
  5169. }
  5170. return a;
  5171. }
  5172. function Rf(i = []) {
  5173. const a = [];
  5174. for (let e = 0; e < i.length; e++) {
  5175. const t = i[e];
  5176. a[e] == null && (a[e] = []);
  5177. for (let r = 0; r < t.length; r++) {
  5178. const n = t[r];
  5179. n == null ? a[e][r] = null : n.isError() ? a[e][r] = n.getErrorType() : a[e][r] = n.getValue();
  5180. }
  5181. }
  5182. return a;
  5183. }
  5184. class q extends kt {
  5185. constructor(e) {
  5186. super(typeof e == "string" ? e : yf());
  5187. A(this, "_values", []);
  5188. A(this, "_rowCount", -1);
  5189. A(this, "_columnCount", -1);
  5190. A(this, "_unitId", "");
  5191. A(this, "_sheetId", "");
  5192. A(this, "_currentRow", -1);
  5193. A(this, "_currentColumn", -1);
  5194. A(this, "_sliceCache", /* @__PURE__ */ new Map());
  5195. A(this, "_flattenCache");
  5196. /**
  5197. * The default value of the array, null values in comparison results support setting to false
  5198. */
  5199. A(this, "_defaultValue", null);
  5200. A(this, "_flattenPosition");
  5201. this._values = this._formatValue(e);
  5202. }
  5203. /**
  5204. * Create an array value object based on the string or IArrayValueObject data.
  5205. * @param rawValue
  5206. * @returns
  5207. */
  5208. static create(e) {
  5209. return new q(e);
  5210. }
  5211. /**
  5212. * Create an array value object based on the array data.
  5213. * @param array
  5214. * @returns
  5215. */
  5216. static createByArray(e) {
  5217. const r = {
  5218. calculateValueList: Ao(e),
  5219. rowCount: e.length,
  5220. columnCount: e[0].length || 0,
  5221. unitId: "",
  5222. sheetId: "",
  5223. row: -1,
  5224. column: -1
  5225. };
  5226. return new q(r);
  5227. }
  5228. dispose() {
  5229. this._values = [], this._defaultValue = null, this._flattenPosition = null, this._clearCache();
  5230. }
  5231. clone() {
  5232. return this.map((e) => e);
  5233. }
  5234. getRowCount() {
  5235. return this._rowCount;
  5236. }
  5237. setRowCount(e) {
  5238. this._rowCount = e;
  5239. }
  5240. getColumnCount() {
  5241. return this._columnCount;
  5242. }
  5243. setColumnCount(e) {
  5244. this._columnCount = e;
  5245. }
  5246. setCurrent(e, t) {
  5247. this._currentRow = e, this._currentColumn = t;
  5248. }
  5249. setUnitId(e) {
  5250. this._unitId = e;
  5251. }
  5252. getUnitId() {
  5253. return this._unitId;
  5254. }
  5255. setSheetId(e) {
  5256. this._sheetId = e;
  5257. }
  5258. getSheetId() {
  5259. return this._sheetId;
  5260. }
  5261. getCurrentRow() {
  5262. return this._currentRow;
  5263. }
  5264. getCurrentColumn() {
  5265. return this._currentColumn;
  5266. }
  5267. getArrayValue() {
  5268. return this._values;
  5269. }
  5270. setArrayValue(e) {
  5271. this._clearCache(), this._values = e;
  5272. }
  5273. isArray() {
  5274. return !0;
  5275. }
  5276. setDefaultValue(e) {
  5277. this._defaultValue = e;
  5278. }
  5279. get(e, t) {
  5280. var r;
  5281. return ((r = this._values[e]) == null ? void 0 : r[t]) || this._defaultValue;
  5282. }
  5283. getRealValue(e, t) {
  5284. const r = this._values[e];
  5285. if (r == null)
  5286. return null;
  5287. const n = r[t];
  5288. return n == null ? null : n;
  5289. }
  5290. getValueOrDefault(e, t) {
  5291. return this.get(e, t) || this._defaultValue;
  5292. }
  5293. set(e, t, r) {
  5294. if (e >= this._rowCount || t >= this._columnCount)
  5295. throw new Error("Exceeding array bounds.");
  5296. this._clearCache(), this._values[e][t] = r;
  5297. }
  5298. getRangePosition() {
  5299. const t = this.getRowCount(), r = 0, n = this.getColumnCount();
  5300. return {
  5301. startRow: 0,
  5302. endRow: t - 1,
  5303. startColumn: r,
  5304. endColumn: n - 1
  5305. };
  5306. }
  5307. iterator(e) {
  5308. var u;
  5309. const { startRow: t, endRow: r, startColumn: n, endColumn: s } = this.getRangePosition(), o = this.getArrayValue();
  5310. for (let c = t; c <= r; c++)
  5311. for (let l = n; l <= s; l++)
  5312. if (e(((u = o[c]) == null ? void 0 : u[l]) || this._defaultValue, c, l) === !1)
  5313. return;
  5314. }
  5315. iteratorReverse(e) {
  5316. var u;
  5317. const { startRow: t, endRow: r, startColumn: n, endColumn: s } = this.getRangePosition(), o = this.getArrayValue();
  5318. for (let c = r; c >= t; c--)
  5319. for (let l = s; l >= n; l--)
  5320. if (e(((u = o[c]) == null ? void 0 : u[l]) || this._defaultValue, c, l) === !1)
  5321. return;
  5322. }
  5323. getLastTruePosition() {
  5324. let e;
  5325. return this.iteratorReverse((t, r, n) => {
  5326. if (t != null && t.isBoolean() && t.getValue() === !0)
  5327. return e = {
  5328. row: r,
  5329. column: n
  5330. }, !1;
  5331. }), e;
  5332. }
  5333. getFirstTruePosition() {
  5334. let e;
  5335. return this.iterator((t, r, n) => {
  5336. if (t != null && t.isBoolean() && t.getValue() === !0)
  5337. return e = {
  5338. row: r,
  5339. column: n
  5340. }, !1;
  5341. }), e;
  5342. }
  5343. getFirstCell() {
  5344. const { startRow: e, startColumn: t } = this.getRangePosition();
  5345. return this.get(e, t) || this._defaultValue || ie.create();
  5346. }
  5347. getLastCell() {
  5348. const { endRow: e, endColumn: t } = this.getRangePosition();
  5349. return this.get(e, t) || this._defaultValue || ie.create();
  5350. }
  5351. /**
  5352. * Referring to matrix calculations,
  5353. * extract the matching values from a true/false matrix based on parameters and store them in a two-dimensional array.
  5354. * implement x[x<10]
  5355. * https://numpy.org/doc/stable/user/basics.indexing.html
  5356. * @param takeArray
  5357. */
  5358. pick(e) {
  5359. const t = this.pickRaw(e);
  5360. return this._createNewArray(t, 1, t[0].length);
  5361. }
  5362. pickRaw(e) {
  5363. const t = e.getRowCount(), r = e.getColumnCount();
  5364. if (t !== this._rowCount || r !== this._columnCount)
  5365. return [[ie.create()]];
  5366. const n = [];
  5367. n[0] = [];
  5368. for (let s = 0; s < t; s++)
  5369. for (let o = 0; o < r; o++) {
  5370. const u = e.get(s, o);
  5371. if (!(u == null || u.isError()) && u.getValue() === !0) {
  5372. const c = this.get(s, o);
  5373. n[0].push(c);
  5374. }
  5375. }
  5376. return n;
  5377. }
  5378. /**
  5379. * Flatten a 2D array.
  5380. * https://numpy.org/doc/stable/reference/generated/numpy.chararray.flatten.html#numpy.chararray.flatten
  5381. */
  5382. flatten() {
  5383. if (this._flattenCache != null)
  5384. return this._flattenCache;
  5385. const e = [];
  5386. e[0] = [];
  5387. for (let r = 0; r < this._rowCount; r++)
  5388. for (let n = 0; n < this._columnCount; n++) {
  5389. const s = this.get(r, n);
  5390. e[0].push(s);
  5391. }
  5392. const t = this._createNewArray(e, 1, e[0].length);
  5393. return t.setDefaultValue(this._defaultValue), this._flattenCache = t, t;
  5394. }
  5395. /**
  5396. * Flatten a 2D array.
  5397. * In Excel, errors and blank cells are ignored, which results in a binary search that cannot strictly adhere to the number of cells.
  5398. */
  5399. flattenPosition() {
  5400. if (this._flattenPosition != null)
  5401. return this._flattenPosition;
  5402. const e = [], t = [], r = [], n = [];
  5403. let s = 0;
  5404. for (let u = 0; u < this._rowCount; u++)
  5405. for (let c = 0; c < this._columnCount; c++) {
  5406. const l = this.get(u, c);
  5407. if (l == null || l.isError() || l.isNull()) {
  5408. s++;
  5409. continue;
  5410. }
  5411. l.isString() ? (e.push(l), r.push(s++)) : (t.push(l), n.push(s++));
  5412. }
  5413. const o = {
  5414. stringArray: e,
  5415. numberArray: t,
  5416. stringPosition: r,
  5417. numberPosition: n
  5418. };
  5419. return this._flattenPosition = o, o;
  5420. }
  5421. /**
  5422. * I'm looking to perform slicing operations on 2D arrays, similar to the functionality provided by NumPy.
  5423. * https://numpy.org/doc/stable/user/basics.indexing.html
  5424. * @rowParam start:stop:step
  5425. * @columnParam start:stop:step
  5426. * @param takeArray
  5427. */
  5428. slice(e, t) {
  5429. let r = 0, n = this._rowCount, s = 1, o = 0, u = this._columnCount, c = 1;
  5430. if (e != null && (r = e[0] || 0, n = e[1] || this._rowCount, s = e[2] || 1), t != null && (o = t[0] || 0, u = t[1] || this._columnCount, c = t[2] || 1), r >= this._rowCount || o >= this._columnCount)
  5431. return;
  5432. const l = `${r}_${n}_${s}_${o}_${u}_${c}`, f = this._sliceCache.get(l);
  5433. if (f != null)
  5434. return f;
  5435. const h = [], d = this._values;
  5436. let _ = 0, C = 0;
  5437. for (let p = r; p < n; p += s) {
  5438. C = 0, h[_] == null && (h[_] = []);
  5439. for (let N = o; N < u; N += c) {
  5440. if (!d[p])
  5441. return;
  5442. let M = d[p][N] || this._defaultValue;
  5443. M == null && (M = ie.create()), h[_][C] = M, C++;
  5444. }
  5445. _++;
  5446. }
  5447. if (h.length === 0 || h[0].length === 0)
  5448. return;
  5449. const E = s > 1 ? -1 : r + this._currentRow, b = c > 1 ? -1 : o + this._currentColumn, R = this._createNewArray(h, h.length, h[0].length, E, b);
  5450. return R.setDefaultValue(this._defaultValue), this._sliceCache.set(l, R), R;
  5451. }
  5452. sortByRow(e) {
  5453. const t = this._transposeArray(this._values);
  5454. t.sort(this._sort(e)), this._clearCache(), this._values = this._transposeArray(t);
  5455. }
  5456. sortByColumn(e) {
  5457. this._clearCache(), this._values.sort(this._sort(e));
  5458. }
  5459. transpose() {
  5460. const e = this._transposeArray(this._values), t = this._rowCount, r = this._columnCount, n = this._createNewArray(e, r, t);
  5461. return n.setDefaultValue(this._defaultValue), n;
  5462. }
  5463. /**
  5464. * Due to the inability to effectively utilize the cache,
  5465. * the sequential matching approach is only used for special matches in XLOOKUP and XMATCH.
  5466. * For example, when match_mode is set to 1 and -1 for an exact match. If not found, it returns the next smaller item.
  5467. */
  5468. orderSearch(e, t = Pe.MIN, r = !1, n = !1) {
  5469. let s, o, u, c;
  5470. const l = (f, h, d) => {
  5471. if (f == null)
  5472. return !0;
  5473. let _;
  5474. if (n === !0 ? _ = f.compare(e, $.EQUALS) : _ = f.isEqual(e), (_ == null ? void 0 : _.getValue()) === !0)
  5475. return s = f, u = { row: h, column: d }, !1;
  5476. t === Pe.MAX ? f.isGreaterThan(e).getValue() === !0 && (o == null || f.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue() === !0) && (o = f, c = { row: h, column: d }) : t === Pe.MIN && f.isLessThan(e).getValue() === !0 && (o == null || f.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue() === !0) && (o = f, c = { row: h, column: d });
  5477. };
  5478. if (r ? this.iteratorReverse((f, h, d) => l(f, h, d)) : this.iterator((f, h, d) => l(f, h, d)), s != null)
  5479. return u;
  5480. if (o != null)
  5481. return c;
  5482. }
  5483. binarySearch(e, t = Wt.MIN, r = Pe.MIN) {
  5484. if (e.isError())
  5485. return;
  5486. const { stringArray: n, stringPosition: s, numberArray: o, numberPosition: u } = this.flattenPosition();
  5487. return e.isString() ? this._binarySearch(e, n, s, t, r) : this._binarySearch(e, o, u, t, r);
  5488. }
  5489. /**
  5490. * searchType defaults to ascending order
  5491. *
  5492. * matchType defaults to the maximum value less than the search value, which is used for the default matching mode of VLOOKUP/LOOKUP/HLOOKUP.
  5493. * @param valueObject
  5494. * @param searchArray
  5495. * @param positionArray
  5496. * @param searchType
  5497. * @param matchType
  5498. * @returns
  5499. */
  5500. _binarySearch(e, t, r, n = Wt.MIN, s = Pe.MIN) {
  5501. const o = hn(), u = Number(e.getValue()), c = !Number.isNaN(u);
  5502. let l = 0, f = t.length - 1, h = -1, d = -1, _ = -1;
  5503. for (; l <= f; ) {
  5504. const C = Math.floor((l + f) / 2), E = t[C];
  5505. let b;
  5506. if (E.isNull())
  5507. b = n === Wt.MIN ? 1 : -1;
  5508. else {
  5509. const R = E.getValue();
  5510. if (c) {
  5511. const p = Number(R);
  5512. b = Number.isNaN(p) ? 1 : Math.sign(p - u);
  5513. } else
  5514. b = o(R.toString().toLocaleLowerCase(), e.getValue().toString().toLocaleLowerCase());
  5515. }
  5516. if (n === Wt.MAX && (b = -b), b === 0) {
  5517. h = C;
  5518. break;
  5519. }
  5520. b < 0 ? (d = C, l = C + 1) : (_ = C, f = C - 1);
  5521. }
  5522. if (s === Pe.NORMAL)
  5523. return h !== -1 ? r[h] : void 0;
  5524. if (s === Pe.MIN)
  5525. return h !== -1 ? r[h] : n === Wt.MIN ? r[d] : r[_];
  5526. if (s === Pe.MAX)
  5527. return h !== -1 ? r[h] : n === Wt.MIN ? r[_] : r[d];
  5528. }
  5529. sum() {
  5530. let e = y.create(0);
  5531. return this.iterator((t) => {
  5532. if (t == null || t.isString() || t.isBoolean() || t.isNull())
  5533. return !0;
  5534. if (t.isError())
  5535. return e = t, !1;
  5536. e = e.plus(
  5537. t
  5538. );
  5539. }), e;
  5540. }
  5541. max() {
  5542. let e = y.create(Number.NEGATIVE_INFINITY);
  5543. return this.iterator((t) => {
  5544. if (t == null)
  5545. return !0;
  5546. if (t.isError())
  5547. return e = t, !1;
  5548. if (t.isString() || t.isNull() || t.isBoolean())
  5549. return !0;
  5550. e.isLessThan(t).getValue() && (e = t);
  5551. }), e;
  5552. }
  5553. min() {
  5554. let e = y.create(Number.POSITIVE_INFINITY);
  5555. return this.iterator((t) => {
  5556. if (t == null)
  5557. return !0;
  5558. if (t.isError())
  5559. return e = t, !1;
  5560. if (t.isString() || t.isNull() || t.isBoolean())
  5561. return !0;
  5562. e.isGreaterThan(t).getValue() && (e = t);
  5563. }), e;
  5564. }
  5565. count() {
  5566. let e = y.create(0);
  5567. return this.iterator((t) => {
  5568. if (t == null || t.isError() || t.isString() || t.isNull() || t.isBoolean())
  5569. return !0;
  5570. e = e.plusBy(1);
  5571. }), e;
  5572. }
  5573. countA() {
  5574. let e = y.create(0);
  5575. return this.iterator((t) => {
  5576. if (t == null || t.isNull())
  5577. return !0;
  5578. e = e.plusBy(1);
  5579. }), e;
  5580. }
  5581. countBlank() {
  5582. let e = y.create(0);
  5583. return this.iterator((t) => {
  5584. (t == null || t.isNull() || t.getValue() === "") && (e = e.plusBy(1));
  5585. }), e;
  5586. }
  5587. getNegative() {
  5588. return q.create("{0}").minus(this);
  5589. }
  5590. getReciprocal() {
  5591. return q.create("{1}").divided(this);
  5592. }
  5593. plus(e) {
  5594. return this._batchOperator(
  5595. e,
  5596. 1
  5597. /* PLUS */
  5598. );
  5599. }
  5600. minus(e) {
  5601. return this._batchOperator(
  5602. e,
  5603. 0
  5604. /* MINUS */
  5605. );
  5606. }
  5607. multiply(e) {
  5608. return this._batchOperator(
  5609. e,
  5610. 2
  5611. /* MULTIPLY */
  5612. );
  5613. }
  5614. divided(e) {
  5615. return this._batchOperator(
  5616. e,
  5617. 3
  5618. /* DIVIDED */
  5619. );
  5620. }
  5621. mod(e) {
  5622. return this._batchOperator(
  5623. e,
  5624. 4
  5625. /* MOD */
  5626. );
  5627. }
  5628. modInverse(e) {
  5629. return this.map((t) => t.isError() ? t : e.mod(t));
  5630. }
  5631. compare(e, t, r) {
  5632. return this._batchOperator(e, 5, t, r);
  5633. }
  5634. concatenateFront(e) {
  5635. return this._batchOperator(
  5636. e,
  5637. 6
  5638. /* CONCATENATE_FRONT */
  5639. );
  5640. }
  5641. concatenateBack(e) {
  5642. return this._batchOperator(
  5643. e,
  5644. 7
  5645. /* CONCATENATE_BACK */
  5646. );
  5647. }
  5648. map(e) {
  5649. const t = (r, n, s) => r == null ? ie.create() : r.isError() ? r : e(r, n, s);
  5650. return this.mapValue(t);
  5651. }
  5652. mapValue(e) {
  5653. var s;
  5654. const t = this._rowCount, r = this._columnCount, n = [];
  5655. for (let o = 0; o < t; o++) {
  5656. const u = [];
  5657. for (let c = 0; c < r; c++) {
  5658. const l = (s = this._values) == null ? void 0 : s[o];
  5659. if (l == null)
  5660. u[c] = g.create(m.VALUE);
  5661. else {
  5662. const f = l[c] || this._defaultValue;
  5663. f ? u[c] = e(f, o, c) : u[c] = ie.create();
  5664. }
  5665. }
  5666. n.push(u);
  5667. }
  5668. return this._createNewArray(n, t, r);
  5669. }
  5670. pow(e) {
  5671. return this._batchOperator(
  5672. e,
  5673. 8
  5674. /* POW */
  5675. );
  5676. }
  5677. /**
  5678. *
  5679. * @param valueObject In the case of an inverse, it is certainly not an array.
  5680. * @returns
  5681. */
  5682. powInverse(e) {
  5683. return this.map((t) => t.isError() ? t : e.pow(t));
  5684. }
  5685. sqrt() {
  5686. return this.map((e) => e.isError() ? e : e.sqrt());
  5687. }
  5688. cbrt() {
  5689. return this.map((e) => e.isError() ? e : e.cbrt());
  5690. }
  5691. cos() {
  5692. return this.map((e) => e.isError() ? e : e.cos());
  5693. }
  5694. cosh() {
  5695. return this.map((e) => e.isError() ? e : e.cosh());
  5696. }
  5697. acos() {
  5698. return this.map((e) => e.isError() ? e : e.acos());
  5699. }
  5700. acosh() {
  5701. return this.map((e) => e.isError() ? e : e.acosh());
  5702. }
  5703. sin() {
  5704. return this.map((e) => e.isError() ? e : e.sin());
  5705. }
  5706. sinh() {
  5707. return this.map((e) => e.isError() ? e : e.sinh());
  5708. }
  5709. asin() {
  5710. return this.map((e) => e.isError() ? e : e.asin());
  5711. }
  5712. asinh() {
  5713. return this.map((e) => e.isError() ? e : e.asinh());
  5714. }
  5715. tan() {
  5716. return this.map((e) => e.isError() ? e : e.tan());
  5717. }
  5718. tanh() {
  5719. return this.map((e) => e.isError() ? e : e.tanh());
  5720. }
  5721. atan() {
  5722. return this.map((e) => e.isError() ? e : e.atan());
  5723. }
  5724. atanh() {
  5725. return this.map((e) => e.isError() ? e : e.atanh());
  5726. }
  5727. atan2(e) {
  5728. return this._batchOperator(
  5729. e,
  5730. 12
  5731. /* ATAN2 */
  5732. );
  5733. }
  5734. atan2Inverse(e) {
  5735. return this.map((t) => t.isError() ? t : e.atan2(t));
  5736. }
  5737. mean(e = 0) {
  5738. const t = this.sum(), r = this.count();
  5739. return t.divided(e === 0 ? r : r.minusBy(1));
  5740. }
  5741. median() {
  5742. const e = this.flattenPosition().numberArray, t = this._createNewArray([e], 1, e.length), r = t.getColumnCount();
  5743. if (r <= 1)
  5744. return t.get(0, 0) || ie.create();
  5745. if (t.sortByRow(0), r % 2 === 0) {
  5746. const n = t.get(0, r / 2) || ie.create(), s = t.get(0, r / 2 - 1) || ie.create();
  5747. return n.plus(s).divided(y.create(2));
  5748. }
  5749. return t.get(0, (r - 1) / 2) || ie.create();
  5750. }
  5751. /**
  5752. * ┌──────────────┬────────────────────────────────┬───────────────────┐
  5753. * │ Function │ Ignore logical values and text │ Type │
  5754. * ├──────────────┼────────────────────────────────┼───────────────────┤
  5755. * │ VAR.S (VAR) │ TRUE │ sample │
  5756. * │ VAR.P (VARP) │ TRUE │ entire population │
  5757. * │ VARA │ FALSE │ sample │
  5758. * │ VARPA │ FALSE │ entire population │
  5759. * └──────────────┴────────────────────────────────┴───────────────────┘
  5760. *
  5761. * for VARPA and VARA, strings and FALSE are counted as 0, TRUE is counted as 1
  5762. * for VAR.S/VAR, or VAR.P/VARP, strings,TRUE and FALSE are ignored
  5763. * Since sum ignores strings and booleans, they are ignored here too, and VAR.S and VAR.P are used more
  5764. *
  5765. * VAR.S assumes that its arguments are a sample of the population, like numpy.var(data, ddof=1)
  5766. * VAR.P assumes that its arguments are the entire population, like numpy.var(data, ddof=0)
  5767. * numpy.var uses ddof=0 (Delta Degrees of Freedom) by default, so we use ddof=0 here
  5768. *
  5769. */
  5770. var(e = 0) {
  5771. const t = this.mean(), r = [[]];
  5772. this.iterator((l) => {
  5773. if (l == null || l.isError() || l.isString() || l.isBoolean() || l.isNull())
  5774. return;
  5775. const f = l.minus(t).pow(y.create(2));
  5776. f.isError() || r[0].push(f);
  5777. });
  5778. const { _unitId: n, _sheetId: s, _currentRow: o, _currentColumn: u } = this;
  5779. return q.create({
  5780. calculateValueList: r,
  5781. rowCount: 1,
  5782. columnCount: r[0].length,
  5783. unitId: n,
  5784. sheetId: s,
  5785. row: o,
  5786. column: u
  5787. }).mean(e);
  5788. }
  5789. /**
  5790. * STDEV.P (STDEVP): ddof=0, ignore strings and booleans
  5791. * STDEV.S (STDEV): ddof=1, ignore strings and booleans
  5792. *
  5793. * STDEVPA: ddof=0,
  5794. * STDEVA: ddof=1,
  5795. * @returns
  5796. */
  5797. std(e = 0) {
  5798. const t = this.var(e);
  5799. return t.isError() ? t : t.sqrt();
  5800. }
  5801. log() {
  5802. return this.map((e) => e.isError() ? e : e.log());
  5803. }
  5804. log10() {
  5805. return this.map((e) => e.isError() ? e : e.log10());
  5806. }
  5807. exp() {
  5808. return this.map((e) => e.isError() ? e : e.exp());
  5809. }
  5810. abs() {
  5811. return this.map((e) => e.isError() ? e : e.abs());
  5812. }
  5813. round(e) {
  5814. return this._batchOperator(
  5815. e,
  5816. 9
  5817. /* ROUND */
  5818. );
  5819. }
  5820. roundInverse(e) {
  5821. return this.map((t) => t.isError() ? t : e.round(t));
  5822. }
  5823. floor(e) {
  5824. return this._batchOperator(
  5825. e,
  5826. 10
  5827. /* FLOOR */
  5828. );
  5829. }
  5830. floorInverse(e) {
  5831. return this.map((t) => t.isError() ? t : e.floor(t));
  5832. }
  5833. ceil(e) {
  5834. return this._batchOperator(
  5835. e,
  5836. 11
  5837. /* CEIL */
  5838. );
  5839. }
  5840. ceilInverse(e) {
  5841. return this.map((t) => t.isError() ? t : e.ceil(t));
  5842. }
  5843. toValue() {
  5844. return Rf(this._values);
  5845. }
  5846. _clearCache() {
  5847. this._flattenCache = null, this._sliceCache.clear();
  5848. }
  5849. _sort(e) {
  5850. const t = hn();
  5851. return (r, n) => {
  5852. const s = r[e], o = n[e];
  5853. return s == null ? 1 : o == null ? -1 : s.isError() && s.isError() ? 0 : s.isError() ? 1 : o.isError() ? -1 : t(
  5854. s.getValue(),
  5855. o.getValue()
  5856. );
  5857. };
  5858. }
  5859. _transposeArray(e) {
  5860. const t = e.length, r = e[0].length, n = [];
  5861. for (let s = 0; s < r; s++) {
  5862. n[s] = [];
  5863. for (let o = 0; o < t; o++)
  5864. n[s][o] = e[o][s];
  5865. }
  5866. return n;
  5867. }
  5868. _batchOperator(e, t, r, n) {
  5869. const s = [];
  5870. let o = this._rowCount, u = this._columnCount;
  5871. if (e.isArray()) {
  5872. const f = e.getRowCount(), h = e.getColumnCount();
  5873. if (o = Math.max(f, o), u = Math.max(h, u), f === 1 && h === 1) {
  5874. const d = e.getFirstCell();
  5875. for (let _ = 0; _ < u; _++)
  5876. s.push(d);
  5877. } else if (f === 1 && this._columnCount > 1) {
  5878. const d = e.getArrayValue();
  5879. for (let _ = 0; _ < u; _++)
  5880. s.push(d[0][_]);
  5881. } else
  5882. return this._batchOperatorArray(e, t, r, n);
  5883. } else
  5884. for (let f = 0; f < u; f++)
  5885. s.push(e);
  5886. const c = [];
  5887. for (let f = 0; f < u; f++) {
  5888. const h = s[f];
  5889. this._batchOperatorValue(h, f, c, t, r, n);
  5890. }
  5891. const l = this._createNewArray(c, o, u);
  5892. return l.setDefaultValue(T.create(!1)), l;
  5893. }
  5894. // eslint-disable-next-line max-lines-per-function
  5895. _batchOperatorValue(e, t, r, n, s, o) {
  5896. const u = this._rowCount, c = this.getUnitId(), l = this.getSheetId(), f = this.getCurrentRow(), h = this.getCurrentColumn();
  5897. if (n === 5) {
  5898. const { rowsInCache: d, rowsNotInCache: _ } = St.canUseCache(
  5899. c,
  5900. l,
  5901. t + h,
  5902. f,
  5903. f + u - 1
  5904. );
  5905. if (d.length > 0) {
  5906. if (s === $.EQUALS) {
  5907. const C = St.getCellPositions(
  5908. c,
  5909. l,
  5910. t + h,
  5911. e.getValue(),
  5912. d
  5913. );
  5914. C != null && C.forEach((E) => {
  5915. if (E < f || E > f + u - 1)
  5916. return;
  5917. const b = E - f;
  5918. r[b] == null && (r[b] = []), r[b][t] = T.create(!0);
  5919. });
  5920. } else {
  5921. const C = St.getCellValuePositions(
  5922. c,
  5923. l,
  5924. t + h
  5925. );
  5926. C != null && C.forEach((E, b) => {
  5927. let R = ie.create();
  5928. yr.has(b) ? R = g.create(b) : typeof b == "string" ? R = j.create(b) : typeof b == "number" ? R = y.create(b) : typeof b == "boolean" && (R = T.create(b));
  5929. let p;
  5930. R.isError() ? p = R : e.isError() ? p = e : p = R.compare(e, s, o), (p.isError() || p.getValue() === !0) && E.forEach((N) => {
  5931. N >= f && N <= f + u - 1 && (r[N - f] == null && (r[N - f] = []), r[N - f][t] = p);
  5932. });
  5933. });
  5934. }
  5935. if (_.length > 0)
  5936. for (const C of _) {
  5937. const [E, b] = C;
  5938. for (let R = E; R <= b; R++)
  5939. this.__batchOperatorRowValue(
  5940. e,
  5941. t,
  5942. r,
  5943. n,
  5944. R - f,
  5945. c,
  5946. l,
  5947. f,
  5948. h,
  5949. s,
  5950. o
  5951. );
  5952. St.setContinueBuildingCache(
  5953. c,
  5954. l,
  5955. t + h,
  5956. E,
  5957. b
  5958. );
  5959. }
  5960. return;
  5961. }
  5962. }
  5963. for (let d = 0; d < u; d++)
  5964. this.__batchOperatorRowValue(
  5965. e,
  5966. t,
  5967. r,
  5968. n,
  5969. d,
  5970. c,
  5971. l,
  5972. f,
  5973. h,
  5974. s,
  5975. o
  5976. );
  5977. St.setContinueBuildingCache(
  5978. c,
  5979. l,
  5980. t + h,
  5981. f,
  5982. f + u - 1
  5983. );
  5984. }
  5985. // eslint-disable-next-line
  5986. __batchOperatorRowValue(e, t, r, n, s, o, u, c, l, f, h) {
  5987. const d = this.getValueOrDefault(s, t);
  5988. if (r[s] == null && (r[s] = []), d && e)
  5989. if (d.isError())
  5990. r[s][t] = d;
  5991. else if (e.isError())
  5992. r[s][t] = e;
  5993. else
  5994. switch (n) {
  5995. case 1:
  5996. r[s][t] = d.plus(e);
  5997. break;
  5998. case 0:
  5999. r[s][t] = d.minus(e);
  6000. break;
  6001. case 2:
  6002. r[s][t] = d.multiply(e);
  6003. break;
  6004. case 3:
  6005. r[s][t] = d.divided(e);
  6006. break;
  6007. case 4:
  6008. r[s][t] = d.mod(e);
  6009. break;
  6010. case 5:
  6011. f ? r[s][t] = d.compare(e, f, h) : r[s][t] = g.create(m.VALUE);
  6012. break;
  6013. case 6:
  6014. r[s][t] = d.concatenateFront(e);
  6015. break;
  6016. case 7:
  6017. r[s][t] = d.concatenateBack(e);
  6018. break;
  6019. case 8:
  6020. r[s][t] = d.pow(e);
  6021. break;
  6022. case 9:
  6023. r[s][t] = d.round(e);
  6024. break;
  6025. case 10:
  6026. r[s][t] = d.floor(e);
  6027. break;
  6028. case 12:
  6029. r[s][t] = d.atan2(e);
  6030. break;
  6031. case 11:
  6032. r[s][t] = d.ceil(e);
  6033. break;
  6034. }
  6035. else
  6036. r[s][t] = g.create(m.NA);
  6037. d != null && (d.isError() ? St.set(
  6038. o,
  6039. u,
  6040. t + l,
  6041. d.getErrorType(),
  6042. s + c
  6043. ) : St.set(
  6044. o,
  6045. u,
  6046. t + l,
  6047. d.getValue(),
  6048. s + c
  6049. ));
  6050. }
  6051. // eslint-disable-next-line max-lines-per-function, complexity
  6052. _batchOperatorArray(e, t, r, n) {
  6053. let s = e.getRowCount(), o = e.getColumnCount();
  6054. s < this._rowCount && (s = this._rowCount), o < this._columnCount && (o = this._columnCount);
  6055. const u = [], c = this._checkArrayCalculateType(this), l = this._checkArrayCalculateType(e);
  6056. for (let f = 0; f < s; f++) {
  6057. const h = [];
  6058. for (let d = 0; d < o; d++) {
  6059. let _;
  6060. c === 3 ? _ = this.getValueOrDefault(0, 0) : c === 1 ? _ = this.getValueOrDefault(0, d) : c === 2 ? _ = this.getValueOrDefault(f, 0) : _ = this.getValueOrDefault(f, d);
  6061. let C;
  6062. if (l === 3 ? C = e.getValueOrDefault(0, 0) : l === 1 ? C = e.getValueOrDefault(0, d) : l === 2 ? C = e.getValueOrDefault(f, 0) : C = e.getValueOrDefault(f, d), _ && C)
  6063. if (_.isError())
  6064. h[d] = _;
  6065. else if (C.isError())
  6066. h[d] = C;
  6067. else
  6068. switch (t) {
  6069. case 1:
  6070. h[d] = _.plus(C);
  6071. break;
  6072. case 0:
  6073. h[d] = _.minus(C);
  6074. break;
  6075. case 2:
  6076. h[d] = _.multiply(C);
  6077. break;
  6078. case 3:
  6079. h[d] = _.divided(C);
  6080. break;
  6081. case 4:
  6082. h[d] = _.mod(C);
  6083. break;
  6084. case 5:
  6085. r ? h[d] = _.compare(C, r, n) : h[d] = g.create(m.VALUE);
  6086. break;
  6087. case 6:
  6088. h[d] = _.concatenateFront(C);
  6089. break;
  6090. case 7:
  6091. h[d] = _.concatenateBack(C);
  6092. break;
  6093. case 8:
  6094. h[d] = _.pow(C);
  6095. break;
  6096. case 9:
  6097. h[d] = _.round(C);
  6098. break;
  6099. case 12:
  6100. h[d] = _.atan2(C);
  6101. break;
  6102. case 10:
  6103. h[d] = _.floor(C);
  6104. break;
  6105. case 11:
  6106. h[d] = _.ceil(C);
  6107. break;
  6108. }
  6109. else
  6110. h[d] = g.create(m.NA);
  6111. }
  6112. u.push(h);
  6113. }
  6114. return this._createNewArray(u, s, o);
  6115. }
  6116. _checkArrayCalculateType(e) {
  6117. return e.getRowCount() === 1 && e.getColumnCount() === 1 ? 3 : e.getRowCount() === 1 ? 1 : e.getColumnCount() === 1 ? 2 : 0;
  6118. }
  6119. _formatValue(e) {
  6120. if (typeof e != "string")
  6121. return e = e, this._rowCount = e.rowCount, this._columnCount = e.columnCount, this._unitId = e.unitId, this._sheetId = e.sheetId, this._currentRow = e.row, this._currentColumn = e.column, e.calculateValueList;
  6122. e = e.slice(1, -1);
  6123. const t = e.split(";"), r = t.length, n = [];
  6124. let s = 0;
  6125. for (let o = 0; o < r; o++) {
  6126. const c = t[o].split(","), l = c.length;
  6127. s < l && (s = l);
  6128. const f = [];
  6129. for (let h = 0; h < l; h++) {
  6130. const d = c[h].trim();
  6131. f.push(pt.create(d));
  6132. }
  6133. n.push(f);
  6134. }
  6135. return this._rowCount = r, this._columnCount = s, n;
  6136. }
  6137. _createNewArray(e, t, r, n = -1, s = -1) {
  6138. (this._currentColumn === -1 || this._currentRow === -1) && (n = -1, s = -1);
  6139. const o = {
  6140. calculateValueList: e,
  6141. rowCount: t,
  6142. columnCount: r,
  6143. unitId: this.getUnitId(),
  6144. sheetId: this.getSheetId(),
  6145. row: n,
  6146. column: s
  6147. };
  6148. return q.create(o);
  6149. }
  6150. }
  6151. class pt {
  6152. static create(a) {
  6153. if (a == null)
  6154. return ie.create();
  6155. if (typeof a == "boolean")
  6156. return T.create(a);
  6157. if (typeof a == "string") {
  6158. const e = a.toLocaleUpperCase().trim();
  6159. if (yr.has(e))
  6160. return g.create(e);
  6161. if (e === er.TRUE || e === er.FALSE)
  6162. return In(a);
  6163. if (Q(a))
  6164. return y.create(Number(a));
  6165. const { isNumberPattern: t, value: r, pattern: n } = il(a);
  6166. if (t)
  6167. return y.create(r, n);
  6168. const s = a.replace(/\n/g, "").replace(/\r/g, "");
  6169. return !pf(s) && Ac(s) ? q.create(s) : bf(a);
  6170. }
  6171. return typeof a == "number" ? Fn(a) : g.create(m.VALUE);
  6172. }
  6173. }
  6174. function pf(i) {
  6175. const a = i.trim();
  6176. return a.startsWith('"') && a.endsWith('"');
  6177. }
  6178. const Vf = 1e4, Bs = new Vt(Vf);
  6179. class kn extends jn {
  6180. constructor(e) {
  6181. super();
  6182. A(this, "_forcedSheetId", "");
  6183. A(this, "_forcedSheetName", "");
  6184. A(this, "_defaultSheetId", "");
  6185. A(this, "_rangeData", {
  6186. startColumn: -1,
  6187. startRow: -1,
  6188. endRow: -1,
  6189. endColumn: -1
  6190. });
  6191. A(this, "_unitData", {});
  6192. A(this, "_unitStylesData", {});
  6193. A(this, "_defaultUnitId", "");
  6194. A(this, "_forcedUnitId", "");
  6195. A(this, "_runtimeData", {});
  6196. A(this, "_arrayFormulaCellData", {});
  6197. A(this, "_runtimeArrayFormulaCellData", {});
  6198. A(this, "_runtimeFeatureCellData", {});
  6199. A(this, "_refOffsetX", 0);
  6200. A(this, "_refOffsetY", 0);
  6201. this._token = e;
  6202. }
  6203. dispose() {
  6204. this._unitData = {}, this._unitStylesData = {}, this._runtimeData = {};
  6205. }
  6206. getToken() {
  6207. return this._token;
  6208. }
  6209. setToken(e) {
  6210. this._token = e;
  6211. }
  6212. isExceedRange() {
  6213. const { startRow: e, endRow: t, startColumn: r, endColumn: n } = this.getRangePosition();
  6214. return e < 0 || r < 0 || t >= this.getActiveSheetRowCount() || n >= this.getActiveSheetColumnCount();
  6215. }
  6216. setRefOffset(e = 0, t = 0) {
  6217. this._refOffsetX = e, this._refOffsetY = t;
  6218. }
  6219. getRefOffset() {
  6220. return {
  6221. x: this._refOffsetX,
  6222. y: this._refOffsetY
  6223. };
  6224. }
  6225. getRangePosition() {
  6226. let { startRow: e, startColumn: t, endRow: r, endColumn: n } = ea(this._rangeData, this._refOffsetX, this._refOffsetY);
  6227. return Number.isNaN(e) && (e = 0), Number.isNaN(t) && (t = 0), Number.isNaN(r) && (r = this.getActiveSheetRowCount() - 1), Number.isNaN(n) && (n = this.getActiveSheetColumnCount() - 1), {
  6228. ...this._rangeData,
  6229. startRow: e,
  6230. endRow: r,
  6231. startColumn: t,
  6232. endColumn: n
  6233. };
  6234. }
  6235. isReferenceObject() {
  6236. return !0;
  6237. }
  6238. iterator(e) {
  6239. const { startRow: t, endRow: r, startColumn: n, endColumn: s } = this.getRangePosition();
  6240. if (this._checkIfWorksheetMiss())
  6241. return e(g.create(m.VALUE), t, n);
  6242. const o = this._forcedUnitId || this._defaultUnitId, u = this._forcedSheetId || this._defaultSheetId;
  6243. for (let c = t; c <= r; c++)
  6244. for (let l = n; l <= s; l++) {
  6245. if (c < 0 || l < 0)
  6246. return e(g.create(m.REF), c, l);
  6247. const f = this.getCellData(c, l);
  6248. let h = !1;
  6249. if (nn(f)) {
  6250. h = e(null, c, l);
  6251. continue;
  6252. }
  6253. let d = this.getCellValueObject(f);
  6254. if (c === t && l === n) {
  6255. const _ = this.getCellPattern(o, u, c, l);
  6256. if (_ && d.isNumber()) {
  6257. const C = Number(d.getValue());
  6258. d = y.create(C, _);
  6259. }
  6260. }
  6261. if (h = e(d, c, l), h === !1)
  6262. return;
  6263. }
  6264. }
  6265. getFirstCell() {
  6266. const { startRow: e, startColumn: t } = this.getRangePosition(), r = this.getCellData(e, t);
  6267. if (!r)
  6268. return y.create(0);
  6269. let n = this.getCellValueObject(r);
  6270. const s = this._forcedUnitId || this._defaultUnitId, o = this._forcedSheetId || this._defaultSheetId, u = this.getCellPattern(s, o, e, t);
  6271. if (u && n.isNumber()) {
  6272. const c = Number(n.getValue());
  6273. n = y.create(c, u);
  6274. }
  6275. return n;
  6276. }
  6277. getRangeData() {
  6278. return this._rangeData;
  6279. }
  6280. setRangeData(e) {
  6281. this._rangeData = e;
  6282. }
  6283. getUnitId() {
  6284. return this._forcedUnitId && this._forcedUnitId.length > 0 ? this._forcedUnitId : this._defaultUnitId;
  6285. }
  6286. getSheetId() {
  6287. return this._forcedSheetId && this._forcedSheetId.length > 0 ? this._forcedSheetId : this._defaultSheetId;
  6288. }
  6289. setForcedUnitIdDirect(e) {
  6290. e.length > 0 && (this._forcedUnitId = e);
  6291. }
  6292. getForcedUnitId() {
  6293. return this._forcedUnitId;
  6294. }
  6295. setForcedSheetId(e) {
  6296. var t;
  6297. this._forcedSheetId = (t = e[this.getUnitId()]) == null ? void 0 : t[this._forcedSheetName];
  6298. }
  6299. setForcedSheetIdDirect(e) {
  6300. this._forcedSheetId = e;
  6301. }
  6302. getForcedSheetId() {
  6303. return this._forcedSheetId;
  6304. }
  6305. setForcedSheetName(e) {
  6306. e.length > 0 && (this._forcedSheetName = e);
  6307. }
  6308. getForcedSheetName() {
  6309. return this._forcedSheetName;
  6310. }
  6311. setDefaultSheetId(e) {
  6312. this._defaultSheetId = e;
  6313. }
  6314. getDefaultSheetId() {
  6315. return this._defaultSheetId;
  6316. }
  6317. setDefaultUnitId(e) {
  6318. this._defaultUnitId = e;
  6319. }
  6320. getDefaultUnitId() {
  6321. return this._defaultUnitId;
  6322. }
  6323. getUnitData() {
  6324. return this._unitData;
  6325. }
  6326. setUnitData(e) {
  6327. this._unitData = e;
  6328. }
  6329. getUnitStylesData() {
  6330. return this._unitStylesData;
  6331. }
  6332. setUnitStylesData(e) {
  6333. this._unitStylesData = e;
  6334. }
  6335. getRuntimeData() {
  6336. return this._runtimeData;
  6337. }
  6338. setRuntimeData(e) {
  6339. this._runtimeData = e;
  6340. }
  6341. getArrayFormulaCellData() {
  6342. return this._arrayFormulaCellData;
  6343. }
  6344. setArrayFormulaCellData(e) {
  6345. this._arrayFormulaCellData = e;
  6346. }
  6347. getRuntimeArrayFormulaCellData() {
  6348. return this._runtimeArrayFormulaCellData;
  6349. }
  6350. setRuntimeArrayFormulaCellData(e) {
  6351. this._runtimeArrayFormulaCellData = e;
  6352. }
  6353. getRuntimeFeatureCellData() {
  6354. return this._runtimeFeatureCellData;
  6355. }
  6356. setRuntimeFeatureCellData(e) {
  6357. this._runtimeFeatureCellData = e;
  6358. }
  6359. getActiveSheetRowCount() {
  6360. var e;
  6361. return ((e = this.getCurrentActiveSheetData()) == null ? void 0 : e.rowCount) || 0;
  6362. }
  6363. getActiveSheetColumnCount() {
  6364. var e;
  6365. return ((e = this.getCurrentActiveSheetData()) == null ? void 0 : e.columnCount) || 0;
  6366. }
  6367. getRowCount() {
  6368. return this._rangeData.endRow - this._rangeData.startRow + 1;
  6369. }
  6370. getColumnCount() {
  6371. return this._rangeData.endColumn - this._rangeData.startColumn + 1;
  6372. }
  6373. getRowData() {
  6374. var e;
  6375. return ((e = this.getCurrentActiveSheetData()) == null ? void 0 : e.rowData) || {};
  6376. }
  6377. getColumnData() {
  6378. var e;
  6379. return ((e = this.getCurrentActiveSheetData()) == null ? void 0 : e.columnData) || {};
  6380. }
  6381. isCell() {
  6382. return !1;
  6383. }
  6384. isColumn() {
  6385. return !1;
  6386. }
  6387. isRow() {
  6388. return !1;
  6389. }
  6390. isRange() {
  6391. return !1;
  6392. }
  6393. isTable() {
  6394. return !1;
  6395. }
  6396. unionBy(e) {
  6397. return g.create(m.REF);
  6398. }
  6399. unionRange(e, t) {
  6400. return {
  6401. startRow: -1,
  6402. startColumn: -1,
  6403. endRow: -1,
  6404. endColumn: -1
  6405. };
  6406. }
  6407. getCellValueObject(e) {
  6408. const t = cl(e);
  6409. if (yr.has(t))
  6410. return g.create(t);
  6411. if (e.t === yt.NUMBER) {
  6412. const r = this._getPatternByCell(e);
  6413. return Fn(t, r);
  6414. }
  6415. return e.t === yt.STRING || e.t === yt.FORCE_STRING ? j.create(t.toString()) : e.t === yt.BOOLEAN ? In(t) : pt.create(t);
  6416. }
  6417. _getPatternByCell(e) {
  6418. var n;
  6419. const t = this._unitStylesData[this.getUnitId()];
  6420. if (!t) return "";
  6421. const r = t.getStyleByCell(e);
  6422. return ((n = r == null ? void 0 : r.n) == null ? void 0 : n.pattern) || "";
  6423. }
  6424. getCellByRow(e) {
  6425. return this.getCellByPosition(e);
  6426. }
  6427. getCellByColumn(e) {
  6428. return this.getCellByPosition(void 0, e);
  6429. }
  6430. getCurrentActiveSheetData() {
  6431. var e;
  6432. return (e = this._unitData[this.getUnitId()]) == null ? void 0 : e[this.getSheetId()];
  6433. }
  6434. getCurrentStylesData() {
  6435. return this._unitStylesData[this.getUnitId()];
  6436. }
  6437. getCurrentRuntimeSheetData() {
  6438. var e, t;
  6439. return (t = (e = this._runtimeData) == null ? void 0 : e[this.getUnitId()]) == null ? void 0 : t[this.getSheetId()];
  6440. }
  6441. getCurrentActiveArrayFormulaCellData() {
  6442. var e, t;
  6443. return (t = (e = this._arrayFormulaCellData) == null ? void 0 : e[this.getUnitId()]) == null ? void 0 : t[this.getSheetId()];
  6444. }
  6445. getCurrentRuntimeActiveArrayFormulaCellData() {
  6446. var e, t;
  6447. return (t = (e = this._runtimeArrayFormulaCellData) == null ? void 0 : e[this.getUnitId()]) == null ? void 0 : t[this.getSheetId()];
  6448. }
  6449. getCellData(e, t) {
  6450. const r = this.getCurrentActiveSheetData(), n = this.getCurrentRuntimeSheetData(), s = this.getCurrentActiveArrayFormulaCellData(), o = this.getCurrentRuntimeActiveArrayFormulaCellData();
  6451. return (n == null ? void 0 : n.getValue(e, t)) || (o == null ? void 0 : o.getValue(e, t)) || this.getRuntimeFeatureCellValue(e, t) || (s == null ? void 0 : s.getValue(e, t)) || (r == null ? void 0 : r.cellData.getValue(e, t));
  6452. }
  6453. getRuntimeFeatureCellValue(e, t) {
  6454. return ao(e, t, this.getSheetId(), this.getUnitId(), this._runtimeFeatureCellData);
  6455. }
  6456. getCellByPosition(e, t) {
  6457. let r = e, n = t;
  6458. r || (r = this._rangeData.startRow), n || (n = this._rangeData.startColumn);
  6459. const s = this.getCellData(r, n);
  6460. return s ? this.getCellValueObject(s) : g.create(m.VALUE);
  6461. }
  6462. /**
  6463. * Get the pattern of the cell
  6464. * @param unitId
  6465. * @param sheetId
  6466. * @param row
  6467. * @param column
  6468. * @returns
  6469. */
  6470. getCellPattern(e, t, r, n) {
  6471. var c, l, f, h;
  6472. const s = this._unitStylesData[e];
  6473. if (!s)
  6474. return "";
  6475. const o = (f = (l = (c = this._unitData[e]) == null ? void 0 : c[t]) == null ? void 0 : l.cellData) == null ? void 0 : f.getValue(r, n);
  6476. if (!o)
  6477. return "";
  6478. const u = s.getStyleByCell(o);
  6479. return ((h = u == null ? void 0 : u.n) == null ? void 0 : h.pattern) || "";
  6480. }
  6481. toArrayValueObject(e = !0) {
  6482. var _;
  6483. const { startRow: t, endRow: r, startColumn: n, endColumn: s } = this.getRangePosition(), o = `${this.getUnitId()}_${this.getSheetId()}_${t}_${r}_${n}_${s}`, u = Bs.get(o);
  6484. if (u && e)
  6485. return u;
  6486. const c = r - t + 1, l = s - n + 1;
  6487. if (c < 0 || l < 0)
  6488. return this._getBlankArrayValueObject();
  6489. const f = new Array(c);
  6490. this.iterator((C, E, b) => {
  6491. const R = E - t, p = b - n;
  6492. f[R] || (f[R] = new Array(l)), C == null && (C = ie.create()), f[R][p] = C;
  6493. });
  6494. const h = {
  6495. calculateValueList: f,
  6496. rowCount: f.length,
  6497. columnCount: ((_ = f[0]) == null ? void 0 : _.length) || 0,
  6498. unitId: this.getUnitId(),
  6499. sheetId: this.getSheetId(),
  6500. row: t,
  6501. column: n
  6502. }, d = q.create(h);
  6503. return e && Bs.set(o, d), d;
  6504. }
  6505. toUnitRange() {
  6506. return {
  6507. range: this.getRangePosition(),
  6508. sheetId: this.getSheetId(),
  6509. unitId: this.getUnitId()
  6510. };
  6511. }
  6512. _checkIfWorksheetMiss() {
  6513. return (this._forcedSheetId == null || this._forcedSheetId.length === 0) && this._forcedSheetName.length > 0;
  6514. }
  6515. _getBlankArrayValueObject() {
  6516. const e = {
  6517. calculateValueList: [],
  6518. rowCount: 0,
  6519. columnCount: 0,
  6520. unitId: this.getUnitId(),
  6521. sheetId: this.getSheetId(),
  6522. row: 0,
  6523. column: 0
  6524. };
  6525. return q.create(e);
  6526. }
  6527. }
  6528. class Nf extends jn {
  6529. constructor(a) {
  6530. super(), this._promise = a;
  6531. }
  6532. isAsyncObject() {
  6533. return !0;
  6534. }
  6535. async getValue() {
  6536. return this._promise;
  6537. }
  6538. }
  6539. class Of extends jn {
  6540. constructor(a) {
  6541. super(), this._promiseList = a;
  6542. }
  6543. isAsyncArrayObject() {
  6544. return !0;
  6545. }
  6546. async getValue() {
  6547. var t;
  6548. const a = [];
  6549. for (let r = 0; r < this._promiseList.length; r++) {
  6550. const n = this._promiseList[r];
  6551. a[r] == null && (a[r] = []);
  6552. for (let s = 0; s < n.length; s++) {
  6553. const o = n[s];
  6554. o.isAsyncObject() ? a[r][s] = await o.getValue() : a[r][s] = o;
  6555. }
  6556. }
  6557. const e = {
  6558. calculateValueList: a,
  6559. rowCount: a.length,
  6560. columnCount: ((t = a[0]) == null ? void 0 : t.length) || 0,
  6561. unitId: "",
  6562. sheetId: "",
  6563. row: 0,
  6564. column: 0
  6565. };
  6566. return q.create(e);
  6567. }
  6568. }
  6569. class Cn extends kn {
  6570. constructor(a, e, t) {
  6571. super(""), this.setRangeData(a), e && this.setForcedSheetIdDirect(e), t && this.setForcedUnitIdDirect(t);
  6572. }
  6573. isRange() {
  6574. return !0;
  6575. }
  6576. }
  6577. class da extends kn {
  6578. constructor(a) {
  6579. super(a);
  6580. const e = mr(a);
  6581. this.setForcedUnitIdDirect(e.unitId), this.setForcedSheetName(e.sheetName), this.setRangeData(e.range);
  6582. }
  6583. isCell() {
  6584. return !0;
  6585. }
  6586. unionBy(a) {
  6587. if (!a.isCell())
  6588. return g.create(m.REF);
  6589. const e = a, t = this.unionRange(this.getRangeData(), e.getRangeData());
  6590. return this._createRange(t);
  6591. }
  6592. unionRange(a, e) {
  6593. const t = a.startRow, r = a.startColumn, n = e.startRow, s = e.startColumn, o = {
  6594. startRow: -1,
  6595. startColumn: -1,
  6596. endRow: -1,
  6597. endColumn: -1
  6598. };
  6599. return t > n ? (o.startRow = n, o.endRow = t) : (o.startRow = t, o.endRow = n), r > s ? (o.startColumn = s, o.endColumn = r) : (o.startColumn = r, o.endColumn = s), a.startAbsoluteRefType && (o.startAbsoluteRefType = a.startAbsoluteRefType), e.startAbsoluteRefType && (o.endAbsoluteRefType = e.startAbsoluteRefType), o;
  6600. }
  6601. _createRange(a) {
  6602. const e = new Cn(
  6603. a,
  6604. this.getForcedSheetId(),
  6605. this.getForcedUnitId()
  6606. );
  6607. e.setUnitData(this.getUnitData()), e.setDefaultSheetId(this.getDefaultSheetId()), e.setDefaultUnitId(this.getDefaultUnitId()), e.setRuntimeData(this.getRuntimeData()), e.setUnitStylesData(this.getUnitStylesData()), e.setArrayFormulaCellData(this.getArrayFormulaCellData()), e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()), e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());
  6608. const { x: t, y: r } = this.getRefOffset();
  6609. e.setRefOffset(t, r);
  6610. const n = this.getForcedSheetId();
  6611. e.setForcedSheetName(this.getForcedSheetName()), n != null && e.setForcedSheetIdDirect(n);
  6612. const s = this.getForcedUnitId();
  6613. return s && e.setForcedUnitIdDirect(s), e;
  6614. }
  6615. }
  6616. class Ca extends kn {
  6617. constructor(a) {
  6618. super(a);
  6619. const e = mr(a);
  6620. this.setForcedUnitIdDirect(e.unitId), this.setForcedSheetName(e.sheetName);
  6621. const t = {
  6622. ...e.range,
  6623. startColumn: e.range.startColumn,
  6624. startRow: Number.NaN,
  6625. endColumn: e.range.endColumn,
  6626. endRow: Number.NaN,
  6627. rangeType: Ze.COLUMN
  6628. };
  6629. this.setRangeData(t);
  6630. }
  6631. isColumn() {
  6632. return !0;
  6633. }
  6634. unionBy(a) {
  6635. if (!a.isColumn())
  6636. return g.create(m.REF);
  6637. const e = a;
  6638. if (e.getForcedSheetName() !== void 0 && e.getForcedSheetName() !== "")
  6639. return g.create(m.REF);
  6640. const t = this.getRangeData(), r = e.getRangeData(), n = r.startColumn;
  6641. if (n >= t.startColumn && n <= t.endColumn)
  6642. return this;
  6643. const s = t.startColumn;
  6644. return n > s ? t.endColumn = n : (t.startColumn = n, t.endColumn = s), r.startAbsoluteRefType && (t.endAbsoluteRefType = r.startAbsoluteRefType), t.rangeType = Ze.COLUMN, this.setToken(`${this.getToken()}${K.COLON}${e.getToken()}`), this;
  6645. }
  6646. }
  6647. class _a extends kn {
  6648. constructor(a) {
  6649. super(a);
  6650. const e = mr(a);
  6651. this.setForcedUnitIdDirect(e.unitId), this.setForcedSheetName(e.sheetName);
  6652. const t = {
  6653. ...e.range,
  6654. startColumn: Number.NaN,
  6655. startRow: e.range.startRow,
  6656. endColumn: Number.NaN,
  6657. endRow: e.range.endRow,
  6658. rangeType: Ze.ROW
  6659. };
  6660. this.setRangeData(t);
  6661. }
  6662. isRow() {
  6663. return !0;
  6664. }
  6665. unionBy(a) {
  6666. if (!a.isRow())
  6667. return g.create(m.REF);
  6668. const e = a;
  6669. if (e.getForcedSheetName() !== void 0 && e.getForcedSheetName() !== "")
  6670. return g.create(m.REF);
  6671. const t = this.getRangeData(), r = e.getRangeData(), n = r.startRow;
  6672. if (n >= t.startRow && n <= t.endRow)
  6673. return this;
  6674. const s = t.startRow;
  6675. return n > s ? t.endRow = n : (t.startRow = n, t.endRow = s), r.startAbsoluteRefType && (t.endAbsoluteRefType = r.startAbsoluteRefType), t.rangeType = Ze.ROW, this.setToken(`${this.getToken()}${K.COLON}${e.getToken()}`), this;
  6676. }
  6677. }
  6678. function O(i, a, e, t) {
  6679. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = [];
  6680. for (let o = 0; o < i; o++) {
  6681. const u = [];
  6682. for (let c = 0; c < a; c++) {
  6683. if (r === 1 && n === 1) {
  6684. const f = e.isArray() ? e.get(0, 0) : e;
  6685. u.push(f);
  6686. continue;
  6687. }
  6688. if (r === 1 && c < n) {
  6689. const f = e.get(0, c);
  6690. u.push(f);
  6691. continue;
  6692. }
  6693. if (n === 1 && o < r) {
  6694. const f = e.get(o, 0);
  6695. u.push(f);
  6696. continue;
  6697. }
  6698. if (o >= r || c >= n) {
  6699. u.push(t != null ? t : ie.create());
  6700. continue;
  6701. }
  6702. const l = e.get(o, c);
  6703. u.push(l);
  6704. }
  6705. s.push(u);
  6706. }
  6707. return tr(s, i, a);
  6708. }
  6709. function tr(i, a, e, t = "", r = "") {
  6710. const n = {
  6711. calculateValueList: i,
  6712. rowCount: a,
  6713. columnCount: e,
  6714. unitId: t,
  6715. sheetId: r,
  6716. row: -1,
  6717. column: -1
  6718. };
  6719. return q.create(n);
  6720. }
  6721. function Aa(i) {
  6722. const a = [
  6723. $.EQUALS,
  6724. $.NOT_EQUAL,
  6725. $.GREATER_THAN_OR_EQUAL,
  6726. $.GREATER_THAN,
  6727. $.LESS_THAN_OR_EQUAL,
  6728. $.LESS_THAN
  6729. ];
  6730. for (const e of a)
  6731. if (i.startsWith(e)) {
  6732. const t = i.substring(e.length);
  6733. return [e, pt.create(t)];
  6734. }
  6735. return [$.EQUALS, pt.create(i)];
  6736. }
  6737. function $n(i, a, e, t) {
  6738. if (!e)
  6739. if (a.isString()) {
  6740. const r = `${a.getValue()}`, [n, s] = Aa(r);
  6741. e = n, a = s;
  6742. } else
  6743. e = $.EQUALS;
  6744. return i.compare(a, e, t);
  6745. }
  6746. function Mf(i, a) {
  6747. const e = Math.max(i.isArray() ? i.getRowCount() : 1, a.isArray() ? a.getRowCount() : 1), t = Math.max(i.isArray() ? i.getColumnCount() : 1, a.isArray() ? a.getColumnCount() : 1), r = O(e, t, i), n = O(e, t, a);
  6748. return r.mapValue((s, o, u) => {
  6749. const c = n.get(o, u);
  6750. return s != null && s.isError() ? s : c != null && c.isError() ? c : s != null && s.isBoolean() && (c != null && c.isBoolean()) ? In(s.getValue() && c.getValue()) : T.create(!1);
  6751. });
  6752. }
  6753. function wf(i) {
  6754. const a = i.getValue();
  6755. let e = 0;
  6756. return a && (e = 1), y.create(e);
  6757. }
  6758. function Ai(i) {
  6759. return i.isArray() && i.getRowCount() === 1 && i.getColumnCount() === 1 ? !0 : i.isReferenceObject() ? !!(i.isCell() || i.getRowCount() === 1 && i.getColumnCount() === 1) : (i = i, !!(i.isString() || i.isNumber() || i.isBoolean() || i.isError() || i.isNull()));
  6760. }
  6761. function Gt(i) {
  6762. const a = i == null ? void 0 : i.getPattern();
  6763. let e = {};
  6764. if (a && (e = {
  6765. s: {
  6766. n: {
  6767. pattern: a
  6768. }
  6769. }
  6770. }), i == null)
  6771. return {
  6772. v: null,
  6773. ...e
  6774. };
  6775. if (i.isError())
  6776. return {
  6777. v: i.getErrorType(),
  6778. t: yt.STRING,
  6779. ...e
  6780. };
  6781. if (i.isValueObject()) {
  6782. const t = i, r = t.getValue();
  6783. return t.isNumber() ? {
  6784. v: r,
  6785. t: yt.NUMBER,
  6786. ...e
  6787. } : t.isBoolean() ? {
  6788. v: r ? 1 : 0,
  6789. t: yt.BOOLEAN,
  6790. ...e
  6791. } : t.isString() ? {
  6792. v: r,
  6793. t: yt.STRING,
  6794. ...e
  6795. } : t.isNull() ? {
  6796. v: null,
  6797. ...e
  6798. } : {
  6799. v: r,
  6800. t: yt.STRING,
  6801. ...e
  6802. };
  6803. }
  6804. }
  6805. function Nr(i) {
  6806. let a = 0, e = 0;
  6807. return i.forEach((t, r) => {
  6808. if (r % 2 === 1)
  6809. if (t.isArray()) {
  6810. const n = t;
  6811. a = Math.max(a, n.getRowCount()), e = Math.max(e, n.getColumnCount());
  6812. } else
  6813. a = Math.max(a, 1), e = Math.max(e, 1);
  6814. }), { maxRowLength: a, maxColumnLength: e };
  6815. }
  6816. function Br(i, a, e, t) {
  6817. const r = a.getRowCount(), n = a.getColumnCount();
  6818. for (let s = 0; s < i.length; s++) {
  6819. if (s % 2 === 1) continue;
  6820. const o = i[s], u = o.getRowCount(), c = o.getColumnCount();
  6821. if (u !== r || c !== n)
  6822. return O(e, t, g.create(m.VALUE));
  6823. }
  6824. return null;
  6825. }
  6826. function Ir(i, a, e, t = !1) {
  6827. const r = [];
  6828. for (let n = 0; n < i.length; n++) {
  6829. if (n % 2 === 1) continue;
  6830. const s = i[n], o = i[n + 1];
  6831. O(a, e, o, g.create(m.NA)).iterator((c, l, f) => {
  6832. if (!c)
  6833. return;
  6834. let h = $n(s, c);
  6835. if (t && (h = Yn(h, s, c)), r[l] === void 0 && (r[l] = []), r[l][f] === void 0) {
  6836. r[l][f] = h;
  6837. return;
  6838. }
  6839. r[l][f] = Mf(r[l][f], h);
  6840. });
  6841. }
  6842. return r;
  6843. }
  6844. function Yn(i, a, e) {
  6845. const [t, r] = Aa(`${e.getValue()}`);
  6846. return i.mapValue((n, s, o) => {
  6847. const u = a.get(s, o);
  6848. if (u && Df(u, r))
  6849. return n;
  6850. if (u != null && u.isNumber()) {
  6851. if (r.isString()) {
  6852. const c = r.convertToNumberObjectValue();
  6853. if (c.isNumber())
  6854. return u.compare(c, t);
  6855. }
  6856. return T.create(!1);
  6857. } else if (r.isNumber()) {
  6858. if (u != null && u.isString()) {
  6859. const c = u.convertToNumberObjectValue();
  6860. if (c.isNumber())
  6861. return c.compare(r, t);
  6862. }
  6863. return T.create(!1);
  6864. } else return u != null && u.isError() && r.isError() && u.getValue() === r.getValue() ? T.create(!0) : T.create(!1);
  6865. });
  6866. }
  6867. function Df(i, a) {
  6868. if (i.isNumber() && a.isNumber() || i.isBoolean() && a.isBoolean())
  6869. return !0;
  6870. const e = i.isString() && i.getValue() === "", t = a.isString() && a.getValue() === "";
  6871. return !!((e || i.isNull()) && (t || a.isNull()) || i.isString() && !e && a.isString() && !t);
  6872. }
  6873. var an = /* @__PURE__ */ ((i) => (i[i.CELL = 0] = "CELL", i[i.COLUMN = 1] = "COLUMN", i[i.ROW = 2] = "ROW", i))(an || {});
  6874. function Sf(i, a) {
  6875. let e;
  6876. switch (a) {
  6877. case 0:
  6878. e = new da(i);
  6879. break;
  6880. case 1:
  6881. e = new Ca(i);
  6882. break;
  6883. case 2:
  6884. e = new _a(i);
  6885. break;
  6886. default:
  6887. throw new Error("Unknown reference object type");
  6888. }
  6889. return e;
  6890. }
  6891. function Pf(i, a) {
  6892. let e = g.create(m.NAME);
  6893. return (i.isCell() && a.isCell() || i.isRow() && a.isRow() || i.isColumn() && a.isColumn()) && (e = i.unionBy(a)), e;
  6894. }
  6895. var Lf = Object.defineProperty, xf = Object.getOwnPropertyDescriptor, jf = (i, a, e, t) => {
  6896. for (var r = t > 1 ? void 0 : t ? xf(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  6897. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  6898. return t && r && Lf(a, e, r), r;
  6899. }, Uf = (i, a) => (e, t) => a(e, t, i), ft = /* @__PURE__ */ ((i) => (i[i.IDLE = 0] = "IDLE", i[i.START = 1] = "START", i[i.START_DEPENDENCY = 2] = "START_DEPENDENCY", i[i.START_CALCULATION = 3] = "START_CALCULATION", i[i.CURRENTLY_CALCULATING = 4] = "CURRENTLY_CALCULATING", i[i.START_DEPENDENCY_ARRAY_FORMULA = 5] = "START_DEPENDENCY_ARRAY_FORMULA", i[i.START_CALCULATION_ARRAY_FORMULA = 6] = "START_CALCULATION_ARRAY_FORMULA", i[i.CURRENTLY_CALCULATING_ARRAY_FORMULA = 7] = "CURRENTLY_CALCULATING_ARRAY_FORMULA", i[i.CALCULATION_COMPLETED = 8] = "CALCULATION_COMPLETED", i))(ft || {}), wr = /* @__PURE__ */ ((i) => (i[i.INITIAL = 0] = "INITIAL", i[i.STOP_EXECUTION = 1] = "STOP_EXECUTION", i[i.NOT_EXECUTED = 2] = "NOT_EXECUTED", i[i.SUCCESS = 3] = "SUCCESS", i))(wr || {});
  6900. let Is = class extends Me {
  6901. constructor(a) {
  6902. super();
  6903. A(this, "_formulaExecuteStage", 0);
  6904. A(this, "_stopState", !1);
  6905. A(this, "_currentRow", -1);
  6906. A(this, "_currentColumn", -1);
  6907. A(this, "_currentRowCount", Number.NEGATIVE_INFINITY);
  6908. A(this, "_currentColumnCount", Number.NEGATIVE_INFINITY);
  6909. A(this, "_currentSubUnitId", "");
  6910. A(this, "_currentUnitId", "");
  6911. A(this, "_runtimeData", {});
  6912. A(this, "_runtimeOtherData", {});
  6913. // Data returned by other businesses through formula calculation, excluding the sheet.
  6914. A(this, "_unitArrayFormulaRange", {});
  6915. A(this, "_runtimeArrayFormulaCellData", {});
  6916. A(this, "_runtimeClearArrayFormulaCellData", {});
  6917. A(this, "_runtimeFeatureRange", {});
  6918. A(this, "_runtimeFeatureCellData", {});
  6919. A(this, "_functionsExecutedState", 0);
  6920. // lambdaId: { key: BaseAstNode }
  6921. A(this, "_functionDefinitionPrivacyVar", /* @__PURE__ */ new Map());
  6922. A(this, "_totalFormulasToCalculate", 0);
  6923. A(this, "_completedFormulasCount", 0);
  6924. A(this, "_totalArrayFormulasToCalculate", 0);
  6925. A(this, "_completedArrayFormulasCount", 0);
  6926. A(this, "_formulaCycleIndex", 0);
  6927. A(this, "_isCycleDependency", !1);
  6928. this._currentConfigService = a;
  6929. }
  6930. get currentRow() {
  6931. return this._currentRow;
  6932. }
  6933. get currentColumn() {
  6934. return this._currentColumn;
  6935. }
  6936. get currentRowCount() {
  6937. return this._currentRowCount;
  6938. }
  6939. get currentColumnCount() {
  6940. return this._currentColumnCount;
  6941. }
  6942. get currentSubUnitId() {
  6943. return this._currentSubUnitId;
  6944. }
  6945. get currentUnitId() {
  6946. return this._currentUnitId;
  6947. }
  6948. dispose() {
  6949. this.reset(), this._runtimeFeatureCellData = {}, this._runtimeFeatureRange = {}, this.clearReferenceAndNumberformatCache();
  6950. }
  6951. enableCycleDependency() {
  6952. this._isCycleDependency = !0;
  6953. }
  6954. disableCycleDependency() {
  6955. this._isCycleDependency = !1;
  6956. }
  6957. isCycleDependency() {
  6958. return this._isCycleDependency;
  6959. }
  6960. setFormulaCycleIndex(a) {
  6961. this._formulaCycleIndex = a;
  6962. }
  6963. getFormulaCycleIndex() {
  6964. return this._formulaCycleIndex;
  6965. }
  6966. setTotalArrayFormulasToCalculate(a) {
  6967. this._totalArrayFormulasToCalculate = a;
  6968. }
  6969. getTotalArrayFormulasToCalculate() {
  6970. return this._totalArrayFormulasToCalculate;
  6971. }
  6972. setCompletedArrayFormulasCount(a) {
  6973. this._completedArrayFormulasCount = a;
  6974. }
  6975. getCompletedArrayFormulasCount() {
  6976. return this._completedArrayFormulasCount;
  6977. }
  6978. setTotalFormulasToCalculate(a) {
  6979. this._totalFormulasToCalculate = a;
  6980. }
  6981. getTotalFormulasToCalculate() {
  6982. return this._totalFormulasToCalculate;
  6983. }
  6984. setCompletedFormulasCount(a) {
  6985. this._completedFormulasCount = a;
  6986. }
  6987. getCompletedFormulasCount() {
  6988. return this._completedFormulasCount;
  6989. }
  6990. markedAsSuccessfullyExecuted() {
  6991. this._functionsExecutedState = 3;
  6992. }
  6993. markedAsNoFunctionsExecuted() {
  6994. this._functionsExecutedState = 2;
  6995. }
  6996. markedAsStopFunctionsExecuted() {
  6997. this._functionsExecutedState = 1;
  6998. }
  6999. markedAsInitialFunctionsExecuted() {
  7000. this._functionsExecutedState = 0;
  7001. }
  7002. stopExecution() {
  7003. this._stopState = !0, this.setFormulaExecuteStage(
  7004. 0
  7005. /* IDLE */
  7006. );
  7007. }
  7008. isStopExecution() {
  7009. return this._stopState;
  7010. }
  7011. setFormulaExecuteStage(a) {
  7012. this._formulaExecuteStage = a;
  7013. }
  7014. getFormulaExecuteStage() {
  7015. return this._formulaExecuteStage;
  7016. }
  7017. reset() {
  7018. this._formulaExecuteStage = 0, this._runtimeData = {}, this._runtimeOtherData = {}, this._unitArrayFormulaRange = {}, this._runtimeArrayFormulaCellData = {}, this._runtimeClearArrayFormulaCellData = {}, this._functionDefinitionPrivacyVar.clear(), this.markedAsInitialFunctionsExecuted(), this._stopState = !1, this._isCycleDependency = !1, this._totalFormulasToCalculate = 0, this._completedFormulasCount = 0, this.clearReferenceAndNumberformatCache();
  7019. }
  7020. clearReferenceAndNumberformatCache() {
  7021. tl(), ol(), Ic();
  7022. }
  7023. setCurrent(a, e, t, r, n, s) {
  7024. this._currentRow = a, this._currentColumn = e, this._currentRowCount = t, this._currentColumnCount = r, this._currentSubUnitId = n, this._currentUnitId = s;
  7025. }
  7026. clearFunctionDefinitionPrivacyVar() {
  7027. this._functionDefinitionPrivacyVar.clear();
  7028. }
  7029. registerFunctionDefinitionPrivacyVar(a, e) {
  7030. this._functionDefinitionPrivacyVar.set(a, e);
  7031. }
  7032. getFunctionDefinitionPrivacyVar(a) {
  7033. return this._functionDefinitionPrivacyVar.get(a);
  7034. }
  7035. setRuntimeOtherData(a, e, t, r) {
  7036. const n = this._currentSubUnitId, s = this._currentUnitId;
  7037. this._runtimeOtherData[s] === void 0 && (this._runtimeOtherData[s] = {});
  7038. const o = this._runtimeOtherData[s];
  7039. (o[n] === void 0 || o[n] === null) && (o[n] = {});
  7040. const u = o[n];
  7041. let c = [];
  7042. if (r.isReferenceObject() || r.isValueObject() && r.isArray()) {
  7043. const l = r, { startRow: f, startColumn: h } = l.getRangePosition();
  7044. l.iterator((d, _, C) => {
  7045. const E = Gt(d), b = _ - f, R = C - h;
  7046. c[b] == null && (c[b] = []), c[b][R] = E;
  7047. });
  7048. } else
  7049. c = [[Gt(r)]];
  7050. (u[a] === void 0 || u[a] === null) && (u[a] = {}), (u[a][t] === void 0 || u[a][t] === null) && (u[a][t] = {}), u[a][t][e] = c;
  7051. }
  7052. // eslint-disable-next-line max-lines-per-function
  7053. setRuntimeData(a) {
  7054. const e = this._currentRow, t = this._currentColumn, r = this._currentRowCount, n = this.currentColumnCount, s = this._currentSubUnitId, o = this._currentUnitId;
  7055. this._runtimeData[o] == null && (this._runtimeData[o] = {});
  7056. const u = this._runtimeData[o];
  7057. u[s] == null && (u[s] = new Ce()), this._unitArrayFormulaRange[o] == null && (this._unitArrayFormulaRange[o] = {});
  7058. const c = this._unitArrayFormulaRange[o];
  7059. (c[s] === null || c[s] === void 0) && (c[s] = {});
  7060. const l = new Ce(c[s]);
  7061. this._runtimeArrayFormulaCellData[o] === void 0 && (this._runtimeArrayFormulaCellData[o] = {});
  7062. const f = this._runtimeArrayFormulaCellData[o];
  7063. f[s] == null && (f[s] = new Ce()), this._runtimeClearArrayFormulaCellData[o] === void 0 && (this._runtimeClearArrayFormulaCellData[o] = {});
  7064. const h = this._runtimeClearArrayFormulaCellData[o];
  7065. h[s] == null && (h[s] = new Ce());
  7066. const d = u[s], _ = f[s], C = h[s];
  7067. if (a.isReferenceObject() || a.isValueObject() && a.isArray()) {
  7068. const E = a, { startRow: b, startColumn: R, endRow: p, endColumn: N } = E.getRangePosition();
  7069. if (b === p && R === N) {
  7070. const w = E.getFirstCell(), D = Gt(w);
  7071. d.setValue(e, t, D), C.setValue(e, t, D);
  7072. return;
  7073. }
  7074. const M = {
  7075. startRow: e,
  7076. startColumn: t,
  7077. endRow: p - b + e,
  7078. endColumn: N - R + t
  7079. };
  7080. if (l.setValue(e, t, M), this._checkIfArrayFormulaRangeHasData(o, s, e, t, M) || this._checkIfArrayFormulaExceeded(r, n, M)) {
  7081. const w = Gt(g.create(m.SPILL));
  7082. d.setValue(e, t, w), C.setValue(e, t, w);
  7083. const D = this._currentConfigService.getUnitData();
  7084. E.iterator((S, P, U) => {
  7085. var ne, z;
  7086. const x = P - b + e, F = U - R + t, W = (z = (ne = D[o]) == null ? void 0 : ne[s]) == null ? void 0 : z.cellData.getValue(x, F);
  7087. if (P === b && U === R)
  7088. _.setValue(e, t, w);
  7089. else if (W != null)
  7090. W.v == null && (W.v = ""), _.setValue(x, F, W);
  7091. else {
  7092. if (this._isInOtherArrayFormulaRange(o, s, e, t, x, F))
  7093. return !0;
  7094. _.setValue(x, F, { v: "" });
  7095. }
  7096. });
  7097. } else {
  7098. const w = g.create(m.SPILL);
  7099. E.iterator((D, S, P) => {
  7100. const U = Gt(D);
  7101. if (S === b && P === R) {
  7102. if (D != null && D.isError() && D.isEqualType(w))
  7103. return C.setValue(e, t, {}), d.setValue(e, t, { ...Gt(w) }), !1;
  7104. d.setValue(e, t, { ...U });
  7105. }
  7106. const x = S - b + e, F = P - R + t;
  7107. _.setValue(x, F, U);
  7108. });
  7109. }
  7110. } else {
  7111. const E = Gt(a);
  7112. d.setValue(e, t, E), C.setValue(e, t, E);
  7113. }
  7114. }
  7115. getUnitData() {
  7116. return this._runtimeData;
  7117. }
  7118. getUnitArrayFormula() {
  7119. return this._unitArrayFormulaRange;
  7120. }
  7121. getRuntimeOtherData() {
  7122. return this._runtimeOtherData;
  7123. }
  7124. getRuntimeArrayFormulaCellData() {
  7125. return this._runtimeArrayFormulaCellData;
  7126. }
  7127. getRuntimeClearArrayFormulaCellData() {
  7128. return this._runtimeClearArrayFormulaCellData;
  7129. }
  7130. getRuntimeFeatureRange() {
  7131. return this._runtimeFeatureRange;
  7132. }
  7133. setRuntimeFeatureRange(a, e) {
  7134. this._runtimeFeatureRange[a] = e;
  7135. }
  7136. getRuntimeFeatureCellData() {
  7137. return this._runtimeFeatureCellData;
  7138. }
  7139. setRuntimeFeatureCellData(a, e) {
  7140. this._runtimeFeatureCellData[a] = e;
  7141. }
  7142. getAllRuntimeData() {
  7143. return {
  7144. unitData: this.getUnitData(),
  7145. arrayFormulaRange: this.getUnitArrayFormula(),
  7146. unitOtherData: this.getRuntimeOtherData(),
  7147. functionsExecutedState: this._functionsExecutedState,
  7148. arrayFormulaCellData: this.getRuntimeArrayFormulaCellData(),
  7149. clearArrayFormulaCellData: this.getRuntimeClearArrayFormulaCellData(),
  7150. runtimeFeatureRange: this.getRuntimeFeatureRange(),
  7151. runtimeFeatureCellData: this.getRuntimeFeatureCellData()
  7152. };
  7153. }
  7154. getRuntimeState() {
  7155. return {
  7156. totalFormulasToCalculate: this.getTotalFormulasToCalculate(),
  7157. completedFormulasCount: this.getCompletedFormulasCount(),
  7158. totalArrayFormulasToCalculate: this.getTotalArrayFormulasToCalculate(),
  7159. completedArrayFormulasCount: this.getCompletedArrayFormulasCount(),
  7160. stage: this.getFormulaExecuteStage(),
  7161. formulaCycleIndex: this.getFormulaCycleIndex()
  7162. };
  7163. }
  7164. // eslint-disable-next-line complexity
  7165. _checkIfArrayFormulaRangeHasData(a, e, t, r, n) {
  7166. var h, d, _, C, E, b, R, p, N, M, w;
  7167. const { startRow: s, startColumn: o, endRow: u, endColumn: c } = n, l = this._currentConfigService.getUnitData(), f = this._currentConfigService.getArrayFormulaCellData();
  7168. (_ = (d = (h = this._unitArrayFormulaRange[a]) == null ? void 0 : h[e]) == null ? void 0 : d[t]) == null || _[r];
  7169. for (let D = s; D <= u; D++)
  7170. for (let S = o; S <= c; S++) {
  7171. if (D === t && r === S)
  7172. continue;
  7173. const P = (b = (E = (C = this._runtimeData) == null ? void 0 : C[a]) == null ? void 0 : E[e]) == null ? void 0 : b.getValue(D, S);
  7174. (p = (R = f == null ? void 0 : f[a]) == null ? void 0 : R[e]) == null || p.getValue(
  7175. D,
  7176. S
  7177. );
  7178. const U = (w = (M = (N = l == null ? void 0 : l[a]) == null ? void 0 : N[e]) == null ? void 0 : M.cellData) == null ? void 0 : w.getValue(D, S), x = this._getRuntimeFeatureCellValue(D, S, e, a);
  7179. if (!nn(P) || this._isInOtherArrayFormulaRange(a, e, t, r, D, S) || !nn(U) || !nn(x))
  7180. return !0;
  7181. }
  7182. return !1;
  7183. }
  7184. _getRuntimeFeatureCellValue(a, e, t, r) {
  7185. return ao(a, e, t, r, this._runtimeFeatureCellData);
  7186. }
  7187. _arrayCellHasData(a) {
  7188. return a == null ? !1 : a.v !== void 0;
  7189. }
  7190. /**
  7191. * If the current array formula in the extended area intersects with the existing array formula, a #SPILL! error will be reported. Note that if other array formulas are already #SPILL!, they will not conflict with the current array formula
  7192. * @param formulaUnitId
  7193. * @param formulaSheetId
  7194. * @param formulaRow
  7195. * @param formulaColumn
  7196. * @param r
  7197. * @param c
  7198. * @returns
  7199. */
  7200. _isInOtherArrayFormulaRange(a, e, t, r, n, s) {
  7201. var l;
  7202. const o = (l = this._currentConfigService.getArrayFormulaRange()[a]) == null ? void 0 : l[e];
  7203. if (o == null)
  7204. return !1;
  7205. let u = !1;
  7206. return new Ce(o).forValue((f, h, d) => {
  7207. var E, b;
  7208. if (f === t && h === r)
  7209. return;
  7210. const _ = this._isInArrayFormulaRange(d, n, s), C = (b = (E = this._runtimeData[a]) == null ? void 0 : E[e]) == null ? void 0 : b.getValue(f, h);
  7211. _ && (C == null ? void 0 : C.v) !== m.SPILL && (u = !0);
  7212. }), u;
  7213. }
  7214. _isInArrayFormulaRange(a, e, t) {
  7215. if (a == null)
  7216. return !1;
  7217. const { startRow: r, startColumn: n, endRow: s, endColumn: o } = a;
  7218. return e >= r && e <= s && t >= n && t <= o;
  7219. }
  7220. _checkIfArrayFormulaExceeded(a, e, t) {
  7221. return t.endRow >= a || t.endColumn >= e;
  7222. }
  7223. _isInDirtyRange(a, e, t, r) {
  7224. const n = this._currentConfigService.getDirtyRanges();
  7225. return n.length === 0 ? !0 : zu(n, a, e, t, r);
  7226. }
  7227. };
  7228. Is = jf([
  7229. Uf(0, Ft)
  7230. ], Is);
  7231. const Nt = lt("univer.formula.runtime.service");
  7232. var oe = /* @__PURE__ */ ((i) => (i[i.REFERENCE = 1] = "REFERENCE", i[i.VALUE = 2] = "VALUE", i[i.OPERATOR = 3] = "OPERATOR", i[i.FUNCTION = 4] = "FUNCTION", i[i.LAMBDA = 5] = "LAMBDA", i[i.LAMBDA_PARAMETER = 6] = "LAMBDA_PARAMETER", i[i.ERROR = 7] = "ERROR", i[i.BASE = 8] = "BASE", i[i.ROOT = 9] = "ROOT", i[i.UNION = 10] = "UNION", i[i.PREFIX = 11] = "PREFIX", i[i.SUFFIX = 12] = "SUFFIX", i[i.NULL = 13] = "NULL", i))(oe || {});
  7233. const _t = /* @__PURE__ */ new Map([
  7234. [1, 7],
  7235. [2, 9],
  7236. [3, 8],
  7237. [4, 6],
  7238. [5, 1],
  7239. [6, 2],
  7240. [9, 10],
  7241. [10, 3],
  7242. [11, 4],
  7243. [12, 5]
  7244. ]);
  7245. class Ge {
  7246. constructor(a) {
  7247. A(this, "_children", []);
  7248. A(this, "_definedNames");
  7249. A(this, "_parent");
  7250. A(this, "_valueObject");
  7251. A(this, "_calculateState", !1);
  7252. A(this, "_async", !1);
  7253. A(this, "_address", !1);
  7254. A(this, "_isForcedCalculateFunction", !1);
  7255. this._token = a;
  7256. }
  7257. dispose() {
  7258. var a;
  7259. this._children.forEach((e) => {
  7260. e.dispose();
  7261. }), (a = this._valueObject) == null || a.dispose(), this._valueObject = null, this._children = [], this._definedNames = null, this._parent = null;
  7262. }
  7263. get nodeType() {
  7264. return oe.BASE;
  7265. }
  7266. isAsync() {
  7267. return this._async;
  7268. }
  7269. isAddress() {
  7270. return this._address;
  7271. }
  7272. isForcedCalculateFunction() {
  7273. return this._isForcedCalculateFunction;
  7274. }
  7275. setAsync() {
  7276. this._async = !0;
  7277. }
  7278. setAddress() {
  7279. this._address = !0;
  7280. }
  7281. getParent() {
  7282. return this._parent;
  7283. }
  7284. setParent(a) {
  7285. this._parent = a, a.addChildren(this);
  7286. }
  7287. setForcedCalculateFunction() {
  7288. this._isForcedCalculateFunction = !0;
  7289. }
  7290. getChildren() {
  7291. return this._children;
  7292. }
  7293. addChildren(...a) {
  7294. this._children.push(...a);
  7295. }
  7296. getToken() {
  7297. return this._token;
  7298. }
  7299. setValue(a) {
  7300. this._valueObject = a;
  7301. }
  7302. getValue() {
  7303. return this._valueObject;
  7304. }
  7305. isCalculated() {
  7306. return this._calculateState;
  7307. }
  7308. setCalculated() {
  7309. this._calculateState = !0;
  7310. }
  7311. execute() {
  7312. }
  7313. setNotEmpty(a = !0) {
  7314. }
  7315. async executeAsync() {
  7316. return Promise.resolve(xt.SUCCESS);
  7317. }
  7318. serialize() {
  7319. const a = this.getToken(), e = this.getChildren(), t = [], r = e.length;
  7320. for (let s = 0; s < r; s++) {
  7321. const o = e[s];
  7322. t.push(o.serialize());
  7323. }
  7324. const n = {
  7325. token: a,
  7326. nodeType: this.nodeType
  7327. };
  7328. return r > 0 && (n.children = t), n;
  7329. }
  7330. hasDefinedName(a) {
  7331. var e;
  7332. return ((e = this._definedNames) == null ? void 0 : e.includes(a)) || !1;
  7333. }
  7334. setDefinedNames(a) {
  7335. this._definedNames = a;
  7336. }
  7337. getDefinedNames() {
  7338. return this._definedNames;
  7339. }
  7340. }
  7341. class xe extends Ge {
  7342. constructor(e) {
  7343. super(e);
  7344. A(this, "_errorValueObject");
  7345. this._errorValueObject = g.create(e);
  7346. }
  7347. get nodeType() {
  7348. return oe.ERROR;
  7349. }
  7350. static create(e) {
  7351. return new xe(e);
  7352. }
  7353. getValue() {
  7354. return this._errorValueObject;
  7355. }
  7356. }
  7357. const At = 100;
  7358. class Et {
  7359. get zIndex() {
  7360. return 0;
  7361. }
  7362. dispose() {
  7363. }
  7364. create(a, e, t) {
  7365. let r;
  7366. return a instanceof ae ? r = a.getToken() : r = a, new Ge(r);
  7367. }
  7368. }
  7369. class Fs extends Ge {
  7370. get nodeType() {
  7371. return oe.ROOT;
  7372. }
  7373. execute() {
  7374. const a = this.getChildren();
  7375. if (a.length > 1) {
  7376. this.setValue(g.create(m.VALUE));
  7377. return;
  7378. }
  7379. const e = a[0];
  7380. e == null ? this.setValue(g.create(m.VALUE)) : this.setValue(e.getValue());
  7381. }
  7382. }
  7383. class Eo extends Et {
  7384. get zIndex() {
  7385. return _t.get(oe.ROOT) || At;
  7386. }
  7387. checkAndCreateNodeType(a) {
  7388. if (!(a instanceof ae))
  7389. return;
  7390. if (a.getToken() === Ut)
  7391. return new Fs(Ut);
  7392. }
  7393. }
  7394. const Yt = lt("univer.formula-function.service");
  7395. class vf extends Me {
  7396. constructor() {
  7397. super(...arguments);
  7398. A(this, "_functionExecutors", /* @__PURE__ */ new Map());
  7399. A(this, "_functionDescriptions", /* @__PURE__ */ new Map());
  7400. }
  7401. dispose() {
  7402. this._functionExecutors.clear(), this._functionDescriptions.clear();
  7403. }
  7404. registerExecutors(...e) {
  7405. for (let t = 0; t < e.length; t++) {
  7406. const r = e[t];
  7407. this._functionExecutors.set(r.name, r);
  7408. }
  7409. }
  7410. getExecutors() {
  7411. return this._functionExecutors;
  7412. }
  7413. getExecutor(e) {
  7414. return this._functionExecutors.get(e);
  7415. }
  7416. hasExecutor(e) {
  7417. return this._functionExecutors.has(e);
  7418. }
  7419. unregisterExecutors(...e) {
  7420. for (let t = 0; t < e.length; t++) {
  7421. const r = e[t];
  7422. this._functionExecutors.delete(r);
  7423. }
  7424. }
  7425. registerDescriptions(...e) {
  7426. for (let t = 0; t < e.length; t++) {
  7427. const r = e[t];
  7428. this._functionDescriptions.set(r.functionName, r);
  7429. }
  7430. return Hu(() => {
  7431. for (let t = 0; t < e.length; t++) {
  7432. const r = e[t];
  7433. this._functionDescriptions.delete(r.functionName);
  7434. }
  7435. });
  7436. }
  7437. getDescriptions() {
  7438. return this._functionDescriptions;
  7439. }
  7440. getDescription(e) {
  7441. return this._functionDescriptions.get(e);
  7442. }
  7443. hasDescription(e) {
  7444. return this._functionDescriptions.has(e);
  7445. }
  7446. unregisterDescriptions(...e) {
  7447. for (let t = 0; t < e.length; t++) {
  7448. const r = e[t];
  7449. this._functionDescriptions.delete(r);
  7450. }
  7451. }
  7452. }
  7453. var Te = /* @__PURE__ */ ((i) => (i.COMPARE = "COMPARE", i.DIVIDED = "DIVIDED", i.MINUS = "MINUS", i.MULTIPLY = "MULTIPLY", i.PLUS = "PLUS", i.UNION = "UNION", i.CUBE = "CUBE", i))(Te || {}), Tf = Object.defineProperty, Bf = Object.getOwnPropertyDescriptor, If = (i, a, e, t) => {
  7454. for (var r = t > 1 ? void 0 : t ? Bf(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  7455. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  7456. return t && r && Tf(a, e, r), r;
  7457. }, Ei = (i, a) => (e, t) => a(e, t, i);
  7458. class _n extends Ge {
  7459. constructor(a, e, t) {
  7460. super(e), this._runtimeService = a, this._operatorString = e, this._functionExecutor = t;
  7461. }
  7462. get nodeType() {
  7463. return oe.PREFIX;
  7464. }
  7465. execute() {
  7466. let e = this.getChildren()[0].getValue(), t;
  7467. if (e == null)
  7468. throw new Error("object is null");
  7469. this._operatorString === Oe.MINUS ? (e.isReferenceObject() && (e = e.toArrayValueObject()), t = this._functionExecutor.calculate(
  7470. y.create(0),
  7471. e
  7472. )) : this._operatorString === Oe.AT ? t = this._handlerAT(e) : t = g.create(m.VALUE), this.setValue(t);
  7473. }
  7474. _handlerAT(a) {
  7475. if (!a.isReferenceObject())
  7476. return g.create(m.VALUE);
  7477. const e = a;
  7478. if (e.isCell())
  7479. return g.create(m.VALUE);
  7480. const t = this._runtimeService, r = t.currentRow || 0, n = t.currentColumn || 0, s = e.getRangePosition(), { startRow: o, startColumn: u, endRow: c, endColumn: l } = s;
  7481. return l !== u && c !== o || o === c && u === l ? g.create(m.VALUE) : c === o && n >= u && n <= l ? e.getCellByColumn(n) : u === l && r >= o && r <= c ? e.getCellByRow(r) : e.isTable() ? e.getCellByPosition(r) : g.create(m.VALUE);
  7482. }
  7483. }
  7484. let An = class extends Et {
  7485. constructor(i, a) {
  7486. super(), this._functionService = i, this._runtimeService = a;
  7487. }
  7488. get zIndex() {
  7489. return _t.get(oe.PREFIX) || At;
  7490. }
  7491. checkAndCreateNodeType(i) {
  7492. if (!(i instanceof ae))
  7493. return;
  7494. const a = i.getToken(), e = a.trim();
  7495. if (e.charAt(0) === '"' && e.charAt(e.length - 1) === '"')
  7496. return;
  7497. let t = "";
  7498. if (e === Oe.MINUS)
  7499. t = Te.MINUS;
  7500. else return e === Oe.AT ? new _n(this._runtimeService, e) : void 0;
  7501. const r = this._functionService.getExecutor(t);
  7502. return r ? new _n(this._runtimeService, e, r) : (console.error(`No function ${a}`), xe.create(m.NAME));
  7503. }
  7504. };
  7505. An = If([
  7506. Ei(0, Yt),
  7507. Ei(1, Nt)
  7508. ], An);
  7509. new RegExp(Oe.MINUS, "g");
  7510. new RegExp(Oe.AT, "g");
  7511. function bo(i, a, e) {
  7512. let t, r, n = i;
  7513. const s = n.slice(0, 2);
  7514. let o = 0;
  7515. if (s[0] === Oe.MINUS) {
  7516. const u = a.getExecutor(Te.MINUS);
  7517. t = new _n(e, Oe.MINUS, u), o++;
  7518. }
  7519. return s[0] === Oe.AT && (r = new _n(e, Oe.AT), t && r.setParent(t), o++), o > 0 && (n = n.slice(o)), { tokenTrim: n, minusPrefixNode: t, atPrefixNode: r };
  7520. }
  7521. var Ff = Object.defineProperty, kf = Object.getOwnPropertyDescriptor, $f = (i, a, e, t) => {
  7522. for (var r = t > 1 ? void 0 : t ? kf(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  7523. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  7524. return t && r && Ff(a, e, r), r;
  7525. }, ir = (i, a) => (e, t) => a(e, t, i);
  7526. class Yf extends Ge {
  7527. constructor(a, e, t, r, n, s) {
  7528. super(a), this._functionExecutor = e, this._currentConfigService = t, this._runtimeService = r, this._definedNamesService = n, this._formulaDataModel = s, this._functionExecutor.isAsync() && this.setAsync(), this._functionExecutor.isAddress() && this.setAddress(), this._functionExecutor.needsLocale && this._setLocale(), this._functionExecutor.needsSheetsInfo && this._setSheetsInfo(), this._functionExecutor.needsFormulaDataModel && this._functionExecutor.setFormulaDataModel(this._formulaDataModel);
  7529. }
  7530. get nodeType() {
  7531. return oe.FUNCTION;
  7532. }
  7533. async executeAsync() {
  7534. const a = [], e = this.getChildren(), t = e.length;
  7535. this._compatibility();
  7536. for (let s = 0; s < t; s++) {
  7537. const u = e[s].getValue();
  7538. u != null && (u.isReferenceObject() && !this._functionExecutor.needsReferenceObject ? a.push(u.toArrayValueObject()) : a.push(u));
  7539. }
  7540. const r = await this._calculateAsync(a);
  7541. let n;
  7542. return r.isAsyncObject() || r.isAsyncArrayObject() ? n = await r.getValue() : n = r, this._setRefData(n), this.setValue(n), Promise.resolve(xt.SUCCESS);
  7543. }
  7544. execute() {
  7545. const a = [], e = this.getChildren(), t = e.length;
  7546. this._compatibility();
  7547. for (let n = 0; n < t; n++) {
  7548. const o = e[n].getValue();
  7549. o != null && (o.isReferenceObject() && !this._functionExecutor.needsReferenceObject ? a.push(o.toArrayValueObject()) : a.push(o));
  7550. }
  7551. const r = this._calculate(a);
  7552. this._setRefData(r), this.setValue(r);
  7553. }
  7554. /**
  7555. * Compatibility handling for special functions.
  7556. */
  7557. _compatibility() {
  7558. this._lookupCompatibility();
  7559. }
  7560. /**
  7561. * The LOOKUP function follows the following rules when dealing with vectors of different sizes:
  7562. * If the lookup_vector is larger than the result_vector,
  7563. * the LOOKUP function will ignore the extra portion of the lookup_vector and only use the portion of the result_vector that is the same size as the lookup_vector for lookup and returning results.
  7564. * If the lookup_vector is smaller than the result_vector,
  7565. * the LOOKUP function will continue using the last value of the result_vector for lookup and returning results after the last value of the lookup_vector.
  7566. */
  7567. _lookupCompatibility() {
  7568. const a = this.getChildren(), e = a.length;
  7569. if (!this._functionExecutor.needsExpandParams || e !== 3)
  7570. return;
  7571. const t = a[1].getValue(), r = a[2].getValue();
  7572. if (!(t != null && t.isReferenceObject()) && !(r != null && r.isReferenceObject()))
  7573. return;
  7574. let n, s;
  7575. if (t != null && t.isReferenceObject()) {
  7576. const _ = t.getRangeData(), { startRow: C, startColumn: E, endRow: b, endColumn: R } = _;
  7577. n = b - C + 1, s = R - E + 1;
  7578. } else
  7579. n = t != null && t.isArray() ? t.getRowCount() : 1, s = t != null && t.isArray() ? t.getColumnCount() : 1;
  7580. const o = r.getRangeData(), { startRow: u, startColumn: c, endRow: l, endColumn: f } = o, h = l - u + 1, d = f - c + 1;
  7581. n !== h && (o.endRow += n - h), s !== d && (o.endColumn += s - d);
  7582. }
  7583. /**
  7584. * Transform the result of a custom function to a NodeValueType.
  7585. */
  7586. _handleCustomResult(a) {
  7587. var t;
  7588. if (typeof a != "object" || a == null)
  7589. return pt.create(a);
  7590. const e = Ao(a);
  7591. return q.create({
  7592. calculateValueList: e,
  7593. rowCount: e.length,
  7594. columnCount: ((t = e[0]) == null ? void 0 : t.length) || 0,
  7595. unitId: "",
  7596. sheetId: "",
  7597. row: -1,
  7598. column: -1
  7599. });
  7600. }
  7601. _handleAddressFunction() {
  7602. this._functionExecutor.isAddress() && this._setDefinedNamesForFunction();
  7603. }
  7604. _mapVariantsToValues(a) {
  7605. return a.map((e) => e.isArray() ? e.toValue() : e.isLambda() ? e : e.getValue());
  7606. }
  7607. _calculate(a) {
  7608. const { minParams: e, maxParams: t } = this._functionExecutor;
  7609. if (e !== -1 && t !== -1 && (a.length < e || a.length > t))
  7610. return g.create(m.NA);
  7611. let r;
  7612. if (this._setRefInfo(), this._functionExecutor.isCustom()) {
  7613. const n = this._functionExecutor.calculateCustom(
  7614. ...this._mapVariantsToValues(a)
  7615. );
  7616. r = this._handleCustomResult(n);
  7617. } else
  7618. this._handleAddressFunction(), r = this._functionExecutor.calculate(...a);
  7619. return r;
  7620. }
  7621. async _calculateAsync(a) {
  7622. const { minParams: e, maxParams: t } = this._functionExecutor;
  7623. if (e !== -1 && t !== -1 && (a.length < e || a.length > t))
  7624. return g.create(m.NA);
  7625. let r;
  7626. if (this._setRefInfo(), this._functionExecutor.isCustom()) {
  7627. const n = await this._functionExecutor.calculateCustom(
  7628. ...this._mapVariantsToValues(a)
  7629. );
  7630. r = this._handleCustomResult(n);
  7631. } else
  7632. this._handleAddressFunction(), r = this._functionExecutor.calculate(...a);
  7633. return r;
  7634. }
  7635. _setDefinedNamesForFunction() {
  7636. const a = this._currentConfigService.getExecuteUnitId();
  7637. if (a == null)
  7638. return;
  7639. const e = this._definedNamesService.getDefinedNameMap(a);
  7640. e != null && this._functionExecutor.setDefinedNames(e);
  7641. }
  7642. _setRefInfo() {
  7643. const { currentUnitId: a, currentSubUnitId: e, currentRow: t, currentColumn: r } = this._runtimeService;
  7644. if (this._functionExecutor.setRefInfo(a, e, t, r), this._functionExecutor.needsSheetRowColumnCount) {
  7645. const { rowCount: n, columnCount: s } = this._currentConfigService.getSheetRowColumnCount(a, e);
  7646. this._functionExecutor.setSheetRowColumnCount(n, s);
  7647. }
  7648. }
  7649. _setRefData(a) {
  7650. if (!a.isReferenceObject())
  7651. return;
  7652. const e = a;
  7653. e.setForcedSheetId(this._currentConfigService.getSheetNameMap()), e.setUnitData(this._currentConfigService.getUnitData()), e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()), e.setRuntimeData(this._runtimeService.getUnitData()), e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()), e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData());
  7654. }
  7655. _setLocale() {
  7656. this._functionExecutor.setLocale(this._currentConfigService.getLocale());
  7657. }
  7658. _setSheetsInfo() {
  7659. this._functionExecutor.setSheetsInfo(this._currentConfigService.getSheetsInfo());
  7660. }
  7661. }
  7662. class Hf extends Ge {
  7663. constructor(a = "Error") {
  7664. super(a);
  7665. }
  7666. get nodeType() {
  7667. return oe.FUNCTION;
  7668. }
  7669. async executeAsync() {
  7670. return this.setValue(g.create(m.NAME)), Promise.resolve(xt.SUCCESS);
  7671. }
  7672. execute() {
  7673. this.setValue(g.create(m.NAME));
  7674. }
  7675. }
  7676. let En = class extends Et {
  7677. constructor(i, a, e, t, r, n) {
  7678. super(), this._functionService = i, this._currentConfigService = a, this._runtimeService = e, this._definedNamesService = t, this._injector = r, this._formulaDataModel = n;
  7679. }
  7680. get zIndex() {
  7681. return _t.get(oe.FUNCTION) || At;
  7682. }
  7683. create(i) {
  7684. const a = this._functionService.getExecutor(i);
  7685. return a ? new Yf(
  7686. i,
  7687. a,
  7688. this._currentConfigService,
  7689. this._runtimeService,
  7690. this._definedNamesService,
  7691. this._formulaDataModel
  7692. ) : (console.error(`No function ${i}`), xe.create(m.NAME));
  7693. }
  7694. checkAndCreateNodeType(i) {
  7695. if (typeof i == "string")
  7696. return;
  7697. const a = i.getToken(), { tokenTrim: e, minusPrefixNode: t, atPrefixNode: r } = bo(a.trim(), this._functionService, this._runtimeService);
  7698. if (!Number.isNaN(Number(e)) && !this._isParentUnionNode(i))
  7699. return xe.create(m.VALUE);
  7700. const n = e.toUpperCase();
  7701. if (this._functionService.hasExecutor(n)) {
  7702. const s = this.create(n);
  7703. return r ? s.setParent(r) : t && s.setParent(t), s;
  7704. }
  7705. }
  7706. _isParentUnionNode(i) {
  7707. var a, e;
  7708. return ((e = (a = i.getParent()) == null ? void 0 : a.getParent()) == null ? void 0 : e.getToken()) === K.COLON;
  7709. }
  7710. };
  7711. En = $f([
  7712. ir(0, Yt),
  7713. ir(1, Ft),
  7714. ir(2, Nt),
  7715. ir(3, pr),
  7716. ir(4, Ve(ki)),
  7717. ir(5, Ve(Pr))
  7718. ], En);
  7719. var Gf = Object.defineProperty, Qf = Object.getOwnPropertyDescriptor, Wf = (i, a, e, t) => {
  7720. for (var r = t > 1 ? void 0 : t ? Qf(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  7721. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  7722. return t && r && Gf(a, e, r), r;
  7723. }, qf = (i, a) => (e, t) => a(e, t, i);
  7724. let Cr = class extends Me {
  7725. constructor(i) {
  7726. super(), this._runtimeService = i;
  7727. }
  7728. async executeAsync(i) {
  7729. if (!i || !i.node)
  7730. return Promise.resolve(g.create(m.VALUE));
  7731. const a = i.node, e = i.refOffsetX, t = i.refOffsetY;
  7732. await this._executeAsync(a, e, t);
  7733. const r = a.getValue();
  7734. return r == null ? Promise.resolve(g.create(m.VALUE)) : Promise.resolve(r);
  7735. }
  7736. execute(i) {
  7737. if (!i || !i.node)
  7738. return g.create(m.VALUE);
  7739. const a = i.node, e = i.refOffsetX, t = i.refOffsetY;
  7740. this._execute(a, e, t);
  7741. const r = a.getValue();
  7742. return r == null ? g.create(m.VALUE) : r;
  7743. }
  7744. executePreCalculateNode(i) {
  7745. return i.execute(), i.getValue();
  7746. }
  7747. checkAsyncNode(i) {
  7748. if (i == null)
  7749. return !1;
  7750. const a = [];
  7751. this._checkAsyncNode(i, a);
  7752. for (let e = 0, t = a.length; e < t; e++)
  7753. if (a[e] === !0)
  7754. return !0;
  7755. return !1;
  7756. }
  7757. _checkAsyncNode(i, a) {
  7758. const e = i.getChildren(), t = e.length;
  7759. for (let r = 0; r < t; r++) {
  7760. const n = e[r];
  7761. a.push(n.isAsync()), this._checkAsyncNode(n, a);
  7762. }
  7763. }
  7764. async _executeAsync(i, a = 0, e = 0) {
  7765. if (this._runtimeService.isStopExecution())
  7766. return Promise.resolve(xt.ERROR);
  7767. const t = i.getChildren(), r = t.length;
  7768. for (let n = 0; n < r; n++) {
  7769. const s = t[n];
  7770. if (s.getToken().toUpperCase() === Sr && s.isEmptyParamFunction()) {
  7771. s.execute();
  7772. continue;
  7773. }
  7774. await this._executeAsync(s, a, e);
  7775. }
  7776. return i.nodeType === oe.REFERENCE && i.setRefOffset(a, e), i.nodeType === oe.FUNCTION && i.isAsync() ? await i.executeAsync() : i.execute(), Promise.resolve(xt.SUCCESS);
  7777. }
  7778. _execute(i, a = 0, e = 0) {
  7779. if (this._runtimeService.isStopExecution())
  7780. return xt.ERROR;
  7781. const t = i.getChildren(), r = t.length;
  7782. for (let n = 0; n < r; n++) {
  7783. const s = t[n];
  7784. if (s.getToken().toUpperCase() === Sr && s.isEmptyParamFunction()) {
  7785. s.execute();
  7786. continue;
  7787. }
  7788. this._execute(s, a, e);
  7789. }
  7790. return i.nodeType === oe.REFERENCE && i.setRefOffset(a, e), i.execute(), xt.SUCCESS;
  7791. }
  7792. };
  7793. Cr = Wf([
  7794. qf(0, Nt)
  7795. ], Cr);
  7796. function yo(i) {
  7797. return i instanceof ae ? i.getToken() === hr : !1;
  7798. }
  7799. function Kf(i) {
  7800. return i instanceof ae ? i.getToken() === ro : !1;
  7801. }
  7802. function Ea(i, a, e) {
  7803. const t = i.getChildren(), r = t.length, n = t[0];
  7804. for (let s = 0; s < r; s++) {
  7805. const o = t[s];
  7806. if (!(yo(n) && s !== 0))
  7807. if (o instanceof ae)
  7808. Ea(o, a, e);
  7809. else {
  7810. const u = o.trim();
  7811. if (e.has(u)) {
  7812. const c = new ae();
  7813. c.setToken(Tr), c.setLambdaId(a), c.setLambdaPrivacyVar(e), c.setLambdaParameter(u), t[s] = c;
  7814. }
  7815. }
  7816. }
  7817. }
  7818. function Xf(i) {
  7819. let a = i;
  7820. for (; a != null && a.getParent(); )
  7821. a = a.getParent();
  7822. return a;
  7823. }
  7824. function bi(i, a = 0, e = 0) {
  7825. return {
  7826. node: i,
  7827. refOffsetX: a,
  7828. refOffsetY: e
  7829. };
  7830. }
  7831. function Ro(i) {
  7832. if (!i)
  7833. return;
  7834. if (i.getToken() !== Tr)
  7835. return i;
  7836. const a = i, e = a.getCurrentLambdaPrivacyVar(), t = a.getLambdaParameter();
  7837. if (!e)
  7838. return;
  7839. const r = e.get(t);
  7840. return r == null && i.getValue() ? i : Ro(r);
  7841. }
  7842. class ba extends kt {
  7843. constructor(e, t, r) {
  7844. super(0);
  7845. A(this, "_lambdaPrivacyValueMap", /* @__PURE__ */ new Map());
  7846. this._lambdaNode = e, this._interpreter = t, this._lambdaPrivacyVarKeys = r, this._lambdaPrivacyValueMap.clear();
  7847. }
  7848. static create(e, t, r) {
  7849. return new ba(e, t, r);
  7850. }
  7851. dispose() {
  7852. this._lambdaPrivacyValueMap.clear(), this._lambdaPrivacyValueMap = /* @__PURE__ */ new Map(), this._lambdaNode = null, this._interpreter = null, this._lambdaPrivacyVarKeys = [];
  7853. }
  7854. isLambda() {
  7855. return !0;
  7856. }
  7857. execute(...e) {
  7858. const t = this._lambdaPrivacyVarKeys.length;
  7859. if (e.length !== t || !this._interpreter || !this._lambdaNode)
  7860. return g.create(m.VALUE);
  7861. this._setLambdaPrivacyValueMap(e), this._setLambdaNodeValue(this._lambdaNode), this._lambdaNode.setNotEmpty(!1);
  7862. let r;
  7863. if (this._interpreter.checkAsyncNode(this._lambdaNode))
  7864. r = new Nf(this._interpreter.executeAsync(bi(this._lambdaNode)));
  7865. else {
  7866. const n = this._interpreter.execute(bi(this._lambdaNode));
  7867. n.isReferenceObject() ? r = n.toArrayValueObject() : r = n;
  7868. }
  7869. return this._lambdaNode.setNotEmpty(!0), r;
  7870. }
  7871. /**
  7872. * Execute custom lambda function, handle basic types
  7873. * @param variants
  7874. */
  7875. executeCustom(...e) {
  7876. const t = e.map((r) => pt.create(r));
  7877. return this.execute(...t);
  7878. }
  7879. _setLambdaNodeValue(e) {
  7880. if (!e)
  7881. return;
  7882. const t = e.getChildren(), r = t.length;
  7883. for (let n = 0; n < r; n++) {
  7884. const s = t[n];
  7885. if (s.getToken() === Tr) {
  7886. const u = s.getLambdaParameter(), c = this._lambdaPrivacyValueMap.get(u);
  7887. if (c)
  7888. s.setValue(c);
  7889. else {
  7890. const l = s.getCurrentLambdaPrivacyVar(), f = Ro(l.get(u));
  7891. f != null && s.setValue(f.getValue());
  7892. }
  7893. continue;
  7894. }
  7895. this._setLambdaNodeValue(s);
  7896. }
  7897. }
  7898. _setLambdaPrivacyValueMap(e) {
  7899. for (let t = 0; t < e.length; t++) {
  7900. const r = e[t], n = this._lambdaPrivacyVarKeys[t];
  7901. this._lambdaPrivacyValueMap.set(n, r);
  7902. }
  7903. }
  7904. getLambdaPrivacyVarKeys() {
  7905. return this._lambdaPrivacyVarKeys;
  7906. }
  7907. }
  7908. var Zf = Object.defineProperty, zf = Object.getOwnPropertyDescriptor, Jf = (i, a, e, t) => {
  7909. for (var r = t > 1 ? void 0 : t ? zf(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  7910. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  7911. return t && r && Zf(a, e, r), r;
  7912. }, yi = (i, a) => (e, t) => a(e, t, i);
  7913. class eh extends Ge {
  7914. constructor(e, t, r, n) {
  7915. super(e);
  7916. A(this, "_isNotEmpty", !0);
  7917. this._lambdaId = t, this._interpreter = r, this._lambdaPrivacyVarKeys = n;
  7918. }
  7919. get nodeType() {
  7920. return oe.LAMBDA;
  7921. }
  7922. setNotEmpty(e = !1) {
  7923. this._isNotEmpty = e;
  7924. }
  7925. isEmptyParamFunction() {
  7926. return this.getChildren().length < 2 && this._isNotEmpty;
  7927. }
  7928. isFunctionParameter() {
  7929. return this._lambdaId === null;
  7930. }
  7931. getLambdaId() {
  7932. return this._lambdaId;
  7933. }
  7934. execute() {
  7935. if (this.isEmptyParamFunction())
  7936. this.setValue(ba.create(this, this._interpreter, this._lambdaPrivacyVarKeys));
  7937. else {
  7938. const e = this.getChildren(), t = e.length;
  7939. this.setValue(e[t - 1].getValue());
  7940. }
  7941. }
  7942. // override async executeAsync() {
  7943. // if (this.isEmptyParamFunction()) {
  7944. // await this.setValue(LambdaValueObjectObject.create(this, this._interpreter, this._lambdaPrivacyVarKeys));
  7945. // } else {
  7946. // const children = this.getChildren();
  7947. // const childrenCount = children.length;
  7948. // await this.setValue(children[childrenCount - 1].getValue());
  7949. // }
  7950. // return Promise.resolve(AstNodePromiseType.SUCCESS);
  7951. // }
  7952. }
  7953. let bn = class extends Et {
  7954. constructor(i, a) {
  7955. super(), this._runtimeService = i, this._interpreter = a;
  7956. }
  7957. get zIndex() {
  7958. return _t.get(oe.LAMBDA) || At;
  7959. }
  7960. create(i) {
  7961. const a = i.getChildren(), e = a[0];
  7962. let t = a.slice(1, -1);
  7963. const r = a[a.length - 1];
  7964. if (!(e instanceof ae && r instanceof ae))
  7965. return xe.create(m.NAME);
  7966. if (e.getToken() === hr) {
  7967. const o = e.getChildren();
  7968. if (t.length !== o.length)
  7969. return xe.create(m.VALUE);
  7970. } else
  7971. t = a.slice(0, -1);
  7972. const n = Xe.generateRandomId(8), s = /* @__PURE__ */ new Map();
  7973. for (let o = 0; o < t.length; o++) {
  7974. const u = t[o];
  7975. if (u instanceof ae) {
  7976. const c = u.getChildren()[0];
  7977. u.setToken(ro), s.set(c.trim(), void 0);
  7978. } else
  7979. return xe.create(m.VALUE);
  7980. }
  7981. return this._runtimeService.registerFunctionDefinitionPrivacyVar(n, s), this._updateLambdaStatement(r, n, s), new eh(i.getToken(), n, this._interpreter, [...s.keys()]);
  7982. }
  7983. checkAndCreateNodeType(i) {
  7984. if (!(!(i instanceof ae) || i.getToken().trim().toUpperCase() !== Sr))
  7985. return this.create(i);
  7986. }
  7987. _updateLambdaStatement(i, a, e) {
  7988. Ea(i, a, e);
  7989. }
  7990. };
  7991. bn = Jf([
  7992. yi(0, Nt),
  7993. yi(1, Ve(Cr))
  7994. ], bn);
  7995. function po(i) {
  7996. if (!i)
  7997. return;
  7998. if (i.getToken() !== Tr)
  7999. return i;
  8000. const a = i, e = a.getCurrentLambdaPrivacyVar(), t = a.getLambdaParameter();
  8001. if (e)
  8002. return po(e.get(t));
  8003. }
  8004. class th extends Ge {
  8005. constructor(a, e, t) {
  8006. super(a), this._lambdaParameter = e, this._currentLambdaPrivacyVar = t;
  8007. }
  8008. getLambdaParameter() {
  8009. return this._lambdaParameter;
  8010. }
  8011. getCurrentLambdaPrivacyVar() {
  8012. return this._currentLambdaPrivacyVar;
  8013. }
  8014. get nodeType() {
  8015. return oe.LAMBDA_PARAMETER;
  8016. }
  8017. execute() {
  8018. const a = po(this._currentLambdaPrivacyVar.get(this._lambdaParameter));
  8019. if (a)
  8020. this.setValue(a.getValue());
  8021. else {
  8022. const e = this.getValue();
  8023. (e == null || e.isError()) && this.setValue(g.create(m.NAME));
  8024. }
  8025. }
  8026. }
  8027. class Vo extends Et {
  8028. get zIndex() {
  8029. return _t.get(oe.LAMBDA_PARAMETER) || At;
  8030. }
  8031. create(a) {
  8032. const e = a.getFunctionDefinitionPrivacyVar(), t = a.getLambdaParameter();
  8033. return e ? new th(a.getToken(), t, e) : new xe(m.NAME);
  8034. }
  8035. checkAndCreateNodeType(a) {
  8036. if (!(!(a instanceof ae) || a.getToken().trim() !== Tr))
  8037. return this.create(a);
  8038. }
  8039. }
  8040. class rh extends Ge {
  8041. constructor(a) {
  8042. super(a), this._operatorString = a;
  8043. }
  8044. get nodeType() {
  8045. return oe.NULL;
  8046. }
  8047. execute() {
  8048. this.setValue(ie.create());
  8049. }
  8050. }
  8051. var Y = /* @__PURE__ */ ((i) => (i.ABS = "ABS", i.ACOS = "ACOS", i.ACOSH = "ACOSH", i.ACOT = "ACOT", i.ACOTH = "ACOTH", i.AGGREGATE = "AGGREGATE", i.ARABIC = "ARABIC", i.ASIN = "ASIN", i.ASINH = "ASINH", i.ATAN = "ATAN", i.ATAN2 = "ATAN2", i.ATANH = "ATANH", i.BASE = "BASE", i.CEILING = "CEILING", i.CEILING_MATH = "CEILING.MATH", i.CEILING_PRECISE = "CEILING.PRECISE", i.COMBIN = "COMBIN", i.COMBINA = "COMBINA", i.COS = "COS", i.COSH = "COSH", i.COT = "COT", i.COTH = "COTH", i.CSC = "CSC", i.CSCH = "CSCH", i.DECIMAL = "DECIMAL", i.DEGREES = "DEGREES", i.EVEN = "EVEN", i.EXP = "EXP", i.FACT = "FACT", i.FACTDOUBLE = "FACTDOUBLE", i.FLOOR = "FLOOR", i.FLOOR_MATH = "FLOOR.MATH", i.FLOOR_PRECISE = "FLOOR.PRECISE", i.GCD = "GCD", i.INT = "INT", i.ISO_CEILING = "ISO.CEILING", i.LCM = "LCM", i.LET = "LET", i.LN = "LN", i.LOG = "LOG", i.LOG10 = "LOG10", i.MDETERM = "MDETERM", i.MINVERSE = "MINVERSE", i.MMULT = "MMULT", i.MOD = "MOD", i.MROUND = "MROUND", i.MULTINOMIAL = "MULTINOMIAL", i.MUNIT = "MUNIT", i.ODD = "ODD", i.PI = "PI", i.POWER = "POWER", i.PRODUCT = "PRODUCT", i.QUOTIENT = "QUOTIENT", i.RADIANS = "RADIANS", i.RAND = "RAND", i.RANDARRAY = "RANDARRAY", i.RANDBETWEEN = "RANDBETWEEN", i.ROMAN = "ROMAN", i.ROUND = "ROUND", i.ROUNDBANK = "ROUNDBANK", i.ROUNDDOWN = "ROUNDDOWN", i.ROUNDUP = "ROUNDUP", i.SEC = "SEC", i.SECH = "SECH", i.SERIESSUM = "SERIESSUM", i.SEQUENCE = "SEQUENCE", i.SIGN = "SIGN", i.SIN = "SIN", i.SINH = "SINH", i.SQRT = "SQRT", i.SQRTPI = "SQRTPI", i.SUBTOTAL = "SUBTOTAL", i.SUM = "SUM", i.SUMIF = "SUMIF", i.SUMIFS = "SUMIFS", i.SUMPRODUCT = "SUMPRODUCT", i.SUMSQ = "SUMSQ", i.SUMX2MY2 = "SUMX2MY2", i.SUMX2PY2 = "SUMX2PY2", i.SUMXMY2 = "SUMXMY2", i.TAN = "TAN", i.TANH = "TANH", i.TRUNC = "TRUNC", i))(Y || {}), se = /* @__PURE__ */ ((i) => (i.ASC = "ASC", i.ARRAYTOTEXT = "ARRAYTOTEXT", i.BAHTTEXT = "BAHTTEXT", i.CHAR = "CHAR", i.CLEAN = "CLEAN", i.CODE = "CODE", i.CONCAT = "CONCAT", i.CONCATENATE = "CONCATENATE", i.DBCS = "DBCS", i.DOLLAR = "DOLLAR", i.EXACT = "EXACT", i.FIND = "FIND", i.FINDB = "FINDB", i.FIXED = "FIXED", i.LEFT = "LEFT", i.LEFTB = "LEFTB", i.LEN = "LEN", i.LENB = "LENB", i.LOWER = "LOWER", i.MID = "MID", i.MIDB = "MIDB", i.NUMBERVALUE = "NUMBERVALUE", i.PHONETIC = "PHONETIC", i.PROPER = "PROPER", i.REGEXEXTRACT = "REGEXEXTRACT", i.REGEXMATCH = "REGEXMATCH", i.REGEXREPLACE = "REGEXREPLACE", i.REPLACE = "REPLACE", i.REPLACEB = "REPLACEB", i.REPT = "REPT", i.RIGHT = "RIGHT", i.RIGHTB = "RIGHTB", i.SEARCH = "SEARCH", i.SEARCHB = "SEARCHB", i.SUBSTITUTE = "SUBSTITUTE", i.T = "T", i.TEXT = "TEXT", i.TEXTAFTER = "TEXTAFTER", i.TEXTBEFORE = "TEXTBEFORE", i.TEXTJOIN = "TEXTJOIN", i.TEXTSPLIT = "TEXTSPLIT", i.TRIM = "TRIM", i.UNICHAR = "UNICHAR", i.UNICODE = "UNICODE", i.UPPER = "UPPER", i.VALUE = "VALUE", i.VALUETOTEXT = "VALUETOTEXT", i.CALL = "CALL", i.EUROCONVERT = "EUROCONVERT", i.REGISTER_ID = "REGISTER.ID", i))(se || {}), nh = Object.defineProperty, sh = Object.getOwnPropertyDescriptor, ah = (i, a, e, t) => {
  8052. for (var r = t > 1 ? void 0 : t ? sh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  8053. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  8054. return t && r && nh(a, e, r), r;
  8055. }, ih = (i, a) => (e, t) => a(e, t, i);
  8056. class oh extends Ge {
  8057. constructor(a, e) {
  8058. super(a), this._functionExecutor = e;
  8059. }
  8060. get nodeType() {
  8061. return oe.OPERATOR;
  8062. }
  8063. execute() {
  8064. const a = this.getChildren();
  8065. this._functionExecutor.name === Te.COMPARE && this._functionExecutor.setCompareType(this.getToken());
  8066. const e = a[0], t = a[1];
  8067. let r = e == null ? void 0 : e.getValue(), n = t == null ? void 0 : t.getValue();
  8068. const s = this.getToken();
  8069. if ((r == null || n == null) && s !== X.MINUS && s !== X.PLUS) {
  8070. this.setValue(g.create(m.VALUE));
  8071. return;
  8072. }
  8073. r == null && (r = ie.create()), n == null && (n = ie.create()), r.isReferenceObject() && (r = r.toArrayValueObject()), n.isReferenceObject() && (n = n.toArrayValueObject()), this.setValue(
  8074. this._functionExecutor.calculate(
  8075. r,
  8076. n
  8077. )
  8078. );
  8079. }
  8080. }
  8081. let yn = class extends Et {
  8082. constructor(i) {
  8083. super(), this._functionService = i;
  8084. }
  8085. get zIndex() {
  8086. return _t.get(oe.OPERATOR) || At;
  8087. }
  8088. create(i) {
  8089. let a = "";
  8090. const e = i;
  8091. e === X.PLUS ? a = Te.PLUS : e === X.MINUS ? a = Te.MINUS : e === X.MULTIPLY ? a = Te.MULTIPLY : e === X.DIVIDED ? a = Te.DIVIDED : e === X.CONCATENATE ? a = se.CONCATENATE : e === X.POWER ? a = Y.POWER : ec.has(e) && (a = Te.COMPARE);
  8092. const t = this._functionService.getExecutor(a);
  8093. return t ? new oh(e, t) : (console.error(`No function ${i}`), xe.create(m.NAME));
  8094. }
  8095. checkAndCreateNodeType(i) {
  8096. if (i instanceof ae)
  8097. return;
  8098. const a = i.trim();
  8099. if (!(a.charAt(0) === '"' && a.charAt(a.length - 1) === '"') && Dt.has(a))
  8100. return this.create(a);
  8101. }
  8102. };
  8103. yn = ah([
  8104. ih(0, Yt)
  8105. ], yn);
  8106. var uh = Object.defineProperty, ch = Object.getOwnPropertyDescriptor, lh = (i, a, e, t) => {
  8107. for (var r = t > 1 ? void 0 : t ? ch(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  8108. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  8109. return t && r && uh(a, e, r), r;
  8110. }, cs = (i, a) => (e, t) => a(e, t, i);
  8111. class ls extends Ge {
  8112. constructor(e, t, r, n, s = !1) {
  8113. super(r);
  8114. A(this, "_refOffsetX", 0);
  8115. A(this, "_refOffsetY", 0);
  8116. this._currentConfigService = e, this._runtimeService = t, this._referenceObjectType = n, this._isPrepareMerge = s;
  8117. }
  8118. get nodeType() {
  8119. return oe.REFERENCE;
  8120. }
  8121. execute() {
  8122. const e = this._currentConfigService, t = this._runtimeService, r = Sf(this.getToken(), this._referenceObjectType);
  8123. r.setDefaultUnitId(t.currentUnitId), r.setDefaultSheetId(t.currentSubUnitId), r.setForcedSheetId(e.getSheetNameMap()), r.setUnitData(e.getUnitData()), r.setArrayFormulaCellData(e.getArrayFormulaCellData()), r.setRuntimeData(t.getUnitData()), r.setUnitStylesData(e.getUnitStylesData()), r.setRuntimeArrayFormulaCellData(t.getRuntimeArrayFormulaCellData()), r.setRuntimeFeatureCellData(t.getRuntimeFeatureCellData());
  8124. const { x: n, y: s } = this.getRefOffset();
  8125. r.setRefOffset(n, s), !this._isPrepareMerge && r.isExceedRange() ? this.setValue(g.create(m.NAME)) : this.setValue(r);
  8126. }
  8127. setRefOffset(e = 0, t = 0) {
  8128. this._refOffsetX = e, this._refOffsetY = t;
  8129. }
  8130. getRefOffset() {
  8131. return {
  8132. x: this._refOffsetX,
  8133. y: this._refOffsetY
  8134. };
  8135. }
  8136. }
  8137. let Rn = class extends Et {
  8138. constructor(i, a, e) {
  8139. super(), this._currentConfigService = i, this._formulaRuntimeService = a, this._functionService = e;
  8140. }
  8141. get zIndex() {
  8142. return _t.get(oe.REFERENCE) || At;
  8143. }
  8144. checkAndCreateNodeType(i) {
  8145. var l, f;
  8146. let a = !1, e, t = !1;
  8147. i instanceof ae ? (a = !0, e = i.getToken().trim(), ((f = (l = i.getParent()) == null ? void 0 : l.getParent()) == null ? void 0 : f.getToken().trim()) === K.COLON && (t = !0)) : e = i.trim();
  8148. const r = this._currentConfigService, n = this._formulaRuntimeService, { tokenTrim: s, minusPrefixNode: o, atPrefixNode: u } = bo(e, this._functionService, n);
  8149. if (!a && s.charAt(0) === '"' && s.charAt(s.length - 1) === '"')
  8150. return;
  8151. let c;
  8152. if (vr(s) ? c = new ls(r, n, s, an.CELL, t) : a && this._checkParentIsUnionOperator(i) && (Qi(s) ? c = new ls(r, n, s, an.ROW, t) : Wi(s) && (c = new ls(r, n, s, an.COLUMN, t))), c)
  8153. return u ? c.setParent(u) : o && c.setParent(o), c;
  8154. }
  8155. _checkParentIsUnionOperator(i) {
  8156. var a, e;
  8157. return ((e = (a = i.getParent()) == null ? void 0 : a.getParent()) == null ? void 0 : e.getToken().trim()) === K.COLON;
  8158. }
  8159. };
  8160. Rn = lh([
  8161. cs(0, Ft),
  8162. cs(1, Nt),
  8163. cs(2, Yt)
  8164. ], Rn);
  8165. var fh = Object.defineProperty, hh = Object.getOwnPropertyDescriptor, mh = (i, a, e, t) => {
  8166. for (var r = t > 1 ? void 0 : t ? hh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  8167. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  8168. return t && r && fh(a, e, r), r;
  8169. }, fs = (i, a) => (e, t) => a(e, t, i);
  8170. class Ri extends Ge {
  8171. constructor(a, e, t, r) {
  8172. super(t), this._currentConfigService = a, this._lexer = e, this._operatorString = t, this._functionExecutor = r;
  8173. }
  8174. get nodeType() {
  8175. return oe.SUFFIX;
  8176. }
  8177. execute() {
  8178. let e = this.getChildren()[0].getValue(), t;
  8179. if (e == null)
  8180. throw new Error("object is null");
  8181. if (this._operatorString === ze.PERCENTAGE) {
  8182. if (e.isReferenceObject() && (e = e.toArrayValueObject()), t = this._functionExecutor.calculate(
  8183. e,
  8184. y.create(100)
  8185. ), t.isNumber()) {
  8186. const r = Number(t.getValue());
  8187. t = y.create(r, "0.00%");
  8188. }
  8189. } else this._operatorString === ze.POUND ? t = this._handlerPound(e) : t = g.create(m.VALUE);
  8190. this.setValue(t);
  8191. }
  8192. _handlerPound(a) {
  8193. var u, c, l, f;
  8194. if (!a.isReferenceObject() || !a.isCell())
  8195. return g.create(m.VALUE);
  8196. const e = a, t = e.getRangePosition(), r = e.getUnitId(), n = e.getSheetId(), s = this._currentConfigService.getFormulaData(), o = (f = (l = (c = (u = s == null ? void 0 : s[r]) == null ? void 0 : u[n]) == null ? void 0 : c[t.startRow]) == null ? void 0 : l[t.startColumn]) == null ? void 0 : f.f;
  8197. return o && this._lexer.treeBuilder(o), g.create(m.VALUE);
  8198. }
  8199. }
  8200. let pn = class extends Et {
  8201. constructor(i, a, e) {
  8202. super(), this._functionService = i, this._lexer = a, this._currentConfigService = e;
  8203. }
  8204. get zIndex() {
  8205. return _t.get(oe.SUFFIX) || At;
  8206. }
  8207. checkAndCreateNodeType(i) {
  8208. if (!(i instanceof ae))
  8209. return;
  8210. const a = i.getToken().trim();
  8211. if (a.charAt(0) === '"' && a.charAt(a.length - 1) === '"')
  8212. return;
  8213. let e = "";
  8214. if (a === ze.PERCENTAGE)
  8215. e = Te.DIVIDED;
  8216. else return a === ze.POUND ? new Ri(this._currentConfigService, this._lexer, a) : void 0;
  8217. const t = this._functionService.getExecutor(e);
  8218. return t ? new Ri(this._currentConfigService, this._lexer, a, t) : (console.error(`No function ${i}`), xe.create(m.NAME));
  8219. }
  8220. };
  8221. pn = mh([
  8222. fs(0, Yt),
  8223. fs(1, Ve(gr)),
  8224. fs(2, Ft)
  8225. ], pn);
  8226. var gh = Object.defineProperty, dh = Object.getOwnPropertyDescriptor, Ch = (i, a, e, t) => {
  8227. for (var r = t > 1 ? void 0 : t ? dh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  8228. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  8229. return t && r && gh(a, e, r), r;
  8230. }, _h = (i, a) => (e, t) => a(e, t, i);
  8231. class Ah extends Ge {
  8232. constructor(a) {
  8233. super(a);
  8234. }
  8235. get nodeType() {
  8236. return oe.UNION;
  8237. }
  8238. execute() {
  8239. const a = this.getChildren(), e = a[0], t = a[1], r = e.getValue(), n = t.getValue();
  8240. if (r == null || n == null)
  8241. throw new Error("leftNode and rightNode");
  8242. let s;
  8243. this.getToken() === K.COLON ? s = this._unionFunction(r, n) : s = g.create(m.NAME), this.setValue(s);
  8244. }
  8245. _unionFunction(a, e) {
  8246. return a.isError() || e.isError() || !a.isReferenceObject() || !e.isReferenceObject() ? g.create(m.REF) : (a = a, e = e, Pf(a, e));
  8247. }
  8248. }
  8249. let Vn = class extends Et {
  8250. constructor(i) {
  8251. super(), this._functionService = i;
  8252. }
  8253. get zIndex() {
  8254. return _t.get(oe.UNION) || At;
  8255. }
  8256. create(i) {
  8257. return new Ah(i);
  8258. }
  8259. checkAndCreateNodeType(i) {
  8260. if (!(i instanceof ae))
  8261. return;
  8262. const e = i.getToken().trim();
  8263. if (!(e.charAt(0) === '"' && e.charAt(e.length - 1) === '"') && e === K.COLON)
  8264. return this.create(e);
  8265. }
  8266. };
  8267. Vn = Ch([
  8268. _h(0, Yt)
  8269. ], Vn);
  8270. class Eh extends Ge {
  8271. constructor(a) {
  8272. super(a);
  8273. }
  8274. get nodeType() {
  8275. return oe.VALUE;
  8276. }
  8277. execute() {
  8278. this.setValue(pt.create(this.getToken()));
  8279. }
  8280. }
  8281. class No extends Et {
  8282. get zIndex() {
  8283. return _t.get(oe.VALUE) || At;
  8284. }
  8285. _checkValueNode(a) {
  8286. if (Number.isNaN(Number(a))) {
  8287. const e = a.trim(), t = e.charAt(0), r = e.charAt(e.length - 1);
  8288. if (yr.has(e))
  8289. return this.create(e);
  8290. if (t === '"' && r === '"')
  8291. return this.create(e);
  8292. if (t === "{" && r === "}")
  8293. return this.create(e);
  8294. const n = e.toUpperCase();
  8295. if (n === er.TRUE || n === er.FALSE)
  8296. return this.create(n);
  8297. } else
  8298. return this.create(a);
  8299. }
  8300. create(a) {
  8301. return new Eh(a);
  8302. }
  8303. checkAndCreateNodeType(a) {
  8304. if (!(a instanceof ae))
  8305. return this._checkValueNode(a);
  8306. }
  8307. }
  8308. var bh = Object.defineProperty, yh = Object.getOwnPropertyDescriptor, Rh = (i, a, e, t) => {
  8309. for (var r = t > 1 ? void 0 : t ? yh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  8310. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  8311. return t && r && bh(a, e, r), r;
  8312. }, at = (i, a) => (e, t) => a(e, t, i);
  8313. let xr = class extends Me {
  8314. constructor(a, e, t, r, n, s, o, u, c, l, f) {
  8315. super();
  8316. A(this, "_astNodeFactoryList", []);
  8317. this._runtimeService = a, this._astRootNodeFactory = e, this._functionNodeFactory = t, this._lambdaNodeFactory = r, this._lambdaParameterNodeFactory = n, this._operatorNodeFactory = s, this._prefixNodeFactory = o, this._referenceNodeFactory = u, this._suffixNodeFactory = c, this._unionNodeFactory = l, this._valueNodeFactory = f, this._initializeAstNode();
  8318. }
  8319. dispose() {
  8320. this._astNodeFactoryList.forEach((a) => {
  8321. a.dispose();
  8322. }), this._astNodeFactoryList = [];
  8323. }
  8324. parse(a) {
  8325. const e = new Fs(Ut), t = this._parse(a, e);
  8326. return a.hasDefinedNames() && (t == null || t.setDefinedNames(a.getDefinedNames())), t;
  8327. }
  8328. _lambdaParameterHandler(a, e) {
  8329. if (e.getLambdaId == null)
  8330. return xe.create(m.VALUE);
  8331. const t = e.getLambdaId(), r = new Fs(Ut), n = this._runtimeService.getFunctionDefinitionPrivacyVar(t);
  8332. if (!n)
  8333. return !1;
  8334. const s = [...n.keys()], o = a.getChildren(), u = o.length;
  8335. for (let c = 0; c < u; c++) {
  8336. const l = o[c];
  8337. if (l instanceof ae) {
  8338. Ea(l, t, n), this._parse(l, r);
  8339. const h = r.getChildren()[c];
  8340. h != null && n.set(s[c], h);
  8341. } else
  8342. return !1;
  8343. }
  8344. return r.setParent(e), e;
  8345. }
  8346. _changeLetToLambda(a) {
  8347. const e = a.getChildren(), t = e.length;
  8348. if (t % 2 !== 1 || t === 0)
  8349. return;
  8350. const r = new ae();
  8351. r.setToken(Sr);
  8352. const n = new ae();
  8353. n.setToken(hr);
  8354. const s = [...e];
  8355. for (let u = 0; u < t; u++) {
  8356. const c = s[u];
  8357. if (!(c instanceof ae))
  8358. return;
  8359. u % 2 === 0 ? c.changeToParent(r) : c.changeToParent(n);
  8360. }
  8361. r.addChildrenFirst(n), n.setParent(r);
  8362. const o = a.getParent();
  8363. return o == null || o.replaceChild(a, r), r;
  8364. }
  8365. // eslint-disable-next-line max-lines-per-function, complexity
  8366. _parse(a, e) {
  8367. var l;
  8368. const t = a.getChildren(), r = t.length, n = [];
  8369. let s = null;
  8370. const o = a.getToken().trim().toUpperCase();
  8371. if (o === vc) {
  8372. const f = this._changeLetToLambda(a);
  8373. return f != null ? this._parse(f, e) : xe.create(m.ERROR);
  8374. }
  8375. if (o === ht) {
  8376. if (s = e, r === 0)
  8377. return new rh(Ut).setParent(e), s;
  8378. } else {
  8379. if (o === hr) {
  8380. let f = this._lambdaParameterHandler(a, e);
  8381. return f === !1 && (f = xe.create(m.ERROR)), f;
  8382. }
  8383. if (s = this._checkAstNode(a), s == null)
  8384. return xe.create(m.NAME);
  8385. }
  8386. const u = t[0];
  8387. for (let f = 0; f < r; f++) {
  8388. const h = t[f];
  8389. if (yo(u)) {
  8390. if (f !== 0 && f !== r - 1)
  8391. continue;
  8392. } else if (Kf(h) && f !== r - 1)
  8393. continue;
  8394. let d = null;
  8395. if (h instanceof ae) {
  8396. if (h.getToken() === ht && h.getChildren().length === 0) {
  8397. const _ = (l = h.getParent()) == null ? void 0 : l.getChildren();
  8398. if (_ && _.length === 1)
  8399. return xe.create(m.NAME);
  8400. }
  8401. if (d = this._parse(h, s), d === s)
  8402. continue;
  8403. } else
  8404. d = this._checkAstNode(h);
  8405. if (d == null)
  8406. return xe.create(m.NAME);
  8407. if (d = Xf(d), d == null || (d == null ? void 0 : d.nodeType) === oe.ERROR)
  8408. return d;
  8409. switch (d.nodeType) {
  8410. // case NodeType.ERROR:
  8411. // return astNode;
  8412. case oe.FUNCTION: {
  8413. const _ = d.getToken().trim().toUpperCase();
  8414. Bc.has(_) && d.setForcedCalculateFunction(), n.push(d);
  8415. break;
  8416. }
  8417. case oe.LAMBDA:
  8418. n.push(d);
  8419. break;
  8420. case oe.LAMBDA_PARAMETER:
  8421. n.push(d);
  8422. break;
  8423. case oe.OPERATOR: {
  8424. const _ = n.pop(), C = n.pop();
  8425. C && C.setParent(d), _ && _.setParent(d), n.push(d);
  8426. break;
  8427. }
  8428. case oe.REFERENCE:
  8429. n.push(d);
  8430. break;
  8431. case oe.ROOT:
  8432. n.push(d);
  8433. break;
  8434. case oe.UNION:
  8435. n.push(d);
  8436. break;
  8437. case oe.VALUE:
  8438. n.push(d);
  8439. break;
  8440. case oe.PREFIX:
  8441. n.push(d);
  8442. break;
  8443. case oe.SUFFIX:
  8444. n.push(d);
  8445. break;
  8446. }
  8447. }
  8448. const c = n.length;
  8449. for (let f = 0; f < c; f++)
  8450. n[f].setParent(s);
  8451. return s;
  8452. }
  8453. // private _setPrefixRefOffset(astNode: BaseAstNode) {
  8454. // const children = astNode.getChildren();
  8455. // const childrenCount = children.length;
  8456. // for (let i = 0; i < childrenCount; i++) {
  8457. // const item = children[i];
  8458. // if (item.nodeType === NodeType.REFERENCE) {
  8459. // item.setRefOffset(this._refOffsetX, this._refOffsetY);
  8460. // }
  8461. // }
  8462. // }
  8463. _checkAstNode(a) {
  8464. let e = null;
  8465. const t = this._astNodeFactoryList.length;
  8466. for (let r = 0; r < t && (e = this._astNodeFactoryList[r].checkAndCreateNodeType(a), e == null); r++)
  8467. ;
  8468. return e == null ? new Hf() : e;
  8469. }
  8470. _initializeAstNode() {
  8471. this._astNodeFactoryList = [
  8472. this._astRootNodeFactory,
  8473. this._functionNodeFactory,
  8474. this._lambdaNodeFactory,
  8475. this._lambdaParameterNodeFactory,
  8476. this._operatorNodeFactory,
  8477. this._prefixNodeFactory,
  8478. this._referenceNodeFactory,
  8479. this._suffixNodeFactory,
  8480. this._unionNodeFactory,
  8481. this._valueNodeFactory
  8482. ].sort(Gu);
  8483. }
  8484. };
  8485. xr = Rh([
  8486. at(0, Nt),
  8487. at(1, Ve(Eo)),
  8488. at(2, Ve(En)),
  8489. at(3, Ve(bn)),
  8490. at(4, Ve(Vo)),
  8491. at(5, Ve(yn)),
  8492. at(6, Ve(An)),
  8493. at(7, Ve(Rn)),
  8494. at(8, Ve(pn)),
  8495. at(9, Ve(Vn)),
  8496. at(10, Ve(No))
  8497. ], xr);
  8498. class ph extends Me {
  8499. constructor() {
  8500. super(...arguments);
  8501. A(this, "_otherFormulaData", /* @__PURE__ */ new Map());
  8502. // [unitId: string]: Nullable<{ [sheetId: string]: { [formulaId: string]: Set<number> } }>;
  8503. A(this, "_featureFormulaData", /* @__PURE__ */ new Map());
  8504. // [unitId: string]: Nullable<{ [sheetId: string]: { [featureId: string]: Nullable<number> } }>;
  8505. A(this, "_formulaData", /* @__PURE__ */ new Map());
  8506. // [unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix<number> }>;
  8507. A(this, "_definedNameMap", /* @__PURE__ */ new Map());
  8508. // unitId -> definedName -> treeId
  8509. A(this, "_otherFormulaDataMainData", /* @__PURE__ */ new Set());
  8510. A(this, "_dependencyRTreeCache", new As());
  8511. A(this, "_dependencyTreeIdLast", 0);
  8512. }
  8513. buildDependencyTree(e, t) {
  8514. throw new Error("Method not implemented.");
  8515. }
  8516. getTreeById(e) {
  8517. throw new Error("Method not implemented.");
  8518. }
  8519. getAllTree() {
  8520. throw new Error("Method not implemented.");
  8521. }
  8522. reset() {
  8523. throw new Error("Method not implemented.");
  8524. }
  8525. addOtherFormulaDependency(e, t, r, n) {
  8526. throw new Error("Method not implemented.");
  8527. }
  8528. removeOtherFormulaDependency(e, t, r) {
  8529. throw new Error("Method not implemented.");
  8530. }
  8531. clearOtherFormulaDependency(e, t) {
  8532. throw new Error("Method not implemented.");
  8533. }
  8534. addFeatureFormulaDependency(e, t, r, n) {
  8535. throw new Error("Method not implemented.");
  8536. }
  8537. removeFeatureFormulaDependency(e, t, r) {
  8538. throw new Error("Method not implemented.");
  8539. }
  8540. clearFeatureFormulaDependency(e, t) {
  8541. throw new Error("Method not implemented.");
  8542. }
  8543. addFormulaDependency(e, t, r, n, s) {
  8544. throw new Error("Method not implemented.");
  8545. }
  8546. removeFormulaDependency(e, t, r, n) {
  8547. throw new Error("Method not implemented.");
  8548. }
  8549. clearFormulaDependency(e, t) {
  8550. throw new Error("Method not implemented.");
  8551. }
  8552. removeFormulaDependencyByDefinedName(e, t) {
  8553. throw new Error("Method not implemented.");
  8554. }
  8555. searchDependency(e, t) {
  8556. return this._dependencyRTreeCache.bulkSearch(e, t);
  8557. }
  8558. _restDependencyTreeId() {
  8559. this._dependencyTreeIdLast = 0;
  8560. }
  8561. getOtherFormulaDependency(e, t, r) {
  8562. var n, s;
  8563. return (s = (n = this._otherFormulaData.get(e)) == null ? void 0 : n.get(t)) == null ? void 0 : s.get(r);
  8564. }
  8565. addOtherFormulaDependencyMainData(e) {
  8566. this._otherFormulaDataMainData.add(e);
  8567. }
  8568. hasOtherFormulaDataMainData(e) {
  8569. return this._otherFormulaDataMainData.has(e);
  8570. }
  8571. _removeDependencyRTreeCacheById(e, t) {
  8572. this._dependencyRTreeCache.removeById(e, t);
  8573. }
  8574. getFeatureFormulaDependency(e, t, r) {
  8575. var n, s;
  8576. return (s = (n = this._featureFormulaData.get(e)) == null ? void 0 : n.get(t)) == null ? void 0 : s.get(r);
  8577. }
  8578. getFormulaDependency(e, t, r, n) {
  8579. var s, o;
  8580. return (o = (s = this._formulaData.get(e)) == null ? void 0 : s.get(t)) == null ? void 0 : o.getValue(r, n);
  8581. }
  8582. addDependencyRTreeCache(e) {
  8583. const t = [];
  8584. for (let r = 0; r < e.rangeList.length; r++) {
  8585. const n = e.rangeList[r], { unitId: s, sheetId: o, range: u } = n;
  8586. t.push({
  8587. unitId: s,
  8588. sheetId: o,
  8589. range: u,
  8590. id: e.treeId
  8591. });
  8592. }
  8593. this._dependencyRTreeCache.bulkInsert(t), this._addAllTreeMap(e);
  8594. }
  8595. getLastTreeId() {
  8596. const e = this._dependencyTreeIdLast;
  8597. return this._dependencyTreeIdLast++, e;
  8598. }
  8599. _addAllTreeMap(e) {
  8600. throw new Error("Method not implemented.");
  8601. }
  8602. _addDefinedName(e, t, r) {
  8603. this._definedNameMap.has(e) || this._definedNameMap.set(e, /* @__PURE__ */ new Map());
  8604. const n = this._definedNameMap.get(e);
  8605. n.has(t) || n.set(t, /* @__PURE__ */ new Set()), n.get(t).add(r);
  8606. }
  8607. addFormulaDependencyByDefinedName(e, t) {
  8608. const r = e.treeId, n = (t == null ? void 0 : t.getDefinedNames()) || [];
  8609. for (const s of n)
  8610. this._addDefinedName(e.unitId, s, r);
  8611. }
  8612. }
  8613. class Vh extends ph {
  8614. constructor() {
  8615. super(...arguments);
  8616. A(this, "_allTreeMap", /* @__PURE__ */ new Map());
  8617. }
  8618. dispose() {
  8619. this.reset();
  8620. }
  8621. buildDependencyTree(e, t = []) {
  8622. const r = this.getAllTree();
  8623. return e.length === 0 ? (this._buildReverseDependency(r, t), r) : (this._buildDependencyTree(r, e), this._buildReverseDependency(r, e), r);
  8624. }
  8625. /**
  8626. * Build the dependency relationship between the trees.
  8627. * @param allTrees all FormulaDependencyTree
  8628. * @param shouldBeBuildTrees FormulaDependencyTree[] | FormulaDependencyTreeCache
  8629. */
  8630. _buildDependencyTree(e, t) {
  8631. const r = /* @__PURE__ */ new Map();
  8632. for (let n = 0; n < t.length; n++) {
  8633. const s = t[n];
  8634. r.set(s.treeId, s);
  8635. }
  8636. for (let n = 0; n < e.length; n++) {
  8637. const s = e[n], o = s.toRTreeItem(), u = this._dependencyRTreeCache.bulkSearch(o);
  8638. for (const c of u) {
  8639. const l = r.get(c);
  8640. l && s !== l && !l.hasChildren(s.treeId) && l.pushChildren(s);
  8641. }
  8642. }
  8643. r.clear();
  8644. }
  8645. /**
  8646. * Build the reverse dependency relationship between the trees.
  8647. * @param allTrees
  8648. * @param dependencyTrees
  8649. */
  8650. _buildReverseDependency(e, t) {
  8651. const r = /* @__PURE__ */ new Map();
  8652. for (let n = 0; n < e.length; n++) {
  8653. const s = e[n];
  8654. r.set(s.treeId, s);
  8655. }
  8656. for (let n = 0; n < t.length; n++) {
  8657. const s = t[n], o = s.toRTreeItem(), u = this._dependencyRTreeCache.bulkSearch(o);
  8658. for (const c of u) {
  8659. const l = r.get(c);
  8660. l && s !== l && !l.hasChildren(s.treeId) && l.pushChildren(s);
  8661. }
  8662. }
  8663. r.clear();
  8664. }
  8665. /**
  8666. * Get all FormulaDependencyTree from _otherFormulaData, _featureFormulaData, _formulaData
  8667. * return FormulaDependencyTree[]
  8668. */
  8669. getAllTree() {
  8670. const e = [];
  8671. return this._allTreeMap.forEach((t) => {
  8672. t.resetState(), e.push(t);
  8673. }), e;
  8674. }
  8675. getTreeById(e) {
  8676. return this._allTreeMap.get(e);
  8677. }
  8678. reset() {
  8679. this._otherFormulaData.clear(), this._featureFormulaData.clear(), this._formulaData.clear(), this._dependencyRTreeCache.clear(), this._allTreeMap.clear(), this._restDependencyTreeId(), this._otherFormulaDataMainData.clear();
  8680. }
  8681. addOtherFormulaDependency(e, t, r, n) {
  8682. this._otherFormulaData.has(e) || this._otherFormulaData.set(e, /* @__PURE__ */ new Map());
  8683. const s = this._otherFormulaData.get(e);
  8684. s.has(t) || s.set(t, /* @__PURE__ */ new Map());
  8685. const o = s.get(t);
  8686. o.has(r) || o.set(r, new Ce()), o.get(r).setValue(n.refOffsetX, n.refOffsetY, n.treeId), this._addAllTreeMap(n);
  8687. }
  8688. removeOtherFormulaDependency(e, t, r) {
  8689. const n = this._otherFormulaData.get(e);
  8690. if (n && n.has(t)) {
  8691. const s = n.get(t);
  8692. r.forEach((o) => {
  8693. const u = s.get(o);
  8694. u != null && (u.forValue((c, l, f) => {
  8695. this._removeDependencyRTreeCache(f), this.clearDependencyForTree(this._allTreeMap.get(f)), this._removeAllTreeMap(f);
  8696. }), s.delete(o), this._otherFormulaDataMainData.delete(o));
  8697. }), s.size === 0 && n.delete(t), n.size === 0 && this._otherFormulaData.delete(e);
  8698. }
  8699. }
  8700. clearOtherFormulaDependency(e, t) {
  8701. const r = this._otherFormulaData.get(e);
  8702. if (t && r && r.has(t)) {
  8703. const n = r.get(t);
  8704. this._removeDependencyRTreeCacheById(e, t);
  8705. for (const s of n.keys()) {
  8706. const o = n.get(s);
  8707. o != null && (o.forValue((u, c, l) => {
  8708. const f = this._allTreeMap.get(l);
  8709. f && (this.clearDependencyForTree(f), this._removeAllTreeMap(l));
  8710. }), this._otherFormulaDataMainData.delete(s));
  8711. }
  8712. n.clear();
  8713. } else if (r) {
  8714. for (const n of r.keys()) {
  8715. const s = r.get(n);
  8716. this._removeDependencyRTreeCacheById(e, n);
  8717. for (const o of s.keys()) {
  8718. const u = s.get(o);
  8719. u != null && (u.forValue((c, l, f) => {
  8720. const h = this._allTreeMap.get(f);
  8721. h && (this.clearDependencyForTree(h), this._removeAllTreeMap(f));
  8722. }), this._otherFormulaDataMainData.delete(o));
  8723. }
  8724. }
  8725. this._otherFormulaData.delete(e);
  8726. }
  8727. }
  8728. addFeatureFormulaDependency(e, t, r, n) {
  8729. this._featureFormulaData.has(e) || this._featureFormulaData.set(e, /* @__PURE__ */ new Map());
  8730. const s = this._featureFormulaData.get(e);
  8731. s.has(t) || s.set(t, /* @__PURE__ */ new Map()), s.get(t).set(r, n.treeId), this._addAllTreeMap(n);
  8732. }
  8733. removeFeatureFormulaDependency(e, t, r) {
  8734. const n = this._featureFormulaData.get(e);
  8735. if (n && n.has(t)) {
  8736. const s = n.get(t);
  8737. r.forEach((o) => {
  8738. const u = s.get(o);
  8739. u != null && (this._removeDependencyRTreeCache(u), s.delete(o), this.clearDependencyForTree(this._allTreeMap.get(u)), this._removeAllTreeMap(u));
  8740. });
  8741. }
  8742. }
  8743. clearFeatureFormulaDependency(e, t) {
  8744. const r = this._featureFormulaData.get(e);
  8745. if (t && r && r.has(t)) {
  8746. const n = r.get(t);
  8747. this._removeDependencyRTreeCacheById(e, t), n.forEach((s) => {
  8748. s != null && (this.clearDependencyForTree(this._allTreeMap.get(s)), this._removeAllTreeMap(s));
  8749. }), n.clear();
  8750. } else r && (r.forEach((n, s) => {
  8751. this._removeDependencyRTreeCacheById(e, s), n.forEach((o) => {
  8752. o != null && (this.clearDependencyForTree(this._allTreeMap.get(o)), this._removeAllTreeMap(o));
  8753. });
  8754. }), this._featureFormulaData.delete(e));
  8755. }
  8756. addFormulaDependency(e, t, r, n, s) {
  8757. this._formulaData.has(e) || this._formulaData.set(e, /* @__PURE__ */ new Map());
  8758. const o = this._formulaData.get(e);
  8759. o.has(t) || o.set(t, new Ce()), o.get(t).setValue(r, n, s.treeId), this._addAllTreeMap(s);
  8760. }
  8761. removeFormulaDependency(e, t, r, n) {
  8762. const s = this._formulaData.get(e);
  8763. if (s && s.has(t)) {
  8764. const o = s.get(t), u = o.getValue(r, n);
  8765. if (u == null)
  8766. return;
  8767. this._removeDependencyRTreeCache(u), o.realDeleteValue(r, n), this.clearDependencyForTree(this._allTreeMap.get(u)), this._removeAllTreeMap(u);
  8768. }
  8769. }
  8770. clearFormulaDependency(e, t) {
  8771. const r = this._formulaData.get(e);
  8772. if (t && r && r.has(t)) {
  8773. const n = r.get(t);
  8774. this._removeDependencyRTreeCacheById(e, t), n.forValue((s, o, u) => {
  8775. if (u == null)
  8776. return !0;
  8777. this.clearDependencyForTree(this._allTreeMap.get(u)), this._removeAllTreeMap(u);
  8778. }), n.reset();
  8779. } else r && (r.forEach((n, s) => {
  8780. this._removeDependencyRTreeCacheById(e, s), n.forValue((o, u, c) => {
  8781. if (c == null)
  8782. return !0;
  8783. this.clearDependencyForTree(this._allTreeMap.get(c)), this._removeAllTreeMap(c);
  8784. });
  8785. }), this._formulaData.delete(e));
  8786. }
  8787. /**
  8788. * Clear the dependency relationship of the tree.
  8789. * establish the relationship between the parent and the child.
  8790. * @param shouldBeClearTree
  8791. */
  8792. clearDependencyForTree(e) {
  8793. if (e == null)
  8794. return;
  8795. const t = e.parents, r = e.children, n = this._allTreeMap;
  8796. for (const s of t) {
  8797. const o = n.get(s);
  8798. o == null || o.children.delete(e.treeId);
  8799. }
  8800. for (const s of r) {
  8801. const o = n.get(s);
  8802. o == null || o.parents.delete(e.treeId);
  8803. }
  8804. e.dispose();
  8805. }
  8806. _removeDependencyRTreeCache(e) {
  8807. if (e == null)
  8808. return;
  8809. const t = this._allTreeMap.get(e);
  8810. if (t) {
  8811. const r = [];
  8812. for (let n = 0; n < t.rangeList.length; n++) {
  8813. const s = t.rangeList[n], { unitId: o, sheetId: u, range: c } = s;
  8814. r.push({
  8815. unitId: o,
  8816. sheetId: u,
  8817. range: c,
  8818. id: e
  8819. });
  8820. }
  8821. this._dependencyRTreeCache.bulkRemove(r);
  8822. }
  8823. }
  8824. removeFormulaDependencyByDefinedName(e, t) {
  8825. const r = this._definedNameMap.get(e);
  8826. if (r) {
  8827. const n = r.get(t);
  8828. if (n) {
  8829. for (const s of n)
  8830. this._removeDependencyRTreeCache(s), this.clearDependencyForTree(this._allTreeMap.get(s)), this._removeAllTreeMap(s);
  8831. n.clear();
  8832. }
  8833. }
  8834. }
  8835. _removeAllTreeMap(e) {
  8836. e != null && this._allTreeMap.delete(e);
  8837. }
  8838. _addAllTreeMap(e) {
  8839. this._allTreeMap.set(e.treeId, e);
  8840. }
  8841. }
  8842. const Hn = lt(
  8843. "univer.formula.dependency-manager.service"
  8844. );
  8845. class Nh extends Me {
  8846. constructor() {
  8847. super(...arguments);
  8848. A(this, "_referenceExecutorMap", /* @__PURE__ */ new Map());
  8849. // unitId -> subUnitId -> featureId -> IFeatureCalculationManagerParam
  8850. A(this, "_onChanged$", new ur());
  8851. A(this, "onChanged$", this._onChanged$.asObservable());
  8852. }
  8853. dispose() {
  8854. this._referenceExecutorMap.clear();
  8855. }
  8856. remove(e, t, r) {
  8857. r.forEach((n) => {
  8858. var s, o;
  8859. (o = (s = this._referenceExecutorMap.get(e)) == null ? void 0 : s.get(t)) == null || o.delete(n);
  8860. }), this._onChanged$.next({
  8861. unitId: e,
  8862. subUnitId: t,
  8863. featureIds: r
  8864. });
  8865. }
  8866. get(e, t, r) {
  8867. var n, s;
  8868. return (s = (n = this._referenceExecutorMap.get(e)) == null ? void 0 : n.get(t)) == null ? void 0 : s.get(r);
  8869. }
  8870. has(e, t, r) {
  8871. var n, s;
  8872. return !!((s = (n = this._referenceExecutorMap.get(e)) == null ? void 0 : n.get(t)) != null && s.has(r));
  8873. }
  8874. register(e, t, r, n) {
  8875. let s = this._referenceExecutorMap.get(e);
  8876. s || (s = /* @__PURE__ */ new Map(), this._referenceExecutorMap.set(e, s));
  8877. let o = s.get(t);
  8878. o || (o = /* @__PURE__ */ new Map(), s.set(t, o)), this._onChanged$.next({
  8879. unitId: e,
  8880. subUnitId: t,
  8881. featureIds: [r]
  8882. }), o.set(r, n);
  8883. }
  8884. getReferenceExecutorMap() {
  8885. return this._referenceExecutorMap;
  8886. }
  8887. }
  8888. const jr = lt(
  8889. "univer.formula.feature-calculation-manager.service"
  8890. );
  8891. class Oh extends Me {
  8892. constructor() {
  8893. super(...arguments);
  8894. A(this, "_otherFormulaData", {});
  8895. }
  8896. dispose() {
  8897. this._otherFormulaData = {};
  8898. }
  8899. remove(e) {
  8900. var s, o, u;
  8901. const { unitId: t, subUnitId: r, formulaId: n } = e;
  8902. (u = (o = (s = this._otherFormulaData) == null ? void 0 : s[t]) == null ? void 0 : o[r]) == null || delete u[n];
  8903. }
  8904. get(e) {
  8905. var s, o;
  8906. const { unitId: t, subUnitId: r, formulaId: n } = e;
  8907. return (o = (s = this._otherFormulaData[t]) == null ? void 0 : s[r]) == null ? void 0 : o[n];
  8908. }
  8909. has(e) {
  8910. var s, o;
  8911. const { unitId: t, subUnitId: r, formulaId: n } = e;
  8912. return ((o = (s = this._otherFormulaData[t]) == null ? void 0 : s[r]) == null ? void 0 : o[n]) != null;
  8913. }
  8914. register(e) {
  8915. const { unitId: t, subUnitId: r, formulaId: n, item: s } = e;
  8916. this._otherFormulaData[t] || (this._otherFormulaData[t] = {}), this._otherFormulaData[t][r] || (this._otherFormulaData[t][r] = {}), this._otherFormulaData[t][r][n] = s;
  8917. }
  8918. batchRegister(e) {
  8919. Object.keys(e).forEach((t) => {
  8920. const r = e[t];
  8921. if (r == null)
  8922. return !0;
  8923. Object.keys(r).forEach((n) => {
  8924. const s = r[n];
  8925. if (s == null)
  8926. return !0;
  8927. Object.keys(s).forEach((o) => {
  8928. const u = s[o];
  8929. if (u == null)
  8930. return !0;
  8931. this.register({
  8932. unitId: t,
  8933. subUnitId: n,
  8934. formulaId: o,
  8935. item: u
  8936. });
  8937. });
  8938. });
  8939. });
  8940. }
  8941. batchRemove(e) {
  8942. Object.keys(e).forEach((t) => {
  8943. const r = e[t];
  8944. if (r == null)
  8945. return !0;
  8946. Object.keys(r).forEach((n) => {
  8947. const s = r[n];
  8948. if (s == null)
  8949. return !0;
  8950. Object.keys(s).forEach((o) => {
  8951. this.remove({
  8952. unitId: t,
  8953. subUnitId: n,
  8954. formulaId: o
  8955. });
  8956. });
  8957. });
  8958. });
  8959. }
  8960. getOtherFormulaData() {
  8961. return this._otherFormulaData;
  8962. }
  8963. }
  8964. const ya = lt(
  8965. "univer.formula.other-formula-manager.service"
  8966. ), Mh = 5e3, ks = new Vt(Mh);
  8967. function pi(i, a, e, t, r) {
  8968. let n = ks.get(`${i}${a}`);
  8969. if (n && !Oo(n, r))
  8970. return n;
  8971. const s = e.treeBuilder(a);
  8972. if (yr.has(s))
  8973. return xe.create(s);
  8974. if (n = t.parse(s), n == null)
  8975. throw new Error("astNode is null");
  8976. return ks.set(`${i}${a}`, n), n;
  8977. }
  8978. function Oo(i, a) {
  8979. const e = a.getDirtyDefinedNameMap(), t = a.getExecuteUnitId();
  8980. if (t != null && e[t] != null) {
  8981. const r = Object.keys(e[t]);
  8982. for (let n = 0, s = r.length; n < s; n++) {
  8983. const o = r[n];
  8984. if (i.hasDefinedName(o))
  8985. return !0;
  8986. }
  8987. }
  8988. return !1;
  8989. }
  8990. function wh(i, a, e) {
  8991. return !!(a != null && Oo(a, e));
  8992. }
  8993. var $s = /* @__PURE__ */ ((i) => (i[i.NORMAL_FORMULA = 0] = "NORMAL_FORMULA", i[i.OTHER_FORMULA = 1] = "OTHER_FORMULA", i[i.FEATURE_FORMULA = 2] = "FEATURE_FORMULA", i))($s || {});
  8994. class Mo {
  8995. constructor() {
  8996. A(this, "_state", 0);
  8997. A(this, "treeId");
  8998. A(this, "children", /* @__PURE__ */ new Set());
  8999. A(this, "parents", /* @__PURE__ */ new Set());
  9000. }
  9001. resetState() {
  9002. this._state = 0;
  9003. }
  9004. setAdded() {
  9005. this._state = 1;
  9006. }
  9007. isAdded() {
  9008. return this._state === 1;
  9009. }
  9010. setSkip() {
  9011. this._state = 2;
  9012. }
  9013. isSkip() {
  9014. return this._state === 2;
  9015. }
  9016. pushChildren(a) {
  9017. this.children.add(a.treeId), a._pushParent(this);
  9018. }
  9019. hasChildren(a) {
  9020. return this.children.has(a);
  9021. }
  9022. _pushParent(a) {
  9023. this.parents.add(a.treeId);
  9024. }
  9025. }
  9026. class Vi extends Mo {
  9027. constructor() {
  9028. super(...arguments);
  9029. A(this, "refTree");
  9030. A(this, "refOffsetX", -1);
  9031. A(this, "refOffsetY", -1);
  9032. A(this, "isCache", !1);
  9033. A(this, "isDirty", !1);
  9034. A(this, "addressFunctionNodes", []);
  9035. A(this, "getDirtyData");
  9036. A(this, "featureId");
  9037. }
  9038. get isVirtual() {
  9039. return !0;
  9040. }
  9041. get row() {
  9042. return this.refTree == null ? -1 : this.refTree.row + this.refOffsetY;
  9043. }
  9044. get column() {
  9045. return this.refTree == null ? -1 : this.refTree.column + this.refOffsetX;
  9046. }
  9047. get rowCount() {
  9048. return this.refTree == null ? 0 : this.refTree.rowCount;
  9049. }
  9050. get columnCount() {
  9051. return this.refTree == null ? 0 : this.refTree.columnCount;
  9052. }
  9053. get unitId() {
  9054. return this.refTree == null ? "" : this.refTree.unitId;
  9055. }
  9056. get subUnitId() {
  9057. return this.refTree == null ? "" : this.refTree.subUnitId;
  9058. }
  9059. get formula() {
  9060. var e, t;
  9061. return (t = (e = this.refTree) == null ? void 0 : e.formula) != null ? t : "";
  9062. }
  9063. get nodeData() {
  9064. return {
  9065. node: this.node,
  9066. refOffsetX: this.refOffsetX,
  9067. refOffsetY: this.refOffsetY
  9068. };
  9069. }
  9070. get node() {
  9071. var e;
  9072. return (e = this.refTree) == null ? void 0 : e.node;
  9073. }
  9074. dispose() {
  9075. this.refTree = null;
  9076. }
  9077. get rangeList() {
  9078. const e = [];
  9079. if (this.refTree == null)
  9080. return [];
  9081. for (let t = 0; t < this.refTree.rangeList.length; t++) {
  9082. const r = this.refTree.rangeList[t];
  9083. e.push({
  9084. unitId: r.unitId,
  9085. sheetId: r.sheetId,
  9086. range: ea(r.range, this.refOffsetX, this.refOffsetY)
  9087. });
  9088. }
  9089. return e;
  9090. }
  9091. toRTreeItem() {
  9092. const e = this.row, t = this.column;
  9093. return [{
  9094. unitId: this.unitId,
  9095. sheetId: this.subUnitId,
  9096. range: {
  9097. startRow: e,
  9098. startColumn: t,
  9099. endRow: e,
  9100. endColumn: t
  9101. }
  9102. }];
  9103. }
  9104. inRangeData(e) {
  9105. const t = e.startRow, r = e.startColumn, n = e.endRow, s = e.endColumn, o = this.row, u = this.column;
  9106. return !(o < t || o > n || u < r || u > s);
  9107. }
  9108. dependencySheetName(e) {
  9109. return this.refTree == null ? !1 : this.refTree.dependencySheetName(e);
  9110. }
  9111. isExcludeRange(e) {
  9112. var r;
  9113. const t = this.rangeList;
  9114. if (t.length === 0)
  9115. return !1;
  9116. for (let n = 0, s = t.length; n < s; n++) {
  9117. const o = t[n], { unitId: u, sheetId: c, range: l } = o, f = (r = e == null ? void 0 : e[u]) == null ? void 0 : r[c];
  9118. let { startRow: h, endRow: d, startColumn: _, endColumn: C } = l;
  9119. Number.isNaN(h) && (h = 0), Number.isNaN(_) && (_ = 0), Number.isNaN(d) && (d = Number.POSITIVE_INFINITY), Number.isNaN(C) && (C = Number.POSITIVE_INFINITY);
  9120. let E = !1;
  9121. if (f == null || f.forValue((b, R) => {
  9122. if (b >= h && b <= d && R >= _ && R <= C)
  9123. return E = !0, !1;
  9124. }), E)
  9125. return !0;
  9126. }
  9127. return !1;
  9128. }
  9129. get formulaId() {
  9130. return this.refTree == null ? "" : this.refTree.formulaId;
  9131. }
  9132. }
  9133. class hs extends Mo {
  9134. constructor(e) {
  9135. super();
  9136. A(this, "isCache", !1);
  9137. A(this, "featureId");
  9138. A(this, "featureDirtyRanges", []);
  9139. A(this, "refOffsetX", 0);
  9140. A(this, "refOffsetY", 0);
  9141. A(this, "type", 0);
  9142. A(this, "formulaId");
  9143. A(this, "subUnitId", "");
  9144. A(this, "unitId", "");
  9145. A(this, "rangeList", []);
  9146. A(this, "formula", "");
  9147. A(this, "row", -1);
  9148. A(this, "column", -1);
  9149. A(this, "rowCount", Number.NEGATIVE_INFINITY);
  9150. A(this, "columnCount", Number.NEGATIVE_INFINITY);
  9151. A(this, "isDirty", !1);
  9152. A(this, "node");
  9153. A(this, "addressFunctionNodes", []);
  9154. A(this, "getDirtyData");
  9155. this.treeId = e;
  9156. }
  9157. get isVirtual() {
  9158. return !1;
  9159. }
  9160. get nodeData() {
  9161. return {
  9162. node: this.node,
  9163. refOffsetX: 0,
  9164. refOffsetY: 0
  9165. };
  9166. }
  9167. toJson() {
  9168. return {
  9169. formula: this.formula,
  9170. refOffsetX: this.refOffsetX,
  9171. refOffsetY: this.refOffsetY
  9172. };
  9173. }
  9174. dispose() {
  9175. this.featureDirtyRanges = [], this.rangeList = [], this.addressFunctionNodes = [], this.getDirtyData = null;
  9176. }
  9177. inRangeData(e) {
  9178. const t = e.startRow, r = e.startColumn, n = e.endRow, s = e.endColumn, o = this.row, u = this.column;
  9179. return !(o < t || o > n || u < r || u > s);
  9180. }
  9181. dependencySheetName(e) {
  9182. var r;
  9183. const t = this.rangeList;
  9184. if (t.length === 0 || e == null)
  9185. return !1;
  9186. for (let n = 0, s = t.length; n < s; n++) {
  9187. const o = t[n], { unitId: u, sheetId: c } = o;
  9188. if (((r = e[u]) == null ? void 0 : r[c]) != null)
  9189. return !0;
  9190. }
  9191. return !1;
  9192. }
  9193. isExcludeRange(e) {
  9194. var r;
  9195. const t = this.rangeList;
  9196. if (t.length === 0)
  9197. return !1;
  9198. for (let n = 0, s = t.length; n < s; n++) {
  9199. const o = t[n], { unitId: u, sheetId: c, range: l } = o, f = (r = e == null ? void 0 : e[u]) == null ? void 0 : r[c];
  9200. let { startRow: h, endRow: d, startColumn: _, endColumn: C } = l;
  9201. Number.isNaN(h) && (h = 0), Number.isNaN(_) && (_ = 0), Number.isNaN(d) && (d = Number.POSITIVE_INFINITY), Number.isNaN(C) && (C = Number.POSITIVE_INFINITY);
  9202. let E = !1;
  9203. if (f == null || f.forValue((b, R) => {
  9204. if (b >= h && b <= d && R >= _ && R <= C)
  9205. return E = !0, !1;
  9206. }), E)
  9207. return !0;
  9208. }
  9209. return !1;
  9210. }
  9211. // pushChildren(tree: FormulaDependencyTree) {
  9212. // this.children.add(tree.treeId);
  9213. // tree._pushParent(this);
  9214. // }
  9215. /**
  9216. * Add the range corresponding to the current ast node.
  9217. * @param range
  9218. */
  9219. pushRangeList(e) {
  9220. this.rangeList.push(...e);
  9221. }
  9222. shouldBePushRangeList() {
  9223. return this.rangeList.length === 0 && this.type !== 2;
  9224. }
  9225. // hasChildren(treeId: number) {
  9226. // return this.children.has(treeId);
  9227. // }
  9228. toRTreeItem() {
  9229. if (this.featureId != null)
  9230. return this.featureDirtyRanges;
  9231. const e = this.row, t = this.column;
  9232. return [{
  9233. unitId: this.unitId,
  9234. sheetId: this.subUnitId,
  9235. range: {
  9236. startRow: e,
  9237. startColumn: t,
  9238. endRow: e,
  9239. endColumn: t
  9240. }
  9241. }];
  9242. }
  9243. /**
  9244. * Determine whether it is dependent on other trees.
  9245. * @param dependenceTree
  9246. */
  9247. // dependency(dependenceTree: FormulaDependencyTree) {
  9248. // if (this.rangeList.length === 0) {
  9249. // return false;
  9250. // }
  9251. // for (let r = 0, len = this.rangeList.length; r < len; r++) {
  9252. // const unitRange = this.rangeList[r];
  9253. // const unitId = unitRange.unitId;
  9254. // const sheetId = unitRange.sheetId;
  9255. // const range = unitRange.range;
  9256. // if (
  9257. // dependenceTree.unitId === unitId &&
  9258. // dependenceTree.subUnitId === sheetId &&
  9259. // dependenceTree.inRangeData(range)
  9260. // ) {
  9261. // return true;
  9262. // }
  9263. // }
  9264. // return false;
  9265. // }
  9266. // private _pushParent(tree: FormulaDependencyTree) {
  9267. // this.parents.add(tree.treeId);
  9268. // }
  9269. }
  9270. var Dh = Object.defineProperty, Sh = Object.getOwnPropertyDescriptor, Ph = (i, a, e, t) => {
  9271. for (var r = t > 1 ? void 0 : t ? Sh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  9272. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  9273. return t && r && Dh(a, e, r), r;
  9274. }, wt = (i, a) => (e, t) => a(e, t, i);
  9275. function or(i) {
  9276. return i.getLastTreeId() || 0;
  9277. }
  9278. const Ys = lt("engine-formula.dependency-generator");
  9279. let Hs = class extends Me {
  9280. constructor(a, e, t, r, n, s, o, u) {
  9281. super();
  9282. A(this, "_updateRangeFlattenCache", /* @__PURE__ */ new Map());
  9283. A(this, "_dependencyRTreeCacheForAddressFunction", new As());
  9284. A(this, "_executedAddressFunctionNodeIds", /* @__PURE__ */ new Set());
  9285. this._currentConfigService = a, this._runtimeService = e, this._otherFormulaManagerService = t, this._featureCalculationManagerService = r, this._interpreter = n, this._astTreeBuilder = s, this._lexer = o, this._dependencyManagerService = u;
  9286. }
  9287. dispose() {
  9288. this._updateRangeFlattenCache.clear(), this._dependencyRTreeCacheForAddressFunction.clear(), ks.clear();
  9289. }
  9290. async generate() {
  9291. this._updateRangeFlatten();
  9292. const a = this._currentConfigService.getFormulaData(), e = this._otherFormulaManagerService.getOtherFormulaData(), t = this._currentConfigService.getClearDependencyTreeCache();
  9293. t != null && Object.keys(t).forEach((l) => {
  9294. l != null && Object.keys(t[l]).forEach((f) => {
  9295. f != null && (this._dependencyManagerService.clearOtherFormulaDependency(l, f), this._dependencyManagerService.clearFeatureFormulaDependency(l, f), this._dependencyManagerService.clearFormulaDependency(l, f));
  9296. });
  9297. });
  9298. const r = this._currentConfigService.getUnitData(), n = await this._generateTreeList(a, e, r), s = this._getUpdateTreeListAndMakeDependency(n);
  9299. let o = this._calculateRunList(s);
  9300. return this._dependencyFeatureCalculation(o) && (o.forEach((l) => {
  9301. l.resetState();
  9302. }), o = this._calculateRunList(o)), this._checkIsCycleDependency(o) && this._runtimeService.enableCycleDependency(), this._dependencyRTreeCacheForAddressFunction.clear(), Promise.resolve(o);
  9303. }
  9304. _dependencyFeatureCalculation(a) {
  9305. const e = this._featureCalculationManagerService.getReferenceExecutorMap();
  9306. if (e.size === 0)
  9307. return;
  9308. this._clearFeatureCalculationNode(a);
  9309. let t = !1;
  9310. return e.forEach((r, n) => {
  9311. r.forEach((s, o) => {
  9312. s.forEach((u, c) => {
  9313. const { unitId: l, subUnitId: f, getDirtyData: h } = u, d = h(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData()), _ = this._convertDirtyRangesToUnitRange(d.dirtyRanges), C = this._intersectFeatureCalculation(_, a, { unitId: l, subUnitId: f, featureId: c });
  9314. if (C.length > 0) {
  9315. let E = this._getExistTreeList({ unitId: l, subUnitId: f, featureId: c }, a);
  9316. E == null && (E = this._getFeatureFormulaTree(c, or(this._dependencyManagerService), u), a.push(E)), E.parents = /* @__PURE__ */ new Set(), C.forEach((b) => {
  9317. b.hasChildren(E.treeId) || b.pushChildren(E);
  9318. }), t = !0;
  9319. }
  9320. });
  9321. });
  9322. }), t;
  9323. }
  9324. _clearFeatureCalculationNode(a) {
  9325. const e = this._featureCalculationManagerService.getReferenceExecutorMap();
  9326. a.forEach((t) => {
  9327. var s, o, u, c;
  9328. const r = /* @__PURE__ */ new Set();
  9329. for (const l of t.children) {
  9330. const f = this._dependencyManagerService.getTreeById(l);
  9331. f && (f.featureId && (o = (s = e.get(t.unitId)) == null ? void 0 : s.get(t.subUnitId)) != null && o.has(f.featureId) || r.add(l));
  9332. }
  9333. t.children = r;
  9334. const n = /* @__PURE__ */ new Set();
  9335. for (const l of t.parents) {
  9336. const f = this._dependencyManagerService.getTreeById(l);
  9337. f && (f.featureId && (c = (u = e.get(t.unitId)) == null ? void 0 : u.get(t.subUnitId)) != null && c.has(f.featureId) || n.add(l));
  9338. }
  9339. t.parents = n;
  9340. });
  9341. }
  9342. /**
  9343. * TODO @DR-Univer: The next step will be to try changing the incoming dirtyRanges to an array, thus avoiding conversion.
  9344. * @param dirtyRanges
  9345. * @returns
  9346. */
  9347. _convertDirtyRangesToUnitRange(a) {
  9348. const e = [];
  9349. for (const t in a) {
  9350. const r = a[t];
  9351. for (const n in r) {
  9352. const s = r[n];
  9353. for (const o of s)
  9354. e.push({
  9355. unitId: t,
  9356. sheetId: n,
  9357. range: o
  9358. });
  9359. }
  9360. }
  9361. return e;
  9362. }
  9363. _intersectFeatureCalculation(a, e, t) {
  9364. const r = [], n = this._dependencyManagerService.searchDependency(a);
  9365. for (let s = 0, o = e.length; s < o; s++) {
  9366. const u = e[s];
  9367. if (u.unitId === t.unitId && u.subUnitId === t.subUnitId && u.featureId === t.featureId)
  9368. continue;
  9369. n.has(u.treeId) && r.push(u);
  9370. }
  9371. return r;
  9372. }
  9373. _getExistTreeList(a, e) {
  9374. const { unitId: t, subUnitId: r, featureId: n } = a;
  9375. for (let s = 0, o = e.length; s < o; s++) {
  9376. const u = e[s];
  9377. if (u.unitId === t && u.subUnitId === r && u.featureId === n)
  9378. return u;
  9379. }
  9380. }
  9381. _isCyclicUtil(a, e, t) {
  9382. const r = this._dependencyManagerService.getTreeById(a);
  9383. if (r == null)
  9384. return !1;
  9385. if (!e.has(r.treeId)) {
  9386. e.add(r.treeId), t.add(r.treeId);
  9387. for (const n of r.children)
  9388. if (!e.has(n) && this._isCyclicUtil(n, e, t) || t.has(n))
  9389. return !0;
  9390. }
  9391. return t.delete(r.treeId), !1;
  9392. }
  9393. _checkIsCycleDependency(a) {
  9394. const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
  9395. for (let r = 0, n = a.length; r < n; r++) {
  9396. const s = a[r];
  9397. if (this._isCyclicUtil(s.treeId, e, t) === !0)
  9398. return !0;
  9399. }
  9400. return !1;
  9401. }
  9402. /**
  9403. * Generate nodes for the dependency tree, where each node contains all the reference data ranges included in each formula.
  9404. * @param formulaData
  9405. */
  9406. async _generateTreeList(a, e, t) {
  9407. const r = Object.keys(a), n = Object.keys(e), s = [];
  9408. this._currentConfigService.isForceCalculate() && this._dependencyManagerService.reset(), this._registerFormulas(r, a, t, s), this._registerOtherFormulas(e, n, s), this._registerFeatureFormulas(s);
  9409. for (let u = 0, c = s.length; u < c; u++) {
  9410. const l = s[u], f = this._getTreeNode(l);
  9411. l.isDirty = this._includeTree(l, f);
  9412. const h = this._getAddressFunctionNodeList(f);
  9413. if (h.length > 0 && (l.addressFunctionNodes = h), l.isVirtual)
  9414. continue;
  9415. this._runtimeService.setCurrent(
  9416. l.row,
  9417. l.column,
  9418. l.rowCount,
  9419. l.columnCount,
  9420. l.subUnitId,
  9421. l.unitId
  9422. );
  9423. const d = await this._getRangeListByNode({
  9424. node: f,
  9425. refOffsetX: l.refOffsetX,
  9426. refOffsetY: l.refOffsetY
  9427. });
  9428. l.pushRangeList(d);
  9429. }
  9430. for (let u = 0, c = s.length; u < c; u++) {
  9431. const l = s[u];
  9432. l.isCache || this._dependencyManagerService.addDependencyRTreeCache(l);
  9433. }
  9434. return await this._calculateListByFunctionRefNode(s), s;
  9435. }
  9436. // private _moveRangeList(tree: FormulaDependencyTree, refOffsetX: number, refOffsetY: number) {
  9437. // const rangeList = tree.rangeList;
  9438. // const newRangeList = [];
  9439. // for (let i = 0, len = rangeList.length; i < len; i++) {
  9440. // const unitRange = rangeList[i];
  9441. // const newRange = {
  9442. // unitId: tree.unitId,
  9443. // sheetId: tree.subUnitId,
  9444. // range: moveRangeByOffset(unitRange.range, refOffsetX, refOffsetY),
  9445. // };
  9446. // newRangeList.push(newRange);
  9447. // }
  9448. // return newRangeList;
  9449. // }
  9450. _registerFeatureFormulas(a) {
  9451. this._featureCalculationManagerService.getReferenceExecutorMap().forEach((t, r) => {
  9452. t.forEach((n, s) => {
  9453. n.forEach((o, u) => {
  9454. const c = this._dependencyManagerService.getFeatureFormulaDependency(o.unitId, o.subUnitId, u);
  9455. a.push(this._getFeatureFormulaTree(u, c, o));
  9456. });
  9457. });
  9458. });
  9459. }
  9460. _getFeatureFormulaTree(a, e, t) {
  9461. const { unitId: r, subUnitId: n, dependencyRanges: s, getDirtyData: o } = t, u = e || or(this._dependencyManagerService), c = new hs(u);
  9462. c.unitId = r, c.subUnitId = n, c.rangeList = s, c.getDirtyData = o;
  9463. const l = o(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData()), f = this._convertDirtyRangesToUnitRange(l.dirtyRanges);
  9464. return c.featureDirtyRanges = f, c.featureId = a, c.type = $s.FEATURE_FORMULA, this._dependencyManagerService.addFeatureFormulaDependency(r, n, a, c), this._dependencyManagerService.getFeatureFormulaDependency(t.unitId, t.subUnitId, a) && (c.isCache = !0), c;
  9465. }
  9466. _registerOtherFormulas(a, e, t) {
  9467. for (const r of e) {
  9468. const n = a[r];
  9469. if (n == null)
  9470. continue;
  9471. const s = Object.keys(n);
  9472. for (const o of s) {
  9473. const u = n[o];
  9474. if (u == null)
  9475. continue;
  9476. const c = Object.keys(u);
  9477. for (const l of c) {
  9478. const f = this._dependencyManagerService.hasOtherFormulaDataMainData(l), h = u[l], { f: d, ranges: _ } = h;
  9479. let C = !1;
  9480. f && (C = !0);
  9481. const E = pi(r, d, this._lexer, this._astTreeBuilder, this._currentConfigService), { firstRow: b, firstColumn: R } = this._getFirstCellOfRange(_), p = this._dependencyManagerService.getOtherFormulaDependency(r, o, l), N = (p == null ? void 0 : p.getValue(0, 0)) || or(this._dependencyManagerService), M = new hs(N);
  9482. for (let w = 0; w < _.length; w++) {
  9483. const D = _[w], { startRow: S, startColumn: P, endRow: U, endColumn: x } = D;
  9484. for (let F = S; F <= U; F++)
  9485. for (let W = P; W <= x; W++) {
  9486. const ne = W - R, z = F - b;
  9487. if (ne === 0 && z === 0) {
  9488. M.node = E, M.formula = d, M.unitId = r, M.subUnitId = o, M.formulaId = l, M.type = $s.OTHER_FORMULA, M.isCache = C, t.push(M), this._dependencyManagerService.addOtherFormulaDependency(r, o, l, M), this._dependencyManagerService.addFormulaDependencyByDefinedName(M);
  9489. continue;
  9490. }
  9491. const G = new Vi();
  9492. G.treeId = (p == null ? void 0 : p.getValue(ne, z)) || or(this._dependencyManagerService), G.refTree = M, G.refOffsetX = ne, G.refOffsetY = z, G.isCache = C, this._dependencyManagerService.addOtherFormulaDependency(r, o, l, G), this._dependencyManagerService.addFormulaDependencyByDefinedName(G), t.push(G);
  9493. }
  9494. }
  9495. this._dependencyManagerService.addOtherFormulaDependencyMainData(l);
  9496. }
  9497. }
  9498. }
  9499. }
  9500. _getFirstCellOfRange(a) {
  9501. const e = a[0];
  9502. return {
  9503. firstRow: e.startRow,
  9504. firstColumn: e.startColumn
  9505. };
  9506. }
  9507. _registerFormulas(a, e, t, r) {
  9508. for (const n of a) {
  9509. const s = e[n];
  9510. if (s == null)
  9511. continue;
  9512. const o = Object.keys(s);
  9513. for (const u of o) {
  9514. const c = new Ce(s[u] || {}), l = /* @__PURE__ */ new Map();
  9515. c.forValue((f, h, d) => {
  9516. if (d == null)
  9517. return !0;
  9518. const { x: _ = 0, y: C = 0, si: E } = d;
  9519. if (!(_ === 0 && C === 0 && E != null))
  9520. return !0;
  9521. const b = this._createFDtree(n, u, f, h, t, d), R = this._dependencyManagerService.getFormulaDependency(n, u, f, h);
  9522. R != null ? b.treeId = R : (this._dependencyManagerService.addFormulaDependency(n, u, f, h, b), this._dependencyManagerService.addFormulaDependencyByDefinedName(b)), l.set(E, b), r.push(b);
  9523. }), c.forValue((f, h, d) => {
  9524. if (d == null)
  9525. return !0;
  9526. const { x: _ = 0, y: C = 0, si: E } = d;
  9527. if (_ === 0 && C === 0 && E != null)
  9528. return !0;
  9529. let b;
  9530. if (E && l.has(E)) {
  9531. const p = l.get(E);
  9532. b = this._createVirtualFDtree(p, d);
  9533. } else
  9534. b = this._createFDtree(n, u, f, h, t, d);
  9535. const R = this._dependencyManagerService.getFormulaDependency(n, u, f, h);
  9536. R != null ? b.treeId = R : (this._dependencyManagerService.addFormulaDependency(n, u, f, h, b), this._dependencyManagerService.addFormulaDependencyByDefinedName(b)), r.push(b);
  9537. }), l.clear();
  9538. }
  9539. }
  9540. }
  9541. _createFDtree(a, e, t, r, n, s) {
  9542. const { f: o, x: u = 0, y: c = 0 } = s, l = new hs(or(this._dependencyManagerService)), f = n[a][e], h = pi(a, o, this._lexer, this._astTreeBuilder, this._currentConfigService);
  9543. return l.node = h, l.formula = o, l.unitId = a, l.subUnitId = e, l.row = t, l.column = r, l.rowCount = f.rowCount, l.columnCount = f.columnCount, l;
  9544. }
  9545. _createVirtualFDtree(a, e) {
  9546. const { x: t = 0, y: r = 0 } = e, n = new Vi();
  9547. return n.treeId = or(this._dependencyManagerService), n.refTree = a, n.refOffsetX = t, n.refOffsetY = r, n;
  9548. }
  9549. /**
  9550. * Break down the dirty areas into ranges for subsequent matching.
  9551. */
  9552. _updateRangeFlatten() {
  9553. const a = this._currentConfigService.isForceCalculate(), e = this._currentConfigService.getDirtyRanges();
  9554. if (!a) {
  9555. this._updateRangeFlattenCache.clear();
  9556. for (let t = 0; t < e.length; t++) {
  9557. const r = e[t], n = r.range, s = r.sheetId, o = r.unitId;
  9558. this._addFlattenCache(o, s, n);
  9559. }
  9560. }
  9561. }
  9562. _addFlattenCache(a, e, t) {
  9563. let r = this._updateRangeFlattenCache.get(a);
  9564. r == null && (r = /* @__PURE__ */ new Map(), this._updateRangeFlattenCache.set(a, r));
  9565. let n = r.get(e);
  9566. n == null && (n = [], r.set(e, n)), n.push(t);
  9567. }
  9568. _isPreCalculateNode(a) {
  9569. return a.nodeType === oe.UNION || a.nodeType === oe.PREFIX && a.getToken() === Oe.AT || a.nodeType === oe.SUFFIX && a.getToken() === ze.POUND;
  9570. }
  9571. _nodeTraversalRef(a, e) {
  9572. const t = a.getChildren(), r = t.length;
  9573. for (let n = 0; n < r; n++) {
  9574. const s = t[n];
  9575. if (this._isPreCalculateNode(s)) {
  9576. if (e.push(s), s.nodeType === oe.UNION)
  9577. for (const o of s.getChildren())
  9578. o.nodeType === oe.FUNCTION && o.isAddress() && this._nodeTraversalRef(o, e);
  9579. continue;
  9580. } else s.nodeType === oe.REFERENCE && e.push(s);
  9581. this._nodeTraversalRef(s, e);
  9582. }
  9583. }
  9584. _nodeTraversalReferenceFunction(a, e) {
  9585. const t = a.getChildren(), r = t.length;
  9586. for (let n = 0; n < r; n++) {
  9587. const s = t[n];
  9588. if (s.nodeType === oe.FUNCTION && s.isAddress()) {
  9589. e.push(s);
  9590. continue;
  9591. }
  9592. this._nodeTraversalReferenceFunction(s, e);
  9593. }
  9594. }
  9595. async _executeNode(a, e = 0, t = 0) {
  9596. let r;
  9597. const n = {
  9598. node: a,
  9599. refOffsetX: e,
  9600. refOffsetY: t
  9601. };
  9602. return this._interpreter.checkAsyncNode(a) ? r = await this._interpreter.executeAsync(n) : r = this._interpreter.execute(n), r;
  9603. }
  9604. /**
  9605. * Calculate the range required for collection in advance,
  9606. * including references and location functions (such as OFFSET, INDIRECT, INDEX, etc.).
  9607. * @param node
  9608. */
  9609. async _getRangeListByNode(a) {
  9610. const e = [], t = a.refOffsetX, r = a.refOffsetY, n = a.node;
  9611. if (n == null)
  9612. return [];
  9613. this._nodeTraversalRef(n, e);
  9614. const s = [];
  9615. for (let o = 0, u = e.length; o < u; o++) {
  9616. const c = e[o], f = (await this._executeNode(c, t, r)).toUnitRange();
  9617. s.push(f), c.setValue(null);
  9618. }
  9619. return s;
  9620. }
  9621. _getAddressFunctionNodeList(a) {
  9622. const e = [];
  9623. return a == null ? [] : (this._nodeTraversalReferenceFunction(a, e), e);
  9624. }
  9625. _getTreeNode(a) {
  9626. return a.node;
  9627. }
  9628. async _buildDirtyRangesByAddressFunction(a, e) {
  9629. const t = e.addressFunctionNodes;
  9630. if (t.length === 0)
  9631. return;
  9632. const r = e.refOffsetX, n = e.refOffsetY, s = await this._getRangeListByFunctionRefNode(t, r, n);
  9633. e.addressFunctionNodes = [], this._addDependencyTreeByAddressFunction(e, s);
  9634. const o = a.bulkSearch(s), u = this._buildTreeNodeById(o);
  9635. u.length !== 0 && await this._calculateAddressFunctionRuntimeData(a, u);
  9636. }
  9637. async _calculateListByFunctionRefNode(a) {
  9638. const e = new As();
  9639. for (let t = 0, r = a.length; t < r; t++) {
  9640. const n = a[t];
  9641. e.insert({
  9642. unitId: n.unitId,
  9643. sheetId: n.subUnitId,
  9644. range: {
  9645. startRow: n.row,
  9646. startColumn: n.column,
  9647. endRow: n.row,
  9648. endColumn: n.column
  9649. },
  9650. id: n.treeId
  9651. });
  9652. }
  9653. this._executedAddressFunctionNodeIds.clear();
  9654. for (let t = 0, r = a.length; t < r; t++) {
  9655. const n = a[t];
  9656. await this._calculateAddressFunction(e, n);
  9657. }
  9658. }
  9659. async _calculateAddressFunction(a, e) {
  9660. const t = e.addressFunctionNodes;
  9661. if (t.length === 0)
  9662. return;
  9663. const r = e.refOffsetX, n = e.refOffsetY;
  9664. this._runtimeService.setCurrent(
  9665. e.row,
  9666. e.column,
  9667. e.rowCount,
  9668. e.columnCount,
  9669. e.subUnitId,
  9670. e.unitId
  9671. );
  9672. const s = [];
  9673. for (let c = 0, l = t.length; c < l; c++) {
  9674. const f = await this._getRangeListByNode({
  9675. node: t[c],
  9676. refOffsetX: r,
  9677. refOffsetY: n
  9678. });
  9679. s.push(...f);
  9680. }
  9681. const o = /* @__PURE__ */ new Set();
  9682. this._searchDependencyByAddressFunction(a, s, o);
  9683. const u = this._buildTreeNodeById(o);
  9684. if (u.length === 0) {
  9685. await this._buildDirtyRangesByAddressFunction(a, e);
  9686. return;
  9687. }
  9688. await this._calculateAddressFunctionRuntimeData(a, u), await this._buildDirtyRangesByAddressFunction(a, e);
  9689. }
  9690. async _calculateAddressFunctionRuntimeData(a, e) {
  9691. for (; e.length > 0; ) {
  9692. const t = e.pop(), n = {
  9693. node: this._getTreeNode(t),
  9694. refOffsetX: t.refOffsetX,
  9695. refOffsetY: t.refOffsetY
  9696. };
  9697. await this._calculateAddressFunction(a, t), this._runtimeService.setCurrent(
  9698. t.row,
  9699. t.column,
  9700. t.rowCount,
  9701. t.columnCount,
  9702. t.subUnitId,
  9703. t.unitId
  9704. );
  9705. let s;
  9706. this._interpreter.checkAsyncNode(n.node) ? s = await this._interpreter.executeAsync(n) : s = this._interpreter.execute(n), t.formulaId != null ? this._runtimeService.setRuntimeOtherData(t.formulaId, t.refOffsetX, t.refOffsetY, s) : this._runtimeService.setRuntimeData(s);
  9707. }
  9708. }
  9709. _buildTreeNodeById(a) {
  9710. const e = [];
  9711. for (const t of a) {
  9712. const r = this._getTreeById(t);
  9713. !r || this._executedAddressFunctionNodeIds.has(t) || (this._executedAddressFunctionNodeIds.add(t), e.push(r));
  9714. }
  9715. return e;
  9716. }
  9717. _searchDependencyByAddressFunction(a, e, t) {
  9718. const r = a.bulkSearch(e), n = this._dependencyRTreeCacheForAddressFunction.bulkSearch(e);
  9719. for (const o of n)
  9720. t.has(o) || t.add(o);
  9721. const s = [];
  9722. for (const o of r) {
  9723. const u = this._getTreeById(o);
  9724. u && !t.has(o) && (s.push(...u.rangeList), t.add(o));
  9725. }
  9726. return s.length > 0 && this._searchDependencyByAddressFunction(a, s, t), t;
  9727. }
  9728. _getTreeById(a) {
  9729. return this._dependencyManagerService.getTreeById(a);
  9730. }
  9731. _addDependencyTreeByAddressFunction(a, e) {
  9732. const t = [];
  9733. for (let r = 0; r < e.length; r++) {
  9734. const n = e[r], { unitId: s, sheetId: o, range: u } = n;
  9735. t.push({
  9736. unitId: s,
  9737. sheetId: o,
  9738. range: u,
  9739. id: a.treeId
  9740. });
  9741. }
  9742. this._dependencyRTreeCacheForAddressFunction.bulkInsert(t);
  9743. }
  9744. /**
  9745. * Calculate the range required for collection in advance,
  9746. * including references and location functions (such as OFFSET, INDIRECT, INDEX, etc.).
  9747. * @param node
  9748. */
  9749. async _getRangeListByFunctionRefNode(a, e, t) {
  9750. const r = [];
  9751. for (let n = 0, s = a.length; n < s; n++) {
  9752. const o = a[n], c = (await this._executeNode(o, e, t)).toUnitRange();
  9753. r.push(c), o.setValue(null);
  9754. }
  9755. return r;
  9756. }
  9757. /**
  9758. * Build a formula dependency tree based on the dependency relationships.
  9759. * @param treeList
  9760. */
  9761. _getUpdateTreeListAndMakeDependency(a) {
  9762. const e = [], t = /* @__PURE__ */ new Set(), r = this._currentConfigService.isForceCalculate(), n = this._currentConfigService.getDirtyRanges(), s = this._dependencyManagerService.searchDependency(n), o = this._dependencyRTreeCacheForAddressFunction.bulkSearch(n);
  9763. for (const c of o)
  9764. s.add(c);
  9765. const u = this._dependencyManagerService.buildDependencyTree(a);
  9766. for (const c of u) {
  9767. const l = c.treeId;
  9768. (r || c.isDirty || c.dependencySheetName(this._currentConfigService.getDirtyNameMap()) || //O(n) n=tree.rangeList.length
  9769. s.has(l) && !c.isExcludeRange(this._currentConfigService.getExcludedRange())) && !t.has(l) && (e.push(c), t.add(l));
  9770. }
  9771. return e;
  9772. }
  9773. _includeTreeFeature(a) {
  9774. var n, s;
  9775. const e = a.unitId, t = a.subUnitId, r = a.featureId;
  9776. if (r != null) {
  9777. const o = this._currentConfigService.getDirtyUnitFeatureMap();
  9778. if (((s = (n = o == null ? void 0 : o[e]) == null ? void 0 : n[t]) == null ? void 0 : s[r]) != null)
  9779. return !0;
  9780. }
  9781. return !1;
  9782. }
  9783. _includeOtherFormula(a) {
  9784. var n, s;
  9785. const e = a.unitId, t = a.subUnitId, r = a.formulaId;
  9786. if (r != null) {
  9787. const o = this._currentConfigService.getDirtyUnitOtherFormulaMap();
  9788. if (((s = (n = o == null ? void 0 : o[e]) == null ? void 0 : n[t]) == null ? void 0 : s[r]) != null)
  9789. return !0;
  9790. }
  9791. return !1;
  9792. }
  9793. _detectForcedRecalculationNode(a, e) {
  9794. return e == null ? !1 : this._detectForcedRecalculationNodeRecursion(e);
  9795. }
  9796. _detectForcedRecalculationNodeRecursion(a) {
  9797. if (a.isForcedCalculateFunction())
  9798. return !0;
  9799. const e = a.getChildren();
  9800. for (let t = 0, r = e.length; t < r; t++) {
  9801. const n = e[t];
  9802. if (this._detectForcedRecalculationNodeRecursion(n))
  9803. return !0;
  9804. }
  9805. return !1;
  9806. }
  9807. /**
  9808. * Determine whether all ranges of the current node exist within the dirty area.
  9809. * If they are within the dirty area, return true, indicating that this node needs to be calculated.
  9810. * @param tree
  9811. */
  9812. _includeTree(a, e) {
  9813. var c, l, f;
  9814. const t = a.unitId, r = a.subUnitId;
  9815. if (this._detectForcedRecalculationNode(a, e) === !0 || this._includeTreeFeature(a) === !0 || this._includeOtherFormula(a) === !0 || wh(a, e, this._currentConfigService) === !0)
  9816. return !0;
  9817. const n = (l = (c = this._currentConfigService.getExcludedRange()) == null ? void 0 : c[t]) == null ? void 0 : l[r];
  9818. if ((n == null ? void 0 : n.getValue(a.row, a.column)) != null)
  9819. return !1;
  9820. if (((f = this._currentConfigService.getDirtyNameMap()[t]) == null ? void 0 : f[r]) != null)
  9821. return !0;
  9822. if (!this._updateRangeFlattenCache.has(t))
  9823. return !1;
  9824. const o = this._updateRangeFlattenCache.get(t);
  9825. if (!o.has(r))
  9826. return !1;
  9827. const u = o.get(r);
  9828. for (const h of u)
  9829. if (a.inRangeData(h))
  9830. return !0;
  9831. return !1;
  9832. }
  9833. /**
  9834. * Generate the final formula calculation order array by traversing the dependency tree established via depth-first search.
  9835. * @param treeList
  9836. */
  9837. _calculateRunList(a) {
  9838. const e = a, t = [], r = [];
  9839. for (; e.length > 0; ) {
  9840. const n = e.pop();
  9841. if (n === void 0 || n.isSkip())
  9842. continue;
  9843. if (n.isAdded()) {
  9844. t.push(n), n.setSkip();
  9845. continue;
  9846. }
  9847. r.length = 0;
  9848. for (const o of n.parents) {
  9849. const u = this._dependencyManagerService.getTreeById(o);
  9850. if (!u)
  9851. throw new Error("ParentDependencyTree object is null");
  9852. u.isAdded() || n.isSkip() || r.push(u);
  9853. }
  9854. const s = this._dependencyRTreeCacheForAddressFunction.bulkSearch(n.toRTreeItem());
  9855. for (const o of s) {
  9856. const u = this._dependencyManagerService.getTreeById(o);
  9857. if (!u)
  9858. throw new Error("ParentDependencyTree object is null");
  9859. u.isAdded() || n.isSkip() || r.push(u);
  9860. }
  9861. r.length === 0 ? (t.push(n), n.setSkip()) : (n.setAdded(), e.push(n, ...r));
  9862. }
  9863. return t;
  9864. }
  9865. };
  9866. Hs = Ph([
  9867. wt(0, Ft),
  9868. wt(1, Nt),
  9869. wt(2, ya),
  9870. wt(3, jr),
  9871. wt(4, Ve(Cr)),
  9872. wt(5, Ve(xr)),
  9873. wt(6, Ve(gr)),
  9874. wt(7, Hn)
  9875. ], Hs);
  9876. var Lh = Object.defineProperty, xh = Object.getOwnPropertyDescriptor, jh = (i, a, e, t) => {
  9877. for (var r = t > 1 ? void 0 : t ? xh(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  9878. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  9879. return t && r && Lh(a, e, r), r;
  9880. }, Qt = (i, a) => (e, t) => a(e, t, i);
  9881. const Uh = 500, Gs = lt("engine-formula.calculate-formula.service");
  9882. let Qs = class extends Me {
  9883. constructor(a, e, t, r, n, s, o) {
  9884. super();
  9885. A(this, "_executionInProgressListener$", new ur());
  9886. A(this, "executionInProgressListener$", this._executionInProgressListener$.asObservable());
  9887. A(this, "_executionCompleteListener$", new ur());
  9888. A(this, "executionCompleteListener$", this._executionCompleteListener$.asObservable());
  9889. this._configService = a, this._lexer = e, this._currentConfigService = t, this._runtimeService = r, this._formulaDependencyGenerator = n, this._interpreter = s, this._astTreeBuilder = o;
  9890. }
  9891. /**
  9892. * Stop the execution of the formula.
  9893. */
  9894. stopFormulaExecution() {
  9895. this._runtimeService.stopExecution();
  9896. }
  9897. /**
  9898. * When the feature is loading,
  9899. * the pre-calculated content needs to be input to the formula engine in advance,
  9900. * so that the formula can read the correct values.
  9901. * @param featureId
  9902. * @param featureData
  9903. */
  9904. setRuntimeFeatureCellData(a, e) {
  9905. this._runtimeService.setRuntimeFeatureCellData(a, e);
  9906. }
  9907. setRuntimeFeatureRange(a, e) {
  9908. this._runtimeService.setRuntimeFeatureRange(a, e);
  9909. }
  9910. async execute(a) {
  9911. this._runtimeService.setFormulaExecuteStage(ft.START), this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()), this._currentConfigService.load(a), this._runtimeService.reset();
  9912. const e = a.maxIteration || so;
  9913. for (let t = 0; t < e && (this._runtimeService.setFormulaCycleIndex(t), await this._execute(), Bs.clear(), !!this._runtimeService.isCycleDependency()); t++)
  9914. ;
  9915. this._runtimeService.setFormulaExecuteStage(ft.CALCULATION_COMPLETED), this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()), this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()), St.clear(), this._runtimeService.reset();
  9916. }
  9917. async _execute() {
  9918. const a = await this._apply();
  9919. if (a == null)
  9920. return;
  9921. const { arrayFormulaRange: e, runtimeFeatureRange: t } = a, { dirtyRanges: r, excludedCell: n } = this._getArrayFormulaDirtyRangeAndExcludedRange(
  9922. e,
  9923. t
  9924. );
  9925. return r == null || r.length === 0 || (this._currentConfigService.loadDirtyRangesAndExcludedCell(r, n), await this._apply(!0)), !0;
  9926. }
  9927. _getArrayFormulaDirtyRangeAndExcludedRange(a, e) {
  9928. const t = [], r = {};
  9929. return Object.keys(a).forEach((n) => {
  9930. const s = a[n];
  9931. if (s == null)
  9932. return !0;
  9933. Object.keys(s).forEach((o) => {
  9934. const u = new Ce(s[o]);
  9935. if (u == null)
  9936. return !0;
  9937. const c = new Ce();
  9938. u.forValue((l, f, h) => {
  9939. c.setValue(l, f, !0), t.push({ unitId: n, sheetId: o, range: h });
  9940. }), r[n] == null && (r[n] = {}), r[n][o] = c;
  9941. });
  9942. }), Object.keys(e).forEach((n) => {
  9943. const s = e[n];
  9944. Object.keys(s).forEach((o) => {
  9945. const u = s[o];
  9946. if (u == null)
  9947. return !0;
  9948. Object.keys(u).forEach((c) => {
  9949. const l = u[c];
  9950. if (l == null)
  9951. return !0;
  9952. for (const f of l)
  9953. t.push({ unitId: o, sheetId: c, range: f });
  9954. });
  9955. });
  9956. }), { dirtyRanges: t, excludedCell: r };
  9957. }
  9958. // eslint-disable-next-line max-lines-per-function
  9959. async _apply(a = !1) {
  9960. a ? this._runtimeService.setFormulaExecuteStage(ft.START_DEPENDENCY_ARRAY_FORMULA) : this._runtimeService.setFormulaExecuteStage(ft.START_DEPENDENCY), this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
  9961. const e = (await this._formulaDependencyGenerator.generate()).reverse(), t = this._interpreter;
  9962. a ? (this._runtimeService.setFormulaExecuteStage(ft.START_CALCULATION_ARRAY_FORMULA), this._runtimeService.setTotalArrayFormulasToCalculate(e.length)) : (this._runtimeService.setFormulaExecuteStage(ft.START_CALCULATION), this._runtimeService.setTotalFormulasToCalculate(e.length)), this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
  9963. let r = [];
  9964. const n = this._configService.getConfig(fa), s = (n == null ? void 0 : n.intervalCount) || Uh, o = e.length;
  9965. for (let u = 0; u < o; u++) {
  9966. const c = e[u], l = c.nodeData, f = c.getDirtyData;
  9967. if (u % s === 0 && (await new Promise((d) => {
  9968. const _ = Qu(d);
  9969. r.push(_);
  9970. }), a ? (this._runtimeService.setFormulaExecuteStage(
  9971. ft.CURRENTLY_CALCULATING_ARRAY_FORMULA
  9972. ), this._runtimeService.setCompletedArrayFormulasCount(u + 1)) : (this._runtimeService.setFormulaExecuteStage(ft.CURRENTLY_CALCULATING), this._runtimeService.setCompletedFormulasCount(u + 1)), this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()), this._runtimeService.isStopExecution() || l == null && f == null)) {
  9973. this._runtimeService.setFormulaExecuteStage(ft.IDLE), this._runtimeService.markedAsStopFunctionsExecuted(), this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());
  9974. return;
  9975. }
  9976. this._runtimeService.setCurrent(
  9977. c.row,
  9978. c.column,
  9979. c.rowCount,
  9980. c.columnCount,
  9981. c.subUnitId,
  9982. c.unitId
  9983. );
  9984. let h;
  9985. if (f != null && c.featureId != null) {
  9986. const { runtimeCellData: d, dirtyRanges: _ } = f(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData());
  9987. this._runtimeService.setRuntimeFeatureCellData(c.featureId, d), this._runtimeService.setRuntimeFeatureRange(c.featureId, _);
  9988. } else l != null && (t.checkAsyncNode(l.node) ? h = await t.executeAsync(l) : h = t.execute(l), c.formulaId != null ? this._runtimeService.setRuntimeOtherData(c.formulaId, c.refOffsetX, c.refOffsetY, h) : this._runtimeService.setRuntimeData(h));
  9989. }
  9990. return r.forEach((u) => u()), r = [], o > 0 ? this._runtimeService.markedAsSuccessfullyExecuted() : a || this._runtimeService.markedAsNoFunctionsExecuted(), this._runtimeService.getAllRuntimeData();
  9991. }
  9992. calculate(a, e = !0) {
  9993. const t = this._lexer.treeBuilder(a, e);
  9994. if (Object.values(m).includes(t))
  9995. return xe.create(t);
  9996. const r = this._astTreeBuilder.parse(t);
  9997. r == null || r.serialize();
  9998. }
  9999. };
  10000. Qs = jh([
  10001. Qt(0, ta),
  10002. Qt(1, Ve(gr)),
  10003. Qt(2, Ft),
  10004. Qt(3, Nt),
  10005. Qt(4, Ys),
  10006. Qt(5, Ve(Cr)),
  10007. Qt(6, Ve(xr))
  10008. ], Qs);
  10009. var vh = Object.defineProperty, Th = Object.getOwnPropertyDescriptor, Bh = (i, a, e, t) => {
  10010. for (var r = t > 1 ? void 0 : t ? Th(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  10011. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  10012. return t && r && vh(a, e, r), r;
  10013. }, ms = (i, a) => (e, t) => a(e, t, i);
  10014. let Nn = class extends Me {
  10015. constructor(i, a, e) {
  10016. super(), this._commandService = i, this._calculateFormulaService = a, this._formulaDataModel = e, this._initialize();
  10017. }
  10018. _initialize() {
  10019. this._commandExecutedListener(), this._initialExecuteFormulaListener();
  10020. }
  10021. _commandExecutedListener() {
  10022. this.disposeWithMe(
  10023. this._commandService.onCommandExecuted((i) => {
  10024. if (i.id === zi.id)
  10025. this._calculateFormulaService.stopFormulaExecution();
  10026. else if (i.id === Zi.id) {
  10027. const a = i.params;
  10028. this._calculate(a);
  10029. } else if (i.id === bs.id) {
  10030. const a = i.params;
  10031. if (a == null)
  10032. return;
  10033. const { arrayFormulaRange: e, arrayFormulaCellData: t } = a;
  10034. this._formulaDataModel.setArrayFormulaRange(e), this._formulaDataModel.setArrayFormulaCellData(t);
  10035. }
  10036. })
  10037. );
  10038. }
  10039. async _calculate(i) {
  10040. const { forceCalculation: a = !1, dirtyRanges: e = [], dirtyNameMap: t = {}, dirtyDefinedNameMap: r = {}, dirtyUnitFeatureMap: n = {}, dirtyUnitOtherFormulaMap: s = {}, clearDependencyTreeCache: o = {}, maxIteration: u = so } = i, c = this._formulaDataModel.getFormulaData(), l = this._formulaDataModel.getArrayFormulaCellData(), f = this._formulaDataModel.getArrayFormulaRange();
  10041. this._calculateFormulaService.execute({
  10042. formulaData: c,
  10043. arrayFormulaCellData: l,
  10044. arrayFormulaRange: f,
  10045. forceCalculate: a,
  10046. dirtyRanges: e,
  10047. dirtyNameMap: t,
  10048. dirtyDefinedNameMap: r,
  10049. dirtyUnitFeatureMap: n,
  10050. dirtyUnitOtherFormulaMap: s,
  10051. clearDependencyTreeCache: o,
  10052. maxIteration: u
  10053. });
  10054. }
  10055. // Notification
  10056. _initialExecuteFormulaListener() {
  10057. this._calculateFormulaService.executionCompleteListener$.subscribe((i) => {
  10058. const a = i.functionsExecutedState;
  10059. switch (a) {
  10060. case wr.NOT_EXECUTED:
  10061. break;
  10062. case wr.STOP_EXECUTION:
  10063. break;
  10064. case wr.SUCCESS:
  10065. this._applyResult(i);
  10066. break;
  10067. case wr.INITIAL:
  10068. break;
  10069. }
  10070. this._commandService.executeCommand(
  10071. Ns.id,
  10072. {
  10073. functionsExecutedState: a
  10074. },
  10075. {
  10076. onlyLocal: !0
  10077. }
  10078. );
  10079. }), this._calculateFormulaService.executionInProgressListener$.subscribe((i) => {
  10080. this._commandService.executeCommand(
  10081. Ns.id,
  10082. {
  10083. stageInfo: i
  10084. },
  10085. {
  10086. onlyLocal: !0
  10087. }
  10088. );
  10089. });
  10090. }
  10091. async _applyResult(i) {
  10092. const { unitData: a, unitOtherData: e, arrayFormulaRange: t, arrayFormulaCellData: r, clearArrayFormulaCellData: n } = i;
  10093. if (!a) {
  10094. console.error("No sheetData from Formula Engine!");
  10095. return;
  10096. }
  10097. t && (this._formulaDataModel.clearPreviousArrayFormulaCellData(n), this._formulaDataModel.mergeArrayFormulaCellData(r), this._formulaDataModel.mergeArrayFormulaRange(t), this._commandService.executeCommand(
  10098. bs.id,
  10099. {
  10100. arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
  10101. arrayFormulaCellData: this._formulaDataModel.getArrayFormulaCellData()
  10102. },
  10103. {
  10104. onlyLocal: !0
  10105. }
  10106. )), this._commandService.executeCommand(
  10107. Ji.id,
  10108. {
  10109. unitData: uc(a),
  10110. unitOtherData: e
  10111. },
  10112. {
  10113. onlyLocal: !0
  10114. }
  10115. );
  10116. }
  10117. };
  10118. Nn = Bh([
  10119. ms(0, br),
  10120. ms(1, Gs),
  10121. ms(2, Ve(Pr))
  10122. ], Nn);
  10123. const Ni = /[\[\]]/g;
  10124. function Oi(i, a) {
  10125. if (Ni.test(i)) {
  10126. const e = Number(i.replace(Ni, ""));
  10127. return a + e;
  10128. }
  10129. return Number(i) - 1;
  10130. }
  10131. function gs(i, a = 0, e = 0) {
  10132. i = i.toLocaleUpperCase();
  10133. const t = i.split(/[RC]/), r = t[1], n = t[2], s = Oi(r, a), o = Oi(n, e);
  10134. return {
  10135. row: s,
  10136. column: o,
  10137. absoluteRefType: we.NONE
  10138. };
  10139. }
  10140. function Ih(i, a = 0, e = 0) {
  10141. const { refBody: t, sheetName: r, unitId: n } = na(i), s = t.indexOf(":");
  10142. if (s === -1) {
  10143. const C = gs(t, a, e), E = C.row, b = C.column, R = C.absoluteRefType;
  10144. return {
  10145. unitId: n,
  10146. sheetName: r,
  10147. range: {
  10148. startRow: E,
  10149. startColumn: b,
  10150. endRow: E,
  10151. endColumn: b,
  10152. startAbsoluteRefType: R,
  10153. endAbsoluteRefType: R
  10154. }
  10155. };
  10156. }
  10157. const o = t.substring(0, s), u = t.substring(s + 1), c = gs(o, a, e), l = gs(u, a, e), f = c.row, h = c.column, d = l.row, _ = l.column;
  10158. return {
  10159. unitId: n,
  10160. sheetName: r,
  10161. range: {
  10162. startRow: f,
  10163. startColumn: h,
  10164. endRow: d,
  10165. endColumn: _,
  10166. startAbsoluteRefType: c.absoluteRefType,
  10167. endAbsoluteRefType: l.absoluteRefType
  10168. }
  10169. };
  10170. }
  10171. function Fh(i) {
  10172. const a = qr(i.startRow, i.startAbsoluteRefType, !0), e = qr(i.startColumn, i.startAbsoluteRefType, !1), t = qr(i.endRow, i.endAbsoluteRefType, !0), r = qr(i.endColumn, i.endAbsoluteRefType, !1);
  10173. return a === t && e === r ? `R${a}C${e}` : `R${a}C${e}:R${t}C${r}`;
  10174. }
  10175. function qr(i, a = we.ALL, e) {
  10176. switch (i += 1, a) {
  10177. case we.ALL:
  10178. return `${i}`;
  10179. case we.ROW:
  10180. return e ? `${i}` : `[${i}]`;
  10181. case we.COLUMN:
  10182. return e ? `[${i}]` : `${i}`;
  10183. case we.NONE:
  10184. return `[${i}]`;
  10185. }
  10186. }
  10187. function Xt(i) {
  10188. let a = i;
  10189. if (i.isArray()) {
  10190. const e = i.getRowCount(), t = i.getColumnCount();
  10191. if (e > 1 || t > 1)
  10192. return g.create(m.VALUE);
  10193. a = i.get(0, 0);
  10194. }
  10195. return a.isError(), a;
  10196. }
  10197. function Fr(...i) {
  10198. for (let a = 0; a < i.length; a++) {
  10199. const e = Xt(i[a]);
  10200. if (e.isError())
  10201. return {
  10202. isError: !0,
  10203. errorObject: e
  10204. };
  10205. i[a] = e;
  10206. }
  10207. return {
  10208. isError: !1,
  10209. variants: i
  10210. };
  10211. }
  10212. function H(...i) {
  10213. for (let a = 0; a < i.length; a++) {
  10214. const e = Xt(i[a]);
  10215. if (e.isError())
  10216. return {
  10217. isError: !0,
  10218. errorObject: e
  10219. };
  10220. if (e.isBoolean())
  10221. return {
  10222. isError: !0,
  10223. errorObject: g.create(m.VALUE)
  10224. };
  10225. i[a] = e;
  10226. }
  10227. return {
  10228. isError: !1,
  10229. variants: i
  10230. };
  10231. }
  10232. function Fe(...i) {
  10233. for (let a = 0; a < i.length; a++) {
  10234. let e = i[a];
  10235. if (e.isError())
  10236. return {
  10237. isError: !0,
  10238. errorObject: e
  10239. };
  10240. if (e.isNull())
  10241. return {
  10242. isError: !0,
  10243. errorObject: g.create(m.NA)
  10244. };
  10245. if (e = Xt(i[a]), e.isError())
  10246. return {
  10247. isError: !0,
  10248. errorObject: e
  10249. };
  10250. if (e.isBoolean())
  10251. return {
  10252. isError: !0,
  10253. errorObject: g.create(m.VALUE)
  10254. };
  10255. i[a] = e;
  10256. }
  10257. return {
  10258. isError: !1,
  10259. variants: i
  10260. };
  10261. }
  10262. function I(...i) {
  10263. for (let a = 0; a < i.length; a++) {
  10264. let e = i[a];
  10265. if (e.isString() && (e = e.convertToNumberObjectValue()), e.isError())
  10266. return {
  10267. isError: !0,
  10268. errorObject: e
  10269. };
  10270. i[a] = e;
  10271. }
  10272. return {
  10273. isError: !1,
  10274. variants: i
  10275. };
  10276. }
  10277. class V {
  10278. constructor(a) {
  10279. A(this, "_unitId");
  10280. A(this, "_subUnitId");
  10281. A(this, "_row", -1);
  10282. A(this, "_column", -1);
  10283. A(this, "_definedNames");
  10284. A(this, "_locale");
  10285. A(this, "_sheetOrder");
  10286. A(this, "_sheetNameMap");
  10287. A(this, "_formulaDataModel");
  10288. A(this, "_rowCount", -1);
  10289. A(this, "_columnCount", -1);
  10290. /**
  10291. * Whether the function needs to expand the parameters
  10292. */
  10293. A(this, "needsExpandParams", !1);
  10294. /**
  10295. * Whether the function needs to pass in reference object
  10296. */
  10297. A(this, "needsReferenceObject", !1);
  10298. /**
  10299. * Whether the function needs handle locale
  10300. */
  10301. A(this, "needsLocale", !1);
  10302. /**
  10303. * Whether the function needs sheets info
  10304. */
  10305. A(this, "needsSheetsInfo", !1);
  10306. /**
  10307. * Whether the function needs function methods in FormulaDataModel
  10308. */
  10309. A(this, "needsFormulaDataModel", !1);
  10310. /**
  10311. * Whether the function needs the number of rows and columns in the sheet
  10312. */
  10313. A(this, "needsSheetRowColumnCount", !1);
  10314. /**
  10315. * Minimum number of parameters
  10316. */
  10317. A(this, "minParams", -1);
  10318. /**
  10319. * Maximum number of parameters
  10320. */
  10321. A(this, "maxParams", -1);
  10322. this._name = a;
  10323. }
  10324. get name() {
  10325. return this._name;
  10326. }
  10327. get unitId() {
  10328. return this._unitId;
  10329. }
  10330. get subUnitId() {
  10331. return this._subUnitId;
  10332. }
  10333. get row() {
  10334. return this._row;
  10335. }
  10336. get column() {
  10337. return this._column;
  10338. }
  10339. dispose() {
  10340. }
  10341. /**
  10342. * In Excel, to inject a defined name into a function that has positioning capabilities,
  10343. * such as using the INDIRECT function to reference a named range,
  10344. * you can write it as follows:
  10345. * =INDIRECT("DefinedName1")
  10346. */
  10347. getDefinedName(a) {
  10348. var t;
  10349. const e = this._definedNames;
  10350. return e == null ? null : (t = Array.from(Object.values(e)).filter((r) => r.name === a)) == null ? void 0 : t[0];
  10351. }
  10352. setDefinedNames(a) {
  10353. this._definedNames = a;
  10354. }
  10355. getLocale() {
  10356. return this._locale;
  10357. }
  10358. setLocale(a) {
  10359. this._locale = a;
  10360. }
  10361. getSheetsInfo() {
  10362. return {
  10363. sheetOrder: this._sheetOrder,
  10364. sheetNameMap: this._sheetNameMap
  10365. };
  10366. }
  10367. setSheetsInfo({
  10368. sheetOrder: a,
  10369. sheetNameMap: e
  10370. }) {
  10371. this._sheetOrder = a, this._sheetNameMap = e;
  10372. }
  10373. setFormulaDataModel(a) {
  10374. this._formulaDataModel = a;
  10375. }
  10376. setSheetRowColumnCount(a, e) {
  10377. this._rowCount = a, this._columnCount = e;
  10378. }
  10379. isAsync() {
  10380. return !1;
  10381. }
  10382. isAddress() {
  10383. return !1;
  10384. }
  10385. isCustom() {
  10386. return !1;
  10387. }
  10388. setRefInfo(a, e, t, r) {
  10389. this._unitId = a, this._subUnitId = e, this._row = t, this._column = r;
  10390. }
  10391. calculateCustom(...a) {
  10392. return null;
  10393. }
  10394. calculate(...a) {
  10395. return g.create(m.VALUE);
  10396. }
  10397. checkArrayType(a) {
  10398. return a.isReferenceObject() || a.isValueObject() && a.isArray();
  10399. }
  10400. /**
  10401. * Starting with 1
  10402. * For instance, The column number (starting with 1 for the left-most column of table_array) that contains the return value.
  10403. * https://support.microsoft.com/en-us/office/vlookup-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
  10404. * @param indexNum
  10405. */
  10406. getIndexNumValue(a, e = 1) {
  10407. let t = a;
  10408. if (t.isArray() && (t = t.getFirstCell()), t.isBoolean())
  10409. return t.getValue() === !1 ? g.create(m.VALUE) : e;
  10410. if (t.isString()) {
  10411. const r = Number(t.getValue());
  10412. return Number.isNaN(r) ? g.create(m.REF) : r;
  10413. } else if (t.isNumber())
  10414. return t.getValue();
  10415. return g.create(m.VALUE);
  10416. }
  10417. /**
  10418. * A logical value that specifies 1/TRUE , 0/FALSE, default 1
  10419. * For instance range_lookup, A logical value that specifies whether you want VLOOKUP to find an approximate or an exact match
  10420. * Approximate match - 1/TRUE
  10421. * Exact match - 0/FALSE
  10422. * https://support.microsoft.com/en-us/office/vlookup-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
  10423. * For instance A1, A logical value that specifies what type of reference is contained in the cell ref_text.
  10424. * If a1 is TRUE or omitted, ref_text is interpreted as an A1-style reference.
  10425. * If a1 is FALSE, ref_text is interpreted as an R1C1-style reference.
  10426. * https://support.microsoft.com/zh-cn/office/indirect-%E5%87%BD%E6%95%B0-474b3a3a-8a26-4f44-b491-92b6306fa261
  10427. * @param logicValueObject
  10428. */
  10429. getZeroOrOneByOneDefault(a) {
  10430. if (a == null)
  10431. return 1;
  10432. let e = 1;
  10433. if (a.isArray() && (a = a.getFirstCell()), a.isBoolean())
  10434. a.getValue() === !1 && (e = 0);
  10435. else {
  10436. if (a.isString())
  10437. return;
  10438. a.isNumber() && a.getValue() === 0 && (e = 0);
  10439. }
  10440. return e;
  10441. }
  10442. /**
  10443. * A logical value that specifies 1/TRUE , 0/FALSE, -1, default 1.
  10444. * The difference from getZeroOrOneByOneDefault is that we need to get -1
  10445. * @param logicValueObject
  10446. */
  10447. getMatchTypeValue(a) {
  10448. if (a == null)
  10449. return 1;
  10450. let e = 1;
  10451. if (a.isArray() && (a = a.getFirstCell()), a.isBoolean())
  10452. a.getValue() === !1 && (e = 0);
  10453. else {
  10454. if (a.isString())
  10455. return;
  10456. if (a.isNumber()) {
  10457. const t = a.getValue();
  10458. t <= 0 && (e = t);
  10459. }
  10460. }
  10461. return e;
  10462. }
  10463. binarySearch(a, e, t, r, n) {
  10464. const s = e.binarySearch(a, r, n);
  10465. if (s == null)
  10466. return g.create(m.NA);
  10467. let o;
  10468. return t.getRowCount() === 1 ? o = t.get(0, s) || ie.create() : o = t.get(s, 0) || ie.create(), o.isNull() ? y.create(0) : o;
  10469. }
  10470. _getOneFirstByRaw(a) {
  10471. return a.length === 0 ? g.create(m.NA) : a[0][0] || g.create(m.NA);
  10472. }
  10473. _getOneLastByRaw(a) {
  10474. return a.length === 0 ? g.create(m.NA) : a[a.length - 1][a[0].length - 1] || g.create(m.NA);
  10475. }
  10476. equalSearch(a, e, t, r = !0) {
  10477. const n = t.pickRaw(e.isEqual(a));
  10478. return r ? this._getOneFirstByRaw(n) : this._getOneLastByRaw(n);
  10479. }
  10480. fuzzySearch(a, e, t, r = !0) {
  10481. const n = t.pickRaw(e.compare(a, $.EQUALS));
  10482. return r ? this._getOneFirstByRaw(n) : this._getOneLastByRaw(n);
  10483. }
  10484. orderSearch(a, e, t, r = Pe.MIN, n = !1) {
  10485. const s = e.orderSearch(a, r, n);
  10486. if (s == null)
  10487. return g.create(m.NA);
  10488. const o = t.get(s.row, s.column) || ie.create();
  10489. return o.isNull() ? g.create(m.NA) : o;
  10490. }
  10491. binarySearchExpand(a, e, t, r = 0, n, s) {
  10492. const o = e.binarySearch(a, n, s);
  10493. return o == null ? g.create(m.NA) : r === 0 ? t.slice([o, o + 1]) : t.slice(void 0, [o, o + 1]);
  10494. }
  10495. equalSearchExpand(a, e, t, r = !0, n = 0) {
  10496. const s = e.isEqual(a);
  10497. let o;
  10498. return r ? o = s.getFirstTruePosition() : o = s.getLastTruePosition(), o == null ? g.create(m.NA) : n === 0 ? t.slice([o.row, o.row + 1]) : t.slice(void 0, [o.column, o.column + 1]);
  10499. }
  10500. fuzzySearchExpand(a, e, t, r = !0, n = 0) {
  10501. const s = e.compare(a, $.EQUALS);
  10502. let o;
  10503. return r ? o = s.getFirstTruePosition() : o = s.getLastTruePosition(), o == null ? g.create(m.NA) : n === 0 ? t.slice([o.row, o.row + 1]) : t.slice(void 0, [o.column, o.column + 1]);
  10504. }
  10505. orderSearchExpand(a, e, t, r = Pe.MIN, n = !1, s = 0) {
  10506. const o = e.orderSearch(a, r, n);
  10507. return o == null ? g.create(m.NA) : s === 0 ? t.slice([o.row, o.row + 1]) : t.slice(void 0, [o.column, o.column + 1]);
  10508. }
  10509. flattenArray(a, e = !0) {
  10510. const t = [];
  10511. t[0] = [];
  10512. for (let r = 0; r < a.length; r++) {
  10513. let n = a[r];
  10514. if ((n.isString() || n.isBoolean() || n.isNull()) && (n = n.convertToNumberObjectValue()), n.isError())
  10515. return n;
  10516. if (n.isArray()) {
  10517. let s;
  10518. if (n.iterator((o) => {
  10519. if (o == null || o.isNull() || e && (o.isString() || o.isBoolean()))
  10520. return !0;
  10521. if (o = this._includingLogicalValuesAndText(o), o.isError())
  10522. return s = o, !1;
  10523. t[0].push(o);
  10524. }), s != null && s.isError())
  10525. return s;
  10526. } else
  10527. t[0].push(n);
  10528. }
  10529. return tr(t, 1, t[0].length);
  10530. }
  10531. _includingLogicalValuesAndText(a) {
  10532. if (a.isBoolean() && (a = wf(a)), a.isString()) {
  10533. const e = Number(a.getValue());
  10534. a = y.create(Number.isNaN(e) ? 0 : e);
  10535. }
  10536. return a;
  10537. }
  10538. createReferenceObject(a, e) {
  10539. const t = a.getForcedUnitId(), r = a.getForcedSheetId() || "", n = a.getForcedSheetName(), o = ys({
  10540. unitId: t,
  10541. sheetName: n,
  10542. range: e
  10543. });
  10544. let u;
  10545. return vr(o) ? u = new da(o) : Qi(o) ? u = new _a(o) : Wi(o) ? u = new Ca(o) : u = new Cn(e, r, t), this._setReferenceDefault(a, u);
  10546. }
  10547. _setReferenceDefault(a, e) {
  10548. return this.unitId == null || this.subUnitId == null ? g.create(m.REF) : (e.setDefaultUnitId(this.unitId), e.setDefaultSheetId(this.subUnitId), e.setUnitData(a.getUnitData()), e.setRuntimeData(a.getRuntimeData()), e.setArrayFormulaCellData(a.getArrayFormulaCellData()), e.setRuntimeArrayFormulaCellData(a.getRuntimeArrayFormulaCellData()), e);
  10549. }
  10550. }
  10551. class kh extends V {
  10552. constructor() {
  10553. super(...arguments);
  10554. A(this, "minParams", 3);
  10555. A(this, "maxParams", 3);
  10556. }
  10557. calculate(e, t, r) {
  10558. if (e.isError())
  10559. return e;
  10560. const { isError: n, errorObject: s, variants: o } = Fr(t, r);
  10561. if (n)
  10562. return s;
  10563. const { isError: u, errorObject: c, variants: l } = I(...o);
  10564. if (u)
  10565. return c;
  10566. const [f, h] = l, d = Math.floor(+f.getValue()), _ = Math.floor(+h.getValue());
  10567. if (d < 0 || _ < 0)
  10568. return g.create(m.NUM);
  10569. if (d === 0 || _ === 0)
  10570. return g.create(m.REF);
  10571. const C = e.isArray() ? e.getRowCount() : 1, E = e.isArray() ? e.getColumnCount() : 1;
  10572. if (C === 1 && E === 1)
  10573. return e.isArray() ? e.get(0, 0) : e;
  10574. const b = d > C ? C : d, R = _ > E ? E : _;
  10575. return e.slice([0, b], [0, R]);
  10576. }
  10577. }
  10578. class $h extends V {
  10579. constructor() {
  10580. super(...arguments);
  10581. A(this, "minParams", 1);
  10582. A(this, "maxParams", 255);
  10583. }
  10584. calculate(...e) {
  10585. const t = [];
  10586. for (let r = 0; r < e.length; r++) {
  10587. const n = e[r], s = n.isArray() ? n.getRowCount() : 1, o = n.isArray() ? n.getColumnCount() : 1;
  10588. for (let u = 0; u < s; u++)
  10589. for (let c = 0; c < o; c++) {
  10590. const l = n.isArray() ? n.get(u, c) : n;
  10591. t.push([l]);
  10592. }
  10593. }
  10594. return q.create({
  10595. calculateValueList: t,
  10596. rowCount: t.length,
  10597. columnCount: 1,
  10598. unitId: this.unitId,
  10599. sheetId: this.subUnitId,
  10600. row: this.row,
  10601. column: this.column
  10602. });
  10603. }
  10604. }
  10605. var Ws = /* @__PURE__ */ ((i) => (i.ARRAY_CONSTRAIN = "ARRAY_CONSTRAIN", i.FLATTEN = "FLATTEN", i))(Ws || {});
  10606. const Yh = [
  10607. [kh, Ws.ARRAY_CONSTRAIN],
  10608. [$h, Ws.FLATTEN]
  10609. ];
  10610. var _r;
  10611. ((i) => {
  10612. const a = 0.636619772;
  10613. function e(n, s) {
  10614. let o = 0;
  10615. for (let u = 0; u < n.length; ++u)
  10616. o = s * o + n[u];
  10617. return o;
  10618. }
  10619. function t(n, s, o, u, c) {
  10620. if (s === 0)
  10621. return o;
  10622. if (s === 1)
  10623. return u;
  10624. const l = 2 / n;
  10625. let f = o, h = u, d = u;
  10626. for (let _ = 1; _ < s; ++_)
  10627. d = h * _ * l + c * f, f = h, h = d;
  10628. return d;
  10629. }
  10630. function r(n, s, o, u) {
  10631. return function(l, f) {
  10632. if (o) {
  10633. if (l === 0)
  10634. return o === 1 ? -1 / 0 : 1 / 0;
  10635. if (l < 0)
  10636. return Number.NaN;
  10637. }
  10638. if (f === 0)
  10639. return n(l);
  10640. if (f === 1)
  10641. return s(l);
  10642. if (f < 0)
  10643. return Number.NaN;
  10644. const h = f | 0, d = n(l), _ = s(l);
  10645. return t(l, h, d, _, u);
  10646. };
  10647. }
  10648. i.besselj = /* @__PURE__ */ (() => {
  10649. const n = [-184.9052456, 77392.33017, -1121442418e-2, 6516196407e-1, -13362590354, 57568490574], s = [1, 267.8532712, 59272.64853, 9494680718e-3, 1029532985, 57568490411], o = [2093887211e-16, -2073370639e-15, 2734510407e-14, -0.001098628627, 1], u = [-934935152e-16, 7621095161e-16, -6911147651e-15, 1430488765e-13, -0.01562499995];
  10650. function c(C) {
  10651. let E = 0, b = 0, R = 0, p = C * C;
  10652. if (C < 8)
  10653. b = e(n, p), R = e(s, p), E = b / R;
  10654. else {
  10655. const N = C - 0.785398164;
  10656. p = 64 / p, b = e(o, p), R = e(u, p), E = Math.sqrt(a / C) * (Math.cos(N) * b - Math.sin(N) * R * 8 / C);
  10657. }
  10658. return E;
  10659. }
  10660. const l = [-30.16036606, 15704.4826, -2972611439e-3, 2423968531e-1, -7895059235, 72362614232], f = [1, 376.9991397, 99447.43394, 1858330474e-2, 2300535178, 144725228442], h = [-240337019e-15, 2457520174e-15, -3516396496e-14, 183105e-8, 1], d = [105787412e-15, -88228987e-14, 8449199096e-15, -2002690873e-13, 0.04687499995];
  10661. function _(C) {
  10662. let E = 0, b = 0, R = 0, p = C * C;
  10663. const N = Math.abs(C) - 2.356194491;
  10664. return Math.abs(C) < 8 ? (b = C * e(l, p), R = e(f, p), E = b / R) : (p = 64 / p, b = e(h, p), R = e(d, p), E = Math.sqrt(a / Math.abs(C)) * (Math.cos(N) * b - Math.sin(N) * R * 8 / Math.abs(C)), C < 0 && (E = -E)), E;
  10665. }
  10666. return function C(E, b) {
  10667. const R = Math.round(b);
  10668. if (!Number.isFinite(E))
  10669. return Number.isNaN(E) ? E : 0;
  10670. if (R < 0)
  10671. return (R % 2 ? -1 : 1) * C(E, -R);
  10672. if (E < 0)
  10673. return (R % 2 ? -1 : 1) * C(-E, R);
  10674. if (R === 0)
  10675. return c(E);
  10676. if (R === 1)
  10677. return _(E);
  10678. if (E === 0)
  10679. return 0;
  10680. let p = 0;
  10681. if (E > R)
  10682. p = t(E, R, c(E), _(E), -1);
  10683. else {
  10684. const N = 2 * Math.floor((R + Math.floor(Math.sqrt(40 * R))) / 2);
  10685. let M = !1, w = 0, D = 0, S = 1, P = 0;
  10686. const U = 2 / E;
  10687. for (let x = N; x > 0; x--)
  10688. if (P = x * U * S - w, w = S, S = P, Math.abs(S) > 1e10 && (S *= 1e-10, w *= 1e-10, p *= 1e-10, D *= 1e-10), M && (D += S), M = !M, x === R && (p = w), N - x > 100 && p === 0)
  10689. return Number.NaN;
  10690. D = 2 * D - S, p /= D;
  10691. }
  10692. return p;
  10693. };
  10694. })(), i.bessely = (() => {
  10695. const n = [228.4622733, -86327.92757, 1087988129e-2, -5123598036e-1, 7062834065, -2957821389], s = [1, 226.1030244, 47447.2647, 7189466438e-3, 7452499648e-1, 40076544269], o = [2093887211e-16, -2073370639e-15, 2734510407e-14, -0.001098628627, 1], u = [-934945152e-16, 7621095161e-16, -6911147651e-15, 1430488765e-13, -0.01562499995];
  10696. function c(C) {
  10697. let E = 0, b = 0, R = 0, p = C * C;
  10698. const N = C - 0.785398164;
  10699. return C < 8 ? (b = e(n, p), R = e(s, p), E = b / R + a * (0, i.besselj)(C, 0) * Math.log(C)) : (p = 64 / p, b = e(o, p), R = e(u, p), E = Math.sqrt(a / C) * (Math.sin(N) * b + Math.cos(N) * R * 8 / C)), E;
  10700. }
  10701. const l = [8511.937935, -4237922726e-3, 7349264551e-1, -51534381390, 127527439e4, -4900604943e3], f = [1, 354.9632885, 102042.605, 2245904002e-2, 3733650367, 424441966400, 249958057e5], h = [-240337019e-15, 2457520174e-15, -3516396496e-14, 183105e-8, 1], d = [105787412e-15, -88228987e-14, 8449199096e-15, -2002690873e-13, 0.04687499995];
  10702. function _(C) {
  10703. let E = 0, b = 0, R = 0, p = C * C;
  10704. const N = C - 2.356194491;
  10705. return C < 8 ? (b = C * e(l, p), R = e(f, p), E = b / R + a * ((0, i.besselj)(C, 1) * Math.log(C) - 1 / C)) : (p = 64 / p, b = e(h, p), R = e(d, p), E = Math.sqrt(a / C) * (Math.sin(N) * b + Math.cos(N) * R * 8 / C)), E;
  10706. }
  10707. return r(c, _, 1, -1);
  10708. })(), i.besseli = /* @__PURE__ */ (() => {
  10709. const n = [45813e-7, 0.0360768, 0.2659732, 1.2067492, 3.0899424, 3.5156229, 1], s = [392377e-8, -0.01647633, 0.02635537, -0.02057706, 916281e-8, -157565e-8, 225319e-8, 0.01328592, 0.39894228];
  10710. function o(f) {
  10711. return f <= 3.75 ? e(n, f * f / (3.75 * 3.75)) : Math.exp(Math.abs(f)) / Math.sqrt(Math.abs(f)) * e(s, 3.75 / Math.abs(f));
  10712. }
  10713. const u = [32411e-8, 301532e-8, 0.02658733, 0.15084934, 0.51498869, 0.87890594, 0.5], c = [-420059e-8, 0.01787654, -0.02895312, 0.02282967, -0.01031555, 163801e-8, -362018e-8, -0.03988024, 0.39894228];
  10714. function l(f) {
  10715. return f < 3.75 ? f * e(u, f * f / (3.75 * 3.75)) : (f < 0 ? -1 : 1) * Math.exp(Math.abs(f)) / Math.sqrt(Math.abs(f)) * e(c, 3.75 / Math.abs(f));
  10716. }
  10717. return function f(h, d) {
  10718. const _ = Math.round(d);
  10719. if (_ === 0)
  10720. return o(h);
  10721. if (_ === 1)
  10722. return l(h);
  10723. if (_ < 0)
  10724. return Number.NaN;
  10725. if (Math.abs(h) === 0)
  10726. return 0;
  10727. if (h === 1 / 0)
  10728. return 1 / 0;
  10729. let C = 0, E;
  10730. const b = 2 / Math.abs(h);
  10731. let R = 0, p = 1, N = 0;
  10732. const M = 2 * Math.round((_ + Math.round(Math.sqrt(40 * _))) / 2);
  10733. for (E = M; E > 0; E--)
  10734. if (N = E * b * p + R, R = p, p = N, Math.abs(p) > 1e10 && (p *= 1e-10, R *= 1e-10, C *= 1e-10), E === _ && (C = R), M - E > 100 && C === 0)
  10735. return Number.NaN;
  10736. return C *= f(h, 0) / p, h < 0 && _ % 2 ? -C : C;
  10737. };
  10738. })(), i.besselk = (() => {
  10739. const n = [74e-7, 1075e-7, 262698e-8, 0.0348859, 0.23069756, 0.4227842, -0.57721566], s = [53208e-8, -25154e-7, 587872e-8, -0.01062446, 0.02189568, -0.07832358, 1.25331414];
  10740. function o(f) {
  10741. return f <= 2 ? -Math.log(f / 2) * (0, i.besseli)(f, 0) + e(n, f * f / 4) : Math.exp(-f) / Math.sqrt(f) * e(s, 2 / f);
  10742. }
  10743. const u = [-4686e-8, -110404e-8, -0.01919402, -0.18156897, -0.67278579, 0.15443144, 1], c = [-68245e-8, 325614e-8, -780353e-8, 0.01504268, -0.0365562, 0.23498619, 1.25331414];
  10744. function l(f) {
  10745. return f <= 2 ? Math.log(f / 2) * (0, i.besseli)(f, 1) + 1 / f * e(u, f * f / 4) : Math.exp(-f) / Math.sqrt(f) * e(c, 2 / f);
  10746. }
  10747. return r(o, l, 2, 1);
  10748. })();
  10749. })(_r || (_r = {}));
  10750. function Ra(i) {
  10751. return /^[01]{1,10}$/.test(i);
  10752. }
  10753. function pa(i) {
  10754. return /^[0-7]{1,10}$/.test(i);
  10755. }
  10756. function Va(i) {
  10757. return /^[0-9A-Fa-f]{1,10}$/.test(i);
  10758. }
  10759. function Zt(i) {
  10760. if (i === 0)
  10761. return 0;
  10762. const a = [
  10763. -1.3026537197817094,
  10764. 0.6419697923564902,
  10765. 0.019476473204185836,
  10766. -0.00956151478680863,
  10767. -946595344482036e-18,
  10768. 366839497852761e-18,
  10769. 42523324806907e-18,
  10770. -20278578112534e-18,
  10771. -1624290004647e-18,
  10772. 130365583558e-17,
  10773. 15626441722e-18,
  10774. -85238095915e-18,
  10775. 6529054439e-18,
  10776. 5059343495e-18,
  10777. -991364156e-18,
  10778. -227365122e-18,
  10779. 96467911e-18,
  10780. 2394038e-18,
  10781. -6886027e-18,
  10782. 894487e-18,
  10783. 313092e-18,
  10784. -112708e-18,
  10785. 381e-18,
  10786. 7106e-18,
  10787. -1523e-18,
  10788. -94e-18,
  10789. 121e-18,
  10790. -28e-18
  10791. ];
  10792. let e = i, t = !1;
  10793. e < 0 && (e = -e, t = !0);
  10794. const r = 2 / (2 + e), n = 4 * r - 2;
  10795. let s = 0, o = 0, u;
  10796. for (let l = a.length - 1; l > 0; l--)
  10797. u = s, s = n * s - o + a[l], o = u;
  10798. const c = r * Math.exp(-e * e + 0.5 * (a[0] + n * s) - o);
  10799. return t ? c - 1 : 1 - c;
  10800. }
  10801. function Na(i) {
  10802. return 1 - Zt(i);
  10803. }
  10804. function Hh(i) {
  10805. if (i >= 2)
  10806. return -100;
  10807. if (i <= 0)
  10808. return 100;
  10809. const a = i < 1 ? i : 2 - i, e = Math.sqrt(-2 * Math.log(a / 2));
  10810. let t = -0.70711 * ((2.30753 + e * 0.27061) / (1 + e * (0.99229 + e * 0.04481)) - e);
  10811. for (let r = 0; r < 2; r++) {
  10812. const n = Na(t) - a;
  10813. t += n / (1.1283791670955126 * Math.exp(-t * t) - t * n);
  10814. }
  10815. return i < 1 ? t : -t;
  10816. }
  10817. function cr(i, a = 1) {
  10818. let e = Math.floor(i);
  10819. if (i < 0)
  10820. return Number.NaN;
  10821. let t = 1;
  10822. for (; e > 1 && Number.isFinite(t); )
  10823. t *= e, e -= a;
  10824. return t;
  10825. }
  10826. function zt(i, a) {
  10827. const e = Math.min(i - a, a);
  10828. let t = 1;
  10829. for (let r = 1; r <= e && Number.isFinite(t); r++)
  10830. t *= i - r + 1, t /= r;
  10831. return t;
  10832. }
  10833. function qs(i, a) {
  10834. let e = Math.floor(i), t = Math.floor(a);
  10835. for (; t !== 0; ) {
  10836. const r = t;
  10837. t = e % t, e = r;
  10838. }
  10839. return e;
  10840. }
  10841. function Mi(i, a) {
  10842. const e = qs(i, a);
  10843. return e === 0 ? 0 : Math.abs(i * a) / e;
  10844. }
  10845. function Gn(i) {
  10846. const a = i.length;
  10847. if (a === 1)
  10848. return i[0][0];
  10849. if (a === 2)
  10850. return i[0][0] * i[1][1] - i[0][1] * i[1][0];
  10851. let e = 0;
  10852. for (let t = 0; t < a; t++)
  10853. e += (t % 2 === 0 ? 1 : -1) * i[0][t] * Gn(wo(i, 0, t));
  10854. return e;
  10855. }
  10856. function Gh(i) {
  10857. const a = Gn(i);
  10858. return a === 0 ? null : i.length === 1 ? [[1 / a]] : Qh(i).map((r) => r.map((n) => n / a));
  10859. }
  10860. function wo(i, a, e) {
  10861. return i.filter((t, r) => r !== a).map((t) => t.filter((r, n) => n !== e));
  10862. }
  10863. function Qh(i) {
  10864. const a = i.length, e = Array.from({ length: a }, () => new Array(a).fill(0));
  10865. for (let t = 0; t < a; t++)
  10866. for (let r = 0; r < a; r++) {
  10867. const n = (t + r) % 2 === 0 ? 1 : -1;
  10868. e[r][t] = n * Gn(wo(i, t, r));
  10869. }
  10870. return e;
  10871. }
  10872. function lr(i, a) {
  10873. return i.map((e) => a[0].map(
  10874. (t, r) => e.reduce((n, s, o) => n + s * a[o][r], 0)
  10875. ));
  10876. }
  10877. function mt(i) {
  10878. return i[0].map((a, e) => i.map((t) => t[e]));
  10879. }
  10880. function Wh(i) {
  10881. const { smallPivotDetected: a, luMatrix: e, permutation: t } = qh(i);
  10882. return a ? null : Kh(e, t);
  10883. }
  10884. function qh(i) {
  10885. const a = mt(i), e = a.length, t = a[0].length;
  10886. let r = !0, n = !1;
  10887. const s = Ks(e, t, 0), o = new Array(t).fill(0).map((u, c) => c);
  10888. for (let u = 0; u < t; u++) {
  10889. for (let h = 0; h < u; h++) {
  10890. let d = a[h][u];
  10891. for (let _ = 0; _ < h; _++)
  10892. d -= s[h][_] * s[_][u];
  10893. s[h][u] = d;
  10894. }
  10895. let c = -1 / 0, l = u;
  10896. for (let h = u; h < e; h++) {
  10897. let d = a[h][u];
  10898. for (let C = 0; C < u; C++)
  10899. d -= s[h][C] * s[C][u];
  10900. s[h][u] = d;
  10901. const _ = Math.abs(d);
  10902. _ > c && (c = _, l = h);
  10903. }
  10904. if (Math.abs(s[l][u]) < 1e-11) {
  10905. n = !0;
  10906. break;
  10907. }
  10908. l !== u && ([s[u], s[l]] = [s[l], s[u]], [a[u], a[l]] = [a[l], a[u]], [o[u], o[l]] = [o[l], o[u]], r = !r);
  10909. const f = s[u][u];
  10910. for (let h = u + 1; h < e; h++)
  10911. s[h][u] /= f;
  10912. }
  10913. return {
  10914. rowSwap: r,
  10915. smallPivotDetected: n,
  10916. luMatrix: s,
  10917. permutation: o
  10918. };
  10919. }
  10920. function Kh(i, a) {
  10921. const e = a.length, t = Ks(e, e, 0);
  10922. for (let n = 0; n < e; n++)
  10923. t[n][n] = 1;
  10924. const r = Ks(e, e, 0);
  10925. for (let n = 0; n < e; n++) {
  10926. const s = a[n];
  10927. for (let o = 0; o < e; o++)
  10928. r[n][o] = t[s][o];
  10929. }
  10930. for (let n = 0; n < e; n++) {
  10931. const s = r[n];
  10932. for (let o = n + 1; o < e; o++) {
  10933. const u = i[o][n];
  10934. for (let c = 0; c < e; c++)
  10935. r[o][c] -= s[c] * u;
  10936. }
  10937. }
  10938. for (let n = e - 1; n >= 0; n--) {
  10939. const s = r[n], o = i[n][n];
  10940. for (let u = 0; u < e; u++)
  10941. s[u] /= o;
  10942. for (let u = 0; u < n; u++) {
  10943. const c = i[u][n];
  10944. for (let l = 0; l < e; l++)
  10945. r[u][l] -= s[l] * c;
  10946. }
  10947. }
  10948. return r;
  10949. }
  10950. function Ks(i, a, e) {
  10951. const t = [];
  10952. for (let r = 0; r < i; r++) {
  10953. t[r] = [];
  10954. for (let n = 0; n < a; n++)
  10955. t[r].push(e);
  10956. }
  10957. return t;
  10958. }
  10959. function Xh(i) {
  10960. const a = Zh(i);
  10961. if (!a)
  10962. return null;
  10963. const { matrixU: e, matrixS: t, matrixV: r } = a, n = mt(e), s = Array.from({ length: t.length }, () => new Array(i[0].length).fill(0)), o = Math.max(i.length, i[0].length) * Number.EPSILON * t[0];
  10964. for (let u = 0; u < t.length; u++)
  10965. Math.abs(t[u]) > o && (s[u][u] = 1 / t[u]);
  10966. return lr(r, lr(s, n));
  10967. }
  10968. function Zh(i) {
  10969. const a = mt(i), e = a.length, t = a[0].length;
  10970. if (e < t)
  10971. return null;
  10972. const r = new Array(t).fill(0), n = new Array(t).fill(0), s = Array.from({ length: t }, () => new Array(t).fill(0));
  10973. let o = Number.EPSILON, u = 0, c = 0, l = 0;
  10974. for (let C = 0; C < t; C++) {
  10975. if (r[C] = u, c = ds(a, C, e, C, C), c <= 1e-64 / o)
  10976. u = 0;
  10977. else {
  10978. u = Math.sqrt(c), a[C][C] >= 0 && (u = -u);
  10979. const b = a[C][C] * u - c;
  10980. a[C][C] -= u;
  10981. for (let R = C + 1; R < t; R++) {
  10982. c = ds(a, C, e, C, R);
  10983. for (let p = C; p < e; p++)
  10984. a[p][R] += c / b * a[p][C];
  10985. }
  10986. }
  10987. if (n[C] = u, c = wi(a, C + 1, t, C, C), c <= 1e-64 / o)
  10988. u = 0;
  10989. else {
  10990. u = Math.sqrt(c), a[C][C + 1] >= 0 && (u = -u);
  10991. const b = a[C][C + 1] * u - c;
  10992. a[C][C + 1] -= u;
  10993. for (let R = C + 1; R < t; R++)
  10994. r[R] = a[C][R] / b;
  10995. for (let R = C + 1; R < e; R++) {
  10996. c = wi(a, C + 1, t, R, C);
  10997. for (let p = C + 1; p < t; p++)
  10998. a[R][p] += c * r[p];
  10999. }
  11000. }
  11001. const E = Math.abs(n[C]) + Math.abs(r[C]);
  11002. E > l && (l = E);
  11003. }
  11004. let f = 0;
  11005. for (let C = t - 1; C >= 0; C--) {
  11006. if (u !== 0) {
  11007. for (let E = f; E < t; E++)
  11008. s[E][C] = a[C][E] / (u * a[C][C + 1]);
  11009. for (let E = f; E < t; E++) {
  11010. c = 0;
  11011. for (let b = f; b < t; b++)
  11012. c += a[C][b] * s[b][E];
  11013. for (let b = f; b < t; b++)
  11014. s[b][E] += c * s[b][C];
  11015. }
  11016. }
  11017. for (let E = f; E < t; E++)
  11018. s[C][E] = 0, s[E][C] = 0;
  11019. s[C][C] = 1, u = r[C], f = C;
  11020. }
  11021. for (let C = t - 1; C >= 0; C--) {
  11022. u = n[C];
  11023. for (let E = C + 1; E < t; E++)
  11024. a[C][E] = 0;
  11025. if (u !== 0) {
  11026. for (let E = C + 1; E < t; E++) {
  11027. c = ds(a, C + 1, e, C, E);
  11028. for (let b = C; b < e; b++)
  11029. a[b][E] += c / (a[C][C] * u) * a[b][C];
  11030. }
  11031. for (let E = C; E < e; E++)
  11032. a[E][C] /= u;
  11033. } else
  11034. for (let E = C; E < e; E++)
  11035. a[E][C] = 0;
  11036. a[C][C] += 1;
  11037. }
  11038. o *= l;
  11039. let h = 0, d = 0, _ = 0;
  11040. for (let C = t - 1; C >= 0; C--)
  11041. for (let E = 0; E < 50; E++) {
  11042. let b = !1, R = C;
  11043. for (; R >= 0; R--) {
  11044. if (Math.abs(r[R]) <= o) {
  11045. b = !0;
  11046. break;
  11047. }
  11048. if (Math.abs(n[R - 1]) <= o)
  11049. break;
  11050. }
  11051. if (!b) {
  11052. let w = 0, D = 1;
  11053. for (let S = R; S < C + 1 && (h = D * r[S], d = n[S], r[S] *= w, !(Math.abs(h) <= o)); S++) {
  11054. _ = Kr(h, d), n[S] = _, w = d / _, D = -h / _;
  11055. for (let P = 0; P < e; P++) {
  11056. const U = a[P][R - 1], x = a[P][S];
  11057. a[P][R - 1] = U * w + x * D, a[P][S] = -U * D + x * w;
  11058. }
  11059. }
  11060. }
  11061. if (R === C) {
  11062. if (n[C] < 0) {
  11063. n[C] = -n[C];
  11064. for (let w = 0; w < t; w++)
  11065. s[w][C] = -s[w][C];
  11066. }
  11067. break;
  11068. }
  11069. if (E >= 49)
  11070. return null;
  11071. let p = n[R];
  11072. h = ((n[C - 1] - n[C]) * (n[C - 1] + n[C]) + (r[C - 1] - r[C]) * (r[C - 1] + r[C])) / (2 * r[C] * n[C - 1]), _ = Kr(h, 1), h < 0 ? h = ((p - n[C]) * (p + n[C]) + r[C] * (n[C - 1] / (h - _) - r[C])) / p : h = ((p - n[C]) * (p + n[C]) + r[C] * (n[C - 1] / (h + _) - r[C])) / p;
  11073. let N = 1, M = 1;
  11074. for (let w = R + 1; w < C + 1; w++) {
  11075. let D = r[w], S = n[w];
  11076. d = M * D, D *= N, _ = Kr(h, d), r[w - 1] = _, N = h / _, M = d / _, h = p * N + D * M, d = S * M, D = -p * M + D * N, S *= N;
  11077. for (let P = 0; P < t; P++) {
  11078. const U = s[P][w - 1], x = s[P][w];
  11079. s[P][w - 1] = U * N + x * M, s[P][w] = -U * M + x * N;
  11080. }
  11081. _ = Kr(h, d), n[w - 1] = _, N = h / _, M = d / _, h = N * D + M * S, p = -M * D + N * S;
  11082. for (let P = 0; P < e; P++) {
  11083. const U = a[P][w - 1], x = a[P][w];
  11084. a[P][w - 1] = U * N + x * M, a[P][w] = -U * M + x * N;
  11085. }
  11086. }
  11087. r[R] = 0, r[C] = h, n[C] = p;
  11088. }
  11089. for (let C = 0; C < n.length; C++)
  11090. n[C] < o && (n[C] = 0);
  11091. for (let C = 0; C < t; C++)
  11092. for (let E = C - 1; E >= 0; E--)
  11093. if (n[E] < n[C]) {
  11094. const b = n[E];
  11095. n[E] = n[C], n[C] = b;
  11096. for (let R = 0; R < a.length; R++) {
  11097. const p = a[R][C];
  11098. a[R][C] = a[R][E], a[R][E] = p;
  11099. }
  11100. for (let R = 0; R < s.length; R++) {
  11101. const p = s[R][C];
  11102. s[R][C] = s[R][E], s[R][E] = p;
  11103. }
  11104. C = E;
  11105. }
  11106. return {
  11107. matrixU: a,
  11108. matrixS: n,
  11109. matrixV: s
  11110. };
  11111. }
  11112. function Kr(i, a) {
  11113. let e = 0;
  11114. return Math.abs(i) > Math.abs(a) ? (e = a / i, Math.abs(i) * Math.sqrt(1 + e * e)) : a !== 0 ? (e = i / a, Math.abs(a) * Math.sqrt(1 + e * e)) : 0;
  11115. }
  11116. function ds(i, a, e, t, r) {
  11117. let n = 0;
  11118. for (let s = a; s < e; s++)
  11119. n += i[s][t] * i[s][r];
  11120. return n;
  11121. }
  11122. function wi(i, a, e, t, r) {
  11123. let n = 0;
  11124. for (let s = a; s < e; s++)
  11125. n += i[t][s] * i[r][s];
  11126. return n;
  11127. }
  11128. const Xr = /* @__PURE__ */ new Map([
  11129. ["I", 1],
  11130. ["V", 5],
  11131. ["X", 10],
  11132. ["L", 50],
  11133. ["C", 100],
  11134. ["D", 500],
  11135. ["M", 1e3]
  11136. ]), zh = /* @__PURE__ */ new Map([
  11137. [1, "I"],
  11138. [4, "IV"],
  11139. [5, "V"],
  11140. [9, "IX"],
  11141. [10, "X"],
  11142. [40, "XL"],
  11143. [45, "VL"],
  11144. [49, "IL"],
  11145. [50, "L"],
  11146. [90, "XC"],
  11147. [95, "VC"],
  11148. [99, "IC"],
  11149. [100, "C"],
  11150. [400, "CD"],
  11151. [450, "LD"],
  11152. [490, "XD"],
  11153. [495, "VD"],
  11154. [499, "ID"],
  11155. [500, "D"],
  11156. [900, "CM"],
  11157. [950, "LM"],
  11158. [990, "XM"],
  11159. [995, "VM"],
  11160. [999, "IM"],
  11161. [1e3, "M"]
  11162. ]), Jh = [
  11163. [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1e3, 4e3],
  11164. [1, 4, 5, 9, 10, 40, 45, 50, 90, 95, 100, 400, 450, 500, 900, 950, 1e3, 4e3],
  11165. [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 500, 900, 950, 990, 1e3, 4e3],
  11166. [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 495, 500, 900, 950, 990, 995, 1e3, 4e3],
  11167. [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 495, 499, 500, 900, 950, 990, 995, 999, 1e3, 4e3]
  11168. ];
  11169. function Do(i, a, e) {
  11170. return i <= 0 ? 0 : i >= 1 ? 1 : Qn(i, a, e);
  11171. }
  11172. function em(i, a, e) {
  11173. return i <= 0 || i >= 1 ? 0 : a === 1 && e === 1 ? 1 : a < 512 && e < 512 ? i ** (a - 1) * (1 - i) ** (e - 1) / Ma(a, e) : Math.exp((a - 1) * Math.log(i) + (e - 1) * Math.log(1 - i) - wa(a, e));
  11174. }
  11175. function Oa(i, a, e) {
  11176. if (i <= 0)
  11177. return 0;
  11178. if (i >= 1)
  11179. return 1;
  11180. const t = 1e-8;
  11181. let r;
  11182. if (a >= 1 && e >= 1) {
  11183. const c = i < 0.5 ? i : 1 - i, l = Math.sqrt(-2 * Math.log(c));
  11184. r = (2.30753 + l * 0.27061) / (1 + l * (0.99229 + l * 0.04481)) - l, i < 0.5 && (r = -r);
  11185. const f = (r * r - 3) / 6, h = 2 / (1 / (2 * a - 1) + 1 / (2 * e - 1)), d = r * Math.sqrt(f + h) / h - (1 / (2 * e - 1) - 1 / (2 * a - 1)) * (f + 5 / 6 - 2 / (3 * h));
  11186. r = a / (a + e * Math.exp(2 * d));
  11187. } else {
  11188. const c = Math.exp(a * Math.log(a / (a + e))) / a, l = Math.exp(e * Math.log(e / (a + e))) / e, f = c + l;
  11189. i < c / f ? r = (a * f * i) ** (1 / a) : r = 1 - (e * f * (1 - i)) ** (1 / e);
  11190. }
  11191. const n = -wa(a, e);
  11192. let s, o, u;
  11193. for (let c = 0; c < 10; c++) {
  11194. if (r === 0 || r === 1)
  11195. return r;
  11196. if (s = Qn(r, a, e) - i, o = Math.exp((a - 1) * Math.log(r) + (e - 1) * Math.log(1 - r) + n), u = s / o, r -= o = u / (1 - 0.5 * Math.min(1, u * ((a - 1) / r - (e - 1) / (1 - r)))), r <= 0 && (r = 0.5 * (r + o)), r >= 1 && (r = 0.5 * (r + o + 1)), Math.abs(o) < t * r && c > 0)
  11197. break;
  11198. }
  11199. return r;
  11200. }
  11201. function Qn(i, a, e) {
  11202. const t = i === 0 || i === 1 ? 0 : Math.exp(ct(a + e) - ct(a) - ct(e) + a * Math.log(i) + e * Math.log(1 - i));
  11203. return i < (a + 1) / (a + e + 2) ? t * Di(i, a, e) / a : 1 - t * Di(1 - i, e, a) / e;
  11204. }
  11205. function Di(i, a, e) {
  11206. let n = 1 - (a + e) * i / (a + 1);
  11207. Math.abs(n) < 1e-8 && (n = 1e-8), n = 1 / n;
  11208. let s = 1, o = n;
  11209. for (let u = 1; u <= 100; u++) {
  11210. let c = u * (e - u) * i / ((a - 1 + u * 2) * (a + u * 2));
  11211. if (n = 1 + c * n, Math.abs(n) < 1e-8 && (n = 1e-8), s = 1 + c / s, Math.abs(s) < 1e-8 && (s = 1e-8), n = 1 / n, o *= n * s, c = -(a + u) * (a + e + u) * i / ((a + u * 2) * (a + 1 + u * 2)), n = 1 + c * n, Math.abs(n) < 1e-8 && (n = 1e-8), s = 1 + c / s, Math.abs(s) < 1e-8 && (s = 1e-8), n = 1 / n, o *= n * s, Math.abs(n * s - 1) < 1e-8)
  11212. break;
  11213. }
  11214. return o;
  11215. }
  11216. function Ma(i, a) {
  11217. return i + a > 170 ? Math.exp(wa(i, a)) : on(i) * on(a) / on(i + a);
  11218. }
  11219. function wa(i, a) {
  11220. return ct(i) + ct(a) - ct(i + a);
  11221. }
  11222. function So(i, a, e) {
  11223. if (i < 0)
  11224. return 0;
  11225. if (i >= a)
  11226. return 1;
  11227. if (e < 0 || e > 1 || a <= 0)
  11228. return Number.NaN;
  11229. let t = 0;
  11230. for (let r = 0; r <= i; r++)
  11231. t += Da(r, a, e);
  11232. return t;
  11233. }
  11234. function Da(i, a, e) {
  11235. return e === 0 || e === 1 ? a * e === i ? 1 : 0 : zt(a, i) * e ** i * (1 - e) ** (a - i);
  11236. }
  11237. function Sa(i, a) {
  11238. return i <= 0 ? 0 : La(a / 2, i / 2);
  11239. }
  11240. function tm(i, a) {
  11241. return i < 0 ? 0 : i === 0 && a === 2 ? 0.5 : Math.exp((a / 2 - 1) * Math.log(i) - i / 2 - a / 2 * Math.log(2) - ct(a / 2));
  11242. }
  11243. function Po(i, a) {
  11244. return i <= 0 ? 0 : i >= 1 ? 1 / 0 : 2 * jo(i, a / 2);
  11245. }
  11246. function Pa(i, a, e) {
  11247. return i < 0 ? 0 : Qn(a * i / (a * i + e), a / 2, e / 2);
  11248. }
  11249. function rm(i, a, e) {
  11250. if (i < 0)
  11251. return 0;
  11252. if (i === 0 && a < 2)
  11253. return 1 / 0;
  11254. if (i === 0 && a === 2)
  11255. return 1;
  11256. let t = 1 / Ma(a / 2, e / 2);
  11257. return t *= (a / e) ** (a / 2), t *= i ** (a / 2 - 1), t *= (1 + a / e * i) ** (-(a + e) / 2), t;
  11258. }
  11259. function Lo(i, a, e) {
  11260. return i <= 0 ? 0 : i >= 1 ? 1 / 0 : e / (a * (1 / Oa(i, a / 2, e / 2) - 1));
  11261. }
  11262. function nm(i, a) {
  11263. return i < 0 ? 0 : 1 - Math.exp(-a * i);
  11264. }
  11265. function sm(i, a) {
  11266. return i < 0 ? 0 : a * Math.exp(-a * i);
  11267. }
  11268. function xo(i, a, e) {
  11269. const t = a.length;
  11270. let r = 0, n = 0;
  11271. for (let h = 0; h < t; h++)
  11272. r += a[h], n += e[h];
  11273. const s = r / t, o = n / t;
  11274. let u = 0, c = 0;
  11275. for (let h = 0; h < t; h++)
  11276. u += (a[h] - s) * (e[h] - o), c += (e[h] - o) ** 2;
  11277. if (c === 0)
  11278. return 1 / 0;
  11279. const l = u / c;
  11280. return s - l * o + l * i;
  11281. }
  11282. function on(i) {
  11283. const a = [
  11284. -1.716185138865495,
  11285. 24.76565080557592,
  11286. -379.80425647094563,
  11287. 629.3311553128184,
  11288. 866.9662027904133,
  11289. -31451.272968848367,
  11290. -36144.413418691176,
  11291. 66456.14382024054
  11292. ], e = [
  11293. -30.8402300119739,
  11294. 315.35062697960416,
  11295. -1015.1563674902192,
  11296. -3107.771671572311,
  11297. 22538.11842098015,
  11298. 4755.846277527881,
  11299. // eslint-disable-line
  11300. -134659.9598649693,
  11301. -115132.2596755535
  11302. ];
  11303. let t = 0, r = i;
  11304. if (i > 171.6243769536076)
  11305. return 1 / 0;
  11306. if (r <= 0) {
  11307. const f = r % 1 + 36e-17;
  11308. if (f)
  11309. t = (r & 1 ? -1 : 1) * Math.PI / Math.sin(Math.PI * f), r = 1 - r;
  11310. else
  11311. return 1 / 0;
  11312. }
  11313. const n = r;
  11314. let s = 0, o;
  11315. r < 1 ? o = r++ : o = (r -= s = (r | 0) - 1) - 1;
  11316. let u = 0, c = 0;
  11317. for (let f = 0; f < 8; ++f)
  11318. u = (u + a[f]) * o, c = c * o + e[f];
  11319. let l = u / c + 1;
  11320. if (n < r)
  11321. l /= n;
  11322. else if (n > r)
  11323. for (let f = 0; f < s; ++f)
  11324. l *= r, r++;
  11325. return t && (l = t / l), l;
  11326. }
  11327. function am(i, a, e) {
  11328. return i <= 0 ? 0 : La(a, i / e);
  11329. }
  11330. function im(i, a, e) {
  11331. return i < 0 ? 0 : i === 0 && a === 1 ? 1 / e : Math.exp((a - 1) * Math.log(i) - i / e - ct(a) - a * Math.log(e));
  11332. }
  11333. function om(i, a, e) {
  11334. return i <= 0 ? 0 : i >= 1 ? 1 / 0 : e * jo(i, a);
  11335. }
  11336. function ct(i) {
  11337. const a = [
  11338. 76.18009172947146,
  11339. -86.50532032941678,
  11340. 24.01409824083091,
  11341. // eslint-disable-line
  11342. -1.231739572450155,
  11343. 0.001208650973866179,
  11344. -5395239384953e-18
  11345. ];
  11346. let e = i, t = i + 5.5;
  11347. t -= (i + 0.5) * Math.log(t);
  11348. let r = 1.000000000190015;
  11349. for (let n = 0; n < 6; n++)
  11350. r += a[n] / ++e;
  11351. return -t + Math.log(2.5066282746310007 * r / i);
  11352. }
  11353. function La(i, a) {
  11354. if (a < 0 || i <= 0)
  11355. return Number.NaN;
  11356. const e = 1e-30, t = -~(Math.log(i >= 1 ? i : 1 / i) * 8.5 + i * 0.4 + 17), r = ct(i), n = Math.exp(-a + i * Math.log(a) - r);
  11357. let s = i, o = 1 / i, u = o;
  11358. if (a < i + 1) {
  11359. if (n === 0)
  11360. return 0;
  11361. for (let d = 1; d <= t && (o += u *= a / ++s, !(Math.abs(u) < Math.abs(o) * e)); d++)
  11362. ;
  11363. return o * n;
  11364. }
  11365. if (n === 0)
  11366. return 1;
  11367. let c = a + 1 - i, l = 1 / e, f = 1 / c, h = f;
  11368. for (let d = 1; d <= t; d++) {
  11369. const _ = -d * (d - i);
  11370. if (c += 2, f = _ * f + c, Math.abs(f) < e && (f = e), l = c + _ / l, Math.abs(l) < e && (l = e), f = 1 / f, h *= f * l, Math.abs(f * l - 1) < e)
  11371. break;
  11372. }
  11373. return 1 - h * n;
  11374. }
  11375. function jo(i, a) {
  11376. if (i <= 0)
  11377. return 0;
  11378. if (i >= 1)
  11379. return Math.max(100, a + 100 * Math.sqrt(a));
  11380. let e;
  11381. if (a > 1) {
  11382. const o = i < 0.5 ? i : 1 - i, u = Math.sqrt(-2 * Math.log(o));
  11383. e = (2.30753 + u * 0.27061) / (1 + u * (0.99229 + u * 0.04481)) - u, i < 0.5 && (e = -e), e = Math.max(1e-3, a * (1 - 1 / (9 * a) - e / (3 * Math.sqrt(a))) ** 3);
  11384. } else {
  11385. const o = 1 - a * (0.253 + a * 0.12);
  11386. i < o ? e = (i / o) ** (1 / a) : e = 1 - Math.log(1 - (i - o) / (1 - o));
  11387. }
  11388. const t = 1e-8, r = ct(a);
  11389. let n, s;
  11390. for (let o = 0; o < 12; o++) {
  11391. if (e <= 0)
  11392. return 0;
  11393. if (n = La(a, e) - i, a > 1 ? s = Math.exp((a - 1) * (Math.log(a - 1) - 1) - r) * Math.exp(-(e - (a - 1)) + (a - 1) * (Math.log(e) - Math.log(a - 1))) : s = Math.exp(-e + (a - 1) * Math.log(e) - r), s !== 0 && (s = n / s / (1 - 0.5 * Math.min(1, n / s * ((a - 1) / e - 1)))), e -= s, e <= 0 && (e = 0.5 * (e + s)), Math.abs(s) < t * e)
  11394. break;
  11395. }
  11396. return e;
  11397. }
  11398. function um(i, a, e, t) {
  11399. let r = 0;
  11400. for (let n = 0; n <= i; n++)
  11401. r += xa(n, a, e, t);
  11402. return r;
  11403. }
  11404. function xa(i, a, e, t) {
  11405. return a - i > t - e ? 0 : zt(e, i) * zt(t - e, a - i) / zt(t, a);
  11406. }
  11407. function Uo(i, a, e) {
  11408. return i < 0 ? 0 : 0.5 + 0.5 * Zt((Math.log(i) - a) / Math.sqrt(2 * e * e));
  11409. }
  11410. function cm(i, a, e) {
  11411. return i <= 0 ? 0 : Math.exp(-Math.log(i) - 0.5 * Math.log(2 * Math.PI) - Math.log(e) - (Math.log(i) - a) ** 2 / (2 * e * e));
  11412. }
  11413. function lm(i, a, e) {
  11414. return Math.exp(Wn(i, a, e));
  11415. }
  11416. function fm(i, a, e) {
  11417. if (i < 0)
  11418. return 0;
  11419. let t = 0;
  11420. for (let r = 0; r <= i; r++)
  11421. t += ja(r, a, e);
  11422. return t;
  11423. }
  11424. function ja(i, a, e) {
  11425. return i < 0 ? 0 : zt(i + a - 1, a - 1) * e ** a * (1 - e) ** i;
  11426. }
  11427. function kr(i, a, e) {
  11428. return 0.5 * (1 + Zt((i - a) / Math.sqrt(2 * e * e)));
  11429. }
  11430. function vo(i, a, e) {
  11431. return Math.exp(-0.5 * Math.log(2 * Math.PI) - Math.log(e) - (i - a) ** 2 / (2 * e * e));
  11432. }
  11433. function Wn(i, a, e) {
  11434. return -1.4142135623730951 * e * Hh(2 * i) + a;
  11435. }
  11436. function hm(i, a) {
  11437. let e = 0;
  11438. for (let t = 0; t <= i; t++)
  11439. e += To(t, a);
  11440. return e;
  11441. }
  11442. function To(i, a) {
  11443. return Math.exp(-a) * a ** i / cr(i);
  11444. }
  11445. function $r(i, a) {
  11446. const e = 0.5 * Qn(a / (i ** 2 + a), a / 2, 0.5);
  11447. return i < 0 ? e : 1 - e;
  11448. }
  11449. function mm(i, a) {
  11450. const e = (1 + i ** 2 / a) ** (-(a + 1) / 2);
  11451. return 1 / (Math.sqrt(a) * Ma(0.5, a / 2)) * e;
  11452. }
  11453. function qn(i, a) {
  11454. let e = Oa(2 * Math.min(i, 1 - i), 0.5 * a, 0.5);
  11455. return e = Math.sqrt(a * (1 - e) / e), i > 0.5 ? e : -e;
  11456. }
  11457. function Je(i, a, e, t, r) {
  11458. const n = [], s = [];
  11459. let o = !0;
  11460. for (let u = 0; u < e; u++) {
  11461. const c = Math.floor(u / t), l = u % t, f = Math.floor(u / r), h = u % r, d = i.isArray() ? i.get(c, l) : i, _ = a.isArray() ? a.get(f, h) : a;
  11462. if (d.isError())
  11463. return {
  11464. isError: !0,
  11465. errorObject: d,
  11466. array1Values: n,
  11467. array2Values: s,
  11468. noCalculate: o
  11469. };
  11470. if (_.isError())
  11471. return {
  11472. isError: !0,
  11473. errorObject: _,
  11474. array1Values: n,
  11475. array2Values: s,
  11476. noCalculate: o
  11477. };
  11478. if (d.isNull() || _.isNull() || d.isBoolean() || _.isBoolean())
  11479. continue;
  11480. const C = d.getValue(), E = _.getValue();
  11481. !Q(C) || !Q(E) || (n.push(+C), s.push(+E), o = !1);
  11482. }
  11483. return {
  11484. isError: !1,
  11485. errorObject: null,
  11486. array1Values: n,
  11487. array2Values: s,
  11488. noCalculate: o
  11489. };
  11490. }
  11491. function Kn(i, a, e) {
  11492. const t = i.isArray() ? i.getRowCount() : 1, r = i.isArray() ? i.getColumnCount() : 1;
  11493. let n = t, s = r;
  11494. if (a && !a.isNull() && (n = a.isArray() ? a.getRowCount() : 1, s = a.isArray() ? a.getColumnCount() : 1, t === 1 && s !== r || r === 1 && n !== t || t !== 1 && r !== 1 && (n !== t || s !== r)))
  11495. return {
  11496. isError: !0,
  11497. errorObject: g.create(m.REF)
  11498. };
  11499. if (e && !e.isNull()) {
  11500. const o = e.isArray() ? e.getRowCount() : 1, u = e.isArray() ? e.getColumnCount() : 1;
  11501. if (t === 1 && n > 1 && o !== n || r === 1 && s > 1 && u !== s)
  11502. return {
  11503. isError: !0,
  11504. errorObject: g.create(m.REF)
  11505. };
  11506. }
  11507. return {
  11508. isError: !1,
  11509. errorObject: null
  11510. };
  11511. }
  11512. function dt(i) {
  11513. const a = i.isArray() ? i.getRowCount() : 1, e = i.isArray() ? i.getColumnCount() : 1, t = [];
  11514. for (let r = 0; r < a; r++) {
  11515. t[r] = [];
  11516. for (let n = 0; n < e; n++) {
  11517. const s = i.isArray() ? i.get(r, n) : i;
  11518. if (s.isError() || s.isNull() || s.isBoolean() || s.isString())
  11519. return g.create(m.VALUE);
  11520. t[r].push(+s.getValue());
  11521. }
  11522. }
  11523. return t;
  11524. }
  11525. function Xn(i, a) {
  11526. const e = [];
  11527. let t = 1;
  11528. for (let r = 0; r < i; r++) {
  11529. e[r] = [];
  11530. for (let n = 0; n < a; n++)
  11531. e[r].push(t++);
  11532. }
  11533. return e;
  11534. }
  11535. function Zn(i, a, e, t) {
  11536. let r = a;
  11537. t && (r = a.map((o) => Math.log(o)));
  11538. let n, s;
  11539. return e ? { slope: n, intercept: s } = gm(i, r) : { slope: n, intercept: s } = dm(i, r), t && (n = Math.exp(n), s = Math.exp(s)), Number.isNaN(n) && !e && (n = 0), { slope: n, intercept: s, Y: r };
  11540. }
  11541. function gm(i, a) {
  11542. const e = a.length;
  11543. let t = 0, r = 0, n = 0, s = 0;
  11544. for (let l = 0; l < e; l++)
  11545. t += i[l], r += a[l], n += i[l] * i[l], s += i[l] * a[l];
  11546. const u = (e * s - t * r) / (e * n - t * t), c = 1 / e * r - u * (1 / e) * t;
  11547. return {
  11548. slope: u,
  11549. intercept: c
  11550. };
  11551. }
  11552. function dm(i, a) {
  11553. const e = [[...i]], t = [...a];
  11554. let r = e.length, n = e[0].length, s = Math.min(r, n);
  11555. const o = new Array(s).fill(0);
  11556. for (let c = 0; c < s; c++) {
  11557. const l = e[c];
  11558. let f = 0;
  11559. for (let d = 0; d < n; d++)
  11560. f += l[d] ** 2;
  11561. const h = l[c] < 0 ? Math.sqrt(f) : -Math.sqrt(f);
  11562. if (o[c] = h, h !== 0) {
  11563. l[c] -= h;
  11564. for (let d = c + 1; d < r; d++) {
  11565. let _ = 0;
  11566. for (let C = c; C < n; C++)
  11567. _ -= e[d][C] * l[C];
  11568. _ /= h * l[c];
  11569. for (let C = c; C < n; C++)
  11570. e[d][C] -= _ * l[C];
  11571. }
  11572. }
  11573. }
  11574. r = e.length, n = e[0].length, s = Math.min(r, n);
  11575. const u = new Array(r).fill(0);
  11576. for (let c = 0; c < s; c++) {
  11577. const l = e[c];
  11578. let f = 0;
  11579. for (let h = 0; h < n; h++)
  11580. f += t[h] * l[h];
  11581. f /= o[c] * l[c];
  11582. for (let h = 0; h < n; h++)
  11583. t[h] += f * l[h];
  11584. }
  11585. for (let c = o.length - 1; c >= 0; c--) {
  11586. t[c] /= o[c];
  11587. const l = t[c], f = e[c];
  11588. u[c] = l;
  11589. for (let h = 0; h < c; h++)
  11590. t[h] -= l * f[h];
  11591. }
  11592. return {
  11593. slope: u[0],
  11594. intercept: 0
  11595. };
  11596. }
  11597. function zn(i, a, e, t, r) {
  11598. const n = i.length === 1 && i[0].length > 1;
  11599. let s = i;
  11600. r && (s = i.map((C) => C.map((E) => Math.log(E))));
  11601. let o = a, u = e;
  11602. n && (s = mt(s), o = mt(o), u = mt(u)), t && (o = o.map((C) => [...C, 1]));
  11603. const c = mt(o), l = lr(c, o), f = lr(c, s);
  11604. let h = Wh(l);
  11605. if (!h && (h = Xh(l), !h))
  11606. return g.create(m.NA);
  11607. let d = lr(h, f);
  11608. t || d.push([0]), d = mt(d);
  11609. const _ = d[0].pop();
  11610. if (d[0].reverse(), d[0].push(_), r)
  11611. for (let C = 0; C < d[0].length; C++)
  11612. d[0][C] = Math.exp(d[0][C]);
  11613. return {
  11614. coefficients: d,
  11615. Y: s,
  11616. X: o,
  11617. newX: u,
  11618. XTXInverse: h
  11619. };
  11620. }
  11621. class Bo extends V {
  11622. constructor() {
  11623. super(...arguments);
  11624. A(this, "minParams", 3);
  11625. A(this, "maxParams", 5);
  11626. }
  11627. calculate(e, t, r, n, s) {
  11628. let o = n != null ? n : y.create(0), u = s != null ? s : y.create(1);
  11629. o.isNull() && (o = y.create(0)), u.isNull() && (u = y.create(1));
  11630. const c = Math.max(
  11631. e.isArray() ? e.getRowCount() : 1,
  11632. t.isArray() ? t.getRowCount() : 1,
  11633. r.isArray() ? r.getRowCount() : 1,
  11634. o.isArray() ? o.getRowCount() : 1,
  11635. u.isArray() ? u.getRowCount() : 1
  11636. ), l = Math.max(
  11637. e.isArray() ? e.getColumnCount() : 1,
  11638. t.isArray() ? t.getColumnCount() : 1,
  11639. r.isArray() ? r.getColumnCount() : 1,
  11640. o.isArray() ? o.getColumnCount() : 1,
  11641. u.isArray() ? u.getColumnCount() : 1
  11642. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.mapValue((b, R, p) => {
  11643. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p);
  11644. return this._handleSignleObject(b, N, M, w, D);
  11645. });
  11646. return c === 1 && l === 1 ? E.get(0, 0) : E;
  11647. }
  11648. _handleSignleObject(e, t, r, n, s) {
  11649. if (e.isError())
  11650. return e;
  11651. if (t.isError())
  11652. return t;
  11653. if (r.isError())
  11654. return r;
  11655. if (n.isError())
  11656. return n;
  11657. if (s.isError())
  11658. return s;
  11659. const { isError: o, errorObject: u, variants: c } = I(e, t, r, n, s);
  11660. if (o)
  11661. return u;
  11662. const [l, f, h, d, _] = c, C = +l.getValue(), E = +f.getValue(), b = +h.getValue(), R = +d.getValue(), p = +_.getValue();
  11663. if (E <= 0 || b <= 0 || C <= 0 || C >= 1 || R >= p)
  11664. return g.create(m.NUM);
  11665. const N = Oa(C, E, b) * (p - R) + R;
  11666. return y.create(N);
  11667. }
  11668. }
  11669. class Io extends V {
  11670. constructor() {
  11671. super(...arguments);
  11672. A(this, "minParams", 4);
  11673. A(this, "maxParams", 4);
  11674. }
  11675. calculate(e, t, r, n) {
  11676. const s = Math.max(
  11677. e.isArray() ? e.getRowCount() : 1,
  11678. t.isArray() ? t.getRowCount() : 1,
  11679. r.isArray() ? r.getRowCount() : 1,
  11680. n.isArray() ? n.getRowCount() : 1
  11681. ), o = Math.max(
  11682. e.isArray() ? e.getColumnCount() : 1,
  11683. t.isArray() ? t.getColumnCount() : 1,
  11684. r.isArray() ? r.getColumnCount() : 1,
  11685. n.isArray() ? n.getColumnCount() : 1
  11686. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  11687. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  11688. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  11689. });
  11690. return s === 1 && o === 1 ? h.get(0, 0) : h;
  11691. }
  11692. _handleSignleObject(e, t, r, n) {
  11693. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  11694. if (s)
  11695. return o;
  11696. const [c, l, f, h] = u, d = Math.floor(+c.getValue()), _ = Math.floor(+l.getValue()), C = +f.getValue(), E = +h.getValue();
  11697. if (d < 0 || d > _ || C < 0 || C > 1)
  11698. return g.create(m.NUM);
  11699. let b;
  11700. return E ? b = So(d, _, C) : b = Da(d, _, C), y.create(b);
  11701. }
  11702. }
  11703. class Fo extends V {
  11704. constructor() {
  11705. super(...arguments);
  11706. A(this, "minParams", 3);
  11707. A(this, "maxParams", 3);
  11708. }
  11709. calculate(e, t, r) {
  11710. const n = Math.max(
  11711. e.isArray() ? e.getRowCount() : 1,
  11712. t.isArray() ? t.getRowCount() : 1,
  11713. r.isArray() ? r.getRowCount() : 1
  11714. ), s = Math.max(
  11715. e.isArray() ? e.getColumnCount() : 1,
  11716. t.isArray() ? t.getColumnCount() : 1,
  11717. r.isArray() ? r.getColumnCount() : 1
  11718. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  11719. const _ = u.get(h, d), C = c.get(h, d);
  11720. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  11721. });
  11722. return n === 1 && s === 1 ? l.get(0, 0) : l;
  11723. }
  11724. _handleSignleObject(e, t, r) {
  11725. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  11726. if (n)
  11727. return s;
  11728. const [u, c, l] = o, f = Math.floor(+u.getValue()), h = +c.getValue(), d = +l.getValue();
  11729. if (f < 0 || h <= 0 || h >= 1 || d <= 0 || d >= 1)
  11730. return g.create(m.NUM);
  11731. let _ = 0;
  11732. for (; _ <= f && !(So(_, f, h) >= d); )
  11733. _++;
  11734. return y.create(_);
  11735. }
  11736. }
  11737. class ko extends V {
  11738. constructor() {
  11739. super(...arguments);
  11740. A(this, "minParams", 2);
  11741. A(this, "maxParams", 2);
  11742. }
  11743. calculate(e, t) {
  11744. const r = Math.max(
  11745. e.isArray() ? e.getRowCount() : 1,
  11746. t.isArray() ? t.getRowCount() : 1
  11747. ), n = Math.max(
  11748. e.isArray() ? e.getColumnCount() : 1,
  11749. t.isArray() ? t.getColumnCount() : 1
  11750. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  11751. const h = o.get(l, f);
  11752. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  11753. });
  11754. return r === 1 && n === 1 ? u.get(0, 0) : u;
  11755. }
  11756. _handleSignleObject(e, t) {
  11757. const { isError: r, errorObject: n, variants: s } = I(e, t);
  11758. if (r)
  11759. return n;
  11760. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  11761. if (c < 0 || l < 1 || l > 10 ** 10)
  11762. return g.create(m.NUM);
  11763. const f = 1 - Sa(c, l);
  11764. return y.create(f);
  11765. }
  11766. }
  11767. class $o extends V {
  11768. constructor() {
  11769. super(...arguments);
  11770. A(this, "minParams", 2);
  11771. A(this, "maxParams", 2);
  11772. }
  11773. calculate(e, t) {
  11774. const r = Math.max(
  11775. e.isArray() ? e.getRowCount() : 1,
  11776. t.isArray() ? t.getRowCount() : 1
  11777. ), n = Math.max(
  11778. e.isArray() ? e.getColumnCount() : 1,
  11779. t.isArray() ? t.getColumnCount() : 1
  11780. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  11781. const h = o.get(l, f);
  11782. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  11783. });
  11784. return r === 1 && n === 1 ? u.get(0, 0) : u;
  11785. }
  11786. _handleSignleObject(e, t) {
  11787. const { isError: r, errorObject: n, variants: s } = I(e, t);
  11788. if (r)
  11789. return n;
  11790. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  11791. if (c < 0 || c > 1 || l < 1 || l > 10 ** 10)
  11792. return g.create(m.NUM);
  11793. const f = Po(1 - c, l);
  11794. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  11795. }
  11796. }
  11797. class Yo extends V {
  11798. constructor() {
  11799. super(...arguments);
  11800. A(this, "minParams", 2);
  11801. A(this, "maxParams", 2);
  11802. }
  11803. calculate(e, t) {
  11804. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  11805. let u = e;
  11806. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  11807. return u;
  11808. let c = t;
  11809. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  11810. return c;
  11811. if (r * n === 1 || s * o === 1)
  11812. return u.isNull() || c.isNull() ? g.create(m.VALUE) : g.create(m.NA);
  11813. if (r * n !== s * o)
  11814. return g.create(m.NA);
  11815. const {
  11816. isError: l,
  11817. errorObject: f,
  11818. array1Values: h,
  11819. array2Values: d,
  11820. noCalculate: _
  11821. } = Je(
  11822. e,
  11823. t,
  11824. r * n,
  11825. n,
  11826. o
  11827. );
  11828. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d, r, n);
  11829. }
  11830. _getResult(e, t, r, n) {
  11831. let s = 0;
  11832. for (let c = 0; c < e.length; c++) {
  11833. if (t[c] === 0)
  11834. return g.create(m.DIV_BY_ZERO);
  11835. s += (e[c] - t[c]) ** 2 / t[c];
  11836. }
  11837. let o = (r - 1) * (n - 1);
  11838. r === 1 ? o = n - 1 : n === 1 && (o = r - 1);
  11839. const u = 1 - Sa(s, o);
  11840. return y.create(u);
  11841. }
  11842. }
  11843. class Ho extends V {
  11844. constructor() {
  11845. super(...arguments);
  11846. A(this, "minParams", 3);
  11847. A(this, "maxParams", 3);
  11848. }
  11849. calculate(e, t, r) {
  11850. const n = Math.max(
  11851. e.isArray() ? e.getRowCount() : 1,
  11852. t.isArray() ? t.getRowCount() : 1,
  11853. r.isArray() ? r.getRowCount() : 1
  11854. ), s = Math.max(
  11855. e.isArray() ? e.getColumnCount() : 1,
  11856. t.isArray() ? t.getColumnCount() : 1,
  11857. r.isArray() ? r.getColumnCount() : 1
  11858. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  11859. const _ = u.get(h, d), C = c.get(h, d);
  11860. if (f.isError())
  11861. return f;
  11862. if (_.isError())
  11863. return _;
  11864. if (C.isError())
  11865. return C;
  11866. const { isError: E, errorObject: b, variants: R } = I(f, _, C);
  11867. if (E)
  11868. return b;
  11869. const [p, N, M] = R, w = +p.getValue(), D = +N.getValue(), S = Math.floor(+M.getValue());
  11870. if (w <= 0 || w >= 1 || D <= 0 || S < 1)
  11871. return g.create(m.NUM);
  11872. const P = Math.abs(Wn(w / 2, 0, 1) * D / Math.sqrt(S));
  11873. return y.create(P);
  11874. });
  11875. return n === 1 && s === 1 ? l.get(0, 0) : l;
  11876. }
  11877. }
  11878. class Go extends V {
  11879. constructor() {
  11880. super(...arguments);
  11881. A(this, "minParams", 2);
  11882. A(this, "maxParams", 2);
  11883. }
  11884. calculate(e, t) {
  11885. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  11886. let u = e;
  11887. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  11888. return u;
  11889. let c = t;
  11890. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  11891. return c;
  11892. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  11893. return g.create(m.VALUE);
  11894. if (r * n !== s * o)
  11895. return g.create(m.NA);
  11896. const {
  11897. isError: l,
  11898. errorObject: f,
  11899. array1Values: h,
  11900. array2Values: d,
  11901. noCalculate: _
  11902. } = Je(
  11903. e,
  11904. t,
  11905. r * n,
  11906. n,
  11907. o
  11908. );
  11909. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  11910. }
  11911. _getResult(e, t) {
  11912. if (e.length === 0)
  11913. return g.create(m.DIV_BY_ZERO);
  11914. const r = e.length;
  11915. let n = 0, s = 0;
  11916. for (let l = 0; l < r; l++)
  11917. n += e[l], s += t[l];
  11918. const o = n / r, u = s / r;
  11919. let c = 0;
  11920. for (let l = 0; l < r; l++) {
  11921. const f = e[l] - o, h = t[l] - u;
  11922. c += f * h;
  11923. }
  11924. return y.create(c / r);
  11925. }
  11926. }
  11927. class Qo extends V {
  11928. constructor() {
  11929. super(...arguments);
  11930. A(this, "minParams", 3);
  11931. A(this, "maxParams", 3);
  11932. }
  11933. calculate(e, t, r) {
  11934. const n = Math.max(
  11935. e.isArray() ? e.getRowCount() : 1,
  11936. t.isArray() ? t.getRowCount() : 1,
  11937. r.isArray() ? r.getRowCount() : 1
  11938. ), s = Math.max(
  11939. e.isArray() ? e.getColumnCount() : 1,
  11940. t.isArray() ? t.getColumnCount() : 1,
  11941. r.isArray() ? r.getColumnCount() : 1
  11942. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  11943. const _ = u.get(h, d), C = c.get(h, d);
  11944. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  11945. });
  11946. return n === 1 && s === 1 ? l.get(0, 0) : l;
  11947. }
  11948. _handleSignleObject(e, t, r) {
  11949. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  11950. if (n)
  11951. return s;
  11952. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  11953. if (f < 0 || h <= 0)
  11954. return g.create(m.NUM);
  11955. let _;
  11956. return d ? _ = nm(f, h) : _ = sm(f, h), y.create(_);
  11957. }
  11958. }
  11959. class Wo extends V {
  11960. constructor() {
  11961. super(...arguments);
  11962. A(this, "minParams", 3);
  11963. A(this, "maxParams", 3);
  11964. }
  11965. calculate(e, t, r) {
  11966. const n = Math.max(
  11967. e.isArray() ? e.getRowCount() : 1,
  11968. t.isArray() ? t.getRowCount() : 1,
  11969. r.isArray() ? r.getRowCount() : 1
  11970. ), s = Math.max(
  11971. e.isArray() ? e.getColumnCount() : 1,
  11972. t.isArray() ? t.getColumnCount() : 1,
  11973. r.isArray() ? r.getColumnCount() : 1
  11974. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  11975. const _ = u.get(h, d), C = c.get(h, d);
  11976. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  11977. });
  11978. return n === 1 && s === 1 ? l.get(0, 0) : l;
  11979. }
  11980. _handleSignleObject(e, t, r) {
  11981. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  11982. if (n)
  11983. return s;
  11984. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = Math.floor(+l.getValue());
  11985. if (f < 0 || h < 1 || h > 10 ** 10 || d < 1 || d > 10 ** 10)
  11986. return g.create(m.NUM);
  11987. const _ = 1 - Pa(f, h, d);
  11988. return y.create(_);
  11989. }
  11990. }
  11991. class qo extends V {
  11992. constructor() {
  11993. super(...arguments);
  11994. A(this, "minParams", 3);
  11995. A(this, "maxParams", 3);
  11996. }
  11997. calculate(e, t, r) {
  11998. const n = Math.max(
  11999. e.isArray() ? e.getRowCount() : 1,
  12000. t.isArray() ? t.getRowCount() : 1,
  12001. r.isArray() ? r.getRowCount() : 1
  12002. ), s = Math.max(
  12003. e.isArray() ? e.getColumnCount() : 1,
  12004. t.isArray() ? t.getColumnCount() : 1,
  12005. r.isArray() ? r.getColumnCount() : 1
  12006. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12007. const _ = u.get(h, d), C = c.get(h, d);
  12008. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12009. });
  12010. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12011. }
  12012. _handleSignleObject(e, t, r) {
  12013. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12014. if (n)
  12015. return s;
  12016. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = Math.floor(+l.getValue());
  12017. if (f < 0 || f > 1 || h < 1 || h > 10 ** 10 || d < 1 || d > 10 ** 10)
  12018. return g.create(m.NUM);
  12019. const _ = Lo(1 - f, h, d);
  12020. return Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  12021. }
  12022. }
  12023. class Ko extends V {
  12024. constructor() {
  12025. super(...arguments);
  12026. A(this, "minParams", 2);
  12027. A(this, "maxParams", 2);
  12028. }
  12029. calculate(e, t) {
  12030. const {
  12031. isError: r,
  12032. errorObject: n,
  12033. variance: s,
  12034. ns1: o
  12035. } = this._getValues(e);
  12036. if (r)
  12037. return n;
  12038. const {
  12039. isError: u,
  12040. errorObject: c,
  12041. variance: l,
  12042. ns1: f
  12043. } = this._getValues(t);
  12044. if (u)
  12045. return c;
  12046. let h = 2 * (1 - Pa(s / l, o, f));
  12047. return h > 1 && (h = 2 - h), y.create(h);
  12048. }
  12049. // eslint-disable-next-line
  12050. _getValues(e) {
  12051. let t = 0, r = 0;
  12052. const n = e.isArray() ? e.getRowCount() : 1, s = e.isArray() ? e.getColumnCount() : 1;
  12053. if (n === 1 && s === 1) {
  12054. const f = e.isArray() ? e.get(0, 0) : e;
  12055. return f.isError() ? {
  12056. isError: !0,
  12057. errorObject: f,
  12058. variance: t,
  12059. ns1: r
  12060. } : f.isNull() ? {
  12061. isError: !0,
  12062. errorObject: g.create(m.VALUE),
  12063. variance: t,
  12064. ns1: r
  12065. } : {
  12066. isError: !0,
  12067. errorObject: g.create(m.DIV_BY_ZERO),
  12068. variance: t,
  12069. ns1: r
  12070. };
  12071. }
  12072. const o = [];
  12073. let u = 0;
  12074. for (let f = 0; f < n; f++)
  12075. for (let h = 0; h < s; h++) {
  12076. const d = e.isArray() ? e.get(f, h) : e;
  12077. if (d.isError())
  12078. return {
  12079. isError: !0,
  12080. errorObject: d,
  12081. variance: t,
  12082. ns1: r
  12083. };
  12084. if (d.isNull() || d.isBoolean())
  12085. continue;
  12086. const _ = d.getValue();
  12087. Q(_) && (o.push(+_), u += +_);
  12088. }
  12089. if (o.length <= 1)
  12090. return {
  12091. isError: !0,
  12092. errorObject: g.create(m.DIV_BY_ZERO),
  12093. variance: t,
  12094. ns1: r
  12095. };
  12096. const c = u / o.length;
  12097. let l = 0;
  12098. for (let f = 0; f < o.length; f++)
  12099. l += (o[f] - c) ** 2;
  12100. return r = o.length - 1, t = l / r, t === 0 ? {
  12101. isError: !0,
  12102. errorObject: g.create(m.DIV_BY_ZERO),
  12103. variance: t,
  12104. ns1: r
  12105. } : {
  12106. isError: !1,
  12107. errorObject: null,
  12108. variance: t,
  12109. ns1: r
  12110. };
  12111. }
  12112. }
  12113. class Xo extends V {
  12114. constructor() {
  12115. super(...arguments);
  12116. A(this, "minParams", 4);
  12117. A(this, "maxParams", 4);
  12118. }
  12119. calculate(e, t, r, n) {
  12120. const s = Math.max(
  12121. e.isArray() ? e.getRowCount() : 1,
  12122. t.isArray() ? t.getRowCount() : 1,
  12123. r.isArray() ? r.getRowCount() : 1,
  12124. n.isArray() ? n.getRowCount() : 1
  12125. ), o = Math.max(
  12126. e.isArray() ? e.getColumnCount() : 1,
  12127. t.isArray() ? t.getColumnCount() : 1,
  12128. r.isArray() ? r.getColumnCount() : 1,
  12129. n.isArray() ? n.getColumnCount() : 1
  12130. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  12131. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  12132. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  12133. });
  12134. return s === 1 && o === 1 ? h.get(0, 0) : h;
  12135. }
  12136. _handleSignleObject(e, t, r, n) {
  12137. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  12138. if (s)
  12139. return o;
  12140. const [c, l, f, h] = u, d = +c.getValue(), _ = +l.getValue(), C = +f.getValue(), E = +h.getValue();
  12141. if (d < 0 || _ <= 0 || C <= 0)
  12142. return g.create(m.NUM);
  12143. let b;
  12144. return E ? b = am(d, _, C) : b = im(d, _, C), y.create(b);
  12145. }
  12146. }
  12147. class Zo extends V {
  12148. constructor() {
  12149. super(...arguments);
  12150. A(this, "minParams", 3);
  12151. A(this, "maxParams", 3);
  12152. }
  12153. calculate(e, t, r) {
  12154. const n = Math.max(
  12155. e.isArray() ? e.getRowCount() : 1,
  12156. t.isArray() ? t.getRowCount() : 1,
  12157. r.isArray() ? r.getRowCount() : 1
  12158. ), s = Math.max(
  12159. e.isArray() ? e.getColumnCount() : 1,
  12160. t.isArray() ? t.getColumnCount() : 1,
  12161. r.isArray() ? r.getColumnCount() : 1
  12162. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12163. const _ = u.get(h, d), C = c.get(h, d);
  12164. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12165. });
  12166. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12167. }
  12168. _handleSignleObject(e, t, r) {
  12169. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12170. if (n)
  12171. return s;
  12172. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  12173. if (f < 0 || f > 1 || h <= 0 || d <= 0)
  12174. return g.create(m.NUM);
  12175. const _ = om(f, h, d);
  12176. return Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  12177. }
  12178. }
  12179. class zo extends V {
  12180. constructor() {
  12181. super(...arguments);
  12182. A(this, "minParams", 3);
  12183. A(this, "maxParams", 3);
  12184. }
  12185. calculate(e, t, r) {
  12186. const n = Math.max(
  12187. e.isArray() ? e.getRowCount() : 1,
  12188. t.isArray() ? t.getRowCount() : 1,
  12189. r.isArray() ? r.getRowCount() : 1
  12190. ), s = Math.max(
  12191. e.isArray() ? e.getColumnCount() : 1,
  12192. t.isArray() ? t.getColumnCount() : 1,
  12193. r.isArray() ? r.getColumnCount() : 1
  12194. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12195. const _ = u.get(h, d), C = c.get(h, d);
  12196. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12197. });
  12198. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12199. }
  12200. _handleSignleObject(e, t, r) {
  12201. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12202. if (n)
  12203. return s;
  12204. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  12205. if (f <= 0 || f >= 1 || d <= 0)
  12206. return g.create(m.NUM);
  12207. const _ = lm(f, h, d);
  12208. return Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  12209. }
  12210. }
  12211. class Jo extends V {
  12212. constructor() {
  12213. super(...arguments);
  12214. A(this, "minParams", 1);
  12215. A(this, "maxParams", 255);
  12216. }
  12217. calculate(...e) {
  12218. const t = {};
  12219. let r = 0, n = 1;
  12220. for (let s = 0; s < e.length; s++) {
  12221. const o = e[s];
  12222. if (o.isError())
  12223. return o;
  12224. if (o.isString()) {
  12225. const l = o.convertToNumberObjectValue();
  12226. if (l.isError())
  12227. return l;
  12228. }
  12229. const u = o.isArray() ? o.getRowCount() : 1, c = o.isArray() ? o.getColumnCount() : 1;
  12230. for (let l = 0; l < u; l++)
  12231. for (let f = 0; f < c; f++) {
  12232. const h = o.isArray() ? o.get(l, f) : o;
  12233. if (h.isError())
  12234. return h;
  12235. if (h.isNull() || h.isBoolean() || h.isString())
  12236. continue;
  12237. const d = h.getValue();
  12238. Q(d) && (t[+d] ? (t[+d].count++, t[+d].count > n && (n = t[+d].count)) : t[+d] = { count: 1, order: r++ });
  12239. }
  12240. }
  12241. return r === 0 || n === 1 ? new g(m.NA) : this._getResult(t, n);
  12242. }
  12243. _getResult(e, t) {
  12244. const r = Object.entries(e).filter(([n, { count: s }]) => s === t).sort((n, s) => n[1].order - s[1].order).map(([n]) => +n);
  12245. return y.create(r[0]);
  12246. }
  12247. }
  12248. class eu extends V {
  12249. constructor() {
  12250. super(...arguments);
  12251. A(this, "minParams", 4);
  12252. A(this, "maxParams", 4);
  12253. }
  12254. calculate(e, t, r, n) {
  12255. const s = Math.max(
  12256. e.isArray() ? e.getRowCount() : 1,
  12257. t.isArray() ? t.getRowCount() : 1,
  12258. r.isArray() ? r.getRowCount() : 1,
  12259. n.isArray() ? n.getRowCount() : 1
  12260. ), o = Math.max(
  12261. e.isArray() ? e.getColumnCount() : 1,
  12262. t.isArray() ? t.getColumnCount() : 1,
  12263. r.isArray() ? r.getColumnCount() : 1,
  12264. n.isArray() ? n.getColumnCount() : 1
  12265. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  12266. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  12267. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  12268. });
  12269. return s === 1 && o === 1 ? h.get(0, 0) : h;
  12270. }
  12271. _handleSignleObject(e, t, r, n) {
  12272. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  12273. if (s)
  12274. return o;
  12275. const [c, l, f, h] = u, d = +c.getValue(), _ = +l.getValue(), C = +f.getValue(), E = +h.getValue();
  12276. if (C <= 0)
  12277. return g.create(m.NUM);
  12278. let b;
  12279. return E ? b = kr(d, _, C) : b = vo(d, _, C), y.create(b);
  12280. }
  12281. }
  12282. class tu extends V {
  12283. constructor() {
  12284. super(...arguments);
  12285. A(this, "minParams", 3);
  12286. A(this, "maxParams", 3);
  12287. }
  12288. calculate(e, t, r) {
  12289. const n = Math.max(
  12290. e.isArray() ? e.getRowCount() : 1,
  12291. t.isArray() ? t.getRowCount() : 1,
  12292. r.isArray() ? r.getRowCount() : 1
  12293. ), s = Math.max(
  12294. e.isArray() ? e.getColumnCount() : 1,
  12295. t.isArray() ? t.getColumnCount() : 1,
  12296. r.isArray() ? r.getColumnCount() : 1
  12297. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12298. const _ = u.get(h, d), C = c.get(h, d);
  12299. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12300. });
  12301. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12302. }
  12303. _handleSignleObject(e, t, r) {
  12304. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12305. if (n)
  12306. return s;
  12307. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  12308. if (f <= 0 || f >= 1 || d <= 0)
  12309. return g.create(m.NUM);
  12310. const _ = Wn(f, h, d);
  12311. return y.create(_);
  12312. }
  12313. }
  12314. class ru extends V {
  12315. constructor() {
  12316. super(...arguments);
  12317. A(this, "minParams", 1);
  12318. A(this, "maxParams", 1);
  12319. }
  12320. calculate(e) {
  12321. if (e.isArray()) {
  12322. const t = e.mapValue((r) => this._handleSignleObject(r));
  12323. return e.getRowCount() === 1 && e.getColumnCount() === 1 ? t.get(0, 0) : t;
  12324. }
  12325. return this._handleSignleObject(e);
  12326. }
  12327. _handleSignleObject(e) {
  12328. const { isError: t, errorObject: r, variants: n } = I(e);
  12329. if (t)
  12330. return r;
  12331. const [s] = n, o = +s.getValue();
  12332. if (o <= 0 || o >= 1)
  12333. return g.create(m.NUM);
  12334. const u = Wn(o, 0, 1);
  12335. return y.create(u);
  12336. }
  12337. }
  12338. class nu extends V {
  12339. constructor() {
  12340. super(...arguments);
  12341. A(this, "minParams", 2);
  12342. A(this, "maxParams", 2);
  12343. }
  12344. calculate(e, t) {
  12345. const r = this._getValues(e);
  12346. if (t.isArray()) {
  12347. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  12348. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  12349. }
  12350. return this._handleSingleObject(r, t);
  12351. }
  12352. _handleSingleObject(e, t) {
  12353. if (e instanceof g)
  12354. return e;
  12355. const { isError: r, errorObject: n, variants: s } = I(t);
  12356. if (r)
  12357. return n;
  12358. const [o] = s, u = +o.getValue(), c = e.length;
  12359. if (u < 0 || u > 1)
  12360. return g.create(m.NUM);
  12361. const l = u * (c - 1), f = Math.floor(l), h = l - f;
  12362. if (h === 0)
  12363. return y.create(e[f]);
  12364. const d = e[f] + h * (e[f + 1] - e[f]);
  12365. return y.create(d);
  12366. }
  12367. _getValues(e) {
  12368. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  12369. for (let s = 0; s < t; s++)
  12370. for (let o = 0; o < r; o++) {
  12371. const u = e.isArray() ? e.get(s, o) : e;
  12372. if (u.isError())
  12373. return u;
  12374. if (u.isNull() || u.isBoolean() || u.isString())
  12375. continue;
  12376. const c = u.getValue();
  12377. Q(c) && n.push(+c);
  12378. }
  12379. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  12380. }
  12381. }
  12382. class su extends V {
  12383. constructor() {
  12384. super(...arguments);
  12385. A(this, "minParams", 2);
  12386. A(this, "maxParams", 3);
  12387. }
  12388. calculate(e, t, r) {
  12389. const n = this._getValues(e);
  12390. let s = r != null ? r : y.create(3);
  12391. s.isNull() && (s = y.create(3));
  12392. const o = Math.max(
  12393. t.isArray() ? t.getRowCount() : 1,
  12394. s.isArray() ? s.getRowCount() : 1
  12395. ), u = Math.max(
  12396. t.isArray() ? t.getColumnCount() : 1,
  12397. s.isArray() ? s.getColumnCount() : 1
  12398. ), c = O(o, u, t, g.create(m.NA)), l = O(o, u, s, g.create(m.NA)), f = c.mapValue((h, d, _) => {
  12399. const C = l.get(d, _);
  12400. return h.isError() ? h : C.isError() ? C : this._handleSingleObject(n, h, C);
  12401. });
  12402. return o === 1 && u === 1 ? f.get(0, 0) : f;
  12403. }
  12404. _handleSingleObject(e, t, r) {
  12405. if (e instanceof g)
  12406. return e;
  12407. const { isError: n, errorObject: s, variants: o } = I(t, r);
  12408. if (n)
  12409. return s;
  12410. const [u, c] = o, l = +u.getValue(), f = Math.floor(+c.getValue()), h = e.length;
  12411. if (h === 0 || l < e[0] || l > e[h - 1])
  12412. return g.create(m.NA);
  12413. if (h === 1)
  12414. return l === e[0] ? y.create(1) : g.create(m.NA);
  12415. let d = 0, _ = !1, C = 0;
  12416. for (; !_ && C < h; )
  12417. l === e[C] ? (d = C / (h - 1), _ = !0) : l > e[C] && C + 1 < h && l < e[C + 1] && (d = (C + (l - e[C]) / (e[C + 1] - e[C])) / (h - 1), _ = !0), C++;
  12418. return _ ? f < 1 ? g.create(m.NUM) : (d = We(d, f), y.create(d)) : g.create(m.NA);
  12419. }
  12420. _getValues(e) {
  12421. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  12422. for (let s = 0; s < t; s++)
  12423. for (let o = 0; o < r; o++) {
  12424. const u = e.isArray() ? e.get(s, o) : e;
  12425. if (u.isError())
  12426. return u;
  12427. if (u.isNull() || u.isBoolean())
  12428. continue;
  12429. const c = u.getValue();
  12430. Q(c) && n.push(+c);
  12431. }
  12432. return n.sort((s, o) => s - o);
  12433. }
  12434. }
  12435. class au extends V {
  12436. constructor() {
  12437. super(...arguments);
  12438. A(this, "minParams", 3);
  12439. A(this, "maxParams", 3);
  12440. }
  12441. calculate(e, t, r) {
  12442. const n = Math.max(
  12443. e.isArray() ? e.getRowCount() : 1,
  12444. t.isArray() ? t.getRowCount() : 1,
  12445. r.isArray() ? r.getRowCount() : 1
  12446. ), s = Math.max(
  12447. e.isArray() ? e.getColumnCount() : 1,
  12448. t.isArray() ? t.getColumnCount() : 1,
  12449. r.isArray() ? r.getColumnCount() : 1
  12450. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12451. const _ = u.get(h, d), C = c.get(h, d);
  12452. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12453. });
  12454. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12455. }
  12456. _handleSignleObject(e, t, r) {
  12457. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12458. if (n)
  12459. return s;
  12460. const [u, c, l] = o, f = Math.floor(+u.getValue()), h = +c.getValue(), d = +l.getValue();
  12461. if (f < 0 || h < 0)
  12462. return g.create(m.NUM);
  12463. let _;
  12464. return d ? _ = hm(f, h) : _ = To(f, h), y.create(_);
  12465. }
  12466. }
  12467. class iu extends V {
  12468. constructor() {
  12469. super(...arguments);
  12470. A(this, "minParams", 2);
  12471. A(this, "maxParams", 2);
  12472. }
  12473. calculate(e, t) {
  12474. const r = this._getValues(e);
  12475. if (t.isArray()) {
  12476. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  12477. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  12478. }
  12479. return this._handleSingleObject(r, t);
  12480. }
  12481. _handleSingleObject(e, t) {
  12482. if (e instanceof g)
  12483. return e;
  12484. const { isError: r, errorObject: n, variants: s } = I(t);
  12485. if (r)
  12486. return n;
  12487. const [o] = s, u = Math.floor(+o.getValue());
  12488. if (u < 0 || u > 4)
  12489. return g.create(m.NUM);
  12490. const c = u / 4, l = e.length, f = c * (l - 1), h = Math.floor(f), d = f - h;
  12491. if (d === 0)
  12492. return y.create(e[h]);
  12493. const _ = e[h] + d * (e[h + 1] - e[h]);
  12494. return y.create(_);
  12495. }
  12496. _getValues(e) {
  12497. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  12498. for (let s = 0; s < t; s++)
  12499. for (let o = 0; o < r; o++) {
  12500. const u = e.isArray() ? e.get(s, o) : e;
  12501. if (u.isError())
  12502. return u;
  12503. if (u.isNull() || u.isBoolean())
  12504. continue;
  12505. const c = u.getValue();
  12506. Q(c) && n.push(+c);
  12507. }
  12508. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  12509. }
  12510. }
  12511. class ou extends V {
  12512. constructor() {
  12513. super(...arguments);
  12514. A(this, "minParams", 1);
  12515. A(this, "maxParams", 255);
  12516. }
  12517. calculate(...e) {
  12518. const t = this.flattenArray(e);
  12519. return t.isError() ? t : t.std();
  12520. }
  12521. }
  12522. class uu extends V {
  12523. constructor() {
  12524. super(...arguments);
  12525. A(this, "minParams", 1);
  12526. A(this, "maxParams", 255);
  12527. }
  12528. calculate(...e) {
  12529. const t = this.flattenArray(e);
  12530. return t.isError() ? t : t.std(1);
  12531. }
  12532. }
  12533. class cu extends V {
  12534. constructor() {
  12535. super(...arguments);
  12536. A(this, "minParams", 2);
  12537. A(this, "maxParams", 2);
  12538. }
  12539. calculate(e, t) {
  12540. const r = Math.max(
  12541. e.isArray() ? e.getRowCount() : 1,
  12542. t.isArray() ? t.getRowCount() : 1
  12543. ), n = Math.max(
  12544. e.isArray() ? e.getColumnCount() : 1,
  12545. t.isArray() ? t.getColumnCount() : 1
  12546. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  12547. const h = o.get(l, f);
  12548. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  12549. });
  12550. return r === 1 && n === 1 ? u.get(0, 0) : u;
  12551. }
  12552. _handleSignleObject(e, t) {
  12553. const { isError: r, errorObject: n, variants: s } = I(e, t);
  12554. if (r)
  12555. return n;
  12556. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  12557. if (c <= 0 || c > 1 || l < 1 || l > 10 ** 10)
  12558. return g.create(m.NUM);
  12559. const f = Math.abs(qn(c / 2, l));
  12560. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  12561. }
  12562. }
  12563. class lu extends V {
  12564. constructor() {
  12565. super(...arguments);
  12566. A(this, "minParams", 4);
  12567. A(this, "maxParams", 4);
  12568. }
  12569. // eslint-disable-next-line
  12570. calculate(e, t, r, n) {
  12571. const { isError: s, errorObject: o, array1Values: u, array2Values: c } = this._handleArray1AndArray2(e, t), l = this._getArrayValues(e), f = this._getArrayValues(t), h = Math.max(
  12572. r.isArray() ? r.getRowCount() : 1,
  12573. n.isArray() ? n.getRowCount() : 1
  12574. ), d = Math.max(
  12575. r.isArray() ? r.getColumnCount() : 1,
  12576. n.isArray() ? n.getColumnCount() : 1
  12577. ), _ = O(h, d, r, g.create(m.NA)), C = O(h, d, n, g.create(m.NA)), E = _.mapValue((b, R, p) => {
  12578. const N = C.get(R, p);
  12579. if (e.isError())
  12580. return e;
  12581. if (t.isError())
  12582. return t;
  12583. if (b.isError())
  12584. return b;
  12585. if (N.isError())
  12586. return N;
  12587. const { isError: M, errorObject: w, variants: D } = I(b, N);
  12588. if (M)
  12589. return w;
  12590. const [S, P] = D, U = Math.floor(+S.getValue()), x = Math.floor(+P.getValue());
  12591. return ![1, 2].includes(U) || ![1, 2, 3].includes(x) ? g.create(m.NUM) : x === 1 && s ? o : x !== 1 && l instanceof g ? l : x !== 1 && f instanceof g ? f : this._handleSignleObject(
  12592. x === 1 ? u : l,
  12593. x === 1 ? c : f,
  12594. U,
  12595. x
  12596. );
  12597. });
  12598. return h === 1 && d === 1 ? E.get(0, 0) : E;
  12599. }
  12600. _handleSignleObject(e, t, r, n) {
  12601. if (e.length < 2 || t.length < 2)
  12602. return g.create(m.DIV_BY_ZERO);
  12603. const { isError: s, errorObject: o, x: u, degFreedom: c } = this._getTDistParamByArrayValues(e, t, n);
  12604. if (s)
  12605. return o;
  12606. let l = $r(-u, c);
  12607. return r === 2 && (l *= 2), Number.isNaN(l) || !Number.isFinite(l) ? g.create(m.NUM) : y.create(l);
  12608. }
  12609. _getArrayValues(e) {
  12610. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  12611. for (let s = 0; s < t; s++)
  12612. for (let o = 0; o < r; o++) {
  12613. const u = e.isArray() ? e.get(s, o) : e;
  12614. if (u.isError())
  12615. return u;
  12616. if (u.isNull()) {
  12617. if (t * r === 1)
  12618. return g.create(m.VALUE);
  12619. continue;
  12620. }
  12621. u.isBoolean() || u.isString() || n.push(+u.getValue());
  12622. }
  12623. return n;
  12624. }
  12625. // eslint-disable-next-line
  12626. _handleArray1AndArray2(e, t) {
  12627. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  12628. let u = e;
  12629. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  12630. return {
  12631. isError: !0,
  12632. errorObject: u,
  12633. array1Values: [],
  12634. array2Values: []
  12635. };
  12636. let c = t;
  12637. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  12638. return {
  12639. isError: !0,
  12640. errorObject: c,
  12641. array1Values: [],
  12642. array2Values: []
  12643. };
  12644. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  12645. return {
  12646. isError: !0,
  12647. errorObject: g.create(m.VALUE),
  12648. array1Values: [],
  12649. array2Values: []
  12650. };
  12651. if (r * n !== s * o)
  12652. return {
  12653. isError: !0,
  12654. errorObject: g.create(m.NA),
  12655. array1Values: [],
  12656. array2Values: []
  12657. };
  12658. const {
  12659. isError: l,
  12660. errorObject: f,
  12661. array1Values: h,
  12662. array2Values: d,
  12663. noCalculate: _
  12664. } = Je(
  12665. e,
  12666. t,
  12667. r * n,
  12668. n,
  12669. o
  12670. );
  12671. return l ? {
  12672. isError: !0,
  12673. errorObject: f,
  12674. array1Values: [],
  12675. array2Values: []
  12676. } : _ || h.length < 2 ? {
  12677. isError: !0,
  12678. errorObject: g.create(m.DIV_BY_ZERO),
  12679. array1Values: [],
  12680. array2Values: []
  12681. } : {
  12682. isError: !1,
  12683. errorObject: null,
  12684. array1Values: h,
  12685. array2Values: d
  12686. };
  12687. }
  12688. _getTDistParamByArrayValues(e, t, r) {
  12689. return r === 1 ? this._getTDistParamByType1(e, t) : r === 2 ? this._getTDistParamByType2(e, t) : this._getTDistParamByType3(e, t);
  12690. }
  12691. _getTDistParamByType1(e, t) {
  12692. const r = e.length;
  12693. let n = 0, s = 0, o = 0;
  12694. for (let h = 0; h < r; h++)
  12695. n += e[h], s += t[h], o += (e[h] - t[h]) ** 2;
  12696. const u = n - s, c = r * o - u ** 2, l = r - 1;
  12697. return c === 0 ? {
  12698. isError: !0,
  12699. errorObject: g.create(m.DIV_BY_ZERO),
  12700. x: 0,
  12701. degFreedom: l
  12702. } : {
  12703. isError: !1,
  12704. errorObject: null,
  12705. x: Math.abs(u) * Math.sqrt(l / c),
  12706. degFreedom: l
  12707. };
  12708. }
  12709. _getTDistParamByType2(e, t) {
  12710. const r = e.length, n = t.length;
  12711. let s = 0, o = 0;
  12712. for (let E = 0; E < r; E++)
  12713. s += e[E], o += e[E] ** 2;
  12714. let u = 0, c = 0;
  12715. for (let E = 0; E < n; E++)
  12716. u += t[E], c += t[E] ** 2;
  12717. const l = o - s ** 2 / r, f = c - u ** 2 / n, h = Math.sqrt(l + f);
  12718. if (h === 0)
  12719. return {
  12720. isError: !0,
  12721. errorObject: g.create(m.DIV_BY_ZERO),
  12722. x: 0,
  12723. degFreedom: 0
  12724. };
  12725. const d = r - 1 + n - 1, _ = Math.sqrt(r * n * d / (r + n));
  12726. return {
  12727. isError: !1,
  12728. errorObject: null,
  12729. x: Math.abs(s / r - u / n) / h * _,
  12730. degFreedom: d
  12731. };
  12732. }
  12733. _getTDistParamByType3(e, t) {
  12734. const r = e.length, n = t.length;
  12735. let s = 0, o = 0;
  12736. for (let C = 0; C < r; C++)
  12737. s += e[C], o += e[C] ** 2;
  12738. let u = 0, c = 0;
  12739. for (let C = 0; C < n; C++)
  12740. u += t[C], c += t[C] ** 2;
  12741. const l = (o - s ** 2 / r) / (r * (r - 1)), f = (c - u ** 2 / n) / (n * (n - 1));
  12742. if (l + f === 0)
  12743. return {
  12744. isError: !0,
  12745. errorObject: g.create(m.DIV_BY_ZERO),
  12746. x: 0,
  12747. degFreedom: 0
  12748. };
  12749. const h = l / (l + f), d = Math.abs(s / r - u / n) / Math.sqrt(l + f), _ = 1 / (h ** 2 / (r - 1) + (1 - h) ** 2 / (n - 1));
  12750. return {
  12751. isError: !1,
  12752. errorObject: null,
  12753. x: d,
  12754. degFreedom: _
  12755. };
  12756. }
  12757. }
  12758. class fu extends V {
  12759. constructor() {
  12760. super(...arguments);
  12761. A(this, "minParams", 1);
  12762. A(this, "maxParams", 255);
  12763. }
  12764. calculate(...e) {
  12765. const t = this.flattenArray(e);
  12766. return t.isError() ? t : t.var();
  12767. }
  12768. }
  12769. class hu extends V {
  12770. constructor() {
  12771. super(...arguments);
  12772. A(this, "minParams", 1);
  12773. A(this, "maxParams", 255);
  12774. }
  12775. calculate(...e) {
  12776. const t = this.flattenArray(e);
  12777. return t.isError() ? t : t.var(1);
  12778. }
  12779. }
  12780. class mu extends V {
  12781. constructor() {
  12782. super(...arguments);
  12783. A(this, "minParams", 4);
  12784. A(this, "maxParams", 4);
  12785. }
  12786. calculate(e, t, r, n) {
  12787. const s = Math.max(
  12788. e.isArray() ? e.getRowCount() : 1,
  12789. t.isArray() ? t.getRowCount() : 1,
  12790. r.isArray() ? r.getRowCount() : 1,
  12791. n.isArray() ? n.getRowCount() : 1
  12792. ), o = Math.max(
  12793. e.isArray() ? e.getColumnCount() : 1,
  12794. t.isArray() ? t.getColumnCount() : 1,
  12795. r.isArray() ? r.getColumnCount() : 1,
  12796. n.isArray() ? n.getColumnCount() : 1
  12797. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  12798. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  12799. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  12800. });
  12801. return s === 1 && o === 1 ? h.get(0, 0) : h;
  12802. }
  12803. _handleSignleObject(e, t, r, n) {
  12804. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  12805. if (s)
  12806. return o;
  12807. const [c, l, f, h] = u, d = +c.getValue(), _ = +l.getValue(), C = +f.getValue(), E = +h.getValue();
  12808. if (d < 0 || _ <= 0 || C <= 0)
  12809. return g.create(m.NUM);
  12810. const b = Math.exp(-((d / C) ** _));
  12811. let R;
  12812. return E ? R = 1 - b : R = _ / C ** _ * d ** (_ - 1) * b, Number.isNaN(R) || !Number.isFinite(R) ? g.create(m.NUM) : y.create(R);
  12813. }
  12814. }
  12815. class gu extends V {
  12816. constructor() {
  12817. super(...arguments);
  12818. A(this, "minParams", 2);
  12819. A(this, "maxParams", 3);
  12820. }
  12821. calculate(e, t, r) {
  12822. const n = this._getArrayValues(e), s = Math.max(
  12823. t.isArray() ? t.getRowCount() : 1,
  12824. r != null && r.isArray() ? r.getRowCount() : 1
  12825. ), o = Math.max(
  12826. t.isArray() ? t.getColumnCount() : 1,
  12827. r != null && r.isArray() ? r.getColumnCount() : 1
  12828. ), u = O(s, o, t, g.create(m.NA)), c = r ? O(s, o, r, g.create(m.NA)) : void 0, l = u.mapValue((f, h, d) => {
  12829. if (n instanceof g)
  12830. return n;
  12831. if (f.isError())
  12832. return f;
  12833. const _ = r ? c.get(h, d) : void 0;
  12834. return _ != null && _.isError() ? _ : n.length === 0 ? g.create(m.NA) : n.length === 1 ? g.create(m.DIV_BY_ZERO) : this._handleSignleObject(n, f, _);
  12835. });
  12836. return s === 1 && o === 1 ? l.get(0, 0) : l;
  12837. }
  12838. _handleSignleObject(e, t, r) {
  12839. const { isError: n, errorObject: s, variants: o } = I(t);
  12840. if (n)
  12841. return s;
  12842. const [u] = o, c = +u.getValue(), l = e.length;
  12843. let f = 0, h = 0;
  12844. for (let E = 0; E < l; E++)
  12845. f += e[E], h += e[E] ** 2;
  12846. let d = 0;
  12847. if (r !== void 0) {
  12848. const { isError: E, errorObject: b, variants: R } = I(r);
  12849. if (E)
  12850. return b;
  12851. const [p] = R;
  12852. d = +p.getValue();
  12853. } else {
  12854. const E = f / l;
  12855. d = Math.sqrt((h - 2 * E * f + l * E ** 2) / (l - 1));
  12856. }
  12857. if (d <= 0)
  12858. return g.create(m.NUM);
  12859. const _ = (f / l - c) / (d / Math.sqrt(l)), C = 1 - kr(_, 0, 1);
  12860. return Number.isNaN(C) || !Number.isFinite(C) ? g.create(m.NUM) : y.create(C);
  12861. }
  12862. _getArrayValues(e) {
  12863. const t = [], r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1;
  12864. for (let s = 0; s < r; s++)
  12865. for (let o = 0; o < n; o++) {
  12866. const u = e.isArray() ? e.get(s, o) : e;
  12867. if (u.isError())
  12868. return u;
  12869. if (u.isNull() || u.isBoolean() || u.isString())
  12870. continue;
  12871. const c = u.getValue();
  12872. Q(c) && t.push(+c);
  12873. }
  12874. return t;
  12875. }
  12876. }
  12877. class Cm extends V {
  12878. constructor() {
  12879. super(...arguments);
  12880. A(this, "minParams", 3);
  12881. A(this, "maxParams", 5);
  12882. }
  12883. calculate(e, t, r, n, s) {
  12884. let o = n != null ? n : y.create(0), u = s != null ? s : y.create(1);
  12885. o.isNull() && (o = y.create(0)), u.isNull() && (u = y.create(1));
  12886. const c = Math.max(
  12887. e.isArray() ? e.getRowCount() : 1,
  12888. t.isArray() ? t.getRowCount() : 1,
  12889. r.isArray() ? r.getRowCount() : 1,
  12890. o.isArray() ? o.getRowCount() : 1,
  12891. u.isArray() ? u.getRowCount() : 1
  12892. ), l = Math.max(
  12893. e.isArray() ? e.getColumnCount() : 1,
  12894. t.isArray() ? t.getColumnCount() : 1,
  12895. r.isArray() ? r.getColumnCount() : 1,
  12896. o.isArray() ? o.getColumnCount() : 1,
  12897. u.isArray() ? u.getColumnCount() : 1
  12898. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.mapValue((b, R, p) => {
  12899. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p);
  12900. return this._handleSignleObject(b, N, M, w, D);
  12901. });
  12902. return c === 1 && l === 1 ? E.get(0, 0) : E;
  12903. }
  12904. _handleSignleObject(e, t, r, n, s) {
  12905. if (e.isError())
  12906. return e;
  12907. if (t.isError())
  12908. return t;
  12909. if (r.isError())
  12910. return r;
  12911. if (n.isError())
  12912. return n;
  12913. if (s.isError())
  12914. return s;
  12915. const { isError: o, errorObject: u, variants: c } = I(e, t, r, n, s);
  12916. if (o)
  12917. return u;
  12918. const [l, f, h, d, _] = c, C = +l.getValue(), E = +f.getValue(), b = +h.getValue(), R = +d.getValue(), p = +_.getValue();
  12919. if (E <= 0 || b <= 0 || C < R || C > p || R === p)
  12920. return g.create(m.NUM);
  12921. const N = Do((C - R) / (p - R), E, b);
  12922. return y.create(N);
  12923. }
  12924. }
  12925. var le = /* @__PURE__ */ ((i) => (i.BETADIST = "BETADIST", i.BETAINV = "BETAINV", i.BINOMDIST = "BINOMDIST", i.CHIDIST = "CHIDIST", i.CHIINV = "CHIINV", i.CHITEST = "CHITEST", i.CONFIDENCE = "CONFIDENCE", i.COVAR = "COVAR", i.CRITBINOM = "CRITBINOM", i.EXPONDIST = "EXPONDIST", i.FDIST = "FDIST", i.FINV = "FINV", i.FTEST = "FTEST", i.GAMMADIST = "GAMMADIST", i.GAMMAINV = "GAMMAINV", i.HYPGEOMDIST = "HYPGEOMDIST", i.LOGINV = "LOGINV", i.LOGNORMDIST = "LOGNORMDIST", i.MODE = "MODE", i.NEGBINOMDIST = "NEGBINOMDIST", i.NORMDIST = "NORMDIST", i.NORMINV = "NORMINV", i.NORMSDIST = "NORMSDIST", i.NORMSINV = "NORMSINV", i.PERCENTILE = "PERCENTILE", i.PERCENTRANK = "PERCENTRANK", i.POISSON = "POISSON", i.QUARTILE = "QUARTILE", i.RANK = "RANK", i.STDEV = "STDEV", i.STDEVP = "STDEVP", i.TDIST = "TDIST", i.TINV = "TINV", i.TTEST = "TTEST", i.VAR = "VAR", i.VARP = "VARP", i.WEIBULL = "WEIBULL", i.ZTEST = "ZTEST", i))(le || {});
  12926. class _m extends V {
  12927. constructor() {
  12928. super(...arguments);
  12929. A(this, "minParams", 4);
  12930. A(this, "maxParams", 4);
  12931. }
  12932. calculate(e, t, r, n) {
  12933. const s = Math.max(
  12934. e.isArray() ? e.getRowCount() : 1,
  12935. t.isArray() ? t.getRowCount() : 1,
  12936. r.isArray() ? r.getRowCount() : 1,
  12937. n.isArray() ? n.getRowCount() : 1
  12938. ), o = Math.max(
  12939. e.isArray() ? e.getColumnCount() : 1,
  12940. t.isArray() ? t.getColumnCount() : 1,
  12941. r.isArray() ? r.getColumnCount() : 1,
  12942. n.isArray() ? n.getColumnCount() : 1
  12943. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  12944. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  12945. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  12946. });
  12947. return s === 1 && o === 1 ? h.get(0, 0) : h;
  12948. }
  12949. _handleSignleObject(e, t, r, n) {
  12950. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  12951. if (s)
  12952. return o;
  12953. const [c, l, f, h] = u, d = Math.floor(+c.getValue()), _ = Math.floor(+l.getValue()), C = Math.floor(+f.getValue()), E = Math.floor(+h.getValue());
  12954. if (d < 0 || d > _ || d > C || d < _ - E + C || _ <= 0 || _ > E || C <= 0 || C > E || E <= 0)
  12955. return g.create(m.NUM);
  12956. let b = xa(d, _, C, E);
  12957. return Number.isNaN(b) && (b = 0), y.create(b);
  12958. }
  12959. }
  12960. class Am extends V {
  12961. constructor() {
  12962. super(...arguments);
  12963. A(this, "minParams", 3);
  12964. A(this, "maxParams", 3);
  12965. }
  12966. calculate(e, t, r) {
  12967. const n = Math.max(
  12968. e.isArray() ? e.getRowCount() : 1,
  12969. t.isArray() ? t.getRowCount() : 1,
  12970. r.isArray() ? r.getRowCount() : 1
  12971. ), s = Math.max(
  12972. e.isArray() ? e.getColumnCount() : 1,
  12973. t.isArray() ? t.getColumnCount() : 1,
  12974. r.isArray() ? r.getColumnCount() : 1
  12975. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  12976. const _ = u.get(h, d), C = c.get(h, d);
  12977. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  12978. });
  12979. return n === 1 && s === 1 ? l.get(0, 0) : l;
  12980. }
  12981. _handleSignleObject(e, t, r) {
  12982. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  12983. if (n)
  12984. return s;
  12985. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  12986. if (f <= 0 || d <= 0)
  12987. return g.create(m.NUM);
  12988. const _ = Uo(f, h, d);
  12989. return y.create(_);
  12990. }
  12991. }
  12992. class Em extends V {
  12993. constructor() {
  12994. super(...arguments);
  12995. A(this, "minParams", 3);
  12996. A(this, "maxParams", 3);
  12997. }
  12998. calculate(e, t, r) {
  12999. const n = Math.max(
  13000. e.isArray() ? e.getRowCount() : 1,
  13001. t.isArray() ? t.getRowCount() : 1,
  13002. r.isArray() ? r.getRowCount() : 1
  13003. ), s = Math.max(
  13004. e.isArray() ? e.getColumnCount() : 1,
  13005. t.isArray() ? t.getColumnCount() : 1,
  13006. r.isArray() ? r.getColumnCount() : 1
  13007. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  13008. const _ = u.get(h, d), C = c.get(h, d);
  13009. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  13010. });
  13011. return n === 1 && s === 1 ? l.get(0, 0) : l;
  13012. }
  13013. _handleSignleObject(e, t, r) {
  13014. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  13015. if (n)
  13016. return s;
  13017. const [u, c, l] = o, f = Math.floor(+u.getValue()), h = Math.floor(+c.getValue()), d = +l.getValue();
  13018. if (f < 0 || h < 1 || d <= 0 || d >= 1)
  13019. return g.create(m.NUM);
  13020. const _ = ja(f, h, d);
  13021. return y.create(_);
  13022. }
  13023. }
  13024. class bm extends V {
  13025. constructor() {
  13026. super(...arguments);
  13027. A(this, "minParams", 1);
  13028. A(this, "maxParams", 1);
  13029. }
  13030. calculate(e) {
  13031. if (e.isArray()) {
  13032. const t = e.mapValue((r) => this._handleSignleObject(r));
  13033. return e.getRowCount() === 1 && e.getColumnCount() === 1 ? t.get(0, 0) : t;
  13034. }
  13035. return this._handleSignleObject(e);
  13036. }
  13037. _handleSignleObject(e) {
  13038. const { isError: t, errorObject: r, variants: n } = I(e);
  13039. if (t)
  13040. return r;
  13041. const [s] = n, o = +s.getValue(), u = kr(o, 0, 1);
  13042. return y.create(u);
  13043. }
  13044. }
  13045. class ym extends V {
  13046. constructor() {
  13047. super(...arguments);
  13048. A(this, "minParams", 2);
  13049. A(this, "maxParams", 3);
  13050. A(this, "needsReferenceObject", !0);
  13051. }
  13052. calculate(e, t, r) {
  13053. let n = e;
  13054. n.isReferenceObject() && (n = n.toArrayValueObject());
  13055. const { refHasError: s, refErrorObject: o, refNumbers: u } = this._checkRefReferenceObject(t);
  13056. let c = r != null ? r : y.create(0);
  13057. c.isReferenceObject() && (c = c.toArrayValueObject());
  13058. const l = Math.max(
  13059. n.isArray() ? n.getRowCount() : 1,
  13060. c.isArray() ? c.getRowCount() : 1
  13061. ), f = Math.max(
  13062. n.isArray() ? n.getColumnCount() : 1,
  13063. c.isArray() ? c.getColumnCount() : 1
  13064. ), h = O(l, f, n, g.create(m.NA)), d = O(l, f, c, g.create(m.NA)), _ = h.map((C, E, b) => {
  13065. const R = d.get(E, b);
  13066. if (!e.isReferenceObject() && e.isNull())
  13067. return g.create(m.NA);
  13068. if (s)
  13069. return o;
  13070. if (R.isError())
  13071. return R;
  13072. const p = +C.getValue(), N = +R.getValue();
  13073. if (Number.isNaN(p) || Number.isNaN(N))
  13074. return g.create(m.VALUE);
  13075. const w = u.sort((D, S) => N ? D - S : S - D).indexOf(p);
  13076. return w === -1 ? g.create(m.NA) : y.create(w + 1);
  13077. });
  13078. return l === 1 && f === 1 ? _.get(0, 0) : _;
  13079. }
  13080. _checkRefReferenceObject(e) {
  13081. let t = !1, r = g.create(m.NA);
  13082. const n = [];
  13083. return e.isReferenceObject() ? (e.toArrayValueObject().iterator((o) => {
  13084. const u = o;
  13085. if (u.isError())
  13086. return t = !0, r = u, !1;
  13087. if (u.isNull() || u.isBoolean())
  13088. return !0;
  13089. const c = +u.getValue();
  13090. if (Number.isNaN(c))
  13091. return !0;
  13092. n.push(c);
  13093. }), {
  13094. refHasError: t,
  13095. refErrorObject: r,
  13096. refNumbers: n
  13097. }) : {
  13098. refHasError: !0,
  13099. refErrorObject: r,
  13100. refNumbers: n
  13101. };
  13102. }
  13103. }
  13104. class Rm extends V {
  13105. constructor() {
  13106. super(...arguments);
  13107. A(this, "minParams", 3);
  13108. A(this, "maxParams", 3);
  13109. }
  13110. calculate(e, t, r) {
  13111. const n = Math.max(
  13112. e.isArray() ? e.getRowCount() : 1,
  13113. t.isArray() ? t.getRowCount() : 1,
  13114. r.isArray() ? r.getRowCount() : 1
  13115. ), s = Math.max(
  13116. e.isArray() ? e.getColumnCount() : 1,
  13117. t.isArray() ? t.getColumnCount() : 1,
  13118. r.isArray() ? r.getColumnCount() : 1
  13119. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  13120. const _ = u.get(h, d), C = c.get(h, d);
  13121. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  13122. });
  13123. return n === 1 && s === 1 ? l.get(0, 0) : l;
  13124. }
  13125. _handleSignleObject(e, t, r) {
  13126. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  13127. if (n)
  13128. return s;
  13129. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = Math.floor(+l.getValue());
  13130. if (f < 0 || h < 1 || h > 10 ** 10 || d < 1 || d > 2)
  13131. return g.create(m.NUM);
  13132. let _ = $r(-f, h);
  13133. return d === 2 && (_ *= 2), Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  13134. }
  13135. }
  13136. const pm = [
  13137. [Cm, le.BETADIST],
  13138. [Bo, le.BETAINV],
  13139. [Io, le.BINOMDIST],
  13140. [ko, le.CHIDIST],
  13141. [$o, le.CHIINV],
  13142. [Yo, le.CHITEST],
  13143. [Ho, le.CONFIDENCE],
  13144. [Go, le.COVAR],
  13145. [Fo, le.CRITBINOM],
  13146. [Qo, le.EXPONDIST],
  13147. [Wo, le.FDIST],
  13148. [qo, le.FINV],
  13149. [Ko, le.FTEST],
  13150. [Xo, le.GAMMADIST],
  13151. [Zo, le.GAMMAINV],
  13152. [_m, le.HYPGEOMDIST],
  13153. [Am, le.LOGNORMDIST],
  13154. [zo, le.LOGINV],
  13155. [Jo, le.MODE],
  13156. [Em, le.NEGBINOMDIST],
  13157. [eu, le.NORMDIST],
  13158. [tu, le.NORMINV],
  13159. [bm, le.NORMSDIST],
  13160. [ru, le.NORMSINV],
  13161. [nu, le.PERCENTILE],
  13162. [su, le.PERCENTRANK],
  13163. [au, le.POISSON],
  13164. [iu, le.QUARTILE],
  13165. [ym, le.RANK],
  13166. [uu, le.STDEV],
  13167. [ou, le.STDEVP],
  13168. [Rm, le.TDIST],
  13169. [cu, le.TINV],
  13170. [lu, le.TTEST],
  13171. [hu, le.VAR],
  13172. [fu, le.VARP],
  13173. [mu, le.WEIBULL],
  13174. [gu, le.ZTEST]
  13175. ], Vm = [];
  13176. var Nm = /* @__PURE__ */ ((i) => (i.CUBEKPIMEMBER = "CUBEKPIMEMBER", i.CUBEMEMBER = "CUBEMEMBER", i.CUBEMEMBERPROPERTY = "CUBEMEMBERPROPERTY", i.CUBERANKEDMEMBER = "CUBERANKEDMEMBER", i.CUBESET = "CUBESET", i.CUBESETCOUNT = "CUBESETCOUNT", i.CUBEVALUE = "CUBEVALUE", i))(Nm || {});
  13177. class Om extends V {
  13178. isCustom() {
  13179. return !0;
  13180. }
  13181. }
  13182. class Qb extends Om {
  13183. isAsync() {
  13184. return !0;
  13185. }
  13186. }
  13187. function et(i) {
  13188. const a = [];
  13189. if (i.isError())
  13190. return {
  13191. isError: !0,
  13192. errorObject: i,
  13193. databaseValues: a
  13194. };
  13195. const e = i.isArray() ? i.getRowCount() : 1, t = i.isArray() ? i.getColumnCount() : 1;
  13196. if (e < 2)
  13197. return {
  13198. isError: !0,
  13199. errorObject: g.create(m.VALUE),
  13200. databaseValues: a
  13201. };
  13202. for (let r = 0; r < e; r++) {
  13203. const n = [];
  13204. for (let s = 0; s < t; s++) {
  13205. const o = i.get(r, s);
  13206. if (o.isNull()) {
  13207. n.push(null);
  13208. continue;
  13209. }
  13210. let u = `${o.getValue()}`;
  13211. if (o.isBoolean() && (u = u.toLocaleUpperCase()), o.isNumber() || Q(u)) {
  13212. n.push(+u);
  13213. continue;
  13214. }
  13215. n.push(u);
  13216. }
  13217. a.push(n);
  13218. }
  13219. return {
  13220. isError: !1,
  13221. errorObject: null,
  13222. databaseValues: a
  13223. };
  13224. }
  13225. function tt(i, a) {
  13226. let e = -1;
  13227. if (i.isError())
  13228. return {
  13229. isError: !0,
  13230. errorObject: i,
  13231. fieldIndex: e
  13232. };
  13233. const t = i.isArray() ? i.getRowCount() : 1, r = i.isArray() ? i.getColumnCount() : 1;
  13234. if (t > 1 || r > 1)
  13235. return {
  13236. isError: !0,
  13237. errorObject: g.create(m.VALUE),
  13238. fieldIndex: e
  13239. };
  13240. const n = i.isArray() ? i.get(0, 0) : i;
  13241. let s = `${n.getValue()}`;
  13242. if (n.isNull() ? s = 0 : n.isBoolean() ? s = n.getValue() ? 1 : 0 : (n.isNumber() || Q(s)) && (s = Math.floor(+s)), typeof s == "number") {
  13243. if (s < 1 || s > a[0].length)
  13244. return {
  13245. isError: !0,
  13246. errorObject: g.create(m.VALUE),
  13247. fieldIndex: e
  13248. };
  13249. e = s - 1;
  13250. } else if (e = a[0].findIndex((o) => o === null ? !1 : `${o}`.toLocaleLowerCase() === s.toLocaleLowerCase()), e === -1)
  13251. return {
  13252. isError: !0,
  13253. errorObject: g.create(m.VALUE),
  13254. fieldIndex: e
  13255. };
  13256. return {
  13257. isError: !1,
  13258. errorObject: null,
  13259. fieldIndex: e
  13260. };
  13261. }
  13262. function rt(i) {
  13263. const a = [];
  13264. if (i.isError())
  13265. return {
  13266. isError: !0,
  13267. errorObject: i,
  13268. criteriaValues: a
  13269. };
  13270. const e = i.isArray() ? i.getRowCount() : 1, t = i.isArray() ? i.getColumnCount() : 1;
  13271. if (e < 2)
  13272. return {
  13273. isError: !0,
  13274. errorObject: g.create(m.VALUE),
  13275. criteriaValues: a
  13276. };
  13277. for (let r = 0; r < e; r++) {
  13278. const n = [];
  13279. for (let s = 0; s < t; s++) {
  13280. const o = i.get(r, s);
  13281. if (o.isNull()) {
  13282. n.push(null);
  13283. continue;
  13284. }
  13285. const u = `${o.getValue()}`;
  13286. if (o.isBoolean()) {
  13287. n.push(o.getValue() ? 1 : 0);
  13288. continue;
  13289. }
  13290. if (o.isNumber() || Q(u)) {
  13291. n.push(+u);
  13292. continue;
  13293. }
  13294. n.push(u);
  13295. }
  13296. a.push(n);
  13297. }
  13298. return {
  13299. isError: !1,
  13300. errorObject: null,
  13301. criteriaValues: a
  13302. };
  13303. }
  13304. function nt(i, a, e) {
  13305. const t = i.length, r = i[0].length, n = {};
  13306. let s = !1;
  13307. for (let o = 1; o < t; o++) {
  13308. let u = !0;
  13309. for (let c = 0; c < r; c++) {
  13310. const l = i[o][c];
  13311. if (l === null)
  13312. continue;
  13313. let f = n[c];
  13314. if (f === void 0) {
  13315. const h = i[0][c];
  13316. f = a[0].findIndex((d) => d === null || h === null ? !1 : `${d}`.toLocaleLowerCase() === `${h}`.toLocaleLowerCase()), n[c] = f;
  13317. }
  13318. if (f === -1 && (typeof l == "string" || l === 0)) {
  13319. u = !1;
  13320. break;
  13321. } else if (f > -1) {
  13322. const h = a[e][f];
  13323. if (h === null) {
  13324. u = !1;
  13325. break;
  13326. }
  13327. const [d, _] = Aa(`${l}`);
  13328. if (!pt.create(`${h}`).compare(_, d).getValue()) {
  13329. u = !1;
  13330. break;
  13331. }
  13332. }
  13333. }
  13334. if (u) {
  13335. s = !0;
  13336. break;
  13337. }
  13338. }
  13339. return s;
  13340. }
  13341. class Mm extends V {
  13342. constructor() {
  13343. super(...arguments);
  13344. A(this, "minParams", 3);
  13345. A(this, "maxParams", 3);
  13346. }
  13347. calculate(e, t, r) {
  13348. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13349. if (n)
  13350. return s;
  13351. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13352. if (u)
  13353. return c;
  13354. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13355. if (f)
  13356. return h;
  13357. let _ = 0, C = 0;
  13358. for (let E = 1; E < o.length; E++) {
  13359. const b = o[E][l];
  13360. typeof b == "number" && nt(d, o, E) && (_ += b, C++);
  13361. }
  13362. return C === 0 ? g.create(m.DIV_BY_ZERO) : y.create(_ / C);
  13363. }
  13364. }
  13365. class wm extends V {
  13366. constructor() {
  13367. super(...arguments);
  13368. A(this, "minParams", 3);
  13369. A(this, "maxParams", 3);
  13370. }
  13371. calculate(e, t, r) {
  13372. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13373. if (n)
  13374. return s;
  13375. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13376. if (u)
  13377. return c;
  13378. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13379. if (f)
  13380. return h;
  13381. let _ = 0;
  13382. for (let C = 1; C < o.length; C++)
  13383. typeof o[C][l] == "number" && nt(d, o, C) && _++;
  13384. return y.create(_);
  13385. }
  13386. }
  13387. class Dm extends V {
  13388. constructor() {
  13389. super(...arguments);
  13390. A(this, "minParams", 3);
  13391. A(this, "maxParams", 3);
  13392. }
  13393. calculate(e, t, r) {
  13394. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13395. if (n)
  13396. return s;
  13397. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13398. if (u)
  13399. return c;
  13400. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13401. if (f)
  13402. return h;
  13403. let _ = 0;
  13404. for (let C = 1; C < o.length; C++) {
  13405. const E = o[C][l];
  13406. E != null && nt(d, o, C) && _++;
  13407. }
  13408. return y.create(_);
  13409. }
  13410. }
  13411. class Sm extends V {
  13412. constructor() {
  13413. super(...arguments);
  13414. A(this, "minParams", 3);
  13415. A(this, "maxParams", 3);
  13416. }
  13417. calculate(e, t, r) {
  13418. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13419. if (n)
  13420. return s;
  13421. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13422. if (u)
  13423. return c;
  13424. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13425. if (f)
  13426. return h;
  13427. let _ = 0, C = 0;
  13428. for (let E = 1; E < o.length; E++) {
  13429. const b = o[E][l];
  13430. b != null && nt(d, o, E) && (_++, C = E);
  13431. }
  13432. return _ === 0 ? g.create(m.VALUE) : _ > 1 ? g.create(m.NUM) : e.get(C, l);
  13433. }
  13434. }
  13435. class Pm extends V {
  13436. constructor() {
  13437. super(...arguments);
  13438. A(this, "minParams", 3);
  13439. A(this, "maxParams", 3);
  13440. }
  13441. calculate(e, t, r) {
  13442. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13443. if (n)
  13444. return s;
  13445. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13446. if (u)
  13447. return c;
  13448. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13449. if (f)
  13450. return h;
  13451. let _ = -1 / 0, C = 0;
  13452. for (let E = 1; E < o.length; E++) {
  13453. const b = o[E][l];
  13454. typeof b == "number" && nt(d, o, E) && (_ = Math.max(_, b), C++);
  13455. }
  13456. return C === 0 ? y.create(0) : y.create(_);
  13457. }
  13458. }
  13459. class Lm extends V {
  13460. constructor() {
  13461. super(...arguments);
  13462. A(this, "minParams", 3);
  13463. A(this, "maxParams", 3);
  13464. }
  13465. calculate(e, t, r) {
  13466. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13467. if (n)
  13468. return s;
  13469. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13470. if (u)
  13471. return c;
  13472. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13473. if (f)
  13474. return h;
  13475. let _ = 1 / 0, C = 0;
  13476. for (let E = 1; E < o.length; E++) {
  13477. const b = o[E][l];
  13478. typeof b == "number" && nt(d, o, E) && (_ = Math.min(_, b), C++);
  13479. }
  13480. return C === 0 ? y.create(0) : y.create(_);
  13481. }
  13482. }
  13483. class xm extends V {
  13484. constructor() {
  13485. super(...arguments);
  13486. A(this, "minParams", 3);
  13487. A(this, "maxParams", 3);
  13488. }
  13489. calculate(e, t, r) {
  13490. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13491. if (n)
  13492. return s;
  13493. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13494. if (u)
  13495. return c;
  13496. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13497. if (f)
  13498. return h;
  13499. let _ = 1, C = 0;
  13500. for (let E = 1; E < o.length; E++) {
  13501. const b = o[E][l];
  13502. typeof b == "number" && nt(d, o, E) && (_ *= b, C++);
  13503. }
  13504. return C === 0 ? y.create(0) : y.create(_);
  13505. }
  13506. }
  13507. class jm extends V {
  13508. constructor() {
  13509. super(...arguments);
  13510. A(this, "minParams", 3);
  13511. A(this, "maxParams", 3);
  13512. }
  13513. calculate(e, t, r) {
  13514. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13515. if (n)
  13516. return s;
  13517. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13518. if (u)
  13519. return c;
  13520. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13521. if (f)
  13522. return h;
  13523. const _ = [];
  13524. let C = 0, E = 0;
  13525. for (let N = 1; N < o.length; N++) {
  13526. const M = o[N][l];
  13527. typeof M == "number" && nt(d, o, N) && (_.push(M), C += M, E++);
  13528. }
  13529. if (E <= 1)
  13530. return g.create(m.DIV_BY_ZERO);
  13531. const b = C / E;
  13532. let R = 0;
  13533. for (let N = 0; N < E; N++)
  13534. R += (_[N] - b) ** 2;
  13535. const p = Math.sqrt(R / (E - 1));
  13536. return y.create(p);
  13537. }
  13538. }
  13539. class Um extends V {
  13540. constructor() {
  13541. super(...arguments);
  13542. A(this, "minParams", 3);
  13543. A(this, "maxParams", 3);
  13544. }
  13545. calculate(e, t, r) {
  13546. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13547. if (n)
  13548. return s;
  13549. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13550. if (u)
  13551. return c;
  13552. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13553. if (f)
  13554. return h;
  13555. const _ = [];
  13556. let C = 0, E = 0;
  13557. for (let N = 1; N < o.length; N++) {
  13558. const M = o[N][l];
  13559. typeof M == "number" && nt(d, o, N) && (_.push(M), C += M, E++);
  13560. }
  13561. if (E === 0)
  13562. return g.create(m.DIV_BY_ZERO);
  13563. const b = C / E;
  13564. let R = 0;
  13565. for (let N = 0; N < E; N++)
  13566. R += (_[N] - b) ** 2;
  13567. const p = Math.sqrt(R / E);
  13568. return y.create(p);
  13569. }
  13570. }
  13571. class vm extends V {
  13572. constructor() {
  13573. super(...arguments);
  13574. A(this, "minParams", 3);
  13575. A(this, "maxParams", 3);
  13576. }
  13577. calculate(e, t, r) {
  13578. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13579. if (n)
  13580. return s;
  13581. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13582. if (u)
  13583. return c;
  13584. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13585. if (f)
  13586. return h;
  13587. let _ = 0;
  13588. for (let C = 1; C < o.length; C++) {
  13589. const E = o[C][l];
  13590. typeof E == "number" && nt(d, o, C) && (_ += E);
  13591. }
  13592. return y.create(_);
  13593. }
  13594. }
  13595. class Tm extends V {
  13596. constructor() {
  13597. super(...arguments);
  13598. A(this, "minParams", 3);
  13599. A(this, "maxParams", 3);
  13600. }
  13601. calculate(e, t, r) {
  13602. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13603. if (n)
  13604. return s;
  13605. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13606. if (u)
  13607. return c;
  13608. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13609. if (f)
  13610. return h;
  13611. const _ = [];
  13612. let C = 0, E = 0;
  13613. for (let N = 1; N < o.length; N++) {
  13614. const M = o[N][l];
  13615. typeof M == "number" && nt(d, o, N) && (_.push(M), C += M, E++);
  13616. }
  13617. if (E <= 1)
  13618. return g.create(m.DIV_BY_ZERO);
  13619. const b = C / E;
  13620. let R = 0;
  13621. for (let N = 0; N < E; N++)
  13622. R += (_[N] - b) ** 2;
  13623. const p = R / (E - 1);
  13624. return y.create(p);
  13625. }
  13626. }
  13627. class Bm extends V {
  13628. constructor() {
  13629. super(...arguments);
  13630. A(this, "minParams", 3);
  13631. A(this, "maxParams", 3);
  13632. }
  13633. calculate(e, t, r) {
  13634. const { isError: n, errorObject: s, databaseValues: o } = et(e);
  13635. if (n)
  13636. return s;
  13637. const { isError: u, errorObject: c, fieldIndex: l } = tt(t, o);
  13638. if (u)
  13639. return c;
  13640. const { isError: f, errorObject: h, criteriaValues: d } = rt(r);
  13641. if (f)
  13642. return h;
  13643. const _ = [];
  13644. let C = 0, E = 0;
  13645. for (let N = 1; N < o.length; N++) {
  13646. const M = o[N][l];
  13647. typeof M == "number" && nt(d, o, N) && (_.push(M), C += M, E++);
  13648. }
  13649. if (E === 0)
  13650. return g.create(m.DIV_BY_ZERO);
  13651. const b = C / E;
  13652. let R = 0;
  13653. for (let N = 0; N < E; N++)
  13654. R += (_[N] - b) ** 2;
  13655. const p = R / E;
  13656. return y.create(p);
  13657. }
  13658. }
  13659. var Qe = /* @__PURE__ */ ((i) => (i.DAVERAGE = "DAVERAGE", i.DCOUNT = "DCOUNT", i.DCOUNTA = "DCOUNTA", i.DGET = "DGET", i.DMAX = "DMAX", i.DMIN = "DMIN", i.DPRODUCT = "DPRODUCT", i.DSTDEV = "DSTDEV", i.DSTDEVP = "DSTDEVP", i.DSUM = "DSUM", i.DVAR = "DVAR", i.DVARP = "DVARP", i))(Qe || {});
  13660. const Im = [
  13661. [Mm, Qe.DAVERAGE],
  13662. [wm, Qe.DCOUNT],
  13663. [Dm, Qe.DCOUNTA],
  13664. [Sm, Qe.DGET],
  13665. [Pm, Qe.DMAX],
  13666. [Lm, Qe.DMIN],
  13667. [xm, Qe.DPRODUCT],
  13668. [jm, Qe.DSTDEV],
  13669. [Um, Qe.DSTDEVP],
  13670. [vm, Qe.DSUM],
  13671. [Tm, Qe.DVAR],
  13672. [Bm, Qe.DVARP]
  13673. ], Ua = "yyyy/mm/dd;@", Fm = "yyyy/mm/dd hh:mm", km = "h:mm A/P";
  13674. function ye(i) {
  13675. const a = new Date(Date.UTC(1900, 0, 1)), e = new Date(Date.UTC(1900, 1, 28)), t = Date.UTC(i.getFullYear(), i.getMonth(), i.getDate());
  13676. let r = (t - a.getTime()) / (1e3 * 3600 * 24);
  13677. return t > e.getTime() && (r += 1), Math.floor(r) + 1;
  13678. }
  13679. function Yr(i) {
  13680. const a = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), e = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
  13681. let r = (i.getTime() - a.getTime()) / (1e3 * 3600 * 24);
  13682. return i > e && (r += 1), r + 1;
  13683. }
  13684. function re(i) {
  13685. const a = new Date(Date.UTC(1900, 0, 1)), e = new Date(Date.UTC(1900, 1, 28));
  13686. let t = Math.floor(i) - 1;
  13687. return t > (e.getTime() - a.getTime()) / (1e3 * 3600 * 24) && (t -= 1), new Date(a.getTime() + t * (1e3 * 3600 * 24));
  13688. }
  13689. function va(i) {
  13690. const a = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), e = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
  13691. let t = i - 1;
  13692. return t > (e.getTime() - a.getTime()) / (1e3 * 3600 * 24) && (t -= 1), t < 0 && (t = i), new Date(a.getTime() + t * (1e3 * 3600 * 24));
  13693. }
  13694. function Ta(i) {
  13695. if (!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(i))
  13696. return !1;
  13697. const e = i.replace(/-/g, "/").replace(/T.+/, ""), t = /* @__PURE__ */ new Date(`${e}`);
  13698. if (Number.isNaN(t.getTime()))
  13699. return !1;
  13700. const r = t.getFullYear(), n = (t.getMonth() + 1).toString().padStart(2, "0"), s = t.getDate().toString().padStart(2, "0"), o = `${r}-${n}-${s}`;
  13701. return i.replace(/\//g, "-").split("-").map((c) => c.padStart(2, "0")).join("-") === o;
  13702. }
  13703. function Xs(i) {
  13704. return gt.parseDate(i);
  13705. }
  13706. function du(i) {
  13707. return gt.parseValue(i);
  13708. }
  13709. function Zs(i) {
  13710. return gt.parseTime(i);
  13711. }
  13712. function Ba(i) {
  13713. return gt.isDate(i);
  13714. }
  13715. const Cu = {
  13716. 1: [6, 0],
  13717. // Saturday, Sunday
  13718. 2: [0, 1],
  13719. // Sunday, Monday
  13720. 3: [1, 2],
  13721. // Monday, Tuesday
  13722. 4: [2, 3],
  13723. // Tuesday, Wednesday
  13724. 5: [3, 4],
  13725. // Wednesday, Thursday
  13726. 6: [4, 5],
  13727. // Thursday, Friday
  13728. 7: [5, 6],
  13729. // Friday, Saturday
  13730. 11: [0],
  13731. // Sunday only
  13732. 12: [1],
  13733. // Monday only
  13734. 13: [2],
  13735. // Tuesday only
  13736. 14: [3],
  13737. // Wednesday only
  13738. 15: [4],
  13739. // Thursday only
  13740. 16: [5],
  13741. // Friday only
  13742. 17: [6]
  13743. // Saturday only
  13744. };
  13745. function Ur(i) {
  13746. return !!(typeof i == "string" && /^[0|1]{7}/.test(i) || Cu[Number(i)]);
  13747. }
  13748. function _u(i) {
  13749. if (!Ur(i))
  13750. return [];
  13751. if (typeof i == "string" && /^[0|1]{7}/.test(i)) {
  13752. const a = [];
  13753. for (let e = 1; e <= i.length; e++)
  13754. `${i[e - 1]}` == "1" && (e === i.length ? a.push(0) : a.push(e));
  13755. return a;
  13756. }
  13757. return Cu[Number(i)] || [];
  13758. }
  13759. function On(i, a, e = 1, t) {
  13760. const r = _u(e), n = Math.floor(i), s = Math.floor(a), o = s > n ? n : s;
  13761. let u = 0;
  13762. const c = Math.abs(Math.floor(a) - Math.floor(i)) + 1;
  13763. for (let l = 0; l < c; l++) {
  13764. const f = o + l;
  13765. if (t && t.length > 0 && t.some((d) => Math.floor(d) === f))
  13766. continue;
  13767. const h = rr(f);
  13768. r.includes(h) || u++;
  13769. }
  13770. return s >= n ? u : -u;
  13771. }
  13772. function Mn(i, a, e = 1, t) {
  13773. const r = _u(e), n = Math.floor(i);
  13774. let s = n, o = Math.abs(a);
  13775. for (let u = 1; u <= o; u++) {
  13776. const c = a < 0 ? n - u : n + u;
  13777. if (c < 0)
  13778. return g.create(m.NUM);
  13779. if (t && t.length > 0 && t.some((f) => Math.floor(f) === c)) {
  13780. o++;
  13781. continue;
  13782. }
  13783. const l = rr(c);
  13784. if (r.includes(l)) {
  13785. o++;
  13786. continue;
  13787. }
  13788. s = c;
  13789. }
  13790. return s;
  13791. }
  13792. function k(i) {
  13793. if (i.isError())
  13794. return i;
  13795. const a = i.getValue();
  13796. if (i.isString()) {
  13797. let e;
  13798. if (Xs(`${a}`))
  13799. e = Xs(`${a}`).v;
  13800. else if (Zs(`${a}`))
  13801. e = Zs(`${a}`).v;
  13802. else if (Q(a))
  13803. e = +a;
  13804. else
  13805. return g.create(m.VALUE);
  13806. return e instanceof Date && (e = Yr(e)), +e < 0 || +e > 2958465 ? g.create(m.NUM) : +e;
  13807. } else {
  13808. const e = +i.getValue();
  13809. return e < 0 || e > 2958465 ? g.create(m.NUM) : e;
  13810. }
  13811. }
  13812. function rr(i) {
  13813. const a = Math.floor(i) === 60;
  13814. let e = re(i);
  13815. const t = new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate())).getTime(), r = new Date(Date.UTC(1900, 1, 28)).getTime();
  13816. return !a && t <= r && (e = new Date(t - 24 * 3600 * 1e3)), new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate())).getUTCDay();
  13817. }
  13818. function _e(i, a, e) {
  13819. switch (e) {
  13820. case 0:
  13821. return $m(i, a);
  13822. case 1:
  13823. return Ym(i, a);
  13824. case 2:
  13825. return {
  13826. days: Math.abs(a - i),
  13827. yearDays: 360
  13828. };
  13829. case 3:
  13830. return {
  13831. days: Math.abs(a - i),
  13832. yearDays: 365
  13833. };
  13834. case 4:
  13835. return Hm(i, a);
  13836. default:
  13837. return {
  13838. days: Math.abs(a - i),
  13839. yearDays: 365
  13840. };
  13841. }
  13842. }
  13843. function $m(i, a) {
  13844. const e = re(i), t = i > 0 ? e.getUTCFullYear() : 1900, r = i > 0 ? e.getUTCMonth() + 1 : 1;
  13845. let n = i > 0 ? e.getUTCDate() : 0, s = re(a), o = a > 0 ? s.getUTCFullYear() : 1900, u = a > 0 ? s.getUTCMonth() + 1 : 1, c = a > 0 ? s.getUTCDate() : 0;
  13846. r === 2 ? re(i + 1).getUTCMonth() + 1 === 3 && (n = 30) : n === 31 && (n = 30), c === 31 && (n < 30 ? (s = re(a + 1), o = s.getUTCFullYear(), u = s.getUTCMonth() + 1, c = s.getUTCDate()) : c = 30);
  13847. const l = (o - t) * 360, f = a >= i ? 30 - n : -n, h = a >= i ? c : c - 30, d = (a >= i ? u - r - 1 : u - r + 1) * 30;
  13848. return {
  13849. days: Math.abs(l + f + h + d),
  13850. yearDays: 360
  13851. };
  13852. }
  13853. function Ym(i, a) {
  13854. const e = re(i), t = i > 0 ? e.getUTCFullYear() : 1900, r = re(a), n = a > 0 ? r.getUTCFullYear() : 1900, s = Math.abs(a - i), o = Math.abs(n - t) + 1;
  13855. let u, c;
  13856. if (n < t) {
  13857. const l = new Date(Date.UTC(n, 0, 1)), f = new Date(Date.UTC(t, 11, 31));
  13858. u = ye(l), c = ye(f), n === 1900 && (u += 1);
  13859. } else {
  13860. const l = new Date(Date.UTC(t, 0, 1)), f = new Date(Date.UTC(n, 11, 31));
  13861. u = ye(l), c = ye(f), t === 1900 && (u += 1);
  13862. }
  13863. return {
  13864. days: s,
  13865. yearDays: (c - u + 1) / o
  13866. };
  13867. }
  13868. function Hm(i, a) {
  13869. const e = re(i), t = i > 0 ? e.getUTCFullYear() : 1900, r = i > 0 ? e.getUTCMonth() + 1 : 1;
  13870. let n = i > 0 ? e.getUTCDate() : 0;
  13871. const s = re(a), o = a > 0 ? s.getUTCFullYear() : 1900, u = a > 0 ? s.getUTCMonth() + 1 : 1;
  13872. let c = a > 0 ? s.getUTCDate() : 0;
  13873. n === 31 && (n = 30), c === 31 && (c = 30);
  13874. const l = (o - t) * 360, f = a >= i ? 30 - n : -n, h = a >= i ? c : c - 30, d = (a >= i ? u - r - 1 : u - r + 1) * 30;
  13875. return {
  13876. days: Math.abs(l + f + h + d),
  13877. yearDays: 360
  13878. };
  13879. }
  13880. function Gm(i) {
  13881. return i % 4 === 0 && i % 100 !== 0 || i % 400 === 0;
  13882. }
  13883. function Qm(i) {
  13884. return i % 4 === 0 && i % 100 !== 0 || i % 400 === 0 || i === 1900;
  13885. }
  13886. const Wm = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], qm = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  13887. function Hr(i, a) {
  13888. return Gm(i) ? Wm[a] : qm[a];
  13889. }
  13890. function Jn(i) {
  13891. return Qm(i) ? 366 : 365;
  13892. }
  13893. function Au(i, a) {
  13894. switch (a) {
  13895. case 0:
  13896. case 2:
  13897. case 4:
  13898. return 360;
  13899. case 1:
  13900. return Jn(re(i).getUTCFullYear());
  13901. case 3:
  13902. return 365;
  13903. default:
  13904. return -1;
  13905. }
  13906. }
  13907. function Ar(i, a, e) {
  13908. return Hr(i, a) === e;
  13909. }
  13910. function Er(i, a) {
  13911. let e = i.getUTCFullYear(), t = i.getUTCMonth();
  13912. const r = i.getUTCDate();
  13913. return Ar(e, t, r) ? (i.setUTCDate(1), i.setUTCMonth(i.getUTCMonth() + a), e = i.getUTCFullYear(), t = i.getUTCMonth(), i.setUTCDate(Hr(e, t))) : i.setUTCMonth(i.getUTCMonth() + a), i;
  13914. }
  13915. class Km extends V {
  13916. constructor() {
  13917. super(...arguments);
  13918. A(this, "minParams", 3);
  13919. A(this, "maxParams", 3);
  13920. }
  13921. calculate(e, t, r) {
  13922. if (e.isError())
  13923. return e;
  13924. if (t.isError())
  13925. return t;
  13926. if (r.isError())
  13927. return r;
  13928. const n = Math.max(
  13929. e.isArray() ? e.getRowCount() : 1,
  13930. t.isArray() ? t.getRowCount() : 1,
  13931. r.isArray() ? r.getRowCount() : 1
  13932. ), s = Math.max(
  13933. e.isArray() ? e.getColumnCount() : 1,
  13934. t.isArray() ? t.getColumnCount() : 1,
  13935. r.isArray() ? r.getColumnCount() : 1
  13936. ), o = O(n, s, e), u = O(n, s, t), c = O(n, s, r);
  13937. return o.map((l, f, h) => {
  13938. const d = u.get(f, h) || ie.create(), _ = c.get(f, h) || ie.create();
  13939. if (l.isError())
  13940. return l;
  13941. if (d.isError())
  13942. return d;
  13943. if (_.isError())
  13944. return _;
  13945. if (l.isString() || d.isString() || _.isString())
  13946. return g.create(m.VALUE);
  13947. let C = +l.getValue();
  13948. const E = Math.floor(+d.getValue()), b = +_.getValue();
  13949. if (C < 0 || C > 9999)
  13950. return g.create(m.NUM);
  13951. C >= 0 && C < 1899 && (C += 1900);
  13952. const R = new Date(C, E - 1, b), p = ye(R);
  13953. return p < 0 ? g.create(m.NUM) : y.create(p, Ua);
  13954. });
  13955. }
  13956. }
  13957. class Xm extends V {
  13958. constructor() {
  13959. super(...arguments);
  13960. A(this, "minParams", 3);
  13961. A(this, "maxParams", 3);
  13962. }
  13963. calculate(e, t, r) {
  13964. let n = e, s = t, o = r;
  13965. if (n.isArray() && (n = n.get(0, 0)), s.isArray() && (s = s.get(0, 0)), o.isArray() && (o = o.get(0, 0)), n.isError())
  13966. return n;
  13967. if (s.isError())
  13968. return s;
  13969. if (o.isError())
  13970. return o;
  13971. const u = k(n);
  13972. if (typeof u != "number")
  13973. return u;
  13974. const c = k(s);
  13975. return typeof c != "number" ? c : c < u || !o.isString() ? g.create(m.NUM) : this._getResultByUnit(u, c, o);
  13976. }
  13977. _getResultByUnit(e, t, r) {
  13978. const n = re(e), s = n.getUTCFullYear(), o = n.getUTCMonth() + 1, u = n.getUTCDate(), c = re(t), l = c.getUTCFullYear(), f = c.getUTCMonth() + 1, h = c.getUTCDate(), d = `${r.getValue()}`.toLocaleUpperCase();
  13979. let _ = 0, C;
  13980. switch (d) {
  13981. case "Y":
  13982. _ = l - s, (f < o || f === o && h < u) && (_ -= 1);
  13983. break;
  13984. case "M":
  13985. _ = (l - s) * 12 + f - o, h < u && (_ -= 1);
  13986. break;
  13987. case "D":
  13988. _ = Math.floor(t) - Math.floor(e);
  13989. break;
  13990. case "MD":
  13991. _ = h - u, h < u && (C = new Date(Date.UTC(l, f - 1, 0)), _ += Hr(C.getUTCFullYear(), C.getUTCMonth()));
  13992. break;
  13993. case "YM":
  13994. _ = f - o, (f < o || f === o && h < u) && (_ += 12), h < u && (_ -= 1);
  13995. break;
  13996. case "YD":
  13997. C = new Date(Date.UTC(s, f - 1, h)), (f < o || f === o && h < u) && (C = new Date(Date.UTC(s + 1, f - 1, h))), _ = Math.floor(ye(C)) - Math.floor(e);
  13998. break;
  13999. default:
  14000. return g.create(m.NUM);
  14001. }
  14002. return y.create(_);
  14003. }
  14004. }
  14005. class Zm extends V {
  14006. constructor() {
  14007. super(...arguments);
  14008. A(this, "minParams", 1);
  14009. A(this, "maxParams", 1);
  14010. }
  14011. calculate(e) {
  14012. return e.isError() ? e : e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  14013. }
  14014. _handleSingleObject(e) {
  14015. if (e.isString()) {
  14016. const t = `${e.getValue()}`, r = du(t);
  14017. if (r) {
  14018. let { v: n, z: s } = r;
  14019. if (s && Ba(s))
  14020. return n instanceof Date && (n = Yr(n)), y.create(Math.trunc(+n));
  14021. }
  14022. }
  14023. return g.create(m.VALUE);
  14024. }
  14025. }
  14026. class zm extends V {
  14027. constructor() {
  14028. super(...arguments);
  14029. A(this, "minParams", 1);
  14030. A(this, "maxParams", 1);
  14031. }
  14032. calculate(e) {
  14033. return e.isError() ? e : e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  14034. }
  14035. _handleSingleObject(e) {
  14036. let t;
  14037. const r = e.getValue();
  14038. if (e.isString()) {
  14039. if (!Ta(`${r}`))
  14040. return g.create(m.VALUE);
  14041. t = /* @__PURE__ */ new Date(`${r}`);
  14042. } else {
  14043. const o = +e.getValue();
  14044. if (o < 0)
  14045. return g.create(m.NUM);
  14046. if (o === 0)
  14047. return y.create(0);
  14048. t = re(o);
  14049. }
  14050. const n = t.getDate();
  14051. return y.create(n);
  14052. }
  14053. }
  14054. class Jm extends V {
  14055. constructor() {
  14056. super(...arguments);
  14057. A(this, "minParams", 2);
  14058. A(this, "maxParams", 2);
  14059. }
  14060. calculate(e, t) {
  14061. if (e.isError())
  14062. return e;
  14063. if (t.isError())
  14064. return t;
  14065. const r = Math.max(
  14066. e.isArray() ? e.getRowCount() : 1,
  14067. t.isArray() ? t.getRowCount() : 1
  14068. ), n = Math.max(
  14069. e.isArray() ? e.getColumnCount() : 1,
  14070. t.isArray() ? t.getColumnCount() : 1
  14071. ), s = O(r, n, e), o = O(r, n, t), u = s.map((c, l, f) => {
  14072. const h = o.get(l, f);
  14073. if (c.isError())
  14074. return c;
  14075. if (h.isError())
  14076. return h;
  14077. const d = k(c);
  14078. if (typeof d != "number")
  14079. return d;
  14080. const _ = k(h);
  14081. if (typeof _ != "number")
  14082. return _;
  14083. const C = Math.floor(d) - Math.floor(_);
  14084. return y.create(C);
  14085. });
  14086. return r === 1 && n === 1 ? u.get(0, 0) : u;
  14087. }
  14088. }
  14089. class eg extends V {
  14090. constructor() {
  14091. super(...arguments);
  14092. A(this, "minParams", 2);
  14093. A(this, "maxParams", 3);
  14094. }
  14095. calculate(e, t, r) {
  14096. const n = r != null ? r : T.create(!1);
  14097. if (e.isError())
  14098. return e;
  14099. if (t.isError())
  14100. return t;
  14101. if (n.isError())
  14102. return n;
  14103. const s = Math.max(
  14104. e.isArray() ? e.getRowCount() : 1,
  14105. t.isArray() ? t.getRowCount() : 1,
  14106. n.isArray() ? n.getRowCount() : 1
  14107. ), o = Math.max(
  14108. e.isArray() ? e.getColumnCount() : 1,
  14109. t.isArray() ? t.getColumnCount() : 1,
  14110. n.isArray() ? n.getColumnCount() : 1
  14111. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.map((h, d, _) => {
  14112. const C = c.get(d, _);
  14113. let E = l.get(d, _);
  14114. if (h.isError())
  14115. return h;
  14116. const b = k(h);
  14117. if (typeof b != "number")
  14118. return b;
  14119. if (C.isError())
  14120. return C;
  14121. const R = k(C);
  14122. if (typeof R != "number")
  14123. return R;
  14124. if (E.isString() && (E = E.convertToNumberObjectValue()), E.isError())
  14125. return E;
  14126. const p = +E.getValue(), { days: N } = _e(b, R, p ? 4 : 0), M = R >= b ? N : -N;
  14127. return y.create(M);
  14128. });
  14129. return s === 1 && o === 1 ? f.get(0, 0) : f;
  14130. }
  14131. }
  14132. class tg extends V {
  14133. constructor() {
  14134. super(...arguments);
  14135. A(this, "minParams", 2);
  14136. A(this, "maxParams", 2);
  14137. }
  14138. calculate(e, t) {
  14139. if (e.isError())
  14140. return e;
  14141. if (t.isError())
  14142. return t;
  14143. const r = Math.max(
  14144. e.isArray() ? e.getRowCount() : 1,
  14145. t.isArray() ? t.getRowCount() : 1
  14146. ), n = Math.max(
  14147. e.isArray() ? e.getColumnCount() : 1,
  14148. t.isArray() ? t.getColumnCount() : 1
  14149. ), s = O(r, n, e), o = O(r, n, t);
  14150. return s.map((u, c, l) => {
  14151. const f = o.get(c, l) || ie.create();
  14152. if (u.isError())
  14153. return u;
  14154. if (f.isError())
  14155. return f;
  14156. if (u.isString() || u.isBoolean() || f.isString() || f.isBoolean())
  14157. return g.create(m.VALUE);
  14158. const h = +u.getValue();
  14159. if (h < 0)
  14160. return g.create(m.NUM);
  14161. const d = Math.floor(+f.getValue()), _ = re(h), C = _.getUTCFullYear(), E = _.getUTCMonth() + d, b = _.getUTCDate(), R = new Date(Date.UTC(C, E, b)), p = ye(R);
  14162. return y.create(p, Ua);
  14163. });
  14164. }
  14165. }
  14166. class rg extends V {
  14167. constructor() {
  14168. super(...arguments);
  14169. A(this, "minParams", 2);
  14170. A(this, "maxParams", 2);
  14171. }
  14172. calculate(e, t) {
  14173. let r = e, n = t;
  14174. if (r.isArray()) {
  14175. const d = r.getRowCount(), _ = r.getColumnCount();
  14176. if (d > 1 || _ > 1)
  14177. return g.create(m.VALUE);
  14178. r = r.get(0, 0);
  14179. }
  14180. if (n.isArray()) {
  14181. const d = n.getRowCount(), _ = n.getColumnCount();
  14182. if (d > 1 || _ > 1)
  14183. return g.create(m.VALUE);
  14184. n = n.get(0, 0);
  14185. }
  14186. if (r.isError())
  14187. return r;
  14188. if (n.isError())
  14189. return n;
  14190. const s = k(r);
  14191. if (typeof s != "number")
  14192. return s;
  14193. if (n.isBoolean())
  14194. return g.create(m.VALUE);
  14195. const o = re(s), u = s > 0 ? o.getUTCFullYear() : 1900, c = s > 0 ? o.getUTCMonth() : 0, l = Math.floor(+n.getValue());
  14196. if (Number.isNaN(l))
  14197. return g.create(m.VALUE);
  14198. const f = new Date(Date.UTC(u, c + l + 1, 0)), h = ye(f);
  14199. return y.create(h);
  14200. }
  14201. }
  14202. class ng extends V {
  14203. constructor() {
  14204. super(...arguments);
  14205. A(this, "minParams", 1);
  14206. A(this, "maxParams", 2);
  14207. A(this, "needsReferenceObject", !0);
  14208. }
  14209. calculate(e, t) {
  14210. const r = t != null ? t : y.create(1), { isError: n, errorObject: s, timestampIsReferenceObject: o, timestampObject: u, unitObject: c } = this._checkVariants(e, r);
  14211. if (n)
  14212. return s;
  14213. if (u.isNull() || u.isBoolean() || u.isString() || !o && u.isNumber() && u.getPattern() !== "")
  14214. return g.create(m.VALUE);
  14215. let l = +u.getValue();
  14216. const { isError: f, errorObject: h, variants: d } = I(c);
  14217. if (f)
  14218. return h;
  14219. const [_] = d, C = Math.floor(+_.getValue());
  14220. if (l < 0 || C < 1 || C > 3)
  14221. return g.create(m.NUM);
  14222. C === 1 && (l = l * 1e3), C === 3 && (l = l / 1e3);
  14223. const E = new Date(Date.UTC(1970, 0, 1, 0, 0, 0, 0) + l);
  14224. if (Number.isNaN(E.getTime())) {
  14225. const b = 25569 + l / 864e5;
  14226. return y.create(b);
  14227. } else {
  14228. const b = Yr(E);
  14229. return y.create(b, "yyyy-MM-dd AM/PM hh:mm:ss");
  14230. }
  14231. }
  14232. _checkVariants(e, t) {
  14233. const r = e.isReferenceObject(), n = t.isReferenceObject();
  14234. let s = e;
  14235. if (r && (s = e.toArrayValueObject()), s.isArray()) {
  14236. const u = s.getRowCount(), c = s.getColumnCount();
  14237. if (u > 1 || c > 1)
  14238. return {
  14239. isError: !0,
  14240. errorObject: g.create(m.VALUE)
  14241. };
  14242. s = s.get(0, 0);
  14243. }
  14244. if (s.isError())
  14245. return {
  14246. isError: !0,
  14247. errorObject: s
  14248. };
  14249. let o = t;
  14250. if (n && (o = t.toArrayValueObject()), o.isArray()) {
  14251. const u = o.getRowCount(), c = o.getColumnCount();
  14252. if (u > 1 || c > 1)
  14253. return {
  14254. isError: !0,
  14255. errorObject: g.create(m.VALUE)
  14256. };
  14257. o = o.get(0, 0);
  14258. }
  14259. return o.isError() ? {
  14260. isError: !0,
  14261. errorObject: o
  14262. } : {
  14263. isError: !1,
  14264. errorObject: null,
  14265. timestampIsReferenceObject: r,
  14266. timestampObject: s,
  14267. unitIsReferenceObject: n,
  14268. unitObject: o
  14269. };
  14270. }
  14271. }
  14272. var be = /* @__PURE__ */ ((i) => (i.DATE = "DATE", i.DATEDIF = "DATEDIF", i.DATEVALUE = "DATEVALUE", i.DAY = "DAY", i.DAYS = "DAYS", i.DAYS360 = "DAYS360", i.EDATE = "EDATE", i.EOMONTH = "EOMONTH", i.EPOCHTODATE = "EPOCHTODATE", i.HOUR = "HOUR", i.ISOWEEKNUM = "ISOWEEKNUM", i.MINUTE = "MINUTE", i.MONTH = "MONTH", i.NETWORKDAYS = "NETWORKDAYS", i.NETWORKDAYS_INTL = "NETWORKDAYS.INTL", i.NOW = "NOW", i.SECOND = "SECOND", i.TIME = "TIME", i.TIMEVALUE = "TIMEVALUE", i.TO_DATE = "TO_DATE", i.TODAY = "TODAY", i.WEEKDAY = "WEEKDAY", i.WEEKNUM = "WEEKNUM", i.WORKDAY = "WORKDAY", i.WORKDAY_INTL = "WORKDAY.INTL", i.YEAR = "YEAR", i.YEARFRAC = "YEARFRAC", i))(be || {});
  14273. class sg extends V {
  14274. constructor() {
  14275. super(...arguments);
  14276. A(this, "minParams", 1);
  14277. A(this, "maxParams", 1);
  14278. }
  14279. calculate(e) {
  14280. return e.isError() ? e : e.isArray() ? e.map((t) => t.isError() ? t : this._handleSingleObject(t)) : this._handleSingleObject(e);
  14281. }
  14282. _handleSingleObject(e) {
  14283. const t = k(e);
  14284. if (typeof t != "number")
  14285. return t;
  14286. if (t === 0)
  14287. return y.create(0);
  14288. const n = va(t).getUTCHours();
  14289. return y.create(n);
  14290. }
  14291. }
  14292. class ag extends V {
  14293. constructor() {
  14294. super(...arguments);
  14295. A(this, "minParams", 1);
  14296. A(this, "maxParams", 1);
  14297. }
  14298. calculate(e) {
  14299. return e.isError() ? e : e.isArray() ? e.map((t) => t.isError() ? t : this._handleSingleObject(t)) : this._handleSingleObject(e);
  14300. }
  14301. _handleSingleObject(e) {
  14302. const t = k(e);
  14303. if (typeof t != "number")
  14304. return t;
  14305. const r = re(t), n = t > 0 ? r.getUTCFullYear() : 1900;
  14306. let s = new Date(Date.UTC(n, 0, 1)), o = ye(s), u = rr(o), c;
  14307. u < 1 ? c = o + 1 : u <= 4 ? c = o - (u - 1) : c = o + (11 - u), t < c && (s = new Date(Date.UTC(n - 1, 0, 1)), o = ye(s), u = rr(o), u < 1 ? c = o + 1 : u <= 4 ? c = o - (u - 1) : c = o + (11 - u));
  14308. const l = Math.ceil((t - c + 1) / 7);
  14309. return y.create(l);
  14310. }
  14311. }
  14312. class ig extends V {
  14313. constructor() {
  14314. super(...arguments);
  14315. A(this, "minParams", 1);
  14316. A(this, "maxParams", 1);
  14317. }
  14318. calculate(e) {
  14319. return e.isError() ? e : e.isArray() ? e.map((t) => t.isError() ? t : this._handleSingleObject(t)) : this._handleSingleObject(e);
  14320. }
  14321. _handleSingleObject(e) {
  14322. const t = k(e);
  14323. if (typeof t != "number")
  14324. return t;
  14325. if (t === 0)
  14326. return y.create(0);
  14327. const n = va(t).getUTCMinutes();
  14328. return y.create(n);
  14329. }
  14330. }
  14331. class og extends V {
  14332. constructor() {
  14333. super(...arguments);
  14334. A(this, "minParams", 1);
  14335. A(this, "maxParams", 1);
  14336. }
  14337. calculate(e) {
  14338. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  14339. }
  14340. _handleSingleObject(e) {
  14341. if (e.isError())
  14342. return e;
  14343. let t;
  14344. const r = e.getValue();
  14345. if (e.isString()) {
  14346. if (!Ta(`${r}`))
  14347. return g.create(m.VALUE);
  14348. t = /* @__PURE__ */ new Date(`${r}`);
  14349. } else {
  14350. const o = +e.getValue();
  14351. if (o < 0)
  14352. return g.create(m.NUM);
  14353. if (o === 0)
  14354. return y.create(1);
  14355. t = re(o);
  14356. }
  14357. const n = t.getUTCMonth() + 1;
  14358. return y.create(n);
  14359. }
  14360. }
  14361. class ug extends V {
  14362. constructor() {
  14363. super(...arguments);
  14364. A(this, "minParams", 2);
  14365. A(this, "maxParams", 3);
  14366. }
  14367. calculate(e, t, r) {
  14368. let n = e, s = t;
  14369. if (n.isArray()) {
  14370. const l = n.getRowCount(), f = n.getColumnCount();
  14371. if (l > 1 || f > 1)
  14372. return g.create(m.VALUE);
  14373. n = n.get(0, 0);
  14374. }
  14375. if (n.isError())
  14376. return n;
  14377. if (s.isArray()) {
  14378. const l = s.getRowCount(), f = s.getColumnCount();
  14379. if (l > 1 || f > 1)
  14380. return g.create(m.VALUE);
  14381. s = s.get(0, 0);
  14382. }
  14383. if (s.isError())
  14384. return s;
  14385. if (r != null && r.isError())
  14386. return r;
  14387. if (n.isBoolean() || s.isBoolean())
  14388. return g.create(m.VALUE);
  14389. const o = k(n);
  14390. if (typeof o != "number")
  14391. return o;
  14392. const u = k(s);
  14393. if (typeof u != "number")
  14394. return u;
  14395. if (r)
  14396. return this._getResultByHolidays(o, u, r);
  14397. const c = On(o, u);
  14398. return y.create(c);
  14399. }
  14400. _getResultByHolidays(e, t, r) {
  14401. const n = [];
  14402. if (r != null && r.isArray()) {
  14403. const o = r.getRowCount(), u = r.getColumnCount();
  14404. for (let c = 0; c < o; c++)
  14405. for (let l = 0; l < u; l++) {
  14406. const f = r.get(c, l);
  14407. if (f.isBoolean())
  14408. return g.create(m.VALUE);
  14409. const h = k(f);
  14410. if (typeof h != "number")
  14411. return h;
  14412. n.push(h);
  14413. }
  14414. } else {
  14415. if (r.isBoolean())
  14416. return g.create(m.VALUE);
  14417. const o = k(r);
  14418. if (typeof o != "number")
  14419. return o;
  14420. n.push(o);
  14421. }
  14422. const s = On(e, t, 1, n);
  14423. return y.create(s);
  14424. }
  14425. }
  14426. class cg extends V {
  14427. constructor() {
  14428. super(...arguments);
  14429. A(this, "minParams", 2);
  14430. A(this, "maxParams", 4);
  14431. }
  14432. calculate(e, t, r, n) {
  14433. return e.isError() ? e : t.isError() ? t : r != null && r.isError() ? r : n != null && n.isError() ? n : r != null && r.isArray() ? r.map((s) => this._handleSingleObject(e, t, s, n)) : this._handleSingleObject(e, t, r, n);
  14434. }
  14435. _handleSingleObject(e, t, r, n) {
  14436. let s = e, o = t;
  14437. if (s.isArray()) {
  14438. const h = s.getRowCount(), d = s.getColumnCount();
  14439. if (h > 1 || d > 1)
  14440. return g.create(m.VALUE);
  14441. s = s.get(0, 0);
  14442. }
  14443. if (s.isError())
  14444. return s;
  14445. if (o.isArray()) {
  14446. const h = o.getRowCount(), d = o.getColumnCount();
  14447. if (h > 1 || d > 1)
  14448. return g.create(m.VALUE);
  14449. o = o.get(0, 0);
  14450. }
  14451. if (o.isError())
  14452. return o;
  14453. let u = 1;
  14454. if (r) {
  14455. if (u = r.getValue(), r.isBoolean() && (u = +u), r.isString() && !Ur(u))
  14456. return g.create(m.VALUE);
  14457. if (!Ur(u))
  14458. return g.create(m.NUM);
  14459. }
  14460. if (s.isBoolean() || o.isBoolean())
  14461. return g.create(m.VALUE);
  14462. const c = k(s);
  14463. if (typeof c != "number")
  14464. return c;
  14465. const l = k(o);
  14466. if (typeof l != "number")
  14467. return l;
  14468. if (n)
  14469. return this._getResultByHolidays(c, l, u, n);
  14470. const f = On(c, l, u);
  14471. return y.create(f);
  14472. }
  14473. _getResultByHolidays(e, t, r, n) {
  14474. const s = [];
  14475. if (n != null && n.isArray()) {
  14476. const u = n.getRowCount(), c = n.getColumnCount();
  14477. for (let l = 0; l < u; l++)
  14478. for (let f = 0; f < c; f++) {
  14479. const h = n.get(l, f);
  14480. if (h.isBoolean())
  14481. return g.create(m.VALUE);
  14482. const d = k(h);
  14483. if (typeof d != "number")
  14484. return d;
  14485. s.push(d);
  14486. }
  14487. } else {
  14488. if (n.isBoolean())
  14489. return g.create(m.VALUE);
  14490. const u = k(n);
  14491. if (typeof u != "number")
  14492. return u;
  14493. s.push(u);
  14494. }
  14495. const o = On(e, t, r, s);
  14496. return y.create(o);
  14497. }
  14498. }
  14499. class lg extends V {
  14500. constructor() {
  14501. super(...arguments);
  14502. A(this, "minParams", 0);
  14503. A(this, "maxParams", 0);
  14504. }
  14505. calculate() {
  14506. const e = /* @__PURE__ */ new Date(), t = new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes(), e.getSeconds())), r = Yr(t);
  14507. return y.create(r, Fm);
  14508. }
  14509. }
  14510. class fg extends V {
  14511. constructor() {
  14512. super(...arguments);
  14513. A(this, "minParams", 1);
  14514. A(this, "maxParams", 1);
  14515. }
  14516. calculate(e) {
  14517. return e.isError() ? e : e.isArray() ? e.map((t) => t.isError() ? t : this._handleSingleObject(t)) : this._handleSingleObject(e);
  14518. }
  14519. _handleSingleObject(e) {
  14520. const t = k(e);
  14521. if (typeof t != "number")
  14522. return t;
  14523. if (t === 0)
  14524. return y.create(0);
  14525. const n = va(t).getUTCSeconds();
  14526. return y.create(n);
  14527. }
  14528. }
  14529. class hg extends V {
  14530. constructor() {
  14531. super(...arguments);
  14532. A(this, "minParams", 3);
  14533. A(this, "maxParams", 3);
  14534. }
  14535. calculate(e, t, r) {
  14536. if (e.isError())
  14537. return e;
  14538. if (t.isError())
  14539. return t;
  14540. if (r.isError())
  14541. return r;
  14542. const n = Math.max(
  14543. e.isArray() ? e.getRowCount() : 1,
  14544. t.isArray() ? t.getRowCount() : 1,
  14545. r.isArray() ? r.getRowCount() : 1
  14546. ), s = Math.max(
  14547. e.isArray() ? e.getColumnCount() : 1,
  14548. t.isArray() ? t.getColumnCount() : 1,
  14549. r.isArray() ? r.getColumnCount() : 1
  14550. ), o = O(n, s, e), u = O(n, s, t), c = O(n, s, r);
  14551. return o.map((l, f, h) => this._calculateTime(l, u, c, f, h));
  14552. }
  14553. _calculateTime(e, t, r, n, s) {
  14554. let o = e, u = t.get(n, s) || ie.create(), c = r.get(n, s) || ie.create();
  14555. if ((o.isString() || o.isBoolean()) && (o = o.convertToNumberObjectValue()), (u.isString() || u.isBoolean()) && (u = u.convertToNumberObjectValue()), (c.isString() || c.isBoolean()) && (c = c.convertToNumberObjectValue()), o.isError())
  14556. return o;
  14557. if (u.isError())
  14558. return u;
  14559. if (c.isError())
  14560. return c;
  14561. let l = Math.floor(+o.getValue()), f = Math.floor(+u.getValue()), h = Math.floor(+c.getValue());
  14562. if (l < 0 || f < 0 || h < 0 || l > 32767 || f > 32767 || h > 32767)
  14563. return g.create(m.NUM);
  14564. f += Math.floor(h / 60), h %= 60, l += Math.floor(f / 60), f %= 60, l %= 24;
  14565. const _ = (l * 3600 + f * 60 + h) / 86400;
  14566. return y.create(_, km);
  14567. }
  14568. }
  14569. class mg extends V {
  14570. constructor() {
  14571. super(...arguments);
  14572. A(this, "minParams", 1);
  14573. A(this, "maxParams", 1);
  14574. }
  14575. calculate(e) {
  14576. return e.isError() ? e : e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  14577. }
  14578. _handleSingleObject(e) {
  14579. if (e.isString()) {
  14580. const t = `${e.getValue()}`, r = du(t);
  14581. if (r) {
  14582. let { v: n, z: s } = r;
  14583. if (s && Ba(s))
  14584. return n instanceof Date && (n = Yr(n)), y.create(Af(+n));
  14585. }
  14586. }
  14587. return g.create(m.VALUE);
  14588. }
  14589. }
  14590. class gg extends V {
  14591. constructor() {
  14592. super(...arguments);
  14593. A(this, "minParams", 1);
  14594. A(this, "maxParams", 1);
  14595. A(this, "needsReferenceObject", !0);
  14596. }
  14597. calculate(e) {
  14598. const t = e.isReferenceObject();
  14599. let r = e;
  14600. if (t && (r = e.toArrayValueObject()), r.isArray()) {
  14601. const s = r.getRowCount(), o = r.getColumnCount();
  14602. if (s > 1 || o > 1)
  14603. return g.create(m.VALUE);
  14604. r = r.get(0, 0);
  14605. }
  14606. if (r.isError() || r.isNull() || r.isBoolean() || r.isString() || !t && r.isNumber() && r.getPattern() !== "")
  14607. return r;
  14608. const n = +r.getValue();
  14609. return y.create(n, "yyyy-MM-dd hh:mm:ss AM/PM");
  14610. }
  14611. }
  14612. class dg extends V {
  14613. constructor() {
  14614. super(...arguments);
  14615. A(this, "minParams", 0);
  14616. A(this, "maxParams", 0);
  14617. }
  14618. calculate() {
  14619. const e = ye(/* @__PURE__ */ new Date());
  14620. return y.create(e, Ua);
  14621. }
  14622. }
  14623. class Cg extends V {
  14624. constructor() {
  14625. super(...arguments);
  14626. A(this, "minParams", 1);
  14627. A(this, "maxParams", 2);
  14628. A(this, "_returnTypeMap", {
  14629. 1: [1, 2, 3, 4, 5, 6, 7],
  14630. // Sunday = 1 ~ Saturday = 7
  14631. 2: [7, 1, 2, 3, 4, 5, 6],
  14632. // Monday = 1 ~ Sunday = 7
  14633. 3: [6, 0, 1, 2, 3, 4, 5],
  14634. // Monday = 0 ~ Sunday = 6
  14635. 11: [7, 1, 2, 3, 4, 5, 6],
  14636. // Monday = 1 ~ Sunday = 7
  14637. 12: [6, 7, 1, 2, 3, 4, 5],
  14638. // Tuesday = 1 ~ Monday = 7
  14639. 13: [5, 6, 7, 1, 2, 3, 4],
  14640. // Wednesday = 1 ~ Tuesday = 7
  14641. 14: [4, 5, 6, 7, 1, 2, 3],
  14642. // Thursday = 1 ~ Wednesday = 7
  14643. 15: [3, 4, 5, 6, 7, 1, 2],
  14644. // Friday = 1 ~ Thursday = 7
  14645. 16: [2, 3, 4, 5, 6, 7, 1],
  14646. // Saturday = 1 ~ Friday = 7
  14647. 17: [1, 2, 3, 4, 5, 6, 7]
  14648. // Sunday = 1 ~ Saturday = 7
  14649. });
  14650. }
  14651. calculate(e, t) {
  14652. const r = t != null ? t : y.create(1);
  14653. if (e.isError())
  14654. return e;
  14655. if (r.isError())
  14656. return r;
  14657. const n = Math.max(
  14658. e.isArray() ? e.getRowCount() : 1,
  14659. r.isArray() ? r.getRowCount() : 1
  14660. ), s = Math.max(
  14661. e.isArray() ? e.getColumnCount() : 1,
  14662. r.isArray() ? r.getColumnCount() : 1
  14663. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.map((l, f, h) => {
  14664. const d = u.get(f, h);
  14665. return this._handleSingleObject(l, d);
  14666. });
  14667. return n === 1 && s === 1 ? c.get(0, 0) : c;
  14668. }
  14669. _handleSingleObject(e, t) {
  14670. let r = t;
  14671. if (e.isError())
  14672. return e;
  14673. if (r.isError())
  14674. return r;
  14675. const n = k(e);
  14676. if (typeof n != "number")
  14677. return n;
  14678. if (r.isString() && (r = r.convertToNumberObjectValue(), r.isError()))
  14679. return r;
  14680. const s = Math.floor(+r.getValue());
  14681. if (!this._returnTypeMap[s])
  14682. return g.create(m.NUM);
  14683. const o = rr(n), u = this._returnTypeMap[s][o];
  14684. return y.create(u);
  14685. }
  14686. }
  14687. class _g extends V {
  14688. constructor() {
  14689. super(...arguments);
  14690. A(this, "minParams", 1);
  14691. A(this, "maxParams", 2);
  14692. A(this, "_returnTypeMap", {
  14693. 1: 0,
  14694. 2: 1,
  14695. 11: 1,
  14696. 12: 2,
  14697. 13: 3,
  14698. 14: 4,
  14699. 15: 5,
  14700. 16: 6,
  14701. 17: 0,
  14702. 21: 4
  14703. });
  14704. }
  14705. calculate(e, t) {
  14706. let r = e, n = t != null ? t : y.create(1);
  14707. if (r.isArray()) {
  14708. const u = r.getRowCount(), c = r.getColumnCount();
  14709. if (u > 1 || c > 1)
  14710. return g.create(m.VALUE);
  14711. r = r.get(0, 0);
  14712. }
  14713. if (r.isError())
  14714. return r;
  14715. if (n.isArray()) {
  14716. const u = n.getRowCount(), c = n.getColumnCount();
  14717. if (u > 1 || c > 1)
  14718. return g.create(m.VALUE);
  14719. n = n.get(0, 0);
  14720. }
  14721. if (n.isError())
  14722. return n;
  14723. if (r.isBoolean())
  14724. return g.create(m.VALUE);
  14725. const s = k(r);
  14726. if (typeof s != "number")
  14727. return s;
  14728. if (n.isBoolean())
  14729. return g.create(m.VALUE);
  14730. const o = Math.floor(+n.getValue());
  14731. return Number.isNaN(o) ? g.create(m.VALUE) : o in this._returnTypeMap ? this._getResult(s, o) : g.create(m.NUM);
  14732. }
  14733. _getResult(e, t) {
  14734. const r = re(e), n = e > 0 ? r.getUTCFullYear() : 1900;
  14735. let s = new Date(Date.UTC(n, 0, 1)), o = ye(s), u = rr(o), c;
  14736. if (t === 21)
  14737. u < 1 ? c = o + 1 : u <= 4 ? c = o - (u - 1) : c = o + (11 - u), e < c && (s = new Date(Date.UTC(n - 1, 0, 1)), o = ye(s), u = rr(o), u < 1 ? c = o + 1 : u <= 4 ? c = o - (u - 1) : c = o + (11 - u));
  14738. else {
  14739. const f = this._returnTypeMap[t];
  14740. u < f ? c = o - (u + 7 - f) : c = o - (u - f);
  14741. }
  14742. const l = Math.ceil((e - c + 1) / 7);
  14743. return y.create(l);
  14744. }
  14745. }
  14746. class Ag extends V {
  14747. constructor() {
  14748. super(...arguments);
  14749. A(this, "minParams", 2);
  14750. A(this, "maxParams", 3);
  14751. }
  14752. calculate(e, t, r) {
  14753. let n = e, s = t;
  14754. if (n.isArray()) {
  14755. const l = n.getRowCount(), f = n.getColumnCount();
  14756. if (l > 1 || f > 1)
  14757. return g.create(m.VALUE);
  14758. n = n.get(0, 0);
  14759. }
  14760. if (n.isError())
  14761. return n;
  14762. if (s.isArray()) {
  14763. const l = s.getRowCount(), f = s.getColumnCount();
  14764. if (l > 1 || f > 1)
  14765. return g.create(m.VALUE);
  14766. s = s.get(0, 0);
  14767. }
  14768. if (s.isError())
  14769. return s;
  14770. if (r != null && r.isError())
  14771. return r;
  14772. if (n.isBoolean() || s.isBoolean())
  14773. return g.create(m.VALUE);
  14774. const o = k(n);
  14775. if (typeof o != "number")
  14776. return o;
  14777. const u = +s.getValue();
  14778. if (Number.isNaN(u))
  14779. return g.create(m.VALUE);
  14780. if (r)
  14781. return this._getResultByHolidays(o, u, r);
  14782. const c = Mn(o, u);
  14783. return typeof c != "number" ? c : y.create(c);
  14784. }
  14785. _getResultByHolidays(e, t, r) {
  14786. const n = [];
  14787. if (r != null && r.isArray()) {
  14788. const o = r.getRowCount(), u = r.getColumnCount();
  14789. for (let c = 0; c < o; c++)
  14790. for (let l = 0; l < u; l++) {
  14791. const f = r.get(c, l);
  14792. if (f.isBoolean())
  14793. return g.create(m.VALUE);
  14794. const h = k(f);
  14795. if (typeof h != "number")
  14796. return h;
  14797. n.push(h);
  14798. }
  14799. } else {
  14800. if (r.isBoolean())
  14801. return g.create(m.VALUE);
  14802. const o = k(r);
  14803. if (typeof o != "number")
  14804. return o;
  14805. n.push(o);
  14806. }
  14807. const s = Mn(e, t, 1, n);
  14808. return typeof s != "number" ? s : y.create(s);
  14809. }
  14810. }
  14811. class Eg extends V {
  14812. constructor() {
  14813. super(...arguments);
  14814. A(this, "minParams", 2);
  14815. A(this, "maxParams", 4);
  14816. }
  14817. calculate(e, t, r, n) {
  14818. return e.isError() ? e : t.isError() ? t : r != null && r.isError() ? r : n != null && n.isError() ? n : r != null && r.isArray() ? r.map((s) => this._handleSingleObject(e, t, s, n)) : this._handleSingleObject(e, t, r, n);
  14819. }
  14820. _handleSingleObject(e, t, r, n) {
  14821. const s = r != null ? r : y.create(1), o = this._checkArrayError(e);
  14822. if (o.isError())
  14823. return o;
  14824. const u = this._checkArrayError(t);
  14825. if (u.isError())
  14826. return u;
  14827. if (o.isBoolean() || u.isBoolean())
  14828. return g.create(m.VALUE);
  14829. const c = k(e);
  14830. if (typeof c != "number")
  14831. return c;
  14832. const l = +t.getValue();
  14833. if (Number.isNaN(l))
  14834. return g.create(m.VALUE);
  14835. let f = s.getValue();
  14836. if (s.isBoolean() && (f = +f), s.isString() && (!Ur(f) || f === "1111111"))
  14837. return g.create(m.VALUE);
  14838. if (!Ur(f))
  14839. return g.create(m.NUM);
  14840. if (n)
  14841. return this._getResultByHolidays(c, l, f, n);
  14842. const h = Mn(c, l, f);
  14843. return typeof h != "number" ? h : y.create(h);
  14844. }
  14845. _checkArrayError(e) {
  14846. let t = e;
  14847. if (t.isArray()) {
  14848. const r = t.getRowCount(), n = t.getColumnCount();
  14849. if (r > 1 || n > 1)
  14850. return g.create(m.VALUE);
  14851. t = t.get(0, 0);
  14852. }
  14853. return t.isError(), t;
  14854. }
  14855. _getResultByHolidays(e, t, r, n) {
  14856. const s = [];
  14857. if (n != null && n.isArray()) {
  14858. const u = n.getRowCount(), c = n.getColumnCount();
  14859. for (let l = 0; l < u; l++)
  14860. for (let f = 0; f < c; f++) {
  14861. const h = n.get(l, f);
  14862. if (h.isBoolean())
  14863. return g.create(m.VALUE);
  14864. const d = k(h);
  14865. if (typeof d != "number")
  14866. return d;
  14867. s.push(d);
  14868. }
  14869. } else {
  14870. if (n.isBoolean())
  14871. return g.create(m.VALUE);
  14872. const u = k(n);
  14873. if (typeof u != "number")
  14874. return u;
  14875. s.push(u);
  14876. }
  14877. const o = Mn(e, t, r, s);
  14878. return typeof o != "number" ? o : y.create(o);
  14879. }
  14880. }
  14881. class bg extends V {
  14882. constructor() {
  14883. super(...arguments);
  14884. A(this, "minParams", 1);
  14885. A(this, "maxParams", 1);
  14886. }
  14887. calculate(e) {
  14888. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  14889. }
  14890. _handleSingleObject(e) {
  14891. if (e.isError())
  14892. return e;
  14893. let t;
  14894. const r = e.getValue();
  14895. if (e.isString()) {
  14896. if (!Ta(`${r}`))
  14897. return g.create(m.VALUE);
  14898. t = /* @__PURE__ */ new Date(`${r}`);
  14899. } else {
  14900. const o = +r;
  14901. if (o < 0)
  14902. return g.create(m.NUM);
  14903. if (o === 0)
  14904. return y.create(1900);
  14905. t = re(o);
  14906. }
  14907. const n = t.getUTCFullYear();
  14908. return y.create(n);
  14909. }
  14910. }
  14911. class yg extends V {
  14912. constructor() {
  14913. super(...arguments);
  14914. A(this, "minParams", 2);
  14915. A(this, "maxParams", 3);
  14916. }
  14917. calculate(e, t, r) {
  14918. let n = r != null ? r : y.create(0);
  14919. const s = Xt(e);
  14920. if (s.isError())
  14921. return s;
  14922. const o = Xt(t);
  14923. if (o.isError())
  14924. return o;
  14925. if (n = Xt(n), n.isError())
  14926. return n;
  14927. if (s.isBoolean() || o.isBoolean() || n.isBoolean())
  14928. return g.create(m.VALUE);
  14929. const u = k(s);
  14930. if (typeof u != "number")
  14931. return u;
  14932. const c = k(o);
  14933. if (typeof c != "number")
  14934. return c;
  14935. const l = Math.floor(+n.getValue());
  14936. if (Number.isNaN(l))
  14937. return g.create(m.VALUE);
  14938. if (l < 0 || l > 4)
  14939. return g.create(m.NUM);
  14940. const { days: f, yearDays: h } = _e(u, c, l), d = f / h;
  14941. return y.create(d);
  14942. }
  14943. }
  14944. const Rg = [
  14945. [Km, be.DATE],
  14946. [Xm, be.DATEDIF],
  14947. [Zm, be.DATEVALUE],
  14948. [zm, be.DAY],
  14949. [Jm, be.DAYS],
  14950. [eg, be.DAYS360],
  14951. [tg, be.EDATE],
  14952. [rg, be.EOMONTH],
  14953. [ng, be.EPOCHTODATE],
  14954. [sg, be.HOUR],
  14955. [ag, be.ISOWEEKNUM],
  14956. [ig, be.MINUTE],
  14957. [og, be.MONTH],
  14958. [ug, be.NETWORKDAYS],
  14959. [cg, be.NETWORKDAYS_INTL],
  14960. [lg, be.NOW],
  14961. [fg, be.SECOND],
  14962. [hg, be.TIME],
  14963. [mg, be.TIMEVALUE],
  14964. [gg, be.TO_DATE],
  14965. [dg, be.TODAY],
  14966. [Cg, be.WEEKDAY],
  14967. [_g, be.WEEKNUM],
  14968. [Ag, be.WORKDAY],
  14969. [Eg, be.WORKDAY_INTL],
  14970. [bg, be.YEAR],
  14971. [yg, be.YEARFRAC]
  14972. ];
  14973. class pg extends V {
  14974. constructor() {
  14975. super(...arguments);
  14976. A(this, "minParams", 2);
  14977. A(this, "maxParams", 2);
  14978. }
  14979. calculate(e, t) {
  14980. if (e.isNull() || t.isNull())
  14981. return g.create(m.NA);
  14982. const { isError: r, errorObject: n, variants: s } = H(e, t);
  14983. if (r)
  14984. return n;
  14985. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  14986. if (Number.isNaN(c) || Number.isNaN(l))
  14987. return g.create(m.VALUE);
  14988. if (l < 0)
  14989. return g.create(m.NUM);
  14990. const f = _r.besseli(c, l);
  14991. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  14992. }
  14993. }
  14994. class Vg extends V {
  14995. constructor() {
  14996. super(...arguments);
  14997. A(this, "minParams", 2);
  14998. A(this, "maxParams", 2);
  14999. }
  15000. calculate(e, t) {
  15001. if (e.isNull() || t.isNull())
  15002. return g.create(m.NA);
  15003. const { isError: r, errorObject: n, variants: s } = H(e, t);
  15004. if (r)
  15005. return n;
  15006. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  15007. if (Number.isNaN(c) || Number.isNaN(l))
  15008. return g.create(m.VALUE);
  15009. if (l < 0)
  15010. return g.create(m.NUM);
  15011. const f = _r.besselj(c, l);
  15012. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  15013. }
  15014. }
  15015. class Ng extends V {
  15016. constructor() {
  15017. super(...arguments);
  15018. A(this, "minParams", 2);
  15019. A(this, "maxParams", 2);
  15020. }
  15021. calculate(e, t) {
  15022. if (e.isNull() || t.isNull())
  15023. return g.create(m.NA);
  15024. const { isError: r, errorObject: n, variants: s } = H(e, t);
  15025. if (r)
  15026. return n;
  15027. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  15028. if (Number.isNaN(c) || Number.isNaN(l))
  15029. return g.create(m.VALUE);
  15030. if (l < 0)
  15031. return g.create(m.NUM);
  15032. const f = _r.besselk(c, l);
  15033. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  15034. }
  15035. }
  15036. class Og extends V {
  15037. constructor() {
  15038. super(...arguments);
  15039. A(this, "minParams", 2);
  15040. A(this, "maxParams", 2);
  15041. }
  15042. calculate(e, t) {
  15043. if (e.isNull() || t.isNull())
  15044. return g.create(m.NA);
  15045. const { isError: r, errorObject: n, variants: s } = H(e, t);
  15046. if (r)
  15047. return n;
  15048. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  15049. if (Number.isNaN(c) || Number.isNaN(l))
  15050. return g.create(m.VALUE);
  15051. if (l < 0)
  15052. return g.create(m.NUM);
  15053. const f = _r.bessely(c, l);
  15054. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  15055. }
  15056. }
  15057. class Mg extends V {
  15058. constructor() {
  15059. super(...arguments);
  15060. A(this, "minParams", 1);
  15061. A(this, "maxParams", 1);
  15062. }
  15063. calculate(e) {
  15064. const { isError: t, errorObject: r, variants: n } = H(e);
  15065. if (t)
  15066. return r;
  15067. const [s] = n, o = `${s.getValue()}`;
  15068. if (!Ra(o))
  15069. return g.create(m.NUM);
  15070. let u;
  15071. return o.length === 10 && o.substring(0, 1) === "1" ? u = Number.parseInt(o.substring(1), 2) - 512 : u = Number.parseInt(o, 2), y.create(u);
  15072. }
  15073. }
  15074. class wg extends V {
  15075. constructor() {
  15076. super(...arguments);
  15077. A(this, "minParams", 1);
  15078. A(this, "maxParams", 2);
  15079. }
  15080. calculate(e, t) {
  15081. if (e.isNull())
  15082. return g.create(m.NA);
  15083. let r = 0;
  15084. if (t) {
  15085. const { isError: f, errorObject: h, variants: d } = H(t);
  15086. if (f)
  15087. return h;
  15088. const [_] = d;
  15089. if (r = Math.floor(+_.getValue()), Number.isNaN(r))
  15090. return g.create(m.VALUE);
  15091. if (r < 0 || r > 10)
  15092. return g.create(m.NUM);
  15093. }
  15094. const { isError: n, errorObject: s, variants: o } = H(e);
  15095. if (n)
  15096. return s;
  15097. const [u] = o, c = `${u.getValue()}`;
  15098. if (!Ra(c))
  15099. return g.create(m.NUM);
  15100. let l;
  15101. if (c.length === 10 && c.substring(0, 1) === "1")
  15102. l = (1099511627264 + Number.parseInt(c.substring(1), 2)).toString(16);
  15103. else if (l = Number.parseInt(c, 2).toString(16), t) {
  15104. if (r < l.length)
  15105. return g.create(m.NUM);
  15106. l = "0".repeat(r - l.length) + l;
  15107. }
  15108. return j.create(l.toLocaleUpperCase());
  15109. }
  15110. }
  15111. class Dg extends V {
  15112. constructor() {
  15113. super(...arguments);
  15114. A(this, "minParams", 1);
  15115. A(this, "maxParams", 2);
  15116. }
  15117. calculate(e, t) {
  15118. if (e.isNull())
  15119. return g.create(m.NA);
  15120. let r = 0;
  15121. if (t) {
  15122. const { isError: f, errorObject: h, variants: d } = H(t);
  15123. if (f)
  15124. return h;
  15125. const [_] = d;
  15126. if (r = Math.floor(+_.getValue()), Number.isNaN(r))
  15127. return g.create(m.VALUE);
  15128. if (r < 0 || r > 10)
  15129. return g.create(m.NUM);
  15130. }
  15131. const { isError: n, errorObject: s, variants: o } = H(e);
  15132. if (n)
  15133. return s;
  15134. const [u] = o, c = `${u.getValue()}`;
  15135. if (!Ra(c))
  15136. return g.create(m.NUM);
  15137. let l;
  15138. if (c.length === 10 && c.substring(0, 1) === "1")
  15139. l = (1073741312 + Number.parseInt(c.substring(1), 2)).toString(8);
  15140. else if (l = Number.parseInt(c, 2).toString(8), t) {
  15141. if (r < l.length)
  15142. return g.create(m.NUM);
  15143. l = "0".repeat(r - l.length) + l;
  15144. }
  15145. return j.create(l);
  15146. }
  15147. }
  15148. class Sg extends V {
  15149. constructor() {
  15150. super(...arguments);
  15151. A(this, "minParams", 2);
  15152. A(this, "maxParams", 2);
  15153. }
  15154. calculate(e, t) {
  15155. if (e.isError())
  15156. return e;
  15157. if (t.isError())
  15158. return t;
  15159. const r = Math.max(
  15160. e.isArray() ? e.getRowCount() : 1,
  15161. t.isArray() ? t.getRowCount() : 1
  15162. ), n = Math.max(
  15163. e.isArray() ? e.getColumnCount() : 1,
  15164. t.isArray() ? t.getColumnCount() : 1
  15165. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  15166. let h = c;
  15167. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  15168. return h;
  15169. let d = o.get(l, f);
  15170. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  15171. return d;
  15172. const _ = +h.getValue(), C = +d.getValue();
  15173. if (_ < 0 || C < 0 || Math.floor(_) !== _ || Math.floor(C) !== C || _ > 281474976710655 || C > 281474976710655)
  15174. return g.create(m.NUM);
  15175. const E = _ & C;
  15176. return y.create(E);
  15177. });
  15178. return r === 1 && n === 1 ? u.get(0, 0) : u;
  15179. }
  15180. }
  15181. class Pg extends V {
  15182. constructor() {
  15183. super(...arguments);
  15184. A(this, "minParams", 2);
  15185. A(this, "maxParams", 2);
  15186. }
  15187. calculate(e, t) {
  15188. if (e.isError())
  15189. return e;
  15190. if (t.isError())
  15191. return t;
  15192. const r = Math.max(
  15193. e.isArray() ? e.getRowCount() : 1,
  15194. t.isArray() ? t.getRowCount() : 1
  15195. ), n = Math.max(
  15196. e.isArray() ? e.getColumnCount() : 1,
  15197. t.isArray() ? t.getColumnCount() : 1
  15198. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  15199. let h = c;
  15200. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  15201. return h;
  15202. let d = o.get(l, f);
  15203. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  15204. return d;
  15205. const _ = +h.getValue();
  15206. let C = +d.getValue();
  15207. if (_ < 0 || Math.floor(_) !== _ || _ > 281474976710655 || Math.abs(C) > 53)
  15208. return g.create(m.NUM);
  15209. C = Math.trunc(C);
  15210. const E = Number(C >= 0 ? BigInt(_) << BigInt(C) : BigInt(_) >> BigInt(-C));
  15211. return E > 281474976710655 ? g.create(m.NUM) : y.create(E);
  15212. });
  15213. return r === 1 && n === 1 ? u.get(0, 0) : u;
  15214. }
  15215. }
  15216. class Lg extends V {
  15217. constructor() {
  15218. super(...arguments);
  15219. A(this, "minParams", 2);
  15220. A(this, "maxParams", 2);
  15221. }
  15222. calculate(e, t) {
  15223. if (e.isError())
  15224. return e;
  15225. if (t.isError())
  15226. return t;
  15227. const r = Math.max(
  15228. e.isArray() ? e.getRowCount() : 1,
  15229. t.isArray() ? t.getRowCount() : 1
  15230. ), n = Math.max(
  15231. e.isArray() ? e.getColumnCount() : 1,
  15232. t.isArray() ? t.getColumnCount() : 1
  15233. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  15234. let h = c;
  15235. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  15236. return h;
  15237. let d = o.get(l, f);
  15238. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  15239. return d;
  15240. const _ = +h.getValue(), C = +d.getValue();
  15241. if (_ < 0 || C < 0 || Math.floor(_) !== _ || Math.floor(C) !== C || _ > 281474976710655 || C > 281474976710655)
  15242. return g.create(m.NUM);
  15243. const E = Number(BigInt(_) | BigInt(C));
  15244. return y.create(E);
  15245. });
  15246. return r === 1 && n === 1 ? u.get(0, 0) : u;
  15247. }
  15248. }
  15249. class xg extends V {
  15250. constructor() {
  15251. super(...arguments);
  15252. A(this, "minParams", 2);
  15253. A(this, "maxParams", 2);
  15254. }
  15255. calculate(e, t) {
  15256. if (e.isError())
  15257. return e;
  15258. if (t.isError())
  15259. return t;
  15260. const r = Math.max(
  15261. e.isArray() ? e.getRowCount() : 1,
  15262. t.isArray() ? t.getRowCount() : 1
  15263. ), n = Math.max(
  15264. e.isArray() ? e.getColumnCount() : 1,
  15265. t.isArray() ? t.getColumnCount() : 1
  15266. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  15267. let h = c;
  15268. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  15269. return h;
  15270. let d = o.get(l, f);
  15271. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  15272. return d;
  15273. const _ = +h.getValue();
  15274. let C = +d.getValue();
  15275. if (_ < 0 || Math.floor(_) !== _ || _ > 281474976710655 || Math.abs(C) > 53)
  15276. return g.create(m.NUM);
  15277. C = Math.trunc(C);
  15278. const E = Number(C >= 0 ? BigInt(_) >> BigInt(C) : BigInt(_) << BigInt(-C));
  15279. return E > 281474976710655 ? g.create(m.NUM) : y.create(E);
  15280. });
  15281. return r === 1 && n === 1 ? u.get(0, 0) : u;
  15282. }
  15283. }
  15284. class jg extends V {
  15285. constructor() {
  15286. super(...arguments);
  15287. A(this, "minParams", 2);
  15288. A(this, "maxParams", 2);
  15289. }
  15290. calculate(e, t) {
  15291. if (e.isError())
  15292. return e;
  15293. if (t.isError())
  15294. return t;
  15295. const r = Math.max(
  15296. e.isArray() ? e.getRowCount() : 1,
  15297. t.isArray() ? t.getRowCount() : 1
  15298. ), n = Math.max(
  15299. e.isArray() ? e.getColumnCount() : 1,
  15300. t.isArray() ? t.getColumnCount() : 1
  15301. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  15302. let h = c;
  15303. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  15304. return h;
  15305. let d = o.get(l, f);
  15306. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  15307. return d;
  15308. const _ = +h.getValue(), C = +d.getValue();
  15309. if (_ < 0 || C < 0 || Math.floor(_) !== _ || Math.floor(C) !== C || _ > 281474976710655 || C > 281474976710655)
  15310. return g.create(m.NUM);
  15311. const E = _ ^ C;
  15312. return y.create(E);
  15313. });
  15314. return r === 1 && n === 1 ? u.get(0, 0) : u;
  15315. }
  15316. }
  15317. L.prototype.cos = function() {
  15318. const i = this.toNumber();
  15319. return new L(Math.cos(i));
  15320. };
  15321. let fe = class ce {
  15322. constructor(a) {
  15323. A(this, "_inumber", "");
  15324. A(this, "_realNum", 0);
  15325. A(this, "_iNum", 0);
  15326. A(this, "_suffix", "");
  15327. A(this, "_isError", !1);
  15328. if (`${a}`.trim() === "") {
  15329. this._isError = !0;
  15330. return;
  15331. }
  15332. this._inumber = a, this._getImReal(), this._getImAginary(), this._getImSuffix();
  15333. }
  15334. static getComplex(a, e, t) {
  15335. const r = new L(a).toSignificantDigits(15).toNumber(), n = new L(e).toSignificantDigits(15).toNumber(), s = t === "" ? "i" : t;
  15336. let o;
  15337. if (r === 0 && n === 0)
  15338. o = 0;
  15339. else if (r === 0)
  15340. o = n === 1 ? s : `${n}${s}`;
  15341. else if (n === 0)
  15342. o = r;
  15343. else {
  15344. const u = n > 0 ? "+" : "", c = n === 1 ? s : `${n}${s}`;
  15345. o = `${r}${u}${c}`;
  15346. }
  15347. return o;
  15348. }
  15349. static createByComplexStr(a, e, t) {
  15350. const r = ce.getComplex(a, e, t);
  15351. return new ce(r);
  15352. }
  15353. _getImReal() {
  15354. if (this._inumber === 0 || this._inumber === "0") {
  15355. this._realNum = 0;
  15356. return;
  15357. }
  15358. const a = `${this._inumber}`;
  15359. if (["i", "+i", "1i", "+1i", "-i", "-1i", "j", "+j", "1j", "+1j", "-j", "-1j"].indexOf(a) >= 0) {
  15360. this._realNum = 0;
  15361. return;
  15362. }
  15363. let e = a.indexOf("+"), t = a.indexOf("-");
  15364. e === 0 && (e = a.indexOf("+", 1)), t === 0 && (t = a.indexOf("-", 1));
  15365. const r = a.substring(a.length - 1, a.length), n = r === "i" || r === "j";
  15366. if (e >= 0 || t >= 0) {
  15367. if (!n) {
  15368. this._isError = !0;
  15369. return;
  15370. }
  15371. e >= 0 ? Number.isNaN(+a.substring(0, e)) || Number.isNaN(+a.substring(e + 1, a.length - 1)) ? this._isError = !0 : this._realNum = +a.substring(0, e) : Number.isNaN(+a.substring(0, t)) || Number.isNaN(+a.substring(t + 1, a.length - 1)) ? this._isError = !0 : this._realNum = +a.substring(0, t);
  15372. } else
  15373. n ? Number.isNaN(+a.substring(0, a.length - 1)) ? this._isError = !0 : this._realNum = 0 : Number.isNaN(+a) ? this._isError = !0 : this._realNum = +a;
  15374. }
  15375. _getImAginary() {
  15376. if (this._isError)
  15377. return;
  15378. if (this._inumber === 0 || this._inumber === "0") {
  15379. this._iNum = 0;
  15380. return;
  15381. }
  15382. let a = `${this._inumber}`;
  15383. if (["i", "j"].indexOf(a) >= 0) {
  15384. this._iNum = 1;
  15385. return;
  15386. }
  15387. a = a.replace("+i", "+1i").replace("-i", "-1i").replace("+j", "+1j").replace("-j", "-1j");
  15388. let e = a.indexOf("+"), t = a.indexOf("-");
  15389. e === 0 && (e = a.indexOf("+", 1)), t === 0 && (t = a.indexOf("-", 1));
  15390. const r = a.substring(a.length - 1, a.length), n = r === "i" || r === "j";
  15391. if (e >= 0 || t >= 0) {
  15392. if (!n) {
  15393. this._isError = !0;
  15394. return;
  15395. }
  15396. e >= 0 ? Number.isNaN(+a.substring(0, e)) || Number.isNaN(+a.substring(e + 1, a.length - 1)) ? this._isError = !0 : this._iNum = +a.substring(e + 1, a.length - 1) : Number.isNaN(+a.substring(0, t)) || Number.isNaN(+a.substring(t + 1, a.length - 1)) ? this._isError = !0 : this._iNum = -+a.substring(t + 1, a.length - 1);
  15397. } else
  15398. n ? Number.isNaN(+a.substring(0, a.length - 1)) ? this._isError = !0 : this._iNum = +a.substring(0, a.length - 1) : Number.isNaN(+a) ? this._isError = !0 : this._iNum = 0;
  15399. }
  15400. _getImSuffix() {
  15401. const a = `${this._inumber}`, e = a.substring(a.length - 1);
  15402. this._suffix = e === "i" || e === "j" ? e : "";
  15403. }
  15404. getRealNum() {
  15405. return this._realNum;
  15406. }
  15407. getINum() {
  15408. return this._iNum;
  15409. }
  15410. getSuffix() {
  15411. return this._suffix;
  15412. }
  15413. isError() {
  15414. return this._isError;
  15415. }
  15416. toString() {
  15417. return ce.getComplex(this._realNum, this._iNum, this._suffix);
  15418. }
  15419. isDifferentSuffixes(a) {
  15420. const e = a.getSuffix();
  15421. return this._suffix === "" || e === "" ? !1 : this._suffix !== e;
  15422. }
  15423. Abs() {
  15424. return L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2))).toSignificantDigits(16).toNumber();
  15425. }
  15426. Argument() {
  15427. const a = L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2)));
  15428. let e = L.acos(new L(this._realNum).div(a)).toSignificantDigits(16).toNumber();
  15429. return this._iNum < 0 && (e = -e), e;
  15430. }
  15431. Conjugate() {
  15432. return ce.getComplex(this._realNum, -this._iNum, this._suffix);
  15433. }
  15434. Cos() {
  15435. if (this._iNum) {
  15436. const a = L.cos(this._realNum).mul(L.cosh(this._iNum)).toNumber(), e = L.sin(this._realNum).mul(L.sinh(this._iNum)).negated().toNumber();
  15437. return ce.getComplex(a, e, this._suffix);
  15438. } else {
  15439. const a = L.cos(this._realNum).toNumber();
  15440. return ce.getComplex(a, this._iNum, this._suffix);
  15441. }
  15442. }
  15443. Cosh() {
  15444. if (!Number.isFinite(Math.sinh(this._realNum)) || !Number.isFinite(Math.cosh(this._realNum)))
  15445. return this._isError = !0, "";
  15446. if (this._iNum) {
  15447. const a = L.cosh(this._realNum).mul(L.cos(this._iNum)).toNumber(), e = L.sinh(this._realNum).mul(L.sin(this._iNum)).toNumber();
  15448. return ce.getComplex(a, e, this._suffix);
  15449. } else {
  15450. const a = L.cosh(this._realNum).toNumber();
  15451. return ce.getComplex(a, this._iNum, this._suffix);
  15452. }
  15453. }
  15454. Cot() {
  15455. if (this._iNum) {
  15456. const a = L.cosh(this._iNum * 2).sub(L.cos(this._realNum * 2)), e = L.sin(this._realNum * 2).div(a).toNumber(), t = L.sinh(this._iNum * 2).div(a).negated().toNumber();
  15457. return ce.getComplex(e, t, this._suffix);
  15458. } else {
  15459. const a = new L(1).div(L.tan(this._realNum)).toNumber();
  15460. return ce.getComplex(a, this._iNum, this._suffix);
  15461. }
  15462. }
  15463. Coth() {
  15464. if (!Number.isFinite(Math.sinh(this._realNum)) || !Number.isFinite(Math.cosh(this._realNum)))
  15465. return this._isError = !0, "";
  15466. if (this._iNum) {
  15467. const a = L.cosh(this._realNum * 2).sub(L.cos(this._iNum * 2)), e = L.sinh(this._realNum * 2).div(a).toNumber(), t = L.sin(this._iNum * 2).div(a).negated().toNumber();
  15468. return ce.getComplex(e, t, this._suffix);
  15469. } else {
  15470. const a = new L(1).div(L.tanh(this._realNum)).toNumber();
  15471. return ce.getComplex(a, this._iNum, this._suffix);
  15472. }
  15473. }
  15474. Csc() {
  15475. if (this._iNum) {
  15476. const a = L.cosh(this._iNum * 2).sub(L.cos(this._realNum * 2)), e = L.sin(this._realNum).mul(L.cosh(this._iNum)).mul(2).div(a).toNumber(), t = L.cos(this._realNum).mul(L.sinh(this._iNum)).mul(-2).div(a).toNumber();
  15477. return ce.getComplex(e, t, this._suffix);
  15478. } else {
  15479. const a = new L(1).div(L.sin(this._realNum)).toNumber();
  15480. return ce.getComplex(a, this._iNum, this._suffix);
  15481. }
  15482. }
  15483. Csch() {
  15484. if (!Number.isFinite(Math.sinh(this._realNum)) || !Number.isFinite(Math.cosh(this._realNum)))
  15485. return ce.getComplex(0, 0, this._suffix);
  15486. if (this._iNum) {
  15487. const a = L.cosh(this._realNum * 2).sub(L.cos(this._iNum * 2)), e = L.sinh(this._realNum).mul(L.cos(this._iNum)).mul(2).div(a).toNumber(), t = L.cosh(this._realNum).mul(L.sin(this._iNum)).mul(-2).div(a).toNumber();
  15488. return ce.getComplex(e, t, this._suffix);
  15489. } else {
  15490. const a = new L(1).div(L.sinh(this._realNum)).toNumber();
  15491. return ce.getComplex(a, this._iNum, this._suffix);
  15492. }
  15493. }
  15494. Div(a) {
  15495. const e = new L(this._realNum), t = new L(this._iNum), r = new L(a.getRealNum()), n = new L(a.getINum()), s = r.mul(r).add(n.mul(n)), o = e.mul(r).add(t.mul(n)).div(s).toNumber(), u = t.mul(r).sub(e.mul(n)).div(s).toNumber(), c = this._suffix === "" ? a.getSuffix() : this._suffix;
  15496. return ce.getComplex(o, u, c);
  15497. }
  15498. Exp() {
  15499. if (!Number.isFinite(Math.exp(this._realNum)))
  15500. return this._isError = !0, "";
  15501. const a = L.exp(this._realNum).mul(L.cos(this._iNum)).toNumber(), e = L.exp(this._realNum).mul(L.sin(this._iNum)).toNumber();
  15502. return ce.getComplex(a, e, this._suffix);
  15503. }
  15504. Ln() {
  15505. const a = L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2))), e = L.ln(a).toNumber(), t = L.acos(new L(this._realNum).div(a)).toNumber();
  15506. return ce.getComplex(e, t, this._suffix);
  15507. }
  15508. Log(a) {
  15509. const e = L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2))), t = L.ln(e);
  15510. let r = L.acos(new L(this._realNum).div(e));
  15511. this._iNum < 0 && (r = r.negated());
  15512. const n = L.ln(a), s = new L(0), o = n.mul(n).add(s.mul(s));
  15513. if (o.eq(0))
  15514. return this._isError = !0, "";
  15515. const u = t.mul(n).add(r.mul(s)).div(o).toNumber(), c = r.mul(n).sub(t.mul(s)).div(o).toNumber();
  15516. return ce.getComplex(u, c, this._suffix);
  15517. }
  15518. Power(a) {
  15519. if (this._realNum === 0 && this._iNum === 0)
  15520. return a > 0 ? ce.getComplex(this._realNum, this._iNum, this._suffix) : (this._isError = !0, "");
  15521. let e = L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2))), t = L.acos(new L(this._realNum).div(e));
  15522. this._iNum < 0 && (t = t.negated()), e = L.pow(e, a), t = t.mul(a);
  15523. const r = L.cos(t).mul(e).toNumber(), n = L.sin(t).mul(e).toNumber();
  15524. return !Number.isFinite(r) || !Number.isFinite(n) ? (this._isError = !0, "") : ce.getComplex(r, n, this._suffix);
  15525. }
  15526. Product(a) {
  15527. const e = new L(this._realNum), t = new L(this._iNum), r = new L(a.getRealNum()), n = new L(a.getINum()), s = e.mul(r).sub(t.mul(n)).toNumber(), o = e.mul(n).add(t.mul(r)).toNumber(), u = this._suffix === "" ? a.getSuffix() : this._suffix;
  15528. return ce.getComplex(s, o, u);
  15529. }
  15530. Sec() {
  15531. if (this._iNum) {
  15532. const a = L.cosh(this._iNum * 2).add(L.cos(this._realNum * 2)), e = L.cos(this._realNum).mul(L.cosh(this._iNum)).mul(2).div(a).toNumber(), t = L.sin(this._realNum).mul(L.sinh(this._iNum)).mul(2).div(a).toNumber();
  15533. return ce.getComplex(e, t, this._suffix);
  15534. } else {
  15535. const a = new L(1).div(L.cos(this._realNum)).toNumber();
  15536. return ce.getComplex(a, this._iNum, this._suffix);
  15537. }
  15538. }
  15539. Sech() {
  15540. if (!Number.isFinite(Math.sinh(this._realNum * 2)) || !Number.isFinite(Math.cosh(this._realNum * 2)))
  15541. return ce.getComplex(0, 0, this._suffix);
  15542. if (this._iNum) {
  15543. const a = L.cosh(this._realNum * 2).add(L.cos(this._iNum * 2)), e = L.cosh(this._realNum).mul(L.cos(this._iNum)).mul(2).div(a).toNumber(), t = L.sinh(this._realNum).mul(L.sin(this._iNum)).mul(-2).div(a).toNumber();
  15544. return ce.getComplex(e, t, this._suffix);
  15545. } else {
  15546. const a = new L(1).div(L.cosh(this._realNum)).toNumber();
  15547. return ce.getComplex(a, this._iNum, this._suffix);
  15548. }
  15549. }
  15550. Sin() {
  15551. if (this._iNum) {
  15552. const a = L.sin(this._realNum).mul(L.cosh(this._iNum)).toNumber(), e = L.cos(this._realNum).mul(L.sinh(this._iNum)).toNumber();
  15553. return ce.getComplex(a, e, this._suffix);
  15554. } else {
  15555. const a = L.sin(this._realNum).toNumber();
  15556. return ce.getComplex(a, this._iNum, this._suffix);
  15557. }
  15558. }
  15559. Sinh() {
  15560. if (!Number.isFinite(Math.sinh(this._realNum)) || !Number.isFinite(Math.cosh(this._realNum)))
  15561. return this._isError = !0, "";
  15562. if (this._iNum) {
  15563. const a = L.sinh(this._realNum).mul(L.cos(this._iNum)).toNumber(), e = L.cosh(this._realNum).mul(L.sin(this._iNum)).toNumber();
  15564. return ce.getComplex(a, e, this._suffix);
  15565. } else {
  15566. const a = L.sinh(this._realNum).toNumber();
  15567. return ce.getComplex(a, this._iNum, this._suffix);
  15568. }
  15569. }
  15570. Sqrt() {
  15571. const a = L.sqrt(L.pow(this._realNum, 2).add(L.pow(this._iNum, 2))), e = L.sqrt(a);
  15572. let t = L.acos(new L(this._realNum).div(a));
  15573. this._iNum < 0 && (t = t.negated());
  15574. const r = e.mul(L.cos(t.div(2).toNumber())).toNumber(), n = e.mul(L.sin(t.div(2))).toNumber();
  15575. return ce.getComplex(r, n, this._suffix);
  15576. }
  15577. Sub(a) {
  15578. const e = new L(this._realNum), t = new L(this._iNum), r = new L(a.getRealNum()), n = new L(a.getINum()), s = e.sub(r).toNumber(), o = t.sub(n).toNumber(), u = this._suffix === "" ? a.getSuffix() : this._suffix;
  15579. return ce.getComplex(s, o, u);
  15580. }
  15581. Sum(a) {
  15582. const e = new L(this._realNum), t = new L(this._iNum), r = new L(a.getRealNum()), n = new L(a.getINum()), s = e.add(r).toNumber(), o = t.add(n).toNumber(), u = this._suffix === "" ? a.getSuffix() : this._suffix;
  15583. return ce.getComplex(s, o, u);
  15584. }
  15585. Tan() {
  15586. if (this._iNum) {
  15587. const a = L.cos(this._realNum * 2).add(L.cosh(this._iNum * 2)), e = L.sin(this._realNum * 2).div(a).toNumber(), t = L.sinh(this._iNum * 2).div(a).toNumber();
  15588. return ce.getComplex(e, t, this._suffix);
  15589. } else {
  15590. const a = L.tan(this._realNum).toNumber();
  15591. return ce.getComplex(a, this._iNum, this._suffix);
  15592. }
  15593. }
  15594. Tanh() {
  15595. if (!Number.isFinite(Math.sinh(this._realNum)) || !Number.isFinite(Math.cosh(this._realNum)))
  15596. return this._isError = !0, "";
  15597. if (this._iNum) {
  15598. const a = L.cosh(this._realNum * 2).add(L.cos(this._iNum * 2)), e = L.sinh(this._realNum * 2).div(a).toNumber(), t = L.sin(this._iNum * 2).div(a).toNumber();
  15599. return ce.getComplex(e, t, this._suffix);
  15600. } else {
  15601. const a = L.tanh(this._realNum).toNumber();
  15602. return ce.getComplex(a, this._iNum, this._suffix);
  15603. }
  15604. }
  15605. };
  15606. class Ug extends V {
  15607. constructor() {
  15608. super(...arguments);
  15609. A(this, "minParams", 2);
  15610. A(this, "maxParams", 3);
  15611. }
  15612. calculate(e, t, r) {
  15613. const n = r != null ? r : j.create("i"), { isError: s, errorObject: o, variants: u } = H(e, t, n);
  15614. if (s)
  15615. return o;
  15616. const [c, l, f] = u, h = +c.getValue(), d = +l.getValue(), _ = `${f.getValue()}`;
  15617. if (Number.isNaN(h) || Number.isNaN(d) || _ !== "i" && _ !== "j")
  15618. return g.create(m.VALUE);
  15619. const C = fe.getComplex(h, d, _);
  15620. return typeof C == "number" ? y.create(C) : j.create(C);
  15621. }
  15622. }
  15623. class vg extends V {
  15624. constructor() {
  15625. super(...arguments);
  15626. A(this, "minParams", 3);
  15627. A(this, "maxParams", 3);
  15628. // List of units supported by CONVERT and units defined by the International System of Units
  15629. // [Name, Symbol, Alternate symbols, Quantity, ISU, CONVERT, Conversion ratio]
  15630. A(this, "_units", [
  15631. ["a.u. of action", "?", null, "action", !1, !1, 105457168181818e-48],
  15632. ["a.u. of charge", "e", null, "electric_charge", !1, !1, 160217653141414e-33],
  15633. ["a.u. of energy", "Eh", null, "energy", !1, !1, 435974417757576e-32],
  15634. ["a.u. of length", "a?", null, "length", !1, !1, 529177210818182e-25],
  15635. ["a.u. of mass", "m?", null, "mass", !1, !1, 910938261616162e-45],
  15636. ["a.u. of time", "?/Eh", null, "time", !1, !1, 241888432650516e-31],
  15637. ["admiralty knot", "admkn", null, "speed", !1, !0, 0.514773333],
  15638. ["ampere", "A", null, "electric_current", !0, !1, 1],
  15639. ["ampere per meter", "A/m", null, "magnetic_field_intensity", !0, !1, 1],
  15640. ["ångström", "Å", ["ang"], "length", !1, !0, 1e-10],
  15641. ["are", "ar", null, "area", !1, !0, 100],
  15642. ["astronomical unit", "ua", null, "length", !1, !1, 149597870691667e-25],
  15643. ["bar", "bar", null, "pressure", !1, !1, 1e5],
  15644. ["barn", "b", null, "area", !1, !1, 1e-28],
  15645. ["becquerel", "Bq", null, "radioactivity", !0, !1, 1],
  15646. ["bit", "bit", ["b"], "information", !1, !0, 1],
  15647. ["btu", "BTU", ["btu"], "energy", !1, !0, 1055.05585262],
  15648. ["byte", "byte", null, "information", !1, !0, 8],
  15649. ["candela", "cd", null, "luminous_intensity", !0, !1, 1],
  15650. ["candela per square metre", "cd/m?", null, "luminance", !0, !1, 1],
  15651. ["centigrade", "C", ["cel"], "temperature", !0, !1, 1],
  15652. ["cubic ångström", "ang3", ["ang^3"], "volume", !1, !0, 1e-30],
  15653. ["cubic foot", "ft3", ["ft^3"], "volume", !1, !0, 0.028316846592],
  15654. ["cubic inch", "in3", ["in^3"], "volume", !1, !0, 16387064e-12],
  15655. ["cubic light-year", "ly3", ["ly^3"], "volume", !1, !0, 846786664623715e-61],
  15656. ["cubic metre", "m3", ["m^3"], "volume", !0, !0, 1],
  15657. ["cubic mile", "mi3", ["mi^3"], "volume", !1, !0, 416818182544058e-5],
  15658. ["cubic nautical mile", "Nmi3", ["Nmi^3"], "volume", !1, !0, 6352182208],
  15659. ["cubic Pica", "Pica3", ["Picapt3", "Pica^3", "Picapt^3"], "volume", !1, !0, 758660370370369e-22],
  15660. ["cubic yard", "yd3", ["yd^3"], "volume", !1, !0, 0.764554857984],
  15661. ["cup", "cup", null, "volume", !1, !0, 2365882365e-13],
  15662. ["dalton", "Da", ["u"], "mass", !1, !1, 166053886282828e-41],
  15663. ["day", "d", ["day"], "time", !1, !0, 86400],
  15664. ["degree", "°", null, "angle", !1, !1, 0.0174532925199433],
  15665. ["dyne", "dyn", ["dy"], "force", !1, !0, 1e-5],
  15666. ["electronvolt", "eV", ["ev"], "energy", !1, !0, 1.60217656514141],
  15667. ["ell", "ell", null, "length", !1, !0, 1.143],
  15668. ["erg", "erg", ["e"], "energy", !1, !0, 1e-7],
  15669. ["fahrenheit", "F", ["fah"], "temperature", !0, !1, 1],
  15670. ["fluid ounce", "oz", null, "volume", !1, !0, 295735295625e-16],
  15671. ["foot", "ft", null, "length", !1, !0, 0.3048],
  15672. ["foot-pound", "flb", null, "energy", !1, !0, 1.3558179483314],
  15673. ["gal", "Gal", null, "acceleration", !1, !1, 0.01],
  15674. ["gallon", "gal", null, "volume", !1, !0, 0.003785411784],
  15675. ["gauss", "G", ["ga"], "magnetic_flux_density", !1, !0, 1],
  15676. ["grain", "grain", null, "mass", !1, !0, 647989e-10],
  15677. ["gram", "g", null, "mass", !1, !0, 1e-3],
  15678. ["gray", "Gy", null, "absorbed_dose", !0, !1, 1],
  15679. ["gross registered ton", "GRT", ["regton"], "volume", !1, !0, 2.8316846592],
  15680. ["hectare", "ha", null, "area", !1, !0, 1e4],
  15681. ["henry", "H", null, "inductance", !0, !1, 1],
  15682. ["hertz", "Hz", null, "frequency", !0, !1, 1],
  15683. ["horsepower", "HP", ["h"], "power", !1, !0, 745.69987158227],
  15684. ["horsepower-hour", "HPh", ["hh", "hph"], "energy", !1, !0, 2684519538e-3],
  15685. ["hour", "h", ["hr"], "time", !1, !0, 3600],
  15686. ["imperial gallon (U.K.)", "uk_gal", null, "volume", !1, !0, 454609e-8],
  15687. ["imperial hundredweight", "lcwt", ["uk_cwt", "hweight"], "mass", !1, !0, 50.802345],
  15688. ["imperial quart (U.K)", "uk_qt", null, "volume", !1, !0, 0.0011365225],
  15689. ["imperial ton", "brton", ["uk_ton", "LTON"], "mass", !1, !0, 1016.046909],
  15690. ["inch", "in", null, "length", !1, !0, 0.0254],
  15691. ["international acre", "uk_acre", null, "area", !1, !0, 4046.8564224],
  15692. ["IT calorie", "cal", null, "energy", !1, !0, 4.1868],
  15693. ["joule", "J", null, "energy", !0, !0, 1],
  15694. ["katal", "kat", null, "catalytic_activity", !0, !1, 1],
  15695. ["kelvin", "K", ["kel"], "temperature", !0, !0, 1],
  15696. ["kilogram", "kg", null, "mass", !0, !0, 1],
  15697. ["knot", "kn", null, "speed", !1, !0, 0.514444444444444],
  15698. ["light-year", "ly", null, "length", !1, !0, 9460730472580800],
  15699. ["litre", "L", ["l", "lt"], "volume", !1, !0, 1e-3],
  15700. ["lumen", "lm", null, "luminous_flux", !0, !1, 1],
  15701. ["lux", "lx", null, "illuminance", !0, !1, 1],
  15702. ["maxwell", "Mx", null, "magnetic_flux", !1, !1, 1e-18],
  15703. ["measurement ton", "MTON", null, "volume", !1, !0, 1.13267386368],
  15704. ["meter per hour", "m/h", ["m/hr"], "speed", !1, !0, 27777777777778e-17],
  15705. ["meter per second", "m/s", ["m/sec"], "speed", !0, !0, 1],
  15706. ["meter per second squared", "m?s??", null, "acceleration", !0, !1, 1],
  15707. ["parsec", "pc", ["parsec"], "length", !1, !0, 30856775814671900],
  15708. ["meter squared per second", "m?/s", null, "kinematic_viscosity", !0, !1, 1],
  15709. ["metre", "m", null, "length", !0, !0, 1],
  15710. ["miles per hour", "mph", null, "speed", !1, !0, 0.44704],
  15711. ["millimetre of mercury", "mmHg", null, "pressure", !1, !1, 133.322],
  15712. ["minute", "?", null, "angle", !1, !1, 290888208665722e-18],
  15713. ["minute", "min", ["mn"], "time", !1, !0, 60],
  15714. ["modern teaspoon", "tspm", null, "volume", !1, !0, 5e-6],
  15715. ["mole", "mol", null, "amount_of_substance", !0, !1, 1],
  15716. ["morgen", "Morgen", null, "area", !1, !0, 2500],
  15717. ["n.u. of action", "?", null, "action", !1, !1, 105457168181818e-48],
  15718. ["n.u. of mass", "m?", null, "mass", !1, !1, 910938261616162e-45],
  15719. ["n.u. of speed", "c?", null, "speed", !1, !1, 299792458],
  15720. ["n.u. of time", "?/(me?c??)", null, "time", !1, !1, 128808866778687e-35],
  15721. ["nautical mile", "M", ["Nmi"], "length", !1, !0, 1852],
  15722. ["newton", "N", null, "force", !0, !0, 1],
  15723. ["œrsted", "Oe ", null, "magnetic_field_intensity", !1, !1, 79.5774715459477],
  15724. ["ohm", "Ω", null, "electric_resistance", !0, !1, 1],
  15725. ["ounce mass", "ozm", null, "mass", !1, !0, 0.028349523125],
  15726. ["pascal", "Pa", null, "pressure", !0, !1, 1],
  15727. ["pascal second", "Pa?s", null, "dynamic_viscosity", !0, !1, 1],
  15728. ["pferdestärke", "PS", null, "power", !1, !0, 735.49875],
  15729. ["phot", "ph", null, "illuminance", !1, !1, 1e-4],
  15730. ["pica (1/6 inch)", "pica", null, "length", !1, !0, 35277777777778e-17],
  15731. ["pica (1/72 inch)", "Pica", ["Picapt"], "length", !1, !0, 0.00423333333333333],
  15732. ["poise", "P", null, "dynamic_viscosity", !1, !1, 0.1],
  15733. ["pond", "pond", null, "force", !1, !0, 980665e-8],
  15734. ["pound force", "lbf", null, "force", !1, !0, 4.4482216152605],
  15735. ["pound mass", "lbm", null, "mass", !1, !0, 0.45359237],
  15736. ["quart", "qt", null, "volume", !1, !0, 946352946e-12],
  15737. ["radian", "rad", null, "angle", !0, !1, 1],
  15738. ["rankine", "Rank", null, "temperature", !1, !0, 1],
  15739. ["reaumur", "Reau", null, "temperature", !1, !0, 1],
  15740. ["second", "?", null, "angle", !1, !1, 484813681109536e-20],
  15741. ["second", "s", ["sec"], "time", !0, !0, 1],
  15742. ["short hundredweight", "cwt", ["shweight"], "mass", !1, !0, 45.359237],
  15743. ["siemens", "S", null, "electrical_conductance", !0, !1, 1],
  15744. ["sievert", "Sv", null, "equivalent_dose", !0, !1, 1],
  15745. ["slug", "sg", null, "mass", !1, !0, 14.59390294],
  15746. ["square ångström", "ang2", ["ang^2"], "area", !1, !0, 1e-20],
  15747. ["square foot", "ft2", ["ft^2"], "area", !1, !0, 0.09290304],
  15748. ["square inch", "in2", ["in^2"], "area", !1, !0, 64516e-8],
  15749. ["square light-year", "ly2", ["ly^2"], "area", !1, !0, 895054210748189e17],
  15750. ["square meter", "m?", null, "area", !0, !0, 1],
  15751. ["square mile", "mi2", ["mi^2"], "area", !1, !0, 2589988110336e-6],
  15752. ["square nautical mile", "Nmi2", ["Nmi^2"], "area", !1, !0, 3429904],
  15753. ["square Pica", "Pica2", ["Picapt2", "Pica^2", "Picapt^2"], "area", !1, !0, 1792111111111e-17],
  15754. ["square yard", "yd2", ["yd^2"], "area", !1, !0, 0.83612736],
  15755. ["statute mile", "mi", null, "length", !1, !0, 1609.344],
  15756. ["steradian", "sr", null, "solid_angle", !0, !1, 1],
  15757. ["stilb", "sb", null, "luminance", !1, !1, 1e-4],
  15758. ["stokes", "St", null, "kinematic_viscosity", !1, !1, 1e-4],
  15759. ["stone", "stone", null, "mass", !1, !0, 6.35029318],
  15760. ["tablespoon", "tbs", null, "volume", !1, !0, 147868e-10],
  15761. ["teaspoon", "tsp", null, "volume", !1, !0, 492892e-11],
  15762. ["tesla", "T", null, "magnetic_flux_density", !0, !0, 1],
  15763. ["thermodynamic calorie", "c", null, "energy", !1, !0, 4.184],
  15764. ["ton", "ton", null, "mass", !1, !0, 907.18474],
  15765. ["tonne", "t", null, "mass", !1, !1, 1e3],
  15766. ["U.K. pint", "uk_pt", null, "volume", !1, !0, 56826125e-11],
  15767. ["U.S. bushel", "bushel", null, "volume", !1, !0, 0.03523907],
  15768. ["U.S. oil barrel", "barrel", null, "volume", !1, !0, 0.158987295],
  15769. ["U.S. pint", "pt", ["us_pt"], "volume", !1, !0, 473176473e-12],
  15770. ["U.S. survey mile", "survey_mi", null, "length", !1, !0, 1609.347219],
  15771. ["U.S. survey/statute acre", "us_acre", null, "area", !1, !0, 4046.87261],
  15772. ["volt", "V", null, "voltage", !0, !1, 1],
  15773. ["watt", "W", null, "power", !0, !0, 1],
  15774. ["watt-hour", "Wh", ["wh"], "energy", !1, !0, 3600],
  15775. ["weber", "Wb", null, "magnetic_flux", !0, !1, 1],
  15776. ["yard", "yd", null, "length", !1, !0, 0.9144],
  15777. ["year", "yr", null, "time", !1, !0, 31557600]
  15778. ]);
  15779. // Binary prefixes
  15780. // [Name, Prefix power of 2 value, Previx value, Abbreviation, Derived from]
  15781. A(this, "_binaryPrefixes", {
  15782. Yi: ["yobi", 80, 12089258196146292e8, "Yi", "yotta"],
  15783. Zi: ["zebi", 70, 11805916207174113e5, "Zi", "zetta"],
  15784. Ei: ["exbi", 60, 1152921504606847e3, "Ei", "exa"],
  15785. Pi: ["pebi", 50, 1125899906842624, "Pi", "peta"],
  15786. Ti: ["tebi", 40, 1099511627776, "Ti", "tera"],
  15787. Gi: ["gibi", 30, 1073741824, "Gi", "giga"],
  15788. Mi: ["mebi", 20, 1048576, "Mi", "mega"],
  15789. ki: ["kibi", 10, 1024, "ki", "kilo"]
  15790. });
  15791. // Unit prefixes
  15792. // [Name, Multiplier, Abbreviation]
  15793. A(this, "_unitPrefixes", {
  15794. Y: ["yotta", 1e24, "Y"],
  15795. Z: ["zetta", 1e21, "Z"],
  15796. E: ["exa", 1e18, "E"],
  15797. P: ["peta", 1e15, "P"],
  15798. T: ["tera", 1e12, "T"],
  15799. G: ["giga", 1e9, "G"],
  15800. M: ["mega", 1e6, "M"],
  15801. k: ["kilo", 1e3, "k"],
  15802. h: ["hecto", 100, "h"],
  15803. e: ["dekao", 10, "e"],
  15804. d: ["deci", 0.1, "d"],
  15805. c: ["centi", 0.01, "c"],
  15806. m: ["milli", 1e-3, "m"],
  15807. u: ["micro", 1e-6, "u"],
  15808. n: ["nano", 1e-9, "n"],
  15809. p: ["pico", 1e-12, "p"],
  15810. f: ["femto", 1e-15, "f"],
  15811. a: ["atto", 1e-18, "a"],
  15812. z: ["zepto", 1e-21, "z"],
  15813. y: ["yocto", 1e-24, "y"]
  15814. });
  15815. }
  15816. calculate(e, t, r) {
  15817. const { isError: n, errorObject: s, variants: o } = H(e, t, r);
  15818. if (n)
  15819. return s;
  15820. const [u, c, l] = o, f = +u.getValue(), h = `${c.getValue()}`, d = `${l.getValue()}`;
  15821. if (Number.isNaN(f))
  15822. return g.create(m.VALUE);
  15823. let _, C = 1, E, b = 1;
  15824. const { _from: R, _to: p } = this._lookupFromAndToUnits(h, d);
  15825. if (_ = R, E = p, _ === null) {
  15826. const { _from: M, _fromMultiplier: w } = this._lookupFromPrefix(h);
  15827. _ = M, C = w;
  15828. }
  15829. if (E === null) {
  15830. const { _to: M, _toMultiplier: w } = this._lookupToPrefix(d);
  15831. E = M, b = w;
  15832. }
  15833. if (_ === null || E === null || _[3] !== E[3])
  15834. return g.create(m.NA);
  15835. let N;
  15836. return _[3] === "temperature" ? (N = this._getTemperatureConversion(f, _[1], E[1]), N = +N.toFixed(2)) : N = f * _[6] * C / (E[6] * b), y.create(N);
  15837. }
  15838. _lookupFromAndToUnits(e, t) {
  15839. let r = null, n = null, s;
  15840. for (let o = 0; o < this._units.length; o++)
  15841. s = this._units[o][2] === null ? [] : this._units[o][2], (this._units[o][1] === e || s.indexOf(e) >= 0) && (r = this._units[o]), (this._units[o][1] === t || s.indexOf(t) >= 0) && (n = this._units[o]);
  15842. return {
  15843. _from: r,
  15844. _to: n
  15845. };
  15846. }
  15847. _lookupFromPrefix(e) {
  15848. let t = null, r = 1, n = e, s;
  15849. const o = this._binaryPrefixes[e.substring(0, 2)];
  15850. let u = this._unitPrefixes[e.substring(0, 1)];
  15851. e.substring(0, 2) === "da" && (u = ["dekao", 10, "da"]), o ? (r = o[2], n = e.substring(2)) : u && (r = u[1], n = e.substring(u[2].length));
  15852. for (let c = 0; c < this._units.length; c++)
  15853. s = this._units[c][2] === null ? [] : this._units[c][2], (this._units[c][1] === n || s.indexOf(n) >= 0) && (t = this._units[c]);
  15854. return {
  15855. _from: t,
  15856. _fromMultiplier: r
  15857. };
  15858. }
  15859. _lookupToPrefix(e) {
  15860. let t = null, r = 1, n = e, s;
  15861. const o = this._binaryPrefixes[e.substring(0, 2)];
  15862. let u = this._unitPrefixes[e.substring(0, 1)];
  15863. e.substring(0, 2) === "da" && (u = ["dekao", 10, "da"]), o ? (r = o[2], n = e.substring(2)) : u && (r = u[1], n = e.substring(u[2].length));
  15864. for (let c = 0; c < this._units.length; c++)
  15865. s = this._units[c][2] === null ? [] : this._units[c][2], (this._units[c][1] === n || s.indexOf(n) >= 0) && (t = this._units[c]);
  15866. return {
  15867. _to: t,
  15868. _toMultiplier: r
  15869. };
  15870. }
  15871. _getTemperatureConversion(e, t, r) {
  15872. switch (t) {
  15873. case "C":
  15874. return this._centigradeConversion(e, r);
  15875. case "F":
  15876. return this._fahrenheitConversion(e, r);
  15877. case "K":
  15878. return this._kelvinConversion(e, r);
  15879. case "Rank":
  15880. return this._rankineConversion(e, r);
  15881. case "Reau":
  15882. return this._reaumurConversion(e, r);
  15883. default:
  15884. return e;
  15885. }
  15886. }
  15887. _centigradeConversion(e, t) {
  15888. switch (t) {
  15889. case "F":
  15890. return e * 9 / 5 + 32;
  15891. case "K":
  15892. return e + 273.15;
  15893. case "Rank":
  15894. return (e + 273.15) * 9 / 5;
  15895. case "Reau":
  15896. return e * 4 / 5;
  15897. default:
  15898. return e;
  15899. }
  15900. }
  15901. _fahrenheitConversion(e, t) {
  15902. switch (t) {
  15903. case "C":
  15904. return (e - 32) * 5 / 9;
  15905. case "K":
  15906. return (e - 32) * 5 / 9 + 273.15;
  15907. case "Rank":
  15908. return e + 459.67;
  15909. case "Reau":
  15910. return (e - 32) * 4 / 9;
  15911. default:
  15912. return e;
  15913. }
  15914. }
  15915. _kelvinConversion(e, t) {
  15916. switch (t) {
  15917. case "C":
  15918. return e - 273.15;
  15919. case "F":
  15920. return (e - 273.15) * 9 / 5 + 32;
  15921. case "Rank":
  15922. return e * 9 / 5;
  15923. case "Reau":
  15924. return (e - 273.15) * 4 / 5;
  15925. default:
  15926. return e;
  15927. }
  15928. }
  15929. _rankineConversion(e, t) {
  15930. switch (t) {
  15931. case "C":
  15932. return (e - 491.67) * 5 / 9;
  15933. case "F":
  15934. return e - 459.67;
  15935. case "K":
  15936. return e * 5 / 9;
  15937. case "Reau":
  15938. return (e - 491.67) * 4 / 9;
  15939. default:
  15940. return e;
  15941. }
  15942. }
  15943. _reaumurConversion(e, t) {
  15944. switch (t) {
  15945. case "C":
  15946. return e * 5 / 4;
  15947. case "F":
  15948. return e * 9 / 4 + 32;
  15949. case "K":
  15950. return e * 5 / 4 + 273.15;
  15951. case "Rank":
  15952. return e * 9 / 4 + 491.67;
  15953. default:
  15954. return e;
  15955. }
  15956. }
  15957. }
  15958. class Tg extends V {
  15959. constructor() {
  15960. super(...arguments);
  15961. A(this, "minParams", 1);
  15962. A(this, "maxParams", 2);
  15963. }
  15964. calculate(e, t) {
  15965. if (e.isNull())
  15966. return g.create(m.NA);
  15967. let r = 0;
  15968. if (t) {
  15969. const { isError: f, errorObject: h, variants: d } = H(t);
  15970. if (f)
  15971. return h;
  15972. const [_] = d;
  15973. if (r = Math.floor(+_.getValue()), Number.isNaN(r))
  15974. return g.create(m.VALUE);
  15975. if (r < 0 || r > 10)
  15976. return g.create(m.NUM);
  15977. }
  15978. const { isError: n, errorObject: s, variants: o } = H(e);
  15979. if (n)
  15980. return s;
  15981. const [u] = o, c = Math.trunc(+u.getValue());
  15982. if (Number.isNaN(c))
  15983. return g.create(m.VALUE);
  15984. if (!/^-?[0-9]{1,3}$/.test(`${c}`) || c < -512 || c > 511)
  15985. return g.create(m.NUM);
  15986. let l;
  15987. if (c < 0) {
  15988. const f = (512 + c).toString(2);
  15989. l = `1${"0".repeat(9 - f.length)}${f}`;
  15990. } else if (l = Number.parseInt(`${c}`, 10).toString(2), t) {
  15991. if (r < l.length)
  15992. return g.create(m.NUM);
  15993. l = "0".repeat(r - l.length) + l;
  15994. }
  15995. return j.create(l);
  15996. }
  15997. }
  15998. class Bg extends V {
  15999. constructor() {
  16000. super(...arguments);
  16001. A(this, "minParams", 1);
  16002. A(this, "maxParams", 2);
  16003. }
  16004. calculate(e, t) {
  16005. if (e.isNull())
  16006. return g.create(m.NA);
  16007. let r = 0;
  16008. if (t) {
  16009. const { isError: f, errorObject: h, variants: d } = H(t);
  16010. if (f)
  16011. return h;
  16012. const [_] = d;
  16013. if (r = Math.floor(+_.getValue()), Number.isNaN(r))
  16014. return g.create(m.VALUE);
  16015. if (r < 0 || r > 10)
  16016. return g.create(m.NUM);
  16017. }
  16018. const { isError: n, errorObject: s, variants: o } = H(e);
  16019. if (n)
  16020. return s;
  16021. const [u] = o, c = Math.trunc(+u.getValue());
  16022. if (Number.isNaN(c))
  16023. return g.create(m.VALUE);
  16024. if (!/^-?[0-9]{1,12}$/.test(`${c}`) || c < -549755813888 || c > 549755813887)
  16025. return g.create(m.NUM);
  16026. let l;
  16027. if (c < 0)
  16028. l = (1099511627776 + c).toString(16);
  16029. else if (l = Number.parseInt(`${c}`, 10).toString(16), t) {
  16030. if (r < l.length)
  16031. return g.create(m.NUM);
  16032. l = "0".repeat(r - l.length) + l;
  16033. }
  16034. return j.create(l.toLocaleUpperCase());
  16035. }
  16036. }
  16037. class Ig extends V {
  16038. constructor() {
  16039. super(...arguments);
  16040. A(this, "minParams", 1);
  16041. A(this, "maxParams", 2);
  16042. }
  16043. calculate(e, t) {
  16044. if (e.isNull())
  16045. return g.create(m.NA);
  16046. let r = 0;
  16047. if (t) {
  16048. const { isError: f, errorObject: h, variants: d } = H(t);
  16049. if (f)
  16050. return h;
  16051. const [_] = d;
  16052. if (r = Math.floor(+_.getValue()), Number.isNaN(r))
  16053. return g.create(m.VALUE);
  16054. if (r < 0 || r > 10)
  16055. return g.create(m.NUM);
  16056. }
  16057. const { isError: n, errorObject: s, variants: o } = H(e);
  16058. if (n)
  16059. return s;
  16060. const [u] = o, c = Math.trunc(+u.getValue());
  16061. if (Number.isNaN(c))
  16062. return g.create(m.VALUE);
  16063. if (!/^-?[0-9]{1,9}$/.test(`${c}`) || c < -536870912 || c > 536870911)
  16064. return g.create(m.NUM);
  16065. let l;
  16066. if (c < 0)
  16067. l = (1073741824 + c).toString(8);
  16068. else if (l = Number.parseInt(`${c}`, 10).toString(8), t) {
  16069. if (r < l.length)
  16070. return g.create(m.NUM);
  16071. l = "0".repeat(r - l.length) + l;
  16072. }
  16073. return j.create(l);
  16074. }
  16075. }
  16076. class Fg extends V {
  16077. constructor() {
  16078. super(...arguments);
  16079. A(this, "minParams", 1);
  16080. A(this, "maxParams", 2);
  16081. }
  16082. calculate(e, t) {
  16083. const r = t != null ? t : y.create(0), { isError: n, errorObject: s, variants: o } = H(e, r);
  16084. if (n)
  16085. return s;
  16086. const [u, c] = o, l = +u.getValue(), f = +c.getValue();
  16087. if (Number.isNaN(l) || Number.isNaN(f))
  16088. return g.create(m.VALUE);
  16089. const h = l === f ? 1 : 0;
  16090. return y.create(h);
  16091. }
  16092. }
  16093. class kg extends V {
  16094. constructor() {
  16095. super(...arguments);
  16096. A(this, "minParams", 1);
  16097. A(this, "maxParams", 2);
  16098. }
  16099. calculate(e, t) {
  16100. let r;
  16101. if (t) {
  16102. const { isError: n, errorObject: s, variants: o } = H(e, t);
  16103. if (n)
  16104. return s;
  16105. const [u, c] = o, l = +u.getValue(), f = +c.getValue();
  16106. if (Number.isNaN(l) || Number.isNaN(f))
  16107. return g.create(m.VALUE);
  16108. r = Zt(f) - Zt(l);
  16109. } else {
  16110. const { isError: n, errorObject: s, variants: o } = H(e);
  16111. if (n)
  16112. return s;
  16113. const [u] = o, c = +u.getValue();
  16114. if (Number.isNaN(c))
  16115. return g.create(m.VALUE);
  16116. r = Zt(c);
  16117. }
  16118. return y.create(r);
  16119. }
  16120. }
  16121. class $g extends V {
  16122. constructor() {
  16123. super(...arguments);
  16124. A(this, "minParams", 1);
  16125. A(this, "maxParams", 1);
  16126. }
  16127. calculate(e) {
  16128. const { isError: t, errorObject: r, variants: n } = H(e);
  16129. if (t)
  16130. return r;
  16131. const [s] = n, o = +s.getValue();
  16132. if (Number.isNaN(o))
  16133. return g.create(m.VALUE);
  16134. const u = Zt(o);
  16135. return y.create(u);
  16136. }
  16137. }
  16138. class Yg extends V {
  16139. constructor() {
  16140. super(...arguments);
  16141. A(this, "minParams", 1);
  16142. A(this, "maxParams", 1);
  16143. }
  16144. calculate(e) {
  16145. const { isError: t, errorObject: r, variants: n } = H(e);
  16146. if (t)
  16147. return r;
  16148. const [s] = n, o = +s.getValue();
  16149. if (Number.isNaN(o))
  16150. return g.create(m.VALUE);
  16151. const u = Na(o);
  16152. return y.create(u);
  16153. }
  16154. }
  16155. class Hg extends V {
  16156. constructor() {
  16157. super(...arguments);
  16158. A(this, "minParams", 1);
  16159. A(this, "maxParams", 1);
  16160. }
  16161. calculate(e) {
  16162. const { isError: t, errorObject: r, variants: n } = H(e);
  16163. if (t)
  16164. return r;
  16165. const [s] = n, o = +s.getValue();
  16166. if (Number.isNaN(o))
  16167. return g.create(m.VALUE);
  16168. const u = Na(o);
  16169. return y.create(u);
  16170. }
  16171. }
  16172. var Z = /* @__PURE__ */ ((i) => (i.BESSELI = "BESSELI", i.BESSELJ = "BESSELJ", i.BESSELK = "BESSELK", i.BESSELY = "BESSELY", i.BIN2DEC = "BIN2DEC", i.BIN2HEX = "BIN2HEX", i.BIN2OCT = "BIN2OCT", i.BITAND = "BITAND", i.BITLSHIFT = "BITLSHIFT", i.BITOR = "BITOR", i.BITRSHIFT = "BITRSHIFT", i.BITXOR = "BITXOR", i.COMPLEX = "COMPLEX", i.CONVERT = "CONVERT", i.DEC2BIN = "DEC2BIN", i.DEC2HEX = "DEC2HEX", i.DEC2OCT = "DEC2OCT", i.DELTA = "DELTA", i.ERF = "ERF", i.ERF_PRECISE = "ERF.PRECISE", i.ERFC = "ERFC", i.ERFC_PRECISE = "ERFC.PRECISE", i.GESTEP = "GESTEP", i.HEX2BIN = "HEX2BIN", i.HEX2DEC = "HEX2DEC", i.HEX2OCT = "HEX2OCT", i.IMABS = "IMABS", i.IMAGINARY = "IMAGINARY", i.IMARGUMENT = "IMARGUMENT", i.IMCONJUGATE = "IMCONJUGATE", i.IMCOS = "IMCOS", i.IMCOSH = "IMCOSH", i.IMCOT = "IMCOT", i.IMCOTH = "IMCOTH", i.IMCSC = "IMCSC", i.IMCSCH = "IMCSCH", i.IMDIV = "IMDIV", i.IMEXP = "IMEXP", i.IMLN = "IMLN", i.IMLOG = "IMLOG", i.IMLOG10 = "IMLOG10", i.IMLOG2 = "IMLOG2", i.IMPOWER = "IMPOWER", i.IMPRODUCT = "IMPRODUCT", i.IMREAL = "IMREAL", i.IMSEC = "IMSEC", i.IMSECH = "IMSECH", i.IMSIN = "IMSIN", i.IMSINH = "IMSINH", i.IMSQRT = "IMSQRT", i.IMSUB = "IMSUB", i.IMSUM = "IMSUM", i.IMTAN = "IMTAN", i.IMTANH = "IMTANH", i.OCT2BIN = "OCT2BIN", i.OCT2DEC = "OCT2DEC", i.OCT2HEX = "OCT2HEX", i))(Z || {});
  16173. class Gg extends V {
  16174. constructor() {
  16175. super(...arguments);
  16176. A(this, "minParams", 1);
  16177. A(this, "maxParams", 2);
  16178. }
  16179. calculate(e, t) {
  16180. if (e.isNull())
  16181. return g.create(m.NA);
  16182. const r = t != null ? t : y.create(0), { isError: n, errorObject: s, variants: o } = H(e, r);
  16183. if (n)
  16184. return s;
  16185. const [u, c] = o, l = +u.getValue(), f = +c.getValue();
  16186. if (Number.isNaN(l) || Number.isNaN(f))
  16187. return g.create(m.VALUE);
  16188. const h = l >= f ? 1 : 0;
  16189. return y.create(h);
  16190. }
  16191. }
  16192. class Qg extends V {
  16193. constructor() {
  16194. super(...arguments);
  16195. A(this, "minParams", 1);
  16196. A(this, "maxParams", 2);
  16197. }
  16198. calculate(e, t) {
  16199. if (e.isNull())
  16200. return g.create(m.NA);
  16201. let r = 0;
  16202. if (t) {
  16203. const { isError: d, errorObject: _, variants: C } = H(t);
  16204. if (d)
  16205. return _;
  16206. const [E] = C;
  16207. if (r = Math.floor(+E.getValue()), Number.isNaN(r))
  16208. return g.create(m.VALUE);
  16209. if (r < 0 || r > 10)
  16210. return g.create(m.NUM);
  16211. }
  16212. const { isError: n, errorObject: s, variants: o } = H(e);
  16213. if (n)
  16214. return s;
  16215. const [u] = o, c = `${u.getValue()}`;
  16216. if (!Va(c))
  16217. return g.create(m.NUM);
  16218. const l = c.length === 10 && c.substring(0, 1).toLocaleUpperCase() === "F", f = l ? Number.parseInt(c, 16) - 1099511627776 : Number.parseInt(c, 16);
  16219. if (f < -512 || f > 511)
  16220. return g.create(m.NUM);
  16221. let h;
  16222. if (l) {
  16223. const d = (512 + f).toString(2);
  16224. h = `1${"0".repeat(9 - d.length)}${d}`;
  16225. } else if (h = f.toString(2), t) {
  16226. if (r < h.length)
  16227. return g.create(m.NUM);
  16228. h = "0".repeat(r - h.length) + h;
  16229. }
  16230. return j.create(h);
  16231. }
  16232. }
  16233. class Wg extends V {
  16234. constructor() {
  16235. super(...arguments);
  16236. A(this, "minParams", 1);
  16237. A(this, "maxParams", 1);
  16238. }
  16239. calculate(e) {
  16240. const { isError: t, errorObject: r, variants: n } = H(e);
  16241. if (t)
  16242. return r;
  16243. const [s] = n, o = `${s.getValue()}`;
  16244. if (!Va(o))
  16245. return g.create(m.NUM);
  16246. let u = Number.parseInt(o, 16);
  16247. return u >= 549755813888 && (u -= 1099511627776), y.create(u);
  16248. }
  16249. }
  16250. class qg extends V {
  16251. constructor() {
  16252. super(...arguments);
  16253. A(this, "minParams", 1);
  16254. A(this, "maxParams", 2);
  16255. }
  16256. calculate(e, t) {
  16257. if (e.isNull())
  16258. return g.create(m.NA);
  16259. let r = 0;
  16260. if (t) {
  16261. const { isError: h, errorObject: d, variants: _ } = H(t);
  16262. if (h)
  16263. return d;
  16264. const [C] = _;
  16265. if (r = Math.floor(+C.getValue()), Number.isNaN(r))
  16266. return g.create(m.VALUE);
  16267. if (r < 0 || r > 10)
  16268. return g.create(m.NUM);
  16269. }
  16270. const { isError: n, errorObject: s, variants: o } = H(e);
  16271. if (n)
  16272. return s;
  16273. const [u] = o, c = `${u.getValue()}`;
  16274. if (!Va(c))
  16275. return g.create(m.NUM);
  16276. const l = Number.parseInt(c, 16);
  16277. if (l > 536870911 && l < 1098974756864)
  16278. return g.create(m.NUM);
  16279. let f;
  16280. if (l >= 1098974756864)
  16281. f = (l - 1098437885952).toString(8);
  16282. else if (f = l.toString(8), t) {
  16283. if (r < f.length)
  16284. return g.create(m.NUM);
  16285. f = "0".repeat(r - f.length) + f;
  16286. }
  16287. return j.create(f);
  16288. }
  16289. }
  16290. class Kg extends V {
  16291. constructor() {
  16292. super(...arguments);
  16293. A(this, "minParams", 1);
  16294. A(this, "maxParams", 1);
  16295. }
  16296. calculate(e) {
  16297. const { isError: t, errorObject: r, variants: n } = H(e);
  16298. if (t)
  16299. return r;
  16300. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16301. if (u.isError())
  16302. return g.create(m.NUM);
  16303. const c = u.Abs();
  16304. return y.create(c);
  16305. }
  16306. }
  16307. class Xg extends V {
  16308. constructor() {
  16309. super(...arguments);
  16310. A(this, "minParams", 1);
  16311. A(this, "maxParams", 1);
  16312. }
  16313. calculate(e) {
  16314. const { isError: t, errorObject: r, variants: n } = H(e);
  16315. if (t)
  16316. return r;
  16317. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16318. if (u.isError())
  16319. return g.create(m.NUM);
  16320. const c = u.getINum();
  16321. return y.create(c);
  16322. }
  16323. }
  16324. class Zg extends V {
  16325. constructor() {
  16326. super(...arguments);
  16327. A(this, "minParams", 1);
  16328. A(this, "maxParams", 1);
  16329. }
  16330. calculate(e) {
  16331. const { isError: t, errorObject: r, variants: n } = H(e);
  16332. if (t)
  16333. return r;
  16334. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16335. if (u.isError())
  16336. return g.create(m.NUM);
  16337. if (u.getRealNum() === 0 && u.getINum() === 0)
  16338. return g.create(m.DIV_BY_ZERO);
  16339. const c = u.Argument();
  16340. return y.create(c);
  16341. }
  16342. }
  16343. class zg extends V {
  16344. constructor() {
  16345. super(...arguments);
  16346. A(this, "minParams", 1);
  16347. A(this, "maxParams", 1);
  16348. }
  16349. calculate(e) {
  16350. const { isError: t, errorObject: r, variants: n } = H(e);
  16351. if (t)
  16352. return r;
  16353. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16354. if (u.isError())
  16355. return g.create(m.NUM);
  16356. const c = u.Conjugate();
  16357. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16358. }
  16359. }
  16360. class Jg extends V {
  16361. constructor() {
  16362. super(...arguments);
  16363. A(this, "minParams", 1);
  16364. A(this, "maxParams", 1);
  16365. }
  16366. calculate(e) {
  16367. const { isError: t, errorObject: r, variants: n } = H(e);
  16368. if (t)
  16369. return r;
  16370. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16371. if (u.isError())
  16372. return g.create(m.NUM);
  16373. const c = u.Cos();
  16374. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16375. }
  16376. }
  16377. class e1 extends V {
  16378. constructor() {
  16379. super(...arguments);
  16380. A(this, "minParams", 1);
  16381. A(this, "maxParams", 1);
  16382. }
  16383. calculate(e) {
  16384. const { isError: t, errorObject: r, variants: n } = H(e);
  16385. if (t)
  16386. return r;
  16387. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16388. if (u.isError())
  16389. return g.create(m.NUM);
  16390. const c = u.Cosh();
  16391. return u.isError() ? g.create(m.NUM) : typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16392. }
  16393. }
  16394. class t1 extends V {
  16395. constructor() {
  16396. super(...arguments);
  16397. A(this, "minParams", 1);
  16398. A(this, "maxParams", 1);
  16399. }
  16400. calculate(e) {
  16401. const { isError: t, errorObject: r, variants: n } = H(e);
  16402. if (t)
  16403. return r;
  16404. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16405. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16406. return g.create(m.NUM);
  16407. const c = u.Cot();
  16408. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16409. }
  16410. }
  16411. class r1 extends V {
  16412. constructor() {
  16413. super(...arguments);
  16414. A(this, "minParams", 1);
  16415. A(this, "maxParams", 1);
  16416. }
  16417. calculate(e) {
  16418. const { isError: t, errorObject: r, variants: n } = H(e);
  16419. if (t)
  16420. return r;
  16421. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16422. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16423. return g.create(m.NUM);
  16424. const c = u.Coth();
  16425. return u.isError() ? g.create(m.NUM) : typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16426. }
  16427. }
  16428. class n1 extends V {
  16429. constructor() {
  16430. super(...arguments);
  16431. A(this, "minParams", 1);
  16432. A(this, "maxParams", 1);
  16433. }
  16434. calculate(e) {
  16435. const { isError: t, errorObject: r, variants: n } = H(e);
  16436. if (t)
  16437. return r;
  16438. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16439. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16440. return g.create(m.NUM);
  16441. const c = u.Csc();
  16442. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16443. }
  16444. }
  16445. class s1 extends V {
  16446. constructor() {
  16447. super(...arguments);
  16448. A(this, "minParams", 1);
  16449. A(this, "maxParams", 1);
  16450. }
  16451. calculate(e) {
  16452. const { isError: t, errorObject: r, variants: n } = H(e);
  16453. if (t)
  16454. return r;
  16455. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16456. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16457. return g.create(m.NUM);
  16458. const c = u.Csch();
  16459. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16460. }
  16461. }
  16462. class a1 extends V {
  16463. constructor() {
  16464. super(...arguments);
  16465. A(this, "minParams", 2);
  16466. A(this, "maxParams", 2);
  16467. }
  16468. calculate(e, t) {
  16469. if (e.isNull() || t.isNull())
  16470. return g.create(m.NA);
  16471. const { isError: r, errorObject: n, variants: s } = H(e, t);
  16472. if (r)
  16473. return n;
  16474. const [o, u] = s, c = `${o.getValue()}`, l = `${u.getValue()}`, f = new fe(c), h = new fe(l);
  16475. if (f.isError() || h.isError() || f.isDifferentSuffixes(h) || h.getRealNum() === 0 && h.getINum() === 0)
  16476. return g.create(m.NUM);
  16477. const d = f.Div(h);
  16478. return typeof d == "number" || Q(d) ? y.create(+d) : j.create(d);
  16479. }
  16480. }
  16481. class i1 extends V {
  16482. constructor() {
  16483. super(...arguments);
  16484. A(this, "minParams", 1);
  16485. A(this, "maxParams", 1);
  16486. }
  16487. calculate(e) {
  16488. const { isError: t, errorObject: r, variants: n } = H(e);
  16489. if (t)
  16490. return r;
  16491. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16492. if (u.isError())
  16493. return g.create(m.NUM);
  16494. const c = u.Exp();
  16495. return u.isError() ? g.create(m.NUM) : typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16496. }
  16497. }
  16498. class o1 extends V {
  16499. constructor() {
  16500. super(...arguments);
  16501. A(this, "minParams", 1);
  16502. A(this, "maxParams", 1);
  16503. }
  16504. calculate(e) {
  16505. const { isError: t, errorObject: r, variants: n } = H(e);
  16506. if (t)
  16507. return r;
  16508. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16509. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16510. return g.create(m.NUM);
  16511. const c = u.Ln();
  16512. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16513. }
  16514. }
  16515. class u1 extends V {
  16516. constructor() {
  16517. super(...arguments);
  16518. A(this, "minParams", 1);
  16519. A(this, "maxParams", 2);
  16520. }
  16521. calculate(e, t) {
  16522. const { isError: r, errorObject: n, variants: s } = H(e);
  16523. if (r)
  16524. return n;
  16525. const [o] = s;
  16526. let u = t != null ? t : y.create(10);
  16527. if (u.isArray()) {
  16528. const b = u.getRowCount(), R = u.getColumnCount();
  16529. if (b > 1 || R > 1)
  16530. return g.create(m.VALUE);
  16531. u = u.get(0, 0);
  16532. }
  16533. const { isError: c, errorObject: l, variants: f } = I(u);
  16534. if (c)
  16535. return l;
  16536. const [h] = f, d = `${o.getValue()}`, _ = +h.getValue(), C = new fe(d);
  16537. if (C.isError() || C.getRealNum() === 0 && C.getINum() === 0 || _ <= 0)
  16538. return g.create(m.NUM);
  16539. const E = C.Log(_);
  16540. return C.isError() ? g.create(m.NUM) : typeof E == "number" || Q(E) ? y.create(+E) : j.create(E);
  16541. }
  16542. }
  16543. class c1 extends V {
  16544. constructor() {
  16545. super(...arguments);
  16546. A(this, "minParams", 1);
  16547. A(this, "maxParams", 1);
  16548. }
  16549. calculate(e) {
  16550. const { isError: t, errorObject: r, variants: n } = H(e);
  16551. if (t)
  16552. return r;
  16553. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16554. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16555. return g.create(m.NUM);
  16556. const c = u.Log(2);
  16557. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16558. }
  16559. }
  16560. class l1 extends V {
  16561. constructor() {
  16562. super(...arguments);
  16563. A(this, "minParams", 1);
  16564. A(this, "maxParams", 1);
  16565. }
  16566. calculate(e) {
  16567. const { isError: t, errorObject: r, variants: n } = H(e);
  16568. if (t)
  16569. return r;
  16570. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16571. if (u.isError() || u.getRealNum() === 0 && u.getINum() === 0)
  16572. return g.create(m.NUM);
  16573. const c = u.Log(10);
  16574. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16575. }
  16576. }
  16577. class f1 extends V {
  16578. constructor() {
  16579. super(...arguments);
  16580. A(this, "minParams", 2);
  16581. A(this, "maxParams", 2);
  16582. }
  16583. calculate(e, t) {
  16584. if (e.isNull() || t.isNull())
  16585. return g.create(m.NA);
  16586. const { isError: r, errorObject: n, variants: s } = H(e, t);
  16587. if (r)
  16588. return n;
  16589. const [o, u] = s, c = `${o.getValue()}`, l = new fe(c);
  16590. if (l.isError())
  16591. return g.create(m.NUM);
  16592. const f = +u.getValue();
  16593. if (Number.isNaN(f))
  16594. return g.create(m.VALUE);
  16595. const h = l.Power(f);
  16596. return l.isError() ? g.create(m.NUM) : typeof h == "number" || Q(h) ? y.create(+h) : j.create(h);
  16597. }
  16598. }
  16599. class h1 extends V {
  16600. constructor() {
  16601. super(...arguments);
  16602. A(this, "minParams", 1);
  16603. A(this, "maxParams", 255);
  16604. }
  16605. calculate(...e) {
  16606. let t = "";
  16607. for (let r = 0; r < e.length; r++) {
  16608. if (t instanceof g)
  16609. return t;
  16610. const n = e[r];
  16611. if (n.isArray()) {
  16612. let s = !1, o;
  16613. if (n.iterator((u) => {
  16614. if (t = this._handleSingleObject(u, t), t instanceof g)
  16615. return s = !0, o = t, !1;
  16616. }), s)
  16617. return o;
  16618. } else
  16619. t = this._handleSingleObject(n, t);
  16620. }
  16621. return t instanceof g ? t : typeof t == "number" || Q(t) ? y.create(+t) : j.create(t);
  16622. }
  16623. _handleSingleObject(e, t) {
  16624. let r = t;
  16625. if (e.isError())
  16626. return e;
  16627. if (e.isBoolean())
  16628. return g.create(m.VALUE);
  16629. const n = `${e.getValue()}`;
  16630. if (typeof t != "number" && !t) {
  16631. const s = new fe(n);
  16632. if (s.isError())
  16633. return g.create(m.NUM);
  16634. r = s.toString();
  16635. } else {
  16636. const s = new fe(t), o = new fe(n);
  16637. if (s.isError() || o.isError())
  16638. return g.create(m.NUM);
  16639. if (s.isDifferentSuffixes(o))
  16640. return g.create(m.VALUE);
  16641. r = s.Product(o);
  16642. }
  16643. return r;
  16644. }
  16645. }
  16646. class m1 extends V {
  16647. constructor() {
  16648. super(...arguments);
  16649. A(this, "minParams", 1);
  16650. A(this, "maxParams", 1);
  16651. }
  16652. calculate(e) {
  16653. const { isError: t, errorObject: r, variants: n } = H(e);
  16654. if (t)
  16655. return r;
  16656. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16657. if (u.isError())
  16658. return g.create(m.NUM);
  16659. const c = u.getRealNum();
  16660. return y.create(c);
  16661. }
  16662. }
  16663. class g1 extends V {
  16664. constructor() {
  16665. super(...arguments);
  16666. A(this, "minParams", 1);
  16667. A(this, "maxParams", 1);
  16668. }
  16669. calculate(e) {
  16670. const { isError: t, errorObject: r, variants: n } = H(e);
  16671. if (t)
  16672. return r;
  16673. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16674. if (u.isError())
  16675. return g.create(m.NUM);
  16676. const c = u.Sec();
  16677. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16678. }
  16679. }
  16680. class d1 extends V {
  16681. constructor() {
  16682. super(...arguments);
  16683. A(this, "minParams", 1);
  16684. A(this, "maxParams", 1);
  16685. }
  16686. calculate(e) {
  16687. const { isError: t, errorObject: r, variants: n } = H(e);
  16688. if (t)
  16689. return r;
  16690. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16691. if (u.isError())
  16692. return g.create(m.NUM);
  16693. const c = u.Sech();
  16694. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16695. }
  16696. }
  16697. class C1 extends V {
  16698. constructor() {
  16699. super(...arguments);
  16700. A(this, "minParams", 1);
  16701. A(this, "maxParams", 1);
  16702. }
  16703. calculate(e) {
  16704. const { isError: t, errorObject: r, variants: n } = H(e);
  16705. if (t)
  16706. return r;
  16707. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16708. if (u.isError())
  16709. return g.create(m.NUM);
  16710. const c = u.Sin();
  16711. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16712. }
  16713. }
  16714. class _1 extends V {
  16715. constructor() {
  16716. super(...arguments);
  16717. A(this, "minParams", 1);
  16718. A(this, "maxParams", 1);
  16719. }
  16720. calculate(e) {
  16721. const { isError: t, errorObject: r, variants: n } = H(e);
  16722. if (t)
  16723. return r;
  16724. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16725. if (u.isError())
  16726. return g.create(m.NUM);
  16727. const c = u.Sinh();
  16728. return u.isError() ? g.create(m.NUM) : typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16729. }
  16730. }
  16731. class A1 extends V {
  16732. constructor() {
  16733. super(...arguments);
  16734. A(this, "minParams", 1);
  16735. A(this, "maxParams", 1);
  16736. }
  16737. calculate(e) {
  16738. const { isError: t, errorObject: r, variants: n } = H(e);
  16739. if (t)
  16740. return r;
  16741. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16742. if (u.isError())
  16743. return g.create(m.NUM);
  16744. if (u.getRealNum() === 0 && u.getINum() === 0)
  16745. return y.create(0);
  16746. const c = u.Sqrt();
  16747. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16748. }
  16749. }
  16750. class E1 extends V {
  16751. constructor() {
  16752. super(...arguments);
  16753. A(this, "minParams", 2);
  16754. A(this, "maxParams", 2);
  16755. }
  16756. calculate(e, t) {
  16757. if (e.isNull() || t.isNull())
  16758. return g.create(m.NA);
  16759. const { isError: r, errorObject: n, variants: s } = H(e, t);
  16760. if (r)
  16761. return n;
  16762. const [o, u] = s, c = `${o.getValue()}`, l = `${u.getValue()}`, f = new fe(c), h = new fe(l);
  16763. if (f.isError() || h.isError() || f.isDifferentSuffixes(h))
  16764. return g.create(m.NUM);
  16765. const d = f.Sub(h);
  16766. return typeof d == "number" || Q(d) ? y.create(+d) : j.create(d);
  16767. }
  16768. }
  16769. class b1 extends V {
  16770. constructor() {
  16771. super(...arguments);
  16772. A(this, "minParams", 1);
  16773. A(this, "maxParams", 255);
  16774. }
  16775. calculate(...e) {
  16776. let t = "";
  16777. for (let r = 0; r < e.length; r++) {
  16778. if (t instanceof g)
  16779. return t;
  16780. const n = e[r];
  16781. if (n.isArray()) {
  16782. let s = !1, o;
  16783. if (n.iterator((u) => {
  16784. if (t = this._handleSingleObject(u, t), t instanceof g)
  16785. return s = !0, o = t, !1;
  16786. }), s)
  16787. return o;
  16788. } else
  16789. t = this._handleSingleObject(n, t);
  16790. }
  16791. return t instanceof g ? t : typeof t == "number" || Q(t) ? y.create(+t) : j.create(t);
  16792. }
  16793. _handleSingleObject(e, t) {
  16794. let r = t;
  16795. if (e.isError())
  16796. return e;
  16797. if (e.isBoolean())
  16798. return g.create(m.VALUE);
  16799. const n = `${e.getValue()}`;
  16800. if (typeof t != "number" && !t) {
  16801. const s = new fe(n);
  16802. if (s.isError())
  16803. return g.create(m.NUM);
  16804. r = s.toString();
  16805. } else {
  16806. const s = new fe(t), o = new fe(n);
  16807. if (s.isError() || o.isError())
  16808. return g.create(m.NUM);
  16809. if (s.isDifferentSuffixes(o))
  16810. return g.create(m.VALUE);
  16811. r = s.Sum(o);
  16812. }
  16813. return r;
  16814. }
  16815. }
  16816. class y1 extends V {
  16817. constructor() {
  16818. super(...arguments);
  16819. A(this, "minParams", 1);
  16820. A(this, "maxParams", 1);
  16821. }
  16822. calculate(e) {
  16823. const { isError: t, errorObject: r, variants: n } = H(e);
  16824. if (t)
  16825. return r;
  16826. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16827. if (u.isError())
  16828. return g.create(m.NUM);
  16829. const c = u.Tan();
  16830. return typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16831. }
  16832. }
  16833. class R1 extends V {
  16834. constructor() {
  16835. super(...arguments);
  16836. A(this, "minParams", 1);
  16837. A(this, "maxParams", 1);
  16838. }
  16839. calculate(e) {
  16840. const { isError: t, errorObject: r, variants: n } = H(e);
  16841. if (t)
  16842. return r;
  16843. const [s] = n, o = `${s.getValue()}`, u = new fe(o);
  16844. if (u.isError())
  16845. return g.create(m.NUM);
  16846. const c = u.Tanh();
  16847. return u.isError() ? g.create(m.NUM) : typeof c == "number" || Q(c) ? y.create(+c) : j.create(c);
  16848. }
  16849. }
  16850. class p1 extends V {
  16851. constructor() {
  16852. super(...arguments);
  16853. A(this, "minParams", 1);
  16854. A(this, "maxParams", 2);
  16855. }
  16856. calculate(e, t) {
  16857. if (e.isNull())
  16858. return g.create(m.NA);
  16859. let r = 0;
  16860. if (t) {
  16861. const { isError: d, errorObject: _, variants: C } = H(t);
  16862. if (d)
  16863. return _;
  16864. const [E] = C;
  16865. if (r = Math.floor(+E.getValue()), Number.isNaN(r))
  16866. return g.create(m.VALUE);
  16867. if (r < 0 || r > 10)
  16868. return g.create(m.NUM);
  16869. }
  16870. const { isError: n, errorObject: s, variants: o } = H(e);
  16871. if (n)
  16872. return s;
  16873. const [u] = o, c = `${u.getValue()}`;
  16874. if (!pa(c))
  16875. return g.create(m.NUM);
  16876. const l = c.length === 10 && c.substring(0, 1) === "7", f = l ? Number.parseInt(c, 8) - 1073741824 : Number.parseInt(c, 8);
  16877. if (f < -512 || f > 511)
  16878. return g.create(m.NUM);
  16879. let h;
  16880. if (l) {
  16881. const d = (512 + f).toString(2);
  16882. h = `1${"0".repeat(9 - d.length)}${d}`;
  16883. } else if (h = f.toString(2), t) {
  16884. if (r < h.length)
  16885. return g.create(m.NUM);
  16886. h = "0".repeat(r - h.length) + h;
  16887. }
  16888. return j.create(h);
  16889. }
  16890. }
  16891. class V1 extends V {
  16892. constructor() {
  16893. super(...arguments);
  16894. A(this, "minParams", 1);
  16895. A(this, "maxParams", 1);
  16896. }
  16897. calculate(e) {
  16898. const { isError: t, errorObject: r, variants: n } = H(e);
  16899. if (t)
  16900. return r;
  16901. const [s] = n, o = `${s.getValue()}`;
  16902. if (!pa(o))
  16903. return g.create(m.NUM);
  16904. let u = Number.parseInt(o, 8);
  16905. return u >= 536870912 && (u -= 1073741824), y.create(u);
  16906. }
  16907. }
  16908. class N1 extends V {
  16909. constructor() {
  16910. super(...arguments);
  16911. A(this, "minParams", 1);
  16912. A(this, "maxParams", 2);
  16913. }
  16914. calculate(e, t) {
  16915. if (e.isNull())
  16916. return g.create(m.NA);
  16917. let r = 0;
  16918. if (t) {
  16919. const { isError: h, errorObject: d, variants: _ } = H(t);
  16920. if (h)
  16921. return d;
  16922. const [C] = _;
  16923. if (r = Math.floor(+C.getValue()), Number.isNaN(r))
  16924. return g.create(m.VALUE);
  16925. if (r < 0 || r > 10)
  16926. return g.create(m.NUM);
  16927. }
  16928. const { isError: n, errorObject: s, variants: o } = H(e);
  16929. if (n)
  16930. return s;
  16931. const [u] = o, c = `${u.getValue()}`;
  16932. if (!pa(c))
  16933. return g.create(m.NUM);
  16934. const l = Number.parseInt(c, 8);
  16935. let f;
  16936. if (l >= 536870912)
  16937. f = `ff${(l + 3221225472).toString(16)}`;
  16938. else if (f = l.toString(16), t) {
  16939. if (r < f.length)
  16940. return g.create(m.NUM);
  16941. f = "0".repeat(r - f.length) + f;
  16942. }
  16943. return j.create(f.toLocaleUpperCase());
  16944. }
  16945. }
  16946. const O1 = [
  16947. [pg, Z.BESSELI],
  16948. [Vg, Z.BESSELJ],
  16949. [Ng, Z.BESSELK],
  16950. [Og, Z.BESSELY],
  16951. [Mg, Z.BIN2DEC],
  16952. [wg, Z.BIN2HEX],
  16953. [Dg, Z.BIN2OCT],
  16954. [Sg, Z.BITAND],
  16955. [Pg, Z.BITLSHIFT],
  16956. [Lg, Z.BITOR],
  16957. [xg, Z.BITRSHIFT],
  16958. [jg, Z.BITXOR],
  16959. [Ug, Z.COMPLEX],
  16960. [vg, Z.CONVERT],
  16961. [Tg, Z.DEC2BIN],
  16962. [Bg, Z.DEC2HEX],
  16963. [Ig, Z.DEC2OCT],
  16964. [Fg, Z.DELTA],
  16965. [kg, Z.ERF],
  16966. [$g, Z.ERF_PRECISE],
  16967. [Yg, Z.ERFC],
  16968. [Hg, Z.ERFC_PRECISE],
  16969. [Gg, Z.GESTEP],
  16970. [Qg, Z.HEX2BIN],
  16971. [Wg, Z.HEX2DEC],
  16972. [qg, Z.HEX2OCT],
  16973. [Kg, Z.IMABS],
  16974. [Xg, Z.IMAGINARY],
  16975. [Zg, Z.IMARGUMENT],
  16976. [zg, Z.IMCONJUGATE],
  16977. [Jg, Z.IMCOS],
  16978. [e1, Z.IMCOSH],
  16979. [t1, Z.IMCOT],
  16980. [r1, Z.IMCOTH],
  16981. [n1, Z.IMCSC],
  16982. [s1, Z.IMCSCH],
  16983. [a1, Z.IMDIV],
  16984. [i1, Z.IMEXP],
  16985. [o1, Z.IMLN],
  16986. [u1, Z.IMLOG],
  16987. [l1, Z.IMLOG10],
  16988. [c1, Z.IMLOG2],
  16989. [f1, Z.IMPOWER],
  16990. [h1, Z.IMPRODUCT],
  16991. [m1, Z.IMREAL],
  16992. [g1, Z.IMSEC],
  16993. [d1, Z.IMSECH],
  16994. [C1, Z.IMSIN],
  16995. [_1, Z.IMSINH],
  16996. [A1, Z.IMSQRT],
  16997. [E1, Z.IMSUB],
  16998. [b1, Z.IMSUM],
  16999. [y1, Z.IMTAN],
  17000. [R1, Z.IMTANH],
  17001. [p1, Z.OCT2BIN],
  17002. [V1, Z.OCT2DEC],
  17003. [N1, Z.OCT2HEX]
  17004. ];
  17005. var ee = /* @__PURE__ */ ((i) => (i.ACCRINT = "ACCRINT", i.ACCRINTM = "ACCRINTM", i.AMORDEGRC = "AMORDEGRC", i.AMORLINC = "AMORLINC", i.COUPDAYBS = "COUPDAYBS", i.COUPDAYS = "COUPDAYS", i.COUPDAYSNC = "COUPDAYSNC", i.COUPNCD = "COUPNCD", i.COUPNUM = "COUPNUM", i.COUPPCD = "COUPPCD", i.CUMIPMT = "CUMIPMT", i.CUMPRINC = "CUMPRINC", i.DB = "DB", i.DDB = "DDB", i.DISC = "DISC", i.DOLLARDE = "DOLLARDE", i.DOLLARFR = "DOLLARFR", i.DURATION = "DURATION", i.EFFECT = "EFFECT", i.FV = "FV", i.FVSCHEDULE = "FVSCHEDULE", i.INTRATE = "INTRATE", i.IPMT = "IPMT", i.IRR = "IRR", i.ISPMT = "ISPMT", i.MDURATION = "MDURATION", i.MIRR = "MIRR", i.NOMINAL = "NOMINAL", i.NPER = "NPER", i.NPV = "NPV", i.ODDFPRICE = "ODDFPRICE", i.ODDFYIELD = "ODDFYIELD", i.ODDLPRICE = "ODDLPRICE", i.ODDLYIELD = "ODDLYIELD", i.PDURATION = "PDURATION", i.PMT = "PMT", i.PPMT = "PPMT", i.PRICE = "PRICE", i.PRICEDISC = "PRICEDISC", i.PRICEMAT = "PRICEMAT", i.PV = "PV", i.RATE = "RATE", i.RECEIVED = "RECEIVED", i.RRI = "RRI", i.SLN = "SLN", i.SYD = "SYD", i.TBILLEQ = "TBILLEQ", i.TBILLPRICE = "TBILLPRICE", i.TBILLYIELD = "TBILLYIELD", i.VDB = "VDB", i.XIRR = "XIRR", i.XNPV = "XNPV", i.YIELD = "YIELD", i.YIELDDISC = "YIELDDISC", i.YIELDMAT = "YIELDMAT", i))(ee || {});
  17006. function es(i, a, e, t) {
  17007. const r = It(i, a, e), { days: n } = _e(r, i, t);
  17008. return n;
  17009. }
  17010. function qe(i, a, e, t) {
  17011. let r;
  17012. if (t === 1) {
  17013. const n = It(i, a, e);
  17014. let s = re(n);
  17015. s = Er(s, 12 / e);
  17016. const o = ye(s);
  17017. n < 0 && e === 1 ? r = 365 : r = o - n;
  17018. } else t === 3 ? r = 365 / e : r = 360 / e;
  17019. return r;
  17020. }
  17021. function Eu(i, a, e) {
  17022. const t = re(i);
  17023. let r = re(a);
  17024. for (r.setUTCFullYear(t.getUTCFullYear()), r < t && r.setUTCFullYear(r.getUTCFullYear() + 1); r > t; )
  17025. r = Er(r, -12 / e);
  17026. return r = Er(r, 12 / e), ye(r);
  17027. }
  17028. function nr(i, a, e) {
  17029. let t = 0;
  17030. const r = re(i);
  17031. let n = re(a);
  17032. for (; n > r; )
  17033. n = Er(n, -12 / e), t++;
  17034. return t;
  17035. }
  17036. function It(i, a, e) {
  17037. const t = re(i);
  17038. let r = re(a);
  17039. for (r.setUTCFullYear(t.getUTCFullYear()), r < t && r.setUTCFullYear(r.getUTCFullYear() + 1); r > t; )
  17040. r = Er(r, -12 / e);
  17041. return ye(r);
  17042. }
  17043. function bu(i, a, e, t, r, n) {
  17044. const s = es(i, a, r, n), o = qe(i, a, r, n), u = nr(i, a, r), c = (o - s) / o - 1, l = t / r + 1, f = e * 100 / r;
  17045. let h = 0, d = 0;
  17046. for (let E = 1; E <= u; E++) {
  17047. const b = E + c, R = f / l ** b;
  17048. h += b * R, d += R;
  17049. }
  17050. const _ = u + c, C = 100 / l ** _;
  17051. return h += _ * C, d += C, h / d / r;
  17052. }
  17053. function Gr(i, a, e, t, r) {
  17054. let n;
  17055. if (i === 0)
  17056. n = (e + t) / a;
  17057. else {
  17058. const s = (1 + i) ** a;
  17059. n = r === 1 ? (t * i / (s - 1) + e * i / (1 - 1 / s)) / (1 + i) : t * i / (s - 1) + e * i / (1 - 1 / s);
  17060. }
  17061. return -n;
  17062. }
  17063. function sr(i, a, e, t, r) {
  17064. let n;
  17065. if (i === 0)
  17066. n = t + e * a;
  17067. else {
  17068. if (i === -1 && a === 0)
  17069. return Number.NaN;
  17070. const s = (1 + i) ** a;
  17071. n = r === 1 ? t * s + e * (1 + i) * (s - 1) / i : t * s + e * (s - 1) / i;
  17072. }
  17073. return -n;
  17074. }
  17075. function yu(i, a, e, t, r, n) {
  17076. const s = Gr(i, e, t, r, n);
  17077. return (a === 1 ? n === 1 ? 0 : -t : n === 1 ? sr(i, a - 2, s, t, 1) - s : sr(i, a - 1, s, t, 0)) * i;
  17078. }
  17079. function Ru(i, a) {
  17080. let e = 0;
  17081. for (let t = 1; t <= a.length; t++)
  17082. e += a[t - 1] / (1 + i) ** t;
  17083. return e;
  17084. }
  17085. function pu(i, a, e, t, r, n, s, o, u) {
  17086. const c = Kt(e, t, u), l = qe(i, t, o, u);
  17087. return c < l ? M1(
  17088. i,
  17089. a,
  17090. e,
  17091. t,
  17092. r,
  17093. n,
  17094. s,
  17095. o,
  17096. u,
  17097. c,
  17098. l
  17099. ) : w1(
  17100. i,
  17101. a,
  17102. e,
  17103. t,
  17104. r,
  17105. n,
  17106. s,
  17107. o,
  17108. u,
  17109. l
  17110. );
  17111. }
  17112. function M1(i, a, e, t, r, n, s, o, u, c, l) {
  17113. let f = 0;
  17114. const h = nr(i, a, o), d = Kt(i, t, u);
  17115. f += s / (1 + n / o) ** (h - 1 + d / l), f += 100 * r / o * c / l / (1 + n / o) ** (d / l);
  17116. for (let C = 2; C <= h; C++)
  17117. f += 100 * r / o / (1 + n / o) ** (C - 1 + d / l);
  17118. const _ = Kt(e, i, u);
  17119. return f -= 100 * r / o * _ / l, f;
  17120. }
  17121. function w1(i, a, e, t, r, n, s, o, u, c) {
  17122. let l = 0;
  17123. const f = nr(t, a, o), h = D1(t, i, 12 / o);
  17124. let d;
  17125. if (u === 2 || u === 3) {
  17126. const R = Eu(i, t, o);
  17127. d = Kt(i, R, u);
  17128. } else {
  17129. const R = It(i, t, o), { days: p } = _e(R, i, u);
  17130. d = c - p;
  17131. }
  17132. l += s / (1 + n / o) ** (f + h + d / c);
  17133. const _ = nr(e, t, o);
  17134. let C = t, E = 0, b = 0;
  17135. for (let R = _; R >= 1; R--) {
  17136. const p = Jt(C, -12 / o, !1), N = u === 1 ? Kt(p, C, u) : c, M = R > 1 ? N : Kt(e, C, u);
  17137. E += M / N;
  17138. const w = e > p ? e : p, D = i < C ? i : C, S = Kt(w, D, u);
  17139. b += S / N, C = p;
  17140. }
  17141. l += 100 * r / o * E / (1 + n / o) ** (h + d / c);
  17142. for (let R = 1; R <= f; R++)
  17143. l += 100 * r / o / (1 + n / o) ** (R + h + d / c);
  17144. return l -= 100 * r / o * b, l;
  17145. }
  17146. function Kt(i, a, e) {
  17147. const { days: t } = _e(i, a, e);
  17148. return i < a ? t : 0;
  17149. }
  17150. function Vu(i, a, e) {
  17151. const t = re(i), r = t.getUTCFullYear(), n = t.getUTCMonth(), s = t.getUTCDate(), o = Ar(r, n, s), u = re(a), c = u.getUTCFullYear(), l = u.getUTCMonth(), f = u.getUTCDate(), h = Ar(c, l, f);
  17152. return !(s !== f && !(o && h) || Math.abs((c - r) * 12 + (l - n)) % (12 / e) !== 0);
  17153. }
  17154. function Or(i, a, e) {
  17155. return It(i, a, e) >= 0;
  17156. }
  17157. function Jt(i, a, e) {
  17158. let t = re(i);
  17159. if (t = Er(t, a), e) {
  17160. const r = t.getUTCFullYear(), n = t.getUTCMonth(), s = Hr(r, n);
  17161. t.setUTCDate(s);
  17162. }
  17163. return ye(t);
  17164. }
  17165. function D1(i, a, e, t) {
  17166. const r = re(i), n = re(a), s = r.getUTCFullYear(), o = r.getUTCMonth(), u = r.getUTCDate(), c = n.getUTCFullYear(), l = n.getUTCMonth(), f = n.getUTCDate(), h = Ar(s, o, u), d = !h && o !== 1 && u > 28 && u < Hr(s, o) ? Ar(c, l, f) : h, _ = Jt(a, 0, d);
  17167. let C = 1 + +(a < _), E = Jt(_, e, d);
  17168. for (; !(e > 0 ? E >= a : E <= a); )
  17169. E = Jt(E, e, d), C++;
  17170. return C;
  17171. }
  17172. function Ia(i, a) {
  17173. let n = 1, s = 0, o = i, u;
  17174. for (; n > 1e-7 && s < 500; ) {
  17175. const c = (a(o + 1e-7) - a(o - 1e-7)) / 2e-7;
  17176. u = o - a(o) / c, s++, n = Math.abs(u - o), o = u;
  17177. }
  17178. return Number.isNaN(o) || Math.abs(o) === 1 / 0 || s === 500 ? S1(i, a) : o;
  17179. }
  17180. function S1(i, a) {
  17181. const r = Number.MAX_VALUE, n = -1, s = 1.6;
  17182. let o = i - 0.01 <= n ? n + 1e-7 : i - 0.01, u = i + 0.01 >= r ? r - 1e-7 : i + 0.01, c, l, f = 0;
  17183. if (i <= n || i >= r)
  17184. return g.create(m.NUM);
  17185. for (let E = 0; E < 60; E++) {
  17186. c = o <= n ? n + 1e-7 : o, l = u >= r ? r - 1e-7 : u;
  17187. const b = a(c), R = a(l);
  17188. if (b * R <= 0)
  17189. break;
  17190. if (b * R > 0)
  17191. o = c + s * (c - l), u = l + s * (l - c);
  17192. else
  17193. return g.create(m.NUM);
  17194. if (E === 59)
  17195. return g.create(m.NUM);
  17196. }
  17197. c = c, l = l;
  17198. let h = a(c);
  17199. const d = a(l);
  17200. let _, C;
  17201. if (Math.abs(h) < 1e-7 || Math.abs(d) < 1e-7)
  17202. return g.create(m.NUM);
  17203. do
  17204. C = c + (l - c) / 2, _ = a(C), h * _ < 0 ? l = C : c = C, h = a(c), f++;
  17205. while (Math.abs(_) > 1e-7 && f < 60);
  17206. return C;
  17207. }
  17208. function un(i, a, e, t, r, n, s) {
  17209. const o = nr(i, a, n), u = qe(i, a, n, s), c = es(i, a, n, s);
  17210. if (o === 1) {
  17211. const h = u - c, d = 100 * e / n + r, _ = t / n * h / u + 1, C = 100 * e / n * c / u;
  17212. return d / _ - C;
  17213. }
  17214. const l = u - c;
  17215. let f = r / (1 + t / n) ** (o - 1 + l / u);
  17216. for (let h = 1; h <= o; h++)
  17217. f += 100 * e / n / (1 + t / n) ** (h - 1 + l / u);
  17218. return f -= 100 * e / n * c / u, f;
  17219. }
  17220. function zs(i, a, e, t, r) {
  17221. let n = 0, s = r / e;
  17222. s >= 1 ? (s = 1, n = t === 1 ? i : 0) : n = i * (1 - s) ** (t - 1);
  17223. const o = i * (1 - s) ** t;
  17224. let u = 0;
  17225. return o < a ? u = n - a : u = n - o, u < 0 && (u = 0), u;
  17226. }
  17227. class P1 extends V {
  17228. constructor() {
  17229. super(...arguments);
  17230. A(this, "minParams", 6);
  17231. A(this, "maxParams", 8);
  17232. }
  17233. calculate(e, t, r, n, s, o, u, c) {
  17234. const l = u != null ? u : y.create(0), f = c != null ? c : T.create(!0), { isError: h, errorObject: d, variants: _ } = H(e, t, r, n, s, o, l);
  17235. if (h)
  17236. return d;
  17237. const [C, E, b, R, p, N, M] = _, w = k(C);
  17238. if (typeof w != "number")
  17239. return w;
  17240. const D = k(E);
  17241. if (typeof D != "number")
  17242. return D;
  17243. const S = k(b);
  17244. if (typeof S != "number")
  17245. return S;
  17246. const P = +R.getValue(), U = +p.getValue(), x = Math.floor(+N.getValue()), F = Math.floor(+M.getValue()), W = +f.getValue();
  17247. return Number.isNaN(P) || Number.isNaN(U) || Number.isNaN(x) || Number.isNaN(F) || Number.isNaN(W) ? g.create(m.VALUE) : P <= 0 || U <= 0 || ![1, 2, 4].includes(x) || F < 0 || F > 4 || Math.floor(w) >= Math.floor(S) ? g.create(m.NUM) : this._getResult(w, D, S, P, U, x, F, W);
  17248. }
  17249. _getResult(e, t, r, n, s, o, u, c) {
  17250. let l = It(e, t, o);
  17251. if (l <= 0)
  17252. return y.create(0);
  17253. l = It(r, t, o);
  17254. const f = 12 / o, h = re(t), d = h.getUTCFullYear(), _ = h.getUTCMonth(), C = h.getUTCDate(), E = Ar(d, _, C);
  17255. let b = Jt(t, -f, E);
  17256. if (r > t && c)
  17257. for (b = t; b < r; )
  17258. b = Jt(b, f, E);
  17259. let R = e > b ? e : b, { days: p } = _e(R, r, u);
  17260. if (l >= e) {
  17261. const { days: P } = _e(R, r, u ? 4 : 0);
  17262. p = P;
  17263. }
  17264. r < R && (p = -p);
  17265. let N = qe(b, t, o, u), M = p / N, w = b, D = e;
  17266. for (; w > e; ) {
  17267. D = w, w = Jt(w, -f, E), R = e > w ? e : w;
  17268. const { days: P } = _e(R, D, u);
  17269. if (u === 0)
  17270. D >= R || e <= w ? p = P : p = -P, N = qe(w, D, o, u);
  17271. else if (p = D < R ? -P : P, u === 3)
  17272. N = 365 / o;
  17273. else {
  17274. const { days: U } = _e(w, D, u);
  17275. N = D < w ? -U : U;
  17276. }
  17277. M += e <= w ? c ? 1 : 0 : p / N;
  17278. }
  17279. const S = s * n / o * M;
  17280. return y.create(S);
  17281. }
  17282. }
  17283. class L1 extends V {
  17284. constructor() {
  17285. super(...arguments);
  17286. A(this, "minParams", 4);
  17287. A(this, "maxParams", 5);
  17288. }
  17289. calculate(e, t, r, n, s) {
  17290. const o = s != null ? s : y.create(0), { isError: u, errorObject: c, variants: l } = H(e, t, r, n, o);
  17291. if (u)
  17292. return c;
  17293. const [f, h, d, _, C] = l, E = k(f);
  17294. if (typeof E != "number")
  17295. return E;
  17296. const b = k(h);
  17297. if (typeof b != "number")
  17298. return b;
  17299. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  17300. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  17301. return g.create(m.VALUE);
  17302. if (R <= 0 || p <= 0 || N < 0 || N > 4 || Math.floor(E) > Math.floor(b))
  17303. return g.create(m.NUM);
  17304. if (Math.floor(E) === Math.floor(b))
  17305. return y.create(0);
  17306. const { days: M, yearDays: w } = _e(E, b, N), D = p * R * M / w;
  17307. return y.create(D);
  17308. }
  17309. }
  17310. class x1 extends V {
  17311. constructor() {
  17312. super(...arguments);
  17313. A(this, "minParams", 6);
  17314. A(this, "maxParams", 7);
  17315. }
  17316. calculate(e, t, r, n, s, o, u) {
  17317. const c = u != null ? u : y.create(0), { isError: l, errorObject: f, variants: h } = H(e, t, r, n, s, o, c);
  17318. if (l)
  17319. return f;
  17320. const [d, _, C, E, b, R, p] = h, N = k(_);
  17321. if (typeof N != "number")
  17322. return N;
  17323. const M = k(C);
  17324. if (typeof M != "number")
  17325. return M;
  17326. const w = +d.getValue(), D = +E.getValue();
  17327. let S = +b.getValue();
  17328. const P = +R.getValue(), U = Math.floor(+p.getValue());
  17329. return Number.isNaN(w) || Number.isNaN(D) || Number.isNaN(S) || Number.isNaN(P) || Number.isNaN(U) ? g.create(m.VALUE) : w <= 0 || D < 0 || w < D || Math.floor(N) > Math.floor(M) || S < 0 || P <= 0 || ![0, 1, 3, 4].includes(U) ? g.create(m.NUM) : (S > 1 ? S = Math.floor(S) : S = Math.ceil(S), this._getResult(w, N, M, D, S, P, U));
  17330. }
  17331. _getResult(e, t, r, n, s, o, u) {
  17332. const c = e - n, l = e * o, { days: f, yearDays: h } = _e(t, r, u), d = f / h, _ = Math.ceil(c / l - d);
  17333. if (_ < 0)
  17334. return y.create(0);
  17335. let C = l;
  17336. return s === 0 ? C = l * d : s === _ ? C = c - l * (d + s - 1) : s > _ && (C = 0), y.create(C);
  17337. }
  17338. }
  17339. class j1 extends V {
  17340. constructor() {
  17341. super(...arguments);
  17342. A(this, "minParams", 3);
  17343. A(this, "maxParams", 4);
  17344. }
  17345. calculate(e, t, r, n) {
  17346. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17347. if (o)
  17348. return u;
  17349. const [l, f, h, d] = c, _ = k(l);
  17350. if (typeof _ != "number")
  17351. return _;
  17352. const C = k(f);
  17353. if (typeof C != "number")
  17354. return C;
  17355. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17356. if (Number.isNaN(E) || Number.isNaN(b))
  17357. return g.create(m.VALUE);
  17358. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C))
  17359. return g.create(m.NUM);
  17360. const R = es(_, C, E, b);
  17361. return y.create(R);
  17362. }
  17363. }
  17364. class U1 extends V {
  17365. constructor() {
  17366. super(...arguments);
  17367. A(this, "minParams", 3);
  17368. A(this, "maxParams", 4);
  17369. }
  17370. calculate(e, t, r, n) {
  17371. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17372. if (o)
  17373. return u;
  17374. const [l, f, h, d] = c, _ = k(l);
  17375. if (typeof _ != "number")
  17376. return _;
  17377. const C = k(f);
  17378. if (typeof C != "number")
  17379. return C;
  17380. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17381. if (Number.isNaN(E) || Number.isNaN(b))
  17382. return g.create(m.VALUE);
  17383. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C))
  17384. return g.create(m.NUM);
  17385. const R = qe(_, C, E, b);
  17386. return y.create(R);
  17387. }
  17388. }
  17389. class v1 extends V {
  17390. constructor() {
  17391. super(...arguments);
  17392. A(this, "minParams", 3);
  17393. A(this, "maxParams", 4);
  17394. }
  17395. calculate(e, t, r, n) {
  17396. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17397. if (o)
  17398. return u;
  17399. const [l, f, h, d] = c, _ = k(l);
  17400. if (typeof _ != "number")
  17401. return _;
  17402. const C = k(f);
  17403. if (typeof C != "number")
  17404. return C;
  17405. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17406. if (Number.isNaN(E) || Number.isNaN(b))
  17407. return g.create(m.VALUE);
  17408. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C))
  17409. return g.create(m.NUM);
  17410. const R = re(_), p = re(C);
  17411. for (p.setUTCFullYear(R.getUTCFullYear()), p < R && p.setUTCFullYear(p.getUTCFullYear() + 1); p > R; )
  17412. p.setUTCMonth(p.getUTCMonth() - 12 / E);
  17413. p.setUTCMonth(p.getUTCMonth() + 12 / E);
  17414. const N = ye(p), { days: M } = _e(_, N, b);
  17415. return y.create(M);
  17416. }
  17417. }
  17418. class T1 extends V {
  17419. constructor() {
  17420. super(...arguments);
  17421. A(this, "minParams", 3);
  17422. A(this, "maxParams", 4);
  17423. }
  17424. calculate(e, t, r, n) {
  17425. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17426. if (o)
  17427. return u;
  17428. const [l, f, h, d] = c, _ = k(l);
  17429. if (typeof _ != "number")
  17430. return _;
  17431. const C = k(f);
  17432. if (typeof C != "number")
  17433. return C;
  17434. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17435. if (Number.isNaN(E) || Number.isNaN(b))
  17436. return g.create(m.VALUE);
  17437. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C))
  17438. return g.create(m.NUM);
  17439. const R = Eu(_, C, E);
  17440. return y.create(R);
  17441. }
  17442. }
  17443. class B1 extends V {
  17444. constructor() {
  17445. super(...arguments);
  17446. A(this, "minParams", 3);
  17447. A(this, "maxParams", 4);
  17448. }
  17449. calculate(e, t, r, n) {
  17450. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17451. if (o)
  17452. return u;
  17453. const [l, f, h, d] = c, _ = k(l);
  17454. if (typeof _ != "number")
  17455. return _;
  17456. const C = k(f);
  17457. if (typeof C != "number")
  17458. return C;
  17459. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17460. if (Number.isNaN(E) || Number.isNaN(b))
  17461. return g.create(m.VALUE);
  17462. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C) || It(_, C, E) < 0)
  17463. return g.create(m.NUM);
  17464. const p = nr(_, C, E);
  17465. return y.create(p);
  17466. }
  17467. }
  17468. class I1 extends V {
  17469. constructor() {
  17470. super(...arguments);
  17471. A(this, "minParams", 3);
  17472. A(this, "maxParams", 4);
  17473. }
  17474. calculate(e, t, r, n) {
  17475. const s = n != null ? n : y.create(0), { isError: o, errorObject: u, variants: c } = H(e, t, r, s);
  17476. if (o)
  17477. return u;
  17478. const [l, f, h, d] = c, _ = k(l);
  17479. if (typeof _ != "number")
  17480. return _;
  17481. const C = k(f);
  17482. if (typeof C != "number")
  17483. return C;
  17484. const E = Math.floor(+h.getValue()), b = Math.floor(+d.getValue());
  17485. if (Number.isNaN(E) || Number.isNaN(b))
  17486. return g.create(m.VALUE);
  17487. if (![1, 2, 4].includes(E) || b < 0 || b > 4 || Math.floor(_) >= Math.floor(C))
  17488. return g.create(m.NUM);
  17489. let R = It(_, C, E);
  17490. return R < 0 && (R = 0), y.create(R);
  17491. }
  17492. }
  17493. class F1 extends V {
  17494. constructor() {
  17495. super(...arguments);
  17496. A(this, "minParams", 6);
  17497. A(this, "maxParams", 6);
  17498. }
  17499. calculate(e, t, r, n, s, o) {
  17500. const { isError: u, errorObject: c, variants: l } = H(e, t, r, n, s, o);
  17501. if (u)
  17502. return c;
  17503. const [f, h, d, _, C, E] = l, b = +f.getValue(), R = +h.getValue(), p = +d.getValue(), N = +_.getValue(), M = +C.getValue(), w = +E.getValue();
  17504. return Number.isNaN(b) || Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N) || Number.isNaN(M) || Number.isNaN(w) ? g.create(m.VALUE) : b <= 0 || R <= 0 || p <= 0 || N < 1 || M < 1 || N > M || N > R || M > R || ![0, 1].includes(w) ? g.create(m.NUM) : Math.trunc(N) !== N && Math.trunc(M) !== M && Math.trunc(N) === Math.trunc(M) ? y.create(0) : this._getResult(b, R, p, N, M, w);
  17505. }
  17506. _getResult(e, t, r, n, s, o) {
  17507. const u = Gr(e, t, r, 0, o);
  17508. let c = 0, l = Math.ceil(n);
  17509. l === 1 && (o === 0 && (c = -r), l++);
  17510. let f = !1;
  17511. for (let h = l; h <= s; h++) {
  17512. const d = o === 1 ? sr(e, h - 2, u, r, 1) : sr(e, h - 1, u, r, 0);
  17513. if (d === 0) {
  17514. f = !0;
  17515. break;
  17516. }
  17517. c += o === 1 ? d - u : d;
  17518. }
  17519. return c *= e, (c < u * (s - n + 1) || f) && (c = u * (s - n + 1)), y.create(c);
  17520. }
  17521. }
  17522. class k1 extends V {
  17523. constructor() {
  17524. super(...arguments);
  17525. A(this, "minParams", 6);
  17526. A(this, "maxParams", 6);
  17527. }
  17528. calculate(e, t, r, n, s, o) {
  17529. const { isError: u, errorObject: c, variants: l } = H(e, t, r, n, s, o);
  17530. if (u)
  17531. return c;
  17532. const [f, h, d, _, C, E] = l, b = +f.getValue(), R = +h.getValue(), p = +d.getValue(), N = +_.getValue(), M = +C.getValue(), w = +E.getValue();
  17533. return Number.isNaN(b) || Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N) || Number.isNaN(M) || Number.isNaN(w) ? g.create(m.VALUE) : b <= 0 || R <= 0 || p <= 0 || N < 1 || M < 1 || N > M || ![0, 1].includes(w) ? g.create(m.NUM) : Math.trunc(N) !== N && Math.trunc(M) !== M && Math.trunc(N) === Math.trunc(M) ? y.create(0) : this._getResult(b, R, p, N, M, w);
  17534. }
  17535. _getResult(e, t, r, n, s, o) {
  17536. const u = Gr(e, t, r, 0, o);
  17537. let c = 0, l = Math.ceil(n);
  17538. l === 1 && (c = o === 0 ? u + r * e : u, l++);
  17539. for (let f = l; f <= s; f++)
  17540. c += o === 1 ? u - (sr(e, f - 2, u, r, 1) - u) * e : u - sr(e, f - 1, u, r, 0) * e;
  17541. return y.create(c);
  17542. }
  17543. }
  17544. class $1 extends V {
  17545. constructor() {
  17546. super(...arguments);
  17547. A(this, "minParams", 4);
  17548. A(this, "maxParams", 5);
  17549. A(this, "needsLocale", !0);
  17550. }
  17551. calculate(e, t, r, n, s) {
  17552. let o = s != null ? s : y.create(12);
  17553. o.isNull() && (o = y.create(12));
  17554. const u = Math.max(
  17555. e.isArray() ? e.getRowCount() : 1,
  17556. t.isArray() ? t.getRowCount() : 1,
  17557. r.isArray() ? r.getRowCount() : 1,
  17558. n.isArray() ? n.getRowCount() : 1,
  17559. o.isArray() ? o.getRowCount() : 1
  17560. ), c = Math.max(
  17561. e.isArray() ? e.getColumnCount() : 1,
  17562. t.isArray() ? t.getColumnCount() : 1,
  17563. r.isArray() ? r.getColumnCount() : 1,
  17564. n.isArray() ? n.getColumnCount() : 1,
  17565. o.isArray() ? o.getColumnCount() : 1
  17566. ), l = O(u, c, e, g.create(m.NA)), f = O(u, c, t, g.create(m.NA)), h = O(u, c, r, g.create(m.NA)), d = O(u, c, n, g.create(m.NA)), _ = O(u, c, o, g.create(m.NA)), C = l.map((E, b, R) => {
  17567. const p = f.get(b, R), N = h.get(b, R), M = d.get(b, R), w = _.get(b, R), { isError: D, errorObject: S, variants: P } = I(E, p, N, M, w);
  17568. if (D)
  17569. return S;
  17570. const [U, x, F, W, ne] = P, z = +U.getValue(), G = +x.getValue(), ge = +F.getValue();
  17571. let de = +W.getValue();
  17572. const Ee = Math.floor(+ne.getValue());
  17573. return z < 0 || G < 0 || ge <= 0 || de <= 0 || Math.floor(de) > Math.floor(ge) || Ee < 1 || Ee > 12 ? g.create(m.NUM) : (de < 1 && (de = 1), de = Math.floor(de), this._getResult(z, G, ge, de, Ee, b, R));
  17574. });
  17575. return u === 1 && c === 1 ? C.get(0, 0) : C;
  17576. }
  17577. _getResult(e, t, r, n, s, o, u) {
  17578. const c = +(1 - (t / e) ** (1 / r)).toFixed(3), l = e * c * s / 12;
  17579. let f = l, h = 0;
  17580. const d = n === r ? r - 1 : n;
  17581. for (let C = 2; C <= d; C++)
  17582. h = (e - f) * c, f += h;
  17583. let _;
  17584. return n === 1 ? _ = l : n === r ? _ = (e - f) * c : _ = h, Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : o === 0 && u === 0 ? y.create(_, Ke(this.getLocale())) : y.create(_);
  17585. }
  17586. }
  17587. class Y1 extends V {
  17588. constructor() {
  17589. super(...arguments);
  17590. A(this, "minParams", 4);
  17591. A(this, "maxParams", 5);
  17592. A(this, "needsLocale", !0);
  17593. }
  17594. calculate(e, t, r, n, s) {
  17595. let o = s != null ? s : y.create(2);
  17596. o.isNull() && (o = y.create(2));
  17597. const u = Math.max(
  17598. e.isArray() ? e.getRowCount() : 1,
  17599. t.isArray() ? t.getRowCount() : 1,
  17600. r.isArray() ? r.getRowCount() : 1,
  17601. n.isArray() ? n.getRowCount() : 1,
  17602. o.isArray() ? o.getRowCount() : 1
  17603. ), c = Math.max(
  17604. e.isArray() ? e.getColumnCount() : 1,
  17605. t.isArray() ? t.getColumnCount() : 1,
  17606. r.isArray() ? r.getColumnCount() : 1,
  17607. n.isArray() ? n.getColumnCount() : 1,
  17608. o.isArray() ? o.getColumnCount() : 1
  17609. ), l = O(u, c, e, g.create(m.NA)), f = O(u, c, t, g.create(m.NA)), h = O(u, c, r, g.create(m.NA)), d = O(u, c, n, g.create(m.NA)), _ = O(u, c, o, g.create(m.NA)), C = l.map((E, b, R) => {
  17610. const p = f.get(b, R), N = h.get(b, R), M = d.get(b, R), w = _.get(b, R), { isError: D, errorObject: S, variants: P } = I(E, p, N, M, w);
  17611. if (D)
  17612. return S;
  17613. const [U, x, F, W, ne] = P, z = +U.getValue(), G = +x.getValue(), ge = +F.getValue(), de = +W.getValue(), Ee = +ne.getValue();
  17614. if (z < 0 || G < 0 || ge <= 0 || de <= 0 || de > ge || Ee <= 0)
  17615. return g.create(m.NUM);
  17616. const Re = zs(z, G, ge, de, Ee);
  17617. return Number.isNaN(Re) || !Number.isFinite(Re) ? g.create(m.NUM) : b === 0 && R === 0 ? y.create(Re, Ke(this.getLocale())) : y.create(Re);
  17618. });
  17619. return u === 1 && c === 1 ? C.get(0, 0) : C;
  17620. }
  17621. }
  17622. class H1 extends V {
  17623. constructor() {
  17624. super(...arguments);
  17625. A(this, "minParams", 4);
  17626. A(this, "maxParams", 5);
  17627. }
  17628. calculate(e, t, r, n, s) {
  17629. const o = s != null ? s : y.create(0), { isError: u, errorObject: c, variants: l } = H(e, t, r, n, o);
  17630. if (u)
  17631. return c;
  17632. const [f, h, d, _, C] = l, E = k(f);
  17633. if (typeof E != "number")
  17634. return E;
  17635. const b = k(h);
  17636. if (typeof b != "number")
  17637. return b;
  17638. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  17639. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  17640. return g.create(m.VALUE);
  17641. if (R <= 0 || p <= 0 || N < 0 || N > 4 || Math.floor(E) >= Math.floor(b))
  17642. return g.create(m.NUM);
  17643. const { days: M, yearDays: w } = _e(E, b, N), D = (p - R) / p * (w / M);
  17644. return y.create(D);
  17645. }
  17646. }
  17647. class G1 extends V {
  17648. constructor() {
  17649. super(...arguments);
  17650. A(this, "minParams", 2);
  17651. A(this, "maxParams", 2);
  17652. }
  17653. calculate(e, t) {
  17654. const { isError: r, errorObject: n, variants: s } = H(e, t);
  17655. if (r)
  17656. return n;
  17657. const [o, u] = s, c = +o.getValue();
  17658. let l = Math.floor(+u.getValue());
  17659. if (Number.isNaN(c) || Number.isNaN(l))
  17660. return g.create(m.VALUE);
  17661. if (l < 0)
  17662. return g.create(m.NUM);
  17663. if (l >= 0 && l < 1)
  17664. return g.create(m.DIV_BY_ZERO);
  17665. l = Number.parseInt(`${l}`, 10);
  17666. let f = Number.parseInt(`${c}`, 10);
  17667. f += c % 1 * 10 ** Math.ceil(Math.log(l) / Math.LN10) / l;
  17668. const h = 10 ** (Math.ceil(Math.log(l) / Math.LN2) + 1);
  17669. return f = Math.round(f * h) / h, y.create(f);
  17670. }
  17671. }
  17672. class Q1 extends V {
  17673. constructor() {
  17674. super(...arguments);
  17675. A(this, "minParams", 2);
  17676. A(this, "maxParams", 2);
  17677. }
  17678. calculate(e, t) {
  17679. const { isError: r, errorObject: n, variants: s } = H(e, t);
  17680. if (r)
  17681. return n;
  17682. const [o, u] = s, c = +o.getValue();
  17683. let l = Math.floor(+u.getValue());
  17684. if (Number.isNaN(c) || Number.isNaN(l))
  17685. return g.create(m.VALUE);
  17686. if (l < 0)
  17687. return g.create(m.NUM);
  17688. if (l >= 0 && l < 1)
  17689. return g.create(m.DIV_BY_ZERO);
  17690. l = Number.parseInt(`${l}`, 10);
  17691. let f = Number.parseInt(`${c}`, 10);
  17692. return f += c % 1 * 10 ** -Math.ceil(Math.log(l) / Math.LN10) * l, y.create(f);
  17693. }
  17694. }
  17695. class W1 extends V {
  17696. constructor() {
  17697. super(...arguments);
  17698. A(this, "minParams", 5);
  17699. A(this, "maxParams", 6);
  17700. }
  17701. calculate(e, t, r, n, s, o) {
  17702. let u = o != null ? o : y.create(0);
  17703. u.isNull() && (u = y.create(0));
  17704. const { isError: c, errorObject: l, variants: f } = Fe(e, t, r, n, s, u);
  17705. if (c)
  17706. return l;
  17707. const [h, d, _, C, E, b] = f, R = k(h);
  17708. if (typeof R != "number")
  17709. return R;
  17710. const p = k(d);
  17711. if (typeof p != "number")
  17712. return p;
  17713. const N = +_.getValue(), M = +C.getValue(), w = Math.floor(+E.getValue()), D = Math.floor(+b.getValue());
  17714. if (Number.isNaN(N) || Number.isNaN(M) || Number.isNaN(w) || Number.isNaN(D))
  17715. return g.create(m.VALUE);
  17716. if (N < 0 || M < 0 || ![1, 2, 4].includes(w) || D < 0 || D > 4 || Math.floor(R) >= Math.floor(p) || R <= 0 || p <= 366)
  17717. return g.create(m.NUM);
  17718. const S = bu(R, p, N, M, w, D);
  17719. return y.create(S);
  17720. }
  17721. }
  17722. class q1 extends V {
  17723. constructor() {
  17724. super(...arguments);
  17725. A(this, "minParams", 2);
  17726. A(this, "maxParams", 2);
  17727. }
  17728. calculate(e, t) {
  17729. const { isError: r, errorObject: n, variants: s } = H(e, t);
  17730. if (r)
  17731. return n;
  17732. const [o, u] = s, c = +o.getValue();
  17733. let l = Math.floor(+u.getValue());
  17734. if (Number.isNaN(c) || Number.isNaN(l))
  17735. return g.create(m.VALUE);
  17736. if (c <= 0 || l < 1)
  17737. return g.create(m.NUM);
  17738. l = Number.parseInt(`${l}`, 10);
  17739. const f = (1 + c / l) ** l - 1;
  17740. return y.create(f);
  17741. }
  17742. }
  17743. class K1 extends V {
  17744. constructor() {
  17745. super(...arguments);
  17746. A(this, "minParams", 3);
  17747. A(this, "maxParams", 5);
  17748. A(this, "needsLocale", !0);
  17749. }
  17750. calculate(e, t, r, n, s) {
  17751. const o = n != null ? n : y.create(0), u = s != null ? s : y.create(0), c = Math.max(
  17752. e.isArray() ? e.getRowCount() : 1,
  17753. t.isArray() ? t.getRowCount() : 1,
  17754. r.isArray() ? r.getRowCount() : 1,
  17755. o.isArray() ? o.getRowCount() : 1,
  17756. u.isArray() ? u.getRowCount() : 1
  17757. ), l = Math.max(
  17758. e.isArray() ? e.getColumnCount() : 1,
  17759. t.isArray() ? t.getColumnCount() : 1,
  17760. r.isArray() ? r.getColumnCount() : 1,
  17761. o.isArray() ? o.getColumnCount() : 1,
  17762. u.isArray() ? u.getColumnCount() : 1
  17763. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.map((b, R, p) => {
  17764. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p), { isError: S, errorObject: P, variants: U } = I(b, N, M, w, D);
  17765. if (S)
  17766. return P;
  17767. const [x, F, W, ne, z] = U, G = +x.getValue(), ge = +F.getValue(), de = +W.getValue(), Ee = +ne.getValue(), Re = +z.getValue(), he = sr(G, ge, de, Ee, Re ? 1 : 0);
  17768. return Number.isNaN(he) || !Number.isFinite(he) ? g.create(m.NUM) : R === 0 && p === 0 ? y.create(he, Ke(this.getLocale())) : y.create(he);
  17769. });
  17770. return c === 1 && l === 1 ? E.get(0, 0) : E;
  17771. }
  17772. }
  17773. class X1 extends V {
  17774. constructor() {
  17775. super(...arguments);
  17776. A(this, "minParams", 2);
  17777. A(this, "maxParams", 2);
  17778. }
  17779. calculate(e, t) {
  17780. const { isError: r, errorObject: n, variants: s } = H(e);
  17781. if (r)
  17782. return n;
  17783. const [o] = s, u = +o.getValue();
  17784. if (Number.isNaN(u))
  17785. return g.create(m.VALUE);
  17786. let c = u;
  17787. if (t.isArray()) {
  17788. const l = t.getArrayValue().flat();
  17789. for (let f = 0; f < l.length; f++) {
  17790. const h = l[f];
  17791. if (h.isBoolean())
  17792. return g.create(m.VALUE);
  17793. const d = +h.getValue();
  17794. if (Number.isNaN(d))
  17795. return g.create(m.VALUE);
  17796. c *= 1 + d;
  17797. }
  17798. } else {
  17799. if (t.isBoolean())
  17800. return g.create(m.VALUE);
  17801. const l = +t.getValue();
  17802. if (Number.isNaN(l))
  17803. return g.create(m.VALUE);
  17804. c *= 1 + l;
  17805. }
  17806. return y.create(c);
  17807. }
  17808. }
  17809. class Z1 extends V {
  17810. constructor() {
  17811. super(...arguments);
  17812. A(this, "minParams", 4);
  17813. A(this, "maxParams", 5);
  17814. }
  17815. calculate(e, t, r, n, s) {
  17816. const o = s != null ? s : y.create(0), { isError: u, errorObject: c, variants: l } = H(e, t, r, n, o);
  17817. if (u)
  17818. return c;
  17819. const [f, h, d, _, C] = l, E = k(f);
  17820. if (typeof E != "number")
  17821. return E;
  17822. const b = k(h);
  17823. if (typeof b != "number")
  17824. return b;
  17825. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  17826. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  17827. return g.create(m.VALUE);
  17828. if (R <= 0 || p <= 0 || N < 0 || N > 4 || Math.floor(E) >= Math.floor(b))
  17829. return g.create(m.NUM);
  17830. const { days: M, yearDays: w } = _e(E, b, N), D = (p - R) / R * (w / M);
  17831. return y.create(D);
  17832. }
  17833. }
  17834. class z1 extends V {
  17835. constructor() {
  17836. super(...arguments);
  17837. A(this, "minParams", 4);
  17838. A(this, "maxParams", 6);
  17839. A(this, "needsLocale", !0);
  17840. }
  17841. calculate(e, t, r, n, s, o) {
  17842. const u = s != null ? s : y.create(0), c = o != null ? o : y.create(0), l = Math.max(
  17843. e.isArray() ? e.getRowCount() : 1,
  17844. t.isArray() ? t.getRowCount() : 1,
  17845. r.isArray() ? r.getRowCount() : 1,
  17846. n.isArray() ? n.getRowCount() : 1,
  17847. u.isArray() ? u.getRowCount() : 1,
  17848. c.isArray() ? c.getRowCount() : 1
  17849. ), f = Math.max(
  17850. e.isArray() ? e.getColumnCount() : 1,
  17851. t.isArray() ? t.getColumnCount() : 1,
  17852. r.isArray() ? r.getColumnCount() : 1,
  17853. n.isArray() ? n.getColumnCount() : 1,
  17854. u.isArray() ? u.getColumnCount() : 1,
  17855. c.isArray() ? c.getColumnCount() : 1
  17856. ), h = O(l, f, e, g.create(m.NA)), d = O(l, f, t, g.create(m.NA)), _ = O(l, f, r, g.create(m.NA)), C = O(l, f, n, g.create(m.NA)), E = O(l, f, u, g.create(m.NA)), b = O(l, f, c, g.create(m.NA)), R = h.map((p, N, M) => {
  17857. const w = d.get(N, M), D = _.get(N, M), S = C.get(N, M), P = E.get(N, M), U = b.get(N, M), { isError: x, errorObject: F, variants: W } = I(p, w, D, S, P, U);
  17858. if (x)
  17859. return F;
  17860. const [ne, z, G, ge, de, Ee] = W, Re = +ne.getValue(), he = +z.getValue(), ke = +G.getValue(), Ot = +ge.getValue(), ar = +de.getValue(), Mt = +Ee.getValue();
  17861. if (he < 1 || Math.floor(he) > Math.ceil(ke))
  17862. return g.create(m.NUM);
  17863. const st = yu(Re, he, ke, Ot, ar, Mt ? 1 : 0);
  17864. return Number.isNaN(st) || !Number.isFinite(st) ? g.create(m.NUM) : N === 0 && M === 0 ? y.create(st, Ke(this.getLocale())) : y.create(st);
  17865. });
  17866. return l === 1 && f === 1 ? R.get(0, 0) : R;
  17867. }
  17868. }
  17869. class J1 extends V {
  17870. constructor() {
  17871. super(...arguments);
  17872. A(this, "minParams", 1);
  17873. A(this, "maxParams", 2);
  17874. }
  17875. calculate(e, t) {
  17876. let r = t != null ? t : y.create(0.1);
  17877. return r.isNull() && (r = y.create(0.1)), r.isArray() ? r.map((n, s, o) => this._handleSingleObject(e, n, s, o)) : this._handleSingleObject(e, r);
  17878. }
  17879. _handleSingleObject(e, t, r = 0, n = 0) {
  17880. if (e.isError())
  17881. return e;
  17882. if (t.isError())
  17883. return t;
  17884. if (e.isNull())
  17885. return g.create(m.VALUE);
  17886. if (!e.isArray())
  17887. return g.create(m.NUM);
  17888. const { _values: s, valuesHasError: o } = this._getValues(e);
  17889. if (o)
  17890. return g.create(m.VALUE);
  17891. let u = t;
  17892. if (u.isString() && (u = u.convertToNumberObjectValue(), u.isError()))
  17893. return u;
  17894. const c = +u.getValue(), { positive: l, negative: f } = this._checkValues(s);
  17895. if (!l || !f)
  17896. return g.create(m.NUM);
  17897. const h = Ia(c, (d) => Ru(d, s));
  17898. return typeof h != "number" ? h : r === 0 && n === 0 ? y.create(h, "0%") : y.create(h);
  17899. }
  17900. _getValues(e) {
  17901. const t = [];
  17902. let r = !1;
  17903. return e.iterator((n) => {
  17904. const s = n;
  17905. if (s.isError())
  17906. return r = !0, !1;
  17907. if (s.isNull() || s.isBoolean())
  17908. return !0;
  17909. const o = +s.getValue();
  17910. if (Number.isNaN(o))
  17911. return !0;
  17912. t.push(o);
  17913. }), {
  17914. _values: t,
  17915. valuesHasError: r
  17916. };
  17917. }
  17918. _checkValues(e) {
  17919. let t = !1, r = !1;
  17920. for (let n = 0; n < e.length; n++)
  17921. e[n] > 0 && (t = !0), e[n] < 0 && (r = !0);
  17922. return {
  17923. positive: t,
  17924. negative: r
  17925. };
  17926. }
  17927. }
  17928. class e0 extends V {
  17929. constructor() {
  17930. super(...arguments);
  17931. A(this, "minParams", 4);
  17932. A(this, "maxParams", 4);
  17933. }
  17934. calculate(e, t, r, n) {
  17935. const s = Math.max(
  17936. e.isArray() ? e.getRowCount() : 1,
  17937. t.isArray() ? t.getRowCount() : 1,
  17938. r.isArray() ? r.getRowCount() : 1,
  17939. n.isArray() ? n.getRowCount() : 1
  17940. ), o = Math.max(
  17941. e.isArray() ? e.getColumnCount() : 1,
  17942. t.isArray() ? t.getColumnCount() : 1,
  17943. r.isArray() ? r.getColumnCount() : 1,
  17944. n.isArray() ? n.getColumnCount() : 1
  17945. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.map((d, _, C) => {
  17946. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C), { isError: p, errorObject: N, variants: M } = I(d, E, b, R);
  17947. if (p)
  17948. return N;
  17949. const [w, D, S, P] = M, U = +w.getValue(), x = +D.getValue(), F = +S.getValue(), W = +P.getValue();
  17950. if (F === 0)
  17951. return g.create(m.DIV_BY_ZERO);
  17952. const ne = W * U * (x / F - 1);
  17953. return y.create(ne);
  17954. });
  17955. return s === 1 && o === 1 ? h.get(0, 0) : h;
  17956. }
  17957. }
  17958. class t0 extends V {
  17959. constructor() {
  17960. super(...arguments);
  17961. A(this, "minParams", 5);
  17962. A(this, "maxParams", 6);
  17963. }
  17964. calculate(e, t, r, n, s, o) {
  17965. let u = o != null ? o : y.create(0);
  17966. u.isNull() && (u = y.create(0));
  17967. const { isError: c, errorObject: l, variants: f } = Fe(e, t, r, n, s, u);
  17968. if (c)
  17969. return l;
  17970. const [h, d, _, C, E, b] = f, R = k(h);
  17971. if (typeof R != "number")
  17972. return R;
  17973. const p = k(d);
  17974. if (typeof p != "number")
  17975. return p;
  17976. const N = +_.getValue(), M = +C.getValue(), w = Math.floor(+E.getValue()), D = Math.floor(+b.getValue());
  17977. if (Number.isNaN(N) || Number.isNaN(M) || Number.isNaN(w) || Number.isNaN(D))
  17978. return g.create(m.VALUE);
  17979. if (N < 0 || M < 0 || ![1, 2, 4].includes(w) || D < 0 || D > 4 || Math.floor(R) >= Math.floor(p))
  17980. return g.create(m.NUM);
  17981. let S = bu(R, p, N, M, w, D);
  17982. return S /= 1 + M / w, y.create(S);
  17983. }
  17984. }
  17985. class r0 extends V {
  17986. constructor() {
  17987. super(...arguments);
  17988. A(this, "minParams", 3);
  17989. A(this, "maxParams", 3);
  17990. }
  17991. calculate(e, t, r) {
  17992. const { _values: n, numberValues: s, positive: o, negative: u } = this._getValues(e), c = Math.max(
  17993. t.isArray() ? t.getRowCount() : 1,
  17994. r.isArray() ? r.getRowCount() : 1
  17995. ), l = Math.max(
  17996. t.isArray() ? t.getColumnCount() : 1,
  17997. r.isArray() ? r.getColumnCount() : 1
  17998. ), f = O(c, l, t, g.create(m.NA)), h = O(c, l, r, g.create(m.NA)), d = f.map((_, C, E) => {
  17999. const b = h.get(C, E);
  18000. if (e.isError())
  18001. return e;
  18002. if (b.isError())
  18003. return b;
  18004. if (n.isError())
  18005. return n;
  18006. if (!o || !u)
  18007. return g.create(m.DIV_BY_ZERO);
  18008. const R = +_.getValue(), p = +b.getValue();
  18009. if (Number.isNaN(R) || Number.isNaN(p))
  18010. return g.create(m.VALUE);
  18011. if (p === -1)
  18012. return g.create(m.DIV_BY_ZERO);
  18013. const N = this._getResult(s, R, p);
  18014. return C === 0 && E === 0 ? y.create(N, "0%") : y.create(N);
  18015. });
  18016. return c === 1 && l === 1 ? d.get(0, 0) : d;
  18017. }
  18018. _getValues(e) {
  18019. let t = e, r = [], n = !1, s = !1;
  18020. if (!e.isError())
  18021. if (e.isNull())
  18022. t = g.create(m.VALUE);
  18023. else if (!e.isArray())
  18024. t = g.create(m.DIV_BY_ZERO);
  18025. else {
  18026. const { numberValues: o, valuesHasError: u, errorObject: c, positive: l, negative: f } = this._checkValues(e);
  18027. u && (t = c), r = o, n = l, s = f;
  18028. }
  18029. return {
  18030. _values: t,
  18031. numberValues: r,
  18032. positive: n,
  18033. negative: s
  18034. };
  18035. }
  18036. _checkValues(e) {
  18037. const t = [];
  18038. let r = !1, n = g.create(m.VALUE), s = !1, o = !1;
  18039. return e.iterator((u) => {
  18040. const c = u;
  18041. if (c.isError())
  18042. return r = !0, n = c, !1;
  18043. if (c.isNull() || c.isBoolean())
  18044. return !0;
  18045. const l = +c.getValue();
  18046. if (Number.isNaN(l))
  18047. return !0;
  18048. l > 0 && (s = !0), l < 0 && (o = !0), t.push(l);
  18049. }), {
  18050. numberValues: t,
  18051. valuesHasError: r,
  18052. errorObject: n,
  18053. positive: s,
  18054. negative: o
  18055. };
  18056. }
  18057. _getResult(e, t, r) {
  18058. const n = e.length, s = [], o = [];
  18059. for (let d = 0; d < n; d++)
  18060. e[d] > 0 ? o.push(e[d]) : e[d] < 0 && s.push(e[d]);
  18061. const u = this._npv(r, e, "positive"), c = this._npv(t, e, "negative"), l = -u * (1 + r) ** n, f = c * (1 + t);
  18062. return (l / f) ** (1 / (n - 1)) - 1;
  18063. }
  18064. _npv(e, t, r) {
  18065. let n = 0;
  18066. for (let s = 1; s <= t.length; s++) {
  18067. const o = t[s - 1];
  18068. (r === "positive" && o > 0 || r === "negative" && o < 0) && (n += o / (1 + e) ** s);
  18069. }
  18070. return n;
  18071. }
  18072. }
  18073. class n0 extends V {
  18074. constructor() {
  18075. super(...arguments);
  18076. A(this, "minParams", 2);
  18077. A(this, "maxParams", 2);
  18078. }
  18079. calculate(e, t) {
  18080. const { isError: r, errorObject: n, variants: s } = H(e, t);
  18081. if (r)
  18082. return n;
  18083. const [o, u] = s, c = +o.getValue();
  18084. let l = Math.floor(+u.getValue());
  18085. if (Number.isNaN(c) || Number.isNaN(l))
  18086. return g.create(m.VALUE);
  18087. if (c <= 0 || l < 1)
  18088. return g.create(m.NUM);
  18089. l = Number.parseInt(`${l}`, 10);
  18090. const f = ((c + 1) ** (1 / l) - 1) * l;
  18091. return y.create(f);
  18092. }
  18093. }
  18094. class s0 extends V {
  18095. constructor() {
  18096. super(...arguments);
  18097. A(this, "minParams", 3);
  18098. A(this, "maxParams", 5);
  18099. }
  18100. calculate(e, t, r, n, s) {
  18101. const o = n != null ? n : y.create(0), u = s != null ? s : y.create(0), c = Math.max(
  18102. e.isArray() ? e.getRowCount() : 1,
  18103. t.isArray() ? t.getRowCount() : 1,
  18104. r.isArray() ? r.getRowCount() : 1,
  18105. o.isArray() ? o.getRowCount() : 1,
  18106. u.isArray() ? u.getRowCount() : 1
  18107. ), l = Math.max(
  18108. e.isArray() ? e.getColumnCount() : 1,
  18109. t.isArray() ? t.getColumnCount() : 1,
  18110. r.isArray() ? r.getColumnCount() : 1,
  18111. o.isArray() ? o.getColumnCount() : 1,
  18112. u.isArray() ? u.getColumnCount() : 1
  18113. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.map((b, R, p) => {
  18114. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p), { isError: S, errorObject: P, variants: U } = I(b, N, M, w, D);
  18115. if (S)
  18116. return P;
  18117. const [x, F, W, ne, z] = U, G = +x.getValue(), ge = +F.getValue(), de = +W.getValue(), Ee = +ne.getValue();
  18118. let Re = +z.getValue();
  18119. if (Re = Re ? 1 : 0, G === 0 && ge === 0)
  18120. return g.create(m.DIV_BY_ZERO);
  18121. let he;
  18122. if (G === 0)
  18123. he = -(de + Ee) / ge;
  18124. else {
  18125. const ke = ge * (1 + G * Re) - Ee * G, Ot = de * G + ge * (1 + G * Re);
  18126. he = Math.log(ke / Ot) / Math.log(1 + G);
  18127. }
  18128. return Number.isNaN(he) || !Number.isFinite(he) ? g.create(m.NUM) : y.create(he);
  18129. });
  18130. return c === 1 && l === 1 ? E.get(0, 0) : E;
  18131. }
  18132. }
  18133. class a0 extends V {
  18134. constructor() {
  18135. super(...arguments);
  18136. A(this, "minParams", 2);
  18137. A(this, "maxParams", 255);
  18138. A(this, "needsLocale", !0);
  18139. }
  18140. calculate(e, ...t) {
  18141. if (e.isError())
  18142. return e;
  18143. const { isError: r, errorObject: n, values: s } = this._getValues(t);
  18144. return e.isArray() ? e.map((o, u, c) => this._handleSingleObject(o, r, n, s, u, c)) : this._handleSingleObject(e, r, n, s);
  18145. }
  18146. _handleSingleObject(e, t, r, n, s = 0, o = 0) {
  18147. let u = e;
  18148. if (u.isString() && (u = u.convertToNumberObjectValue()), u.isError())
  18149. return u;
  18150. if (t)
  18151. return r;
  18152. const c = +e.getValue(), l = Ru(c, n);
  18153. return Number.isNaN(l) || Math.abs(l) === 1 / 0 ? g.create(m.DIV_BY_ZERO) : s === 0 && o === 0 ? y.create(l, Ke(this.getLocale())) : y.create(l);
  18154. }
  18155. _getValues(e) {
  18156. const t = [];
  18157. for (let r = 0; r < e.length; r++) {
  18158. const n = e[r];
  18159. if (n.isError())
  18160. return {
  18161. isError: !0,
  18162. errorObject: n
  18163. };
  18164. if (n.isArray()) {
  18165. let s = !1, o = g.create(m.VALUE);
  18166. if (n.iterator((u) => {
  18167. const c = u;
  18168. if (c.isError())
  18169. return s = !0, o = c, !1;
  18170. if (c.isNull() || c.isBoolean())
  18171. return !0;
  18172. const l = +c.getValue();
  18173. if (Number.isNaN(l))
  18174. return !0;
  18175. t.push(l);
  18176. }), s)
  18177. return {
  18178. isError: s,
  18179. errorObject: o
  18180. };
  18181. } else {
  18182. const s = +n.getValue();
  18183. if (Number.isNaN(s))
  18184. return {
  18185. isError: !0,
  18186. errorObject: g.create(m.VALUE)
  18187. };
  18188. t.push(s);
  18189. }
  18190. }
  18191. return {
  18192. isError: !1,
  18193. values: t
  18194. };
  18195. }
  18196. }
  18197. class i0 extends V {
  18198. constructor() {
  18199. super(...arguments);
  18200. A(this, "minParams", 8);
  18201. A(this, "maxParams", 9);
  18202. }
  18203. calculate(e, t, r, n, s, o, u, c, l) {
  18204. let f = l != null ? l : y.create(0);
  18205. f.isNull() && (f = y.create(0));
  18206. const { isError: h, errorObject: d, variants: _ } = Fe(e, t, r, n, s, o, u, c, f);
  18207. if (h)
  18208. return d;
  18209. const [C, E, b, R, p, N, M, w, D] = _, S = k(C);
  18210. if (typeof S != "number")
  18211. return S;
  18212. const P = k(E);
  18213. if (typeof P != "number")
  18214. return P;
  18215. const U = k(b);
  18216. if (typeof U != "number")
  18217. return U;
  18218. const x = k(R);
  18219. if (typeof x != "number")
  18220. return x;
  18221. const F = +p.getValue(), W = +N.getValue(), ne = +M.getValue(), z = Math.floor(+w.getValue()), G = Math.floor(+D.getValue());
  18222. if (Number.isNaN(F) || Number.isNaN(W) || Number.isNaN(ne) || Number.isNaN(z) || Number.isNaN(G))
  18223. return g.create(m.VALUE);
  18224. if (F < 0 || W < 0 || ne <= 0 || ![1, 2, 4].includes(z) || G < 0 || G > 4 || !this._validDate(P, x, S, U, z))
  18225. return g.create(m.NUM);
  18226. const ge = pu(S, P, U, x, F, W, ne, z, G);
  18227. return y.create(ge);
  18228. }
  18229. _validDate(e, t, r, n, s) {
  18230. return this._getDateCorrectOrder(e, t, r, n) && Vu(e, t, s) && Or(n, e, s);
  18231. }
  18232. _getDateCorrectOrder(e, t, r, n) {
  18233. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r) && Math.floor(r) > Math.floor(n);
  18234. }
  18235. }
  18236. class o0 extends V {
  18237. constructor() {
  18238. super(...arguments);
  18239. A(this, "minParams", 8);
  18240. A(this, "maxParams", 9);
  18241. }
  18242. calculate(e, t, r, n, s, o, u, c, l) {
  18243. let f = l != null ? l : y.create(0);
  18244. f.isNull() && (f = y.create(0));
  18245. const { isError: h, errorObject: d, variants: _ } = Fe(e, t, r, n, s, o, u, c, f);
  18246. if (h)
  18247. return d;
  18248. const [C, E, b, R, p, N, M, w, D] = _, S = k(C);
  18249. if (typeof S != "number")
  18250. return S;
  18251. const P = k(E);
  18252. if (typeof P != "number")
  18253. return P;
  18254. const U = k(b);
  18255. if (typeof U != "number")
  18256. return U;
  18257. const x = k(R);
  18258. if (typeof x != "number")
  18259. return x;
  18260. const F = +p.getValue(), W = +N.getValue(), ne = +M.getValue(), z = Math.floor(+w.getValue()), G = Math.floor(+D.getValue());
  18261. return Number.isNaN(F) || Number.isNaN(W) || Number.isNaN(ne) || Number.isNaN(z) || Number.isNaN(G) ? g.create(m.VALUE) : F < 0 || W <= 0 || ne <= 0 || ![1, 2, 4].includes(z) || G < 0 || G > 4 || !this._validDate(P, x, S, U, z) ? g.create(m.NUM) : this._getResult(S, P, U, x, F, W, ne, z, G);
  18262. }
  18263. _validDate(e, t, r, n, s) {
  18264. return this._getDateCorrectOrder(e, t, r, n) && Vu(e, t, s) && Or(n, e, s);
  18265. }
  18266. _getDateCorrectOrder(e, t, r, n) {
  18267. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r) && Math.floor(r) > Math.floor(n);
  18268. }
  18269. _getResult(e, t, r, n, s, o, u, c, l) {
  18270. const { days: f } = _e(e, t, l), h = (s * f * 100 - (o - 100)) / ((o - 100) * 0.25 * (1 + 2 * f) + f * 100);
  18271. function d(C) {
  18272. return o - pu(e, t, r, n, s, C, u, c, l);
  18273. }
  18274. const _ = Ia(h, (C) => d(C));
  18275. return typeof _ != "number" ? _ : y.create(_);
  18276. }
  18277. }
  18278. class u0 extends V {
  18279. constructor() {
  18280. super(...arguments);
  18281. A(this, "minParams", 7);
  18282. A(this, "maxParams", 8);
  18283. }
  18284. calculate(e, t, r, n, s, o, u, c) {
  18285. let l = c != null ? c : y.create(0);
  18286. l.isNull() && (l = y.create(0));
  18287. const { isError: f, errorObject: h, variants: d } = Fe(e, t, r, n, s, o, u, l);
  18288. if (f)
  18289. return h;
  18290. const [_, C, E, b, R, p, N, M] = d, w = k(_);
  18291. if (typeof w != "number")
  18292. return w;
  18293. const D = k(C);
  18294. if (typeof D != "number")
  18295. return D;
  18296. const S = k(E);
  18297. if (typeof S != "number")
  18298. return S;
  18299. const P = +b.getValue(), U = +R.getValue(), x = +p.getValue(), F = Math.floor(+N.getValue()), W = Math.floor(+M.getValue());
  18300. if (Number.isNaN(P) || Number.isNaN(U) || Number.isNaN(x) || Number.isNaN(F) || Number.isNaN(W))
  18301. return g.create(m.VALUE);
  18302. if (P < 0 || U < 0 || x <= 0 || ![1, 2, 4].includes(F) || W < 0 || W > 4 || !this._validDate(D, w, S, F))
  18303. return g.create(m.NUM);
  18304. const ne = this._getResult(w, D, S, P, U, x, F, W);
  18305. return y.create(ne);
  18306. }
  18307. _validDate(e, t, r, n) {
  18308. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r) && Or(r, e, n);
  18309. }
  18310. _getResult(e, t, r, n, s, o, u, c) {
  18311. const l = this._getCoupDate(t, r, u), f = this._getFrac(r, e, l, u, c), h = this._getFrac(r, t, l, u, c), d = this._getFrac(e, t, l, u, c);
  18312. return (o * u + 100 * n * (h - f * (1 + s * d / u))) / (s * d + u);
  18313. }
  18314. _getCoupDate(e, t, r) {
  18315. const n = re(e), s = re(t);
  18316. for (s.setUTCFullYear(n.getUTCFullYear()), s > n && s.setUTCFullYear(s.getUTCFullYear() - 1); s < n; )
  18317. s.setUTCMonth(s.getUTCMonth() + 12 / r);
  18318. return ye(s);
  18319. }
  18320. _getFrac(e, t, r, n, s) {
  18321. const o = re(e), u = re(t), c = re(r);
  18322. for (c.setUTCFullYear(o.getUTCFullYear()), c < o && c.setUTCFullYear(c.getUTCFullYear() + 1); c > o; )
  18323. c.setUTCMonth(c.getUTCMonth() - 12 / n);
  18324. let l = ye(c);
  18325. c.setUTCMonth(c.getUTCMonth() + 12 / n);
  18326. let f = ye(c);
  18327. if (f >= t) {
  18328. const { days: p } = _e(e, t, s), N = qe(l, f, n, s);
  18329. return p / N;
  18330. }
  18331. const { days: h } = _e(e, f, s), d = qe(l, f, n, s);
  18332. let _ = h / d;
  18333. const C = re(f), E = re(f);
  18334. for (E.setUTCMonth(E.getUTCMonth() + 12 / n); E < u; )
  18335. C.setUTCMonth(C.getUTCMonth() + 12 / n), E.setUTCMonth(E.getUTCMonth() + 12 / n), _ += 1;
  18336. l = ye(C), f = ye(E);
  18337. const { days: b } = _e(l, t, s), R = qe(l, f, n, s);
  18338. return _ += b / R, _;
  18339. }
  18340. }
  18341. class c0 extends V {
  18342. constructor() {
  18343. super(...arguments);
  18344. A(this, "minParams", 8);
  18345. A(this, "maxParams", 9);
  18346. }
  18347. calculate(e, t, r, n, s, o, u, c) {
  18348. let l = c != null ? c : y.create(0);
  18349. l.isNull() && (l = y.create(0));
  18350. const { isError: f, errorObject: h, variants: d } = Fe(e, t, r, n, s, o, u, l);
  18351. if (f)
  18352. return h;
  18353. const [_, C, E, b, R, p, N, M] = d, w = k(_);
  18354. if (typeof w != "number")
  18355. return w;
  18356. const D = k(C);
  18357. if (typeof D != "number")
  18358. return D;
  18359. const S = k(E);
  18360. if (typeof S != "number")
  18361. return S;
  18362. const P = +b.getValue(), U = +R.getValue(), x = +p.getValue(), F = Math.floor(+N.getValue()), W = Math.floor(+M.getValue());
  18363. if (Number.isNaN(P) || Number.isNaN(U) || Number.isNaN(x) || Number.isNaN(F) || Number.isNaN(W))
  18364. return g.create(m.VALUE);
  18365. if (P < 0 || U <= 0 || x <= 0 || ![1, 2, 4].includes(F) || W < 0 || W > 4 || !this._validDate(D, w, S, F))
  18366. return g.create(m.NUM);
  18367. const ne = this._getResult(w, D, S, P, U, x, F, W);
  18368. return y.create(ne);
  18369. }
  18370. _validDate(e, t, r, n) {
  18371. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r) && Or(r, e, n);
  18372. }
  18373. _getResult(e, t, r, n, s, o, u, c) {
  18374. const l = this._getCoupDate(t, r, u), f = this._getFrac(r, e, l, u, c), h = this._getFrac(r, t, l, u, c), d = this._getFrac(e, t, l, u, c);
  18375. return (u * (o - s) + 100 * n * (h - f)) / (d * s + 100 * n * f * d / u);
  18376. }
  18377. _getCoupDate(e, t, r) {
  18378. const n = re(e), s = re(t);
  18379. for (s.setUTCFullYear(n.getUTCFullYear()), s > n && s.setUTCFullYear(s.getUTCFullYear() - 1); s < n; )
  18380. s.setUTCMonth(s.getUTCMonth() + 12 / r);
  18381. return ye(s);
  18382. }
  18383. _getFrac(e, t, r, n, s) {
  18384. const o = re(e), u = re(t), c = re(r);
  18385. for (c.setUTCFullYear(o.getUTCFullYear()), c < o && c.setUTCFullYear(c.getUTCFullYear() + 1); c > o; )
  18386. c.setUTCMonth(c.getUTCMonth() - 12 / n);
  18387. let l = ye(c);
  18388. c.setUTCMonth(c.getUTCMonth() + 12 / n);
  18389. let f = ye(c);
  18390. if (f >= t) {
  18391. const { days: p } = _e(e, t, s), N = qe(l, f, n, s);
  18392. return p / N;
  18393. }
  18394. const { days: h } = _e(e, f, s), d = qe(l, f, n, s);
  18395. let _ = h / d;
  18396. const C = re(f), E = re(f);
  18397. for (E.setUTCMonth(E.getUTCMonth() + 12 / n); E < u; )
  18398. C.setUTCMonth(C.getUTCMonth() + 12 / n), E.setUTCMonth(E.getUTCMonth() + 12 / n), _ += 1;
  18399. l = ye(C), f = ye(E);
  18400. const { days: b } = _e(l, t, s), R = qe(l, f, n, s);
  18401. return _ += b / R, _;
  18402. }
  18403. }
  18404. class l0 extends V {
  18405. constructor() {
  18406. super(...arguments);
  18407. A(this, "minParams", 3);
  18408. A(this, "maxParams", 3);
  18409. }
  18410. calculate(e, t, r) {
  18411. const n = Math.max(
  18412. e.isArray() ? e.getRowCount() : 1,
  18413. t.isArray() ? t.getRowCount() : 1,
  18414. r.isArray() ? r.getRowCount() : 1
  18415. ), s = Math.max(
  18416. e.isArray() ? e.getColumnCount() : 1,
  18417. t.isArray() ? t.getColumnCount() : 1,
  18418. r.isArray() ? r.getColumnCount() : 1
  18419. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.map((f, h, d) => {
  18420. const _ = u.get(h, d), C = c.get(h, d), { isError: E, errorObject: b, variants: R } = I(f, _, C);
  18421. if (E)
  18422. return b;
  18423. const [p, N, M] = R, w = +p.getValue(), D = +N.getValue(), S = +M.getValue();
  18424. if (w <= -1)
  18425. return g.create(m.NUM);
  18426. const P = (Math.log(S) - Math.log(D)) / Math.log(1 + w);
  18427. return Number.isNaN(P) || !Number.isFinite(P) ? g.create(m.NUM) : y.create(P);
  18428. });
  18429. return n === 1 && s === 1 ? l.get(0, 0) : l;
  18430. }
  18431. }
  18432. class f0 extends V {
  18433. constructor() {
  18434. super(...arguments);
  18435. A(this, "minParams", 3);
  18436. A(this, "maxParams", 5);
  18437. A(this, "needsLocale", !0);
  18438. }
  18439. calculate(e, t, r, n, s) {
  18440. const o = n != null ? n : y.create(0), u = s != null ? s : y.create(0), c = Math.max(
  18441. e.isArray() ? e.getRowCount() : 1,
  18442. t.isArray() ? t.getRowCount() : 1,
  18443. r.isArray() ? r.getRowCount() : 1,
  18444. o.isArray() ? o.getRowCount() : 1,
  18445. u.isArray() ? u.getRowCount() : 1
  18446. ), l = Math.max(
  18447. e.isArray() ? e.getColumnCount() : 1,
  18448. t.isArray() ? t.getColumnCount() : 1,
  18449. r.isArray() ? r.getColumnCount() : 1,
  18450. o.isArray() ? o.getColumnCount() : 1,
  18451. u.isArray() ? u.getColumnCount() : 1
  18452. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.map((b, R, p) => {
  18453. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p), { isError: S, errorObject: P, variants: U } = I(b, N, M, w, D);
  18454. if (S)
  18455. return P;
  18456. const [x, F, W, ne, z] = U, G = +x.getValue(), ge = +F.getValue(), de = +W.getValue(), Ee = +ne.getValue(), Re = +z.getValue();
  18457. if (G <= -1)
  18458. return g.create(m.NUM);
  18459. const he = Gr(G, ge, de, Ee, Re ? 1 : 0);
  18460. return Number.isNaN(he) || !Number.isFinite(he) ? g.create(m.NUM) : R === 0 && p === 0 ? y.create(he, Ke(this.getLocale())) : y.create(he);
  18461. });
  18462. return c === 1 && l === 1 ? E.get(0, 0) : E;
  18463. }
  18464. }
  18465. class h0 extends V {
  18466. constructor() {
  18467. super(...arguments);
  18468. A(this, "minParams", 4);
  18469. A(this, "maxParams", 6);
  18470. A(this, "needsLocale", !0);
  18471. }
  18472. calculate(e, t, r, n, s, o) {
  18473. const u = s != null ? s : y.create(0), c = o != null ? o : y.create(0), l = Math.max(
  18474. e.isArray() ? e.getRowCount() : 1,
  18475. t.isArray() ? t.getRowCount() : 1,
  18476. r.isArray() ? r.getRowCount() : 1,
  18477. n.isArray() ? n.getRowCount() : 1,
  18478. u.isArray() ? u.getRowCount() : 1,
  18479. c.isArray() ? c.getRowCount() : 1
  18480. ), f = Math.max(
  18481. e.isArray() ? e.getColumnCount() : 1,
  18482. t.isArray() ? t.getColumnCount() : 1,
  18483. r.isArray() ? r.getColumnCount() : 1,
  18484. n.isArray() ? n.getColumnCount() : 1,
  18485. u.isArray() ? u.getColumnCount() : 1,
  18486. c.isArray() ? c.getColumnCount() : 1
  18487. ), h = O(l, f, e, g.create(m.NA)), d = O(l, f, t, g.create(m.NA)), _ = O(l, f, r, g.create(m.NA)), C = O(l, f, n, g.create(m.NA)), E = O(l, f, u, g.create(m.NA)), b = O(l, f, c, g.create(m.NA)), R = h.map((p, N, M) => {
  18488. const w = d.get(N, M), D = _.get(N, M), S = C.get(N, M), P = E.get(N, M), U = b.get(N, M), { isError: x, errorObject: F, variants: W } = I(p, w, D, S, P, U);
  18489. if (x)
  18490. return F;
  18491. const [ne, z, G, ge, de, Ee] = W, Re = +ne.getValue(), he = +z.getValue(), ke = +G.getValue(), Ot = +ge.getValue(), ar = +de.getValue(), Mt = +Ee.getValue();
  18492. if (he < 1 || Math.floor(he) > Math.ceil(ke) || he - ke >= 1)
  18493. return g.create(m.NUM);
  18494. const st = Gr(Re, ke, Ot, ar, Mt ? 1 : 0) - yu(Re, he, ke, Ot, ar, Mt ? 1 : 0);
  18495. return Number.isNaN(st) || !Number.isFinite(st) ? g.create(m.NUM) : N === 0 && M === 0 ? y.create(st, Ke(this.getLocale())) : y.create(st);
  18496. });
  18497. return l === 1 && f === 1 ? R.get(0, 0) : R;
  18498. }
  18499. }
  18500. class m0 extends V {
  18501. constructor() {
  18502. super(...arguments);
  18503. A(this, "minParams", 6);
  18504. A(this, "maxParams", 7);
  18505. }
  18506. calculate(e, t, r, n, s, o, u) {
  18507. let c = u != null ? u : y.create(0);
  18508. c.isNull() && (c = y.create(0));
  18509. const { isError: l, errorObject: f, variants: h } = Fe(e, t, r, n, s, o, c);
  18510. if (l)
  18511. return f;
  18512. const [d, _, C, E, b, R, p] = h, N = k(d);
  18513. if (typeof N != "number")
  18514. return N;
  18515. const M = k(_);
  18516. if (typeof M != "number")
  18517. return M;
  18518. const w = +C.getValue(), D = +E.getValue(), S = +b.getValue(), P = Math.floor(+R.getValue()), U = Math.floor(+p.getValue());
  18519. if (Number.isNaN(w) || Number.isNaN(D) || Number.isNaN(S) || Number.isNaN(P) || Number.isNaN(U))
  18520. return g.create(m.VALUE);
  18521. if (w < 0 || D < 0 || S <= 0 || ![1, 2, 4].includes(P) || U < 0 || U > 4 || N >= M || !Or(N, M, P))
  18522. return g.create(m.NUM);
  18523. const x = un(N, M, w, D, S, P, U);
  18524. return y.create(x);
  18525. }
  18526. }
  18527. class g0 extends V {
  18528. constructor() {
  18529. super(...arguments);
  18530. A(this, "minParams", 4);
  18531. A(this, "maxParams", 5);
  18532. }
  18533. calculate(e, t, r, n, s) {
  18534. let o = s != null ? s : y.create(0);
  18535. o.isNull() && (o = y.create(0));
  18536. const { isError: u, errorObject: c, variants: l } = Fe(e, t, r, n, o);
  18537. if (u)
  18538. return c;
  18539. const [f, h, d, _, C] = l, E = k(f);
  18540. if (typeof E != "number")
  18541. return E;
  18542. const b = k(h);
  18543. if (typeof b != "number")
  18544. return b;
  18545. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  18546. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  18547. return g.create(m.VALUE);
  18548. if (R <= 0 || p <= 0 || N < 0 || N > 4 || E >= b)
  18549. return g.create(m.NUM);
  18550. const { days: M, yearDays: w } = _e(E, b, N), D = p - R * p * M / w;
  18551. return y.create(D);
  18552. }
  18553. }
  18554. class d0 extends V {
  18555. constructor() {
  18556. super(...arguments);
  18557. A(this, "minParams", 5);
  18558. A(this, "maxParams", 6);
  18559. }
  18560. calculate(e, t, r, n, s, o) {
  18561. let u = o != null ? o : y.create(0);
  18562. u.isNull() && (u = y.create(0));
  18563. const { isError: c, errorObject: l, variants: f } = Fe(e, t, r, n, s, u);
  18564. if (c)
  18565. return l;
  18566. const [h, d, _, C, E, b] = f, R = k(h);
  18567. if (typeof R != "number")
  18568. return R;
  18569. const p = k(d);
  18570. if (typeof p != "number")
  18571. return p;
  18572. const N = k(_);
  18573. if (typeof N != "number")
  18574. return N;
  18575. const M = +C.getValue(), w = +E.getValue(), D = Math.floor(+b.getValue());
  18576. if (Number.isNaN(M) || Number.isNaN(w) || Number.isNaN(D))
  18577. return g.create(m.VALUE);
  18578. const S = this._getDateCorrectOrder(p, R, N);
  18579. if (M < 0 || w < 0 || D < 0 || D > 4 || !S)
  18580. return g.create(m.NUM);
  18581. const P = Au(R, D), { days: U } = _e(R, p, D), { days: x } = _e(N, p, D), { days: F } = _e(N, R, D), W = (100 + x / P * M * 100) / (1 + U / P * w) - F / P * M * 100;
  18582. return y.create(W);
  18583. }
  18584. _getDateCorrectOrder(e, t, r) {
  18585. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r);
  18586. }
  18587. }
  18588. class C0 extends V {
  18589. constructor() {
  18590. super(...arguments);
  18591. A(this, "minParams", 3);
  18592. A(this, "maxParams", 5);
  18593. A(this, "needsLocale", !0);
  18594. }
  18595. calculate(e, t, r, n, s) {
  18596. const o = n != null ? n : y.create(0), u = s != null ? s : y.create(0), c = Math.max(
  18597. e.isArray() ? e.getRowCount() : 1,
  18598. t.isArray() ? t.getRowCount() : 1,
  18599. r.isArray() ? r.getRowCount() : 1,
  18600. o.isArray() ? o.getRowCount() : 1,
  18601. u.isArray() ? u.getRowCount() : 1
  18602. ), l = Math.max(
  18603. e.isArray() ? e.getColumnCount() : 1,
  18604. t.isArray() ? t.getColumnCount() : 1,
  18605. r.isArray() ? r.getColumnCount() : 1,
  18606. o.isArray() ? o.getColumnCount() : 1,
  18607. u.isArray() ? u.getColumnCount() : 1
  18608. ), f = O(c, l, e, g.create(m.NA)), h = O(c, l, t, g.create(m.NA)), d = O(c, l, r, g.create(m.NA)), _ = O(c, l, o, g.create(m.NA)), C = O(c, l, u, g.create(m.NA)), E = f.map((b, R, p) => {
  18609. const N = h.get(R, p), M = d.get(R, p), w = _.get(R, p), D = C.get(R, p), { isError: S, errorObject: P, variants: U } = I(b, N, M, w, D);
  18610. if (S)
  18611. return P;
  18612. const [x, F, W, ne, z] = U, G = +x.getValue(), ge = +F.getValue(), de = +W.getValue(), Ee = +ne.getValue();
  18613. let Re = +z.getValue();
  18614. Re = Re ? 1 : 0;
  18615. const he = G === 0 ? -de * ge - Ee : ((1 - (1 + G) ** ge) / G * de * (1 + G * Re) - Ee) / (1 + G) ** ge;
  18616. return Number.isNaN(he) || !Number.isFinite(he) ? g.create(m.NUM) : R === 0 && p === 0 ? y.create(he, Ke(this.getLocale())) : y.create(he);
  18617. });
  18618. return c === 1 && l === 1 ? E.get(0, 0) : E;
  18619. }
  18620. }
  18621. class _0 extends V {
  18622. constructor() {
  18623. super(...arguments);
  18624. A(this, "minParams", 3);
  18625. A(this, "maxParams", 6);
  18626. }
  18627. calculate(e, t, r, n, s, o) {
  18628. const u = n != null ? n : y.create(0), c = s != null ? s : y.create(0), l = o != null ? o : y.create(0.1), f = Math.max(
  18629. e.isArray() ? e.getRowCount() : 1,
  18630. t.isArray() ? t.getRowCount() : 1,
  18631. r.isArray() ? r.getRowCount() : 1,
  18632. u.isArray() ? u.getRowCount() : 1,
  18633. c.isArray() ? c.getRowCount() : 1,
  18634. l.isArray() ? l.getRowCount() : 1
  18635. ), h = Math.max(
  18636. e.isArray() ? e.getColumnCount() : 1,
  18637. t.isArray() ? t.getColumnCount() : 1,
  18638. r.isArray() ? r.getColumnCount() : 1,
  18639. u.isArray() ? u.getColumnCount() : 1,
  18640. c.isArray() ? c.getColumnCount() : 1,
  18641. l.isArray() ? l.getColumnCount() : 1
  18642. ), d = O(f, h, e, g.create(m.NA)), _ = O(f, h, t, g.create(m.NA)), C = O(f, h, r, g.create(m.NA)), E = O(f, h, u, g.create(m.NA)), b = O(f, h, c, g.create(m.NA)), R = O(f, h, l, g.create(m.NA)), p = d.map((N, M, w) => {
  18643. const D = _.get(M, w), S = C.get(M, w), P = E.get(M, w), U = b.get(M, w), x = R.get(M, w), { isError: F, errorObject: W, variants: ne } = I(N, D, S, P, U, x);
  18644. if (F)
  18645. return W;
  18646. const [z, G, ge, de, Ee, Re] = ne, he = +z.getValue(), ke = +G.getValue(), Ot = +ge.getValue(), ar = +de.getValue();
  18647. let Mt = +Ee.getValue();
  18648. const st = +Re.getValue();
  18649. return Mt = Mt ? 1 : 0, he <= 0 || ke >= 0 ? g.create(m.NUM) : this._getResult(he, ke, Ot, ar, Mt, st, M, w);
  18650. });
  18651. return f === 1 && h === 1 ? p.get(0, 0) : p;
  18652. }
  18653. _getResult(e, t, r, n, s, o, u, c) {
  18654. let h = o;
  18655. for (let d = 0; d < 20; d++) {
  18656. if (h <= -1)
  18657. return g.create(m.NUM);
  18658. let _, C;
  18659. if (Math.abs(h) < 1e-10 ? _ = r * (1 + e * h) + t * (1 + h * s) * e + n : (C = (1 + h) ** e, _ = r * C + t * (1 / h + s) * (C - 1) + n), Math.abs(_) < 1e-10)
  18660. break;
  18661. let E;
  18662. if (Math.abs(h) < 1e-10)
  18663. E = r * e + t * s * e;
  18664. else {
  18665. C = (1 + h) ** e;
  18666. const b = e * (1 + h) ** (e - 1);
  18667. E = r * b + t * (1 / h + s) * b + t * (-1 / (h * h)) * (C - 1);
  18668. }
  18669. h -= _ / E;
  18670. }
  18671. return u === 0 && c === 0 ? y.create(h, "0%") : y.create(h);
  18672. }
  18673. }
  18674. class A0 extends V {
  18675. constructor() {
  18676. super(...arguments);
  18677. A(this, "minParams", 4);
  18678. A(this, "maxParams", 5);
  18679. }
  18680. calculate(e, t, r, n, s) {
  18681. let o = s != null ? s : y.create(0);
  18682. o.isNull() && (o = y.create(0));
  18683. const { isError: u, errorObject: c, variants: l } = Fe(e, t, r, n, o);
  18684. if (u)
  18685. return c;
  18686. const [f, h, d, _, C] = l, E = k(f);
  18687. if (typeof E != "number")
  18688. return E;
  18689. const b = k(h);
  18690. if (typeof b != "number")
  18691. return b;
  18692. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  18693. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  18694. return g.create(m.VALUE);
  18695. if (R <= 0 || p <= 0 || N < 0 || N > 4 || E >= b)
  18696. return g.create(m.NUM);
  18697. const { days: M, yearDays: w } = _e(E, b, N), D = R / (1 - p * M / w);
  18698. return D < 0 ? g.create(m.NUM) : y.create(D);
  18699. }
  18700. }
  18701. class E0 extends V {
  18702. constructor() {
  18703. super(...arguments);
  18704. A(this, "minParams", 3);
  18705. A(this, "maxParams", 6);
  18706. }
  18707. calculate(e, t, r) {
  18708. const n = Math.max(
  18709. e.isArray() ? e.getRowCount() : 1,
  18710. t.isArray() ? t.getRowCount() : 1,
  18711. r.isArray() ? r.getRowCount() : 1
  18712. ), s = Math.max(
  18713. e.isArray() ? e.getColumnCount() : 1,
  18714. t.isArray() ? t.getColumnCount() : 1,
  18715. r.isArray() ? r.getColumnCount() : 1
  18716. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.map((f, h, d) => {
  18717. const _ = u.get(h, d), C = c.get(h, d), { isError: E, errorObject: b, variants: R } = I(f, _, C);
  18718. if (E)
  18719. return b;
  18720. const [p, N, M] = R, w = +p.getValue(), D = +N.getValue(), S = +M.getValue();
  18721. if (w <= 0)
  18722. return g.create(m.NUM);
  18723. if (D === 0 && S === 0)
  18724. return y.create(0);
  18725. const P = (S / D) ** (1 / w) - 1;
  18726. return Number.isNaN(P) || !Number.isFinite(P) || S / D < 0 ? g.create(m.NUM) : y.create(P);
  18727. });
  18728. return n === 1 && s === 1 ? l.get(0, 0) : l;
  18729. }
  18730. }
  18731. class b0 extends V {
  18732. constructor() {
  18733. super(...arguments);
  18734. A(this, "minParams", 3);
  18735. A(this, "maxParams", 3);
  18736. A(this, "needsLocale", !0);
  18737. }
  18738. calculate(e, t, r) {
  18739. const n = Math.max(
  18740. e.isArray() ? e.getRowCount() : 1,
  18741. t.isArray() ? t.getRowCount() : 1,
  18742. r.isArray() ? r.getRowCount() : 1
  18743. ), s = Math.max(
  18744. e.isArray() ? e.getColumnCount() : 1,
  18745. t.isArray() ? t.getColumnCount() : 1,
  18746. r.isArray() ? r.getColumnCount() : 1
  18747. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.map((f, h, d) => {
  18748. const _ = u.get(h, d), C = c.get(h, d);
  18749. if (_.isError())
  18750. return _;
  18751. if (C.isError())
  18752. return C;
  18753. const E = +f.getValue(), b = +_.getValue(), R = +C.getValue();
  18754. if (Number.isNaN(E) || Number.isNaN(b) || Number.isNaN(R))
  18755. return g.create(m.VALUE);
  18756. if (R === 0)
  18757. return g.create(m.DIV_BY_ZERO);
  18758. const p = (E - b) / R;
  18759. return h === 0 && d === 0 ? y.create(p, Ke(this.getLocale())) : y.create(p);
  18760. });
  18761. return n === 1 && s === 1 ? l.get(0, 0) : l;
  18762. }
  18763. }
  18764. class y0 extends V {
  18765. constructor() {
  18766. super(...arguments);
  18767. A(this, "minParams", 4);
  18768. A(this, "maxParams", 4);
  18769. A(this, "needsLocale", !0);
  18770. }
  18771. calculate(e, t, r, n) {
  18772. const s = Math.max(
  18773. e.isArray() ? e.getRowCount() : 1,
  18774. t.isArray() ? t.getRowCount() : 1,
  18775. r.isArray() ? r.getRowCount() : 1,
  18776. n.isArray() ? n.getRowCount() : 1
  18777. ), o = Math.max(
  18778. e.isArray() ? e.getColumnCount() : 1,
  18779. t.isArray() ? t.getColumnCount() : 1,
  18780. r.isArray() ? r.getColumnCount() : 1,
  18781. n.isArray() ? n.getColumnCount() : 1
  18782. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.map((d, _, C) => {
  18783. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  18784. if (E.isError())
  18785. return E;
  18786. if (b.isError())
  18787. return b;
  18788. if (R.isError())
  18789. return R;
  18790. const p = +d.getValue(), N = +E.getValue(), M = +b.getValue(), w = +R.getValue();
  18791. if (Number.isNaN(p) || Number.isNaN(N) || Number.isNaN(M) || Number.isNaN(w))
  18792. return g.create(m.VALUE);
  18793. if (N < 0 || M <= 0 || w > M)
  18794. return g.create(m.NUM);
  18795. const D = (p - N) * (M - w + 1) * 2 / (M * (M + 1));
  18796. return _ === 0 && C === 0 ? y.create(D, Ke(this.getLocale())) : y.create(D);
  18797. });
  18798. return s === 1 && o === 1 ? h.get(0, 0) : h;
  18799. }
  18800. }
  18801. class R0 extends V {
  18802. constructor() {
  18803. super(...arguments);
  18804. A(this, "minParams", 3);
  18805. A(this, "maxParams", 3);
  18806. }
  18807. calculate(e, t, r) {
  18808. const { isError: n, errorObject: s, variants: o } = Fe(e, t, r);
  18809. if (n)
  18810. return s;
  18811. const [u, c, l] = o, f = k(u);
  18812. if (typeof f != "number")
  18813. return f;
  18814. const h = k(c);
  18815. if (typeof h != "number")
  18816. return h;
  18817. const d = +l.getValue();
  18818. if (Number.isNaN(d))
  18819. return g.create(m.VALUE);
  18820. if (d <= 0 || f >= h)
  18821. return g.create(m.NUM);
  18822. const _ = Math.floor(h) - Math.floor(f), E = re(f).getUTCFullYear(), b = Jn(E);
  18823. if (_ > b)
  18824. return g.create(m.NUM);
  18825. let R = 365 * d / (360 - d * _);
  18826. if (_ > 182) {
  18827. const p = 100 * (1 - d * _ / 360), N = _ / 365;
  18828. if (R = (-N + Math.sqrt(N * N - (N * 2 - 1) * (1 - 100 / p))) / (N - 0.5), Number.isNaN(R))
  18829. return g.create(m.NUM);
  18830. }
  18831. return R < 0 ? g.create(m.NUM) : y.create(R);
  18832. }
  18833. }
  18834. class p0 extends V {
  18835. constructor() {
  18836. super(...arguments);
  18837. A(this, "minParams", 3);
  18838. A(this, "maxParams", 3);
  18839. A(this, "needsLocale", !0);
  18840. }
  18841. calculate(e, t, r) {
  18842. const { isError: n, errorObject: s, variants: o } = Fe(e, t, r);
  18843. if (n)
  18844. return s;
  18845. const [u, c, l] = o, f = k(u);
  18846. if (typeof f != "number")
  18847. return f;
  18848. const h = k(c);
  18849. if (typeof h != "number")
  18850. return h;
  18851. const d = +l.getValue();
  18852. if (Number.isNaN(d))
  18853. return g.create(m.VALUE);
  18854. if (d <= 0 || f >= h)
  18855. return g.create(m.NUM);
  18856. const _ = Math.floor(h) - Math.floor(f), E = re(f).getUTCFullYear(), b = Jn(E);
  18857. if (_ > b)
  18858. return g.create(m.NUM);
  18859. const R = 100 * (1 - d * _ / 360);
  18860. return R < 0 ? g.create(m.NUM) : y.create(R, Ke(this.getLocale()));
  18861. }
  18862. }
  18863. class V0 extends V {
  18864. constructor() {
  18865. super(...arguments);
  18866. A(this, "minParams", 3);
  18867. A(this, "maxParams", 3);
  18868. }
  18869. calculate(e, t, r) {
  18870. const { isError: n, errorObject: s, variants: o } = Fe(e, t, r);
  18871. if (n)
  18872. return s;
  18873. const [u, c, l] = o, f = k(u);
  18874. if (typeof f != "number")
  18875. return f;
  18876. const h = k(c);
  18877. if (typeof h != "number")
  18878. return h;
  18879. const d = +l.getValue();
  18880. if (Number.isNaN(d))
  18881. return g.create(m.VALUE);
  18882. if (d <= 0 || f >= h)
  18883. return g.create(m.NUM);
  18884. const _ = Math.floor(h) - Math.floor(f), E = re(f).getUTCFullYear(), b = Jn(E);
  18885. if (_ > b)
  18886. return g.create(m.NUM);
  18887. const R = (100 - d) / d * 360 / _;
  18888. return y.create(R);
  18889. }
  18890. }
  18891. class N0 extends V {
  18892. constructor() {
  18893. super(...arguments);
  18894. A(this, "minParams", 5);
  18895. A(this, "maxParams", 7);
  18896. A(this, "needsLocale", !0);
  18897. }
  18898. calculate(e, t, r, n, s, o, u) {
  18899. let c = o != null ? o : y.create(2);
  18900. c.isNull() && (c = y.create(2));
  18901. let l = u != null ? u : T.create(!1);
  18902. l.isNull() && (l = T.create(!1));
  18903. const f = Math.max(
  18904. e.isArray() ? e.getRowCount() : 1,
  18905. t.isArray() ? t.getRowCount() : 1,
  18906. r.isArray() ? r.getRowCount() : 1,
  18907. n.isArray() ? n.getRowCount() : 1,
  18908. s.isArray() ? s.getRowCount() : 1,
  18909. c.isArray() ? c.getRowCount() : 1,
  18910. l.isArray() ? l.getRowCount() : 1
  18911. ), h = Math.max(
  18912. e.isArray() ? e.getColumnCount() : 1,
  18913. t.isArray() ? t.getColumnCount() : 1,
  18914. r.isArray() ? r.getColumnCount() : 1,
  18915. n.isArray() ? n.getColumnCount() : 1,
  18916. s.isArray() ? s.getColumnCount() : 1,
  18917. c.isArray() ? c.getColumnCount() : 1,
  18918. l.isArray() ? l.getColumnCount() : 1
  18919. ), d = O(f, h, e, g.create(m.NA)), _ = O(f, h, t, g.create(m.NA)), C = O(f, h, r, g.create(m.NA)), E = O(f, h, n, g.create(m.NA)), b = O(f, h, s, g.create(m.NA)), R = O(f, h, c, g.create(m.NA)), p = O(f, h, l, g.create(m.NA));
  18920. return this._getResultArray(
  18921. d,
  18922. _,
  18923. C,
  18924. E,
  18925. b,
  18926. R,
  18927. p,
  18928. f,
  18929. h
  18930. );
  18931. }
  18932. _getResultArray(e, t, r, n, s, o, u, c, l) {
  18933. const f = e.map((h, d, _) => {
  18934. const C = t.get(d, _), E = r.get(d, _), b = n.get(d, _), R = s.get(d, _), p = o.get(d, _), N = u.get(d, _), { isError: M, errorObject: w, variants: D } = I(h, C, E, b, R, p, N);
  18935. if (M)
  18936. return w;
  18937. const [S, P, U, x, F, W, ne] = D, z = +S.getValue(), G = +P.getValue(), ge = +U.getValue(), de = +x.getValue(), Ee = +F.getValue(), Re = +W.getValue(), he = +ne.getValue();
  18938. if (z < 0 || G < 0 || ge < 0 || de < 0 || Ee < 0 || Ee > ge || de > Ee || Re < 0)
  18939. return g.create(m.NUM);
  18940. if (ge === 0 && de === 0 && Ee === 0)
  18941. return g.create(m.DIV_BY_ZERO);
  18942. const ke = this._getResult(z, G, ge, de, Ee, Re, he);
  18943. return d === 0 && _ === 0 ? y.create(ke, Ke(this.getLocale())) : y.create(ke);
  18944. });
  18945. return c === 1 && l === 1 ? f.get(0, 0) : f;
  18946. }
  18947. _getResult(e, t, r, n, s, o, u) {
  18948. const c = Math.floor(n), l = Math.ceil(s);
  18949. let f = 0;
  18950. if (e < t) {
  18951. if (n >= 1 || u)
  18952. return f;
  18953. const h = Math.abs(e - t);
  18954. return f = h * (s - n) > h ? h : h * (s - n), -f;
  18955. }
  18956. if (u)
  18957. for (let h = c + 1; h <= l; h++) {
  18958. let d = zs(e, t, r, h, o);
  18959. h === c + 1 ? d *= Math.min(s, c + 1) - n : h === l && (d *= s + 1 - l), f += d;
  18960. }
  18961. else {
  18962. const h = e - this._getVdb(e, t, r, r, n, o);
  18963. f = this._getVdb(h, t, r, r - n, s - n, o);
  18964. }
  18965. return f;
  18966. }
  18967. _getVdb(e, t, r, n, s, o) {
  18968. const u = Math.ceil(s);
  18969. let c = 0, l = e - t, f = 0, h = 0, d = !1;
  18970. for (let _ = 1; _ <= u; _++) {
  18971. if (d)
  18972. h = f;
  18973. else {
  18974. const C = zs(e, t, r, _, o);
  18975. f = l / (n - (_ - 1)), f > C ? (h = f, d = !0) : (h = C, l -= C);
  18976. }
  18977. _ === u && (h *= s + 1 - u), c += h;
  18978. }
  18979. return c;
  18980. }
  18981. }
  18982. class O0 extends V {
  18983. constructor() {
  18984. super(...arguments);
  18985. A(this, "minParams", 2);
  18986. A(this, "maxParams", 3);
  18987. }
  18988. calculate(e, t, r) {
  18989. if (e.isNull() || t.isNull())
  18990. return g.create(m.NA);
  18991. const { isError: n, errorObejct: s, _values: o, _dates: u } = this._checkErrors(e, t);
  18992. if (n)
  18993. return s;
  18994. let c = r != null ? r : y.create(0.1);
  18995. c.isNull() && (c = y.create(0.1));
  18996. const { isError: l, errorObject: f, variants: h } = H(c);
  18997. if (l)
  18998. return f;
  18999. const [d] = h, _ = +d.getValue();
  19000. if (Number.isNaN(_))
  19001. return g.create(m.VALUE);
  19002. const { positive: C, negative: E } = this._checkValues(o);
  19003. if (!C || !E || (o == null ? void 0 : o.length) !== (u == null ? void 0 : u.length) || _ < 0)
  19004. return g.create(m.NUM);
  19005. const b = Ia(_, (R) => this._iterF(o, u, R));
  19006. return typeof b != "number" ? b : y.create(b);
  19007. }
  19008. _checkErrors(e, t) {
  19009. if (e.isError())
  19010. return {
  19011. isError: !0,
  19012. errorObejct: e
  19013. };
  19014. if (t.isError())
  19015. return {
  19016. isError: !0,
  19017. errorObejct: t
  19018. };
  19019. const { isError: r, errorObejct: n, _values: s } = this._checkErrorValues(e);
  19020. if (r)
  19021. return {
  19022. isError: r,
  19023. errorObejct: n
  19024. };
  19025. const { isError: o, errorObejct: u, _dates: c } = this._checkErrorDates(t);
  19026. return o ? {
  19027. isError: o,
  19028. errorObejct: u
  19029. } : {
  19030. isError: !1,
  19031. _values: s,
  19032. _dates: c
  19033. };
  19034. }
  19035. _checkErrorValues(e) {
  19036. const t = [];
  19037. if (e.isArray()) {
  19038. let r = !1, n = g.create(m.VALUE);
  19039. return e.iterator((s) => {
  19040. const o = s;
  19041. if (o.isError())
  19042. return r = !0, n = o, !1;
  19043. if (o.isBoolean())
  19044. return r = !0, n = g.create(m.VALUE), !1;
  19045. const u = +o.getValue();
  19046. if (Number.isNaN(u))
  19047. return r = !0, n = g.create(m.VALUE), !1;
  19048. t.push(u);
  19049. }), r ? {
  19050. isError: r,
  19051. errorObejct: n
  19052. } : t.length <= 1 ? {
  19053. isError: !0,
  19054. errorObejct: g.create(m.NA)
  19055. } : {
  19056. isError: r,
  19057. _values: t
  19058. };
  19059. } else {
  19060. const r = e.getValue();
  19061. return e.isBoolean() || e.isString() && !Q(r) ? {
  19062. isError: !0,
  19063. errorObejct: g.create(m.VALUE)
  19064. } : {
  19065. isError: !0,
  19066. errorObejct: g.create(m.NA)
  19067. };
  19068. }
  19069. }
  19070. _checkErrorDates(e) {
  19071. const t = [];
  19072. if (e.isArray()) {
  19073. let r = !1, n = g.create(m.VALUE);
  19074. return e.iterator((s) => {
  19075. if (s != null && s.isError())
  19076. return r = !0, n = s, !1;
  19077. if (s != null && s.isBoolean())
  19078. return r = !0, n = g.create(m.VALUE), !1;
  19079. const o = +s.getValue();
  19080. if (Number.isNaN(o))
  19081. return r = !0, n = g.create(m.VALUE), !1;
  19082. if (o < 0)
  19083. return r = !0, n = g.create(m.NUM), !1;
  19084. t.push(Math.floor(o));
  19085. }), r ? {
  19086. isError: r,
  19087. errorObejct: n
  19088. } : t.length <= 1 ? {
  19089. isError: !0,
  19090. errorObejct: g.create(m.NA)
  19091. } : {
  19092. isError: r,
  19093. _dates: t
  19094. };
  19095. } else {
  19096. const r = e.getValue();
  19097. return e.isBoolean() || e.isString() && !Q(r) ? {
  19098. isError: !0,
  19099. errorObejct: g.create(m.VALUE)
  19100. } : +r < 0 ? {
  19101. isError: !0,
  19102. errorObejct: g.create(m.NUM)
  19103. } : {
  19104. isError: !0,
  19105. errorObejct: g.create(m.NA)
  19106. };
  19107. }
  19108. }
  19109. _checkValues(e) {
  19110. let t = !1, r = !1;
  19111. for (let n = 0; n < e.length; n++)
  19112. e[n] > 0 && (t = !0), e[n] < 0 && (r = !0);
  19113. return {
  19114. positive: t,
  19115. negative: r
  19116. };
  19117. }
  19118. _iterF(e, t, r) {
  19119. return e.reduce((n, s, o) => n + s / (1 + r) ** ((t[o] - t[0]) / 365), 0);
  19120. }
  19121. }
  19122. class M0 extends V {
  19123. constructor() {
  19124. super(...arguments);
  19125. A(this, "minParams", 3);
  19126. A(this, "maxParams", 3);
  19127. }
  19128. calculate(e, t, r) {
  19129. if (e.isNull() || t.isNull() || r.isNull())
  19130. return g.create(m.NA);
  19131. const { isError: n, errorObject: s, variants: o } = H(e);
  19132. if (n)
  19133. return s;
  19134. const [u] = o, c = +u.getValue();
  19135. if (Number.isNaN(c))
  19136. return g.create(m.VALUE);
  19137. let { isError: l, errorObejct: f, _values: h, _dates: d } = this._checkErrors(t, r);
  19138. if (l)
  19139. return f;
  19140. if (h = h, d = d, c < 0 || h.length !== d.length)
  19141. return g.create(m.NUM);
  19142. let _ = 0;
  19143. const C = d[0];
  19144. for (let E = 0; E < d.length; E++) {
  19145. const b = d[E], R = h[E];
  19146. _ += R / (1 + c) ** ((b - C) / 365);
  19147. }
  19148. return y.create(_);
  19149. }
  19150. _checkErrors(e, t) {
  19151. if (e.isError())
  19152. return {
  19153. isError: !0,
  19154. errorObejct: e
  19155. };
  19156. if (t.isError())
  19157. return {
  19158. isError: !0,
  19159. errorObejct: t
  19160. };
  19161. const { isError: r, errorObejct: n, _values: s } = this._checkErrorValues(e);
  19162. if (r)
  19163. return {
  19164. isError: r,
  19165. errorObejct: n
  19166. };
  19167. const { isError: o, errorObejct: u, _dates: c } = this._checkErrorDates(t);
  19168. return o ? {
  19169. isError: o,
  19170. errorObejct: u
  19171. } : {
  19172. isError: !1,
  19173. _values: s,
  19174. _dates: c
  19175. };
  19176. }
  19177. _checkErrorValues(e) {
  19178. const t = [];
  19179. if (e.isArray()) {
  19180. let r = !1, n = g.create(m.VALUE);
  19181. return e.iterator((s) => {
  19182. const o = s;
  19183. if (o.isError())
  19184. return r = !0, n = o, !1;
  19185. if (o.isNull() || o.isBoolean())
  19186. return r = !0, n = g.create(m.VALUE), !1;
  19187. const u = +o.getValue();
  19188. if (Number.isNaN(u))
  19189. return r = !0, n = g.create(m.VALUE), !1;
  19190. t.push(u);
  19191. }), r ? {
  19192. isError: r,
  19193. errorObejct: n
  19194. } : t.length <= 1 ? {
  19195. isError: !0,
  19196. errorObejct: g.create(m.NA)
  19197. } : {
  19198. isError: r,
  19199. _values: t
  19200. };
  19201. } else {
  19202. const r = e.getValue();
  19203. return e.isNull() || e.isBoolean() || e.isString() && !Q(r) ? {
  19204. isError: !0,
  19205. errorObejct: g.create(m.VALUE)
  19206. } : {
  19207. isError: !0,
  19208. errorObejct: g.create(m.NA)
  19209. };
  19210. }
  19211. }
  19212. _checkErrorDates(e) {
  19213. const t = [];
  19214. if (e.isArray()) {
  19215. let r = !1, n = g.create(m.VALUE);
  19216. return e.iterator((s) => {
  19217. const o = s;
  19218. if (o.isError())
  19219. return r = !0, n = o, !1;
  19220. if (o.isNull() || o.isBoolean())
  19221. return r = !0, n = g.create(m.VALUE), !1;
  19222. const u = +o.getValue();
  19223. if (Number.isNaN(u))
  19224. return r = !0, n = g.create(m.VALUE), !1;
  19225. if (u < 0)
  19226. return r = !0, n = g.create(m.NUM), !1;
  19227. t.push(Math.floor(u));
  19228. }), r ? {
  19229. isError: r,
  19230. errorObejct: n
  19231. } : t.length <= 1 ? {
  19232. isError: !0,
  19233. errorObejct: g.create(m.NA)
  19234. } : {
  19235. isError: r,
  19236. _dates: t
  19237. };
  19238. } else {
  19239. const r = e.getValue();
  19240. return e.isNull() || e.isBoolean() || e.isString() && !Q(r) ? {
  19241. isError: !0,
  19242. errorObejct: g.create(m.VALUE)
  19243. } : +r < 0 ? {
  19244. isError: !0,
  19245. errorObejct: g.create(m.NUM)
  19246. } : {
  19247. isError: !0,
  19248. errorObejct: g.create(m.NA)
  19249. };
  19250. }
  19251. }
  19252. }
  19253. class w0 extends V {
  19254. constructor() {
  19255. super(...arguments);
  19256. A(this, "minParams", 6);
  19257. A(this, "maxParams", 7);
  19258. }
  19259. calculate(e, t, r, n, s, o, u) {
  19260. let c = u != null ? u : y.create(0);
  19261. c.isNull() && (c = y.create(0));
  19262. const { isError: l, errorObject: f, variants: h } = Fe(e, t, r, n, s, o, c);
  19263. if (l)
  19264. return f;
  19265. const [d, _, C, E, b, R, p] = h, N = k(d);
  19266. if (typeof N != "number")
  19267. return N;
  19268. const M = k(_);
  19269. if (typeof M != "number")
  19270. return M;
  19271. const w = +C.getValue(), D = +E.getValue(), S = +b.getValue(), P = Math.floor(+R.getValue()), U = Math.floor(+p.getValue());
  19272. if (Number.isNaN(w) || Number.isNaN(D) || Number.isNaN(S) || Number.isNaN(P) || Number.isNaN(U))
  19273. return g.create(m.VALUE);
  19274. if (w < 0 || D <= 0 || S <= 0 || ![1, 2, 4].includes(P) || U < 0 || U > 4 || N >= M || !Or(N, M, P))
  19275. return g.create(m.NUM);
  19276. const x = this._getResult(N, M, w, D, S, P, U);
  19277. return y.create(x);
  19278. }
  19279. _getResult(e, t, r, n, s, o, u) {
  19280. if (nr(e, t, o) > 1) {
  19281. let E = r || 0.01, b = un(e, t, r, E, s, o, u), R = b - n;
  19282. for (let p = 0; p < 100 && Math.abs(R) > 1e-7; p++)
  19283. b = un(e, t, r, 1.01 * E, s, o, u), E += -R / (b - n - R) * E * 0.01, R = un(e, t, r, E, s, o, u) - n;
  19284. return E;
  19285. }
  19286. const l = es(e, t, o, u), f = qe(e, t, o, u), { days: h } = _e(e, t, u), d = n / 100 + l / f * r / o;
  19287. return (s / 100 + r / o - d) / d * o * f / h;
  19288. }
  19289. }
  19290. class D0 extends V {
  19291. constructor() {
  19292. super(...arguments);
  19293. A(this, "minParams", 4);
  19294. A(this, "maxParams", 5);
  19295. }
  19296. calculate(e, t, r, n, s) {
  19297. let o = s != null ? s : y.create(0);
  19298. o.isNull() && (o = y.create(0));
  19299. const { isError: u, errorObject: c, variants: l } = Fe(e, t, r, n, o);
  19300. if (u)
  19301. return c;
  19302. const [f, h, d, _, C] = l, E = k(f);
  19303. if (typeof E != "number")
  19304. return E;
  19305. const b = k(h);
  19306. if (typeof b != "number")
  19307. return b;
  19308. const R = +d.getValue(), p = +_.getValue(), N = Math.floor(+C.getValue());
  19309. if (Number.isNaN(R) || Number.isNaN(p) || Number.isNaN(N))
  19310. return g.create(m.VALUE);
  19311. if (R <= 0 || p <= 0 || N < 0 || N > 4 || E >= b)
  19312. return g.create(m.NUM);
  19313. const { days: M, yearDays: w } = _e(E, b, N), D = (p / R - 1) / (M / w);
  19314. return y.create(D);
  19315. }
  19316. }
  19317. class S0 extends V {
  19318. constructor() {
  19319. super(...arguments);
  19320. A(this, "minParams", 5);
  19321. A(this, "maxParams", 6);
  19322. }
  19323. calculate(e, t, r, n, s, o) {
  19324. let u = o != null ? o : y.create(0);
  19325. u.isNull() && (u = y.create(0));
  19326. const { isError: c, errorObject: l, variants: f } = Fe(e, t, r, n, s, u);
  19327. if (c)
  19328. return l;
  19329. const [h, d, _, C, E, b] = f, R = k(h);
  19330. if (typeof R != "number")
  19331. return R;
  19332. const p = k(d);
  19333. if (typeof p != "number")
  19334. return p;
  19335. const N = k(_);
  19336. if (typeof N != "number")
  19337. return N;
  19338. const M = +C.getValue(), w = +E.getValue(), D = Math.floor(+b.getValue());
  19339. if (Number.isNaN(M) || Number.isNaN(w) || Number.isNaN(D))
  19340. return g.create(m.VALUE);
  19341. const S = this._getDateCorrectOrder(p, R, N);
  19342. if (M < 0 || w <= 0 || D < 0 || D > 4 || !S)
  19343. return g.create(m.NUM);
  19344. const P = Au(R, D), { days: U } = _e(R, p, D), { days: x } = _e(N, p, D), { days: F } = _e(N, R, D), W = ((1 + x / P * M) / (w / 100 + F / P * M) - 1) / (U / P);
  19345. return y.create(W);
  19346. }
  19347. _getDateCorrectOrder(e, t, r) {
  19348. return Math.floor(e) > Math.floor(t) && Math.floor(t) > Math.floor(r);
  19349. }
  19350. }
  19351. const P0 = [
  19352. [P1, ee.ACCRINT],
  19353. [L1, ee.ACCRINTM],
  19354. [x1, ee.AMORLINC],
  19355. [j1, ee.COUPDAYBS],
  19356. [U1, ee.COUPDAYS],
  19357. [v1, ee.COUPDAYSNC],
  19358. [T1, ee.COUPNCD],
  19359. [B1, ee.COUPNUM],
  19360. [I1, ee.COUPPCD],
  19361. [F1, ee.CUMIPMT],
  19362. [k1, ee.CUMPRINC],
  19363. [$1, ee.DB],
  19364. [Y1, ee.DDB],
  19365. [H1, ee.DISC],
  19366. [G1, ee.DOLLARDE],
  19367. [Q1, ee.DOLLARFR],
  19368. [W1, ee.DURATION],
  19369. [q1, ee.EFFECT],
  19370. [K1, ee.FV],
  19371. [X1, ee.FVSCHEDULE],
  19372. [Z1, ee.INTRATE],
  19373. [z1, ee.IPMT],
  19374. [J1, ee.IRR],
  19375. [e0, ee.ISPMT],
  19376. [t0, ee.MDURATION],
  19377. [r0, ee.MIRR],
  19378. [n0, ee.NOMINAL],
  19379. [s0, ee.NPER],
  19380. [a0, ee.NPV],
  19381. [i0, ee.ODDFPRICE],
  19382. [o0, ee.ODDFYIELD],
  19383. [u0, ee.ODDLPRICE],
  19384. [c0, ee.ODDLYIELD],
  19385. [l0, ee.PDURATION],
  19386. [f0, ee.PMT],
  19387. [h0, ee.PPMT],
  19388. [m0, ee.PRICE],
  19389. [g0, ee.PRICEDISC],
  19390. [d0, ee.PRICEMAT],
  19391. [C0, ee.PV],
  19392. [_0, ee.RATE],
  19393. [A0, ee.RECEIVED],
  19394. [E0, ee.RRI],
  19395. [b0, ee.SLN],
  19396. [y0, ee.SYD],
  19397. [R0, ee.TBILLEQ],
  19398. [p0, ee.TBILLPRICE],
  19399. [V0, ee.TBILLYIELD],
  19400. [N0, ee.VDB],
  19401. [O0, ee.XIRR],
  19402. [M0, ee.XNPV],
  19403. [w0, ee.YIELD],
  19404. [D0, ee.YIELDDISC],
  19405. [S0, ee.YIELDMAT]
  19406. ];
  19407. class L0 extends V {
  19408. constructor() {
  19409. super(...arguments);
  19410. A(this, "needsReferenceObject", !0);
  19411. A(this, "minParams", 2);
  19412. A(this, "maxParams", 2);
  19413. }
  19414. calculate(e, t) {
  19415. let r = e;
  19416. if (r.isError())
  19417. return r;
  19418. if (r.isReferenceObject() && (r = r.toArrayValueObject()), r.isArray()) {
  19419. const n = r.getRowCount(), s = r.getColumnCount();
  19420. if (n === 1 && s === 1) {
  19421. const o = r.get(0, 0);
  19422. return this._handleSingleObject(o, t);
  19423. }
  19424. return r.map((o) => o.isError() ? o : this._handleSingleObject(o, t, !0));
  19425. }
  19426. return this._handleSingleObject(r, t);
  19427. }
  19428. _handleSingleObject(e, t, r = !1) {
  19429. let n = t;
  19430. if (n.isError())
  19431. return n;
  19432. if (!n.isReferenceObject())
  19433. return g.create(m.NA);
  19434. const s = n.getCurrentActiveSheetData(), { columnData: o, defaultColumnWidth: u } = s;
  19435. n = n.toArrayValueObject();
  19436. const c = n.getCurrentRow(), l = n.getCurrentColumn();
  19437. n = n.getFirstCell();
  19438. const f = `${e.getValue()}`;
  19439. let h;
  19440. switch (f.toLocaleLowerCase()) {
  19441. case "address":
  19442. return j.create(`$${Xe.chatAtABC(l)}$${c + 1}`);
  19443. case "col":
  19444. return y.create(l + 1);
  19445. case "color":
  19446. return y.create(0);
  19447. case "contents":
  19448. return n;
  19449. case "filename":
  19450. return g.create(m.VALUE);
  19451. case "format":
  19452. return j.create("G");
  19453. case "parentheses":
  19454. return y.create(0);
  19455. case "prefix":
  19456. return j.create("");
  19457. case "protect":
  19458. return y.create(1);
  19459. case "row":
  19460. return y.create(c + 1);
  19461. case "type":
  19462. return h = "v", n.isNull() && (h = "b"), n.isString() && (h = "l"), j.create(h);
  19463. case "width":
  19464. return this._getWidthResult(o, u, l, r);
  19465. default:
  19466. return g.create(m.VALUE);
  19467. }
  19468. }
  19469. _getWidthResult(e, t, r, n) {
  19470. var u;
  19471. let s = (u = e[r]) == null ? void 0 : u.w;
  19472. if (!s && s !== 0 && (s = t), n)
  19473. return y.create(s);
  19474. const o = [[s, s === t]];
  19475. return q.createByArray(o);
  19476. }
  19477. }
  19478. class x0 extends V {
  19479. constructor() {
  19480. super(...arguments);
  19481. A(this, "minParams", 1);
  19482. A(this, "maxParams", 1);
  19483. A(this, "_errorTypeValueMap", /* @__PURE__ */ new Map([
  19484. [m.NULL, 1],
  19485. [m.DIV_BY_ZERO, 2],
  19486. [m.VALUE, 3],
  19487. [m.REF, 4],
  19488. [m.NAME, 5],
  19489. [m.NUM, 6],
  19490. [m.NA, 7],
  19491. [m.CONNECT, 8],
  19492. [m.CALC, 14]
  19493. ]));
  19494. }
  19495. calculate(e) {
  19496. return e.isArray() ? e.mapValue((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  19497. }
  19498. _handleSingleObject(e) {
  19499. const t = e.getValue(), r = this._errorTypeValueMap.get(t);
  19500. return r ? y.create(r) : g.create(m.NA);
  19501. }
  19502. }
  19503. var Ne = /* @__PURE__ */ ((i) => (i.CELL = "CELL", i.ERROR_TYPE = "ERROR.TYPE", i.INFO = "INFO", i.ISBETWEEN = "ISBETWEEN", i.ISBLANK = "ISBLANK", i.ISDATE = "ISDATE", i.ISEMAIL = "ISEMAIL", i.ISERR = "ISERR", i.ISERROR = "ISERROR", i.ISEVEN = "ISEVEN", i.ISFORMULA = "ISFORMULA", i.ISLOGICAL = "ISLOGICAL", i.ISNA = "ISNA", i.ISNONTEXT = "ISNONTEXT", i.ISNUMBER = "ISNUMBER", i.ISODD = "ISODD", i.ISOMITTED = "ISOMITTED", i.ISREF = "ISREF", i.ISTEXT = "ISTEXT", i.ISURL = "ISURL", i.N = "N", i.NA = "NA", i.SHEET = "SHEET", i.SHEETS = "SHEETS", i.TYPE = "TYPE", i))(Ne || {});
  19504. class j0 extends V {
  19505. constructor() {
  19506. super(...arguments);
  19507. A(this, "minParams", 3);
  19508. A(this, "maxParams", 5);
  19509. }
  19510. calculate(e, t, r, n, s) {
  19511. const o = n != null ? n : T.create(!0), u = s != null ? s : T.create(!0), { isError: c, errorObject: l, variants: f } = Fr(e, t, r, o, u);
  19512. if (c)
  19513. return l;
  19514. const [h, d, _, C, E] = f;
  19515. if (C.isString() || E.isString())
  19516. return g.create(m.VALUE);
  19517. if (d.compare(_, ">").getValue() === !0)
  19518. return g.create(m.NUM);
  19519. const R = +C.getValue(), p = +E.getValue(), N = R ? ">=" : ">", M = p ? "<=" : "<";
  19520. return h.compare(d, N).getValue() === !1 || h.compare(_, M).getValue() === !1 ? T.create(!1) : T.create(!0);
  19521. }
  19522. }
  19523. class U0 extends V {
  19524. constructor() {
  19525. super(...arguments);
  19526. A(this, "minParams", 1);
  19527. A(this, "maxParams", 1);
  19528. }
  19529. calculate(e) {
  19530. return e.isNull() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isNull() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19531. }
  19532. }
  19533. class v0 extends V {
  19534. constructor() {
  19535. super(...arguments);
  19536. A(this, "minParams", 1);
  19537. A(this, "maxParams", 1);
  19538. }
  19539. calculate(e) {
  19540. let t = e;
  19541. if (t.isArray()) {
  19542. const r = t.getRowCount(), n = t.getColumnCount();
  19543. if (r > 1 || n > 1)
  19544. return g.create(m.VALUE);
  19545. t = t.get(0, 0);
  19546. }
  19547. return t.isError() ? t : t.isNumber() && t.getPattern() !== "" ? T.create(Ba(t.getPattern())) : t.isString() && (Xs(`${t.getValue()}`) || Zs(`${t.getValue()}`)) ? T.create(!0) : T.create(!1);
  19548. }
  19549. }
  19550. class T0 extends V {
  19551. constructor() {
  19552. super(...arguments);
  19553. A(this, "minParams", 1);
  19554. A(this, "maxParams", 1);
  19555. }
  19556. calculate(e) {
  19557. let t = e;
  19558. if (t.isArray()) {
  19559. const o = t.getRowCount(), u = t.getColumnCount();
  19560. if (o > 1 || u > 1)
  19561. return g.create(m.VALUE);
  19562. t = t.get(0, 0);
  19563. }
  19564. if (t.isError())
  19565. return t;
  19566. if (t.isNull() || t.isBoolean() || t.isNumber())
  19567. return T.create(!1);
  19568. const r = `${t.getValue()}`;
  19569. if (r.length > 254)
  19570. return T.create(!1);
  19571. const n = Xe.topLevelDomainCombiningString(), s = new RegExp(
  19572. `^(?:[\\w+-]+\\.)*[\\w+-]+@[a-z0-9_-]+(?:\\.[a-z0-9_-]+)*\\.(?:${n})$`,
  19573. "i"
  19574. );
  19575. return T.create(s.test(r));
  19576. }
  19577. }
  19578. class B0 extends V {
  19579. constructor() {
  19580. super(...arguments);
  19581. A(this, "minParams", 1);
  19582. A(this, "maxParams", 1);
  19583. }
  19584. calculate(e) {
  19585. return e.getValue() === m.NA ? T.create(!1) : e.isError() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.getValue() === m.NA ? T.create(!1) : t.isError() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19586. }
  19587. }
  19588. class I0 extends V {
  19589. constructor() {
  19590. super(...arguments);
  19591. A(this, "minParams", 1);
  19592. A(this, "maxParams", 1);
  19593. }
  19594. calculate(e) {
  19595. return e.isError() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isError() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19596. }
  19597. }
  19598. class F0 extends V {
  19599. constructor() {
  19600. super(...arguments);
  19601. A(this, "minParams", 1);
  19602. A(this, "maxParams", 1);
  19603. }
  19604. calculate(e) {
  19605. let t = e;
  19606. if (t.isArray()) {
  19607. const s = t.getRowCount(), o = t.getColumnCount();
  19608. if (s > 1 || o > 1)
  19609. return g.create(m.VALUE);
  19610. t = t.get(0, 0);
  19611. }
  19612. if (t.isError())
  19613. return t;
  19614. if (t.isBoolean())
  19615. return g.create(m.VALUE);
  19616. const r = Math.trunc(+t.getValue());
  19617. if (Number.isNaN(r))
  19618. return g.create(m.VALUE);
  19619. const n = r % 2 === 0;
  19620. return T.create(n);
  19621. }
  19622. }
  19623. class k0 extends V {
  19624. constructor() {
  19625. super(...arguments);
  19626. A(this, "minParams", 1);
  19627. A(this, "maxParams", 1);
  19628. A(this, "needsReferenceObject", !0);
  19629. }
  19630. calculate(e) {
  19631. var u;
  19632. if (e.isError())
  19633. return e;
  19634. if (!e.isReferenceObject())
  19635. return g.create(m.NA);
  19636. const t = (u = e.getCurrentActiveSheetData()) == null ? void 0 : u.cellData.getMatrix(), { startRow: r, startColumn: n } = e.getRangePosition(), s = e.toArrayValueObject(), o = s.mapValue((c, l, f) => {
  19637. var d;
  19638. const h = (d = t == null ? void 0 : t[r + l]) == null ? void 0 : d[n + f];
  19639. return h != null && h.f || h != null && h.si ? T.create(!0) : T.create(!1);
  19640. });
  19641. return s.getRowCount() === 1 && s.getColumnCount() === 1 ? o.get(0, 0) : o;
  19642. }
  19643. }
  19644. class $0 extends V {
  19645. constructor() {
  19646. super(...arguments);
  19647. A(this, "minParams", 1);
  19648. A(this, "maxParams", 1);
  19649. }
  19650. calculate(e) {
  19651. return e.isBoolean() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isBoolean() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19652. }
  19653. }
  19654. class Y0 extends V {
  19655. constructor() {
  19656. super(...arguments);
  19657. A(this, "minParams", 1);
  19658. A(this, "maxParams", 1);
  19659. }
  19660. calculate(e) {
  19661. return e.getValue() === m.NA ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.getValue() === m.NA ? T.create(!0) : T.create(!1)) : T.create(!1);
  19662. }
  19663. }
  19664. class H0 extends V {
  19665. constructor() {
  19666. super(...arguments);
  19667. A(this, "minParams", 1);
  19668. A(this, "maxParams", 1);
  19669. }
  19670. calculate(e) {
  19671. return !e.isArray() && !e.isString() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isString() ? T.create(!1) : T.create(!0)) : T.create(!1);
  19672. }
  19673. }
  19674. class G0 extends V {
  19675. constructor() {
  19676. super(...arguments);
  19677. A(this, "minParams", 1);
  19678. A(this, "maxParams", 1);
  19679. }
  19680. calculate(e) {
  19681. return e.isNumber() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isNumber() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19682. }
  19683. }
  19684. class Q0 extends V {
  19685. constructor() {
  19686. super(...arguments);
  19687. A(this, "minParams", 1);
  19688. A(this, "maxParams", 1);
  19689. }
  19690. calculate(e) {
  19691. let t = e;
  19692. if (t.isArray()) {
  19693. const s = t.getRowCount(), o = t.getColumnCount();
  19694. if (s > 1 || o > 1)
  19695. return g.create(m.VALUE);
  19696. t = t.get(0, 0);
  19697. }
  19698. if (t.isError())
  19699. return t;
  19700. if (t.isBoolean())
  19701. return g.create(m.VALUE);
  19702. const r = Math.trunc(+t.getValue());
  19703. if (Number.isNaN(r))
  19704. return g.create(m.VALUE);
  19705. const n = r % 2 !== 0;
  19706. return T.create(n);
  19707. }
  19708. }
  19709. class W0 extends V {
  19710. constructor() {
  19711. super(...arguments);
  19712. A(this, "minParams", 1);
  19713. A(this, "maxParams", 1);
  19714. A(this, "needsReferenceObject", !0);
  19715. }
  19716. calculate(e) {
  19717. return e.isReferenceObject() ? T.create(!0) : T.create(!1);
  19718. }
  19719. }
  19720. class q0 extends V {
  19721. constructor() {
  19722. super(...arguments);
  19723. A(this, "minParams", 1);
  19724. A(this, "maxParams", 1);
  19725. }
  19726. calculate(e) {
  19727. return e.isString() ? T.create(!0) : e.isArray() ? e.mapValue((t) => t.isString() ? T.create(!0) : T.create(!1)) : T.create(!1);
  19728. }
  19729. }
  19730. class K0 extends V {
  19731. constructor() {
  19732. super(...arguments);
  19733. A(this, "minParams", 1);
  19734. A(this, "maxParams", 1);
  19735. }
  19736. calculate(e) {
  19737. let t = e;
  19738. if (t.isArray()) {
  19739. const o = t.getRowCount(), u = t.getColumnCount();
  19740. if (o > 1 || u > 1)
  19741. return g.create(m.VALUE);
  19742. t = t.get(0, 0);
  19743. }
  19744. if (t.isError())
  19745. return t;
  19746. if (t.isNull() || t.isBoolean() || t.isNumber())
  19747. return T.create(!1);
  19748. const r = `${t.getValue()}`.replace(/^\s+|\s+$/g, "");
  19749. if (r.length > 1e3)
  19750. return T.create(!1);
  19751. const n = Xe.topLevelDomainCombiningString(), s = new RegExp(
  19752. `^(?:(?:https?|s?ftp|ftps|nfs|ssh)://+[a-z0-9_-]+(?:\\.[a-z0-9_-]+)*(?::[0-9]+)?(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[A-Fa-f0-9]{2})*)*/?(?:[?#]\\S*)?|[a-z0-9_-]+(?:\\.[a-z0-9_-]+)*\\.(?:${n})(?::[0-9]+)?(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[A-Fa-f0-9]{2})*)*/?(?:[?#]\\S*)?|mailto:(?:[\\w+-]+\\.)*[\\w+-]+@[a-z0-9_-]+(?:\\.[a-z0-9_-]+)*\\.(?:${n})|(?:news|aim):[%a-z0-9$_\\.+!*(),;/?#:@&~=-]+)$`,
  19753. "i"
  19754. );
  19755. return T.create(s.test(r));
  19756. }
  19757. }
  19758. class X0 extends V {
  19759. constructor() {
  19760. super(...arguments);
  19761. A(this, "minParams", 1);
  19762. A(this, "maxParams", 1);
  19763. }
  19764. calculate(e) {
  19765. let t = e;
  19766. if (e.isArray() && (t = e.get(0, 0)), t.isError())
  19767. return t;
  19768. if (t.isString())
  19769. return y.create(0);
  19770. const r = +t.getValue();
  19771. return y.create(r);
  19772. }
  19773. }
  19774. class Z0 extends V {
  19775. constructor() {
  19776. super(...arguments);
  19777. A(this, "minParams", 0);
  19778. A(this, "maxParams", 0);
  19779. }
  19780. calculate() {
  19781. return g.create(m.NA);
  19782. }
  19783. }
  19784. class z0 extends V {
  19785. constructor() {
  19786. super(...arguments);
  19787. A(this, "minParams", 0);
  19788. A(this, "maxParams", 1);
  19789. A(this, "needsReferenceObject", !0);
  19790. A(this, "needsSheetsInfo", !0);
  19791. }
  19792. calculate(e) {
  19793. var u;
  19794. if (e != null && e.isError())
  19795. return e;
  19796. const { sheetOrder: t, sheetNameMap: r } = this.getSheetsInfo();
  19797. if (!e) {
  19798. const c = t.findIndex((l) => l === this.subUnitId);
  19799. return y.create(c + 1);
  19800. }
  19801. if (e.isReferenceObject()) {
  19802. const c = e.getForcedSheetId(), l = e.getDefaultSheetId(), f = t.findIndex((h) => c ? h === c : h === l);
  19803. return y.create(f + 1);
  19804. }
  19805. if (e.isArray())
  19806. return g.create(m.NA);
  19807. const n = `${e.getValue()}`.toLocaleLowerCase(), s = (u = Object.entries(r).find(([c, l]) => l.toLocaleLowerCase() === n)) == null ? void 0 : u[0];
  19808. if (!s)
  19809. return g.create(m.NA);
  19810. const o = t.findIndex((c) => c === s);
  19811. return y.create(o + 1);
  19812. }
  19813. }
  19814. class J0 extends V {
  19815. constructor() {
  19816. super(...arguments);
  19817. A(this, "minParams", 0);
  19818. A(this, "maxParams", 0);
  19819. A(this, "needsSheetsInfo", !0);
  19820. }
  19821. calculate() {
  19822. const { sheetOrder: e } = this.getSheetsInfo();
  19823. return y.create(e.length);
  19824. }
  19825. }
  19826. class ed extends V {
  19827. constructor() {
  19828. super(...arguments);
  19829. A(this, "needsReferenceObject", !0);
  19830. A(this, "minParams", 1);
  19831. A(this, "maxParams", 1);
  19832. }
  19833. calculate(e) {
  19834. if (e.isReferenceObject()) {
  19835. const t = e.getRowCount(), r = e.getColumnCount();
  19836. if (t === 1 && r === 1) {
  19837. const n = e.getFirstCell();
  19838. if (n.isError())
  19839. return y.create(16);
  19840. if (n.isBoolean())
  19841. return y.create(4);
  19842. if (n.isString())
  19843. return y.create(2);
  19844. if (n.isNumber() || n.isNull())
  19845. return y.create(1);
  19846. } else
  19847. return y.create(64);
  19848. } else {
  19849. if (e.isArray())
  19850. return y.create(64);
  19851. if (e.isError())
  19852. return y.create(16);
  19853. if (e.isBoolean())
  19854. return y.create(4);
  19855. if (e.isString())
  19856. return y.create(2);
  19857. if (e.isNumber() || e.isNull())
  19858. return y.create(1);
  19859. }
  19860. return y.create(128);
  19861. }
  19862. }
  19863. const td = [
  19864. [L0, Ne.CELL],
  19865. [x0, Ne.ERROR_TYPE],
  19866. [j0, Ne.ISBETWEEN],
  19867. [U0, Ne.ISBLANK],
  19868. [v0, Ne.ISDATE],
  19869. [T0, Ne.ISEMAIL],
  19870. [B0, Ne.ISERR],
  19871. [I0, Ne.ISERROR],
  19872. [F0, Ne.ISEVEN],
  19873. [k0, Ne.ISFORMULA],
  19874. [$0, Ne.ISLOGICAL],
  19875. [Y0, Ne.ISNA],
  19876. [H0, Ne.ISNONTEXT],
  19877. [G0, Ne.ISNUMBER],
  19878. [Q0, Ne.ISODD],
  19879. [W0, Ne.ISREF],
  19880. [q0, Ne.ISTEXT],
  19881. [K0, Ne.ISURL],
  19882. [X0, Ne.N],
  19883. [Z0, Ne.NA],
  19884. [z0, Ne.SHEET],
  19885. [J0, Ne.SHEETS],
  19886. [ed, Ne.TYPE]
  19887. ];
  19888. class rd extends V {
  19889. constructor() {
  19890. super(...arguments);
  19891. A(this, "minParams", 1);
  19892. A(this, "maxParams", 255);
  19893. }
  19894. calculate(...e) {
  19895. let t = !0, r = !0, n = null;
  19896. for (const s of e) {
  19897. if (s.isError())
  19898. return s;
  19899. if (s.isArray()) {
  19900. if (s.iterator((o) => {
  19901. if (o != null && o.isError())
  19902. return n = o, !1;
  19903. (o != null && o.isBoolean() || o != null && o.isNumber()) && (t = t && !!o.getValue(), r = !1);
  19904. }), n)
  19905. return n;
  19906. } else (s.isBoolean() || s.isNumber()) && (t = t && !!s.getValue(), r = !1);
  19907. }
  19908. return r ? g.create(m.VALUE) : T.create(t);
  19909. }
  19910. }
  19911. class nd extends V {
  19912. constructor() {
  19913. super(...arguments);
  19914. A(this, "minParams", 2);
  19915. A(this, "maxParams", 2);
  19916. A(this, "needsReferenceObject", !0);
  19917. }
  19918. // eslint-disable-next-line
  19919. calculate(e, t) {
  19920. let r = e, n = null;
  19921. if (e.isReferenceObject() && (r = e.toArrayValueObject(), n = e), r.isError())
  19922. return r;
  19923. if (t.isError())
  19924. return t;
  19925. if (!(t.isValueObject() && t.isLambda() && t.getLambdaPrivacyVarKeys().length === 1))
  19926. return g.create(m.VALUE);
  19927. const s = t, o = r.isArray() ? r.getRowCount() : 1, u = r.isArray() ? r.getColumnCount() : 1;
  19928. r = O(o, u, r);
  19929. const c = [[]];
  19930. for (let l = 0; l < u; l++) {
  19931. const f = [];
  19932. for (let _ = 0; _ < o; _++) {
  19933. const C = r.get(_, l);
  19934. f.push([C]);
  19935. }
  19936. let h = q.create({
  19937. calculateValueList: f,
  19938. rowCount: o,
  19939. columnCount: 1,
  19940. unitId: "",
  19941. sheetId: "",
  19942. row: 0,
  19943. column: 0
  19944. });
  19945. if (n) {
  19946. const { startRow: _, startColumn: C } = n.getRangePosition(), E = {
  19947. startRow: _,
  19948. startColumn: C + l,
  19949. endRow: _ + o - 1,
  19950. endColumn: C + l
  19951. };
  19952. h = this.createReferenceObject(n, E);
  19953. }
  19954. let d = s.execute(h);
  19955. if (d.isArray()) {
  19956. const _ = d.getRowCount(), C = d.getColumnCount();
  19957. if (_ > 1 || C > 1)
  19958. return g.create(m.CALC);
  19959. d = d.get(0, 0);
  19960. }
  19961. d.isNull() && (d = y.create(0)), c[0].push(d);
  19962. }
  19963. return u === 1 ? c[0][0] : q.create({
  19964. calculateValueList: c,
  19965. rowCount: 1,
  19966. columnCount: u,
  19967. unitId: this.unitId,
  19968. sheetId: this.subUnitId,
  19969. row: this.row,
  19970. column: this.column
  19971. });
  19972. }
  19973. }
  19974. class sd extends V {
  19975. constructor() {
  19976. super(...arguments);
  19977. A(this, "minParams", 2);
  19978. A(this, "maxParams", 2);
  19979. A(this, "needsReferenceObject", !0);
  19980. }
  19981. // eslint-disable-next-line
  19982. calculate(e, t) {
  19983. let r = e, n = null;
  19984. if (e.isReferenceObject() && (r = e.toArrayValueObject(), n = e), r.isError())
  19985. return r;
  19986. if (t.isError())
  19987. return t;
  19988. if (!(t.isValueObject() && t.isLambda() && t.getLambdaPrivacyVarKeys().length === 1))
  19989. return g.create(m.VALUE);
  19990. const s = t, o = r.isArray() ? r.getRowCount() : 1, u = r.isArray() ? r.getColumnCount() : 1;
  19991. r = O(o, u, r);
  19992. const c = [];
  19993. for (let l = 0; l < o; l++) {
  19994. const f = [[]];
  19995. for (let _ = 0; _ < u; _++) {
  19996. const C = r.get(l, _);
  19997. f[0].push(C);
  19998. }
  19999. let h = q.create({
  20000. calculateValueList: f,
  20001. rowCount: 1,
  20002. columnCount: u,
  20003. unitId: "",
  20004. sheetId: "",
  20005. row: 0,
  20006. column: 0
  20007. });
  20008. if (n) {
  20009. const { startRow: _, startColumn: C } = n.getRangePosition(), E = {
  20010. startRow: _ + l,
  20011. startColumn: C,
  20012. endRow: _ + l,
  20013. endColumn: C + u - 1
  20014. };
  20015. h = this.createReferenceObject(n, E);
  20016. }
  20017. let d = s.execute(h);
  20018. if (d.isArray()) {
  20019. const _ = d.getRowCount(), C = d.getColumnCount();
  20020. if (_ > 1 || C > 1)
  20021. return g.create(m.CALC);
  20022. d = d.get(0, 0);
  20023. }
  20024. d.isNull() && (d = y.create(0)), c.push([d]);
  20025. }
  20026. return o === 1 ? c[0][0] : q.create({
  20027. calculateValueList: c,
  20028. rowCount: o,
  20029. columnCount: 1,
  20030. unitId: this.unitId,
  20031. sheetId: this.subUnitId,
  20032. row: this.row,
  20033. column: this.column
  20034. });
  20035. }
  20036. }
  20037. class ad extends V {
  20038. constructor() {
  20039. super(...arguments);
  20040. A(this, "minParams", 0);
  20041. A(this, "maxParams", 0);
  20042. }
  20043. calculate() {
  20044. return T.create(!1);
  20045. }
  20046. }
  20047. var Se = /* @__PURE__ */ ((i) => (i.AND = "AND", i.BYCOL = "BYCOL", i.BYROW = "BYROW", i.FALSE = "FALSE", i.IF = "IF", i.IFERROR = "IFERROR", i.IFNA = "IFNA", i.IFS = "IFS", i.LAMBDA = "LAMBDA", i.LET = "LET", i.MAKEARRAY = "MAKEARRAY", i.MAP = "MAP", i.NOT = "NOT", i.OR = "OR", i.REDUCE = "REDUCE", i.SCAN = "SCAN", i.SWITCH = "SWITCH", i.TRUE = "TRUE", i.XOR = "XOR", i))(Se || {});
  20048. class id extends V {
  20049. constructor() {
  20050. super(...arguments);
  20051. A(this, "minParams", 2);
  20052. A(this, "maxParams", 3);
  20053. }
  20054. calculate(e, t, r = T.create(!1)) {
  20055. const n = this._getSingleValueObject(e);
  20056. if (n.isError())
  20057. return n;
  20058. if (!n.isArray())
  20059. return n.getValue() ? t : r;
  20060. const s = Math.max(
  20061. n.isArray() ? n.getRowCount() : 1,
  20062. t.isArray() ? t.getRowCount() : 1,
  20063. r.isArray() ? r.getRowCount() : 1
  20064. ), o = Math.max(
  20065. n.isArray() ? n.getColumnCount() : 1,
  20066. t.isArray() ? t.getColumnCount() : 1,
  20067. r.isArray() ? r.getColumnCount() : 1
  20068. ), u = O(s, o, n), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA));
  20069. return u.map((f, h, d) => {
  20070. if (f.isNull())
  20071. return g.create(m.NA);
  20072. {
  20073. const _ = c.get(h, d) || ie.create(), C = l.get(h, d) || ie.create();
  20074. return this._calculateSingleCell(f, _, C);
  20075. }
  20076. });
  20077. }
  20078. _getSingleValueObject(e) {
  20079. return e.isArray() && e.getRowCount() === 1 && e.getColumnCount() === 1 ? e.getFirstCell() : e;
  20080. }
  20081. _calculateSingleCell(e, t, r) {
  20082. return e.isNull() ? g.create(m.NA) : e.getValue() ? t.isNull() ? g.create(m.NA) : t : r.isNull() ? g.create(m.NA) : r;
  20083. }
  20084. }
  20085. class od extends V {
  20086. constructor() {
  20087. super(...arguments);
  20088. A(this, "minParams", 2);
  20089. A(this, "maxParams", 2);
  20090. }
  20091. calculate(e, t) {
  20092. if (!e.isArray())
  20093. return e.isError() ? t : e;
  20094. const r = Math.max(
  20095. e.isArray() ? e.getRowCount() : 1,
  20096. t.isArray() ? t.getRowCount() : 1
  20097. ), n = Math.max(
  20098. e.isArray() ? e.getColumnCount() : 1,
  20099. t.isArray() ? t.getColumnCount() : 1
  20100. ), s = O(r, n, e), o = O(r, n, t);
  20101. return s.iterator((u, c, l) => {
  20102. u != null && u.isError() && s.set(c, l, o.get(c, l));
  20103. }), s;
  20104. }
  20105. }
  20106. class ud extends V {
  20107. constructor() {
  20108. super(...arguments);
  20109. A(this, "minParams", 2);
  20110. A(this, "maxParams", 2);
  20111. }
  20112. calculate(e, t) {
  20113. if (e.isError() && e.getErrorType() !== m.NA)
  20114. return e;
  20115. if (t.isError())
  20116. return t;
  20117. if (!e.isArray())
  20118. return e.isError() && e.getErrorType() === m.NA ? t : e;
  20119. const r = Math.max(
  20120. e.isArray() ? e.getRowCount() : 1,
  20121. t.isArray() ? t.getRowCount() : 1
  20122. ), n = Math.max(
  20123. e.isArray() ? e.getColumnCount() : 1,
  20124. t.isArray() ? t.getColumnCount() : 1
  20125. ), s = O(r, n, e), o = O(r, n, t);
  20126. return s.iterator((u, c, l) => {
  20127. u != null && u.isError() && u.getErrorType() === m.NA && s.set(c, l, o.get(c, l));
  20128. }), s;
  20129. }
  20130. }
  20131. class cd extends V {
  20132. constructor() {
  20133. super(...arguments);
  20134. A(this, "minParams", 2);
  20135. A(this, "maxParams", 255);
  20136. }
  20137. calculate(...e) {
  20138. if (e.length % 2 !== 0)
  20139. return g.create(m.NA);
  20140. for (let o = 0; o < e.length; o++)
  20141. if (e[o].isError())
  20142. return e[o];
  20143. const t = Math.max(
  20144. ...e.map((o) => o.isArray() ? o.getRowCount() : 1)
  20145. ), r = Math.max(
  20146. ...e.map((o) => o.isArray() ? o.getColumnCount() : 1)
  20147. ), n = e.map(
  20148. (o) => O(t, r, o, g.create(m.NA))
  20149. ), s = n[0].map((o, u, c) => {
  20150. for (let l = 0; l < n.length; l += 2) {
  20151. const f = n[l].get(u, c) || ie.create(), h = n[l + 1].get(u, c) || ie.create();
  20152. if (f.isNull())
  20153. continue;
  20154. if (f.isError())
  20155. return f;
  20156. const d = f.getValue();
  20157. if (f.isString()) {
  20158. if (`${d}`.toLocaleUpperCase() === "TRUE")
  20159. return h;
  20160. if (`${d}`.toLocaleUpperCase() === "FALSE")
  20161. continue;
  20162. return g.create(m.VALUE);
  20163. }
  20164. if (+d)
  20165. return h.isNull() ? g.create(m.NA) : h;
  20166. }
  20167. return g.create(m.NA);
  20168. });
  20169. return t === 1 && r === 1 ? s.get(0, 0) : s;
  20170. }
  20171. }
  20172. class ld extends V {
  20173. constructor() {
  20174. super(...arguments);
  20175. A(this, "minParams", 1);
  20176. A(this, "maxParams", 255);
  20177. }
  20178. calculate(...e) {
  20179. return g.create(m.VALUE);
  20180. }
  20181. }
  20182. class fd extends V {
  20183. constructor() {
  20184. super(...arguments);
  20185. A(this, "minParams", 3);
  20186. A(this, "maxParams", 255);
  20187. }
  20188. calculate(...e) {
  20189. return g.create(m.VALUE);
  20190. }
  20191. }
  20192. class hd extends V {
  20193. constructor() {
  20194. super(...arguments);
  20195. A(this, "minParams", 3);
  20196. A(this, "maxParams", 3);
  20197. }
  20198. calculate(...e) {
  20199. const t = this.getIndexNumValue(e[0]);
  20200. if (typeof t != "number")
  20201. return t;
  20202. const r = this.getIndexNumValue(e[1]);
  20203. if (typeof r != "number")
  20204. return r;
  20205. if (!(e[2].isValueObject() && e[2].isLambda()))
  20206. return g.create(m.VALUE);
  20207. const n = e[2], s = [];
  20208. for (let o = 0; o < t; o++) {
  20209. s[o] == null && (s[o] = []);
  20210. for (let u = 0; u < r; u++) {
  20211. let c = n.execute(y.create(o + 1), y.create(u + 1));
  20212. c.isArray() && (c = c.get(0, 0)), s[o][u] = c;
  20213. }
  20214. }
  20215. return new Of(s);
  20216. }
  20217. isAsync() {
  20218. return !0;
  20219. }
  20220. }
  20221. let md = class extends V {
  20222. constructor() {
  20223. super(...arguments);
  20224. A(this, "minParams", 2);
  20225. A(this, "maxParams", 255);
  20226. A(this, "needsReferenceObject", !0);
  20227. }
  20228. calculate(...e) {
  20229. const t = [];
  20230. let r = null, n = 0, s = 0;
  20231. for (let u = 0; u < e.length; u++) {
  20232. const c = e[u];
  20233. let l = c;
  20234. if (l.isReferenceObject() && (l = c.toArrayValueObject()), l.isError())
  20235. return l;
  20236. if (u === e.length - 1) {
  20237. if (!(c.isValueObject() && c.isLambda()))
  20238. return g.create(m.VALUE);
  20239. r = c;
  20240. } else
  20241. t.push(c), n = Math.max(n, l.isArray() ? l.getRowCount() : 1), s = Math.max(s, l.isArray() ? l.getColumnCount() : 1);
  20242. }
  20243. const o = this._getResultArray(t, r, n, s);
  20244. return o instanceof g ? o : n === 1 && s === 1 ? o[0][0] : q.create({
  20245. calculateValueList: o,
  20246. rowCount: n,
  20247. columnCount: s,
  20248. unitId: this.unitId,
  20249. sheetId: this.subUnitId,
  20250. row: this.row,
  20251. column: this.column
  20252. });
  20253. }
  20254. // eslint-disable-next-line
  20255. _getResultArray(e, t, r, n) {
  20256. const s = [];
  20257. for (let o = 0; o < r; o++) {
  20258. const u = [];
  20259. for (let c = 0; c < n; c++) {
  20260. const l = [];
  20261. let f = !1;
  20262. for (let d = 0; d < e.length; d++) {
  20263. let _ = e[d], C = null;
  20264. if (_.isReferenceObject() && (C = _, _ = _.toArrayValueObject()), !_.isArray())
  20265. if (o === 0 && c === 0) {
  20266. l.push(C || _);
  20267. continue;
  20268. } else {
  20269. u.push(g.create(m.NA)), f = !0;
  20270. break;
  20271. }
  20272. let E = _.get(o, c);
  20273. if (!E) {
  20274. u.push(g.create(m.NA)), f = !0;
  20275. break;
  20276. }
  20277. if (C) {
  20278. const { startRow: b, startColumn: R } = C.getRangePosition(), p = {
  20279. startRow: b + o,
  20280. startColumn: R + c,
  20281. endRow: b + o,
  20282. endColumn: R + c
  20283. };
  20284. E = this.createReferenceObject(C, p);
  20285. }
  20286. l.push(E);
  20287. }
  20288. if (f || l.length === 0)
  20289. continue;
  20290. let h = t.execute(...l);
  20291. if (h.isArray()) {
  20292. const d = h.getRowCount(), _ = h.getColumnCount();
  20293. if (d > 1 || _ > 1)
  20294. return g.create(m.CALC);
  20295. h = h.get(0, 0);
  20296. }
  20297. h.isNull() && (h = y.create(0)), u.push(h);
  20298. }
  20299. s.push(u);
  20300. }
  20301. return s;
  20302. }
  20303. };
  20304. class gd extends V {
  20305. constructor() {
  20306. super(...arguments);
  20307. A(this, "minParams", 1);
  20308. A(this, "maxParams", 1);
  20309. }
  20310. calculate(e) {
  20311. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  20312. }
  20313. _handleSingleObject(e) {
  20314. if (e.isError())
  20315. return e;
  20316. const t = +e.getValue();
  20317. return Number.isNaN(t) ? g.create(m.VALUE) : T.create(!t);
  20318. }
  20319. }
  20320. class dd extends V {
  20321. constructor() {
  20322. super(...arguments);
  20323. A(this, "minParams", 1);
  20324. A(this, "maxParams", 255);
  20325. }
  20326. calculate(...e) {
  20327. let t = !1, r = !0, n = null;
  20328. for (const s of e) {
  20329. if (s.isError())
  20330. return s;
  20331. if (s.isArray()) {
  20332. if (s.iterator((o) => {
  20333. if (o != null && o.isError())
  20334. return n = o, !1;
  20335. (o != null && o.isBoolean() || o != null && o.isNumber()) && (t = t || !!o.getValue(), r = !1);
  20336. }), n)
  20337. return n;
  20338. } else (s.isBoolean() || s.isNumber()) && (t = t || !!s.getValue(), r = !1);
  20339. }
  20340. return r ? new g(m.VALUE) : new T(t);
  20341. }
  20342. }
  20343. class Cd extends V {
  20344. constructor() {
  20345. super(...arguments);
  20346. A(this, "minParams", 3);
  20347. A(this, "maxParams", 3);
  20348. A(this, "needsReferenceObject", !0);
  20349. }
  20350. calculate(e, t, r) {
  20351. let n, s;
  20352. e.isReferenceObject() ? (n = e.toArrayValueObject(), s = e) : (n = e, s = null);
  20353. let o, u;
  20354. return t.isReferenceObject() ? (o = t.toArrayValueObject(), u = t) : (o = t, u = null), n.isArray() ? n.mapValue((c) => this._handleSingleValueObject(c, o, r, s, u)) : this._handleSingleValueObject(n, o, r, s, u);
  20355. }
  20356. _handleSingleValueObject(e, t, r, n, s) {
  20357. if (e.isError())
  20358. return e;
  20359. if (t.isError())
  20360. return t;
  20361. if (r.isError())
  20362. return r;
  20363. if (!(r.isValueObject() && r.isLambda() && r.getLambdaPrivacyVarKeys().length === 2))
  20364. return g.create(m.VALUE);
  20365. const o = r, u = t.isArray() ? t.getRowCount() : 1, c = t.isArray() ? t.getColumnCount() : 1;
  20366. let l = e;
  20367. n && (l = n);
  20368. for (let f = 0; f < u; f++)
  20369. for (let h = 0; h < c; h++) {
  20370. let d = t.isArray() ? t.get(f, h) : t;
  20371. if (d.isError())
  20372. return d;
  20373. if (s) {
  20374. const { startRow: C, startColumn: E } = s.getRangePosition(), b = {
  20375. startRow: C + f,
  20376. startColumn: E + h,
  20377. endRow: C + f,
  20378. endColumn: E + h
  20379. };
  20380. d = this.createReferenceObject(s, b);
  20381. }
  20382. let _ = o.execute(l, d);
  20383. if (_.isError())
  20384. return _;
  20385. _.isNull() && (_ = y.create(0)), l = _;
  20386. }
  20387. return l.isReferenceObject() ? l.toArrayValueObject() : l;
  20388. }
  20389. }
  20390. class _d extends V {
  20391. constructor() {
  20392. super(...arguments);
  20393. A(this, "minParams", 3);
  20394. A(this, "maxParams", 3);
  20395. A(this, "needsReferenceObject", !0);
  20396. }
  20397. calculate(e, t, r) {
  20398. let n = e, s = null;
  20399. e.isReferenceObject() && (n = e.toArrayValueObject(), s = e), n = n;
  20400. let o = t, u = null;
  20401. if (t.isReferenceObject() && (o = t.toArrayValueObject(), u = t), o = o, n.isError())
  20402. return n;
  20403. if (o.isError())
  20404. return o;
  20405. if (r.isError())
  20406. return r;
  20407. if (!(r.isValueObject() && r.isLambda() && r.getLambdaPrivacyVarKeys().length === 2))
  20408. return g.create(m.VALUE);
  20409. if (n.isArray()) {
  20410. const c = n.getRowCount(), l = n.getColumnCount();
  20411. if (c > 1 || l > 1)
  20412. return g.create(m.CALC);
  20413. n = n.get(0, 0);
  20414. }
  20415. return this._getResult(n, o, r, s, u);
  20416. }
  20417. // eslint-disable-next-line
  20418. _getResult(e, t, r, n, s) {
  20419. const o = [], u = t.isArray() ? t.getRowCount() : 1, c = t.isArray() ? t.getColumnCount() : 1;
  20420. let l = e;
  20421. n && (l = n);
  20422. for (let f = 0; f < u; f++) {
  20423. const h = [];
  20424. for (let d = 0; d < c; d++) {
  20425. if (l.isError()) {
  20426. h.push(l);
  20427. continue;
  20428. }
  20429. let _ = t.isArray() ? t.get(f, d) : t;
  20430. if (_.isError()) {
  20431. l = _, h.push(_);
  20432. continue;
  20433. }
  20434. if (s) {
  20435. const { startRow: E, startColumn: b } = s.getRangePosition(), R = {
  20436. startRow: E + f,
  20437. startColumn: b + d,
  20438. endRow: E + f,
  20439. endColumn: b + d
  20440. };
  20441. _ = this.createReferenceObject(s, R);
  20442. }
  20443. let C = r.execute(l, _);
  20444. if (C.isArray()) {
  20445. const E = C.getRowCount(), b = C.getColumnCount();
  20446. if (E > 1 || b > 1)
  20447. return g.create(m.CALC);
  20448. C = C.get(0, 0);
  20449. }
  20450. C.isNull() && (C = y.create(0)), l = C, h.push(C);
  20451. }
  20452. o.push(h);
  20453. }
  20454. return u === 1 && c === 1 ? o[0][0] : q.create({
  20455. calculateValueList: o,
  20456. rowCount: u,
  20457. columnCount: c,
  20458. unitId: this.unitId,
  20459. sheetId: this.subUnitId,
  20460. row: this.row,
  20461. column: this.column
  20462. });
  20463. }
  20464. }
  20465. class Ad extends V {
  20466. constructor() {
  20467. super(...arguments);
  20468. A(this, "minParams", 3);
  20469. }
  20470. calculate(e, ...t) {
  20471. if (e.isError())
  20472. return e;
  20473. const r = t.length % 2 !== 0, n = r ? t[t.length - 1] : ie.create();
  20474. return !e.isArray() && !t.some((s) => s.isArray()) ? this._handleNonArrayInputs(e, t, n, r) : this._handleArrayInputs(e, t, n, r);
  20475. }
  20476. _handleNonArrayInputs(e, t, r, n) {
  20477. for (let s = 0; s < t.length - (n ? 1 : 0); s += 2) {
  20478. const o = t[s], u = t[s + 1];
  20479. if (!o.isNull()) {
  20480. if (o.isError())
  20481. return o;
  20482. if (`${e.getValue()}`.toLocaleLowerCase() === `${o.getValue()}`.toLocaleLowerCase())
  20483. return u.isNull() ? g.create(m.NA) : u;
  20484. }
  20485. }
  20486. return r.isNull() ? g.create(m.NA) : r;
  20487. }
  20488. _handleArrayInputs(e, t, r, n) {
  20489. const s = Math.max(
  20490. e.isArray() ? e.getRowCount() : 1,
  20491. ...t.map((f) => f.isArray() ? f.getRowCount() : 1),
  20492. r.isArray() ? r.getRowCount() : 1
  20493. ), o = Math.max(
  20494. e.isArray() ? e.getColumnCount() : 1,
  20495. ...t.map((f) => f.isArray() ? f.getColumnCount() : 1),
  20496. r.isArray() ? r.getColumnCount() : 1
  20497. ), u = O(s, o, e), c = t.map(
  20498. (f) => O(s, o, f, g.create(m.NA))
  20499. ), l = O(s, o, r, g.create(m.NA));
  20500. return u.map((f, h, d) => {
  20501. for (let C = 0; C < c.length - (n ? 1 : 0); C += 2) {
  20502. const E = c[C].get(h, d) || ie.create(), b = c[C + 1].get(h, d) || ie.create();
  20503. if (!E.isNull()) {
  20504. if (E.isError() || f.isError())
  20505. return E.isError() ? E : f;
  20506. if (`${f.getValue()}`.toLocaleLowerCase() === `${E.getValue()}`.toLocaleLowerCase())
  20507. return b.isNull() ? g.create(m.NA) : b;
  20508. }
  20509. }
  20510. const _ = l.get(h, d) || ie.create();
  20511. return _.isNull() ? g.create(m.NA) : _;
  20512. });
  20513. }
  20514. }
  20515. class Ed extends V {
  20516. constructor() {
  20517. super(...arguments);
  20518. A(this, "minParams", 0);
  20519. A(this, "maxParams", 0);
  20520. }
  20521. calculate() {
  20522. return T.create(!0);
  20523. }
  20524. }
  20525. class bd extends V {
  20526. constructor() {
  20527. super(...arguments);
  20528. A(this, "minParams", 1);
  20529. A(this, "maxParams", 255);
  20530. }
  20531. calculate(...e) {
  20532. let t = 0, r = !0, n = null;
  20533. for (const s of e) {
  20534. if (s.isError())
  20535. return s;
  20536. if (s.isArray()) {
  20537. if (s.iterator((o) => {
  20538. if (o != null && o.isError())
  20539. return n = o, !1;
  20540. (o != null && o.isBoolean() || o != null && o.isNumber()) && (o.getValue() && t++, r = !1);
  20541. }), n)
  20542. return n;
  20543. } else (s.isBoolean() || s.isNumber()) && (s.getValue() && t++, r = !1);
  20544. }
  20545. return r ? g.create(m.VALUE) : T.create(t % 2 === 1);
  20546. }
  20547. }
  20548. const yd = [
  20549. [rd, Se.AND],
  20550. [nd, Se.BYCOL],
  20551. [sd, Se.BYROW],
  20552. [ad, Se.FALSE],
  20553. [id, Se.IF],
  20554. [od, Se.IFERROR],
  20555. [ud, Se.IFNA],
  20556. [cd, Se.IFS],
  20557. [ld, Se.LAMBDA],
  20558. [fd, Se.LET],
  20559. [hd, Se.MAKEARRAY],
  20560. [md, Se.MAP],
  20561. [gd, Se.NOT],
  20562. [dd, Se.OR],
  20563. [Cd, Se.REDUCE],
  20564. [_d, Se.SCAN],
  20565. [Ad, Se.SWITCH],
  20566. [Ed, Se.TRUE],
  20567. [bd, Se.XOR]
  20568. ];
  20569. class Rd extends V {
  20570. constructor() {
  20571. super(...arguments);
  20572. A(this, "minParams", 2);
  20573. A(this, "maxParams", 5);
  20574. }
  20575. // eslint-disable-next-line max-lines-per-function
  20576. calculate(e, t, r, n, s) {
  20577. if (e.isError())
  20578. return e;
  20579. if (t.isError())
  20580. return t;
  20581. if (r != null && r.isError())
  20582. return r;
  20583. if (n != null && n.isError())
  20584. return n;
  20585. if (s != null && s.isError())
  20586. return s;
  20587. const o = r != null ? r : y.create(1), u = n != null ? n : T.create(!0), c = s != null ? s : j.create(""), l = Math.max(
  20588. e.isArray() ? e.getRowCount() : 1,
  20589. t.isArray() ? t.getRowCount() : 1,
  20590. o.isArray() ? o.getRowCount() : 1,
  20591. u.isArray() ? u.getRowCount() : 1,
  20592. c.isArray() ? c.getRowCount() : 1
  20593. ), f = Math.max(
  20594. e.isArray() ? e.getColumnCount() : 1,
  20595. t.isArray() ? t.getColumnCount() : 1,
  20596. o.isArray() ? o.getColumnCount() : 1,
  20597. u.isArray() ? u.getColumnCount() : 1,
  20598. c.isArray() ? c.getColumnCount() : 1
  20599. ), h = O(l, f, e, g.create(m.NA)), d = O(l, f, t, g.create(m.NA)), _ = O(l, f, o, g.create(m.NA)), C = O(l, f, u, g.create(m.NA)), E = O(l, f, c, g.create(m.NA));
  20600. return h.map((b, R, p) => {
  20601. const N = d.get(R, p) || g.create(m.NA), M = _.get(R, p) || g.create(m.NA), w = C.get(R, p) || g.create(m.NA), D = E.get(R, p) || g.create(m.NA);
  20602. return b.isError() ? b : N.isError() ? N : M.isError() ? M : w.isError() ? w : D.isError() ? D : this._calculateSingleCell(b, N, M, w, D);
  20603. });
  20604. }
  20605. _calculateSingleCell(e, t, r, n, s) {
  20606. const o = Number.parseInt(`${Number(e.getValue()) - 1}`), u = Number.parseInt(`${Number(t.getValue()) - 1}`), c = Number.parseInt(`${Number(r.getValue())}`);
  20607. if (Number.isNaN(o) || Number.isNaN(u) || Number.isNaN(c) || c < 1 || c > 4)
  20608. return g.create(m.VALUE);
  20609. const l = pd(c), f = this.getZeroOrOneByOneDefault(n), h = `${s.getValue()}`, d = Ki(h), _ = {
  20610. startRow: o,
  20611. startColumn: u,
  20612. endRow: o,
  20613. endColumn: u,
  20614. startAbsoluteRefType: l,
  20615. endAbsoluteRefType: l
  20616. }, C = n && !f ? Fh(_) : fr(_);
  20617. return j.create(d !== "" ? `${d}!${C}` : C);
  20618. }
  20619. }
  20620. function pd(i) {
  20621. switch (i) {
  20622. case 1:
  20623. return we.ALL;
  20624. case 2:
  20625. return we.ROW;
  20626. case 3:
  20627. return we.COLUMN;
  20628. case 4:
  20629. return we.NONE;
  20630. default:
  20631. return we.ALL;
  20632. }
  20633. }
  20634. class Vd extends V {
  20635. constructor() {
  20636. super(...arguments);
  20637. A(this, "minParams", 1);
  20638. A(this, "maxParams", 1);
  20639. A(this, "needsReferenceObject", !0);
  20640. }
  20641. calculate(e) {
  20642. return e.isReferenceObject() ? y.create(1) : g.create(m.VALUE);
  20643. }
  20644. }
  20645. class Nd extends V {
  20646. constructor() {
  20647. super(...arguments);
  20648. A(this, "minParams", 2);
  20649. A(this, "maxParams", 255);
  20650. A(this, "needsReferenceObject", !0);
  20651. }
  20652. calculate(e, ...t) {
  20653. let r = e;
  20654. if (r.isError())
  20655. return r;
  20656. if (r.isReferenceObject() && (r = r.toArrayValueObject()), !r.isArray()) {
  20657. const c = r.convertToNumberObjectValue();
  20658. return c.isError() ? c : t[Math.trunc(+c.getValue()) - 1] || g.create(m.VALUE);
  20659. }
  20660. let n = r.isArray() ? r.getRowCount() : 1, s = r.isArray() ? r.getColumnCount() : 1;
  20661. t.forEach((c, l) => {
  20662. if (c.isArray()) {
  20663. const f = c;
  20664. n = Math.max(n, f.getRowCount()), s = Math.max(s, f.getColumnCount());
  20665. } else
  20666. n = Math.max(n, 1), s = Math.max(s, 1);
  20667. });
  20668. const o = O(n, s, r, g.create(m.NA)), u = t.map((c) => {
  20669. let l = c;
  20670. return l.isReferenceObject() && (l = l.toArrayValueObject()), O(n, s, l, g.create(m.NA));
  20671. });
  20672. return o.map((c, l, f) => {
  20673. if (c.isError())
  20674. return c;
  20675. const h = c.convertToNumberObjectValue();
  20676. if (h.isError())
  20677. return h;
  20678. const d = u[Math.trunc(+h.getValue()) - 1];
  20679. let _ = (d == null ? void 0 : d.get(l, f)) || g.create(m.VALUE);
  20680. return _ != null && _.isNull() && (_ = y.create(0)), _;
  20681. });
  20682. }
  20683. }
  20684. class Od extends V {
  20685. constructor() {
  20686. super(...arguments);
  20687. A(this, "minParams", 2);
  20688. A(this, "maxParams", 255);
  20689. }
  20690. calculate(e, ...t) {
  20691. if (e.isError())
  20692. return e;
  20693. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = [];
  20694. for (let o = 0; o < t.length; o++) {
  20695. let u = t[o];
  20696. if (u.isArray()) {
  20697. const f = u.getRowCount(), h = u.getColumnCount();
  20698. if (f > 1 || h > 1)
  20699. return g.create(m.VALUE);
  20700. u = u.get(0, 0);
  20701. }
  20702. if (u.isString() && (u = u.convertToNumberObjectValue()), u.isError())
  20703. return u;
  20704. const c = Math.trunc(+u.getValue());
  20705. if (c === 0 || Math.abs(c) > n)
  20706. return g.create(m.VALUE);
  20707. let l = e;
  20708. n > 1 && (c < 0 ? l = e.slice(void 0, [c + n, c + 1 + n]) : l = e.slice(void 0, [c - 1, c]));
  20709. for (let f = 0; f < r; f++)
  20710. s[f] || (s[f] = []), e.isArray() ? s[f].push(l.get(f, 0)) : s[f].push(e);
  20711. }
  20712. return q.create({
  20713. calculateValueList: s,
  20714. rowCount: s.length,
  20715. columnCount: s[0].length || 0,
  20716. unitId: this.unitId,
  20717. sheetId: this.subUnitId,
  20718. row: this.row,
  20719. column: this.column
  20720. });
  20721. }
  20722. }
  20723. class Md extends V {
  20724. constructor() {
  20725. super(...arguments);
  20726. A(this, "minParams", 2);
  20727. A(this, "maxParams", 255);
  20728. }
  20729. calculate(e, ...t) {
  20730. if (e.isError())
  20731. return e;
  20732. const r = e.isArray() ? e.getRowCount() : 1, n = [];
  20733. for (let s = 0; s < t.length; s++) {
  20734. let o = t[s];
  20735. if (o.isArray()) {
  20736. const l = o.getRowCount(), f = o.getColumnCount();
  20737. if (l > 1 || f > 1)
  20738. return g.create(m.VALUE);
  20739. o = o.get(0, 0);
  20740. }
  20741. if (o.isString() && (o = o.convertToNumberObjectValue()), o.isError())
  20742. return o;
  20743. const u = Math.trunc(+o.getValue());
  20744. if (u === 0 || Math.abs(u) > r)
  20745. return g.create(m.VALUE);
  20746. let c = e;
  20747. r > 1 && (u < 0 ? c = e.slice([u + r, u + 1 + r]) : c = e.slice([u - 1, u])), e.isArray() ? n.push(c.getArrayValue()[0]) : n.push([e]);
  20748. }
  20749. return q.create({
  20750. calculateValueList: n,
  20751. rowCount: n.length,
  20752. columnCount: n[0].length || 0,
  20753. unitId: this.unitId,
  20754. sheetId: this.subUnitId,
  20755. row: this.row,
  20756. column: this.column
  20757. });
  20758. }
  20759. }
  20760. class wd extends V {
  20761. constructor() {
  20762. super(...arguments);
  20763. A(this, "minParams", 0);
  20764. A(this, "maxParams", 1);
  20765. }
  20766. calculate(e) {
  20767. if (e == null)
  20768. return y.create(this.column + 1);
  20769. if (e.isError())
  20770. return e;
  20771. if (!e.isArray())
  20772. return g.create(m.NA);
  20773. const t = e.getCurrentColumn(), r = e.getColumnCount(), n = [];
  20774. for (let o = 0; o < r; o++)
  20775. n.push(y.create(t + o + 1));
  20776. const s = {
  20777. calculateValueList: [n],
  20778. rowCount: 1,
  20779. columnCount: r,
  20780. unitId: this.unitId || "",
  20781. sheetId: this.subUnitId || "",
  20782. row: this.row,
  20783. column: this.column
  20784. };
  20785. return q.create(s);
  20786. }
  20787. }
  20788. class Dd extends V {
  20789. constructor() {
  20790. super(...arguments);
  20791. A(this, "minParams", 1);
  20792. A(this, "maxParams", 1);
  20793. }
  20794. calculate(e) {
  20795. if (e.isError())
  20796. return e;
  20797. if (e.isString() || e.isNumber() || e.isBoolean())
  20798. return y.create(1);
  20799. if (!e.isArray())
  20800. return g.create(m.NA);
  20801. const t = e.getColumnCount();
  20802. return y.create(t);
  20803. }
  20804. }
  20805. class Sd extends V {
  20806. constructor() {
  20807. super(...arguments);
  20808. A(this, "minParams", 2);
  20809. A(this, "maxParams", 3);
  20810. }
  20811. calculate(e, t, r) {
  20812. const n = r != null ? r : y.create(0), s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = Math.max(
  20813. t.isArray() ? t.getRowCount() : 1,
  20814. n.isArray() ? n.getRowCount() : 1
  20815. ), c = Math.max(
  20816. t.isArray() ? t.getColumnCount() : 1,
  20817. n.isArray() ? n.getColumnCount() : 1
  20818. ), l = O(u, c, t, g.create(m.NA)), f = O(u, c, n, g.create(m.NA));
  20819. if (u > 1 || c > 1)
  20820. return l.mapValue((R, p, N) => {
  20821. const M = f.get(p, N);
  20822. if (e.isError())
  20823. return e;
  20824. if (e.isNull())
  20825. return g.create(m.VALUE);
  20826. const { isError: w, errorObject: D } = this._checkRowsColumns(R, M, s, o);
  20827. return w ? D : e.isArray() ? g.create(m.VALUE) : e;
  20828. });
  20829. if (e.isError())
  20830. return e;
  20831. if (e.isNull())
  20832. return g.create(m.VALUE);
  20833. const h = t.isArray() ? t.get(0, 0) : t, d = n.isArray() ? n.get(0, 0) : n, { isError: _, errorObject: C, rowsValue: E, columnsValue: b } = this._checkRowsColumns(h, d, s, o);
  20834. return _ ? C : this._getResultArray(e, E, b, s, o);
  20835. }
  20836. _checkRowsColumns(e, t, r, n) {
  20837. if (e.isError())
  20838. return {
  20839. isError: !0,
  20840. errorObject: e
  20841. };
  20842. if (t.isError())
  20843. return {
  20844. isError: !0,
  20845. errorObject: t
  20846. };
  20847. const s = Math.trunc(+e.getValue()), o = Math.trunc(+t.getValue());
  20848. return Number.isNaN(s) || Number.isNaN(o) ? {
  20849. isError: !0,
  20850. errorObject: g.create(m.VALUE)
  20851. } : Math.abs(s) >= r || Math.abs(o) >= n ? {
  20852. isError: !0,
  20853. errorObject: g.create(m.CALC)
  20854. } : {
  20855. isError: !1,
  20856. rowsValue: s,
  20857. columnsValue: o
  20858. };
  20859. }
  20860. _getResultArray(e, t, r, n, s) {
  20861. const o = t >= 0 ? [t, n] : [0, n + t], u = r >= 0 ? [r, s] : [0, s + r];
  20862. let c;
  20863. return t === 0 && r === 0 ? c = e : t === 0 ? c = e.slice(void 0, u) : r === 0 ? c = e.slice(o, void 0) : c = e.slice(o, u), c = c.map((l) => l.isNull() ? y.create(0) : l), n - t === 1 && s - r === 1 ? c.get(0, 0) : c;
  20864. }
  20865. }
  20866. class Pd extends V {
  20867. constructor() {
  20868. super(...arguments);
  20869. A(this, "minParams", 2);
  20870. A(this, "maxParams", 4);
  20871. }
  20872. calculate(e, t, r, n) {
  20873. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1;
  20874. let u = t, c = r != null ? r : y.create(o);
  20875. const l = n != null ? n : g.create(m.NA);
  20876. t.isNull() && (u = y.create(s)), c.isNull() && (c = y.create(o));
  20877. const f = Math.max(
  20878. u.isArray() ? u.getRowCount() : 1,
  20879. c.isArray() ? c.getRowCount() : 1
  20880. ), h = Math.max(
  20881. u.isArray() ? u.getColumnCount() : 1,
  20882. c.isArray() ? c.getColumnCount() : 1
  20883. ), d = O(f, h, u, g.create(m.NA)), _ = O(f, h, c, g.create(m.NA));
  20884. if (f > 1 || h > 1)
  20885. return d.mapValue((w, D, S) => {
  20886. const P = _.get(D, S);
  20887. if (e.isError())
  20888. return e;
  20889. if (e.isNull())
  20890. return g.create(m.VALUE);
  20891. const { isError: U, errorObject: x } = this._checkRowsColumnsPadWith(w, P, l, s, o);
  20892. return U ? x : e.isArray() ? e.get(0, 0) : e;
  20893. });
  20894. if (e.isError())
  20895. return e;
  20896. if (e.isNull())
  20897. return g.create(m.VALUE);
  20898. const C = u.isArray() ? u.get(0, 0) : u, E = c.isArray() ? c.get(0, 0) : c, { isError: b, errorObject: R, rowsValue: p, columnsValue: N, padWithObject: M } = this._checkRowsColumnsPadWith(C, E, l, s, o);
  20899. return b ? R : this._getResultArray(e, p, N, M, s, o);
  20900. }
  20901. _checkRowsColumnsPadWith(e, t, r, n, s) {
  20902. if (e.isError())
  20903. return {
  20904. isError: !0,
  20905. errorObject: e
  20906. };
  20907. if (t.isError())
  20908. return {
  20909. isError: !0,
  20910. errorObject: t
  20911. };
  20912. const o = Math.trunc(+e.getValue()), u = Math.trunc(+t.getValue());
  20913. if (Number.isNaN(o) || Number.isNaN(u))
  20914. return {
  20915. isError: !0,
  20916. errorObject: g.create(m.VALUE)
  20917. };
  20918. if (Math.abs(o) < n || Math.abs(u) < s)
  20919. return {
  20920. isError: !0,
  20921. errorObject: g.create(m.VALUE)
  20922. };
  20923. let c = r;
  20924. if (r.isArray()) {
  20925. const l = r.getRowCount(), f = r.getColumnCount();
  20926. if (l > 1 || f > 1)
  20927. return {
  20928. isError: !0,
  20929. errorObject: g.create(m.VALUE)
  20930. };
  20931. c = r.get(0, 0);
  20932. }
  20933. return {
  20934. isError: !1,
  20935. rowsValue: o,
  20936. columnsValue: u,
  20937. padWithObject: c
  20938. };
  20939. }
  20940. _getResultArray(e, t, r, n, s, o) {
  20941. let u = [];
  20942. e.isArray() ? u = e.map((f) => f.isNull() ? y.create(0) : f).getArrayValue() : u = [[e]];
  20943. const c = Math.max(0, t - s), l = Math.max(0, r - o);
  20944. for (let f = 0; f < c; f++)
  20945. u.push(new Array(o).fill(n));
  20946. for (let f = 0; f < l; f++)
  20947. u.forEach((h) => {
  20948. h.push(n);
  20949. });
  20950. return t === 1 && r === 1 ? u[0][0] : q.create({
  20951. calculateValueList: u,
  20952. rowCount: u.length,
  20953. columnCount: u[0].length,
  20954. unitId: this.unitId,
  20955. sheetId: this.subUnitId,
  20956. row: this.row,
  20957. column: this.column
  20958. });
  20959. }
  20960. }
  20961. class Ld extends V {
  20962. constructor() {
  20963. super(...arguments);
  20964. A(this, "minParams", 2);
  20965. A(this, "maxParams", 3);
  20966. }
  20967. calculate(e, t, r) {
  20968. const n = r != null ? r : g.create(m.CALC);
  20969. if (e.isError())
  20970. return e;
  20971. if (t.isError())
  20972. return t;
  20973. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = t.isArray() ? t.getRowCount() : 1, c = t.isArray() ? t.getColumnCount() : 1;
  20974. return u > 1 && c > 1 || u === 1 && c !== o || c === 1 && u !== s ? g.create(m.VALUE) : s === 1 && o === 1 ? this._getResultArrayByR1C1(e, t, n) : u === 1 ? c !== o ? g.create(m.VALUE) : this._getResultArrayByR1(s, o, e, t, n) : c === 1 ? u !== s ? g.create(m.VALUE) : this._getResultArrayByC1(s, o, e, t, n) : n;
  20975. }
  20976. _getResultArrayByR1C1(e, t, r) {
  20977. let n = e, s = t;
  20978. return n.isArray() && (n = n.get(0, 0)), s.isArray() && (s = s.get(0, 0)), s.isString() && (s = s.convertToNumberObjectValue()), s.isError() ? s : +s.getValue() ? n : r;
  20979. }
  20980. _getResultArrayByR1(e, t, r, n, s) {
  20981. const o = [];
  20982. for (let u = 0; u < t; u++) {
  20983. let c = n.get(0, u);
  20984. if (c.isString() && (c = c.convertToNumberObjectValue()), c.isError())
  20985. return c;
  20986. if (+c.getValue())
  20987. for (let f = 0; f < e; f++) {
  20988. o[f] || (o[f] = []);
  20989. const h = r.get(f, u);
  20990. o[f].push(h);
  20991. }
  20992. }
  20993. return o.length === 0 ? s : q.create({
  20994. calculateValueList: o,
  20995. rowCount: o.length,
  20996. columnCount: o[0].length || 0,
  20997. unitId: this.unitId,
  20998. sheetId: this.subUnitId,
  20999. row: this.row,
  21000. column: this.column
  21001. });
  21002. }
  21003. _getResultArrayByC1(e, t, r, n, s) {
  21004. const o = [];
  21005. for (let u = 0; u < e; u++) {
  21006. let c = n.get(u, 0);
  21007. if (c.isString() && (c = c.convertToNumberObjectValue()), c.isError())
  21008. return c;
  21009. if (!+c.getValue())
  21010. continue;
  21011. const f = [];
  21012. for (let h = 0; h < t; h++) {
  21013. const d = r.get(u, h);
  21014. f.push(d);
  21015. }
  21016. o.push(f);
  21017. }
  21018. return o.length === 0 ? s : q.create({
  21019. calculateValueList: o,
  21020. rowCount: o.length,
  21021. columnCount: o[0].length || 0,
  21022. unitId: this.unitId,
  21023. sheetId: this.subUnitId,
  21024. row: this.row,
  21025. column: this.column
  21026. });
  21027. }
  21028. }
  21029. class xd extends V {
  21030. constructor() {
  21031. super(...arguments);
  21032. A(this, "minParams", 1);
  21033. A(this, "maxParams", 1);
  21034. A(this, "needsReferenceObject", !0);
  21035. A(this, "needsFormulaDataModel", !0);
  21036. }
  21037. calculate(e) {
  21038. var f, h;
  21039. if (!e.isReferenceObject())
  21040. return g.create(m.NA);
  21041. const t = e.getUnitId(), r = e.getSheetId(), s = (h = (f = e.getUnitData()[t]) == null ? void 0 : f[r]) == null ? void 0 : h.cellData, { startRow: o, startColumn: u } = e.getRangePosition(), l = e.toArrayValueObject().mapValue((d, _, C) => {
  21042. const E = s.getValue(o + _, u + C);
  21043. if (E != null && E.f || E != null && E.si) {
  21044. const b = this._formulaDataModel.getFormulaStringByCell(o + _, u + C, r, t);
  21045. return j.create(b);
  21046. }
  21047. return g.create(m.NA);
  21048. });
  21049. return l.getRowCount() === 1 && l.getColumnCount() === 1 ? l.get(0, 0) : l;
  21050. }
  21051. }
  21052. var me = /* @__PURE__ */ ((i) => (i.ADDRESS = "ADDRESS", i.AREAS = "AREAS", i.CHOOSE = "CHOOSE", i.CHOOSECOLS = "CHOOSECOLS", i.CHOOSEROWS = "CHOOSEROWS", i.COLUMN = "COLUMN", i.COLUMNS = "COLUMNS", i.DROP = "DROP", i.EXPAND = "EXPAND", i.FILTER = "FILTER", i.FORMULATEXT = "FORMULATEXT", i.GETPIVOTDATA = "GETPIVOTDATA", i.HLOOKUP = "HLOOKUP", i.HSTACK = "HSTACK", i.HYPERLINK = "HYPERLINK", i.IMAGE = "IMAGE", i.INDEX = "INDEX", i.INDIRECT = "INDIRECT", i.LOOKUP = "LOOKUP", i.MATCH = "MATCH", i.OFFSET = "OFFSET", i.ROW = "ROW", i.ROWS = "ROWS", i.RTD = "RTD", i.SORT = "SORT", i.SORTBY = "SORTBY", i.TAKE = "TAKE", i.TOCOL = "TOCOL", i.TOROW = "TOROW", i.TRANSPOSE = "TRANSPOSE", i.UNIQUE = "UNIQUE", i.VLOOKUP = "VLOOKUP", i.VSTACK = "VSTACK", i.WRAPCOLS = "WRAPCOLS", i.WRAPROWS = "WRAPROWS", i.XLOOKUP = "XLOOKUP", i.XMATCH = "XMATCH", i))(me || {});
  21053. class jd extends V {
  21054. constructor() {
  21055. super(...arguments);
  21056. A(this, "minParams", 3);
  21057. A(this, "maxParams", 4);
  21058. }
  21059. calculate(e, t, r, n) {
  21060. if (e.isError())
  21061. return e;
  21062. if (t.isError())
  21063. return g.create(m.REF);
  21064. if (!t.isArray() || r.isError() || n != null && n.isError())
  21065. return g.create(m.NA);
  21066. const s = this.getZeroOrOneByOneDefault(n);
  21067. if (s == null)
  21068. return g.create(m.VALUE);
  21069. const o = this.getIndexNumValue(r);
  21070. if (o instanceof g)
  21071. return o;
  21072. const u = t.slice([0, 1]), c = t.slice([o - 1, o]);
  21073. return u == null || c == null ? g.create(m.REF) : e.isArray() ? e.map((l) => this._handleSingleObject(l, u, c, s)) : this._handleSingleObject(e, u, c, s);
  21074. }
  21075. _handleSingleObject(e, t, r, n) {
  21076. return n === 0 ? this.equalSearch(e, t, r) : this.binarySearch(e, t, r);
  21077. }
  21078. }
  21079. class Ud extends V {
  21080. constructor() {
  21081. super(...arguments);
  21082. A(this, "minParams", 1);
  21083. A(this, "maxParams", 255);
  21084. }
  21085. calculate(...e) {
  21086. const t = Math.max(
  21087. ...e.map((n) => n.isArray() ? n.getRowCount() : 1)
  21088. ), r = [];
  21089. for (let n = 0; n < e.length; n++) {
  21090. const s = e[n];
  21091. if (s.isError())
  21092. return s;
  21093. const o = s.isArray() ? s.getRowCount() : 1, u = s.isArray() ? s.getColumnCount() : 1;
  21094. for (let c = 0; c < t; c++) {
  21095. r[c] || (r[c] = []);
  21096. for (let l = 0; l < u; l++) {
  21097. let f = s;
  21098. s.isArray() && (f = s.get(c, l)), c > o - 1 || !f ? r[c].push(g.create(m.NA)) : r[c].push(f);
  21099. }
  21100. }
  21101. }
  21102. return q.create({
  21103. calculateValueList: r,
  21104. rowCount: r.length,
  21105. columnCount: r[0].length || 0,
  21106. unitId: this.unitId,
  21107. sheetId: this.subUnitId,
  21108. row: this.row,
  21109. column: this.column
  21110. });
  21111. }
  21112. }
  21113. class vd extends V {
  21114. constructor() {
  21115. super(...arguments);
  21116. A(this, "minParams", 1);
  21117. A(this, "maxParams", 4);
  21118. A(this, "needsReferenceObject", !0);
  21119. }
  21120. // eslint-disable-next-line max-lines-per-function, complexity
  21121. calculate(e, t, r, n) {
  21122. if (e.isError())
  21123. return e;
  21124. if (t != null && t.isError())
  21125. return t;
  21126. if (r != null && r.isError())
  21127. return r;
  21128. if (n != null && n.isError())
  21129. return n;
  21130. let s = 0, o = 0;
  21131. if (e.isValueObject())
  21132. s = 1, o = 1;
  21133. else if (e.isReferenceObject()) {
  21134. const { startRow: d, endRow: _, startColumn: C, endColumn: E } = e.getRangePosition();
  21135. s = _ - d + 1, o = E - C + 1;
  21136. } else
  21137. return g.create(m.VALUE);
  21138. let u, c;
  21139. s === 1 && o > 1 && r == null ? (c = t != null ? t : y.create(0), u = y.create(0)) : (u = t != null ? t : y.create(0), c = r != null ? r : y.create(0));
  21140. let l = n != null ? n : y.create(1);
  21141. u.isReferenceObject() && (u = u.toArrayValueObject()), c.isReferenceObject() && (c = c.toArrayValueObject()), l.isReferenceObject() && (l = l.toArrayValueObject());
  21142. const f = Math.max(
  21143. u.isArray() ? u.getRowCount() : 1,
  21144. c.isArray() ? c.getRowCount() : 1,
  21145. l.isArray() ? l.getRowCount() : 1
  21146. ), h = Math.max(
  21147. u.isArray() ? u.getColumnCount() : 1,
  21148. c.isArray() ? c.getColumnCount() : 1,
  21149. l.isArray() ? l.getColumnCount() : 1
  21150. );
  21151. if (u = u, c = c, l = l, f === 1 && h === 1)
  21152. return this._calculateSingleCell(e, u, c, l);
  21153. {
  21154. const d = O(f, h, u, g.create(m.NA)), _ = O(f, h, c, g.create(m.NA)), C = O(f, h, l, g.create(m.NA));
  21155. return d.map((E, b, R) => {
  21156. const p = _.get(b, R) || ie.create(), N = C.get(b, R) || ie.create(), M = this._calculateSingleCell(e, E, p, N);
  21157. return M.isReferenceObject() ? M.toArrayValueObject().getFirstCell() : M;
  21158. });
  21159. }
  21160. }
  21161. _calculateSingleCell(e, t, r, n) {
  21162. if (t.isError())
  21163. return t;
  21164. const s = this._getNumberValue(t);
  21165. if (s === void 0 || s < 0)
  21166. return g.create(m.VALUE);
  21167. if (r.isError())
  21168. return r;
  21169. const o = this._getNumberValue(r);
  21170. if (o === void 0 || o < 0)
  21171. return g.create(m.VALUE);
  21172. if (n.isError())
  21173. return n;
  21174. const u = this._getAreaNumberValue(n);
  21175. return u === void 0 || u < 1 ? g.create(m.VALUE) : e.isReferenceObject() ? this._getReferenceObject(e, s, o, u) : e.isValueObject() && s === 1 && o === 1 ? e : g.create(m.REF);
  21176. }
  21177. _getNumberValue(e) {
  21178. if (e == null)
  21179. return 0;
  21180. let t = 0;
  21181. if (e.isBoolean())
  21182. e.getValue() === !0 && (t = 1);
  21183. else {
  21184. if (e.isString())
  21185. return;
  21186. e.isNumber() ? t = Math.floor(e.getValue()) : e.isNull() && (t = 0);
  21187. }
  21188. return t;
  21189. }
  21190. _getAreaNumberValue(e) {
  21191. if (e == null)
  21192. return 1;
  21193. let t = 0;
  21194. if (e.isBoolean())
  21195. e.getValue() === !0 && (t = 1);
  21196. else {
  21197. if (e.isString())
  21198. return;
  21199. e.isNumber() ? t = Math.floor(e.getValue()) : e.isNull() && (t = 0);
  21200. }
  21201. return t;
  21202. }
  21203. _getReferenceObject(e, t, r, n) {
  21204. const { startRow: s, endRow: o, startColumn: u, endColumn: c } = e.getRangePosition();
  21205. let l = 0, f = 0, h = 0, d = 0;
  21206. if (t === 0 ? (l = s, f = o) : l = f = s + t - 1, r === 0 ? (h = u, d = c) : h = d = u + r - 1, l > o || h > c)
  21207. return g.create(m.REF);
  21208. const _ = {
  21209. startRow: l,
  21210. startColumn: h,
  21211. endRow: f,
  21212. endColumn: d
  21213. };
  21214. return this.createReferenceObject(e, _);
  21215. }
  21216. }
  21217. class Td extends V {
  21218. constructor() {
  21219. super(...arguments);
  21220. A(this, "minParams", 1);
  21221. A(this, "maxParams", 2);
  21222. }
  21223. isAddress() {
  21224. return !0;
  21225. }
  21226. calculate(e, t) {
  21227. if (e.isError())
  21228. return e;
  21229. if (t != null && t.isError())
  21230. return t;
  21231. let r = this.getZeroOrOneByOneDefault(t);
  21232. r == null && (r = 1);
  21233. let n = e;
  21234. if (e.isArray()) {
  21235. const s = e.getRowCount(), o = e.getColumnCount();
  21236. if (s > 1 || o > 1)
  21237. return e.map(() => g.create(m.VALUE));
  21238. n = e.getFirstCell();
  21239. }
  21240. return this._handleSingleObject(n, r);
  21241. }
  21242. _handleSingleObject(e, t) {
  21243. const r = `${e.getValue()}`;
  21244. if (r.trim() === "")
  21245. return g.create(m.REF);
  21246. const n = this._convertToDefinedName(r);
  21247. if (t === 0) {
  21248. const f = Ih(n), { range: h, sheetName: d, unitId: _ } = f, C = new Cn(h);
  21249. return C.setForcedUnitIdDirect(_), C.setForcedSheetName(d), this._setDefault(C);
  21250. }
  21251. if (vr(n))
  21252. return this._setDefault(new da(n));
  21253. if (Hi(n))
  21254. return this._setDefault(new _a(n));
  21255. if (Gi(n))
  21256. return this._setDefault(new Ca(n));
  21257. const s = mr(n), { range: o, sheetName: u, unitId: c } = s;
  21258. if (Number.isNaN(o.startRow) || o.endRow + 1 > 1048576 || Number.isNaN(o.startColumn) || o.endColumn + 1 > 16384)
  21259. return g.create(m.REF);
  21260. const l = new Cn(o);
  21261. return l.setForcedUnitIdDirect(c), l.setForcedSheetName(u), this._setDefault(l);
  21262. }
  21263. _setDefault(e) {
  21264. return this.unitId == null || this.subUnitId == null ? g.create(m.REF) : (e.setDefaultUnitId(this.unitId), e.setDefaultSheetId(this.subUnitId), e);
  21265. }
  21266. /**
  21267. * In Excel, to inject a defined name into a function that has positioning capabilities,
  21268. * such as using the INDIRECT function to reference a named range,
  21269. * you can write it as follows:
  21270. * =INDIRECT("DefinedName1")
  21271. */
  21272. _convertToDefinedName(e) {
  21273. const t = this.getDefinedName(e);
  21274. if (t == null)
  21275. return e;
  21276. const r = t.formulaOrRefString;
  21277. return r == null ? e : r.startsWith(X.EQUALS) ? r.slice(1) : r;
  21278. }
  21279. }
  21280. class Bd extends V {
  21281. constructor() {
  21282. super(...arguments);
  21283. A(this, "minParams", 2);
  21284. A(this, "maxParams", 3);
  21285. A(this, "needsExpandParams", !0);
  21286. }
  21287. calculate(e, t, r) {
  21288. return e.isError() ? e : t.isError() ? g.create(m.REF) : t.isArray() ? r != null && r.isError() ? r : t.getColumnCount() === 1 || t.getRowCount() === 1 ? r != null && !r.isArray() ? g.create(m.REF) : this._handleVector(e, t, r) : this._handleArray(e, t) : g.create(m.VALUE);
  21289. }
  21290. _handleVector(e, t, r) {
  21291. let n = r;
  21292. if (n == null)
  21293. n = t;
  21294. else if (n.getRowCount() !== t.getRowCount() || n.getColumnCount() !== t.getColumnCount())
  21295. return g.create(m.REF);
  21296. return e.isArray() ? e.map((s) => this.binarySearch(s, t, n)) : this.binarySearch(e, t, n);
  21297. }
  21298. _handleArray(e, t) {
  21299. const r = t.getRowCount(), n = t.getColumnCount();
  21300. let s, o;
  21301. return n > r ? (s = t.slice([0, 1]), o = t.slice([r - 1, r])) : (s = t.slice(void 0, [0, 1]), o = t.slice(void 0, [n - 1, n])), s == null || o == null ? g.create(m.VALUE) : e.isArray() ? e.map((u) => this.binarySearch(u, s, o)) : this.binarySearch(e, s, o);
  21302. }
  21303. }
  21304. class Id extends V {
  21305. constructor() {
  21306. super(...arguments);
  21307. A(this, "minParams", 2);
  21308. A(this, "maxParams", 3);
  21309. }
  21310. calculate(e, t, r) {
  21311. if (e.isError())
  21312. return e;
  21313. if (t.isError())
  21314. return g.create(m.REF);
  21315. if (!t.isArray())
  21316. return g.create(m.VALUE);
  21317. const n = t.getRowCount(), s = t.getColumnCount();
  21318. if (n !== 1 && s !== 1 || r != null && r.isError())
  21319. return g.create(m.NA);
  21320. const o = this.getMatchTypeValue(r);
  21321. return o == null ? g.create(m.VALUE) : e.isArray() ? e.map((u) => this._handleSingleObject(
  21322. u,
  21323. t,
  21324. o
  21325. )) : this._handleSingleObject(
  21326. e,
  21327. t,
  21328. o
  21329. );
  21330. }
  21331. _handleSingleObject(e, t, r) {
  21332. const n = this._getSearchModeValue(r), s = t.orderSearch(e, n);
  21333. if (s == null)
  21334. return g.create(m.NA);
  21335. if (s instanceof g)
  21336. return s;
  21337. const o = t.getRowCount() === 1 ? s.column + 1 : s.row + 1;
  21338. return y.create(o);
  21339. }
  21340. _getSearchModeValue(e) {
  21341. switch (e) {
  21342. case 1:
  21343. return Pe.MIN;
  21344. case 0:
  21345. return Pe.NORMAL;
  21346. case -1:
  21347. return Pe.MAX;
  21348. }
  21349. }
  21350. }
  21351. class Fd extends V {
  21352. constructor() {
  21353. super(...arguments);
  21354. A(this, "minParams", 3);
  21355. A(this, "maxParams", 5);
  21356. A(this, "needsReferenceObject", !0);
  21357. }
  21358. isAddress() {
  21359. return !0;
  21360. }
  21361. // eslint-disable-next-line max-lines-per-function, complexity
  21362. calculate(e, t, r, n, s) {
  21363. if (e.isError())
  21364. return e;
  21365. if (t.isError())
  21366. return t;
  21367. if (r.isError())
  21368. return r;
  21369. if (n != null && n.isError())
  21370. return n;
  21371. if (s != null && s.isError())
  21372. return s;
  21373. if (!e.isReferenceObject())
  21374. return g.create(m.VALUE);
  21375. const o = e.getRowCount(), u = e.getColumnCount();
  21376. let c = t;
  21377. c.isReferenceObject() && (c = c.toArrayValueObject());
  21378. let l = r;
  21379. l.isReferenceObject() && (l = l.toArrayValueObject());
  21380. let f = n != null ? n : y.create(o);
  21381. f.isReferenceObject() && (f = f.toArrayValueObject()), f.isNull() && (f = y.create(o));
  21382. let h = s != null ? s : y.create(u);
  21383. h.isReferenceObject() && (h = h.toArrayValueObject()), h.isNull() && (h = y.create(u));
  21384. const d = Math.max(
  21385. c.isArray() ? c.getRowCount() : 1,
  21386. l.isArray() ? l.getRowCount() : 1,
  21387. f.isArray() ? f.getRowCount() : 1,
  21388. h.isArray() ? h.getRowCount() : 1
  21389. ), _ = Math.max(
  21390. c.isArray() ? c.getColumnCount() : 1,
  21391. l.isArray() ? l.getColumnCount() : 1,
  21392. f.isArray() ? f.getColumnCount() : 1,
  21393. h.isArray() ? h.getColumnCount() : 1
  21394. );
  21395. if (c = c, l = l, f = f, h = h, d === 1 && _ === 1)
  21396. return c = c.isArray() ? c.get(0, 0) : c, l = l.isArray() ? l.get(0, 0) : l, f = f.isArray() ? f.get(0, 0) : f, h = h.isArray() ? h.get(0, 0) : h, this._handleSingleObject(e, c, l, f, h);
  21397. const C = O(d, _, c, g.create(m.NA)), E = O(d, _, l, g.create(m.NA)), b = O(d, _, f, g.create(m.NA)), R = O(d, _, h, g.create(m.NA));
  21398. return C.mapValue((p, N, M) => {
  21399. const w = E.get(N, M), D = b.get(N, M), S = R.get(N, M);
  21400. return p.isError() ? p : w.isError() ? w : D.isError() ? D : S.isError() ? S : this._handleSingleObject(e, p, w, D, S, !0);
  21401. });
  21402. }
  21403. // eslint-disable-next-line
  21404. _handleSingleObject(e, t, r, n, s, o = !1) {
  21405. const { startRow: u, startColumn: c } = e.getRangePosition();
  21406. let l = t;
  21407. if (l.isString() && (l = l.convertToNumberObjectValue()), l.isError())
  21408. return l;
  21409. let f = r;
  21410. if (f.isString() && (f = f.convertToNumberObjectValue()), f.isError())
  21411. return f;
  21412. const h = +l.getValue(), d = +f.getValue();
  21413. if (typeof h != "number" || typeof d != "number")
  21414. return g.create(m.VALUE);
  21415. const _ = u + h, C = c + d;
  21416. if (_ < 0 || C < 0)
  21417. return g.create(m.REF);
  21418. const E = this.getIndexNumValue(n), b = this.getIndexNumValue(s);
  21419. if (typeof E != "number" || typeof b != "number")
  21420. return g.create(m.VALUE);
  21421. if (E === 0 || b === 0)
  21422. return g.create(m.REF);
  21423. const R = E > 0 ? _ + E - 1 : _ + E + 1, p = b > 0 ? C + b - 1 : C + b + 1;
  21424. if (R < 0 || p < 0)
  21425. return g.create(m.REF);
  21426. if (o)
  21427. return g.create(m.VALUE);
  21428. const N = _ < R ? _ : R, M = C < p ? C : p, w = _ > R ? _ : R, D = C > p ? C : p, S = {
  21429. startRow: N,
  21430. startColumn: M,
  21431. endRow: w,
  21432. endColumn: D
  21433. };
  21434. return this.createReferenceObject(e, S);
  21435. }
  21436. }
  21437. class kd extends V {
  21438. constructor() {
  21439. super(...arguments);
  21440. A(this, "minParams", 0);
  21441. A(this, "maxParams", 1);
  21442. }
  21443. calculate(e) {
  21444. if (e == null)
  21445. return y.create(this.row + 1);
  21446. if (e.isError())
  21447. return e;
  21448. if (!e.isArray())
  21449. return g.create(m.NA);
  21450. const t = e.getCurrentRow(), r = e.getRowCount(), n = [];
  21451. for (let o = 0; o < r; o++)
  21452. n.push([y.create(t + o + 1)]);
  21453. const s = {
  21454. calculateValueList: n,
  21455. rowCount: r,
  21456. columnCount: 1,
  21457. unitId: this.unitId || "",
  21458. sheetId: this.subUnitId || "",
  21459. row: this.row,
  21460. column: this.column
  21461. };
  21462. return q.create(s);
  21463. }
  21464. }
  21465. class $d extends V {
  21466. constructor() {
  21467. super(...arguments);
  21468. A(this, "minParams", 1);
  21469. A(this, "maxParams", 1);
  21470. }
  21471. calculate(e) {
  21472. if (e.isError())
  21473. return e;
  21474. if (e.isString() || e.isNumber() || e.isBoolean())
  21475. return y.create(1);
  21476. if (!e.isArray())
  21477. return g.create(m.NA);
  21478. const t = e.getRowCount();
  21479. return y.create(t);
  21480. }
  21481. }
  21482. class Yd extends V {
  21483. constructor() {
  21484. super(...arguments);
  21485. A(this, "minParams", 1);
  21486. A(this, "maxParams", 4);
  21487. }
  21488. calculate(e, t, r, n) {
  21489. const s = t != null ? t : y.create(1), o = r != null ? r : y.create(1), u = n != null ? n : T.create(!1);
  21490. if (u.isArray()) {
  21491. const c = u.getRowCount(), l = u.getColumnCount();
  21492. if (c === 1 && l === 1) {
  21493. const f = u.get(0, 0);
  21494. return this._handleSingleObject(e, s, o, f);
  21495. }
  21496. return u.map((f) => {
  21497. const h = this._handleSingleObject(e, s, o, f);
  21498. return h.isArray() ? h.get(0, 0) : h;
  21499. });
  21500. }
  21501. return this._handleSingleObject(e, s, o, u);
  21502. }
  21503. _handleSingleObject(e, t, r, n) {
  21504. if (e.isError())
  21505. return e;
  21506. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = this._checkArrayError(t);
  21507. if (u.isError())
  21508. return u;
  21509. const c = Math.floor(+u.getValue());
  21510. if (c < 1)
  21511. return g.create(m.VALUE);
  21512. const l = this._checkArrayError(r);
  21513. if (l.isError())
  21514. return l;
  21515. const f = Math.floor(+l.getValue());
  21516. if (f !== -1 && f !== 1)
  21517. return g.create(m.VALUE);
  21518. let h = n;
  21519. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  21520. return h;
  21521. if (!e.isArray() || s === 1 && o === 1)
  21522. return e;
  21523. const d = +h.getValue();
  21524. return this._getResult(e, c, f, d, s, o);
  21525. }
  21526. _checkArrayError(e) {
  21527. let t = e;
  21528. if (t.isArray()) {
  21529. const r = t.getRowCount(), n = t.getColumnCount();
  21530. if (r > 1 || n > 1)
  21531. return g.create(m.VALUE);
  21532. t = t.get(0, 0);
  21533. }
  21534. return t.isString() && (t = t.convertToNumberObjectValue()), t;
  21535. }
  21536. _getResult(e, t, r, n, s, o) {
  21537. if (n) {
  21538. if (t > s)
  21539. return g.create(m.VALUE);
  21540. const u = e.transpose().getArrayValue();
  21541. return u.sort(this._sort(t - 1, r)), q.create({
  21542. calculateValueList: u,
  21543. rowCount: u.length,
  21544. columnCount: u[0].length || 0,
  21545. unitId: this.unitId,
  21546. sheetId: this.subUnitId,
  21547. row: this.row,
  21548. column: this.column
  21549. }).transpose();
  21550. } else {
  21551. if (t > o)
  21552. return g.create(m.VALUE);
  21553. const u = e.getArrayValue();
  21554. return u.sort(this._sort(t - 1, r)), q.create({
  21555. calculateValueList: u,
  21556. rowCount: u.length,
  21557. columnCount: u[0].length || 0,
  21558. unitId: this.unitId,
  21559. sheetId: this.subUnitId,
  21560. row: this.row,
  21561. column: this.column
  21562. });
  21563. }
  21564. }
  21565. _sort(e, t = 1) {
  21566. const r = hn();
  21567. return t === 1 ? this._sortAsc(e, r) : this._sortDesc(e, r);
  21568. }
  21569. _sortAsc(e, t) {
  21570. return (r, n) => {
  21571. const s = r[e], o = n[e];
  21572. if (s == null || s.isNull())
  21573. return 1;
  21574. if (o == null || o.isNull())
  21575. return -1;
  21576. if (s.isError() && o.isError())
  21577. return 0;
  21578. if (s.isError())
  21579. return 1;
  21580. if (o.isError())
  21581. return -1;
  21582. const u = s.getValue(), c = o.getValue();
  21583. return s.isBoolean() && u === !0 ? 1 : o.isBoolean() && c === !0 ? -1 : s.isBoolean() && u === !1 ? 1 : o.isBoolean() && c === !1 ? -1 : s.isNumber() && o.isNumber() ? +u - +c : t(
  21584. u,
  21585. c
  21586. );
  21587. };
  21588. }
  21589. _sortDesc(e, t) {
  21590. return (r, n) => {
  21591. const s = r[e], o = n[e];
  21592. if (s == null || s.isNull())
  21593. return 1;
  21594. if (o == null || o.isNull())
  21595. return -1;
  21596. if (s.isError() && o.isError())
  21597. return 0;
  21598. if (s.isError())
  21599. return -1;
  21600. if (o.isError())
  21601. return 1;
  21602. const u = s.getValue(), c = o.getValue();
  21603. return s.isBoolean() && u === !0 ? -1 : o.isBoolean() && c === !0 ? 1 : s.isBoolean() && u === !1 ? -1 : o.isBoolean() && c === !1 ? 1 : s.isNumber() && o.isNumber() ? +c - +u : t(
  21604. c,
  21605. u
  21606. );
  21607. };
  21608. }
  21609. }
  21610. class Hd extends V {
  21611. constructor() {
  21612. super(...arguments);
  21613. A(this, "minParams", 2);
  21614. A(this, "maxParams", 255);
  21615. }
  21616. calculate(e, ...t) {
  21617. t.length === 1 && t.push(y.create(1));
  21618. const r = this._getVariantsError(e, ...t), { maxRowLength: n, maxColumnLength: s } = Nr(t);
  21619. if (r.isError()) {
  21620. const c = O(n, s, r);
  21621. return n === 1 && s === 1 ? c.get(0, 0) : c;
  21622. }
  21623. const o = t.map((c, l) => l % 2 === 0 ? c : O(n, s, c, g.create(m.NA))), u = this._getResultArray(e, o, n, s);
  21624. return n === 1 && s === 1 ? u[0][0] : q.create({
  21625. calculateValueList: u,
  21626. rowCount: u.length,
  21627. columnCount: u[0].length || 0,
  21628. unitId: this.unitId,
  21629. sheetId: this.subUnitId,
  21630. row: this.row,
  21631. column: this.column
  21632. });
  21633. }
  21634. // eslint-disable-next-line complexity
  21635. _getVariantsError(e, ...t) {
  21636. if (e.isError())
  21637. return e;
  21638. for (let u = 0; u < t.length; u++) {
  21639. const c = t[u];
  21640. if (c.isError())
  21641. return c;
  21642. }
  21643. if (t.length < 2 || t.length % 2 !== 0)
  21644. return g.create(m.VALUE);
  21645. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t[0].isArray() ? t[0].getRowCount() : 1, o = t[0].isArray() ? t[0].getColumnCount() : 1;
  21646. if ((s > 1 || o > 1) && (s > 1 && o > 1 || s === 1 && o !== n || o === 1 && s !== r))
  21647. return g.create(m.VALUE);
  21648. for (let u = 2; u < t.length; u++) {
  21649. if (u % 2 === 1)
  21650. continue;
  21651. const c = t[u].isArray() ? t[u].getRowCount() : 1, l = t[u].isArray() ? t[u].getColumnCount() : 1;
  21652. if (c !== s || l !== o)
  21653. return g.create(m.VALUE);
  21654. }
  21655. return T.create(!0);
  21656. }
  21657. _getResultArray(e, t, r, n) {
  21658. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = t[0].isArray() ? t[0].getRowCount() : 1, c = t[0].isArray() ? t[0].getColumnCount() : 1, l = [];
  21659. for (let f = 0; f < r; f++) {
  21660. l[f] = [];
  21661. for (let h = 0; h < n; h++) {
  21662. const { isError: d, errorObject: _, byArrays: C, sortOrders: E } = this._getByArraysAndSortOrders(t, f, h, c);
  21663. if (d) {
  21664. l[f].push(_);
  21665. continue;
  21666. }
  21667. if (!e.isArray() || s === 1 && o === 1) {
  21668. l[f].push(e);
  21669. continue;
  21670. }
  21671. let b = e.getArrayValue();
  21672. u === 1 && c === 1 || (u === 1 ? (b = b.concat(C), b = this._transposeArray(b), b.sort(this._sort(s, E)), b = this._transposeArray(b).slice(0, s)) : c === 1 && (b = this._transposeArray(b), b = b.concat(C), b = this._transposeArray(b), b.sort(this._sort(o, E)), b = b.map((p) => p.slice(0, o))));
  21673. const R = q.create({
  21674. calculateValueList: b,
  21675. rowCount: b.length,
  21676. columnCount: b[0].length || 0,
  21677. unitId: this.unitId,
  21678. sheetId: this.subUnitId,
  21679. row: this.row,
  21680. column: this.column
  21681. });
  21682. if (r > 1 || n > 1) {
  21683. l[f].push(R.get(0, 0));
  21684. continue;
  21685. }
  21686. l[f].push(R);
  21687. }
  21688. }
  21689. return l;
  21690. }
  21691. _getByArraysAndSortOrders(e, t, r, n) {
  21692. const s = [], o = [];
  21693. let u = !1, c = null;
  21694. for (let l = 0; l < e.length; l++) {
  21695. if (l % 2 === 1)
  21696. continue;
  21697. const f = e[l];
  21698. let h = e[l + 1].get(t, r);
  21699. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError()) {
  21700. u = !0, c = h;
  21701. break;
  21702. }
  21703. const d = Math.floor(+h.getValue());
  21704. if (d !== -1 && d !== 1) {
  21705. u = !0, c = g.create(m.VALUE);
  21706. break;
  21707. }
  21708. if (o.push(d), f.isArray()) {
  21709. let _ = f.getArrayValue();
  21710. n === 1 && (_ = this._transposeArray(_)), s.push(_[0]);
  21711. } else
  21712. s.push([f]);
  21713. }
  21714. return {
  21715. isError: u,
  21716. errorObject: c,
  21717. byArrays: s,
  21718. sortOrders: o
  21719. };
  21720. }
  21721. _transposeArray(e) {
  21722. const t = e.length, r = e[0].length, n = [];
  21723. for (let s = 0; s < r; s++) {
  21724. n[s] = [];
  21725. for (let o = 0; o < t; o++)
  21726. n[s][o] = e[o][s];
  21727. }
  21728. return n;
  21729. }
  21730. _sort(e, t) {
  21731. const r = hn();
  21732. return (n, s) => {
  21733. let o = n[e], u = s[e], c = this._compare(o, u, t[0], r);
  21734. if (c === 0 && t.length > 1) {
  21735. for (let l = 1; l < t.length; l++)
  21736. if (o = n[e + l], u = s[e + l], c = this._compare(o, u, t[l], r), c !== 0)
  21737. return c;
  21738. }
  21739. return c;
  21740. };
  21741. }
  21742. _compare(e, t, r, n) {
  21743. return r === 1 ? this._asc(e, t, n) : this._desc(e, t, n);
  21744. }
  21745. _asc(e, t, r) {
  21746. if (e == null || e.isNull())
  21747. return 1;
  21748. if (t == null || t.isNull())
  21749. return -1;
  21750. if (e.isError() && t.isError())
  21751. return 0;
  21752. if (e.isError())
  21753. return 1;
  21754. if (t.isError())
  21755. return -1;
  21756. const n = e.getValue(), s = t.getValue();
  21757. return e.isBoolean() && n === !0 ? 1 : t.isBoolean() && s === !0 ? -1 : e.isBoolean() && n === !1 ? 1 : t.isBoolean() && s === !1 ? -1 : e.isNumber() && t.isNumber() ? +n - +s : r(
  21758. n,
  21759. s
  21760. );
  21761. }
  21762. _desc(e, t, r) {
  21763. if (e == null || e.isNull())
  21764. return 1;
  21765. if (t == null || t.isNull())
  21766. return -1;
  21767. if (e.isError() && t.isError())
  21768. return 0;
  21769. if (e.isError())
  21770. return -1;
  21771. if (t.isError())
  21772. return 1;
  21773. const n = e.getValue(), s = t.getValue();
  21774. return e.isBoolean() && n === !0 ? -1 : t.isBoolean() && s === !0 ? 1 : e.isBoolean() && n === !1 ? -1 : t.isBoolean() && s === !1 ? 1 : e.isNumber() && t.isNumber() ? +s - +n : r(
  21775. s,
  21776. n
  21777. );
  21778. }
  21779. }
  21780. class Gd extends V {
  21781. constructor() {
  21782. super(...arguments);
  21783. A(this, "minParams", 2);
  21784. A(this, "maxParams", 3);
  21785. }
  21786. calculate(e, t, r) {
  21787. const n = e.isArray() ? e.getRowCount() : 1, s = e.isArray() ? e.getColumnCount() : 1;
  21788. let o = t, u = r != null ? r : y.create(s);
  21789. t.isNull() && (o = y.create(n)), u.isNull() && (u = y.create(s));
  21790. const c = Math.max(
  21791. o.isArray() ? o.getRowCount() : 1,
  21792. u.isArray() ? u.getRowCount() : 1
  21793. ), l = Math.max(
  21794. o.isArray() ? o.getColumnCount() : 1,
  21795. u.isArray() ? u.getColumnCount() : 1
  21796. ), f = O(c, l, o, g.create(m.NA)), h = O(c, l, u, g.create(m.NA));
  21797. if (c > 1 || l > 1)
  21798. return f.mapValue((p, N, M) => {
  21799. const w = h.get(N, M);
  21800. if (e.isError())
  21801. return e;
  21802. if (e.isNull())
  21803. return g.create(m.VALUE);
  21804. const { isError: D, errorObject: S } = this._checkRowsColumns(p, w, n, s);
  21805. return D ? S : e.isArray() ? g.create(m.VALUE) : e;
  21806. });
  21807. if (e.isError())
  21808. return e;
  21809. if (e.isNull())
  21810. return g.create(m.VALUE);
  21811. const d = o.isArray() ? o.get(0, 0) : o, _ = u.isArray() ? u.get(0, 0) : u, { isError: C, errorObject: E, rowsValue: b, columnsValue: R } = this._checkRowsColumns(d, _, n, s);
  21812. return C ? E : this._getResultArray(e, b, R, n, s);
  21813. }
  21814. _checkRowsColumns(e, t, r, n) {
  21815. if (e.isError())
  21816. return {
  21817. isError: !0,
  21818. errorObject: e
  21819. };
  21820. if (t.isError())
  21821. return {
  21822. isError: !0,
  21823. errorObject: t
  21824. };
  21825. let s = Math.trunc(+e.getValue()), o = Math.trunc(+t.getValue());
  21826. return Number.isNaN(s) || Number.isNaN(o) ? {
  21827. isError: !0,
  21828. errorObject: g.create(m.VALUE)
  21829. } : Math.abs(s) === 0 || Math.abs(o) === 0 ? {
  21830. isError: !0,
  21831. errorObject: g.create(m.CALC)
  21832. } : (s > r && (s = r), o > n && (o = n), {
  21833. isError: !1,
  21834. rowsValue: s,
  21835. columnsValue: o
  21836. });
  21837. }
  21838. _getResultArray(e, t, r, n, s) {
  21839. if (!e.isArray())
  21840. return e;
  21841. const o = t >= 0 ? [0, t] : [n + t, n], u = r >= 0 ? [0, r] : [s + r, s];
  21842. let c;
  21843. return t === n && r === s ? c = e : t === n ? c = e.slice(void 0, u) : r === s ? c = e.slice(o, void 0) : c = e.slice(o, u), c = c.map((l) => l.isNull() ? y.create(0) : l), t === 1 && r === 1 ? c.get(0, 0) : c;
  21844. }
  21845. }
  21846. class Qd extends V {
  21847. constructor() {
  21848. super(...arguments);
  21849. A(this, "minParams", 1);
  21850. A(this, "maxParams", 3);
  21851. }
  21852. calculate(e, t, r) {
  21853. const n = t != null ? t : y.create(0), s = r != null ? r : T.create(!1), o = Math.max(
  21854. n.isArray() ? n.getRowCount() : 1,
  21855. s.isArray() ? s.getRowCount() : 1
  21856. ), u = Math.max(
  21857. n.isArray() ? n.getColumnCount() : 1,
  21858. s.isArray() ? s.getColumnCount() : 1
  21859. ), c = O(o, u, n, g.create(m.NA)), l = O(o, u, s, g.create(m.NA)), f = c.mapValue((h, d, _) => {
  21860. const C = l.get(d, _);
  21861. if (e.isError())
  21862. return e;
  21863. if (e.isNull())
  21864. return g.create(m.VALUE);
  21865. if (h.isError())
  21866. return h;
  21867. if (C.isError())
  21868. return C;
  21869. const E = Math.trunc(+h.getValue()), b = +C.getValue();
  21870. if (Number.isNaN(E) || E < 0 || E > 3 || Number.isNaN(b))
  21871. return g.create(m.VALUE);
  21872. if (!e.isArray())
  21873. return e;
  21874. let R = [];
  21875. return b ? R = this._getArrayValueByColumn(e, E) : R = this._getArrayValueByRow(e, E), R.length === 0 ? g.create(m.CALC) : o > 1 || u > 1 || R.length === 1 ? R[0] : q.create({
  21876. calculateValueList: R.map((p) => [p]),
  21877. rowCount: R.length,
  21878. columnCount: 1,
  21879. unitId: this.unitId,
  21880. sheetId: this.subUnitId,
  21881. row: this.row,
  21882. column: this.column
  21883. });
  21884. });
  21885. return o === 1 && u === 1 ? f.get(0, 0) : f;
  21886. }
  21887. _getArrayValueByColumn(e, t) {
  21888. const r = e, n = r.getRowCount(), s = r.getColumnCount(), o = [];
  21889. for (let u = 0; u < s; u++)
  21890. for (let c = 0; c < n; c++) {
  21891. const l = r.get(c, u);
  21892. this._isIgnore(l, t) || o.push(l.isNull() ? y.create(0) : l);
  21893. }
  21894. return o;
  21895. }
  21896. _getArrayValueByRow(e, t) {
  21897. const r = e, n = r.getRowCount(), s = r.getColumnCount(), o = [];
  21898. for (let u = 0; u < n; u++)
  21899. for (let c = 0; c < s; c++) {
  21900. const l = r.get(u, c);
  21901. this._isIgnore(l, t) || o.push(l.isNull() ? y.create(0) : l);
  21902. }
  21903. return o;
  21904. }
  21905. _isIgnore(e, t) {
  21906. switch (t) {
  21907. case 0:
  21908. return !1;
  21909. case 1:
  21910. return e.isNull();
  21911. case 2:
  21912. return e.isError();
  21913. case 3:
  21914. return e.isNull() || e.isError();
  21915. default:
  21916. return !1;
  21917. }
  21918. }
  21919. }
  21920. class Wd extends V {
  21921. constructor() {
  21922. super(...arguments);
  21923. A(this, "minParams", 1);
  21924. A(this, "maxParams", 3);
  21925. }
  21926. calculate(e, t, r) {
  21927. const n = t != null ? t : y.create(0), s = r != null ? r : T.create(!1), o = Math.max(
  21928. n.isArray() ? n.getRowCount() : 1,
  21929. s.isArray() ? s.getRowCount() : 1
  21930. ), u = Math.max(
  21931. n.isArray() ? n.getColumnCount() : 1,
  21932. s.isArray() ? s.getColumnCount() : 1
  21933. ), c = O(o, u, n, g.create(m.NA)), l = O(o, u, s, g.create(m.NA)), f = c.mapValue((h, d, _) => {
  21934. const C = l.get(d, _);
  21935. if (e.isError())
  21936. return e;
  21937. if (h.isError())
  21938. return h;
  21939. if (C.isError())
  21940. return C;
  21941. const E = Math.trunc(+h.getValue()), b = +C.getValue();
  21942. if (Number.isNaN(E) || E < 0 || E > 3 || Number.isNaN(b) || e.isNull())
  21943. return g.create(m.VALUE);
  21944. if (!e.isArray())
  21945. return e;
  21946. let R = [];
  21947. return b ? R = this._getArrayValueByColumn(e, E) : R = this._getArrayValueByRow(e, E), R.length === 0 ? g.create(m.CALC) : o > 1 || u > 1 || R.length === 1 ? R[0] : q.create({
  21948. calculateValueList: [R],
  21949. rowCount: 1,
  21950. columnCount: R.length,
  21951. unitId: this.unitId,
  21952. sheetId: this.subUnitId,
  21953. row: this.row,
  21954. column: this.column
  21955. });
  21956. });
  21957. return o === 1 && u === 1 ? f.get(0, 0) : f;
  21958. }
  21959. _getArrayValueByColumn(e, t) {
  21960. const r = e, n = r.getRowCount(), s = r.getColumnCount(), o = [];
  21961. for (let u = 0; u < s; u++)
  21962. for (let c = 0; c < n; c++) {
  21963. const l = r.get(c, u);
  21964. this._isIgnore(l, t) || o.push(l.isNull() ? y.create(0) : l);
  21965. }
  21966. return o;
  21967. }
  21968. _getArrayValueByRow(e, t) {
  21969. const r = e, n = r.getRowCount(), s = r.getColumnCount(), o = [];
  21970. for (let u = 0; u < n; u++)
  21971. for (let c = 0; c < s; c++) {
  21972. const l = r.get(u, c);
  21973. this._isIgnore(l, t) || o.push(l.isNull() ? y.create(0) : l);
  21974. }
  21975. return o;
  21976. }
  21977. _isIgnore(e, t) {
  21978. switch (t) {
  21979. case 0:
  21980. return !1;
  21981. case 1:
  21982. return e.isNull();
  21983. case 2:
  21984. return e.isError();
  21985. case 3:
  21986. return e.isNull() || e.isError();
  21987. default:
  21988. return !1;
  21989. }
  21990. }
  21991. }
  21992. class qd extends V {
  21993. constructor() {
  21994. super(...arguments);
  21995. A(this, "minParams", 1);
  21996. A(this, "maxParams", 1);
  21997. }
  21998. calculate(e) {
  21999. if (e.isError())
  22000. return e;
  22001. if (e.isArray()) {
  22002. const t = e.getRowCount(), r = e.getColumnCount();
  22003. return t === 1 && r === 1 ? e.get(0, 0) : e.transpose();
  22004. }
  22005. return e;
  22006. }
  22007. }
  22008. class Kd extends V {
  22009. constructor() {
  22010. super(...arguments);
  22011. A(this, "minParams", 1);
  22012. A(this, "maxParams", 3);
  22013. }
  22014. calculate(e, t, r) {
  22015. const n = t != null ? t : T.create(!1), s = r != null ? r : T.create(!1), o = e.isArray() ? e.getRowCount() : 1, u = e.isArray() ? e.getColumnCount() : 1, c = Math.max(
  22016. n.isArray() ? n.getRowCount() : 1,
  22017. s.isArray() ? s.getRowCount() : 1
  22018. ), l = Math.max(
  22019. n.isArray() ? n.getColumnCount() : 1,
  22020. s.isArray() ? s.getColumnCount() : 1
  22021. ), f = O(c, l, n, g.create(m.NA)), h = O(c, l, s, g.create(m.NA)), d = f.map((_, C, E) => {
  22022. let b = _, R = h.get(C, E);
  22023. if (e.isError())
  22024. return e;
  22025. if (b.isString() && (b = b.convertToNumberObjectValue()), b.isError())
  22026. return b;
  22027. if (R.isString() && (R = R.convertToNumberObjectValue()), R.isError())
  22028. return R;
  22029. const p = +b.getValue(), N = +R.getValue();
  22030. let M;
  22031. return !p && o === 1 || p && u === 1 ? M = e : M = this._getResult(e, p, N), (c > 1 || l > 1) && (M != null && M.isArray()) ? M.get(0, 0) : M;
  22032. });
  22033. return c === 1 && l === 1 ? d.get(0, 0) : d;
  22034. }
  22035. _getResult(e, t, r) {
  22036. const n = e.isArray() ? e.getRowCount() : 1, s = e.isArray() ? e.getColumnCount() : 1;
  22037. let o = e.getArrayValue(), u = n, c = s;
  22038. t && (o = this._transposeArray(o), u = s, c = n);
  22039. const l = this._getRepeatRows(o, u, c);
  22040. if (l.length > 0) {
  22041. const f = [];
  22042. l.forEach((h) => {
  22043. h.forEach((d, _) => {
  22044. (_ !== 0 || r) && f.push(d);
  22045. });
  22046. }), o = o.filter((h, d) => !f.includes(d));
  22047. }
  22048. return o.length === 0 ? g.create(m.CALC) : (t && (o = this._transposeArray(o)), q.create({
  22049. calculateValueList: o,
  22050. rowCount: o.length,
  22051. columnCount: o[0].length || 0,
  22052. unitId: this.unitId,
  22053. sheetId: this.subUnitId,
  22054. row: this.row,
  22055. column: this.column
  22056. }));
  22057. }
  22058. _getRepeatRows(e, t, r) {
  22059. let n = [];
  22060. for (let s = 0; s < r; s++)
  22061. if (s === 0) {
  22062. const o = new Array(t).fill(null).map((u, c) => ({
  22063. r: c,
  22064. valueObject: e[c][s]
  22065. }));
  22066. n = this._getRepeatRowsByObjects(o);
  22067. } else {
  22068. if (n.length === 0)
  22069. break;
  22070. let o = [];
  22071. n.forEach((u) => {
  22072. const c = u.map((f) => ({
  22073. r: f,
  22074. valueObject: e[f][s]
  22075. })), l = this._getRepeatRowsByObjects(c);
  22076. o = o.concat(l);
  22077. }), n = o;
  22078. }
  22079. return n;
  22080. }
  22081. _getRepeatRowsByObjects(e) {
  22082. const t = /* @__PURE__ */ new Map();
  22083. return e.forEach((r) => {
  22084. const n = r.r, s = r.valueObject;
  22085. let o = s.getValue();
  22086. if (s.isNull() ? o = null : s.isString() && Q(o) && (o = +o), !t.has(o))
  22087. t.set(o, [n]);
  22088. else {
  22089. const u = t.get(o);
  22090. u.push(n), t.set(o, u);
  22091. }
  22092. }), Array.from(t.values()).filter((r) => r.length > 1);
  22093. }
  22094. _transposeArray(e) {
  22095. const t = e.length, r = e[0].length, n = [];
  22096. for (let s = 0; s < r; s++) {
  22097. n[s] = [];
  22098. for (let o = 0; o < t; o++)
  22099. n[s][o] = e[o][s];
  22100. }
  22101. return n;
  22102. }
  22103. }
  22104. class Xd extends V {
  22105. constructor() {
  22106. super(...arguments);
  22107. A(this, "minParams", 3);
  22108. A(this, "maxParams", 4);
  22109. }
  22110. calculate(e, t, r, n) {
  22111. if (e.isError())
  22112. return e;
  22113. if (t.isError())
  22114. return t;
  22115. if (!t.isArray())
  22116. return g.create(m.VALUE);
  22117. if (r.isError())
  22118. return r;
  22119. if (n != null && n.isError())
  22120. return n;
  22121. const s = n != null ? n : T.create(!0);
  22122. return Ai(e) && Ai(s) && r.isArray() ? this._handleArrayColIndexNum(e, t, r, s) : this._handleNonArrayColIndexNum(e, t, r, s);
  22123. }
  22124. _handleArrayColIndexNum(e, t, r, n) {
  22125. const s = e.isArray() ? e.getFirstCell() : e, o = this.getZeroOrOneByOneDefault(n);
  22126. if (o == null)
  22127. return g.create(m.VALUE);
  22128. let u;
  22129. const c = [];
  22130. return r.iterator((l, f, h) => {
  22131. if (l == null)
  22132. return u = g.create(m.VALUE), !1;
  22133. const d = this._handleTableArray(s, t, l, o);
  22134. if (d.isError())
  22135. return u = d, !1;
  22136. c[f] === void 0 && (c[f] = []), c[f][h] = d;
  22137. }), u || tr(c, c.length, c[0].length, this.unitId || "", this.subUnitId || "");
  22138. }
  22139. _handleNonArrayColIndexNum(e, t, r, n) {
  22140. const s = Math.max(
  22141. e.isArray() ? e.getRowCount() : 1,
  22142. n.isArray() ? n.getRowCount() : 1
  22143. ), o = Math.max(
  22144. e.isArray() ? e.getColumnCount() : 1,
  22145. n.isArray() ? n.getColumnCount() : 1
  22146. ), u = O(s, o, e), c = O(s, o, n);
  22147. return u.map((l, f, h) => {
  22148. if (l.isError())
  22149. return l;
  22150. const d = c.get(f, h);
  22151. if (d == null)
  22152. return g.create(m.VALUE);
  22153. if (d.isError())
  22154. return d;
  22155. const _ = this.getZeroOrOneByOneDefault(d);
  22156. return _ == null ? g.create(m.VALUE) : this._handleTableArray(l, t, r, _);
  22157. });
  22158. }
  22159. _handleTableArray(e, t, r, n) {
  22160. let s = this.getIndexNumValue(r);
  22161. if (s instanceof g)
  22162. return s;
  22163. if (s = Math.floor(s), s < 1)
  22164. return g.create(m.VALUE);
  22165. const o = t.slice(void 0, [0, 1]);
  22166. if (o == null)
  22167. return g.create(m.VALUE);
  22168. const u = t.slice(void 0, [s - 1, s]);
  22169. return u == null ? g.create(m.REF) : this._handleSingleObject(e, o, u, n);
  22170. }
  22171. _handleSingleObject(e, t, r, n) {
  22172. return n === 0 ? this.equalSearch(e, t, r) : this.binarySearch(e, t, r);
  22173. }
  22174. }
  22175. class Zd extends V {
  22176. constructor() {
  22177. super(...arguments);
  22178. A(this, "minParams", 1);
  22179. A(this, "maxParams", 255);
  22180. }
  22181. calculate(...e) {
  22182. const t = Math.max(
  22183. ...e.map((n) => n.isArray() ? n.getColumnCount() : 1)
  22184. ), r = [];
  22185. for (let n = 0; n < e.length; n++) {
  22186. const s = e[n];
  22187. if (s.isError())
  22188. return s;
  22189. const o = s.isArray() ? s.getRowCount() : 1, u = s.isArray() ? s.getColumnCount() : 1;
  22190. for (let c = 0; c < o; c++) {
  22191. const l = [];
  22192. for (let f = 0; f < t; f++) {
  22193. let h = s;
  22194. s.isArray() && (h = s.get(c, f)), f > u - 1 || !h ? l.push(g.create(m.NA)) : l.push(h);
  22195. }
  22196. r.push(l);
  22197. }
  22198. }
  22199. return q.create({
  22200. calculateValueList: r,
  22201. rowCount: r.length,
  22202. columnCount: r[0].length || 0,
  22203. unitId: this.unitId,
  22204. sheetId: this.subUnitId,
  22205. row: this.row,
  22206. column: this.column
  22207. });
  22208. }
  22209. }
  22210. class zd extends V {
  22211. constructor() {
  22212. super(...arguments);
  22213. A(this, "minParams", 2);
  22214. A(this, "maxParams", 3);
  22215. }
  22216. calculate(e, t, r) {
  22217. let n = r != null ? r : g.create(m.NA);
  22218. n.isNull() && (n = g.create(m.NA));
  22219. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = Math.max(
  22220. t.isArray() ? t.getRowCount() : 1,
  22221. n.isArray() ? n.getRowCount() : 1
  22222. ), c = Math.max(
  22223. t.isArray() ? t.getColumnCount() : 1,
  22224. n.isArray() ? n.getColumnCount() : 1
  22225. ), l = O(u, c, t, g.create(m.NA)), f = O(u, c, n, g.create(m.NA)), h = l.mapValue((d, _, C) => {
  22226. const E = f.get(_, C);
  22227. if (e.isError())
  22228. return e;
  22229. if (e.isNull())
  22230. return g.create(m.VALUE);
  22231. if (d.isError())
  22232. return d;
  22233. const b = Math.trunc(+d.getValue());
  22234. if (s > 1 && o > 1 || Number.isNaN(b))
  22235. return g.create(m.VALUE);
  22236. if (b < 1)
  22237. return g.create(m.NUM);
  22238. const R = e.isArray() ? e.getArrayValue().flat() : [e], p = this._getWrapArray(R, b, E);
  22239. return u > 1 || c > 1 || p.length === 1 && p[0].length === 1 ? p[0][0] : q.create({
  22240. calculateValueList: p,
  22241. rowCount: p.length,
  22242. columnCount: p[0].length,
  22243. unitId: this.unitId,
  22244. sheetId: this.subUnitId,
  22245. row: this.row,
  22246. column: this.column
  22247. });
  22248. });
  22249. return u === 1 && c === 1 ? h.get(0, 0) : h;
  22250. }
  22251. _getWrapArray(e, t, r) {
  22252. const n = Math.ceil(e.length / t), s = n > 1 ? t : e.length, o = [];
  22253. for (let u = 0; u < n; u++)
  22254. for (let c = 0; c < s; c++) {
  22255. o[c] || (o[c] = []);
  22256. const l = u * s + c;
  22257. l < e.length ? o[c].push(e[l].isNull() ? y.create(0) : e[l]) : o[c].push(r);
  22258. }
  22259. return o;
  22260. }
  22261. }
  22262. class Jd extends V {
  22263. constructor() {
  22264. super(...arguments);
  22265. A(this, "minParams", 2);
  22266. A(this, "maxParams", 3);
  22267. }
  22268. calculate(e, t, r) {
  22269. let n = r != null ? r : g.create(m.NA);
  22270. n.isNull() && (n = g.create(m.NA));
  22271. const s = e.isArray() ? e.getRowCount() : 1, o = e.isArray() ? e.getColumnCount() : 1, u = Math.max(
  22272. t.isArray() ? t.getRowCount() : 1,
  22273. n.isArray() ? n.getRowCount() : 1
  22274. ), c = Math.max(
  22275. t.isArray() ? t.getColumnCount() : 1,
  22276. n.isArray() ? n.getColumnCount() : 1
  22277. ), l = O(u, c, t, g.create(m.NA)), f = O(u, c, n, g.create(m.NA)), h = l.mapValue((d, _, C) => {
  22278. const E = f.get(_, C);
  22279. if (e.isError())
  22280. return e;
  22281. if (e.isNull())
  22282. return g.create(m.VALUE);
  22283. if (d.isError())
  22284. return d;
  22285. const b = Math.trunc(+d.getValue());
  22286. if (s > 1 && o > 1 || Number.isNaN(b))
  22287. return g.create(m.VALUE);
  22288. if (b < 1)
  22289. return g.create(m.NUM);
  22290. const R = e.isArray() ? e.getArrayValue().flat() : [e], p = this._getWrapArray(R, b, E);
  22291. return u > 1 || c > 1 || p.length === 1 && p[0].length === 1 ? p[0][0] : q.create({
  22292. calculateValueList: p,
  22293. rowCount: p.length,
  22294. columnCount: p[0].length,
  22295. unitId: this.unitId,
  22296. sheetId: this.subUnitId,
  22297. row: this.row,
  22298. column: this.column
  22299. });
  22300. });
  22301. return u === 1 && c === 1 ? h.get(0, 0) : h;
  22302. }
  22303. _getWrapArray(e, t, r) {
  22304. const n = Math.ceil(e.length / t), s = n > 1 ? t : e.length, o = [];
  22305. for (let u = 0; u < n; u++) {
  22306. const c = [];
  22307. for (let l = 0; l < s; l++) {
  22308. const f = u * s + l;
  22309. f < e.length ? c.push(e[f].isNull() ? y.create(0) : e[f]) : c.push(r);
  22310. }
  22311. o.push(c);
  22312. }
  22313. return o;
  22314. }
  22315. }
  22316. class eC extends V {
  22317. constructor() {
  22318. super(...arguments);
  22319. A(this, "minParams", 3);
  22320. A(this, "maxParams", 6);
  22321. }
  22322. // eslint-disable-next-line
  22323. calculate(e, t, r, n, s, o) {
  22324. let u = n != null ? n : g.create(m.NA);
  22325. n != null && n.isNull() && (u = g.create(m.NA));
  22326. let c = s != null ? s : y.create(0);
  22327. s != null && s.isNull() && (c = y.create(0));
  22328. let l = o != null ? o : y.create(1);
  22329. if (o != null && o.isNull() && (l = y.create(1)), e.isError())
  22330. return e;
  22331. if (t.isError() || r.isError())
  22332. return g.create(m.REF);
  22333. if (!t.isArray() || !r.isArray())
  22334. return g.create(m.VALUE);
  22335. const f = t.getRowCount(), h = t.getColumnCount(), d = r.getRowCount(), _ = r.getColumnCount();
  22336. if (f !== 1 && h !== 1 || f === 1 && h > 1 && h !== _ || h === 1 && f > 1 && f !== d)
  22337. return g.create(m.VALUE);
  22338. if (c.isError())
  22339. return c;
  22340. if (l.isError())
  22341. return l;
  22342. const C = this.getIndexNumValue(c);
  22343. if (C instanceof g)
  22344. return C;
  22345. const E = this.getIndexNumValue(l);
  22346. return E instanceof g ? E : this._getResult(
  22347. e,
  22348. t,
  22349. r,
  22350. u,
  22351. C,
  22352. E,
  22353. f,
  22354. h,
  22355. d,
  22356. _
  22357. );
  22358. }
  22359. _getResult(e, t, r, n, s, o, u, c, l, f) {
  22360. const h = e.isArray() ? e.getRowCount() : 1, d = e.isArray() ? e.getColumnCount() : 1;
  22361. if (h > 1 || d > 1) {
  22362. let b;
  22363. return u === 1 ? b = r.slice([0, 1]) : b = r.slice(void 0, [0, 1]), b == null ? g.create(m.NA) : e.map((R) => {
  22364. const p = this._checkErrorCombination(s, o);
  22365. if (p)
  22366. return p;
  22367. const N = this._handleSingleObject(R, t, b, s, o);
  22368. return N.isError() ? n : N;
  22369. });
  22370. }
  22371. const _ = e.isArray() ? e.get(0, 0) : e;
  22372. if (c === f && u === l) {
  22373. const b = this._checkErrorCombination(s, o);
  22374. if (b)
  22375. return b;
  22376. const R = this._handleSingleObject(_, t, r, s, o);
  22377. return R.isError() ? n : R;
  22378. }
  22379. let C = 0;
  22380. c === f && (C = 1);
  22381. const E = this._handleExpandObject(_, t, r, s, o, C);
  22382. return E == null ? g.create(m.NA) : E;
  22383. }
  22384. _handleExpandObject(e, t, r, n, s, o = 0) {
  22385. if ((s === 2 || s === -2) && n !== 2) {
  22386. const u = Ps(s), c = Ss(n);
  22387. return this.binarySearchExpand(
  22388. e,
  22389. t,
  22390. r,
  22391. o,
  22392. u,
  22393. c
  22394. );
  22395. }
  22396. return n === 2 ? this.fuzzySearchExpand(e, t, r, s !== -1, o) : n === -1 || n === 1 ? this.orderSearchExpand(
  22397. e,
  22398. t,
  22399. r,
  22400. n === 1 ? Pe.MAX : Pe.MIN,
  22401. s === -1,
  22402. o
  22403. ) : this.equalSearchExpand(e, t, r, s !== -1, o);
  22404. }
  22405. _handleSingleObject(e, t, r, n, s) {
  22406. if ((s === 2 || s === -2) && n !== 2) {
  22407. const o = Ps(s), u = Ss(n);
  22408. return this.binarySearch(e, t, r, o, u);
  22409. }
  22410. return n === 2 ? this.fuzzySearch(e, t, r, s !== -1) : n === -1 || n === 1 ? this.orderSearch(
  22411. e,
  22412. t,
  22413. r,
  22414. n === 1 ? Pe.MAX : Pe.MIN,
  22415. s === -1
  22416. ) : this.equalSearch(e, t, r, s !== -1);
  22417. }
  22418. /**
  22419. * Wildcard matching and binary search cannot appear at the same time
  22420. * @param matchModeValue
  22421. * @param searchModeValue
  22422. * @returns
  22423. */
  22424. _checkErrorCombination(e, t) {
  22425. return e === 2 && (t === -2 || t === 2) ? g.create(m.VALUE) : null;
  22426. }
  22427. }
  22428. class tC extends V {
  22429. constructor() {
  22430. super(...arguments);
  22431. A(this, "minParams", 2);
  22432. A(this, "maxParams", 4);
  22433. }
  22434. calculate(e, t, r, n) {
  22435. if (e.isError())
  22436. return e;
  22437. if (t.isError())
  22438. return g.create(m.REF);
  22439. if (!t.isArray())
  22440. return g.create(m.VALUE);
  22441. const s = t.getRowCount(), o = t.getColumnCount();
  22442. if (s !== 1 && o !== 1)
  22443. return g.create(m.VALUE);
  22444. if (r != null && r.isError() || n != null && n.isError())
  22445. return g.create(m.NA);
  22446. const u = this.getIndexNumValue(r || y.create(0));
  22447. if (u instanceof g)
  22448. return u;
  22449. const c = this.getIndexNumValue(n || y.create(1));
  22450. return c instanceof g ? c : e.isArray() ? e.map((l) => this._handleSingleObject(
  22451. l,
  22452. t,
  22453. u,
  22454. c
  22455. )) : this._handleSingleObject(
  22456. e,
  22457. t,
  22458. u,
  22459. c
  22460. );
  22461. }
  22462. _handleSingleObject(e, t, r, n) {
  22463. let s;
  22464. if ((n === 2 || n === -2) && r !== 2) {
  22465. const o = Ps(n), u = Ss(r);
  22466. s = t.binarySearch(e, o, u);
  22467. } else if (r === 2) {
  22468. const o = t.compare(e, $.EQUALS);
  22469. let u;
  22470. if (n !== -1 ? u = o.getFirstTruePosition() : u = o.getLastTruePosition(), u == null)
  22471. return g.create(m.NA);
  22472. s = t.getRowCount() === 1 ? u.column : u.row;
  22473. } else if (r === -1 || r === 1) {
  22474. const o = t.orderSearch(e, r === 1 ? Pe.MAX : Pe.MIN, n === -1);
  22475. if (o == null)
  22476. return g.create(m.NA);
  22477. if (o instanceof g)
  22478. return o;
  22479. s = t.getRowCount() === 1 ? o.column : o.row;
  22480. } else {
  22481. const o = t.isEqual(e);
  22482. let u;
  22483. if (n !== -1 ? u = o.getFirstTruePosition() : u = o.getLastTruePosition(), u == null)
  22484. return g.create(m.NA);
  22485. s = t.getRowCount() === 1 ? u.column : u.row;
  22486. }
  22487. return s == null ? g.create(m.NA) : y.create(s + 1);
  22488. }
  22489. }
  22490. const rC = [
  22491. [Rd, me.ADDRESS],
  22492. [Vd, me.AREAS],
  22493. [Nd, me.CHOOSE],
  22494. [Od, me.CHOOSECOLS],
  22495. [Md, me.CHOOSEROWS],
  22496. [wd, me.COLUMN],
  22497. [Dd, me.COLUMNS],
  22498. [Sd, me.DROP],
  22499. [Pd, me.EXPAND],
  22500. [Ld, me.FILTER],
  22501. [xd, me.FORMULATEXT],
  22502. [jd, me.HLOOKUP],
  22503. [Ud, me.HSTACK],
  22504. [vd, me.INDEX],
  22505. [Td, me.INDIRECT],
  22506. [Bd, me.LOOKUP],
  22507. [Id, me.MATCH],
  22508. [Fd, me.OFFSET],
  22509. [kd, me.ROW],
  22510. [$d, me.ROWS],
  22511. [Yd, me.SORT],
  22512. [Hd, me.SORTBY],
  22513. [Gd, me.TAKE],
  22514. [Qd, me.TOCOL],
  22515. [Wd, me.TOROW],
  22516. [qd, me.TRANSPOSE],
  22517. [Kd, me.UNIQUE],
  22518. [Xd, me.VLOOKUP],
  22519. [Zd, me.VSTACK],
  22520. [zd, me.WRAPCOLS],
  22521. [Jd, me.WRAPROWS],
  22522. [eC, me.XLOOKUP],
  22523. [tC, me.XMATCH]
  22524. ];
  22525. class nC extends V {
  22526. constructor() {
  22527. super(...arguments);
  22528. A(this, "minParams", 1);
  22529. A(this, "maxParams", 1);
  22530. }
  22531. calculate(e) {
  22532. let t = e;
  22533. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.abs();
  22534. }
  22535. }
  22536. class sC extends V {
  22537. constructor() {
  22538. super(...arguments);
  22539. A(this, "minParams", 1);
  22540. A(this, "maxParams", 1);
  22541. }
  22542. calculate(e) {
  22543. let t = e;
  22544. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.acos();
  22545. }
  22546. }
  22547. class aC extends V {
  22548. constructor() {
  22549. super(...arguments);
  22550. A(this, "minParams", 1);
  22551. A(this, "maxParams", 1);
  22552. }
  22553. calculate(e) {
  22554. let t = e;
  22555. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.acosh();
  22556. }
  22557. }
  22558. class iC extends V {
  22559. constructor() {
  22560. super(...arguments);
  22561. A(this, "minParams", 1);
  22562. A(this, "maxParams", 1);
  22563. }
  22564. calculate(e) {
  22565. let t = e;
  22566. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.isArray() ? t.map((r) => r.isError() ? r : Si(r)) : Si(t);
  22567. }
  22568. }
  22569. function Si(i) {
  22570. let a = i.getValue();
  22571. if (i.isBoolean() && (a = a ? 1 : 0), !Number.isFinite(a))
  22572. return g.create(m.VALUE);
  22573. a = Number(a);
  22574. let e = Math.atan(1 / a);
  22575. return a < 0 && (e += Math.PI), Number.isNaN(e) ? g.create(m.VALUE) : y.create(e);
  22576. }
  22577. class oC extends V {
  22578. constructor() {
  22579. super(...arguments);
  22580. A(this, "minParams", 1);
  22581. A(this, "maxParams", 1);
  22582. }
  22583. calculate(e) {
  22584. let t = e;
  22585. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.isArray() ? t.map((r) => r.isError() ? r : Pi(r)) : Pi(t);
  22586. }
  22587. }
  22588. function Pi(i) {
  22589. let a = i.getValue();
  22590. if (i.isBoolean() && (a = a ? 1 : 0), !Number.isFinite(a))
  22591. return g.create(m.VALUE);
  22592. if (a = Number(a), Math.abs(a) <= 1)
  22593. return g.create(m.NUM);
  22594. const e = 1 / 2 * Math.log((a + 1) / (a - 1));
  22595. return Number.isNaN(e) ? g.create(m.VALUE) : y.create(e);
  22596. }
  22597. class uC extends V {
  22598. constructor() {
  22599. super(...arguments);
  22600. A(this, "minParams", 1);
  22601. A(this, "maxParams", 1);
  22602. }
  22603. calculate(e) {
  22604. if (e.isArray()) {
  22605. const t = e.mapValue((r) => this._handleSingleObject(r));
  22606. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  22607. }
  22608. return this._handleSingleObject(e);
  22609. }
  22610. // eslint-disable-next-line
  22611. _handleSingleObject(e) {
  22612. if (e.isError())
  22613. return e;
  22614. if (e.isNull())
  22615. return y.create(0);
  22616. if (e.isBoolean() || e.isNumber())
  22617. return g.create(m.VALUE);
  22618. let t = e.getValue().toLocaleString().toLocaleUpperCase();
  22619. if (t.length > 255)
  22620. return g.create(m.VALUE);
  22621. const r = t.startsWith("-");
  22622. r && (t = t.slice(1));
  22623. let n = 0;
  22624. for (let s = 0; s < t.length; s++) {
  22625. const o = Xr.get(t[s]) || 0, u = Xr.get(t[s + 1]) || 0, c = Xr.get(t[s + 2]) || 0, l = Xr.get(t[s + 3]) || 0;
  22626. if (!o || c >= u && c > o || o === u && o === c && o === l || o === u / 2)
  22627. return g.create(m.VALUE);
  22628. o < u ? n -= o : n += o;
  22629. }
  22630. return y.create(r ? -n : n);
  22631. }
  22632. }
  22633. class cC extends V {
  22634. constructor() {
  22635. super(...arguments);
  22636. A(this, "minParams", 1);
  22637. A(this, "maxParams", 1);
  22638. }
  22639. calculate(e) {
  22640. let t = e;
  22641. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.asin();
  22642. }
  22643. }
  22644. class lC extends V {
  22645. constructor() {
  22646. super(...arguments);
  22647. A(this, "minParams", 1);
  22648. A(this, "maxParams", 1);
  22649. }
  22650. calculate(e) {
  22651. let t = e;
  22652. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.asinh();
  22653. }
  22654. }
  22655. class fC extends V {
  22656. constructor() {
  22657. super(...arguments);
  22658. A(this, "minParams", 1);
  22659. A(this, "maxParams", 1);
  22660. }
  22661. calculate(e) {
  22662. let t = e;
  22663. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.atan();
  22664. }
  22665. }
  22666. class hC extends V {
  22667. constructor() {
  22668. super(...arguments);
  22669. A(this, "minParams", 2);
  22670. A(this, "maxParams", 2);
  22671. }
  22672. calculate(e, t) {
  22673. let r = e, n = t;
  22674. return r.isString() && (r = r.convertToNumberObjectValue()), r.isError() ? r : (n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : n.atan2(r));
  22675. }
  22676. }
  22677. class mC extends V {
  22678. constructor() {
  22679. super(...arguments);
  22680. A(this, "minParams", 1);
  22681. A(this, "maxParams", 1);
  22682. }
  22683. calculate(e) {
  22684. let t = e;
  22685. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.atanh();
  22686. }
  22687. }
  22688. class gC extends V {
  22689. constructor() {
  22690. super(...arguments);
  22691. A(this, "minParams", 2);
  22692. A(this, "maxParams", 3);
  22693. }
  22694. calculate(e, t, r) {
  22695. const n = r != null ? r : y.create(0);
  22696. if (e.isError())
  22697. return e;
  22698. if (t.isError())
  22699. return t;
  22700. if (n.isError())
  22701. return n;
  22702. const s = Math.max(
  22703. e.isArray() ? e.getRowCount() : 1,
  22704. t.isArray() ? t.getRowCount() : 1,
  22705. n.isArray() ? n.getRowCount() : 1
  22706. ), o = Math.max(
  22707. e.isArray() ? e.getColumnCount() : 1,
  22708. t.isArray() ? t.getColumnCount() : 1,
  22709. n.isArray() ? n.getColumnCount() : 1
  22710. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.map((h, d, _) => {
  22711. const C = c.get(d, _), E = l.get(d, _);
  22712. return this._handleSingleObject(h, C, E);
  22713. });
  22714. return f.getRowCount() === 1 && f.getColumnCount() === 1 ? f.getArrayValue()[0][0] : f;
  22715. }
  22716. _handleSingleObject(e, t, r) {
  22717. let n = e;
  22718. if (n.isString() && (n = n.convertToNumberObjectValue()), n.isError())
  22719. return n;
  22720. let s = t;
  22721. if (s.isString() && (s = s.convertToNumberObjectValue()), s.isError())
  22722. return s;
  22723. let o = r;
  22724. if (o.isString() && (o = o.convertToNumberObjectValue()), o.isError())
  22725. return o;
  22726. const u = Math.floor(+n.getValue()), c = Math.floor(+s.getValue()), l = Math.floor(+o.getValue());
  22727. if (u < 0 || u >= 2 ** 53 || c < 2 || c > 36 || l < 0)
  22728. return g.create(m.NUM);
  22729. let f = u.toString(c);
  22730. return f.length < l && (f = new Array(l - f.length + 1).join("0") + f), j.create(f.toLocaleUpperCase());
  22731. }
  22732. }
  22733. class dC extends V {
  22734. constructor() {
  22735. super(...arguments);
  22736. A(this, "minParams", 2);
  22737. A(this, "maxParams", 2);
  22738. }
  22739. calculate(e, t) {
  22740. if (e.isError())
  22741. return e;
  22742. if (t.isError())
  22743. return t;
  22744. const r = Math.max(
  22745. e.isArray() ? e.getRowCount() : 1,
  22746. t.isArray() ? t.getRowCount() : 1
  22747. ), n = Math.max(
  22748. e.isArray() ? e.getColumnCount() : 1,
  22749. t.isArray() ? t.getColumnCount() : 1
  22750. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  22751. let h = c, d = o.get(l, f);
  22752. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  22753. return h;
  22754. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  22755. return d;
  22756. const _ = +h.getValue(), C = +d.getValue();
  22757. if (_ > 0 && C < 0)
  22758. return g.create(m.NUM);
  22759. if (_ === 0 || C === 0)
  22760. return y.create(0);
  22761. const E = Ye(_ / C, 0) * C;
  22762. return y.create(E);
  22763. });
  22764. return u.getRowCount() === 1 && u.getColumnCount() === 1 ? u.getArrayValue()[0][0] : u;
  22765. }
  22766. }
  22767. class CC extends V {
  22768. constructor() {
  22769. super(...arguments);
  22770. A(this, "minParams", 1);
  22771. A(this, "maxParams", 3);
  22772. }
  22773. calculate(e, t, r) {
  22774. const n = t != null ? t : y.create(1), s = r != null ? r : y.create(0);
  22775. if (e.isError())
  22776. return e;
  22777. if (n.isError())
  22778. return n;
  22779. if (s.isError())
  22780. return s;
  22781. const o = Math.max(
  22782. e.isArray() ? e.getRowCount() : 1,
  22783. n.isArray() ? n.getRowCount() : 1,
  22784. s.isArray() ? s.getRowCount() : 1
  22785. ), u = Math.max(
  22786. e.isArray() ? e.getColumnCount() : 1,
  22787. n.isArray() ? n.getColumnCount() : 1,
  22788. s.isArray() ? s.getColumnCount() : 1
  22789. ), c = O(o, u, e, g.create(m.NA)), l = O(o, u, n, g.create(m.NA)), f = O(o, u, s, g.create(m.NA)), h = c.map((d, _, C) => {
  22790. let E = d, b = l.get(_, C), R = f.get(_, C);
  22791. if (E.isString() && (E = E.convertToNumberObjectValue()), E.isError())
  22792. return E;
  22793. if (b.isString() && (b = b.convertToNumberObjectValue()), b.isError())
  22794. return b;
  22795. if (R.isString() && (R = R.convertToNumberObjectValue()), R.isError())
  22796. return R;
  22797. const p = +E.getValue(), N = +b.getValue(), M = +R.getValue();
  22798. return p === 0 || N === 0 ? y.create(0) : this._getResult(p, N, M);
  22799. });
  22800. return o === 1 && u === 1 ? h.get(0, 0) : h;
  22801. }
  22802. _getResult(e, t, r) {
  22803. let n;
  22804. return e < 0 && r !== 0 ? n = (t < 0 ? Ye(Math.abs(e) / Math.abs(t), 0) : -Ye(Math.abs(e) / t, 0)) * t : n = (t < 0 ? -Ye(e / Math.abs(t), 0) : Ye(e / t, 0)) * t, y.create(n);
  22805. }
  22806. }
  22807. class _C extends V {
  22808. constructor() {
  22809. super(...arguments);
  22810. A(this, "minParams", 1);
  22811. A(this, "maxParams", 2);
  22812. }
  22813. calculate(e, t) {
  22814. const r = t != null ? t : y.create(1);
  22815. if (e.isError())
  22816. return e;
  22817. if (r.isError())
  22818. return r;
  22819. const n = Math.max(
  22820. e.isArray() ? e.getRowCount() : 1,
  22821. r.isArray() ? r.getRowCount() : 1
  22822. ), s = Math.max(
  22823. e.isArray() ? e.getColumnCount() : 1,
  22824. r.isArray() ? r.getColumnCount() : 1
  22825. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.map((l, f, h) => {
  22826. let d = u.get(f, h), _ = l;
  22827. if (_.isString() && (_ = _.convertToNumberObjectValue()), _.isError())
  22828. return _;
  22829. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  22830. return d;
  22831. const C = +_.getValue(), E = +d.getValue();
  22832. if (C === 0 || E === 0)
  22833. return y.create(0);
  22834. const b = (E < 0 ? -Ye(C / Math.abs(E), 0) : Ye(C / E, 0)) * E;
  22835. return y.create(b);
  22836. });
  22837. return n === 1 && s === 1 ? c.get(0, 0) : c;
  22838. }
  22839. }
  22840. class AC extends V {
  22841. constructor() {
  22842. super(...arguments);
  22843. A(this, "minParams", 2);
  22844. A(this, "maxParams", 2);
  22845. }
  22846. calculate(e, t) {
  22847. const r = Math.max(
  22848. e.isArray() ? e.getRowCount() : 1,
  22849. t.isArray() ? t.getRowCount() : 1
  22850. ), n = Math.max(
  22851. e.isArray() ? e.getColumnCount() : 1,
  22852. t.isArray() ? t.getColumnCount() : 1
  22853. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  22854. let h = c, d = o.get(l, f);
  22855. if (h.isString() && (h = h.convertToNumberObjectValue()), d.isString() && (d = d.convertToNumberObjectValue()), h.isError())
  22856. return h;
  22857. if (d.isError())
  22858. return d;
  22859. const _ = Math.floor(+h.getValue()), C = Math.floor(+d.getValue());
  22860. if (_ < 0 || C < 0 || _ < C)
  22861. return g.create(m.NUM);
  22862. const E = zt(_, C);
  22863. return Number.isNaN(E) || !Number.isFinite(E) ? g.create(m.NUM) : y.create(E);
  22864. });
  22865. return r === 1 && n === 1 ? u.get(0, 0) : u;
  22866. }
  22867. }
  22868. class EC extends V {
  22869. constructor() {
  22870. super(...arguments);
  22871. A(this, "minParams", 2);
  22872. A(this, "maxParams", 2);
  22873. }
  22874. calculate(e, t) {
  22875. const r = Math.max(
  22876. e.isArray() ? e.getRowCount() : 1,
  22877. t.isArray() ? t.getRowCount() : 1
  22878. ), n = Math.max(
  22879. e.isArray() ? e.getColumnCount() : 1,
  22880. t.isArray() ? t.getColumnCount() : 1
  22881. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  22882. let h = c, d = o.get(l, f);
  22883. if (h.isString() && (h = h.convertToNumberObjectValue()), d.isString() && (d = d.convertToNumberObjectValue()), h.isError())
  22884. return h;
  22885. if (d.isError())
  22886. return d;
  22887. const _ = Math.floor(+h.getValue()), C = Math.floor(+d.getValue());
  22888. if (_ < 0 || C < 0 || _ === 0 && _ < C)
  22889. return g.create(m.NUM);
  22890. const E = zt(_ + C - 1, _ - 1);
  22891. return Number.isNaN(E) || !Number.isFinite(E) ? g.create(m.NUM) : y.create(E);
  22892. });
  22893. return r === 1 && n === 1 ? u.get(0, 0) : u;
  22894. }
  22895. }
  22896. class bC extends V {
  22897. constructor() {
  22898. super(...arguments);
  22899. A(this, "minParams", 1);
  22900. A(this, "maxParams", 1);
  22901. }
  22902. calculate(e) {
  22903. let t = e;
  22904. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.cos();
  22905. }
  22906. }
  22907. class yC extends V {
  22908. constructor() {
  22909. super(...arguments);
  22910. A(this, "minParams", 1);
  22911. A(this, "maxParams", 1);
  22912. }
  22913. calculate(e) {
  22914. let t = e;
  22915. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.cosh();
  22916. }
  22917. }
  22918. class RC extends V {
  22919. constructor() {
  22920. super(...arguments);
  22921. A(this, "minParams", 1);
  22922. A(this, "maxParams", 1);
  22923. }
  22924. calculate(e) {
  22925. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  22926. }
  22927. _handleSingleObject(e) {
  22928. let t = e;
  22929. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  22930. return t;
  22931. const r = +t.getValue();
  22932. return Math.abs(r) >= 2 ** 27 ? g.create(m.NUM) : r === 0 ? g.create(m.DIV_BY_ZERO) : t.tan().getReciprocal();
  22933. }
  22934. }
  22935. class pC extends V {
  22936. constructor() {
  22937. super(...arguments);
  22938. A(this, "minParams", 1);
  22939. A(this, "maxParams", 1);
  22940. }
  22941. calculate(e) {
  22942. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  22943. }
  22944. _handleSingleObject(e) {
  22945. let t = e;
  22946. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : +t.getValue() === 0 ? g.create(m.DIV_BY_ZERO) : t.tanh().getReciprocal();
  22947. }
  22948. }
  22949. class VC extends V {
  22950. constructor() {
  22951. super(...arguments);
  22952. A(this, "minParams", 1);
  22953. A(this, "maxParams", 1);
  22954. }
  22955. calculate(e) {
  22956. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  22957. }
  22958. _handleSingleObject(e) {
  22959. let t = e;
  22960. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  22961. return t;
  22962. const r = +t.getValue();
  22963. return Math.abs(r) >= 2 ** 27 ? g.create(m.NUM) : r === 0 ? g.create(m.DIV_BY_ZERO) : t.sin().getReciprocal();
  22964. }
  22965. }
  22966. class NC extends V {
  22967. constructor() {
  22968. super(...arguments);
  22969. A(this, "minParams", 1);
  22970. A(this, "maxParams", 1);
  22971. }
  22972. calculate(e) {
  22973. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  22974. }
  22975. _handleSingleObject(e) {
  22976. let t = e;
  22977. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  22978. return t;
  22979. const r = +t.getValue();
  22980. return r === 0 ? g.create(m.DIV_BY_ZERO) : !Number.isNaN(r) && !Number.isFinite(Math.sinh(r)) ? y.create(0) : t.sinh().getReciprocal();
  22981. }
  22982. }
  22983. class OC extends V {
  22984. constructor() {
  22985. super(...arguments);
  22986. A(this, "minParams", 2);
  22987. A(this, "maxParams", 2);
  22988. }
  22989. calculate(e, t) {
  22990. if (e.isError())
  22991. return e;
  22992. if (t.isError())
  22993. return t;
  22994. const r = Math.max(
  22995. e.isArray() ? e.getRowCount() : 1,
  22996. t.isArray() ? t.getRowCount() : 1
  22997. ), n = Math.max(
  22998. e.isArray() ? e.getColumnCount() : 1,
  22999. t.isArray() ? t.getColumnCount() : 1
  23000. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  23001. if (c.isError())
  23002. return c;
  23003. let h = o.get(l, f);
  23004. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  23005. return h;
  23006. const d = `${c.getValue()}`, _ = Math.floor(+h.getValue());
  23007. if (Q(d) && (+d < 0 || +d >= 2 ** 53 || !Number.isInteger(+d)) || d.toLocaleLowerCase() === "true" || d.toLocaleLowerCase() === "false" || _ < 2 || _ > 36)
  23008. return g.create(m.NUM);
  23009. if (d.replace(/\s/g, "") === "")
  23010. return y.create(0);
  23011. if (!this._isValidCharForRadix(d, _))
  23012. return g.create(m.NUM);
  23013. const C = Number.parseInt(d, _);
  23014. return Number.isNaN(C) ? g.create(m.NUM) : y.create(C);
  23015. });
  23016. return r === 1 && n === 1 ? u.get(0, 0) : u;
  23017. }
  23018. _isValidCharForRadix(e, t) {
  23019. for (const r of e) {
  23020. const n = r.toUpperCase().charCodeAt(0);
  23021. if (t <= 10 && !(n >= 48 && n < 48 + t) || t > 10 && !(n >= 48 && n < 58 || n >= 65 && n < 65 + t - 10))
  23022. return !1;
  23023. }
  23024. return !0;
  23025. }
  23026. }
  23027. class MC extends V {
  23028. constructor() {
  23029. super(...arguments);
  23030. A(this, "minParams", 1);
  23031. A(this, "maxParams", 1);
  23032. }
  23033. calculate(e) {
  23034. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23035. }
  23036. _handleSingleObject(e) {
  23037. let t = e;
  23038. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23039. return t;
  23040. const r = +t.getValue();
  23041. if (!Number.isFinite(r))
  23042. return g.create(m.VALUE);
  23043. const n = r * (180 / Math.PI);
  23044. return Number.isNaN(n) ? g.create(m.VALUE) : y.create(n);
  23045. }
  23046. }
  23047. class wC extends V {
  23048. constructor() {
  23049. super(...arguments);
  23050. A(this, "minParams", 1);
  23051. A(this, "maxParams", 1);
  23052. }
  23053. calculate(e) {
  23054. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23055. }
  23056. _handleSingleObject(e) {
  23057. let t = e;
  23058. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23059. return t;
  23060. const r = +t.getValue();
  23061. if (!Number.isFinite(r))
  23062. return g.create(m.VALUE);
  23063. const n = (r < 0 ? -Ye(Math.abs(r) / 2, 0) : Ye(r / 2, 0)) * 2;
  23064. return Number.isNaN(n) ? g.create(m.VALUE) : n === 0 ? y.create(0) : y.create(n);
  23065. }
  23066. }
  23067. class DC extends V {
  23068. constructor() {
  23069. super(...arguments);
  23070. A(this, "minParams", 1);
  23071. A(this, "maxParams", 1);
  23072. }
  23073. calculate(e) {
  23074. let t = e;
  23075. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.exp();
  23076. }
  23077. }
  23078. class SC extends V {
  23079. constructor() {
  23080. super(...arguments);
  23081. A(this, "minParams", 1);
  23082. A(this, "maxParams", 1);
  23083. }
  23084. calculate(e) {
  23085. return e.isArray() ? e.mapValue((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23086. }
  23087. _handleSingleObject(e) {
  23088. let t = e;
  23089. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23090. return t;
  23091. const r = Math.floor(+t.getValue()), n = cr(r);
  23092. return Number.isNaN(n) || !Number.isFinite(n) ? g.create(m.NUM) : y.create(n);
  23093. }
  23094. }
  23095. class PC extends V {
  23096. constructor() {
  23097. super(...arguments);
  23098. A(this, "minParams", 1);
  23099. A(this, "maxParams", 1);
  23100. }
  23101. calculate(e) {
  23102. let t = e;
  23103. if (e.isArray()) {
  23104. const r = e.getRowCount(), n = e.getColumnCount();
  23105. if (r > 1 || n > 1)
  23106. return g.create(m.VALUE);
  23107. t = e.get(0, 0);
  23108. }
  23109. return this._handleSingleObject(t);
  23110. }
  23111. _handleSingleObject(e) {
  23112. let t = e;
  23113. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23114. return t;
  23115. const r = Math.floor(+t.getValue()), n = cr(r, 2);
  23116. return Number.isNaN(n) || !Number.isFinite(n) ? g.create(m.NUM) : y.create(n);
  23117. }
  23118. }
  23119. class LC extends V {
  23120. constructor() {
  23121. super(...arguments);
  23122. A(this, "minParams", 2);
  23123. A(this, "maxParams", 2);
  23124. }
  23125. calculate(e, t) {
  23126. if (e.isError())
  23127. return e;
  23128. if (t.isError())
  23129. return t;
  23130. const r = Math.max(
  23131. e.isArray() ? e.getRowCount() : 1,
  23132. t.isArray() ? t.getRowCount() : 1
  23133. ), n = Math.max(
  23134. e.isArray() ? e.getColumnCount() : 1,
  23135. t.isArray() ? t.getColumnCount() : 1
  23136. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  23137. let h = o.get(l, f), d = c;
  23138. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  23139. return d;
  23140. if (h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  23141. return h;
  23142. const _ = +d.getValue(), C = +h.getValue();
  23143. if (_ > 0 && C < 0)
  23144. return g.create(m.NUM);
  23145. if (_ === 0)
  23146. return y.create(0);
  23147. if (C === 0)
  23148. return g.create(m.DIV_BY_ZERO);
  23149. const E = We(_ / C, 0) * C;
  23150. return y.create(E);
  23151. });
  23152. return r === 1 && n === 1 ? u.get(0, 0) : u;
  23153. }
  23154. }
  23155. class xC extends V {
  23156. constructor() {
  23157. super(...arguments);
  23158. A(this, "minParams", 1);
  23159. A(this, "maxParams", 3);
  23160. }
  23161. calculate(e, t, r) {
  23162. const n = t != null ? t : y.create(1), s = r != null ? r : y.create(0), o = Math.max(
  23163. e.isArray() ? e.getRowCount() : 1,
  23164. n.isArray() ? n.getRowCount() : 1,
  23165. s.isArray() ? s.getRowCount() : 1
  23166. ), u = Math.max(
  23167. e.isArray() ? e.getColumnCount() : 1,
  23168. n.isArray() ? n.getColumnCount() : 1,
  23169. s.isArray() ? s.getColumnCount() : 1
  23170. ), c = O(o, u, e, g.create(m.NA)), l = O(o, u, n, g.create(m.NA)), f = O(o, u, s, g.create(m.NA)), h = c.map((d, _, C) => {
  23171. let E = d, b = l.get(_, C), R = f.get(_, C);
  23172. if (E.isString() && (E = E.convertToNumberObjectValue()), E.isError())
  23173. return E;
  23174. if (b.isString() && (b = b.convertToNumberObjectValue()), b.isError())
  23175. return b;
  23176. if (R.isString() && (R = R.convertToNumberObjectValue()), R.isError())
  23177. return R;
  23178. const p = +E.getValue(), N = +b.getValue(), M = +R.getValue();
  23179. if (p === 0 || N === 0)
  23180. return y.create(0);
  23181. let w;
  23182. return p < 0 && M !== 0 ? w = (N < 0 ? We(Math.abs(p) / Math.abs(N), 0) : -We(Math.abs(p) / N, 0)) * N : w = (N < 0 ? -We(p / Math.abs(N), 0) : We(p / N, 0)) * N, y.create(w);
  23183. });
  23184. return o === 1 && u === 1 ? h.get(0, 0) : h;
  23185. }
  23186. }
  23187. class jC extends V {
  23188. constructor() {
  23189. super(...arguments);
  23190. A(this, "minParams", 1);
  23191. A(this, "maxParams", 2);
  23192. }
  23193. calculate(e, t) {
  23194. const r = t != null ? t : y.create(1);
  23195. if (e.isError())
  23196. return e;
  23197. if (r.isError())
  23198. return r;
  23199. const n = Math.max(
  23200. e.isArray() ? e.getRowCount() : 1,
  23201. r.isArray() ? r.getRowCount() : 1
  23202. ), s = Math.max(
  23203. e.isArray() ? e.getColumnCount() : 1,
  23204. r.isArray() ? r.getColumnCount() : 1
  23205. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.map((l, f, h) => {
  23206. let d = u.get(f, h), _ = l;
  23207. if (_.isString() && (_ = _.convertToNumberObjectValue()), _.isError())
  23208. return _;
  23209. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  23210. return d;
  23211. const C = +_.getValue(), E = +d.getValue();
  23212. if (C === 0 || E === 0)
  23213. return y.create(0);
  23214. const b = (E < 0 ? -We(C / Math.abs(E), 0) : We(C / E, 0)) * E;
  23215. return y.create(b);
  23216. });
  23217. return n === 1 && s === 1 ? c.get(0, 0) : c;
  23218. }
  23219. }
  23220. class UC extends V {
  23221. constructor() {
  23222. super(...arguments);
  23223. A(this, "minParams", 1);
  23224. A(this, "maxParams", 255);
  23225. }
  23226. calculate(...e) {
  23227. let t = 0;
  23228. for (let r = 0; r < e.length; r++) {
  23229. const n = e[r];
  23230. if (!n.isNull())
  23231. if (n.isArray()) {
  23232. let s = !1, o = g.create(m.VALUE);
  23233. if (n.iterator((u) => {
  23234. if (u != null && u.isNull())
  23235. return !0;
  23236. const { isError: c, errorObject: l, number: f } = this._handleSingleObject(u);
  23237. if (c)
  23238. return s = !0, o = l, !1;
  23239. t = qs(t, f);
  23240. }), s)
  23241. return o;
  23242. } else {
  23243. const { isError: s, errorObject: o, number: u } = this._handleSingleObject(n);
  23244. if (s)
  23245. return o;
  23246. t = qs(t, u);
  23247. }
  23248. }
  23249. return y.create(t);
  23250. }
  23251. _handleSingleObject(e) {
  23252. if (e.isBoolean())
  23253. return {
  23254. isError: !0,
  23255. errorObject: g.create(m.VALUE),
  23256. number: null
  23257. };
  23258. let t = e;
  23259. if (e.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23260. return {
  23261. isError: !0,
  23262. errorObject: t,
  23263. number: null
  23264. };
  23265. const r = Math.floor(+t.getValue());
  23266. return r < 0 || r >= 2 ** 53 ? {
  23267. isError: !0,
  23268. errorObject: g.create(m.NUM),
  23269. number: null
  23270. } : {
  23271. isError: !1,
  23272. errorObject: null,
  23273. number: r
  23274. };
  23275. }
  23276. }
  23277. class vC extends V {
  23278. constructor() {
  23279. super(...arguments);
  23280. A(this, "minParams", 1);
  23281. A(this, "maxParams", 1);
  23282. }
  23283. calculate(e) {
  23284. return e.isArray() ? e.mapValue((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23285. }
  23286. _handleSingleObject(e) {
  23287. let t = e;
  23288. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23289. return t;
  23290. const r = Math.floor(+t.getValue());
  23291. return y.create(r);
  23292. }
  23293. }
  23294. class TC extends V {
  23295. constructor() {
  23296. super(...arguments);
  23297. A(this, "minParams", 1);
  23298. A(this, "maxParams", 255);
  23299. }
  23300. calculate(...e) {
  23301. let t = 1, r = !0;
  23302. for (let n = 0; n < e.length; n++) {
  23303. const s = e[n];
  23304. if (!s.isNull())
  23305. if (s.isArray()) {
  23306. let o = !1, u = g.create(m.VALUE);
  23307. if (s.iterator((c) => {
  23308. if (c != null && c.isNull())
  23309. return !0;
  23310. const { isError: l, errorObject: f, number: h } = this._handleSingleObject(c);
  23311. if (l)
  23312. return o = !0, u = f, !1;
  23313. t = Mi(t, h), r = !1;
  23314. }), o)
  23315. return u;
  23316. } else {
  23317. const { isError: o, errorObject: u, number: c } = this._handleSingleObject(s);
  23318. if (o)
  23319. return u;
  23320. t = Mi(t, c), r = !1;
  23321. }
  23322. }
  23323. return r ? y.create(0) : Number.isNaN(t) || !Number.isFinite(t) || t >= 2 ** 53 ? g.create(m.VALUE) : y.create(t);
  23324. }
  23325. _handleSingleObject(e) {
  23326. if (e.isBoolean())
  23327. return {
  23328. isError: !0,
  23329. errorObject: g.create(m.VALUE),
  23330. number: null
  23331. };
  23332. let t = e;
  23333. if (e.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23334. return {
  23335. isError: !0,
  23336. errorObject: t,
  23337. number: null
  23338. };
  23339. const r = Math.floor(+t.getValue());
  23340. return r < 0 ? {
  23341. isError: !0,
  23342. errorObject: g.create(m.NUM),
  23343. number: null
  23344. } : {
  23345. isError: !1,
  23346. errorObject: null,
  23347. number: r
  23348. };
  23349. }
  23350. }
  23351. class BC extends V {
  23352. constructor() {
  23353. super(...arguments);
  23354. A(this, "minParams", 1);
  23355. A(this, "maxParams", 1);
  23356. }
  23357. calculate(e) {
  23358. let t = e;
  23359. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.log();
  23360. }
  23361. }
  23362. class IC extends V {
  23363. constructor() {
  23364. super(...arguments);
  23365. A(this, "minParams", 1);
  23366. A(this, "maxParams", 2);
  23367. }
  23368. calculate(e, t) {
  23369. const r = t != null ? t : y.create(10);
  23370. if (e.isError())
  23371. return e;
  23372. if (r.isError())
  23373. return r;
  23374. const n = Math.max(
  23375. e.isArray() ? e.getRowCount() : 1,
  23376. r.isArray() ? r.getRowCount() : 1
  23377. ), s = Math.max(
  23378. e.isArray() ? e.getColumnCount() : 1,
  23379. r.isArray() ? r.getColumnCount() : 1
  23380. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.map((l, f, h) => {
  23381. let d = u.get(f, h), _ = l;
  23382. if (_.isString() && (_ = _.convertToNumberObjectValue()), _.isError())
  23383. return _;
  23384. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  23385. return d;
  23386. const C = +_.getValue(), E = +d.getValue();
  23387. if (C <= 0 || E <= 0)
  23388. return g.create(m.NUM);
  23389. const b = Math.log(E);
  23390. if (b === 0)
  23391. return g.create(m.DIV_BY_ZERO);
  23392. const R = Math.log(C) / b;
  23393. return y.create(R);
  23394. });
  23395. return n === 1 && s === 1 ? c.get(0, 0) : c;
  23396. }
  23397. }
  23398. class FC extends V {
  23399. constructor() {
  23400. super(...arguments);
  23401. A(this, "minParams", 1);
  23402. A(this, "maxParams", 1);
  23403. }
  23404. calculate(e) {
  23405. let t = e;
  23406. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.log10();
  23407. }
  23408. }
  23409. class kC extends V {
  23410. constructor() {
  23411. super(...arguments);
  23412. A(this, "minParams", 1);
  23413. A(this, "maxParams", 1);
  23414. }
  23415. calculate(e) {
  23416. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  23417. for (let o = 0; o < t; o++) {
  23418. const u = [];
  23419. for (let c = 0; c < r; c++) {
  23420. let l = e.isArray() ? e.get(o, c) : e;
  23421. if (l.isError())
  23422. return l;
  23423. if (l.isNull() || l.isBoolean())
  23424. return g.create(m.VALUE);
  23425. if (l.isString() && (l = l.convertToNumberObjectValue()), l.isError())
  23426. return l;
  23427. const f = +l.getValue();
  23428. u.push(f);
  23429. }
  23430. n.push(u);
  23431. }
  23432. if (t !== r)
  23433. return g.create(m.VALUE);
  23434. const s = Gn(n);
  23435. return y.create(s);
  23436. }
  23437. }
  23438. class $C extends V {
  23439. constructor() {
  23440. super(...arguments);
  23441. A(this, "minParams", 1);
  23442. A(this, "maxParams", 1);
  23443. }
  23444. calculate(e) {
  23445. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  23446. for (let o = 0; o < t; o++) {
  23447. const u = [];
  23448. for (let c = 0; c < r; c++) {
  23449. let l = e.isArray() ? e.get(o, c) : e;
  23450. if (l.isError())
  23451. return l;
  23452. if (l.isNull() || l.isBoolean())
  23453. return g.create(m.VALUE);
  23454. if (l.isString() && (l = l.convertToNumberObjectValue()), l.isError())
  23455. return l;
  23456. const f = +l.getValue();
  23457. u.push(f);
  23458. }
  23459. n.push(u);
  23460. }
  23461. if (t !== r)
  23462. return g.create(m.VALUE);
  23463. const s = Gh(n);
  23464. return s === null ? g.create(m.NUM) : q.createByArray(s);
  23465. }
  23466. }
  23467. class YC extends V {
  23468. constructor() {
  23469. super(...arguments);
  23470. A(this, "minParams", 2);
  23471. A(this, "maxParams", 2);
  23472. }
  23473. calculate(e, t) {
  23474. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  23475. if (n !== s)
  23476. return g.create(m.VALUE);
  23477. const u = this._getMatrix(e, r, n), c = this._getMatrix(t, s, o);
  23478. if (u instanceof g)
  23479. return u;
  23480. if (c instanceof g)
  23481. return c;
  23482. const l = lr(u, c);
  23483. return q.createByArray(l);
  23484. }
  23485. _getMatrix(e, t, r) {
  23486. const n = [];
  23487. for (let s = 0; s < t; s++) {
  23488. const o = [];
  23489. for (let u = 0; u < r; u++) {
  23490. let c = e.isArray() ? e.get(s, u) : e;
  23491. if (c.isError())
  23492. return c;
  23493. if (c.isNull() || c.isBoolean())
  23494. return g.create(m.VALUE);
  23495. if (c.isString() && (c = c.convertToNumberObjectValue()), c.isError())
  23496. return c;
  23497. const l = +c.getValue();
  23498. o.push(l);
  23499. }
  23500. n.push(o);
  23501. }
  23502. return n;
  23503. }
  23504. }
  23505. class HC extends V {
  23506. constructor() {
  23507. super(...arguments);
  23508. A(this, "minParams", 2);
  23509. A(this, "maxParams", 2);
  23510. }
  23511. calculate(e, t) {
  23512. let r = e;
  23513. if (r.isString() && (r = r.convertToNumberObjectValue()), r.isError())
  23514. return r;
  23515. let n = t;
  23516. return n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : r.mod(n);
  23517. }
  23518. }
  23519. class GC extends V {
  23520. constructor() {
  23521. super(...arguments);
  23522. A(this, "minParams", 2);
  23523. A(this, "maxParams", 2);
  23524. }
  23525. calculate(e, t) {
  23526. let r = e;
  23527. if (r.isArray()) {
  23528. const c = r.getRowCount(), l = r.getColumnCount();
  23529. if (c > 1 || l > 1)
  23530. return g.create(m.VALUE);
  23531. r = r.get(0, 0);
  23532. }
  23533. if (r.isError())
  23534. return r;
  23535. let n = t;
  23536. if (n.isArray()) {
  23537. const c = n.getRowCount(), l = n.getColumnCount();
  23538. if (c > 1 || l > 1)
  23539. return g.create(m.VALUE);
  23540. n = n.get(0, 0);
  23541. }
  23542. if (n.isError())
  23543. return n;
  23544. if (r.isBoolean() || n.isBoolean())
  23545. return g.create(m.VALUE);
  23546. const s = +r.getValue(), o = +n.getValue();
  23547. if (Number.isNaN(s) || Number.isNaN(o))
  23548. return g.create(m.VALUE);
  23549. if (o === 0)
  23550. return y.create(0);
  23551. if (s > 0 && o < 0 || s < 0 && o > 0)
  23552. return g.create(m.NUM);
  23553. const u = vt(s / o, 0) * o;
  23554. return y.create(u);
  23555. }
  23556. }
  23557. class QC extends V {
  23558. constructor() {
  23559. super(...arguments);
  23560. A(this, "minParams", 1);
  23561. A(this, "maxParams", 255);
  23562. }
  23563. calculate(...e) {
  23564. let t = 0, r = 1;
  23565. for (let s = 0; s < e.length; s++) {
  23566. const o = e[s];
  23567. if (!o.isNull())
  23568. if (o.isArray()) {
  23569. let u = !1, c = g.create(m.VALUE);
  23570. if (o.iterator((l) => {
  23571. if (l != null && l.isNull())
  23572. return !0;
  23573. const { isError: f, errorObject: h, number: d } = this._handleSingleObject(l);
  23574. if (f)
  23575. return u = !0, c = h, !1;
  23576. if (t += d, t > 170)
  23577. return u = !0, c = g.create(m.NUM), !1;
  23578. r *= cr(d);
  23579. }), u)
  23580. return c;
  23581. } else {
  23582. const { isError: u, errorObject: c, number: l } = this._handleSingleObject(o);
  23583. if (u)
  23584. return c;
  23585. if (t += l, t > 170)
  23586. return g.create(m.NUM);
  23587. r *= cr(l);
  23588. }
  23589. }
  23590. const n = cr(t) / r;
  23591. return y.create(n);
  23592. }
  23593. _handleSingleObject(e) {
  23594. if (e.isBoolean())
  23595. return {
  23596. isError: !0,
  23597. errorObject: g.create(m.VALUE),
  23598. number: null
  23599. };
  23600. let t = e;
  23601. if (e.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23602. return {
  23603. isError: !0,
  23604. errorObject: t,
  23605. number: null
  23606. };
  23607. const r = Math.floor(+t.getValue());
  23608. return r < 0 ? {
  23609. isError: !0,
  23610. errorObject: g.create(m.NUM),
  23611. number: null
  23612. } : {
  23613. isError: !1,
  23614. errorObject: null,
  23615. number: r
  23616. };
  23617. }
  23618. }
  23619. class WC extends V {
  23620. constructor() {
  23621. super(...arguments);
  23622. A(this, "minParams", 1);
  23623. A(this, "maxParams", 1);
  23624. }
  23625. calculate(e) {
  23626. if (e.isArray()) {
  23627. const t = e.getRowCount(), r = e.getColumnCount(), n = e.mapValue((s) => {
  23628. const o = this._handleSingleObject(s);
  23629. return o.isError() ? o : t > 1 || r > 1 ? o.get(0, 0) : o;
  23630. });
  23631. return t === 1 && r === 1 ? n.get(0, 0) : n;
  23632. }
  23633. return this._handleSingleObject(e);
  23634. }
  23635. _handleSingleObject(e) {
  23636. let t = e;
  23637. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23638. return t;
  23639. const r = Math.floor(+t.getValue());
  23640. if (r <= 0)
  23641. return g.create(m.VALUE);
  23642. const n = [];
  23643. for (let s = 0; s < r; s++) {
  23644. n[s] = [];
  23645. for (let o = 0; o < r; o++)
  23646. n[s][o] = s === o ? 1 : 0;
  23647. }
  23648. return q.createByArray(n);
  23649. }
  23650. }
  23651. class qC extends V {
  23652. constructor() {
  23653. super(...arguments);
  23654. A(this, "minParams", 1);
  23655. A(this, "maxParams", 1);
  23656. }
  23657. calculate(e) {
  23658. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23659. }
  23660. _handleSingleObject(e) {
  23661. let t = e;
  23662. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23663. return t;
  23664. const r = +t.getValue();
  23665. if (!Number.isFinite(r))
  23666. return g.create(m.VALUE);
  23667. let n = r < 0 ? -Ye(Math.abs(r), 0) : Ye(r, 0);
  23668. return Number.isNaN(n) ? g.create(m.VALUE) : (Math.abs(n) % 2 === 0 && (r < 0 ? n-- : n++), y.create(n));
  23669. }
  23670. }
  23671. class KC extends V {
  23672. constructor() {
  23673. super(...arguments);
  23674. A(this, "minParams", 0);
  23675. A(this, "maxParams", 0);
  23676. }
  23677. calculate() {
  23678. return y.create(Math.PI);
  23679. }
  23680. }
  23681. class XC extends V {
  23682. constructor() {
  23683. super(...arguments);
  23684. A(this, "minParams", 2);
  23685. A(this, "maxParams", 2);
  23686. }
  23687. calculate(e, t) {
  23688. let r = e;
  23689. if (r.isString() && (r = r.convertToNumberObjectValue()), r.isError())
  23690. return r;
  23691. let n = t;
  23692. return n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : r.pow(n);
  23693. }
  23694. }
  23695. class ZC extends V {
  23696. constructor() {
  23697. super(...arguments);
  23698. A(this, "minParams", 1);
  23699. A(this, "maxParams", 255);
  23700. }
  23701. calculate(...e) {
  23702. let t = y.create(1), r = !0;
  23703. for (let n = 0; n < e.length; n++) {
  23704. let s = e[n];
  23705. if (s.isError())
  23706. return s;
  23707. if (s.isArray()) {
  23708. let o = !1, u = null;
  23709. if (s.iterator((c) => {
  23710. if (c != null && c.isError())
  23711. return o = !0, u = c, !1;
  23712. if (!c || c.isNull() || c.isString() || c.isBoolean())
  23713. return !0;
  23714. t = t.multiply(c), r = !1;
  23715. }), o)
  23716. return u;
  23717. } else {
  23718. if (s.isNull())
  23719. continue;
  23720. if (s.isString() && (s = s.convertToNumberObjectValue()), s.isError())
  23721. return s;
  23722. t = t.multiply(s), r = !1;
  23723. }
  23724. if (t.isError())
  23725. return t;
  23726. }
  23727. return r ? y.create(0) : t;
  23728. }
  23729. }
  23730. class zC extends V {
  23731. constructor() {
  23732. super(...arguments);
  23733. A(this, "minParams", 2);
  23734. A(this, "maxParams", 2);
  23735. }
  23736. calculate(e, t) {
  23737. const { isError: r, errorObject: n, variants: s } = H(e, t);
  23738. if (r)
  23739. return n;
  23740. const [o, u] = s, c = +o.getValue(), l = +u.getValue();
  23741. if (Number.isNaN(c) || Number.isNaN(l))
  23742. return g.create(m.VALUE);
  23743. if (l === 0)
  23744. return g.create(m.DIV_BY_ZERO);
  23745. const f = Math.trunc(c / l);
  23746. return y.create(f);
  23747. }
  23748. }
  23749. class JC extends V {
  23750. constructor() {
  23751. super(...arguments);
  23752. A(this, "minParams", 1);
  23753. A(this, "maxParams", 1);
  23754. }
  23755. calculate(e) {
  23756. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  23757. }
  23758. _handleSingleObject(e) {
  23759. let t = e;
  23760. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  23761. return t;
  23762. const r = +t.getValue();
  23763. if (!Number.isFinite(r))
  23764. return g.create(m.VALUE);
  23765. const n = r * (Math.PI / 180);
  23766. return Number.isNaN(n) ? g.create(m.VALUE) : y.create(n);
  23767. }
  23768. }
  23769. class e_ extends V {
  23770. constructor() {
  23771. super(...arguments);
  23772. A(this, "minParams", 0);
  23773. A(this, "maxParams", 0);
  23774. }
  23775. calculate() {
  23776. return y.create(Math.random());
  23777. }
  23778. }
  23779. class t_ extends V {
  23780. constructor() {
  23781. super(...arguments);
  23782. A(this, "minParams", 0);
  23783. A(this, "maxParams", 5);
  23784. A(this, "needsSheetRowColumnCount", !0);
  23785. }
  23786. calculate(e, t, r, n, s) {
  23787. if (e != null && e.isError())
  23788. return e;
  23789. if (t != null && t.isError())
  23790. return t;
  23791. if (r != null && r.isError())
  23792. return r;
  23793. if (n != null && n.isError())
  23794. return n;
  23795. if (s != null && s.isError())
  23796. return s;
  23797. const o = e != null ? e : y.create(1), u = t != null ? t : y.create(1), c = r != null ? r : y.create(0), l = n != null ? n : y.create(1), f = s != null ? s : y.create(0);
  23798. return this._calculateResult(o, u, c, l, f);
  23799. }
  23800. _calculateResult(e, t, r, n, s) {
  23801. const o = Math.max(
  23802. e.isArray() ? e.getRowCount() : 1,
  23803. t.isArray() ? t.getRowCount() : 1,
  23804. r.isArray() ? r.getRowCount() : 1,
  23805. n.isArray() ? n.getRowCount() : 1,
  23806. s.isArray() ? s.getRowCount() : 1
  23807. ), u = Math.max(
  23808. e.isArray() ? e.getColumnCount() : 1,
  23809. t.isArray() ? t.getColumnCount() : 1,
  23810. r.isArray() ? r.getColumnCount() : 1,
  23811. n.isArray() ? n.getColumnCount() : 1,
  23812. s.isArray() ? s.getColumnCount() : 1
  23813. );
  23814. if (o === 1 && u === 1)
  23815. return this._calculateSingleCell(e, t, r, n, s);
  23816. const c = O(o, u, e, g.create(m.NA)), l = O(o, u, t, g.create(m.NA)), f = O(o, u, r, g.create(m.NA)), h = O(o, u, n, g.create(m.NA)), d = O(o, u, s, g.create(m.NA));
  23817. return c.map((_, C, E) => {
  23818. const b = l.get(C, E), R = f.get(C, E), p = h.get(C, E), N = d.get(C, E), M = this._handleError(_, b, R, p, N);
  23819. if (M.errorObject)
  23820. return M.errorObject;
  23821. let { minValue: w, maxValue: D, wholeNumberValue: S } = M, P;
  23822. return S ? (w = Math.ceil(w), D = Math.floor(D), P = Math.floor(Math.random() * (D - w + 1)) + w) : P = Math.random() * (D - w) + w, P < w || P > D ? g.create(m.VALUE) : y.create(P);
  23823. });
  23824. }
  23825. _calculateSingleCell(e, t, r, n, s) {
  23826. let o = e;
  23827. o.isArray() && (o = o.get(0, 0));
  23828. let u = t;
  23829. u.isArray() && (u = u.get(0, 0));
  23830. let c = r;
  23831. c.isArray() && (c = c.get(0, 0));
  23832. let l = n;
  23833. l.isArray() && (l = l.get(0, 0));
  23834. let f = s;
  23835. f.isArray() && (f = f.get(0, 0));
  23836. const h = this._handleError(o, u, c, l, f);
  23837. if (h.errorObject)
  23838. return h.errorObject;
  23839. let { rowsValue: d, columnsValue: _, minValue: C, maxValue: E, wholeNumberValue: b } = h;
  23840. if (b && (C = Math.ceil(C), E = Math.floor(E), C > E))
  23841. return g.create(m.VALUE);
  23842. const R = [];
  23843. for (let p = 0; p < d; p++) {
  23844. const N = [];
  23845. for (let M = 0; M < _; M++)
  23846. b ? N.push(Math.floor(Math.random() * (E - C + 1)) + C) : N.push(Math.random() * (E - C) + C);
  23847. R.push(N);
  23848. }
  23849. return d === 1 && _ === 1 ? y.create(R[0][0]) : q.createByArray(R);
  23850. }
  23851. _handleError(e, t, r, n, s) {
  23852. let o = e;
  23853. if (o.isString() && (o = o.convertToNumberObjectValue()), o.isError())
  23854. return {
  23855. errorObject: o
  23856. };
  23857. let u = t;
  23858. if (u.isString() && (u = u.convertToNumberObjectValue()), u.isError())
  23859. return {
  23860. errorObject: u
  23861. };
  23862. let c = r;
  23863. if (c.isString() && (c = c.convertToNumberObjectValue()), c.isError())
  23864. return {
  23865. errorObject: c
  23866. };
  23867. let l = n;
  23868. if (l.isString() && (l = l.convertToNumberObjectValue()), l.isError())
  23869. return {
  23870. errorObject: l
  23871. };
  23872. let f = s;
  23873. return f.isString() && (f = f.convertToNumberObjectValue()), f.isError() ? {
  23874. errorObject: f
  23875. } : this._getValue(o, u, c, l, f);
  23876. }
  23877. _getValue(e, t, r, n, s) {
  23878. const o = Math.floor(+e.getValue()), u = Math.floor(+t.getValue());
  23879. if (o === 0 || u === 0)
  23880. return {
  23881. errorObject: g.create(m.CALC)
  23882. };
  23883. const c = this._rowCount - this.row, l = this._columnCount - this.column;
  23884. if (o < 0 || u < 0 || o * u > 10 ** 7)
  23885. return {
  23886. errorObject: g.create(m.VALUE)
  23887. };
  23888. if (o > c || u > l)
  23889. return {
  23890. errorObject: g.create(m.REF)
  23891. };
  23892. const f = +r.getValue(), h = +n.getValue(), d = +s.getValue();
  23893. return f > h ? {
  23894. errorObject: g.create(m.VALUE)
  23895. } : d && (!Number.isInteger(f) || !Number.isInteger(h)) ? {
  23896. errorObject: g.create(m.VALUE)
  23897. } : {
  23898. rowsValue: o,
  23899. columnsValue: u,
  23900. minValue: f,
  23901. maxValue: h,
  23902. wholeNumberValue: d
  23903. };
  23904. }
  23905. }
  23906. class r_ extends V {
  23907. constructor() {
  23908. super(...arguments);
  23909. A(this, "minParams", 2);
  23910. A(this, "maxParams", 2);
  23911. }
  23912. calculate(e, t) {
  23913. let r = e;
  23914. if (r.isArray()) {
  23915. const c = r.getRowCount(), l = r.getColumnCount();
  23916. if (c > 1 || l > 1)
  23917. return g.create(m.VALUE);
  23918. r = r.get(0, 0);
  23919. }
  23920. if (r.isError())
  23921. return r;
  23922. let n = t;
  23923. if (n.isArray()) {
  23924. const c = n.getRowCount(), l = n.getColumnCount();
  23925. if (c > 1 || l > 1)
  23926. return g.create(m.VALUE);
  23927. n = n.get(0, 0);
  23928. }
  23929. if (n.isError())
  23930. return n;
  23931. if (r.isBoolean() || n.isBoolean())
  23932. return g.create(m.VALUE);
  23933. let s = +r.getValue(), o = +n.getValue();
  23934. if (Number.isNaN(s) || Number.isNaN(o))
  23935. return g.create(m.VALUE);
  23936. if (s > o)
  23937. return g.create(m.NUM);
  23938. s = Math.ceil(s), o = Math.floor(o);
  23939. const u = Math.floor(Math.random() * (o - s + 1)) + s;
  23940. return y.create(u);
  23941. }
  23942. }
  23943. class n_ extends V {
  23944. constructor() {
  23945. super(...arguments);
  23946. A(this, "minParams", 1);
  23947. A(this, "maxParams", 2);
  23948. }
  23949. calculate(e, t) {
  23950. const r = t != null ? t : y.create(0), n = Math.max(
  23951. e.isArray() ? e.getRowCount() : 1,
  23952. r.isArray() ? r.getRowCount() : 1
  23953. ), s = Math.max(
  23954. e.isArray() ? e.getColumnCount() : 1,
  23955. r.isArray() ? r.getColumnCount() : 1
  23956. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  23957. const d = u.get(f, h);
  23958. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  23959. });
  23960. return n === 1 && s === 1 ? c.get(0, 0) : c;
  23961. }
  23962. _handleSingleObject(e, t) {
  23963. const { isError: r, errorObject: n, variants: s } = I(e);
  23964. if (r)
  23965. return n;
  23966. const [o] = s;
  23967. let u = Math.floor(+o.getValue()), c = t;
  23968. if (c.isString() && (c = c.convertToNumberObjectValue(), c.isError()))
  23969. return c;
  23970. let l = Math.floor(+c.getValue());
  23971. if (c.isBoolean() && (l = c.getValue() ? 0 : 4), u < 0 || u > 3999 || l < 0 || l > 4)
  23972. return g.create(m.VALUE);
  23973. const f = Jh[l];
  23974. let h = f.length - 1, d = "";
  23975. for (; u > 0; ) {
  23976. h = this._binarySearch(u, 0, h, f);
  23977. const _ = f[h];
  23978. u -= _, d += zh.get(_);
  23979. }
  23980. return j.create(d);
  23981. }
  23982. _binarySearch(e, t, r, n) {
  23983. let s = t, o = r;
  23984. for (; o - s > 1; ) {
  23985. const u = Math.floor((s + o) / 2), c = n[u];
  23986. if (c === e)
  23987. return u;
  23988. c > e ? o = u : s = u;
  23989. }
  23990. return s !== o && n[o] <= e ? o : s;
  23991. }
  23992. }
  23993. class s_ extends V {
  23994. constructor() {
  23995. super(...arguments);
  23996. A(this, "minParams", 2);
  23997. A(this, "maxParams", 2);
  23998. }
  23999. calculate(e, t) {
  24000. let r = e;
  24001. if (r.isString() && (r = r.convertToNumberObjectValue()), r.isError())
  24002. return r;
  24003. let n = t;
  24004. return n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : r.round(n);
  24005. }
  24006. }
  24007. class a_ extends V {
  24008. constructor() {
  24009. super(...arguments);
  24010. A(this, "minParams", 2);
  24011. A(this, "maxParams", 2);
  24012. }
  24013. calculate(e, t) {
  24014. const r = Math.max(
  24015. e.isArray() ? e.getRowCount() : 1,
  24016. t.isArray() ? t.getRowCount() : 1
  24017. ), n = Math.max(
  24018. e.isArray() ? e.getColumnCount() : 1,
  24019. t.isArray() ? t.getColumnCount() : 1
  24020. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  24021. const h = o.get(l, f);
  24022. if (c.isError())
  24023. return c;
  24024. if (h.isError())
  24025. return h;
  24026. const { isError: d, errorObject: _, variants: C } = I(c, h);
  24027. if (d)
  24028. return _;
  24029. const [E, b] = C, R = +E.getValue(), p = Math.trunc(+b.getValue()), N = this._roundBank(R, p);
  24030. return y.create(N);
  24031. });
  24032. return r === 1 && n === 1 ? u.get(0, 0) : u;
  24033. }
  24034. _roundBank(e, t) {
  24035. if (t > 16)
  24036. return e;
  24037. if (t < -16)
  24038. return 0;
  24039. const r = 1e-8, n = 10 ** t, s = +(e * n).toFixed(8), o = Math.floor(s), u = s - o;
  24040. let c = Math.round(s);
  24041. return u > 0.5 - r && u < 0.5 + r && (c = o % 2 === 0 ? o : o + 1), t ? c / n : c;
  24042. }
  24043. }
  24044. class i_ extends V {
  24045. constructor() {
  24046. super(...arguments);
  24047. A(this, "minParams", 2);
  24048. A(this, "maxParams", 2);
  24049. }
  24050. calculate(e, t) {
  24051. let r = e;
  24052. if (r.isString() && (r = r.convertToNumberObjectValue()), r.isError())
  24053. return r;
  24054. let n = t;
  24055. return n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : r.floor(n);
  24056. }
  24057. }
  24058. class o_ extends V {
  24059. constructor() {
  24060. super(...arguments);
  24061. A(this, "minParams", 2);
  24062. A(this, "maxParams", 2);
  24063. }
  24064. calculate(e, t) {
  24065. let r = e;
  24066. if (r.isString() && (r = r.convertToNumberObjectValue()), r.isError())
  24067. return r;
  24068. let n = t;
  24069. return n.isString() && (n = n.convertToNumberObjectValue()), n.isError() ? n : r.ceil(n);
  24070. }
  24071. }
  24072. class u_ extends V {
  24073. constructor() {
  24074. super(...arguments);
  24075. A(this, "minParams", 1);
  24076. A(this, "maxParams", 1);
  24077. }
  24078. calculate(e) {
  24079. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  24080. }
  24081. _handleSingleObject(e) {
  24082. let t = e;
  24083. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  24084. return t;
  24085. const r = +t.getValue();
  24086. return Math.abs(r) >= 2 ** 27 ? g.create(m.NUM) : t.cos().getReciprocal();
  24087. }
  24088. }
  24089. class c_ extends V {
  24090. constructor() {
  24091. super(...arguments);
  24092. A(this, "minParams", 1);
  24093. A(this, "maxParams", 1);
  24094. }
  24095. calculate(e) {
  24096. return e.isArray() ? e.map((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  24097. }
  24098. _handleSingleObject(e) {
  24099. let t = e;
  24100. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  24101. return t;
  24102. const r = +t.getValue();
  24103. return Number.isFinite(Math.cosh(r)) ? Math.abs(r) >= 2 ** 27 ? g.create(m.NUM) : t.cosh().getReciprocal() : y.create(0);
  24104. }
  24105. }
  24106. class l_ extends V {
  24107. constructor() {
  24108. super(...arguments);
  24109. A(this, "minParams", 1);
  24110. A(this, "maxParams", 4);
  24111. A(this, "needsSheetRowColumnCount", !0);
  24112. }
  24113. calculate(e, t, r, n) {
  24114. let s = e, o = t != null ? t : y.create(1), u = r != null ? r : y.create(1), c = n != null ? n : y.create(1);
  24115. s.isNull() && (s = y.create(1)), o.isNull() && (o = y.create(1)), u.isNull() && (u = y.create(1)), c.isNull() && (c = y.create(1));
  24116. const l = Math.max(
  24117. s.isArray() ? s.getRowCount() : 1,
  24118. o.isArray() ? o.getRowCount() : 1,
  24119. u.isArray() ? u.getRowCount() : 1,
  24120. c.isArray() ? c.getRowCount() : 1
  24121. ), f = Math.max(
  24122. s.isArray() ? s.getColumnCount() : 1,
  24123. o.isArray() ? o.getColumnCount() : 1,
  24124. u.isArray() ? u.getColumnCount() : 1,
  24125. c.isArray() ? c.getColumnCount() : 1
  24126. ), h = O(l, f, s, g.create(m.NA)), d = O(l, f, o, g.create(m.NA)), _ = O(l, f, u, g.create(m.NA)), C = O(l, f, c, g.create(m.NA)), E = h.mapValue((b, R, p) => {
  24127. const N = d.get(R, p), M = _.get(R, p), w = C.get(R, p);
  24128. return b.isError() ? b : N.isError() ? N : M.isError() ? M : w.isError() ? w : this._getResult(b, N, M, w, l, f);
  24129. });
  24130. return l === 1 && f === 1 ? E.get(0, 0) : E;
  24131. }
  24132. _getResult(e, t, r, n, s, o) {
  24133. const { isError: u, errorObject: c, variants: l } = I(e, t, r, n);
  24134. if (u)
  24135. return c;
  24136. const [f, h, d, _] = l, C = Math.floor(+f.getValue()), E = Math.floor(+h.getValue()), b = +d.getValue(), R = +_.getValue();
  24137. if (C < 0 || E < 0 || C * E > 10 ** 7)
  24138. return g.create(m.VALUE);
  24139. if (C === 0 || E === 0)
  24140. return g.create(m.CALC);
  24141. const p = this._rowCount - this.row, N = this._columnCount - this.column;
  24142. if (C > p || E > N)
  24143. return g.create(m.REF);
  24144. const M = [];
  24145. for (let w = 0; w < C; w++) {
  24146. M[w] = [];
  24147. for (let D = 0; D < E; D++)
  24148. M[w][D] = b + (w * E + D) * R;
  24149. }
  24150. return s > 1 || o > 1 ? y.create(M[0][0]) : q.createByArray(M);
  24151. }
  24152. }
  24153. class f_ extends V {
  24154. constructor() {
  24155. super(...arguments);
  24156. A(this, "minParams", 4);
  24157. A(this, "maxParams", 4);
  24158. }
  24159. calculate(e, t, r, n) {
  24160. if (e.isNull() || t.isNull() || r.isNull() || n.isNull())
  24161. return g.create(m.NA);
  24162. const { isError: s, errorObject: o, variants: u } = H(e, t, r);
  24163. if (s)
  24164. return o;
  24165. const { isError: c, errorObject: l, variants: f } = I(...u);
  24166. if (c)
  24167. return l;
  24168. const [h, d, _] = f, C = +h.getValue(), E = +d.getValue(), b = +_.getValue(), R = [];
  24169. if (n.isArray()) {
  24170. let N = !1, M = g.create(m.VALUE);
  24171. if (n.iterator((w) => {
  24172. const { isError: D, errorObject: S, coefficientsObject: P } = this._handleSingleObject(w);
  24173. if (D)
  24174. return N = !0, M = S, !1;
  24175. const U = +P.getValue();
  24176. R.push(U);
  24177. }), N)
  24178. return M;
  24179. } else {
  24180. const { isError: N, errorObject: M, coefficientsObject: w } = this._handleSingleObject(n);
  24181. if (N)
  24182. return M;
  24183. const D = +w.getValue();
  24184. R.push(D);
  24185. }
  24186. let p = 0;
  24187. for (let N = 0; N < R.length; N++)
  24188. p += R[N] * C ** (E + N * b);
  24189. return Number.isNaN(p) || !Number.isFinite(p) ? g.create(m.NUM) : y.create(p);
  24190. }
  24191. _handleSingleObject(e) {
  24192. if (e.isError())
  24193. return {
  24194. isError: !0,
  24195. errorObject: e,
  24196. coefficientsObject: null
  24197. };
  24198. if (e != null && e.isBoolean())
  24199. return {
  24200. isError: !0,
  24201. errorObject: g.create(m.VALUE),
  24202. coefficientsObject: null
  24203. };
  24204. let t = e;
  24205. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? {
  24206. isError: !0,
  24207. errorObject: t,
  24208. coefficientsObject: null
  24209. } : {
  24210. isError: !1,
  24211. errorObject: null,
  24212. coefficientsObject: t
  24213. };
  24214. }
  24215. }
  24216. class h_ extends V {
  24217. constructor() {
  24218. super(...arguments);
  24219. A(this, "minParams", 1);
  24220. A(this, "maxParams", 1);
  24221. }
  24222. calculate(e) {
  24223. if (e.isArray()) {
  24224. const t = e.mapValue((r) => this._handleSingleObject(r));
  24225. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  24226. }
  24227. return this._handleSingleObject(e);
  24228. }
  24229. _handleSingleObject(e) {
  24230. if (e.isError())
  24231. return e;
  24232. const { isError: t, errorObject: r, variants: n } = I(e);
  24233. if (t)
  24234. return r;
  24235. const [s] = n, o = +s.getValue();
  24236. return o > 0 ? y.create(1) : o < 0 ? y.create(-1) : y.create(0);
  24237. }
  24238. }
  24239. class m_ extends V {
  24240. constructor() {
  24241. super(...arguments);
  24242. A(this, "minParams", 1);
  24243. A(this, "maxParams", 1);
  24244. }
  24245. calculate(e) {
  24246. let t = e;
  24247. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.sin();
  24248. }
  24249. }
  24250. class g_ extends V {
  24251. constructor() {
  24252. super(...arguments);
  24253. A(this, "minParams", 1);
  24254. A(this, "maxParams", 1);
  24255. }
  24256. calculate(e) {
  24257. let t = e;
  24258. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.sinh();
  24259. }
  24260. }
  24261. class d_ extends V {
  24262. constructor() {
  24263. super(...arguments);
  24264. A(this, "minParams", 1);
  24265. A(this, "maxParams", 1);
  24266. }
  24267. calculate(e) {
  24268. let t = e;
  24269. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.sqrt();
  24270. }
  24271. }
  24272. class C_ extends V {
  24273. constructor() {
  24274. super(...arguments);
  24275. A(this, "minParams", 1);
  24276. A(this, "maxParams", 1);
  24277. }
  24278. calculate(e) {
  24279. let t = e;
  24280. if (t.isArray()) {
  24281. const s = t.getRowCount(), o = t.getColumnCount();
  24282. if (s > 1 || o > 1)
  24283. return g.create(m.VALUE);
  24284. t = t.get(0, 0);
  24285. }
  24286. if (t.isString() && (t = t.convertToNumberObjectValue()), t.isError())
  24287. return t;
  24288. const r = +t.getValue();
  24289. if (r < 0)
  24290. return g.create(m.NUM);
  24291. const n = Math.sqrt(r * Math.PI);
  24292. return y.create(n);
  24293. }
  24294. }
  24295. class __ extends V {
  24296. constructor() {
  24297. super(...arguments);
  24298. A(this, "minParams", 2);
  24299. A(this, "maxParams", 255);
  24300. A(this, "needsReferenceObject", !0);
  24301. }
  24302. calculate(e, ...t) {
  24303. if (e.isError())
  24304. return e;
  24305. if (e.isReferenceObject()) {
  24306. const r = [];
  24307. return e.iterator((n, s, o) => {
  24308. r[s] == null && (r[s] = []), r[s][o] = this._handleSingleObject(
  24309. n,
  24310. ...t
  24311. );
  24312. }), tr(r, r.length, r[0].length);
  24313. }
  24314. return this._handleSingleObject(e, ...t);
  24315. }
  24316. // eslint-disable-next-line max-lines-per-function, complexity
  24317. _handleSingleObject(e, ...t) {
  24318. const r = this._getIndexNumValue(e);
  24319. let n;
  24320. if (r instanceof g)
  24321. return r;
  24322. switch (r) {
  24323. case 1:
  24324. n = this._average(!1, ...t);
  24325. break;
  24326. case 2:
  24327. n = this._count(!1, ...t);
  24328. break;
  24329. case 3:
  24330. n = this._counta(!1, ...t);
  24331. break;
  24332. case 4:
  24333. n = this._max(!1, ...t);
  24334. break;
  24335. case 5:
  24336. n = this._min(!1, ...t);
  24337. break;
  24338. case 6:
  24339. n = this._product(!1, ...t);
  24340. break;
  24341. case 7:
  24342. n = this._stdev(!1, ...t);
  24343. break;
  24344. case 8:
  24345. n = this._stdevp(!1, ...t);
  24346. break;
  24347. case 9:
  24348. n = this._sum(!1, ...t);
  24349. break;
  24350. case 10:
  24351. n = this._var(!1, ...t);
  24352. break;
  24353. case 11:
  24354. n = this._varp(!1, ...t);
  24355. break;
  24356. case 101:
  24357. n = this._average(!0, ...t);
  24358. break;
  24359. case 102:
  24360. n = this._count(!0, ...t);
  24361. break;
  24362. case 103:
  24363. n = this._counta(!0, ...t);
  24364. break;
  24365. case 104:
  24366. n = this._max(!0, ...t);
  24367. break;
  24368. case 105:
  24369. n = this._min(!0, ...t);
  24370. break;
  24371. case 106:
  24372. n = this._product(!0, ...t);
  24373. break;
  24374. case 107:
  24375. n = this._stdev(!0, ...t);
  24376. break;
  24377. case 108:
  24378. n = this._stdevp(!0, ...t);
  24379. break;
  24380. case 109:
  24381. n = this._sum(!0, ...t);
  24382. break;
  24383. case 110:
  24384. n = this._var(!0, ...t);
  24385. break;
  24386. case 111:
  24387. n = this._varp(!0, ...t);
  24388. break;
  24389. default:
  24390. n = g.create(m.VALUE);
  24391. }
  24392. return n;
  24393. }
  24394. _getIndexNumValue(e) {
  24395. const t = e ? Number(e.getValue()) : 0;
  24396. if (Number.isNaN(t))
  24397. return g.create(m.VALUE);
  24398. const r = Math.floor(t);
  24399. return r >= 1 && r <= 11 || r >= 101 && r <= 111 ? r : g.create(m.VALUE);
  24400. }
  24401. _average(e, ...t) {
  24402. const r = this._flattenRefArray(e, ...t);
  24403. return r.isError() ? r : r.mean();
  24404. }
  24405. _count(e, ...t) {
  24406. let r = y.create(0);
  24407. for (let n = 0; n < t.length; n++) {
  24408. const s = t[n];
  24409. if (!s.isReferenceObject())
  24410. return g.create(m.VALUE);
  24411. const o = s.getRowData();
  24412. s.iterator((u, c) => {
  24413. if (e && this._isRowHidden(o, c))
  24414. return !0;
  24415. u != null && u.isNumber() && (r = r.plusBy(1));
  24416. });
  24417. }
  24418. return r;
  24419. }
  24420. _counta(e, ...t) {
  24421. let r = y.create(0);
  24422. for (let n = 0; n < t.length; n++) {
  24423. const s = t[n];
  24424. if (!s.isReferenceObject())
  24425. return g.create(m.VALUE);
  24426. const o = s.getRowData();
  24427. s.iterator((u, c) => {
  24428. if (e && this._isRowHidden(o, c) || u == null || u.isNull())
  24429. return !0;
  24430. r = r.plusBy(1);
  24431. });
  24432. }
  24433. return r;
  24434. }
  24435. _max(e, ...t) {
  24436. const r = this._flattenRefArray(e, ...t);
  24437. return r.isError() ? r : this._isBlankArrayObject(r) ? y.create(0) : r.max();
  24438. }
  24439. _min(e, ...t) {
  24440. const r = this._flattenRefArray(e, ...t);
  24441. return r.isError() ? r : this._isBlankArrayObject(r) ? y.create(0) : r.min();
  24442. }
  24443. _product(e, ...t) {
  24444. const r = this._flattenRefArray(e, ...t);
  24445. if (r.isError())
  24446. return r;
  24447. if (this._isBlankArrayObject(r))
  24448. return y.create(0);
  24449. let n = y.create(1);
  24450. return r.iterator((s) => {
  24451. n = n.multiply(
  24452. s
  24453. );
  24454. }), n;
  24455. }
  24456. _stdev(e, ...t) {
  24457. const r = this._flattenRefArray(e, ...t);
  24458. return r.isError() ? r : this._isBlankArrayObject(r) ? g.create(m.DIV_BY_ZERO) : r.std(1);
  24459. }
  24460. _stdevp(e, ...t) {
  24461. const r = this._flattenRefArray(e, ...t);
  24462. return r.isError() ? r : this._isBlankArrayObject(r) ? g.create(m.DIV_BY_ZERO) : r.std();
  24463. }
  24464. _sum(e, ...t) {
  24465. const r = this._flattenRefArray(e, ...t);
  24466. return r.isError() ? r : r.sum();
  24467. }
  24468. _var(e, ...t) {
  24469. const r = this._flattenRefArray(e, ...t);
  24470. return r.isError() ? r : this._isBlankArrayObject(r) ? g.create(m.DIV_BY_ZERO) : r.var(1);
  24471. }
  24472. _varp(e, ...t) {
  24473. const r = this._flattenRefArray(e, ...t);
  24474. return r.isError() ? r : this._isBlankArrayObject(r) ? g.create(m.DIV_BY_ZERO) : r.var();
  24475. }
  24476. _flattenRefArray(e, ...t) {
  24477. const r = [];
  24478. r[0] = [];
  24479. for (let n = 0; n < t.length; n++) {
  24480. const s = t[n];
  24481. if (s.isError())
  24482. return s;
  24483. if (!s.isReferenceObject())
  24484. return g.create(m.VALUE);
  24485. const o = s.getRowData();
  24486. let u;
  24487. if (s.iterator((c, l) => {
  24488. if (e && this._isRowHidden(o, l) || c == null || c.isNull() || c.isString() || c.isBoolean())
  24489. return !0;
  24490. if (c.isError())
  24491. return u = c, !1;
  24492. r[0].push(c);
  24493. }), u != null && u.isError())
  24494. return u;
  24495. }
  24496. return tr(r, 1, r[0].length);
  24497. }
  24498. _isRowHidden(e, t) {
  24499. const r = e[t];
  24500. return r ? r.hd === Wu.TRUE : !1;
  24501. }
  24502. _isBlankArrayObject(e) {
  24503. return e.getArrayValue()[0].length === 0;
  24504. }
  24505. }
  24506. class A_ extends V {
  24507. constructor() {
  24508. super(...arguments);
  24509. A(this, "minParams", 1);
  24510. A(this, "maxParams", 255);
  24511. }
  24512. calculate(...e) {
  24513. let t = y.create(0);
  24514. for (let r = 0; r < e.length; r++) {
  24515. let n = e[r];
  24516. if (n.isString() && (n = n.convertToNumberObjectValue()), n.isError() || (n.isArray() && (n = n.sum()), n.isError()))
  24517. return n;
  24518. if (t = t.plus(n), t.isError())
  24519. return t;
  24520. }
  24521. return t;
  24522. }
  24523. }
  24524. class E_ extends V {
  24525. constructor() {
  24526. super(...arguments);
  24527. A(this, "minParams", 2);
  24528. A(this, "maxParams", 3);
  24529. A(this, "needsReferenceObject", !0);
  24530. }
  24531. calculate(e, t, r) {
  24532. let n = t;
  24533. if (t.isReferenceObject() && (n = t.toArrayValueObject()), n.isArray()) {
  24534. const s = n.mapValue((o) => this._handleSingleObject(e, o, r));
  24535. return s.getRowCount() === 1 && s.getColumnCount() === 1 ? s.get(0, 0) : s;
  24536. }
  24537. return this._handleSingleObject(e, n, r);
  24538. }
  24539. _handleSingleObject(e, t, r) {
  24540. if (e.isError())
  24541. return e;
  24542. if (t.isError())
  24543. return t;
  24544. if (r != null && r.isError())
  24545. return r;
  24546. if (!e.isReferenceObject() || r && !r.isReferenceObject())
  24547. return g.create(m.VALUE);
  24548. const n = e.toArrayValueObject();
  24549. let s = $n(n, t);
  24550. s = Yn(s, n, t);
  24551. const o = n.getRowCount(), u = n.getColumnCount();
  24552. let c = n;
  24553. if (r) {
  24554. c = r.toArrayValueObject();
  24555. const l = c.getRowCount(), f = c.getColumnCount();
  24556. if (o !== l || u !== f) {
  24557. const h = r.getRangeData();
  24558. h.endRow = h.startRow + o - 1, h.endColumn = h.startColumn + u - 1, r.setRangeData(h), c = r.toArrayValueObject();
  24559. }
  24560. }
  24561. return c.pick(s).sum();
  24562. }
  24563. }
  24564. class b_ extends V {
  24565. constructor() {
  24566. super(...arguments);
  24567. A(this, "minParams", 3);
  24568. A(this, "maxParams", 255);
  24569. }
  24570. calculate(e, ...t) {
  24571. if (e.isError())
  24572. return e;
  24573. if (!e.isArray() || t.length < 2 || t.length % 2 !== 0 || t.some((u, c) => c % 2 === 0 && !u.isArray()))
  24574. return g.create(m.VALUE);
  24575. const { maxRowLength: r, maxColumnLength: n } = Nr(t), s = Br(t, e, r, n);
  24576. if (s)
  24577. return s;
  24578. const o = Ir(t, r, n, !0);
  24579. return this._aggregateResults(e, o);
  24580. }
  24581. _aggregateResults(e, t) {
  24582. const r = t.map((s) => s.map((o) => e.pick(o).sum())), n = {
  24583. calculateValueList: r,
  24584. rowCount: r.length,
  24585. columnCount: r[0].length,
  24586. unitId: this.unitId || "",
  24587. sheetId: this.subUnitId || "",
  24588. row: this.row,
  24589. column: this.column
  24590. };
  24591. return q.create(n);
  24592. }
  24593. }
  24594. class y_ extends V {
  24595. constructor() {
  24596. super(...arguments);
  24597. A(this, "minParams", 1);
  24598. A(this, "maxParams", 255);
  24599. }
  24600. calculate(e, ...t) {
  24601. if (e.isError())
  24602. return e;
  24603. const r = this._initArray1(e);
  24604. if (t.length > 0) {
  24605. const n = r.getRowCount(), s = r.getColumnCount();
  24606. let o = this._getResultArrayByArray1(n, s, r);
  24607. if (o instanceof g)
  24608. return o;
  24609. o = o;
  24610. for (let c = 0; c < t.length; c++) {
  24611. if (t[c].isError())
  24612. return t[c];
  24613. let l = 1, f = 1;
  24614. if (t[c].isArray() && (l = t[c].getRowCount(), f = t[c].getColumnCount()), l !== n || f !== s)
  24615. return g.create(m.VALUE);
  24616. for (let h = 0; h < n; h++) {
  24617. const d = [];
  24618. for (let _ = 0; _ < s; _++) {
  24619. let C = t[c];
  24620. if (t[c].isArray() && (C = t[c].get(h, _)), C.isError())
  24621. return C;
  24622. const E = C.getValue();
  24623. !E || !Q(E) ? d.push(0) : d.push(+E * o[h][_]);
  24624. }
  24625. o[h] = d;
  24626. }
  24627. }
  24628. const u = o.reduce((c, l) => c.concat(l)).reduce((c, l) => c + l, 0);
  24629. return y.create(u);
  24630. } else
  24631. return r.sum();
  24632. }
  24633. _initArray1(e) {
  24634. let t = e;
  24635. return t.isArray() || (t = q.create({
  24636. calculateValueList: [[t]],
  24637. rowCount: 1,
  24638. columnCount: 1,
  24639. unitId: "",
  24640. sheetId: "",
  24641. row: 0,
  24642. column: 0
  24643. })), t;
  24644. }
  24645. _getResultArrayByArray1(e, t, r) {
  24646. const n = [];
  24647. for (let s = 0; s < e; s++) {
  24648. const o = [];
  24649. for (let u = 0; u < t; u++) {
  24650. const c = r.get(s, u);
  24651. if (c.isError())
  24652. return c;
  24653. const l = c.getValue();
  24654. !l || !Q(l) ? o.push(0) : o.push(+l);
  24655. }
  24656. n.push(o);
  24657. }
  24658. return n;
  24659. }
  24660. }
  24661. class R_ extends V {
  24662. constructor() {
  24663. super(...arguments);
  24664. A(this, "minParams", 1);
  24665. A(this, "maxParams", 255);
  24666. }
  24667. calculate(...e) {
  24668. let t = y.create(0);
  24669. const r = y.create(2);
  24670. for (let n = 0; n < e.length; n++) {
  24671. let s = e[n];
  24672. if (s.isString() && (s = s.convertToNumberObjectValue()), s.isError())
  24673. return s;
  24674. if (s.isArray() ? s.iterator((o) => {
  24675. if (o == null || o.isString() || o.isBoolean() || o.isNull())
  24676. return !0;
  24677. if (o.isError())
  24678. return t = o, !1;
  24679. t = t.plus(
  24680. o.pow(r)
  24681. );
  24682. }) : t = t.plus(s.pow(r)), t.isError())
  24683. return t;
  24684. }
  24685. return t;
  24686. }
  24687. }
  24688. class p_ extends V {
  24689. constructor() {
  24690. super(...arguments);
  24691. A(this, "minParams", 2);
  24692. A(this, "maxParams", 2);
  24693. }
  24694. calculate(e, t) {
  24695. if (e.isError())
  24696. return e;
  24697. if (t.isError())
  24698. return t;
  24699. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = r * n, o = t.isArray() ? t.getRowCount() : 1, u = t.isArray() ? t.getColumnCount() : 1, c = o * u;
  24700. if (s !== c)
  24701. return g.create(m.NA);
  24702. if (s === 1)
  24703. return this._calculateSingleCell(e, t);
  24704. {
  24705. const l = e.flatten(), f = t.flatten();
  24706. let h = ie.create();
  24707. const d = [], _ = [];
  24708. let C = 0;
  24709. return l.iterator((E, b, R) => {
  24710. const p = f.get(b, R);
  24711. if (E == null || E.isString() || E.isBoolean() || E.isNull())
  24712. return !0;
  24713. if (E != null && E.isError())
  24714. return h = E, !1;
  24715. if (p == null || p.isString() || p.isBoolean() || p.isNull())
  24716. return !0;
  24717. if (p != null && p.isError())
  24718. return h = p, !1;
  24719. const N = +E.getValue(), M = +p.getValue();
  24720. d.push(N), _.push(M), C += N ** 2 - M ** 2;
  24721. }), h.isError() ? h : d.length === 0 || _.length === 0 ? g.create(m.DIV_BY_ZERO) : y.create(C);
  24722. }
  24723. }
  24724. _calculateSingleCell(e, t) {
  24725. let r = e;
  24726. if (r.isArray() && (r = r.get(0, 0)), r.isError())
  24727. return r;
  24728. let n = t;
  24729. if (n.isArray() && (n = n.get(0, 0)), n.isError())
  24730. return n;
  24731. if (r.isNull() || n.isNull())
  24732. return g.create(m.VALUE);
  24733. const s = +r.getValue(), o = +n.getValue();
  24734. if (r.isString() && !Q(s) || r.isBoolean() || n.isString() && !Q(o) || n.isBoolean())
  24735. return g.create(m.DIV_BY_ZERO);
  24736. const u = s ** 2 - o ** 2;
  24737. return y.create(u);
  24738. }
  24739. }
  24740. class V_ extends V {
  24741. constructor() {
  24742. super(...arguments);
  24743. A(this, "minParams", 2);
  24744. A(this, "maxParams", 2);
  24745. }
  24746. calculate(e, t) {
  24747. if (e.isError())
  24748. return e;
  24749. if (t.isError())
  24750. return t;
  24751. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = r * n, o = t.isArray() ? t.getRowCount() : 1, u = t.isArray() ? t.getColumnCount() : 1, c = o * u;
  24752. if (s !== c)
  24753. return g.create(m.NA);
  24754. if (s === 1)
  24755. return this._calculateSingleCell(e, t);
  24756. {
  24757. const l = e.flatten(), f = t.flatten();
  24758. let h = ie.create();
  24759. const d = [], _ = [];
  24760. let C = 0;
  24761. return l.iterator((E, b, R) => {
  24762. const p = f.get(b, R);
  24763. if (E == null || E.isString() || E.isBoolean() || E.isNull())
  24764. return !0;
  24765. if (E != null && E.isError())
  24766. return h = E, !1;
  24767. if (p == null || p.isString() || p.isBoolean() || p.isNull())
  24768. return !0;
  24769. if (p != null && p.isError())
  24770. return h = p, !1;
  24771. const N = +E.getValue(), M = +p.getValue();
  24772. d.push(N), _.push(M), C += N ** 2 + M ** 2;
  24773. }), h.isError() ? h : d.length === 0 || _.length === 0 ? g.create(m.DIV_BY_ZERO) : y.create(C);
  24774. }
  24775. }
  24776. _calculateSingleCell(e, t) {
  24777. let r = e;
  24778. if (r.isArray() && (r = r.get(0, 0)), r.isError())
  24779. return r;
  24780. let n = t;
  24781. if (n.isArray() && (n = n.get(0, 0)), n.isError())
  24782. return n;
  24783. if (r.isNull() || n.isNull())
  24784. return g.create(m.VALUE);
  24785. const s = +r.getValue(), o = +n.getValue();
  24786. if (r.isString() && !Q(s) || r.isBoolean() || n.isString() && !Q(o) || n.isBoolean())
  24787. return g.create(m.DIV_BY_ZERO);
  24788. const u = s ** 2 + o ** 2;
  24789. return y.create(u);
  24790. }
  24791. }
  24792. class N_ extends V {
  24793. constructor() {
  24794. super(...arguments);
  24795. A(this, "minParams", 2);
  24796. A(this, "maxParams", 2);
  24797. }
  24798. calculate(e, t) {
  24799. if (e.isError())
  24800. return e;
  24801. if (t.isError())
  24802. return t;
  24803. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = r * n, o = t.isArray() ? t.getRowCount() : 1, u = t.isArray() ? t.getColumnCount() : 1, c = o * u;
  24804. if (s !== c)
  24805. return g.create(m.NA);
  24806. if (s === 1)
  24807. return this._calculateSingleCell(e, t);
  24808. {
  24809. const l = e.flatten(), f = t.flatten();
  24810. let h = ie.create();
  24811. const d = [], _ = [];
  24812. let C = 0;
  24813. return l.iterator((E, b, R) => {
  24814. const p = f.get(b, R);
  24815. if (E == null || E.isString() || E.isBoolean() || E.isNull())
  24816. return !0;
  24817. if (E != null && E.isError())
  24818. return h = E, !1;
  24819. if (p == null || p.isString() || p.isBoolean() || p.isNull())
  24820. return !0;
  24821. if (p != null && p.isError())
  24822. return h = p, !1;
  24823. const N = +E.getValue(), M = +p.getValue();
  24824. d.push(N), _.push(M), C += (N - M) ** 2;
  24825. }), h.isError() ? h : d.length === 0 || _.length === 0 ? g.create(m.DIV_BY_ZERO) : y.create(C);
  24826. }
  24827. }
  24828. _calculateSingleCell(e, t) {
  24829. let r = e;
  24830. if (r.isArray() && (r = r.get(0, 0)), r.isError())
  24831. return r;
  24832. let n = t;
  24833. if (n.isArray() && (n = n.get(0, 0)), n.isError())
  24834. return n;
  24835. if (r.isNull() || n.isNull())
  24836. return g.create(m.VALUE);
  24837. const s = +r.getValue(), o = +n.getValue();
  24838. if (r.isString() && !Q(s) || r.isBoolean() || n.isString() && !Q(o) || n.isBoolean())
  24839. return g.create(m.DIV_BY_ZERO);
  24840. const u = (s - o) ** 2;
  24841. return y.create(u);
  24842. }
  24843. }
  24844. class O_ extends V {
  24845. constructor() {
  24846. super(...arguments);
  24847. A(this, "minParams", 1);
  24848. A(this, "maxParams", 1);
  24849. }
  24850. calculate(e) {
  24851. let t = e;
  24852. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.tan();
  24853. }
  24854. }
  24855. class M_ extends V {
  24856. constructor() {
  24857. super(...arguments);
  24858. A(this, "minParams", 1);
  24859. A(this, "maxParams", 1);
  24860. }
  24861. calculate(e) {
  24862. let t = e;
  24863. return t.isString() && (t = t.convertToNumberObjectValue()), t.isError() ? t : t.tanh();
  24864. }
  24865. }
  24866. class w_ extends V {
  24867. constructor() {
  24868. super(...arguments);
  24869. A(this, "minParams", 1);
  24870. A(this, "maxParams", 2);
  24871. }
  24872. calculate(e, t) {
  24873. const r = t != null ? t : y.create(0), n = Math.max(
  24874. e.isArray() ? e.getRowCount() : 1,
  24875. r.isArray() ? r.getRowCount() : 1
  24876. ), s = Math.max(
  24877. e.isArray() ? e.getColumnCount() : 1,
  24878. r.isArray() ? r.getColumnCount() : 1
  24879. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.map((l, f, h) => {
  24880. let d = u.get(f, h), _ = l;
  24881. if (_.isString() && (_ = _.convertToNumberObjectValue()), _.isError())
  24882. return _;
  24883. if (d.isString() && (d = d.convertToNumberObjectValue()), d.isError())
  24884. return d;
  24885. const C = +_.getValue(), E = +d.getValue(), b = 10 ** Math.trunc(E), R = Bn(C, b), p = Math.trunc(Vr(C, b) + R) / b;
  24886. return y.create(p);
  24887. });
  24888. return n === 1 && s === 1 ? c.get(0, 0) : c;
  24889. }
  24890. }
  24891. const D_ = [
  24892. [nC, Y.ABS],
  24893. [sC, Y.ACOS],
  24894. [aC, Y.ACOSH],
  24895. [iC, Y.ACOT],
  24896. [oC, Y.ACOTH],
  24897. [uC, Y.ARABIC],
  24898. [cC, Y.ASIN],
  24899. [lC, Y.ASINH],
  24900. [fC, Y.ATAN],
  24901. [hC, Y.ATAN2],
  24902. [mC, Y.ATANH],
  24903. [gC, Y.BASE],
  24904. [dC, Y.CEILING],
  24905. [CC, Y.CEILING_MATH],
  24906. [_C, Y.CEILING_PRECISE],
  24907. [AC, Y.COMBIN],
  24908. [EC, Y.COMBINA],
  24909. [bC, Y.COS],
  24910. [yC, Y.COSH],
  24911. [RC, Y.COT],
  24912. [pC, Y.COTH],
  24913. [VC, Y.CSC],
  24914. [NC, Y.CSCH],
  24915. [OC, Y.DECIMAL],
  24916. [MC, Y.DEGREES],
  24917. [wC, Y.EVEN],
  24918. [DC, Y.EXP],
  24919. [SC, Y.FACT],
  24920. [PC, Y.FACTDOUBLE],
  24921. [LC, Y.FLOOR],
  24922. [xC, Y.FLOOR_MATH],
  24923. [jC, Y.FLOOR_PRECISE],
  24924. [UC, Y.GCD],
  24925. [vC, Y.INT],
  24926. [TC, Y.LCM],
  24927. [BC, Y.LN],
  24928. [IC, Y.LOG],
  24929. [FC, Y.LOG10],
  24930. [kC, Y.MDETERM],
  24931. [$C, Y.MINVERSE],
  24932. [YC, Y.MMULT],
  24933. [HC, Y.MOD],
  24934. [GC, Y.MROUND],
  24935. [QC, Y.MULTINOMIAL],
  24936. [WC, Y.MUNIT],
  24937. [qC, Y.ODD],
  24938. [KC, Y.PI],
  24939. [XC, Y.POWER],
  24940. [ZC, Y.PRODUCT],
  24941. [zC, Y.QUOTIENT],
  24942. [JC, Y.RADIANS],
  24943. [e_, Y.RAND],
  24944. [t_, Y.RANDARRAY],
  24945. [r_, Y.RANDBETWEEN],
  24946. [n_, Y.ROMAN],
  24947. [s_, Y.ROUND],
  24948. [a_, Y.ROUNDBANK],
  24949. [i_, Y.ROUNDDOWN],
  24950. [o_, Y.ROUNDUP],
  24951. [u_, Y.SEC],
  24952. [c_, Y.SECH],
  24953. [f_, Y.SERIESSUM],
  24954. [l_, Y.SEQUENCE],
  24955. [h_, Y.SIGN],
  24956. [m_, Y.SIN],
  24957. [g_, Y.SINH],
  24958. [d_, Y.SQRT],
  24959. [C_, Y.SQRTPI],
  24960. [__, Y.SUBTOTAL],
  24961. [A_, Y.SUM],
  24962. [E_, Y.SUMIF],
  24963. [b_, Y.SUMIFS],
  24964. [y_, Y.SUMPRODUCT],
  24965. [R_, Y.SUMSQ],
  24966. [p_, Y.SUMX2MY2],
  24967. [V_, Y.SUMX2PY2],
  24968. [N_, Y.SUMXMY2],
  24969. [O_, Y.TAN],
  24970. [M_, Y.TANH],
  24971. [w_, Y.TRUNC]
  24972. ];
  24973. class S_ extends V {
  24974. constructor() {
  24975. super(...arguments);
  24976. A(this, "minParams", 2);
  24977. A(this, "maxParams", 2);
  24978. A(this, "_compareType", $.EQUALS);
  24979. }
  24980. setCompareType(e) {
  24981. this._compareType = e;
  24982. }
  24983. calculate(e, t) {
  24984. return e.isError() ? e : t.isError() ? t : e.compare(t, this._compareType);
  24985. }
  24986. }
  24987. class Fa extends kt {
  24988. constructor(e) {
  24989. super("");
  24990. A(this, "_values", []);
  24991. this._values = e;
  24992. }
  24993. static create(e) {
  24994. return new Fa(e);
  24995. }
  24996. isCube() {
  24997. return !0;
  24998. }
  24999. dispose() {
  25000. this._values.forEach((e) => {
  25001. e.dispose();
  25002. }), this._values = [];
  25003. }
  25004. sum() {
  25005. const e = y.create(0);
  25006. return this._values.forEach((t) => {
  25007. e.plus(t.sum());
  25008. }), e;
  25009. }
  25010. max() {
  25011. let e = y.create(Number.NEGATIVE_INFINITY);
  25012. return this._values.forEach((t) => {
  25013. const r = t.max();
  25014. e.isLessThan(r) && (e = r);
  25015. }), e;
  25016. }
  25017. min() {
  25018. let e = y.create(Number.POSITIVE_INFINITY);
  25019. return this._values.forEach((t) => {
  25020. const r = t.max();
  25021. e.isGreaterThan(r) && (e = r);
  25022. }), e;
  25023. }
  25024. count() {
  25025. const e = y.create(0);
  25026. return this._values.forEach((t) => {
  25027. e.plus(t.count());
  25028. }), e;
  25029. }
  25030. countA() {
  25031. const e = y.create(0);
  25032. return this._values.forEach((t) => {
  25033. e.plus(t.countA());
  25034. }), e;
  25035. }
  25036. countBlank() {
  25037. const e = y.create(0);
  25038. return this._values.forEach((t) => {
  25039. e.plus(t.countBlank());
  25040. }), e;
  25041. }
  25042. }
  25043. class P_ extends V {
  25044. constructor() {
  25045. super(...arguments);
  25046. A(this, "minParams", 1);
  25047. A(this, "maxParams", 255);
  25048. }
  25049. calculate(...e) {
  25050. const t = [];
  25051. for (let r = 0; r < e.length; r++) {
  25052. const n = e[r];
  25053. if (n.isError())
  25054. return n;
  25055. if (!n.isArray())
  25056. return g.create(m.VALUE);
  25057. t.push(n);
  25058. }
  25059. return Fa.create(t);
  25060. }
  25061. }
  25062. class L_ extends V {
  25063. constructor() {
  25064. super(...arguments);
  25065. A(this, "minParams", 2);
  25066. A(this, "maxParams", 2);
  25067. }
  25068. calculate(e, t) {
  25069. return e.isError() ? e : t.isError() ? t : !t.isArray() && t.getValue() === 0 ? g.create(m.DIV_BY_ZERO) : e.divided(t);
  25070. }
  25071. }
  25072. class x_ extends V {
  25073. constructor() {
  25074. super(...arguments);
  25075. A(this, "minParams", 2);
  25076. A(this, "maxParams", 2);
  25077. }
  25078. calculate(e, t) {
  25079. return e.isError() ? e : t.isError() ? t : e.minus(t);
  25080. }
  25081. }
  25082. class j_ extends V {
  25083. constructor() {
  25084. super(...arguments);
  25085. A(this, "minParams", 2);
  25086. A(this, "maxParams", 2);
  25087. }
  25088. calculate(e, t) {
  25089. return e.isError() ? e : t.isError() ? t : e.multiply(t);
  25090. }
  25091. }
  25092. class U_ extends V {
  25093. constructor() {
  25094. super(...arguments);
  25095. A(this, "minParams", 2);
  25096. A(this, "maxParams", 2);
  25097. }
  25098. calculate(e, t) {
  25099. return e.isError() ? e : t.isError() ? t : e.plus(t);
  25100. }
  25101. }
  25102. const v_ = [
  25103. [S_, Te.COMPARE],
  25104. [L_, Te.DIVIDED],
  25105. [x_, Te.MINUS],
  25106. [j_, Te.MULTIPLY],
  25107. [U_, Te.PLUS],
  25108. [P_, Te.CUBE]
  25109. ];
  25110. class T_ extends V {
  25111. constructor() {
  25112. super(...arguments);
  25113. A(this, "minParams", 1);
  25114. A(this, "maxParams", 255);
  25115. }
  25116. calculate(...e) {
  25117. let t = y.create(0), r = y.create(0);
  25118. for (let o = 0; o < e.length; o++) {
  25119. let u = e[o];
  25120. if (u.isString() && (u = u.convertToNumberObjectValue()), u.isError())
  25121. return u;
  25122. if (u.isArray()) {
  25123. if (u = B_(u), u.isError())
  25124. return u;
  25125. if (e[o] = u, t = t.plus(u.sum()), t.isError())
  25126. return t;
  25127. r = r.plus(u.count());
  25128. } else u.isNull() || (t = t.plus(u), r = r.plus(y.create(1)));
  25129. }
  25130. if (r.getValue() === 0)
  25131. return g.create(m.NUM);
  25132. const n = t.divided(r);
  25133. if (n.isError())
  25134. return n;
  25135. let s = y.create(0);
  25136. for (let o = 0; o < e.length; o++) {
  25137. let u = e[o];
  25138. if (u.isString() && (u = u.convertToNumberObjectValue()), u.isError())
  25139. return u;
  25140. if (u.isArray()) {
  25141. if (s = s.plus(u.minus(n).abs().sum()), s.isError())
  25142. return s;
  25143. } else u.isNull() || (s = s.plus(u.minus(n).abs()));
  25144. }
  25145. return s.divided(r);
  25146. }
  25147. }
  25148. function B_(i) {
  25149. const a = [];
  25150. a[0] = [];
  25151. let e = null;
  25152. return i.iterator((t, r, n) => {
  25153. if (t != null && t.isError())
  25154. return e = t, !1;
  25155. t != null && t.isNumber() && a[0].push(t);
  25156. }), e || tr(a, 1, a[0].length);
  25157. }
  25158. class I_ extends V {
  25159. constructor() {
  25160. super(...arguments);
  25161. A(this, "minParams", 1);
  25162. A(this, "maxParams", 255);
  25163. }
  25164. calculate(...e) {
  25165. let t = y.create(0), r = y.create(0);
  25166. for (let n = 0; n < e.length; n++) {
  25167. let s = e[n];
  25168. if ((s.isString() || s.isBoolean()) && (s = s.convertToNumberObjectValue()), s.isError())
  25169. return s;
  25170. if (s.isArray()) {
  25171. if (t = t.plus(s.sum()), t.isError())
  25172. return t;
  25173. r = r.plus(s.count());
  25174. } else s.isNull() || (t = t.plus(s), r = r.plus(y.create(1)));
  25175. }
  25176. return t.divided(r);
  25177. }
  25178. }
  25179. class F_ extends V {
  25180. constructor() {
  25181. super(...arguments);
  25182. A(this, "minParams", 2);
  25183. A(this, "maxParams", 254);
  25184. }
  25185. // eslint-disable-next-line
  25186. calculate(...e) {
  25187. let t = !1, r;
  25188. e.length % 2 !== 0 && (t = !0, r = g.create(m.NA));
  25189. const n = [], s = [];
  25190. for (let o = 0; o < e.length; o += 2) {
  25191. const u = e[o], c = u.isArray() ? u.getRowCount() : 1, l = u.isArray() ? u.getColumnCount() : 1;
  25192. for (let _ = 0; _ < c; _++)
  25193. for (let C = 0; C < l; C++) {
  25194. const E = u.isArray() ? u.get(_, C) : u;
  25195. if (E.isError())
  25196. return E;
  25197. if (t)
  25198. continue;
  25199. const b = E.isNull() ? "" : E.getValue();
  25200. n.push(b);
  25201. }
  25202. if (o + 1 >= e.length)
  25203. continue;
  25204. const f = e[o + 1], h = f.isArray() ? f.getRowCount() : 1, d = f.isArray() ? f.getColumnCount() : 1;
  25205. (h !== c || d !== l) && (t = !0, r = g.create(m.VALUE));
  25206. for (let _ = 0; _ < h; _++)
  25207. for (let C = 0; C < d; C++) {
  25208. const E = f.isArray() ? f.get(_, C) : f;
  25209. if (E.isError())
  25210. return E;
  25211. if (t)
  25212. continue;
  25213. const b = E.isNull() ? "" : E.getValue();
  25214. s.push(b);
  25215. }
  25216. }
  25217. return t ? r : this._getResult(n, s);
  25218. }
  25219. _getResult(e, t) {
  25220. const r = e.length;
  25221. let n = 0, s = 0;
  25222. for (let u = 0; u < r; u++) {
  25223. const c = e[u], l = t[u];
  25224. if (!(typeof c != "number" && typeof l != "number")) {
  25225. if (typeof c != "number" || typeof l != "number" || l < 0)
  25226. return g.create(m.VALUE);
  25227. n += c * l, s += l;
  25228. }
  25229. }
  25230. if (s === 0)
  25231. return g.create(m.DIV_BY_ZERO);
  25232. const o = n / s;
  25233. return y.create(o);
  25234. }
  25235. }
  25236. class k_ extends V {
  25237. constructor() {
  25238. super(...arguments);
  25239. A(this, "minParams", 1);
  25240. A(this, "maxParams", 255);
  25241. }
  25242. calculate(...e) {
  25243. let t = y.create(0), r = y.create(0);
  25244. for (let n = 0; n < e.length; n++) {
  25245. let s = e[n];
  25246. if ((s.isString() || s.isBoolean()) && (s = s.convertToNumberObjectValue()), s.isError())
  25247. return s;
  25248. if (s.isArray()) {
  25249. if (s.iterator((o) => {
  25250. if (o == null || o.isNull())
  25251. return !0;
  25252. let u = o;
  25253. if (u.isString() && (u = u.convertToNumberObjectValue(), u.isError() && (u = y.create(0))), u.isBoolean() && (u = u.convertToNumberObjectValue()), u.isError())
  25254. return t = u, !1;
  25255. t = t.plus(u), r = r.plus(y.create(1));
  25256. }), t.isError())
  25257. return t;
  25258. } else s.isNull() || (t = t.plus(s), r = r.plus(y.create(1)));
  25259. }
  25260. return t.divided(r);
  25261. }
  25262. }
  25263. class $_ extends V {
  25264. constructor() {
  25265. super(...arguments);
  25266. A(this, "minParams", 2);
  25267. A(this, "maxParams", 3);
  25268. A(this, "needsReferenceObject", !0);
  25269. }
  25270. calculate(e, t, r) {
  25271. if (e.isError())
  25272. return e;
  25273. if (t.isError())
  25274. return t;
  25275. if (r != null && r.isError())
  25276. return r;
  25277. let n = e;
  25278. n.isReferenceObject() && (n = n.toArrayValueObject()), n.isArray() || (n = tr([[n]], 1, 1));
  25279. let s = t;
  25280. return s.isReferenceObject() && (s = s.toArrayValueObject()), r && !(r != null && r.isReferenceObject()) ? g.create(m.NA) : (s = s, s.isArray() ? s.map((o) => this._handleSingleObject(n, o, r)) : this._handleSingleObject(n, s, r));
  25281. }
  25282. _handleSingleObject(e, t, r) {
  25283. let n = $n(e, t);
  25284. n = Yn(n, e, t);
  25285. let s = r ? this._createRangeReferenceObject(r, e) : e;
  25286. if (!s)
  25287. return g.create(m.VALUE);
  25288. if (s.isError())
  25289. return s;
  25290. s.isReferenceObject() && (s = s.toArrayValueObject()), s = s;
  25291. const o = s.pick(n), u = o.sum(), c = o.count();
  25292. return u.divided(c);
  25293. }
  25294. /**
  25295. * Create reference object, starting from the first cell in the upper left corner, the height is rowCount and the width is columnCount
  25296. * @param averageRange
  25297. * @param rowCount
  25298. * @param columnCount
  25299. * @returns
  25300. */
  25301. _createRangeReferenceObject(e, t) {
  25302. const r = e.getRowCount(), n = e.getColumnCount(), s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  25303. if (r === s && n === o)
  25304. return e;
  25305. const { startRow: u, startColumn: c } = e.getRangePosition(), l = {
  25306. startRow: u,
  25307. startColumn: c,
  25308. endRow: u + s - 1,
  25309. endColumn: c + o - 1
  25310. };
  25311. return this.createReferenceObject(e, l);
  25312. }
  25313. }
  25314. class Y_ extends V {
  25315. constructor() {
  25316. super(...arguments);
  25317. A(this, "minParams", 3);
  25318. A(this, "maxParams", 255);
  25319. }
  25320. calculate(e, ...t) {
  25321. if (e.isError())
  25322. return g.create(m.NA);
  25323. if (!e.isArray() || t.length % 2 !== 0 || t.some((u, c) => c % 2 === 0 && !u.isArray()))
  25324. return g.create(m.VALUE);
  25325. const { maxRowLength: r, maxColumnLength: n } = Nr(t), s = Br(t, e, r, n);
  25326. if (s)
  25327. return s;
  25328. const o = Ir(t, r, n, !0);
  25329. return this._aggregateResults(e, o);
  25330. }
  25331. _aggregateResults(e, t) {
  25332. const r = t.map((s) => s.map((o) => {
  25333. const u = e.pick(o), c = u.sum(), l = u.count();
  25334. return c.divided(l);
  25335. })), n = {
  25336. calculateValueList: r,
  25337. rowCount: r.length,
  25338. columnCount: r[0].length,
  25339. unitId: this.unitId || "",
  25340. sheetId: this.subUnitId || "",
  25341. row: this.row,
  25342. column: this.column
  25343. };
  25344. return q.create(n);
  25345. }
  25346. }
  25347. class H_ extends V {
  25348. constructor() {
  25349. super(...arguments);
  25350. A(this, "minParams", 4);
  25351. A(this, "maxParams", 6);
  25352. }
  25353. calculate(e, t, r, n, s, o) {
  25354. let u = s != null ? s : y.create(0), c = o != null ? o : y.create(1);
  25355. u.isNull() && (u = y.create(0)), c.isNull() && (c = y.create(1));
  25356. const l = Math.max(
  25357. e.isArray() ? e.getRowCount() : 1,
  25358. t.isArray() ? t.getRowCount() : 1,
  25359. r.isArray() ? r.getRowCount() : 1,
  25360. n.isArray() ? n.getRowCount() : 1,
  25361. u.isArray() ? u.getRowCount() : 1,
  25362. c.isArray() ? c.getRowCount() : 1
  25363. ), f = Math.max(
  25364. e.isArray() ? e.getColumnCount() : 1,
  25365. t.isArray() ? t.getColumnCount() : 1,
  25366. r.isArray() ? r.getColumnCount() : 1,
  25367. n.isArray() ? n.getColumnCount() : 1,
  25368. u.isArray() ? u.getColumnCount() : 1,
  25369. c.isArray() ? c.getColumnCount() : 1
  25370. ), h = O(l, f, e, g.create(m.NA)), d = O(l, f, t, g.create(m.NA)), _ = O(l, f, r, g.create(m.NA)), C = O(l, f, n, g.create(m.NA)), E = O(l, f, u, g.create(m.NA)), b = O(l, f, c, g.create(m.NA)), R = h.mapValue((p, N, M) => {
  25371. const w = d.get(N, M), D = _.get(N, M), S = C.get(N, M), P = E.get(N, M), U = b.get(N, M);
  25372. return this._handleSignleObject(p, w, D, S, P, U);
  25373. });
  25374. return l === 1 && f === 1 ? R.get(0, 0) : R;
  25375. }
  25376. _handleSignleObject(e, t, r, n, s, o) {
  25377. if (e.isError())
  25378. return e;
  25379. if (t.isError())
  25380. return t;
  25381. if (r.isError())
  25382. return r;
  25383. if (n.isError())
  25384. return n;
  25385. if (s.isError())
  25386. return s;
  25387. if (o.isError())
  25388. return o;
  25389. const { isError: u, errorObject: c, variants: l } = I(e, t, r, n, s, o);
  25390. if (u)
  25391. return c;
  25392. const [f, h, d, _, C, E] = l, b = +f.getValue(), R = +h.getValue(), p = +d.getValue(), N = +_.getValue(), M = +C.getValue(), w = +E.getValue();
  25393. if (R <= 0 || p <= 0 || b < M || b > w || M === w)
  25394. return g.create(m.NUM);
  25395. let D;
  25396. return N ? D = Do((b - M) / (w - M), R, p) : D = em((b - M) / (w - M), R, p) / (w - M), y.create(D);
  25397. }
  25398. }
  25399. class G_ extends V {
  25400. constructor() {
  25401. super(...arguments);
  25402. A(this, "minParams", 3);
  25403. A(this, "maxParams", 4);
  25404. }
  25405. calculate(e, t, r, n) {
  25406. let s = n != null ? n : r;
  25407. s.isNull() && (s = r);
  25408. const o = Math.max(
  25409. e.isArray() ? e.getRowCount() : 1,
  25410. t.isArray() ? t.getRowCount() : 1,
  25411. r.isArray() ? r.getRowCount() : 1,
  25412. s.isArray() ? s.getRowCount() : 1
  25413. ), u = Math.max(
  25414. e.isArray() ? e.getColumnCount() : 1,
  25415. t.isArray() ? t.getColumnCount() : 1,
  25416. r.isArray() ? r.getColumnCount() : 1,
  25417. s.isArray() ? s.getColumnCount() : 1
  25418. ), c = O(o, u, e, g.create(m.NA)), l = O(o, u, t, g.create(m.NA)), f = O(o, u, r, g.create(m.NA)), h = O(o, u, s, g.create(m.NA)), d = c.mapValue((_, C, E) => {
  25419. const b = l.get(C, E), R = f.get(C, E), p = h.get(C, E);
  25420. return _.isError() ? _ : b.isError() ? b : R.isError() ? R : p.isError() ? p : this._handleSignleObject(_, b, R, p);
  25421. });
  25422. return o === 1 && u === 1 ? d.get(0, 0) : d;
  25423. }
  25424. _handleSignleObject(e, t, r, n) {
  25425. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  25426. if (s)
  25427. return o;
  25428. const [c, l, f, h] = u, d = Math.floor(+c.getValue()), _ = +l.getValue(), C = Math.floor(+f.getValue()), E = Math.floor(+h.getValue());
  25429. if (d < 0 || _ < 0 || _ > 1 || C < 0 || C > d || E < 0 || E < C || E > d)
  25430. return g.create(m.NUM);
  25431. let b = 0;
  25432. for (let R = C; R <= E; R++)
  25433. b += Da(R, d, _);
  25434. return y.create(b);
  25435. }
  25436. }
  25437. class Q_ extends V {
  25438. constructor() {
  25439. super(...arguments);
  25440. A(this, "minParams", 3);
  25441. A(this, "maxParams", 3);
  25442. }
  25443. calculate(e, t, r) {
  25444. const n = Math.max(
  25445. e.isArray() ? e.getRowCount() : 1,
  25446. t.isArray() ? t.getRowCount() : 1,
  25447. r.isArray() ? r.getRowCount() : 1
  25448. ), s = Math.max(
  25449. e.isArray() ? e.getColumnCount() : 1,
  25450. t.isArray() ? t.getColumnCount() : 1,
  25451. r.isArray() ? r.getColumnCount() : 1
  25452. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  25453. const _ = u.get(h, d), C = c.get(h, d);
  25454. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  25455. });
  25456. return n === 1 && s === 1 ? l.get(0, 0) : l;
  25457. }
  25458. _handleSignleObject(e, t, r) {
  25459. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  25460. if (n)
  25461. return s;
  25462. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = +l.getValue();
  25463. if (f < 0 || h < 1 || h > 10 ** 10)
  25464. return g.create(m.NUM);
  25465. let _;
  25466. return d ? _ = Sa(f, h) : _ = tm(f, h), y.create(_);
  25467. }
  25468. }
  25469. class W_ extends V {
  25470. constructor() {
  25471. super(...arguments);
  25472. A(this, "minParams", 2);
  25473. A(this, "maxParams", 2);
  25474. }
  25475. calculate(e, t) {
  25476. const r = Math.max(
  25477. e.isArray() ? e.getRowCount() : 1,
  25478. t.isArray() ? t.getRowCount() : 1
  25479. ), n = Math.max(
  25480. e.isArray() ? e.getColumnCount() : 1,
  25481. t.isArray() ? t.getColumnCount() : 1
  25482. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  25483. const h = o.get(l, f);
  25484. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  25485. });
  25486. return r === 1 && n === 1 ? u.get(0, 0) : u;
  25487. }
  25488. _handleSignleObject(e, t) {
  25489. const { isError: r, errorObject: n, variants: s } = I(e, t);
  25490. if (r)
  25491. return n;
  25492. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  25493. if (c < 0 || c > 1 || l < 1 || l > 10 ** 10)
  25494. return g.create(m.NUM);
  25495. const f = Po(c, l);
  25496. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  25497. }
  25498. }
  25499. class q_ extends V {
  25500. constructor() {
  25501. super(...arguments);
  25502. A(this, "minParams", 3);
  25503. A(this, "maxParams", 3);
  25504. }
  25505. calculate(e, t, r) {
  25506. const n = Math.max(
  25507. e.isArray() ? e.getRowCount() : 1,
  25508. t.isArray() ? t.getRowCount() : 1,
  25509. r.isArray() ? r.getRowCount() : 1
  25510. ), s = Math.max(
  25511. e.isArray() ? e.getColumnCount() : 1,
  25512. t.isArray() ? t.getColumnCount() : 1,
  25513. r.isArray() ? r.getColumnCount() : 1
  25514. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  25515. const _ = u.get(h, d), C = c.get(h, d);
  25516. if (f.isError())
  25517. return f;
  25518. if (_.isError())
  25519. return _;
  25520. if (C.isError())
  25521. return C;
  25522. const { isError: E, errorObject: b, variants: R } = I(f, _, C);
  25523. if (E)
  25524. return b;
  25525. const [p, N, M] = R, w = +p.getValue(), D = +N.getValue(), S = Math.floor(+M.getValue());
  25526. if (w <= 0 || w >= 1 || D <= 0 || S < 1)
  25527. return g.create(m.NUM);
  25528. if (S === 1)
  25529. return g.create(m.DIV_BY_ZERO);
  25530. const P = Math.abs(qn(w / 2, S - 1) * D / Math.sqrt(S));
  25531. return y.create(P);
  25532. });
  25533. return n === 1 && s === 1 ? l.get(0, 0) : l;
  25534. }
  25535. }
  25536. class K_ extends V {
  25537. constructor() {
  25538. super(...arguments);
  25539. A(this, "minParams", 2);
  25540. A(this, "maxParams", 2);
  25541. }
  25542. calculate(e, t) {
  25543. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  25544. let u = e;
  25545. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  25546. return u;
  25547. let c = t;
  25548. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  25549. return c;
  25550. if (r * n === 1 || s * o === 1)
  25551. return u.isNull() || c.isNull() ? g.create(m.VALUE) : g.create(m.DIV_BY_ZERO);
  25552. if (r * n !== s * o)
  25553. return g.create(m.NA);
  25554. const {
  25555. isError: l,
  25556. errorObject: f,
  25557. array1Values: h,
  25558. array2Values: d,
  25559. noCalculate: _
  25560. } = Je(
  25561. e,
  25562. t,
  25563. r * n,
  25564. n,
  25565. o
  25566. );
  25567. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  25568. }
  25569. _getResult(e, t) {
  25570. const r = e.length;
  25571. let n = 0, s = 0;
  25572. for (let d = 0; d < r; d++)
  25573. n += e[d], s += t[d];
  25574. const o = n / r, u = s / r;
  25575. let c = 0, l = 0, f = 0;
  25576. for (let d = 0; d < r; d++) {
  25577. const _ = e[d] - o, C = t[d] - u;
  25578. c += _ * C, l += _ ** 2, f += C ** 2;
  25579. }
  25580. const h = Math.sqrt(l * f);
  25581. return h === 0 ? g.create(m.DIV_BY_ZERO) : y.create(c / h);
  25582. }
  25583. }
  25584. class X_ extends V {
  25585. constructor() {
  25586. super(...arguments);
  25587. A(this, "minParams", 1);
  25588. A(this, "maxParams", 255);
  25589. }
  25590. calculate(...e) {
  25591. let t = y.create(0);
  25592. for (let r = 0; r < e.length; r++) {
  25593. const n = e[r];
  25594. n.isError() || (n.isArray() ? t = t.plus(n.count()) : n.isString() ? n.convertToNumberObjectValue().isError() || (t = t.plus(y.create(1))) : n.isNull() || (t = t.plus(y.create(1))));
  25595. }
  25596. return t;
  25597. }
  25598. }
  25599. class Z_ extends V {
  25600. constructor() {
  25601. super(...arguments);
  25602. A(this, "minParams", 1);
  25603. A(this, "maxParams", 255);
  25604. }
  25605. calculate(...e) {
  25606. let t = y.create(0);
  25607. for (let r = 0; r < e.length; r++) {
  25608. let n = e[r];
  25609. if (n.isError()) {
  25610. t = t.plus(y.create(1));
  25611. continue;
  25612. }
  25613. n.isArray() ? (n = n.countA(), t = t.plus(n)) : n.isNull() || (t = t.plus(y.create(1)));
  25614. }
  25615. return t;
  25616. }
  25617. }
  25618. class z_ extends V {
  25619. constructor() {
  25620. super(...arguments);
  25621. A(this, "minParams", 1);
  25622. A(this, "maxParams", 1);
  25623. }
  25624. calculate(e) {
  25625. return e.isError() ? e : e.getValue() === "" || e.isNull() ? y.create(1) : e.isArray() ? e.countBlank() : y.create(0);
  25626. }
  25627. }
  25628. class J_ extends V {
  25629. constructor() {
  25630. super(...arguments);
  25631. A(this, "minParams", 2);
  25632. A(this, "maxParams", 2);
  25633. }
  25634. calculate(e, t) {
  25635. return e.isError() || t.isError() ? g.create(m.NA) : e.isArray() ? t.isArray() ? t.mapValue((r) => this._handleSingleObject(e, r)) : this._handleSingleObject(e, t) : g.create(m.VALUE);
  25636. }
  25637. _handleSingleObject(e, t) {
  25638. let r = $n(e, t);
  25639. r = Yn(r, e, t);
  25640. const n = e.pick(r);
  25641. return this._countA(n);
  25642. }
  25643. _countA(e) {
  25644. let t = y.create(0);
  25645. return e.iterator((r) => {
  25646. if (r == null)
  25647. return !0;
  25648. t = t.plusBy(1);
  25649. }), t;
  25650. }
  25651. }
  25652. class eA extends V {
  25653. constructor() {
  25654. super(...arguments);
  25655. A(this, "minParams", 2);
  25656. A(this, "maxParams", 255);
  25657. }
  25658. calculate(...e) {
  25659. if (e.length % 2 !== 0 || e.some((o, u) => u % 2 === 0 && !o.isArray()))
  25660. return g.create(m.VALUE);
  25661. const { maxRowLength: t, maxColumnLength: r } = Nr(e), n = Br(e, e[0], t, r);
  25662. if (n)
  25663. return n;
  25664. const s = Ir(e, t, r, !0);
  25665. return this._aggregateResults(s);
  25666. }
  25667. _aggregateResults(e) {
  25668. const t = e.map((n) => n.map((s) => tA(s))), r = {
  25669. calculateValueList: t,
  25670. rowCount: t.length,
  25671. columnCount: t[0].length,
  25672. unitId: this.unitId || "",
  25673. sheetId: this.subUnitId || "",
  25674. row: this.row,
  25675. column: this.column
  25676. };
  25677. return q.create(r);
  25678. }
  25679. }
  25680. function tA(i) {
  25681. let a = 0;
  25682. return i.iterator((e) => {
  25683. e != null && e.isBoolean() && e.getValue() === !0 && a++;
  25684. }), y.create(a);
  25685. }
  25686. class rA extends V {
  25687. constructor() {
  25688. super(...arguments);
  25689. A(this, "minParams", 2);
  25690. A(this, "maxParams", 2);
  25691. }
  25692. calculate(e, t) {
  25693. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  25694. let u = e;
  25695. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  25696. return u;
  25697. let c = t;
  25698. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  25699. return c;
  25700. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  25701. return g.create(m.VALUE);
  25702. if (r * n !== s * o)
  25703. return g.create(m.NA);
  25704. const {
  25705. isError: l,
  25706. errorObject: f,
  25707. array1Values: h,
  25708. array2Values: d,
  25709. noCalculate: _
  25710. } = Je(
  25711. e,
  25712. t,
  25713. r * n,
  25714. n,
  25715. o
  25716. );
  25717. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  25718. }
  25719. _getResult(e, t) {
  25720. if (e.length <= 1)
  25721. return g.create(m.DIV_BY_ZERO);
  25722. const r = e.length;
  25723. let n = 0, s = 0;
  25724. for (let l = 0; l < r; l++)
  25725. n += e[l], s += t[l];
  25726. const o = n / r, u = s / r;
  25727. let c = 0;
  25728. for (let l = 0; l < r; l++) {
  25729. const f = e[l] - o, h = t[l] - u;
  25730. c += f * h;
  25731. }
  25732. return y.create(c / (r - 1));
  25733. }
  25734. }
  25735. class nA extends V {
  25736. constructor() {
  25737. super(...arguments);
  25738. A(this, "minParams", 1);
  25739. A(this, "maxParams", 255);
  25740. }
  25741. calculate(...e) {
  25742. const t = [];
  25743. let r = 0, n = !0;
  25744. for (let u = 0; u < e.length; u++) {
  25745. const c = e[u];
  25746. if (c.isArray()) {
  25747. let l = !1, f = g.create(m.VALUE);
  25748. if (c.iterator((h) => {
  25749. const d = this._handleSingleObject(h);
  25750. if (d.isError())
  25751. return l = !0, f = d, !1;
  25752. if (d.isNull())
  25753. return !0;
  25754. const _ = d.getValue();
  25755. t.push(_), r += _, n = !1;
  25756. }), l)
  25757. return f;
  25758. } else {
  25759. const l = this._handleSingleObject(c);
  25760. if (l.isError())
  25761. return l;
  25762. if (l.isNull())
  25763. continue;
  25764. const f = l.getValue();
  25765. t.push(f), r += f, n = !1;
  25766. }
  25767. }
  25768. if (n)
  25769. return g.create(m.NUM);
  25770. const s = r / t.length;
  25771. let o = 0;
  25772. for (let u = 0; u < t.length; u++)
  25773. o += (t[u] - s) ** 2;
  25774. return y.create(o);
  25775. }
  25776. _handleSingleObject(e) {
  25777. if (e.isError())
  25778. return e;
  25779. if (e.isNull() || e.isBoolean())
  25780. return ie.create();
  25781. const t = e.getValue();
  25782. return Q(t) ? y.create(+t) : ie.create();
  25783. }
  25784. }
  25785. class sA extends V {
  25786. constructor() {
  25787. super(...arguments);
  25788. A(this, "minParams", 4);
  25789. A(this, "maxParams", 4);
  25790. }
  25791. calculate(e, t, r, n) {
  25792. const s = Math.max(
  25793. e.isArray() ? e.getRowCount() : 1,
  25794. t.isArray() ? t.getRowCount() : 1,
  25795. r.isArray() ? r.getRowCount() : 1,
  25796. n.isArray() ? n.getRowCount() : 1
  25797. ), o = Math.max(
  25798. e.isArray() ? e.getColumnCount() : 1,
  25799. t.isArray() ? t.getColumnCount() : 1,
  25800. r.isArray() ? r.getColumnCount() : 1,
  25801. n.isArray() ? n.getColumnCount() : 1
  25802. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  25803. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  25804. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  25805. });
  25806. return s === 1 && o === 1 ? h.get(0, 0) : h;
  25807. }
  25808. _handleSignleObject(e, t, r, n) {
  25809. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  25810. if (s)
  25811. return o;
  25812. const [c, l, f, h] = u, d = +c.getValue(), _ = Math.floor(+l.getValue()), C = Math.floor(+f.getValue()), E = +h.getValue();
  25813. if (d < 0 || _ < 1 || _ > 10 ** 10 || C < 1 || C > 10 ** 10)
  25814. return g.create(m.NUM);
  25815. let b;
  25816. return E ? b = Pa(d, _, C) : b = rm(d, _, C), Number.isNaN(b) || !Number.isFinite(b) ? g.create(m.NUM) : y.create(b);
  25817. }
  25818. }
  25819. class aA extends V {
  25820. constructor() {
  25821. super(...arguments);
  25822. A(this, "minParams", 3);
  25823. A(this, "maxParams", 3);
  25824. }
  25825. calculate(e, t, r) {
  25826. const n = Math.max(
  25827. e.isArray() ? e.getRowCount() : 1,
  25828. t.isArray() ? t.getRowCount() : 1,
  25829. r.isArray() ? r.getRowCount() : 1
  25830. ), s = Math.max(
  25831. e.isArray() ? e.getColumnCount() : 1,
  25832. t.isArray() ? t.getColumnCount() : 1,
  25833. r.isArray() ? r.getColumnCount() : 1
  25834. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  25835. const _ = u.get(h, d), C = c.get(h, d);
  25836. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  25837. });
  25838. return n === 1 && s === 1 ? l.get(0, 0) : l;
  25839. }
  25840. _handleSignleObject(e, t, r) {
  25841. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  25842. if (n)
  25843. return s;
  25844. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = Math.floor(+l.getValue());
  25845. if (f < 0 || f > 1 || h < 1 || h > 10 ** 10 || d < 1 || d > 10 ** 10)
  25846. return g.create(m.NUM);
  25847. const _ = Lo(f, h, d);
  25848. return Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  25849. }
  25850. }
  25851. class iA extends V {
  25852. constructor() {
  25853. super(...arguments);
  25854. A(this, "minParams", 1);
  25855. A(this, "maxParams", 1);
  25856. }
  25857. calculate(e) {
  25858. return e.isArray() ? e.mapValue((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  25859. }
  25860. _handleSingleObject(e) {
  25861. const { isError: t, errorObject: r, variants: n } = I(e);
  25862. if (t)
  25863. return r;
  25864. const [s] = n, o = s.getValue();
  25865. if (o <= -1 || o >= 1)
  25866. return g.create(m.NUM);
  25867. const u = Math.log((1 + o) / (1 - o)) / 2;
  25868. return y.create(u);
  25869. }
  25870. }
  25871. class oA extends V {
  25872. constructor() {
  25873. super(...arguments);
  25874. A(this, "minParams", 1);
  25875. A(this, "maxParams", 1);
  25876. }
  25877. calculate(e) {
  25878. return e.isArray() ? e.mapValue((t) => this._handleSingleObject(t)) : this._handleSingleObject(e);
  25879. }
  25880. _handleSingleObject(e) {
  25881. const { isError: t, errorObject: r, variants: n } = I(e);
  25882. if (t)
  25883. return r;
  25884. const [s] = n, o = +s.getValue(), u = Math.exp(2 * o) - 1, c = Math.exp(2 * o) + 1;
  25885. return !Number.isFinite(u) && u > 0 && !Number.isFinite(c) && c > 0 ? y.create(1) : y.create(u / c);
  25886. }
  25887. }
  25888. class Li extends V {
  25889. constructor() {
  25890. super(...arguments);
  25891. A(this, "minParams", 3);
  25892. A(this, "maxParams", 3);
  25893. }
  25894. calculate(e, t, r) {
  25895. const n = t.isArray() ? t.getRowCount() : 1, s = t.isArray() ? t.getColumnCount() : 1, o = r.isArray() ? r.getRowCount() : 1, u = r.isArray() ? r.getColumnCount() : 1;
  25896. let c = t;
  25897. t.isArray() && n === 1 && s === 1 && (c = t.get(0, 0));
  25898. let l = r;
  25899. return r.isArray() && o === 1 && u === 1 && (l = r.get(0, 0)), e.isArray() ? e.mapValue(
  25900. (f) => this._handleSignleObject(f, c, l, n, s, o, u)
  25901. ) : this._handleSignleObject(e, c, l, n, s, o, u);
  25902. }
  25903. _handleSignleObject(e, t, r, n, s, o, u) {
  25904. if (e.isError())
  25905. return e;
  25906. if (t.isError())
  25907. return t;
  25908. if (r.isError())
  25909. return r;
  25910. let c = e;
  25911. if (e.isString() && (c = e.convertToNumberObjectValue()), c.isError())
  25912. return c;
  25913. const l = +c.getValue();
  25914. if ((n * s === 1 || o * u === 1) && (t.isNull() || r.isNull()))
  25915. return g.create(m.VALUE);
  25916. if (n * s !== o * u)
  25917. return g.create(m.NA);
  25918. const {
  25919. isError: f,
  25920. errorObject: h,
  25921. array1Values: d,
  25922. array2Values: _,
  25923. noCalculate: C
  25924. } = Je(
  25925. t,
  25926. r,
  25927. n * s,
  25928. s,
  25929. u
  25930. );
  25931. if (f)
  25932. return h;
  25933. if (C)
  25934. return g.create(m.DIV_BY_ZERO);
  25935. const E = xo(l, d, _);
  25936. return Number.isFinite(E) ? y.create(E) : g.create(m.DIV_BY_ZERO);
  25937. }
  25938. }
  25939. class uA extends V {
  25940. constructor() {
  25941. super(...arguments);
  25942. A(this, "minParams", 2);
  25943. A(this, "maxParams", 2);
  25944. }
  25945. calculate(e, t) {
  25946. const { isError: r, errorObject: n, values: s } = this._getValues(e);
  25947. if (r)
  25948. return n;
  25949. if (e.isNull() || t.isNull())
  25950. return g.create(m.VALUE);
  25951. let { values: o } = this._getValues(t, !0);
  25952. o.length === 0 && (o = [0]);
  25953. const u = this._getNewBinsArrayValues(o), c = new Array(u.length).fill(0);
  25954. for (let l = 0; l < s.length; l++) {
  25955. const f = s[l], h = u.findIndex((d) => f > d.start && f <= d.end);
  25956. c[h]++;
  25957. }
  25958. return q.createByArray(c.map((l) => [l]));
  25959. }
  25960. _getValues(e, t = !1) {
  25961. const r = [], n = e.isArray() ? e.getRowCount() : 1, s = e.isArray() ? e.getColumnCount() : 1;
  25962. for (let o = 0; o < n; o++)
  25963. for (let u = 0; u < s; u++) {
  25964. const c = e.isArray() ? e.get(o, u) : e;
  25965. if (c.isError()) {
  25966. if (!t)
  25967. return {
  25968. isError: !0,
  25969. errorObject: c,
  25970. values: r
  25971. };
  25972. continue;
  25973. }
  25974. if (c.isNull() || c.isBoolean())
  25975. continue;
  25976. const l = c.getValue();
  25977. Q(l) && r.push(+l);
  25978. }
  25979. return {
  25980. isError: !1,
  25981. errorObject: null,
  25982. values: r
  25983. };
  25984. }
  25985. _getNewBinsArrayValues(e) {
  25986. const t = e.map((n, s) => ({
  25987. value: n,
  25988. index: s
  25989. })).sort((n, s) => n.value - s.value), r = [];
  25990. for (let n = 0; n < t.length; n++) {
  25991. const s = t[n].index;
  25992. if (n === 0) {
  25993. r[s] = {
  25994. start: -1 / 0,
  25995. end: t[n].value
  25996. };
  25997. continue;
  25998. }
  25999. r[s] = {
  26000. start: t[n - 1].value,
  26001. end: t[n].value
  26002. };
  26003. }
  26004. return r.push({
  26005. start: t[t.length - 1].value,
  26006. end: 1 / 0
  26007. }), r;
  26008. }
  26009. }
  26010. var v = /* @__PURE__ */ ((i) => (i.AVEDEV = "AVEDEV", i.AVERAGE = "AVERAGE", i.AVERAGE_WEIGHTED = "AVERAGE.WEIGHTED", i.AVERAGEA = "AVERAGEA", i.AVERAGEIF = "AVERAGEIF", i.AVERAGEIFS = "AVERAGEIFS", i.BETA_DIST = "BETA.DIST", i.BETA_INV = "BETA.INV", i.BINOM_DIST = "BINOM.DIST", i.BINOM_DIST_RANGE = "BINOM.DIST.RANGE", i.BINOM_INV = "BINOM.INV", i.CHISQ_DIST = "CHISQ.DIST", i.CHISQ_DIST_RT = "CHISQ.DIST.RT", i.CHISQ_INV = "CHISQ.INV", i.CHISQ_INV_RT = "CHISQ.INV.RT", i.CHISQ_TEST = "CHISQ.TEST", i.CONFIDENCE_NORM = "CONFIDENCE.NORM", i.CONFIDENCE_T = "CONFIDENCE.T", i.CORREL = "CORREL", i.COUNT = "COUNT", i.COUNTA = "COUNTA", i.COUNTBLANK = "COUNTBLANK", i.COUNTIF = "COUNTIF", i.COUNTIFS = "COUNTIFS", i.COVARIANCE_P = "COVARIANCE.P", i.COVARIANCE_S = "COVARIANCE.S", i.DEVSQ = "DEVSQ", i.EXPON_DIST = "EXPON.DIST", i.F_DIST = "F.DIST", i.F_DIST_RT = "F.DIST.RT", i.F_INV = "F.INV", i.F_INV_RT = "F.INV.RT", i.F_TEST = "F.TEST", i.FISHER = "FISHER", i.FISHERINV = "FISHERINV", i.FORECAST = "FORECAST", i.FORECAST_ETS = "FORECAST.ETS", i.FORECAST_ETS_CONFINT = "FORECAST.ETS.CONFINT", i.FORECAST_ETS_SEASONALITY = "FORECAST.ETS.SEASONALITY", i.FORECAST_ETS_STAT = "FORECAST.ETS.STAT", i.FORECAST_LINEAR = "FORECAST.LINEAR", i.FREQUENCY = "FREQUENCY", i.GAMMA = "GAMMA", i.GAMMA_DIST = "GAMMA.DIST", i.GAMMA_INV = "GAMMA.INV", i.GAMMALN = "GAMMALN", i.GAMMALN_PRECISE = "GAMMALN.PRECISE", i.GAUSS = "GAUSS", i.GEOMEAN = "GEOMEAN", i.GROWTH = "GROWTH", i.HARMEAN = "HARMEAN", i.HYPGEOM_DIST = "HYPGEOM.DIST", i.INTERCEPT = "INTERCEPT", i.KURT = "KURT", i.LARGE = "LARGE", i.LINEST = "LINEST", i.LOGEST = "LOGEST", i.LOGNORM_DIST = "LOGNORM.DIST", i.LOGNORM_INV = "LOGNORM.INV", i.MARGINOFERROR = "MARGINOFERROR", i.MAX = "MAX", i.MAXA = "MAXA", i.MAXIFS = "MAXIFS", i.MEDIAN = "MEDIAN", i.MIN = "MIN", i.MINA = "MINA", i.MINIFS = "MINIFS", i.MODE_MULT = "MODE.MULT", i.MODE_SNGL = "MODE.SNGL", i.NEGBINOM_DIST = "NEGBINOM.DIST", i.NORM_DIST = "NORM.DIST", i.NORM_INV = "NORM.INV", i.NORM_S_DIST = "NORM.S.DIST", i.NORM_S_INV = "NORM.S.INV", i.PEARSON = "PEARSON", i.PERCENTILE_EXC = "PERCENTILE.EXC", i.PERCENTILE_INC = "PERCENTILE.INC", i.PERCENTRANK_EXC = "PERCENTRANK.EXC", i.PERCENTRANK_INC = "PERCENTRANK.INC", i.PERMUT = "PERMUT", i.PERMUTATIONA = "PERMUTATIONA", i.PHI = "PHI", i.POISSON_DIST = "POISSON.DIST", i.PROB = "PROB", i.QUARTILE_EXC = "QUARTILE.EXC", i.QUARTILE_INC = "QUARTILE.INC", i.RANK_AVG = "RANK.AVG", i.RANK_EQ = "RANK.EQ", i.RSQ = "RSQ", i.SKEW = "SKEW", i.SKEW_P = "SKEW.P", i.SLOPE = "SLOPE", i.SMALL = "SMALL", i.STANDARDIZE = "STANDARDIZE", i.STDEV_P = "STDEV.P", i.STDEV_S = "STDEV.S", i.STDEVA = "STDEVA", i.STDEVPA = "STDEVPA", i.STEYX = "STEYX", i.T_DIST = "T.DIST", i.T_DIST_2T = "T.DIST.2T", i.T_DIST_RT = "T.DIST.RT", i.T_INV = "T.INV", i.T_INV_2T = "T.INV.2T", i.T_TEST = "T.TEST", i.TREND = "TREND", i.TRIMMEAN = "TRIMMEAN", i.VAR_P = "VAR.P", i.VAR_S = "VAR.S", i.VARA = "VARA", i.VARPA = "VARPA", i.WEIBULL_DIST = "WEIBULL.DIST", i.Z_TEST = "Z.TEST", i))(v || {});
  26011. class cA extends V {
  26012. constructor() {
  26013. super(...arguments);
  26014. A(this, "minParams", 1);
  26015. A(this, "maxParams", 1);
  26016. }
  26017. calculate(e) {
  26018. if (e.isArray()) {
  26019. const t = e.mapValue((r) => this._handleSingleObject(r));
  26020. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  26021. }
  26022. return this._handleSingleObject(e);
  26023. }
  26024. _handleSingleObject(e) {
  26025. const { isError: t, errorObject: r, variants: n } = I(e);
  26026. if (t)
  26027. return r;
  26028. const [s] = n, o = +s.getValue();
  26029. if (o === 0 || o < 0 && o % 1 === 0)
  26030. return g.create(m.NUM);
  26031. const u = on(o);
  26032. return Number.isNaN(u) || !Number.isFinite(u) ? g.create(m.NUM) : y.create(u);
  26033. }
  26034. }
  26035. class xi extends V {
  26036. constructor() {
  26037. super(...arguments);
  26038. A(this, "minParams", 1);
  26039. A(this, "maxParams", 1);
  26040. }
  26041. calculate(e) {
  26042. if (e.isArray()) {
  26043. const t = e.mapValue((r) => this._handleSingleObject(r));
  26044. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  26045. }
  26046. return this._handleSingleObject(e);
  26047. }
  26048. _handleSingleObject(e) {
  26049. const { isError: t, errorObject: r, variants: n } = I(e);
  26050. if (t)
  26051. return r;
  26052. const [s] = n, o = +s.getValue();
  26053. if (o <= 0)
  26054. return g.create(m.NUM);
  26055. const u = ct(o);
  26056. return Math.abs(u) < 1e-15 ? y.create(0) : y.create(u);
  26057. }
  26058. }
  26059. class lA extends V {
  26060. constructor() {
  26061. super(...arguments);
  26062. A(this, "minParams", 1);
  26063. A(this, "maxParams", 1);
  26064. }
  26065. calculate(e) {
  26066. if (e.isArray()) {
  26067. const t = e.mapValue((r) => this._handleSingleObject(r));
  26068. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  26069. }
  26070. return this._handleSingleObject(e);
  26071. }
  26072. _handleSingleObject(e) {
  26073. const { isError: t, errorObject: r, variants: n } = I(e);
  26074. if (t)
  26075. return r;
  26076. const [s] = n, o = +s.getValue(), u = kr(o, 0, 1) - 0.5;
  26077. return y.create(u);
  26078. }
  26079. }
  26080. class fA extends V {
  26081. constructor() {
  26082. super(...arguments);
  26083. A(this, "minParams", 1);
  26084. A(this, "maxParams", 255);
  26085. }
  26086. calculate(...e) {
  26087. let t = 1, r = 0, n = !1;
  26088. for (let o = 0; o < e.length; o++) {
  26089. const u = e[o];
  26090. if (u.isArray()) {
  26091. let c = !1, l = g.create(m.VALUE);
  26092. if (u.iterator((f) => {
  26093. if (f != null && f.isError())
  26094. return c = !0, l = f, !1;
  26095. if (f != null && f.isNull() || f != null && f.isBoolean())
  26096. return !0;
  26097. const h = f.getValue();
  26098. if (!Q(h))
  26099. return !0;
  26100. +h <= 0 && (n = !0), t *= +h, r++;
  26101. }), c)
  26102. return l;
  26103. } else {
  26104. if (u.isError())
  26105. return u;
  26106. if (u.isString()) {
  26107. const l = u.convertToNumberObjectValue();
  26108. if (l.isError())
  26109. return l;
  26110. }
  26111. if (u.isNull() || u.isBoolean())
  26112. continue;
  26113. const c = u.getValue();
  26114. if (!Q(c))
  26115. continue;
  26116. +c <= 0 && (n = !0), t *= +c, r++;
  26117. }
  26118. }
  26119. if (r === 0 || n)
  26120. return g.create(m.NUM);
  26121. const s = t ** (1 / r);
  26122. return y.create(s);
  26123. }
  26124. }
  26125. class hA extends V {
  26126. constructor() {
  26127. super(...arguments);
  26128. A(this, "minParams", 1);
  26129. A(this, "maxParams", 4);
  26130. }
  26131. calculate(e, t, r, n) {
  26132. const { isError: s, errorObject: o } = Kn(e, t, r);
  26133. if (s)
  26134. return o;
  26135. const u = dt(e);
  26136. if (u instanceof g)
  26137. return u;
  26138. const c = this._getKnownXsValues(u, t);
  26139. if (c instanceof g)
  26140. return c;
  26141. const l = this._getNewXsValues(c, r);
  26142. if (l instanceof g)
  26143. return l;
  26144. let f = n != null ? n : T.create(!0);
  26145. if (f.isArray() && (f = f.get(0, 0)), f.isString() && (f = f.convertToNumberObjectValue()), f.isError())
  26146. return f;
  26147. const h = +f.getValue();
  26148. return this._getResult(u, c, l, h);
  26149. }
  26150. _getResult(e, t, r, n) {
  26151. return e.length === 1 && t.length > 1 || e[0].length === 1 && t[0].length > 1 ? e.length === 1 && t.length > 1 && (n ? t.length + 1 : t.length) > e[0].length || e[0].length === 1 && t[0].length > 1 && (n ? t[0].length + 1 : t[0].length) > e.length ? g.create(m.NA) : this._getResultByMultipleVariables(e, t, r, n) : this._getResultBySimpleVariables(e, t, r, n);
  26152. }
  26153. _getResultByMultipleVariables(e, t, r, n) {
  26154. const s = e.length === 1 && e[0].length > 1, o = zn(e, t, r, n, !0);
  26155. if (o instanceof g)
  26156. return o;
  26157. const { coefficients: u, newX: c } = o, l = u[0].length, f = u[0][l - 1];
  26158. let h = [];
  26159. for (let d = 0; d < c.length; d++) {
  26160. h[d] = [];
  26161. let _ = f;
  26162. for (let C = l - 2; C >= 0; C--)
  26163. _ *= u[0][l - 2 - C] ** c[d][C];
  26164. h[d].push(_);
  26165. }
  26166. return s && (h = mt(h)), q.createByArray(h);
  26167. }
  26168. _getResultBySimpleVariables(e, t, r, n) {
  26169. const s = e.flat(), o = t.flat(), { slope: u, intercept: c } = Zn(o, s, n, !0), l = r.map((f) => f.map((h) => c * u ** h));
  26170. return q.createByArray(l);
  26171. }
  26172. _getKnownXsValues(e, t) {
  26173. return !t || t.isNull() ? Xn(e.length, e[0].length) : dt(t);
  26174. }
  26175. _getNewXsValues(e, t) {
  26176. return !t || t.isNull() ? e : dt(t);
  26177. }
  26178. }
  26179. class mA extends V {
  26180. constructor() {
  26181. super(...arguments);
  26182. A(this, "minParams", 1);
  26183. A(this, "maxParams", 255);
  26184. }
  26185. calculate(...e) {
  26186. let t = 0, r = 0, n = !1;
  26187. for (let o = 0; o < e.length; o++) {
  26188. const u = e[o];
  26189. if (u.isArray()) {
  26190. let c = !1, l = g.create(m.VALUE);
  26191. if (u.iterator((f) => {
  26192. if (f != null && f.isError())
  26193. return c = !0, l = f, !1;
  26194. if (f != null && f.isNull() || f != null && f.isBoolean())
  26195. return !0;
  26196. const h = f.getValue();
  26197. if (!Q(h))
  26198. return !0;
  26199. +h <= 0 && (n = !0), t += 1 / +h, r++;
  26200. }), c)
  26201. return l;
  26202. } else {
  26203. if (u.isError())
  26204. return u;
  26205. if (u.isString()) {
  26206. const l = u.convertToNumberObjectValue();
  26207. if (l.isError())
  26208. return l;
  26209. }
  26210. if (u.isNull() || u.isBoolean())
  26211. continue;
  26212. const c = u.getValue();
  26213. if (!Q(c))
  26214. continue;
  26215. +c <= 0 && (n = !0), t += 1 / +c, r++;
  26216. }
  26217. }
  26218. if (r === 0)
  26219. return g.create(m.NA);
  26220. if (n)
  26221. return g.create(m.NUM);
  26222. const s = r / t;
  26223. return y.create(s);
  26224. }
  26225. }
  26226. class gA extends V {
  26227. constructor() {
  26228. super(...arguments);
  26229. A(this, "minParams", 5);
  26230. A(this, "maxParams", 5);
  26231. }
  26232. calculate(e, t, r, n, s) {
  26233. const o = Math.max(
  26234. e.isArray() ? e.getRowCount() : 1,
  26235. t.isArray() ? t.getRowCount() : 1,
  26236. r.isArray() ? r.getRowCount() : 1,
  26237. n.isArray() ? n.getRowCount() : 1,
  26238. s.isArray() ? s.getRowCount() : 1
  26239. ), u = Math.max(
  26240. e.isArray() ? e.getColumnCount() : 1,
  26241. t.isArray() ? t.getColumnCount() : 1,
  26242. r.isArray() ? r.getColumnCount() : 1,
  26243. n.isArray() ? n.getColumnCount() : 1,
  26244. s.isArray() ? s.getColumnCount() : 1
  26245. ), c = O(o, u, e, g.create(m.NA)), l = O(o, u, t, g.create(m.NA)), f = O(o, u, r, g.create(m.NA)), h = O(o, u, n, g.create(m.NA)), d = O(o, u, s, g.create(m.NA)), _ = c.mapValue((C, E, b) => {
  26246. const R = l.get(E, b), p = f.get(E, b), N = h.get(E, b), M = d.get(E, b);
  26247. return C.isError() ? C : R.isError() ? R : p.isError() ? p : N.isError() ? N : M.isError() ? M : this._handleSignleObject(C, R, p, N, M);
  26248. });
  26249. return o === 1 && u === 1 ? _.get(0, 0) : _;
  26250. }
  26251. _handleSignleObject(e, t, r, n, s) {
  26252. const { isError: o, errorObject: u, variants: c } = I(e, t, r, n, s);
  26253. if (o)
  26254. return u;
  26255. const [l, f, h, d, _] = c, C = Math.floor(+l.getValue()), E = Math.floor(+f.getValue()), b = Math.floor(+h.getValue()), R = Math.floor(+d.getValue()), p = +_.getValue();
  26256. if (C < 0 || C > E || C > b || C < E - R + b || E <= 0 || E > R || b <= 0 || b > R || R <= 0)
  26257. return g.create(m.NUM);
  26258. let N;
  26259. return p ? N = um(C, E, b, R) : N = xa(C, E, b, R), Number.isNaN(N) && (N = 0), y.create(N);
  26260. }
  26261. }
  26262. class dA extends V {
  26263. constructor() {
  26264. super(...arguments);
  26265. A(this, "minParams", 2);
  26266. A(this, "maxParams", 2);
  26267. }
  26268. calculate(e, t) {
  26269. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  26270. let u = e;
  26271. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  26272. return u;
  26273. let c = t;
  26274. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  26275. return c;
  26276. if (r * n === 1 || s * o === 1)
  26277. return u.isNull() || c.isNull() ? g.create(m.VALUE) : g.create(m.DIV_BY_ZERO);
  26278. if (r * n !== s * o)
  26279. return g.create(m.NA);
  26280. const {
  26281. isError: l,
  26282. errorObject: f,
  26283. array1Values: h,
  26284. array2Values: d,
  26285. noCalculate: _
  26286. } = Je(
  26287. e,
  26288. t,
  26289. r * n,
  26290. n,
  26291. o
  26292. );
  26293. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  26294. }
  26295. _getResult(e, t) {
  26296. const r = xo(0, e, t);
  26297. return Number.isFinite(r) ? y.create(r) : g.create(m.DIV_BY_ZERO);
  26298. }
  26299. }
  26300. class CA extends V {
  26301. constructor() {
  26302. super(...arguments);
  26303. A(this, "minParams", 1);
  26304. A(this, "maxParams", 255);
  26305. }
  26306. calculate(...e) {
  26307. const t = [];
  26308. let r = 0;
  26309. for (let n = 0; n < e.length; n++) {
  26310. const s = e[n];
  26311. if (s.isError())
  26312. return s;
  26313. if (s.isString()) {
  26314. const c = s.convertToNumberObjectValue();
  26315. if (c.isError())
  26316. return c;
  26317. }
  26318. const o = s.isArray() ? s.getRowCount() : 1, u = s.isArray() ? s.getColumnCount() : 1;
  26319. for (let c = 0; c < o; c++)
  26320. for (let l = 0; l < u; l++) {
  26321. const f = s.isArray() ? s.get(c, l) : s;
  26322. if (f.isError())
  26323. return f;
  26324. if (f.isNull() || f.isBoolean())
  26325. continue;
  26326. const h = f.getValue();
  26327. Q(h) && (t.push(+h), r += +h);
  26328. }
  26329. }
  26330. return t.length <= 3 ? g.create(m.DIV_BY_ZERO) : this._getResult(t, r);
  26331. }
  26332. _getResult(e, t) {
  26333. const r = e.length, n = t / r;
  26334. let s = 0;
  26335. for (let l = 0; l < r; l++)
  26336. s += (e[l] - n) ** 2;
  26337. const o = Math.sqrt(s / (r - 1));
  26338. if (o === 0)
  26339. return g.create(m.DIV_BY_ZERO);
  26340. let u = 0;
  26341. for (let l = 0; l < r; l++)
  26342. u += ((e[l] - n) / o) ** 4;
  26343. const c = r * (r + 1) / ((r - 1) * (r - 2) * (r - 3)) * u - 3 * (r - 1) ** 2 / ((r - 2) * (r - 3));
  26344. return y.create(c);
  26345. }
  26346. }
  26347. class _A extends V {
  26348. constructor() {
  26349. super(...arguments);
  26350. A(this, "minParams", 2);
  26351. A(this, "maxParams", 2);
  26352. }
  26353. calculate(e, t) {
  26354. const r = this._getValues(e);
  26355. if (t.isArray()) {
  26356. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  26357. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  26358. }
  26359. return this._handleSingleObject(r, t);
  26360. }
  26361. _handleSingleObject(e, t) {
  26362. if (e instanceof g)
  26363. return e;
  26364. const { isError: r, errorObject: n, variants: s } = I(t);
  26365. if (r)
  26366. return n;
  26367. const [o] = s;
  26368. let u = +o.getValue();
  26369. return u < 1 || u > e.length ? g.create(m.NUM) : (u = Math.ceil(u), y.create(e[u - 1]));
  26370. }
  26371. _getValues(e) {
  26372. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  26373. for (let s = 0; s < t; s++)
  26374. for (let o = 0; o < r; o++) {
  26375. const u = e.isArray() ? e.get(s, o) : e;
  26376. if (u.isError())
  26377. return u;
  26378. if (u.isNull() || u.isBoolean() || u.isString())
  26379. continue;
  26380. const c = u.getValue();
  26381. Q(c) && n.push(+c);
  26382. }
  26383. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => o - s);
  26384. }
  26385. }
  26386. class AA extends V {
  26387. constructor() {
  26388. super(...arguments);
  26389. A(this, "minParams", 1);
  26390. A(this, "maxParams", 4);
  26391. }
  26392. calculate(e, t, r, n) {
  26393. const { isError: s, errorObject: o } = Kn(e, t);
  26394. if (s)
  26395. return o;
  26396. const u = dt(e);
  26397. if (u instanceof g)
  26398. return u;
  26399. const c = this._getKnownXsValues(u, t);
  26400. if (c instanceof g)
  26401. return c;
  26402. let l = r != null ? r : T.create(!0);
  26403. l.isArray() && (l = l.get(0, 0));
  26404. let f = n != null ? n : T.create(!1);
  26405. f.isArray() && (f = f.get(0, 0));
  26406. const { isError: h, errorObject: d, variants: _ } = I(l, f);
  26407. if (h)
  26408. return d;
  26409. const [C, E] = _;
  26410. return this._getResult(u, c, +C.getValue(), +E.getValue());
  26411. }
  26412. _getResult(e, t, r, n) {
  26413. return e.length === 1 && t.length > 1 || e[0].length === 1 && t[0].length > 1 ? e.length === 1 && t.length > 1 && (r ? t.length + 1 : t.length) > e[0].length || e[0].length === 1 && t[0].length > 1 && (r ? t[0].length + 1 : t[0].length) > e.length ? g.create(m.NA) : this._getResultByMultipleVariables(e, t, r, n) : this._getResultBySimpleVariables(e, t, r, n);
  26414. }
  26415. _getResultByMultipleVariables(e, t, r, n) {
  26416. const s = zn(e, t, t, r, !1);
  26417. if (s instanceof g)
  26418. return s;
  26419. const { coefficients: o, X: u, XTXInverse: c } = s;
  26420. let l = [];
  26421. if (n) {
  26422. const f = e.flat(), h = f.length, d = r ? f.reduce((x, F) => x + F, 0) / h : 0, _ = c.length, C = h - _, E = o[0].length, b = new Array(E - 2).fill(m.NA), R = o[0][E - 1], p = [];
  26423. for (let x = 0; x < u.length; x++) {
  26424. let F = R;
  26425. for (let W = E - 2; W >= 0; W--)
  26426. F += o[0][E - 2 - W] * u[x][W];
  26427. p.push(F);
  26428. }
  26429. let N = 0, M = 0;
  26430. for (let x = 0; x < h; x++)
  26431. N += (f[x] - d) ** 2, M += (f[x] - p[x]) ** 2;
  26432. const w = N - M, D = N === 0 ? 0 : w / N, S = [];
  26433. for (let x = _ - 1; x >= 0; x--) {
  26434. const F = C > 0 ? Math.sqrt(M / C * c[x][x]) : 0;
  26435. S.push(F);
  26436. }
  26437. if (r) {
  26438. const x = S.shift();
  26439. S.push(x);
  26440. } else
  26441. S.push(m.NA);
  26442. const P = C > 0 ? Math.sqrt(M / C) : 0, U = C > 0 ? w / (E - 1) / (M / C) : m.NUM;
  26443. l = [
  26444. o[0],
  26445. // [mn, mn-1, ..., m1, b]
  26446. [...S],
  26447. // [sen, sen-1, ..., se1, seb]
  26448. [D, P, ...b],
  26449. // [r2, sey]
  26450. [U, C, ...b],
  26451. // [F, df]
  26452. [w, M, ...b]
  26453. // [ssreg, ssresid]
  26454. ];
  26455. } else
  26456. l = [
  26457. o[0]
  26458. // [mn, mn-1, ..., m1, b]
  26459. ];
  26460. return q.createByArray(l);
  26461. }
  26462. _getResultBySimpleVariables(e, t, r, n) {
  26463. const s = e.flat(), o = t.flat(), { slope: u, intercept: c } = Zn(o, s, r, !1);
  26464. if (Number.isNaN(u))
  26465. return g.create(m.NA);
  26466. let l = [];
  26467. if (n) {
  26468. const f = s.length;
  26469. let h = 0, d = 0, _ = f - 1;
  26470. if (r) {
  26471. let S = 0, P = 0;
  26472. for (let U = 0; U < f; U++)
  26473. S += s[U], P += o[U];
  26474. h = S / f, d = P / f, _ = f - 2;
  26475. }
  26476. let C = 0, E = 0, b = 0;
  26477. for (let S = 0; S < f; S++)
  26478. C += (s[S] - h) ** 2, E += (s[S] - (u * o[S] + c)) ** 2, b += (o[S] - d) ** 2;
  26479. const R = C - E, p = R === C ? 1 : R / C;
  26480. let N = 0, M = 0, w = 0;
  26481. _ > 0 && (b > 0 && (N = Math.sqrt(E / _ / b), M = Math.sqrt(E / _ * (1 / f + d ** 2 / b))), w = Math.sqrt(E / _));
  26482. const D = _ > 0 ? R / 1 / (E / _) : m.NUM;
  26483. r || (M = m.NA), l = [
  26484. [u, c],
  26485. // [m, b]
  26486. [N, M],
  26487. // [se, seb]
  26488. [p, w],
  26489. // [r2, sey]
  26490. [D, _],
  26491. // [F, df]
  26492. [R, E]
  26493. // [ssreg, ssresid]
  26494. ];
  26495. } else
  26496. l = [
  26497. [u, c]
  26498. // [m, b]
  26499. ];
  26500. return q.createByArray(l);
  26501. }
  26502. _getKnownXsValues(e, t) {
  26503. return !t || t.isNull() ? Xn(e.length, e[0].length) : dt(t);
  26504. }
  26505. }
  26506. class EA extends V {
  26507. constructor() {
  26508. super(...arguments);
  26509. A(this, "minParams", 1);
  26510. A(this, "maxParams", 4);
  26511. }
  26512. calculate(e, t, r, n) {
  26513. const { isError: s, errorObject: o } = Kn(e, t);
  26514. if (s)
  26515. return o;
  26516. const u = dt(e);
  26517. if (u instanceof g)
  26518. return u;
  26519. const c = this._getKnownXsValues(u, t);
  26520. if (c instanceof g)
  26521. return c;
  26522. let l = r != null ? r : T.create(!0);
  26523. l.isArray() && (l = l.get(0, 0));
  26524. let f = n != null ? n : T.create(!1);
  26525. f.isArray() && (f = f.get(0, 0));
  26526. const { isError: h, errorObject: d, variants: _ } = I(l, f);
  26527. if (h)
  26528. return d;
  26529. const [C, E] = _;
  26530. return this._getResult(u, c, +C.getValue(), +E.getValue());
  26531. }
  26532. _getResult(e, t, r, n) {
  26533. return e.length === 1 && t.length > 1 || e[0].length === 1 && t[0].length > 1 ? e.length === 1 && t.length > 1 && (r ? t.length + 1 : t.length) > e[0].length || e[0].length === 1 && t[0].length > 1 && (r ? t[0].length + 1 : t[0].length) > e.length ? g.create(m.NA) : this._getResultByMultipleVariables(e, t, r, n) : this._getResultBySimpleVariables(e, t, r, n);
  26534. }
  26535. // eslint-disable-next-line max-lines-per-function
  26536. _getResultByMultipleVariables(e, t, r, n) {
  26537. const s = zn(e, t, t, r, !0);
  26538. if (s instanceof g)
  26539. return s;
  26540. const { coefficients: o, Y: u, X: c, XTXInverse: l } = s;
  26541. let f = [];
  26542. if (n) {
  26543. const h = u.flat(), d = h.length, _ = r ? h.reduce((F, W) => F + W, 0) / d : 0, C = l.length, E = d - C, b = o[0].length, R = new Array(b - 2).fill(m.NA), p = o[0][b - 1], N = [];
  26544. for (let F = 0; F < c.length; F++) {
  26545. let W = p;
  26546. for (let ne = b - 2; ne >= 0; ne--)
  26547. W *= o[0][b - 2 - ne] ** c[F][ne];
  26548. N.push(Math.log(W));
  26549. }
  26550. let M = 0, w = 0;
  26551. for (let F = 0; F < d; F++)
  26552. M += (h[F] - _) ** 2, !(!r && !Number.isFinite(N[F])) && (w += (h[F] - N[F]) ** 2);
  26553. Number.isFinite(w) || (w = 0);
  26554. const D = M - w, S = M === 0 ? 0 : D / M, P = [];
  26555. for (let F = C - 1; F >= 0; F--) {
  26556. const W = E > 0 ? Math.sqrt(w / E * l[F][F]) : 0;
  26557. P.push(W);
  26558. }
  26559. if (r) {
  26560. const F = P.shift();
  26561. P.push(F);
  26562. } else
  26563. P.push(m.NA);
  26564. const U = E > 0 ? Math.sqrt(w / E) : 0, x = E > 0 ? D / (b - 1) / (w / E) : m.NUM;
  26565. f = [
  26566. o[0],
  26567. // [mn, mn-1, ..., m1, b]
  26568. [...P],
  26569. // [sen, sen-1, ..., se1, seb]
  26570. [S, U, ...R],
  26571. // [r2, sey]
  26572. [x, E, ...R],
  26573. // [F, df]
  26574. [D, w, ...R]
  26575. // [ssreg, ssresid]
  26576. ];
  26577. } else
  26578. f = [
  26579. o[0]
  26580. // [mn, mn-1, ..., m1, b]
  26581. ];
  26582. return q.createByArray(f);
  26583. }
  26584. _getResultBySimpleVariables(e, t, r, n) {
  26585. const s = e.flat(), o = t.flat(), { slope: u, intercept: c, Y: l } = Zn(o, s, r, !0);
  26586. if (Number.isNaN(u))
  26587. return g.create(m.NA);
  26588. let f = [];
  26589. if (n) {
  26590. const h = l.length;
  26591. let d = 0, _ = 0, C = h - 1;
  26592. if (r) {
  26593. let P = 0, U = 0;
  26594. for (let x = 0; x < h; x++)
  26595. P += l[x], U += o[x];
  26596. d = P / h, _ = U / h, C = h - 2;
  26597. }
  26598. let E = 0, b = 0, R = 0;
  26599. for (let P = 0; P < h; P++)
  26600. E += (l[P] - d) ** 2, b += (l[P] - Math.log(c * u ** o[P])) ** 2, R += (o[P] - _) ** 2;
  26601. const p = E - b, N = E === 0 ? 0 : p / E;
  26602. let M = 0, w = 0, D = 0, S = 0;
  26603. C > 0 && (R > 0 && (M = Math.sqrt(b / C / R), w = Math.sqrt(b / C * (1 / h + _ ** 2 / R))), D = Math.sqrt(b / C), S = p / 1 / (b / C)), r || (w = m.NA), f = [
  26604. [u, c],
  26605. // [m, b]
  26606. [M, w],
  26607. // [se, seb]
  26608. [N, D],
  26609. // [r2, sey]
  26610. [S, C],
  26611. // [F, df]
  26612. [p, b]
  26613. // [ssreg, ssresid]
  26614. ];
  26615. } else
  26616. f = [
  26617. [u, c]
  26618. // [m, b]
  26619. ];
  26620. return q.createByArray(f);
  26621. }
  26622. _getKnownXsValues(e, t) {
  26623. return !t || t.isNull() ? Xn(e.length, e[0].length) : dt(t);
  26624. }
  26625. }
  26626. class bA extends V {
  26627. constructor() {
  26628. super(...arguments);
  26629. A(this, "minParams", 4);
  26630. A(this, "maxParams", 4);
  26631. }
  26632. calculate(e, t, r, n) {
  26633. const s = Math.max(
  26634. e.isArray() ? e.getRowCount() : 1,
  26635. t.isArray() ? t.getRowCount() : 1,
  26636. r.isArray() ? r.getRowCount() : 1,
  26637. n.isArray() ? n.getRowCount() : 1
  26638. ), o = Math.max(
  26639. e.isArray() ? e.getColumnCount() : 1,
  26640. t.isArray() ? t.getColumnCount() : 1,
  26641. r.isArray() ? r.getColumnCount() : 1,
  26642. n.isArray() ? n.getColumnCount() : 1
  26643. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  26644. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  26645. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  26646. });
  26647. return s === 1 && o === 1 ? h.get(0, 0) : h;
  26648. }
  26649. _handleSignleObject(e, t, r, n) {
  26650. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  26651. if (s)
  26652. return o;
  26653. const [c, l, f, h] = u, d = +c.getValue(), _ = +l.getValue(), C = +f.getValue(), E = +h.getValue();
  26654. if (d <= 0 || C <= 0)
  26655. return g.create(m.NUM);
  26656. let b;
  26657. return E ? b = Uo(d, _, C) : b = cm(d, _, C), y.create(b);
  26658. }
  26659. }
  26660. class yA extends V {
  26661. constructor() {
  26662. super(...arguments);
  26663. A(this, "minParams", 2);
  26664. A(this, "maxParams", 2);
  26665. }
  26666. calculate(e, t) {
  26667. const r = this._getRangeValues(e);
  26668. if (r instanceof g)
  26669. return r;
  26670. const n = Xt(t);
  26671. if (n.isError())
  26672. return n;
  26673. const { isError: s, errorObject: o, variants: u } = I(n);
  26674. if (s)
  26675. return o;
  26676. const [c] = u, l = +c.getValue();
  26677. if (l <= 0 || l >= 1)
  26678. return g.create(m.NUM);
  26679. if (r.length < 2)
  26680. return g.create(m.DIV_BY_ZERO);
  26681. const f = 1 - l, h = r.length, d = r.reduce((b, R) => b + R, 0) / h, _ = r.reduce((b, R) => b + (R - d) ** 2, 0) / (h - 1), C = Math.sqrt(_);
  26682. if (C <= 0)
  26683. return g.create(m.NUM);
  26684. const E = Math.abs(qn(f / 2, h - 1) * C / Math.sqrt(h));
  26685. return y.create(E);
  26686. }
  26687. _getRangeValues(e) {
  26688. const t = [], r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1;
  26689. for (let s = 0; s < r; s++)
  26690. for (let o = 0; o < n; o++) {
  26691. const u = e.isArray() ? e.get(s, o) : e;
  26692. if (u.isError())
  26693. return u;
  26694. u.isNull() || u.isBoolean() || u.isString() || t.push(+u.getValue());
  26695. }
  26696. return t;
  26697. }
  26698. }
  26699. class RA extends V {
  26700. constructor() {
  26701. super(...arguments);
  26702. A(this, "minParams", 1);
  26703. A(this, "maxParams", 255);
  26704. }
  26705. calculate(...e) {
  26706. let t = y.create(Number.NEGATIVE_INFINITY);
  26707. for (let r = 0; r < e.length; r++) {
  26708. let n = e[r];
  26709. if (!n.isNull()) {
  26710. if ((n.isString() || n.isBoolean()) && (n = n.convertToNumberObjectValue()), n.isArray() && (n = n.max()), n.isError())
  26711. return n;
  26712. t = this._validator(t, n);
  26713. }
  26714. }
  26715. return t.getValue() === Number.NEGATIVE_INFINITY ? y.create(0) : t;
  26716. }
  26717. _validator(e, t) {
  26718. const r = e.isLessThan(t);
  26719. let n = e;
  26720. return r.getValue() && (n = t), n;
  26721. }
  26722. }
  26723. class pA extends V {
  26724. constructor() {
  26725. super(...arguments);
  26726. A(this, "minParams", 1);
  26727. A(this, "maxParams", 255);
  26728. }
  26729. calculate(...e) {
  26730. let t = y.create(Number.NEGATIVE_INFINITY);
  26731. for (let r = 0; r < e.length; r++) {
  26732. let n = e[r];
  26733. if (!n.isNull()) {
  26734. if ((n.isString() || n.isBoolean()) && (n = n.convertToNumberObjectValue()), n.isError())
  26735. return n;
  26736. if (n.isArray() && n.iterator((s) => {
  26737. let o = s;
  26738. if ((o == null || o.isNull() || o.isString()) && (o = y.create(0)), o.isBoolean() && (o = o.convertToNumberObjectValue()), o.isError())
  26739. return t = o, !1;
  26740. t = this._validator(t, o);
  26741. }), t.isError())
  26742. return t;
  26743. t = this._validator(t, n);
  26744. }
  26745. }
  26746. return t.getValue() === Number.NEGATIVE_INFINITY ? y.create(0) : t;
  26747. }
  26748. _validator(e, t) {
  26749. const r = e.isLessThan(t);
  26750. let n = e;
  26751. return r.getValue() && (n = t), n;
  26752. }
  26753. }
  26754. class VA extends V {
  26755. constructor() {
  26756. super(...arguments);
  26757. A(this, "minParams", 3);
  26758. A(this, "maxParams", 255);
  26759. }
  26760. calculate(e, ...t) {
  26761. if (e.isError())
  26762. return g.create(m.NA);
  26763. if (!e.isArray() || t.length % 2 !== 0 || t.some((u, c) => c % 2 === 0 && !u.isArray()))
  26764. return g.create(m.VALUE);
  26765. const { maxRowLength: r, maxColumnLength: n } = Nr(t), s = Br(t, e, r, n);
  26766. if (s)
  26767. return s;
  26768. const o = Ir(t, r, n, !0);
  26769. return this._aggregateResults(e, o);
  26770. }
  26771. _aggregateResults(e, t) {
  26772. const r = t.map((s) => s.map((o) => {
  26773. const u = e.pick(o);
  26774. return u.getColumnCount() === 0 ? q.create("0") : u.max();
  26775. })), n = {
  26776. calculateValueList: r,
  26777. rowCount: r.length,
  26778. columnCount: r[0].length,
  26779. unitId: this.unitId || "",
  26780. sheetId: this.subUnitId || "",
  26781. row: this.row,
  26782. column: this.column
  26783. };
  26784. return q.create(n);
  26785. }
  26786. }
  26787. class NA extends V {
  26788. constructor() {
  26789. super(...arguments);
  26790. A(this, "minParams", 1);
  26791. A(this, "maxParams", 255);
  26792. }
  26793. calculate(...e) {
  26794. const t = [];
  26795. for (let r = 0; r < e.length; r++) {
  26796. const n = e[r];
  26797. if (n.isArray()) {
  26798. let s = !1, o = g.create(m.VALUE);
  26799. if (n.iterator((u) => {
  26800. if (u != null && u.isError())
  26801. return s = !0, o = u, !1;
  26802. if (u != null && u.isNull() || u != null && u.isBoolean())
  26803. return !0;
  26804. const c = u.getValue();
  26805. if (!Q(c))
  26806. return !0;
  26807. t.push(+c);
  26808. }), s)
  26809. return o;
  26810. } else {
  26811. if (n.isError())
  26812. return n;
  26813. if (n.isNull() || n.isBoolean())
  26814. continue;
  26815. if (n.isString()) {
  26816. const o = n.convertToNumberObjectValue();
  26817. if (o.isError())
  26818. return o;
  26819. }
  26820. const s = n.getValue();
  26821. if (!Q(s))
  26822. continue;
  26823. t.push(+s);
  26824. }
  26825. }
  26826. return t.length === 0 ? g.create(m.NUM) : this._getResult(t.sort((r, n) => r - n));
  26827. }
  26828. _getResult(e) {
  26829. const t = e.length;
  26830. let r;
  26831. if (t % 2 === 0) {
  26832. const n = t / 2;
  26833. r = (e[n - 1] + e[n]) / 2;
  26834. } else
  26835. r = e[Math.floor(t / 2)];
  26836. return y.create(r);
  26837. }
  26838. }
  26839. class OA extends V {
  26840. constructor() {
  26841. super(...arguments);
  26842. A(this, "minParams", 1);
  26843. A(this, "maxParams", 255);
  26844. }
  26845. calculate(...e) {
  26846. let t = y.create(Number.POSITIVE_INFINITY);
  26847. for (let r = 0; r < e.length; r++) {
  26848. let n = e[r];
  26849. if (!n.isNull()) {
  26850. if ((n.isString() || n.isBoolean()) && (n = n.convertToNumberObjectValue()), n.isArray() && (n = n.min()), n.isError())
  26851. return n;
  26852. t = this._validator(t, n);
  26853. }
  26854. }
  26855. return t.getValue() === Number.POSITIVE_INFINITY ? y.create(0) : t;
  26856. }
  26857. _validator(e, t) {
  26858. const r = e.isGreaterThan(t);
  26859. let n = e;
  26860. return r.getValue() && (n = t), n;
  26861. }
  26862. }
  26863. class MA extends V {
  26864. constructor() {
  26865. super(...arguments);
  26866. A(this, "minParams", 1);
  26867. A(this, "maxParams", 255);
  26868. }
  26869. calculate(...e) {
  26870. let t = y.create(Number.POSITIVE_INFINITY);
  26871. for (let r = 0; r < e.length; r++) {
  26872. let n = e[r];
  26873. if (!n.isNull()) {
  26874. if ((n.isString() || n.isBoolean()) && (n = n.convertToNumberObjectValue()), n.isError())
  26875. return n;
  26876. if (n.isArray() && n.iterator((s) => {
  26877. let o = s;
  26878. if ((o == null || o.isNull() || o.isString()) && (o = y.create(0)), o.isBoolean() && (o = o.convertToNumberObjectValue()), o.isError())
  26879. return t = o, !1;
  26880. t = this._validator(t, o);
  26881. }), t.isError())
  26882. return t;
  26883. t = this._validator(t, n);
  26884. }
  26885. }
  26886. return t.getValue() === Number.POSITIVE_INFINITY ? y.create(0) : t;
  26887. }
  26888. _validator(e, t) {
  26889. const r = e.isGreaterThan(t);
  26890. let n = e;
  26891. return r.getValue() && (n = t), n;
  26892. }
  26893. }
  26894. class wA extends V {
  26895. constructor() {
  26896. super(...arguments);
  26897. A(this, "minParams", 3);
  26898. A(this, "maxParams", 255);
  26899. }
  26900. calculate(e, ...t) {
  26901. if (e.isError())
  26902. return g.create(m.NA);
  26903. if (!e.isArray() || t.length % 2 !== 0 || t.some((u, c) => c % 2 === 0 && !u.isArray()))
  26904. return g.create(m.VALUE);
  26905. const { maxRowLength: r, maxColumnLength: n } = Nr(t), s = Br(t, e, r, n);
  26906. if (s)
  26907. return s;
  26908. const o = Ir(t, r, n, !0);
  26909. return this._aggregateResults(e, o);
  26910. }
  26911. _aggregateResults(e, t) {
  26912. const r = t.map((s) => s.map((o) => {
  26913. const u = e.pick(o);
  26914. return u.getColumnCount() === 0 ? q.create("0") : u.min();
  26915. })), n = {
  26916. calculateValueList: r,
  26917. rowCount: r.length,
  26918. columnCount: r[0].length,
  26919. unitId: this.unitId || "",
  26920. sheetId: this.subUnitId || "",
  26921. row: this.row,
  26922. column: this.column
  26923. };
  26924. return q.create(n);
  26925. }
  26926. }
  26927. class DA extends V {
  26928. constructor() {
  26929. super(...arguments);
  26930. A(this, "minParams", 1);
  26931. A(this, "maxParams", 255);
  26932. }
  26933. calculate(...e) {
  26934. const t = {};
  26935. let r = 0, n = 1;
  26936. for (let s = 0; s < e.length; s++) {
  26937. const o = e[s];
  26938. if (o.isError())
  26939. return o;
  26940. if (o.isString()) {
  26941. const l = o.convertToNumberObjectValue();
  26942. if (l.isError())
  26943. return l;
  26944. }
  26945. const u = o.isArray() ? o.getRowCount() : 1, c = o.isArray() ? o.getColumnCount() : 1;
  26946. for (let l = 0; l < u; l++)
  26947. for (let f = 0; f < c; f++) {
  26948. const h = o.isArray() ? o.get(l, f) : o;
  26949. if (h.isError())
  26950. return h;
  26951. if (h.isNull() || h.isBoolean() || h.isString())
  26952. continue;
  26953. const d = h.getValue();
  26954. Q(d) && (t[+d] ? (t[+d].count++, t[+d].count > n && (n = t[+d].count)) : t[+d] = { count: 1, order: r++ });
  26955. }
  26956. }
  26957. return r === 0 || n === 1 ? new g(m.NA) : this._getResult(t, n);
  26958. }
  26959. _getResult(e, t) {
  26960. const r = Object.entries(e).filter(([n, { count: s }]) => s === t).sort((n, s) => n[1].order - s[1].order).map(([n]) => +n);
  26961. return r.length === 1 ? y.create(r[0]) : q.createByArray(r.map((n) => [n]));
  26962. }
  26963. }
  26964. class SA extends V {
  26965. constructor() {
  26966. super(...arguments);
  26967. A(this, "minParams", 4);
  26968. A(this, "maxParams", 4);
  26969. }
  26970. calculate(e, t, r, n) {
  26971. const s = Math.max(
  26972. e.isArray() ? e.getRowCount() : 1,
  26973. t.isArray() ? t.getRowCount() : 1,
  26974. r.isArray() ? r.getRowCount() : 1,
  26975. n.isArray() ? n.getRowCount() : 1
  26976. ), o = Math.max(
  26977. e.isArray() ? e.getColumnCount() : 1,
  26978. t.isArray() ? t.getColumnCount() : 1,
  26979. r.isArray() ? r.getColumnCount() : 1,
  26980. n.isArray() ? n.getColumnCount() : 1
  26981. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  26982. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  26983. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSignleObject(d, E, b, R);
  26984. });
  26985. return s === 1 && o === 1 ? h.get(0, 0) : h;
  26986. }
  26987. _handleSignleObject(e, t, r, n) {
  26988. const { isError: s, errorObject: o, variants: u } = I(e, t, r, n);
  26989. if (s)
  26990. return o;
  26991. const [c, l, f, h] = u, d = Math.floor(+c.getValue()), _ = Math.floor(+l.getValue()), C = +f.getValue(), E = +h.getValue();
  26992. if (d < 0 || _ < 1 || C <= 0 || C >= 1)
  26993. return g.create(m.NUM);
  26994. let b;
  26995. return E ? b = fm(d, _, C) : b = ja(d, _, C), y.create(b);
  26996. }
  26997. }
  26998. class PA extends V {
  26999. constructor() {
  27000. super(...arguments);
  27001. A(this, "minParams", 2);
  27002. A(this, "maxParams", 2);
  27003. }
  27004. calculate(e, t) {
  27005. const r = Math.max(
  27006. e.isArray() ? e.getRowCount() : 1,
  27007. t.isArray() ? t.getRowCount() : 1
  27008. ), n = Math.max(
  27009. e.isArray() ? e.getColumnCount() : 1,
  27010. t.isArray() ? t.getColumnCount() : 1
  27011. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27012. const h = o.get(l, f);
  27013. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  27014. });
  27015. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27016. }
  27017. _handleSignleObject(e, t) {
  27018. const { isError: r, errorObject: n, variants: s } = I(e, t);
  27019. if (r)
  27020. return n;
  27021. const [o, u] = s, c = +o.getValue(), l = +u.getValue();
  27022. let f;
  27023. return l ? f = kr(c, 0, 1) : f = vo(c, 0, 1), y.create(f);
  27024. }
  27025. }
  27026. class LA extends V {
  27027. constructor() {
  27028. super(...arguments);
  27029. A(this, "minParams", 2);
  27030. A(this, "maxParams", 2);
  27031. }
  27032. calculate(e, t) {
  27033. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  27034. let u = e;
  27035. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  27036. return u;
  27037. let c = t;
  27038. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  27039. return c;
  27040. if (r * n === 1 || s * o === 1)
  27041. return u.isNull() || c.isNull() ? g.create(m.VALUE) : g.create(m.DIV_BY_ZERO);
  27042. if (r * n !== s * o)
  27043. return g.create(m.NA);
  27044. const {
  27045. isError: l,
  27046. errorObject: f,
  27047. array1Values: h,
  27048. array2Values: d,
  27049. noCalculate: _
  27050. } = Je(
  27051. e,
  27052. t,
  27053. r * n,
  27054. n,
  27055. o
  27056. );
  27057. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  27058. }
  27059. _getResult(e, t) {
  27060. const r = e.length;
  27061. let n = 0, s = 0;
  27062. for (let d = 0; d < r; d++)
  27063. n += e[d], s += t[d];
  27064. const o = n / r, u = s / r;
  27065. let c = 0, l = 0, f = 0;
  27066. for (let d = 0; d < r; d++)
  27067. c += (e[d] - o) * (t[d] - u), l += (e[d] - o) ** 2, f += (t[d] - u) ** 2;
  27068. if (l === 0 || f === 0)
  27069. return g.create(m.DIV_BY_ZERO);
  27070. const h = c / Math.sqrt(l * f);
  27071. return y.create(h);
  27072. }
  27073. }
  27074. class xA extends V {
  27075. constructor() {
  27076. super(...arguments);
  27077. A(this, "minParams", 2);
  27078. A(this, "maxParams", 2);
  27079. }
  27080. calculate(e, t) {
  27081. const r = this._getValues(e);
  27082. if (t.isArray()) {
  27083. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  27084. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  27085. }
  27086. return this._handleSingleObject(r, t);
  27087. }
  27088. _handleSingleObject(e, t) {
  27089. if (e instanceof g)
  27090. return e;
  27091. const { isError: r, errorObject: n, variants: s } = I(t);
  27092. if (r)
  27093. return n;
  27094. const [o] = s, u = +o.getValue(), c = e.length;
  27095. if (u < 1 / (c + 1) || u > 1 - 1 / (c + 1))
  27096. return g.create(m.NUM);
  27097. const l = u * (c + 1) - 1, f = Math.floor(l), h = l - f;
  27098. if (h === 0)
  27099. return y.create(e[f]);
  27100. const d = e[f] + h * (e[f + 1] - e[f]);
  27101. return y.create(d);
  27102. }
  27103. _getValues(e) {
  27104. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  27105. for (let s = 0; s < t; s++)
  27106. for (let o = 0; o < r; o++) {
  27107. const u = e.isArray() ? e.get(s, o) : e;
  27108. if (u.isError())
  27109. return u;
  27110. if (u.isNull() || u.isBoolean() || u.isString())
  27111. continue;
  27112. const c = u.getValue();
  27113. Q(c) && n.push(+c);
  27114. }
  27115. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  27116. }
  27117. }
  27118. class jA extends V {
  27119. constructor() {
  27120. super(...arguments);
  27121. A(this, "minParams", 2);
  27122. A(this, "maxParams", 3);
  27123. }
  27124. calculate(e, t, r) {
  27125. const n = this._getValues(e);
  27126. let s = r != null ? r : y.create(3);
  27127. s.isNull() && (s = y.create(3));
  27128. const o = Math.max(
  27129. t.isArray() ? t.getRowCount() : 1,
  27130. s.isArray() ? s.getRowCount() : 1
  27131. ), u = Math.max(
  27132. t.isArray() ? t.getColumnCount() : 1,
  27133. s.isArray() ? s.getColumnCount() : 1
  27134. ), c = O(o, u, t, g.create(m.NA)), l = O(o, u, s, g.create(m.NA)), f = c.mapValue((h, d, _) => {
  27135. const C = l.get(d, _);
  27136. return h.isError() ? h : C.isError() ? C : this._handleSingleObject(n, h, C);
  27137. });
  27138. return o === 1 && u === 1 ? f.get(0, 0) : f;
  27139. }
  27140. _handleSingleObject(e, t, r) {
  27141. if (e instanceof g)
  27142. return e;
  27143. const { isError: n, errorObject: s, variants: o } = I(t, r);
  27144. if (n)
  27145. return s;
  27146. const [u, c] = o, l = +u.getValue(), f = Math.floor(+c.getValue()), h = e.length;
  27147. if (h === 0 || l < e[0] || l > e[h - 1])
  27148. return g.create(m.NA);
  27149. if (h === 1)
  27150. return l === e[0] ? y.create(1) : g.create(m.NA);
  27151. let d = 0, _ = !1, C = 0;
  27152. for (; !_ && C < h; )
  27153. l === e[C] ? (d = (C + 1) / (h + 1), _ = !0) : l > e[C] && C + 1 < h && l < e[C + 1] && (d = (C + 1 + (l - e[C]) / (e[C + 1] - e[C])) / (h + 1), _ = !0), C++;
  27154. return _ ? f < 1 ? g.create(m.NUM) : (d = We(d, f), y.create(d)) : g.create(m.NA);
  27155. }
  27156. _getValues(e) {
  27157. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  27158. for (let s = 0; s < t; s++)
  27159. for (let o = 0; o < r; o++) {
  27160. const u = e.isArray() ? e.get(s, o) : e;
  27161. if (u.isError())
  27162. return u;
  27163. if (u.isNull() || u.isBoolean())
  27164. continue;
  27165. const c = u.getValue();
  27166. Q(c) && n.push(+c);
  27167. }
  27168. return n.sort((s, o) => s - o);
  27169. }
  27170. }
  27171. class UA extends V {
  27172. constructor() {
  27173. super(...arguments);
  27174. A(this, "minParams", 2);
  27175. A(this, "maxParams", 2);
  27176. }
  27177. calculate(e, t) {
  27178. const r = Math.max(
  27179. e.isArray() ? e.getRowCount() : 1,
  27180. t.isArray() ? t.getRowCount() : 1
  27181. ), n = Math.max(
  27182. e.isArray() ? e.getColumnCount() : 1,
  27183. t.isArray() ? t.getColumnCount() : 1
  27184. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27185. const h = o.get(l, f);
  27186. if (c.isError())
  27187. return c;
  27188. if (h.isError())
  27189. return h;
  27190. const { isError: d, errorObject: _, variants: C } = I(c, h);
  27191. if (d)
  27192. return _;
  27193. const [E, b] = C, R = Math.floor(+E.getValue()), p = Math.floor(+b.getValue());
  27194. if (R < 0 || R >= 2147483647 || p < 0 || R < p)
  27195. return g.create(m.NUM);
  27196. let N = 1;
  27197. for (let M = R - p + 1; M <= R; M++)
  27198. N *= M;
  27199. return Number.isFinite(N) ? y.create(N) : g.create(m.NUM);
  27200. });
  27201. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27202. }
  27203. }
  27204. class vA extends V {
  27205. constructor() {
  27206. super(...arguments);
  27207. A(this, "minParams", 2);
  27208. A(this, "maxParams", 2);
  27209. }
  27210. calculate(e, t) {
  27211. const r = Math.max(
  27212. e.isArray() ? e.getRowCount() : 1,
  27213. t.isArray() ? t.getRowCount() : 1
  27214. ), n = Math.max(
  27215. e.isArray() ? e.getColumnCount() : 1,
  27216. t.isArray() ? t.getColumnCount() : 1
  27217. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27218. const h = o.get(l, f);
  27219. if (c.isError())
  27220. return c;
  27221. if (h.isError())
  27222. return h;
  27223. const { isError: d, errorObject: _, variants: C } = I(c, h);
  27224. if (d)
  27225. return _;
  27226. const [E, b] = C, R = Math.floor(+E.getValue()), p = Math.floor(+b.getValue());
  27227. if (R < 0 || R >= 2147483647 || p < 0)
  27228. return g.create(m.NUM);
  27229. if (R === 0)
  27230. return p === 0 ? y.create(1) : y.create(0);
  27231. const N = R ** p;
  27232. return Number.isFinite(N) ? y.create(N) : g.create(m.NUM);
  27233. });
  27234. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27235. }
  27236. }
  27237. class TA extends V {
  27238. constructor() {
  27239. super(...arguments);
  27240. A(this, "minParams", 1);
  27241. A(this, "maxParams", 1);
  27242. }
  27243. calculate(e) {
  27244. if (e.isArray()) {
  27245. const t = e.mapValue((r) => this._handleSingleObject(r));
  27246. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  27247. }
  27248. return this._handleSingleObject(e);
  27249. }
  27250. _handleSingleObject(e) {
  27251. const { isError: t, errorObject: r, variants: n } = I(e);
  27252. if (t)
  27253. return r;
  27254. const [s] = n, o = +s.getValue(), u = Math.exp(-0.5 * o * o) / Math.sqrt(2 * Math.PI);
  27255. return y.create(u);
  27256. }
  27257. }
  27258. class BA extends V {
  27259. constructor() {
  27260. super(...arguments);
  27261. A(this, "minParams", 3);
  27262. A(this, "maxParams", 4);
  27263. }
  27264. calculate(e, t, r, n) {
  27265. const { isError: s, errorObject: o, xRangeValues: u, probRangeValues: c } = this._handleXRangeAndProbRange(e, t);
  27266. let l = n != null ? n : r;
  27267. n != null && n.isNull() && (l = r);
  27268. const f = Math.max(
  27269. r.isArray() ? r.getRowCount() : 1,
  27270. l.isArray() ? l.getRowCount() : 1
  27271. ), h = Math.max(
  27272. r.isArray() ? r.getColumnCount() : 1,
  27273. l.isArray() ? l.getColumnCount() : 1
  27274. ), d = O(f, h, r, g.create(m.NA)), _ = O(f, h, l, g.create(m.NA)), C = d.mapValue((E, b, R) => {
  27275. const p = _.get(b, R);
  27276. return e.isError() ? e : t.isError() ? t : E.isError() ? E : p.isError() ? p : s ? o : this._handleSignleObject(u, c, E, p);
  27277. });
  27278. return f === 1 && h === 1 ? C.get(0, 0) : C;
  27279. }
  27280. _handleSignleObject(e, t, r, n) {
  27281. const { isError: s, errorObject: o, variants: u } = I(r, n);
  27282. if (s)
  27283. return o;
  27284. const [c, l] = u, f = +c.getValue(), h = +l.getValue();
  27285. if (t.reduce((_, C) => _ + C, 0) !== 1)
  27286. return g.create(m.NUM);
  27287. let d = 0;
  27288. for (let _ = 0; _ < e.length; _++)
  27289. e[_] >= f && e[_] <= h && (d += t[_]);
  27290. return y.create(d);
  27291. }
  27292. // eslint-disable-next-line
  27293. _handleXRangeAndProbRange(e, t) {
  27294. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  27295. let u = e;
  27296. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  27297. return {
  27298. isError: !0,
  27299. errorObject: u,
  27300. xRangeValues: [],
  27301. probRangeValues: []
  27302. };
  27303. let c = t;
  27304. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  27305. return {
  27306. isError: !0,
  27307. errorObject: c,
  27308. xRangeValues: [],
  27309. probRangeValues: []
  27310. };
  27311. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  27312. return {
  27313. isError: !0,
  27314. errorObject: g.create(m.VALUE),
  27315. xRangeValues: [],
  27316. probRangeValues: []
  27317. };
  27318. if (r * n !== s * o)
  27319. return {
  27320. isError: !0,
  27321. errorObject: g.create(m.NA),
  27322. xRangeValues: [],
  27323. probRangeValues: []
  27324. };
  27325. const {
  27326. isError: l,
  27327. errorObject: f,
  27328. array1Values: h,
  27329. array2Values: d,
  27330. noCalculate: _
  27331. } = Je(
  27332. e,
  27333. t,
  27334. r * n,
  27335. n,
  27336. o
  27337. );
  27338. return l ? {
  27339. isError: !0,
  27340. errorObject: f,
  27341. xRangeValues: [],
  27342. probRangeValues: []
  27343. } : _ ? {
  27344. isError: !0,
  27345. errorObject: g.create(m.DIV_BY_ZERO),
  27346. xRangeValues: [],
  27347. probRangeValues: []
  27348. } : {
  27349. isError: !1,
  27350. errorObject: null,
  27351. xRangeValues: h,
  27352. probRangeValues: d
  27353. };
  27354. }
  27355. }
  27356. class IA extends V {
  27357. constructor() {
  27358. super(...arguments);
  27359. A(this, "minParams", 2);
  27360. A(this, "maxParams", 2);
  27361. }
  27362. calculate(e, t) {
  27363. const r = this._getValues(e);
  27364. if (t.isArray()) {
  27365. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  27366. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  27367. }
  27368. return this._handleSingleObject(r, t);
  27369. }
  27370. _handleSingleObject(e, t) {
  27371. if (e instanceof g)
  27372. return e;
  27373. const { isError: r, errorObject: n, variants: s } = I(t);
  27374. if (r)
  27375. return n;
  27376. const [o] = s, u = Math.floor(+o.getValue());
  27377. if (u <= 0 || u >= 4)
  27378. return g.create(m.NUM);
  27379. const c = u / 4, l = e.length;
  27380. if (c < 1 / (l + 1) || c > 1 - 1 / (l + 1))
  27381. return g.create(m.NUM);
  27382. const f = c * (l + 1) - 1, h = Math.floor(f), d = f - h;
  27383. if (d === 0)
  27384. return y.create(e[h]);
  27385. const _ = e[h] + d * (e[h + 1] - e[h]);
  27386. return y.create(_);
  27387. }
  27388. _getValues(e) {
  27389. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  27390. for (let s = 0; s < t; s++)
  27391. for (let o = 0; o < r; o++) {
  27392. const u = e.isArray() ? e.get(s, o) : e;
  27393. if (u.isError())
  27394. return u;
  27395. if (u.isNull() || u.isBoolean())
  27396. continue;
  27397. const c = u.getValue();
  27398. Q(c) && n.push(+c);
  27399. }
  27400. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  27401. }
  27402. }
  27403. class FA extends V {
  27404. constructor() {
  27405. super(...arguments);
  27406. A(this, "minParams", 2);
  27407. A(this, "maxParams", 3);
  27408. A(this, "needsReferenceObject", !0);
  27409. }
  27410. calculate(e, t, r) {
  27411. let n = e;
  27412. n.isReferenceObject() && (n = n.toArrayValueObject());
  27413. const { refHasError: s, refErrorObject: o, refNumbers: u } = this._checkRefReferenceObject(t);
  27414. let c = r != null ? r : y.create(0);
  27415. c.isReferenceObject() && (c = c.toArrayValueObject());
  27416. const l = Math.max(
  27417. n.isArray() ? n.getRowCount() : 1,
  27418. c.isArray() ? c.getRowCount() : 1
  27419. ), f = Math.max(
  27420. n.isArray() ? n.getColumnCount() : 1,
  27421. c.isArray() ? c.getColumnCount() : 1
  27422. ), h = O(l, f, n, g.create(m.NA)), d = O(l, f, c, g.create(m.NA)), _ = h.map((C, E, b) => {
  27423. const R = d.get(E, b);
  27424. if (!e.isReferenceObject() && e.isNull())
  27425. return g.create(m.NA);
  27426. if (s)
  27427. return o;
  27428. if (R.isError())
  27429. return R;
  27430. const p = +C.getValue(), N = +R.getValue();
  27431. return Number.isNaN(p) || Number.isNaN(N) ? g.create(m.VALUE) : this._getResult(p, N, u);
  27432. });
  27433. return l === 1 && f === 1 ? _.get(0, 0) : _;
  27434. }
  27435. _getResult(e, t, r) {
  27436. const n = r.sort((c, l) => t ? c - l : l - c);
  27437. let s = n.indexOf(e);
  27438. const o = [];
  27439. for (; s >= 0; ) {
  27440. const c = s + 1;
  27441. o.push(c), s = n.indexOf(e, c);
  27442. }
  27443. if (o.length === 0)
  27444. return g.create(m.NA);
  27445. const u = o.reduce((c, l) => c + l, 0) / o.length;
  27446. return y.create(u);
  27447. }
  27448. _checkRefReferenceObject(e) {
  27449. let t = !1, r = g.create(m.NA);
  27450. const n = [];
  27451. return e.isReferenceObject() ? (e.toArrayValueObject().iterator((o) => {
  27452. const u = o;
  27453. if (u.isError())
  27454. return t = !0, r = u, !1;
  27455. if (u.isNull() || u.isBoolean())
  27456. return !0;
  27457. const c = +u.getValue();
  27458. if (Number.isNaN(c))
  27459. return !0;
  27460. n.push(c);
  27461. }), {
  27462. refHasError: t,
  27463. refErrorObject: r,
  27464. refNumbers: n
  27465. }) : {
  27466. refHasError: !0,
  27467. refErrorObject: r,
  27468. refNumbers: n
  27469. };
  27470. }
  27471. }
  27472. class kA extends V {
  27473. constructor() {
  27474. super(...arguments);
  27475. A(this, "minParams", 2);
  27476. A(this, "maxParams", 3);
  27477. A(this, "needsReferenceObject", !0);
  27478. }
  27479. calculate(e, t, r) {
  27480. let n = e;
  27481. n.isReferenceObject() && (n = n.toArrayValueObject());
  27482. const { refHasError: s, refErrorObject: o, refNumbers: u } = this._checkRefReferenceObject(t);
  27483. let c = r != null ? r : y.create(0);
  27484. c.isReferenceObject() && (c = c.toArrayValueObject());
  27485. const l = Math.max(
  27486. n.isArray() ? n.getRowCount() : 1,
  27487. c.isArray() ? c.getRowCount() : 1
  27488. ), f = Math.max(
  27489. n.isArray() ? n.getColumnCount() : 1,
  27490. c.isArray() ? c.getColumnCount() : 1
  27491. ), h = O(l, f, n, g.create(m.NA)), d = O(l, f, c, g.create(m.NA)), _ = h.map((C, E, b) => {
  27492. const R = d.get(E, b);
  27493. if (!e.isReferenceObject() && e.isNull())
  27494. return g.create(m.NA);
  27495. if (s)
  27496. return o;
  27497. if (R.isError())
  27498. return R;
  27499. const p = +C.getValue(), N = +R.getValue();
  27500. if (Number.isNaN(p) || Number.isNaN(N))
  27501. return g.create(m.VALUE);
  27502. const w = u.sort((D, S) => N ? D - S : S - D).indexOf(p);
  27503. return w === -1 ? g.create(m.NA) : y.create(w + 1);
  27504. });
  27505. return l === 1 && f === 1 ? _.get(0, 0) : _;
  27506. }
  27507. _checkRefReferenceObject(e) {
  27508. let t = !1, r = g.create(m.NA);
  27509. const n = [];
  27510. return e.isReferenceObject() ? (e.toArrayValueObject().iterator((o) => {
  27511. const u = o;
  27512. if (u.isError())
  27513. return t = !0, r = u, !1;
  27514. if (u.isNull() || u.isBoolean())
  27515. return !0;
  27516. const c = +u.getValue();
  27517. if (Number.isNaN(c))
  27518. return !0;
  27519. n.push(c);
  27520. }), {
  27521. refHasError: t,
  27522. refErrorObject: r,
  27523. refNumbers: n
  27524. }) : {
  27525. refHasError: !0,
  27526. refErrorObject: r,
  27527. refNumbers: n
  27528. };
  27529. }
  27530. }
  27531. class $A extends V {
  27532. constructor() {
  27533. super(...arguments);
  27534. A(this, "minParams", 2);
  27535. A(this, "maxParams", 2);
  27536. }
  27537. calculate(e, t) {
  27538. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  27539. let u = e;
  27540. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  27541. return u;
  27542. let c = t;
  27543. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  27544. return c;
  27545. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  27546. return g.create(m.VALUE);
  27547. if (r * n !== s * o)
  27548. return g.create(m.NA);
  27549. const {
  27550. isError: l,
  27551. errorObject: f,
  27552. array1Values: h,
  27553. array2Values: d,
  27554. noCalculate: _
  27555. } = Je(
  27556. e,
  27557. t,
  27558. r * n,
  27559. n,
  27560. o
  27561. );
  27562. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  27563. }
  27564. _getResult(e, t) {
  27565. if (e.length === 0)
  27566. return g.create(m.DIV_BY_ZERO);
  27567. const r = e.length;
  27568. let n = 0, s = 0;
  27569. for (let d = 0; d < r; d++)
  27570. n += e[d], s += t[d];
  27571. const o = n / r, u = s / r;
  27572. let c = 0, l = 0, f = 0;
  27573. for (let d = 0; d < r; d++)
  27574. c += (e[d] - o) * (t[d] - u), l += (e[d] - o) ** 2, f += (t[d] - u) ** 2;
  27575. if (l === 0 || f === 0)
  27576. return g.create(m.DIV_BY_ZERO);
  27577. const h = (c / Math.sqrt(l * f)) ** 2;
  27578. return y.create(h);
  27579. }
  27580. }
  27581. class YA extends V {
  27582. constructor() {
  27583. super(...arguments);
  27584. A(this, "minParams", 1);
  27585. A(this, "maxParams", 255);
  27586. }
  27587. calculate(...e) {
  27588. const t = [];
  27589. let r = 0;
  27590. for (let n = 0; n < e.length; n++) {
  27591. const s = e[n];
  27592. if (s.isError())
  27593. return s;
  27594. if (s.isString()) {
  27595. const c = s.convertToNumberObjectValue();
  27596. if (c.isError())
  27597. return c;
  27598. }
  27599. const o = s.isArray() ? s.getRowCount() : 1, u = s.isArray() ? s.getColumnCount() : 1;
  27600. for (let c = 0; c < o; c++)
  27601. for (let l = 0; l < u; l++) {
  27602. const f = s.isArray() ? s.get(c, l) : s;
  27603. if (f.isError())
  27604. return f;
  27605. if (f.isNull() || f.isBoolean())
  27606. continue;
  27607. const h = f.getValue();
  27608. Q(h) && (t.push(+h), r += +h);
  27609. }
  27610. }
  27611. return t.length <= 2 ? g.create(m.DIV_BY_ZERO) : this._getResult(t, r);
  27612. }
  27613. _getResult(e, t) {
  27614. const r = e.length, n = t / r;
  27615. let s = 0;
  27616. for (let l = 0; l < r; l++)
  27617. s += (e[l] - n) ** 2;
  27618. const o = Math.sqrt(s / (r - 1));
  27619. if (o === 0)
  27620. return g.create(m.DIV_BY_ZERO);
  27621. let u = 0;
  27622. for (let l = 0; l < r; l++)
  27623. u += ((e[l] - n) / o) ** 3;
  27624. const c = r / ((r - 1) * (r - 2)) * u;
  27625. return y.create(c);
  27626. }
  27627. }
  27628. class HA extends V {
  27629. constructor() {
  27630. super(...arguments);
  27631. A(this, "minParams", 1);
  27632. A(this, "maxParams", 255);
  27633. }
  27634. calculate(...e) {
  27635. const t = [];
  27636. let r = 0;
  27637. for (let n = 0; n < e.length; n++) {
  27638. const s = e[n];
  27639. if (s.isError())
  27640. return s;
  27641. if (s.isString()) {
  27642. const c = s.convertToNumberObjectValue();
  27643. if (c.isError())
  27644. return c;
  27645. }
  27646. const o = s.isArray() ? s.getRowCount() : 1, u = s.isArray() ? s.getColumnCount() : 1;
  27647. for (let c = 0; c < o; c++)
  27648. for (let l = 0; l < u; l++) {
  27649. const f = s.isArray() ? s.get(c, l) : s;
  27650. if (f.isError())
  27651. return f;
  27652. if (f.isNull() || f.isBoolean())
  27653. continue;
  27654. const h = f.getValue();
  27655. Q(h) && (t.push(+h), r += +h);
  27656. }
  27657. }
  27658. return t.length <= 2 ? g.create(m.DIV_BY_ZERO) : this._getResult(t, r);
  27659. }
  27660. _getResult(e, t) {
  27661. const r = e.length, n = t / r;
  27662. let s = 0;
  27663. for (let l = 0; l < r; l++)
  27664. s += (e[l] - n) ** 2;
  27665. const o = Math.sqrt(s / r);
  27666. if (o === 0)
  27667. return g.create(m.DIV_BY_ZERO);
  27668. let u = 0;
  27669. for (let l = 0; l < r; l++)
  27670. u += ((e[l] - n) / o) ** 3;
  27671. const c = u / r;
  27672. return y.create(c);
  27673. }
  27674. }
  27675. class GA extends V {
  27676. constructor() {
  27677. super(...arguments);
  27678. A(this, "minParams", 2);
  27679. A(this, "maxParams", 2);
  27680. }
  27681. calculate(e, t) {
  27682. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  27683. let u = e;
  27684. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  27685. return u;
  27686. let c = t;
  27687. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  27688. return c;
  27689. if (r * n === 1 || s * o === 1)
  27690. return u.isNull() || c.isNull() ? g.create(m.VALUE) : g.create(m.DIV_BY_ZERO);
  27691. if (r * n !== s * o)
  27692. return g.create(m.NA);
  27693. const {
  27694. isError: l,
  27695. errorObject: f,
  27696. array1Values: h,
  27697. array2Values: d,
  27698. noCalculate: _
  27699. } = Je(
  27700. e,
  27701. t,
  27702. r * n,
  27703. n,
  27704. o
  27705. );
  27706. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  27707. }
  27708. _getResult(e, t) {
  27709. const r = e.length;
  27710. let n = 0, s = 0;
  27711. for (let h = 0; h < r; h++)
  27712. n += e[h], s += t[h];
  27713. const o = n / r, u = s / r;
  27714. let c = 0, l = 0;
  27715. for (let h = 0; h < r; h++)
  27716. c += (e[h] - o) * (t[h] - u), l += (t[h] - u) ** 2;
  27717. if (l === 0)
  27718. return g.create(m.DIV_BY_ZERO);
  27719. const f = c / l;
  27720. return y.create(f);
  27721. }
  27722. }
  27723. class QA extends V {
  27724. constructor() {
  27725. super(...arguments);
  27726. A(this, "minParams", 2);
  27727. A(this, "maxParams", 2);
  27728. }
  27729. calculate(e, t) {
  27730. const r = this._getValues(e);
  27731. if (t.isArray()) {
  27732. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  27733. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  27734. }
  27735. return this._handleSingleObject(r, t);
  27736. }
  27737. _handleSingleObject(e, t) {
  27738. if (e instanceof g)
  27739. return e;
  27740. const { isError: r, errorObject: n, variants: s } = I(t);
  27741. if (r)
  27742. return n;
  27743. const [o] = s;
  27744. let u = +o.getValue();
  27745. return u < 1 || u > e.length ? g.create(m.NUM) : (u = Math.floor(u), y.create(e[u - 1]));
  27746. }
  27747. _getValues(e) {
  27748. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  27749. for (let s = 0; s < t; s++)
  27750. for (let o = 0; o < r; o++) {
  27751. const u = e.isArray() ? e.get(s, o) : e;
  27752. if (u.isError())
  27753. return u;
  27754. if (u.isNull() || u.isBoolean() || u.isString())
  27755. continue;
  27756. const c = u.getValue();
  27757. Q(c) && n.push(+c);
  27758. }
  27759. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  27760. }
  27761. }
  27762. class WA extends V {
  27763. constructor() {
  27764. super(...arguments);
  27765. A(this, "minParams", 3);
  27766. A(this, "maxParams", 3);
  27767. }
  27768. calculate(e, t, r) {
  27769. const n = Math.max(
  27770. e.isArray() ? e.getRowCount() : 1,
  27771. t.isArray() ? t.getRowCount() : 1,
  27772. r.isArray() ? r.getRowCount() : 1
  27773. ), s = Math.max(
  27774. e.isArray() ? e.getColumnCount() : 1,
  27775. t.isArray() ? t.getColumnCount() : 1,
  27776. r.isArray() ? r.getColumnCount() : 1
  27777. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  27778. const _ = u.get(h, d), C = c.get(h, d);
  27779. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  27780. });
  27781. return n === 1 && s === 1 ? l.get(0, 0) : l;
  27782. }
  27783. _handleSignleObject(e, t, r) {
  27784. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  27785. if (n)
  27786. return s;
  27787. const [u, c, l] = o, f = +u.getValue(), h = +c.getValue(), d = +l.getValue();
  27788. if (d <= 0)
  27789. return g.create(m.NUM);
  27790. const _ = (f - h) / d;
  27791. return y.create(_);
  27792. }
  27793. }
  27794. class qA extends V {
  27795. constructor() {
  27796. super(...arguments);
  27797. A(this, "minParams", 1);
  27798. A(this, "maxParams", 255);
  27799. }
  27800. calculate(...e) {
  27801. const t = this.flattenArray(e, !1);
  27802. return t.isError() ? t : t.std(1);
  27803. }
  27804. }
  27805. class KA extends V {
  27806. constructor() {
  27807. super(...arguments);
  27808. A(this, "minParams", 1);
  27809. A(this, "maxParams", 255);
  27810. }
  27811. calculate(...e) {
  27812. const t = this.flattenArray(e, !1);
  27813. return t.isError() ? t : t.std();
  27814. }
  27815. }
  27816. class XA extends V {
  27817. constructor() {
  27818. super(...arguments);
  27819. A(this, "minParams", 2);
  27820. A(this, "maxParams", 2);
  27821. }
  27822. calculate(e, t) {
  27823. const r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1, s = t.isArray() ? t.getRowCount() : 1, o = t.isArray() ? t.getColumnCount() : 1;
  27824. let u = e;
  27825. if (e.isArray() && r === 1 && n === 1 && (u = e.get(0, 0)), u.isError())
  27826. return u;
  27827. let c = t;
  27828. if (t.isArray() && s === 1 && o === 1 && (c = t.get(0, 0)), c.isError())
  27829. return c;
  27830. if ((r * n === 1 || s * o === 1) && (u.isNull() || c.isNull()))
  27831. return g.create(m.VALUE);
  27832. if (r * n !== s * o)
  27833. return g.create(m.NA);
  27834. const {
  27835. isError: l,
  27836. errorObject: f,
  27837. array1Values: h,
  27838. array2Values: d,
  27839. noCalculate: _
  27840. } = Je(
  27841. e,
  27842. t,
  27843. r * n,
  27844. n,
  27845. o
  27846. );
  27847. return l ? f : _ ? g.create(m.DIV_BY_ZERO) : this._getResult(h, d);
  27848. }
  27849. _getResult(e, t) {
  27850. const r = e.length;
  27851. if (r <= 2)
  27852. return g.create(m.DIV_BY_ZERO);
  27853. let n = 0, s = 0;
  27854. for (let d = 0; d < r; d++)
  27855. n += e[d], s += t[d];
  27856. const o = n / r, u = s / r;
  27857. let c = 0, l = 0, f = 0;
  27858. for (let d = 0; d < r; d++)
  27859. c += (e[d] - o) * (t[d] - u), l += (e[d] - o) ** 2, f += (t[d] - u) ** 2;
  27860. if (f === 0)
  27861. return g.create(m.DIV_BY_ZERO);
  27862. const h = Math.sqrt((l - c ** 2 / f) / (r - 2));
  27863. return Number.isNaN(h) || !Number.isFinite(h) ? g.create(m.NUM) : y.create(h);
  27864. }
  27865. }
  27866. class ZA extends V {
  27867. constructor() {
  27868. super(...arguments);
  27869. A(this, "minParams", 3);
  27870. A(this, "maxParams", 3);
  27871. }
  27872. calculate(e, t, r) {
  27873. const n = Math.max(
  27874. e.isArray() ? e.getRowCount() : 1,
  27875. t.isArray() ? t.getRowCount() : 1,
  27876. r.isArray() ? r.getRowCount() : 1
  27877. ), s = Math.max(
  27878. e.isArray() ? e.getColumnCount() : 1,
  27879. t.isArray() ? t.getColumnCount() : 1,
  27880. r.isArray() ? r.getColumnCount() : 1
  27881. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  27882. const _ = u.get(h, d), C = c.get(h, d);
  27883. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSignleObject(f, _, C);
  27884. });
  27885. return n === 1 && s === 1 ? l.get(0, 0) : l;
  27886. }
  27887. _handleSignleObject(e, t, r) {
  27888. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  27889. if (n)
  27890. return s;
  27891. const [u, c, l] = o, f = +u.getValue(), h = Math.floor(+c.getValue()), d = +l.getValue();
  27892. if (h < 1)
  27893. return g.create(m.NUM);
  27894. let _;
  27895. return d ? _ = $r(f, h) : _ = mm(f, h), Number.isNaN(_) || !Number.isFinite(_) ? g.create(m.NUM) : y.create(_);
  27896. }
  27897. }
  27898. class zA extends V {
  27899. constructor() {
  27900. super(...arguments);
  27901. A(this, "minParams", 2);
  27902. A(this, "maxParams", 2);
  27903. }
  27904. calculate(e, t) {
  27905. const r = Math.max(
  27906. e.isArray() ? e.getRowCount() : 1,
  27907. t.isArray() ? t.getRowCount() : 1
  27908. ), n = Math.max(
  27909. e.isArray() ? e.getColumnCount() : 1,
  27910. t.isArray() ? t.getColumnCount() : 1
  27911. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27912. const h = o.get(l, f);
  27913. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  27914. });
  27915. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27916. }
  27917. _handleSignleObject(e, t) {
  27918. const { isError: r, errorObject: n, variants: s } = I(e, t);
  27919. if (r)
  27920. return n;
  27921. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  27922. if (c < 0 || l < 1 || l > 10 ** 10)
  27923. return g.create(m.NUM);
  27924. const f = $r(-c, l) * 2;
  27925. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  27926. }
  27927. }
  27928. class JA extends V {
  27929. constructor() {
  27930. super(...arguments);
  27931. A(this, "minParams", 2);
  27932. A(this, "maxParams", 2);
  27933. }
  27934. calculate(e, t) {
  27935. const r = Math.max(
  27936. e.isArray() ? e.getRowCount() : 1,
  27937. t.isArray() ? t.getRowCount() : 1
  27938. ), n = Math.max(
  27939. e.isArray() ? e.getColumnCount() : 1,
  27940. t.isArray() ? t.getColumnCount() : 1
  27941. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27942. const h = o.get(l, f);
  27943. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  27944. });
  27945. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27946. }
  27947. _handleSignleObject(e, t) {
  27948. const { isError: r, errorObject: n, variants: s } = I(e, t);
  27949. if (r)
  27950. return n;
  27951. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  27952. if (l < 1 || l > 10 ** 10)
  27953. return g.create(m.NUM);
  27954. const f = $r(-c, l);
  27955. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  27956. }
  27957. }
  27958. class eE extends V {
  27959. constructor() {
  27960. super(...arguments);
  27961. A(this, "minParams", 2);
  27962. A(this, "maxParams", 2);
  27963. }
  27964. calculate(e, t) {
  27965. const r = Math.max(
  27966. e.isArray() ? e.getRowCount() : 1,
  27967. t.isArray() ? t.getRowCount() : 1
  27968. ), n = Math.max(
  27969. e.isArray() ? e.getColumnCount() : 1,
  27970. t.isArray() ? t.getColumnCount() : 1
  27971. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.mapValue((c, l, f) => {
  27972. const h = o.get(l, f);
  27973. return c.isError() ? c : h.isError() ? h : this._handleSignleObject(c, h);
  27974. });
  27975. return r === 1 && n === 1 ? u.get(0, 0) : u;
  27976. }
  27977. _handleSignleObject(e, t) {
  27978. const { isError: r, errorObject: n, variants: s } = I(e, t);
  27979. if (r)
  27980. return n;
  27981. const [o, u] = s, c = +o.getValue(), l = Math.floor(+u.getValue());
  27982. if (c <= 0 || c > 1 || l < 1 || l > 10 ** 10)
  27983. return g.create(m.NUM);
  27984. const f = qn(c, l);
  27985. return Number.isNaN(f) || !Number.isFinite(f) ? g.create(m.NUM) : y.create(f);
  27986. }
  27987. }
  27988. class tE extends V {
  27989. constructor() {
  27990. super(...arguments);
  27991. A(this, "minParams", 1);
  27992. A(this, "maxParams", 4);
  27993. }
  27994. calculate(e, t, r, n) {
  27995. const { isError: s, errorObject: o } = Kn(e, t, r);
  27996. if (s)
  27997. return o;
  27998. const u = dt(e);
  27999. if (u instanceof g)
  28000. return u;
  28001. const c = this._getKnownXsValues(u, t);
  28002. if (c instanceof g)
  28003. return c;
  28004. const l = this._getNewXsValues(c, r);
  28005. if (l instanceof g)
  28006. return l;
  28007. let f = n != null ? n : T.create(!0);
  28008. if (f.isArray() && (f = f.get(0, 0)), f.isString() && (f = f.convertToNumberObjectValue()), f.isError())
  28009. return f;
  28010. const h = +f.getValue();
  28011. return this._getResult(u, c, l, h);
  28012. }
  28013. _getResult(e, t, r, n) {
  28014. return e.length === 1 && t.length > 1 || e[0].length === 1 && t[0].length > 1 ? e.length === 1 && t.length > 1 && (n ? t.length + 1 : t.length) > e[0].length || e[0].length === 1 && t[0].length > 1 && (n ? t[0].length + 1 : t[0].length) > e.length ? g.create(m.NA) : this._getResultByMultipleVariables(e, t, r, n) : this._getResultBySimpleVariables(e, t, r, n);
  28015. }
  28016. _getResultByMultipleVariables(e, t, r, n) {
  28017. const s = e.length === 1 && e[0].length > 1, o = zn(e, t, r, n, !1);
  28018. if (o instanceof g)
  28019. return o;
  28020. const { coefficients: u, newX: c } = o, l = u[0].length, f = u[0][l - 1];
  28021. let h = [];
  28022. for (let d = 0; d < c.length; d++) {
  28023. h[d] = [];
  28024. let _ = f;
  28025. for (let C = l - 2; C >= 0; C--)
  28026. _ += u[0][l - 2 - C] * c[d][C];
  28027. h[d].push(_);
  28028. }
  28029. return s && (h = mt(h)), q.createByArray(h);
  28030. }
  28031. _getResultBySimpleVariables(e, t, r, n) {
  28032. const s = e.flat(), o = t.flat(), { slope: u, intercept: c } = Zn(o, s, n, !1);
  28033. if (Number.isNaN(u))
  28034. return g.create(m.NA);
  28035. const l = r.map((f) => f.map((h) => u * h + c));
  28036. return q.createByArray(l);
  28037. }
  28038. _getKnownXsValues(e, t) {
  28039. return !t || t.isNull() ? Xn(e.length, e[0].length) : dt(t);
  28040. }
  28041. _getNewXsValues(e, t) {
  28042. return !t || t.isNull() ? e : dt(t);
  28043. }
  28044. }
  28045. class rE extends V {
  28046. constructor() {
  28047. super(...arguments);
  28048. A(this, "minParams", 2);
  28049. A(this, "maxParams", 2);
  28050. }
  28051. calculate(e, t) {
  28052. const r = this._getValues(e);
  28053. if (t.isArray()) {
  28054. const n = t.mapValue((s) => this._handleSingleObject(r, s));
  28055. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  28056. }
  28057. return this._handleSingleObject(r, t);
  28058. }
  28059. _handleSingleObject(e, t) {
  28060. if (e instanceof g)
  28061. return e;
  28062. const { isError: r, errorObject: n, variants: s } = I(t);
  28063. if (r)
  28064. return n;
  28065. const [o] = s, u = +o.getValue();
  28066. if (u < 0 || u >= 1)
  28067. return g.create(m.NUM);
  28068. const c = We(e.length * u / 2, 0) * 2, l = e.slice(c / 2, e.length - c / 2), f = l.reduce((h, d) => h + d, 0) / l.length;
  28069. return y.create(f);
  28070. }
  28071. _getValues(e) {
  28072. const t = e.isArray() ? e.getRowCount() : 1, r = e.isArray() ? e.getColumnCount() : 1, n = [];
  28073. for (let s = 0; s < t; s++)
  28074. for (let o = 0; o < r; o++) {
  28075. const u = e.isArray() ? e.get(s, o) : e;
  28076. if (u.isError())
  28077. return u;
  28078. if (u.isNull() || u.isBoolean())
  28079. continue;
  28080. const c = u.getValue();
  28081. Q(c) && n.push(+c);
  28082. }
  28083. return n.length === 0 ? g.create(m.NUM) : n.sort((s, o) => s - o);
  28084. }
  28085. }
  28086. class nE extends V {
  28087. constructor() {
  28088. super(...arguments);
  28089. A(this, "minParams", 1);
  28090. A(this, "maxParams", 255);
  28091. }
  28092. calculate(...e) {
  28093. const t = this.flattenArray(e, !1);
  28094. return t.isError() ? t : t.var(1);
  28095. }
  28096. }
  28097. class sE extends V {
  28098. constructor() {
  28099. super(...arguments);
  28100. A(this, "minParams", 1);
  28101. A(this, "maxParams", 255);
  28102. }
  28103. calculate(...e) {
  28104. const t = this.flattenArray(e, !1);
  28105. return t.isError() ? t : t.var();
  28106. }
  28107. }
  28108. const aE = [
  28109. [T_, v.AVEDEV],
  28110. [I_, v.AVERAGE],
  28111. [F_, v.AVERAGE_WEIGHTED],
  28112. [k_, v.AVERAGEA],
  28113. [$_, v.AVERAGEIF],
  28114. [Y_, v.AVERAGEIFS],
  28115. [H_, v.BETA_DIST],
  28116. [Bo, v.BETA_INV],
  28117. [Io, v.BINOM_DIST],
  28118. [G_, v.BINOM_DIST_RANGE],
  28119. [Fo, v.BINOM_INV],
  28120. [Q_, v.CHISQ_DIST],
  28121. [ko, v.CHISQ_DIST_RT],
  28122. [W_, v.CHISQ_INV],
  28123. [$o, v.CHISQ_INV_RT],
  28124. [Yo, v.CHISQ_TEST],
  28125. [Ho, v.CONFIDENCE_NORM],
  28126. [q_, v.CONFIDENCE_T],
  28127. [K_, v.CORREL],
  28128. [X_, v.COUNT],
  28129. [Z_, v.COUNTA],
  28130. [z_, v.COUNTBLANK],
  28131. [J_, v.COUNTIF],
  28132. [eA, v.COUNTIFS],
  28133. [Go, v.COVARIANCE_P],
  28134. [rA, v.COVARIANCE_S],
  28135. [nA, v.DEVSQ],
  28136. [Qo, v.EXPON_DIST],
  28137. [sA, v.F_DIST],
  28138. [Wo, v.F_DIST_RT],
  28139. [aA, v.F_INV],
  28140. [qo, v.F_INV_RT],
  28141. [Ko, v.F_TEST],
  28142. [iA, v.FISHER],
  28143. [oA, v.FISHERINV],
  28144. [Li, v.FORECAST],
  28145. [Li, v.FORECAST_LINEAR],
  28146. [uA, v.FREQUENCY],
  28147. [cA, v.GAMMA],
  28148. [Xo, v.GAMMA_DIST],
  28149. [Zo, v.GAMMA_INV],
  28150. [xi, v.GAMMALN],
  28151. [xi, v.GAMMALN_PRECISE],
  28152. [lA, v.GAUSS],
  28153. [fA, v.GEOMEAN],
  28154. [hA, v.GROWTH],
  28155. [mA, v.HARMEAN],
  28156. [gA, v.HYPGEOM_DIST],
  28157. [dA, v.INTERCEPT],
  28158. [CA, v.KURT],
  28159. [_A, v.LARGE],
  28160. [AA, v.LINEST],
  28161. [EA, v.LOGEST],
  28162. [bA, v.LOGNORM_DIST],
  28163. [zo, v.LOGNORM_INV],
  28164. [yA, v.MARGINOFERROR],
  28165. [RA, v.MAX],
  28166. [pA, v.MAXA],
  28167. [VA, v.MAXIFS],
  28168. [NA, v.MEDIAN],
  28169. [OA, v.MIN],
  28170. [MA, v.MINA],
  28171. [wA, v.MINIFS],
  28172. [DA, v.MODE_MULT],
  28173. [Jo, v.MODE_SNGL],
  28174. [SA, v.NEGBINOM_DIST],
  28175. [eu, v.NORM_DIST],
  28176. [tu, v.NORM_INV],
  28177. [PA, v.NORM_S_DIST],
  28178. [ru, v.NORM_S_INV],
  28179. [LA, v.PEARSON],
  28180. [xA, v.PERCENTILE_EXC],
  28181. [nu, v.PERCENTILE_INC],
  28182. [jA, v.PERCENTRANK_EXC],
  28183. [su, v.PERCENTRANK_INC],
  28184. [UA, v.PERMUT],
  28185. [vA, v.PERMUTATIONA],
  28186. [TA, v.PHI],
  28187. [au, v.POISSON_DIST],
  28188. [BA, v.PROB],
  28189. [IA, v.QUARTILE_EXC],
  28190. [iu, v.QUARTILE_INC],
  28191. [FA, v.RANK_AVG],
  28192. [kA, v.RANK_EQ],
  28193. [$A, v.RSQ],
  28194. [YA, v.SKEW],
  28195. [HA, v.SKEW_P],
  28196. [GA, v.SLOPE],
  28197. [QA, v.SMALL],
  28198. [WA, v.STANDARDIZE],
  28199. [ou, v.STDEV_P],
  28200. [uu, v.STDEV_S],
  28201. [qA, v.STDEVA],
  28202. [KA, v.STDEVPA],
  28203. [XA, v.STEYX],
  28204. [ZA, v.T_DIST],
  28205. [zA, v.T_DIST_2T],
  28206. [JA, v.T_DIST_RT],
  28207. [eE, v.T_INV],
  28208. [cu, v.T_INV_2T],
  28209. [lu, v.T_TEST],
  28210. [tE, v.TREND],
  28211. [rE, v.TRIMMEAN],
  28212. [fu, v.VAR_P],
  28213. [hu, v.VAR_S],
  28214. [nE, v.VARA],
  28215. [sE, v.VARPA],
  28216. [mu, v.WEIBULL_DIST],
  28217. [gu, v.Z_TEST]
  28218. ];
  28219. class iE extends V {
  28220. constructor() {
  28221. super(...arguments);
  28222. A(this, "minParams", 1);
  28223. A(this, "maxParams", 2);
  28224. }
  28225. calculate(e, t) {
  28226. let r = t != null ? t : y.create(0);
  28227. if (t != null && t.isNull() && (r = y.create(0)), r.isArray()) {
  28228. const n = r.mapValue((s) => this._handleSingleObject(e, s));
  28229. return n.getRowCount() === 1 && n.getColumnCount() === 1 ? n.get(0, 0) : n;
  28230. }
  28231. return this._handleSingleObject(e, r);
  28232. }
  28233. _handleSingleObject(e, t) {
  28234. const r = this._checkArray(e);
  28235. if (r.isError())
  28236. return r;
  28237. const { isError: n, errorObject: s, variants: o } = I(t);
  28238. if (n)
  28239. return s;
  28240. const [u] = o, c = +u.getValue(), l = e.isArray() ? e.getRowCount() : 1, f = e.isArray() ? e.getColumnCount() : 1;
  28241. let h = "";
  28242. for (let d = 0; d < l; d++)
  28243. for (let _ = 0; _ < f; _++) {
  28244. const C = e.isArray() ? e.get(d, _) : e;
  28245. let E = `${C.getValue()}`;
  28246. C.isNull() && (E = ""), C.isBoolean() && (E = E.toLocaleUpperCase()), C.isString() && c ? h += `"${E}"` : h += E, d === l - 1 && _ === f - 1 || (c ? _ === f - 1 ? h += ";" : h += "," : h += ", ");
  28247. }
  28248. return c && (h = `{${h}}`), h.length > 32767 ? g.create(m.CALC) : j.create(h);
  28249. }
  28250. _checkArray(e) {
  28251. if (e.isArray()) {
  28252. const t = e.getRowCount(), r = e.getColumnCount();
  28253. return t > 1 || r > 1 ? e : e.get(0, 0);
  28254. }
  28255. return e;
  28256. }
  28257. }
  28258. class oE extends V {
  28259. constructor() {
  28260. super(...arguments);
  28261. A(this, "minParams", 1);
  28262. A(this, "maxParams", 1);
  28263. }
  28264. calculate(e) {
  28265. if (e.isArray()) {
  28266. const t = e.mapValue((r) => this._handleSingleObject(r));
  28267. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28268. }
  28269. return this._handleSingleObject(e);
  28270. }
  28271. _handleSingleObject(e) {
  28272. if (e.isError() || e.isNull() || e.isBoolean() || e.isNumber())
  28273. return e;
  28274. const t = e.getValue().toLocaleString();
  28275. let r = "";
  28276. for (let n = 0; n < t.length; n++) {
  28277. let s = t.charCodeAt(n);
  28278. s === 12288 ? s = 32 : s >= 65281 && s <= 65374 && (s -= 65248), r += String.fromCharCode(s);
  28279. }
  28280. return j.create(r);
  28281. }
  28282. }
  28283. class uE extends V {
  28284. constructor() {
  28285. super(...arguments);
  28286. A(this, "minParams", 1);
  28287. A(this, "maxParams", 1);
  28288. }
  28289. calculate(e) {
  28290. if (e.isArray()) {
  28291. const t = e.mapValue((r) => this._handleSingleObject(r));
  28292. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28293. }
  28294. return this._handleSingleObject(e);
  28295. }
  28296. _handleSingleObject(e) {
  28297. const { isError: t, errorObject: r, variants: n } = I(e);
  28298. if (t)
  28299. return r;
  28300. const [s] = n, o = +s.getValue(), u = Math.abs(Number.parseInt(o.toString(), 10)), c = Number.parseFloat((Math.abs(o) - u).toFixed(2));
  28301. let l = "";
  28302. return u === 0 ? c !== 0 ? l = `${o < 0 ? "ลบ" : ""}${this._convertNumberToThaiText(c * 100)}สตางค์` : l = "ศูนย์บาทถ้วน" : c === 0 ? l = `${o < 0 ? "ลบ" : ""}${this._convertNumberToThaiText(u)}บาทถ้วน` : l = `${o < 0 ? "ลบ" : ""}${this._convertNumberToThaiText(u)}บาท${this._convertNumberToThaiText(c * 100)}สตางค์`, j.create(l);
  28303. }
  28304. _convertNumberToThaiText(e) {
  28305. const t = ["ล้าน", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน", ""], r = ["ศูนย์", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"], n = ["ลบ", "บาท", "ถ้วน", "สตางค์", "ยี่", "เอ็ด", ",", " ", "฿"], s = e.toString(), o = s.length;
  28306. let u = "";
  28307. for (let c = o; c > 0; c--) {
  28308. const l = Number.parseInt(s.charAt(o - c), 10);
  28309. let f = r[l];
  28310. const h = c > 1 ? (c - 1) % 6 : 6;
  28311. if (h === 1 && l === 2 && (f = n[4]), l === 1)
  28312. switch (h) {
  28313. case 0:
  28314. case 6:
  28315. u += c < o ? n[5] : f;
  28316. break;
  28317. case 1:
  28318. break;
  28319. default:
  28320. u += f;
  28321. break;
  28322. }
  28323. else if (l === 0) {
  28324. h === 0 && (u += t[h]);
  28325. continue;
  28326. } else
  28327. u += f;
  28328. u += t[h];
  28329. }
  28330. return u;
  28331. }
  28332. }
  28333. const cE = Object.values(ve).filter((i) => [
  28334. ve.TABLE_START,
  28335. ve.TABLE_ROW_START,
  28336. ve.TABLE_CELL_START,
  28337. ve.TABLE_CELL_END,
  28338. ve.TABLE_ROW_END,
  28339. ve.TABLE_END,
  28340. ve.CUSTOM_BLOCK
  28341. ].includes(i));
  28342. class lE extends V {
  28343. constructor() {
  28344. super(...arguments);
  28345. A(this, "minParams", 1);
  28346. A(this, "maxParams", 1);
  28347. }
  28348. calculate(e) {
  28349. if (e.isArray()) {
  28350. const t = e.mapValue((r) => this._handleSingleObject(r));
  28351. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28352. }
  28353. return this._handleSingleObject(e);
  28354. }
  28355. _handleSingleObject(e) {
  28356. const { isError: t, errorObject: r, variants: n } = I(e);
  28357. if (t)
  28358. return r;
  28359. const [s] = n, o = Math.floor(+s.getValue());
  28360. if (o <= 0)
  28361. return g.create(m.VALUE);
  28362. let u = String.fromCharCode(o);
  28363. return cE.some((c) => c === u) && (u = ""), j.create(u);
  28364. }
  28365. }
  28366. class fE extends V {
  28367. constructor() {
  28368. super(...arguments);
  28369. A(this, "minParams", 1);
  28370. A(this, "maxParams", 1);
  28371. }
  28372. calculate(e) {
  28373. if (e.isArray()) {
  28374. const t = e.mapValue((r) => this._handleSingleObject(r));
  28375. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28376. }
  28377. return this._handleSingleObject(e);
  28378. }
  28379. _handleSingleObject(e) {
  28380. if (e.isError() || e.isBoolean() || e.isNumber())
  28381. return e;
  28382. if (e.isNull())
  28383. return j.create("");
  28384. const r = `${e.getValue()}`.replace(/[\0-\x1F]/g, "");
  28385. return j.create(r);
  28386. }
  28387. }
  28388. class hE extends V {
  28389. constructor() {
  28390. super(...arguments);
  28391. A(this, "minParams", 1);
  28392. A(this, "maxParams", 1);
  28393. }
  28394. calculate(e) {
  28395. if (e.isArray()) {
  28396. const t = e.mapValue((r) => this._handleSingleObject(r));
  28397. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28398. }
  28399. return this._handleSingleObject(e);
  28400. }
  28401. _handleSingleObject(e) {
  28402. if (e.isError())
  28403. return e;
  28404. if (e.isNull())
  28405. return g.create(m.VALUE);
  28406. let t = e.getValue().toLocaleString();
  28407. if (e.isBoolean() && (t = t.toLocaleUpperCase()), t === "")
  28408. return g.create(m.VALUE);
  28409. const r = t.charCodeAt(0);
  28410. return y.create(r);
  28411. }
  28412. }
  28413. class mE extends V {
  28414. constructor() {
  28415. super(...arguments);
  28416. A(this, "minParams", 1);
  28417. A(this, "maxParams", 255);
  28418. }
  28419. calculate(...e) {
  28420. let t = "", r = null;
  28421. for (const n of e)
  28422. if (n.isArray()) {
  28423. if (n.iterator((s) => {
  28424. if (s == null || s.isNull())
  28425. return !0;
  28426. if (s.isError())
  28427. return r = s, !1;
  28428. s.isBoolean() ? t += `${s.getValue()}`.toLocaleUpperCase() : (s.isString() || s.isNumber()) && (t += s.getValue());
  28429. }), r)
  28430. return r;
  28431. } else !n.isError() && !n.isNull() && (t += n.getValue());
  28432. return j.create(t);
  28433. }
  28434. }
  28435. class gE extends V {
  28436. constructor() {
  28437. super(...arguments);
  28438. A(this, "minParams", 1);
  28439. A(this, "maxParams", 255);
  28440. }
  28441. calculate(...e) {
  28442. let t = 0, r = 0;
  28443. e.forEach((s) => {
  28444. if (s.isArray()) {
  28445. const o = s;
  28446. t = Math.max(t, o.getRowCount()), r = Math.max(r, o.getColumnCount());
  28447. } else
  28448. t = Math.max(t, 1), r = Math.max(r, 1);
  28449. });
  28450. let n = null;
  28451. for (const s of e)
  28452. n = O(t, r, s, g.create(m.NA)).mapValue((u, c, l) => {
  28453. const f = n && n.get(c, l);
  28454. if (f != null && f.isError())
  28455. return f;
  28456. if (u.isError())
  28457. return u;
  28458. let h = f == null ? void 0 : f.getValue(), d = u == null ? void 0 : u.getValue();
  28459. f != null && f.isBoolean() && (h = `${h}`.toLocaleUpperCase()), u != null && u.isBoolean() && (d = `${d}`.toLocaleUpperCase());
  28460. const _ = f != null && f.isNull() ? "" : h != null ? h : "", C = u != null && u.isNull() ? "" : d != null ? d : "";
  28461. return j.create(`${_}${C}`);
  28462. });
  28463. return n || g.create(m.VALUE);
  28464. }
  28465. }
  28466. class dE extends V {
  28467. constructor() {
  28468. super(...arguments);
  28469. A(this, "minParams", 1);
  28470. A(this, "maxParams", 1);
  28471. }
  28472. calculate(e) {
  28473. if (e.isArray()) {
  28474. const t = e.mapValue((r) => this._handleSingleObject(r));
  28475. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28476. }
  28477. return this._handleSingleObject(e);
  28478. }
  28479. _handleSingleObject(e) {
  28480. if (e.isError())
  28481. return e;
  28482. if (e.isNull())
  28483. return j.create("");
  28484. let t = `${e.getValue()}`;
  28485. e.isBoolean() && (t = t.toLocaleUpperCase());
  28486. let r = "";
  28487. for (let n = 0; n < t.length; n++) {
  28488. const s = t.charCodeAt(n);
  28489. s >= 33 && s <= 126 ? r += String.fromCharCode(s + 65248) : s === 32 ? r += " " : r += t.charAt(n);
  28490. }
  28491. return j.create(r);
  28492. }
  28493. }
  28494. class CE extends V {
  28495. constructor() {
  28496. super(...arguments);
  28497. A(this, "minParams", 1);
  28498. A(this, "maxParams", 2);
  28499. A(this, "needsLocale", !0);
  28500. }
  28501. calculate(e, t) {
  28502. let r = t != null ? t : y.create(2);
  28503. r.isNull() && (r = y.create(2));
  28504. const n = Math.max(
  28505. e.isArray() ? e.getRowCount() : 1,
  28506. r.isArray() ? r.getRowCount() : 1
  28507. ), s = Math.max(
  28508. e.isArray() ? e.getColumnCount() : 1,
  28509. r.isArray() ? r.getColumnCount() : 1
  28510. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  28511. const d = u.get(f, h);
  28512. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  28513. });
  28514. return n === 1 && s === 1 ? c.get(0, 0) : c;
  28515. }
  28516. _handleSingleObject(e, t) {
  28517. const { isError: r, errorObject: n, variants: s } = I(e, t);
  28518. if (r)
  28519. return n;
  28520. const [o, u] = s;
  28521. let c = +o.getValue(), l = Math.trunc(+u.getValue());
  28522. if (l > 127)
  28523. return g.create(m.VALUE);
  28524. l < 0 && (`${c}`.length < Math.abs(l) ? c = 0 : c = c < 0 ? -vt(Math.abs(c), l) : vt(c, l), l = 0);
  28525. const f = al(this.getLocale(), c, l);
  28526. return j.create(f);
  28527. }
  28528. }
  28529. class _E extends V {
  28530. constructor() {
  28531. super(...arguments);
  28532. A(this, "minParams", 2);
  28533. A(this, "maxParams", 2);
  28534. }
  28535. calculate(e, t) {
  28536. const r = Math.max(
  28537. e.isArray() ? e.getRowCount() : 1,
  28538. t.isArray() ? t.getRowCount() : 1
  28539. ), n = Math.max(
  28540. e.isArray() ? e.getColumnCount() : 1,
  28541. t.isArray() ? t.getColumnCount() : 1
  28542. ), s = O(r, n, e, ie.create()), o = O(r, n, t, ie.create()), u = s.mapValue((c, l, f) => {
  28543. const h = o.get(l, f);
  28544. return c.isError() ? c : h.isError() ? h : this._handleSingleObject(c, h);
  28545. });
  28546. return r === 1 && n === 1 ? u.get(0, 0) : u;
  28547. }
  28548. _handleSingleObject(e, t) {
  28549. if (e.isNull() || t.isNull()) {
  28550. const o = e.isNull() && t.isNull();
  28551. return T.create(o);
  28552. }
  28553. let r = `${e.getValue()}`;
  28554. e.isBoolean() && (r = r.toLocaleUpperCase());
  28555. let n = `${t.getValue()}`;
  28556. t.isBoolean() && (n = n.toLocaleUpperCase());
  28557. const s = r === n;
  28558. return T.create(s);
  28559. }
  28560. }
  28561. const ka = (i, a) => gt.format(i, a, { throws: !1 }), De = (i) => {
  28562. let a = `${i.getValue()}`;
  28563. return i.isNull() && (a = ""), i.isBoolean() && (a = a.toLocaleUpperCase()), i.isNumber() && (i.getPattern() !== "" ? a = ka(i.getPattern(), +i.getValue()) : a = `${_f(+i.getValue())}`), a;
  28564. };
  28565. class AE extends V {
  28566. constructor() {
  28567. super(...arguments);
  28568. A(this, "minParams", 2);
  28569. A(this, "maxParams", 3);
  28570. }
  28571. calculate(e, t, r) {
  28572. const n = r != null ? r : y.create(1), s = Math.max(
  28573. e.isArray() ? e.getRowCount() : 1,
  28574. t.isArray() ? t.getRowCount() : 1,
  28575. n.isArray() ? n.getRowCount() : 1
  28576. ), o = Math.max(
  28577. e.isArray() ? e.getColumnCount() : 1,
  28578. t.isArray() ? t.getColumnCount() : 1,
  28579. n.isArray() ? n.getColumnCount() : 1
  28580. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.mapValue((h, d, _) => {
  28581. const C = c.get(d, _), E = l.get(d, _);
  28582. return h.isError() ? h : C.isError() ? C : E.isError() ? E : this._handleSingleObject(h, C, E);
  28583. });
  28584. return s === 1 && o === 1 ? f.get(0, 0) : f;
  28585. }
  28586. _handleSingleObject(e, t, r) {
  28587. const n = De(e), s = De(t), { isError: o, errorObject: u, variants: c } = I(r);
  28588. if (o)
  28589. return u;
  28590. const [l] = c, f = Math.floor(+l.getValue());
  28591. if (t.isNull() || f <= 0 || f > s.length)
  28592. return g.create(m.VALUE);
  28593. if (e.isNull() || n.length === 0)
  28594. return y.create(f);
  28595. const h = s.indexOf(n, f - 1);
  28596. return h === -1 ? g.create(m.VALUE) : y.create(h + 1);
  28597. }
  28598. }
  28599. function $a(i) {
  28600. let a = 0;
  28601. for (let e = 0; e < i.length; e++)
  28602. a += Qr(i, e);
  28603. return a;
  28604. }
  28605. function Qr(i, a, e = "ltr") {
  28606. return EE(i, a, e) > 255 ? 2 : 1;
  28607. }
  28608. function ji(i) {
  28609. return i >= 55296 && i <= 56319;
  28610. }
  28611. function Ui(i) {
  28612. return i >= 56320 && i <= 57343;
  28613. }
  28614. function vi(i, a) {
  28615. const e = (i & 1023) << 10, t = a & 1023;
  28616. return e + t + 65536;
  28617. }
  28618. function EE(i, a, e = "ltr") {
  28619. const t = i.charCodeAt(a);
  28620. if (e === "ltr" && ji(t) && a + 1 < i.length) {
  28621. const r = i.charCodeAt(a + 1);
  28622. if (Ui(r))
  28623. return vi(t, r);
  28624. }
  28625. if (e === "rtl" && Ui(t) && a - 1 >= 0) {
  28626. const r = i.charCodeAt(a - 1);
  28627. if (ji(r))
  28628. return vi(r, t);
  28629. }
  28630. return t;
  28631. }
  28632. class bE extends V {
  28633. constructor() {
  28634. super(...arguments);
  28635. A(this, "minParams", 2);
  28636. A(this, "maxParams", 3);
  28637. }
  28638. calculate(e, t, r) {
  28639. const n = r != null ? r : y.create(1), s = Math.max(
  28640. e.isArray() ? e.getRowCount() : 1,
  28641. t.isArray() ? t.getRowCount() : 1,
  28642. n.isArray() ? n.getRowCount() : 1
  28643. ), o = Math.max(
  28644. e.isArray() ? e.getColumnCount() : 1,
  28645. t.isArray() ? t.getColumnCount() : 1,
  28646. n.isArray() ? n.getColumnCount() : 1
  28647. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.mapValue((h, d, _) => {
  28648. const C = c.get(d, _), E = l.get(d, _);
  28649. return h.isError() ? h : C.isError() ? C : E.isError() ? E : this._handleSingleObject(h, C, E);
  28650. });
  28651. return s === 1 && o === 1 ? f.get(0, 0) : f;
  28652. }
  28653. _handleSingleObject(e, t, r) {
  28654. const n = De(e), s = De(t), { isError: o, errorObject: u, variants: c } = I(r);
  28655. if (o)
  28656. return u;
  28657. const [l] = c, f = Math.floor(+l.getValue());
  28658. if (t.isNull() || f <= 0 || f > s.length)
  28659. return g.create(m.VALUE);
  28660. if (e.isNull() || n.length === 0)
  28661. return y.create(f);
  28662. const h = s.indexOf(n, f - 1);
  28663. if (h === -1)
  28664. return g.create(m.VALUE);
  28665. const d = $a(s.substring(0, h)) + 1;
  28666. return y.create(d);
  28667. }
  28668. }
  28669. class yE extends V {
  28670. constructor() {
  28671. super(...arguments);
  28672. A(this, "minParams", 1);
  28673. A(this, "maxParams", 3);
  28674. }
  28675. calculate(e, t, r) {
  28676. let n = t != null ? t : y.create(2);
  28677. n.isNull() && (n = y.create(2));
  28678. let s = r != null ? r : T.create(!1);
  28679. s.isNull() && (s = T.create(!1));
  28680. const o = Math.max(
  28681. e.isArray() ? e.getRowCount() : 1,
  28682. n.isArray() ? n.getRowCount() : 1,
  28683. s.isArray() ? s.getRowCount() : 1
  28684. ), u = Math.max(
  28685. e.isArray() ? e.getColumnCount() : 1,
  28686. n.isArray() ? n.getColumnCount() : 1,
  28687. s.isArray() ? s.getColumnCount() : 1
  28688. ), c = O(o, u, e, g.create(m.NA)), l = O(o, u, n, g.create(m.NA)), f = O(o, u, s, g.create(m.NA)), h = c.mapValue((d, _, C) => {
  28689. const E = l.get(_, C), b = f.get(_, C);
  28690. return d.isError() ? d : E.isError() ? E : b.isError() ? b : this._handleSingleObject(d, E, b);
  28691. });
  28692. return o === 1 && u === 1 ? h.get(0, 0) : h;
  28693. }
  28694. _handleSingleObject(e, t, r) {
  28695. const { isError: n, errorObject: s, variants: o } = I(e, t, r);
  28696. if (n)
  28697. return s;
  28698. const [u, c, l] = o;
  28699. let f = +u.getValue(), h = Math.trunc(+c.getValue());
  28700. const d = +l.getValue();
  28701. if (h > 127)
  28702. return g.create(m.VALUE);
  28703. h < 0 && (`${f}`.length < Math.abs(h) ? f = 0 : f = f < 0 ? -vt(Math.abs(f), h) : vt(f, h), h = 0);
  28704. let _ = d ? "###0" : "#,##0";
  28705. h > 0 && (_ += `.${"0".repeat(h)}`);
  28706. const C = ka(_, f);
  28707. return j.create(C);
  28708. }
  28709. }
  28710. class RE extends V {
  28711. constructor() {
  28712. super(...arguments);
  28713. A(this, "minParams", 1);
  28714. A(this, "maxParams", 2);
  28715. }
  28716. calculate(e, t) {
  28717. const r = t != null ? t : y.create(1), n = Math.max(
  28718. e.isArray() ? e.getRowCount() : 1,
  28719. r.isArray() ? r.getRowCount() : 1
  28720. ), s = Math.max(
  28721. e.isArray() ? e.getColumnCount() : 1,
  28722. r.isArray() ? r.getColumnCount() : 1
  28723. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  28724. const d = u.get(f, h);
  28725. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  28726. });
  28727. return n === 1 && s === 1 ? c.get(0, 0) : c;
  28728. }
  28729. _handleSingleObject(e, t) {
  28730. const r = De(e), { isError: n, errorObject: s, variants: o } = I(t);
  28731. if (n)
  28732. return s;
  28733. const [u] = o, c = Math.floor(+u.getValue());
  28734. if (c < 0)
  28735. return g.create(m.VALUE);
  28736. if (e.isNull() || c === 0)
  28737. return j.create("");
  28738. if (c >= r.length)
  28739. return j.create(r);
  28740. const l = r.substring(0, c);
  28741. return j.create(l);
  28742. }
  28743. }
  28744. class pE extends V {
  28745. constructor() {
  28746. super(...arguments);
  28747. A(this, "minParams", 1);
  28748. A(this, "maxParams", 2);
  28749. }
  28750. calculate(e, t) {
  28751. const r = t != null ? t : y.create(1), n = Math.max(
  28752. e.isArray() ? e.getRowCount() : 1,
  28753. r.isArray() ? r.getRowCount() : 1
  28754. ), s = Math.max(
  28755. e.isArray() ? e.getColumnCount() : 1,
  28756. r.isArray() ? r.getColumnCount() : 1
  28757. ), o = O(n, s, e, ie.create()), u = O(n, s, r, ie.create()), c = o.mapValue((l, f, h) => {
  28758. const d = u.get(f, h);
  28759. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  28760. });
  28761. return n === 1 && s === 1 ? c.get(0, 0) : c;
  28762. }
  28763. _handleSingleObject(e, t) {
  28764. const r = De(e), { isError: n, errorObject: s, variants: o } = I(t);
  28765. if (n)
  28766. return s;
  28767. const [u] = o, c = Math.floor(+u.getValue());
  28768. if (c < 0)
  28769. return g.create(m.VALUE);
  28770. if (e.isNull() || c === 0)
  28771. return j.create("");
  28772. let l = 0, f = 0, h = "";
  28773. for (; f < c && l < r.length; )
  28774. f += Qr(r, l), h += r.charAt(l), l++;
  28775. return j.create(h);
  28776. }
  28777. }
  28778. class VE extends V {
  28779. constructor() {
  28780. super(...arguments);
  28781. A(this, "minParams", 1);
  28782. A(this, "maxParams", 1);
  28783. }
  28784. calculate(e) {
  28785. if (e.isArray()) {
  28786. const t = e.mapValue((r) => this._handleSingleText(r));
  28787. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28788. }
  28789. return this._handleSingleText(e);
  28790. }
  28791. _handleSingleText(e) {
  28792. if (e.isError())
  28793. return e;
  28794. const t = De(e);
  28795. return y.create(t.length);
  28796. }
  28797. }
  28798. class NE extends V {
  28799. constructor() {
  28800. super(...arguments);
  28801. A(this, "minParams", 1);
  28802. A(this, "maxParams", 1);
  28803. }
  28804. calculate(e) {
  28805. if (e.isArray()) {
  28806. const t = e.mapValue((r) => this._handleSingleText(r));
  28807. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28808. }
  28809. return this._handleSingleText(e);
  28810. }
  28811. _handleSingleText(e) {
  28812. if (e.isError())
  28813. return e;
  28814. const t = De(e), r = $a(t);
  28815. return y.create(r);
  28816. }
  28817. }
  28818. class OE extends V {
  28819. constructor() {
  28820. super(...arguments);
  28821. A(this, "minParams", 1);
  28822. A(this, "maxParams", 1);
  28823. }
  28824. calculate(e) {
  28825. if (e.isArray()) {
  28826. const t = e.mapValue((r) => this._handleSingleObject(r));
  28827. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28828. }
  28829. return this._handleSingleObject(e);
  28830. }
  28831. _handleSingleObject(e) {
  28832. if (e.isError())
  28833. return e;
  28834. if (e.isNull())
  28835. return j.create("");
  28836. const t = `${e.getValue()}`.toLocaleLowerCase();
  28837. return j.create(t);
  28838. }
  28839. }
  28840. class ME extends V {
  28841. constructor() {
  28842. super(...arguments);
  28843. A(this, "minParams", 3);
  28844. A(this, "maxParams", 3);
  28845. }
  28846. calculate(e, t, r) {
  28847. const n = Math.max(
  28848. e.isArray() ? e.getRowCount() : 1,
  28849. t.isArray() ? t.getRowCount() : 1,
  28850. r.isArray() ? r.getRowCount() : 1
  28851. ), s = Math.max(
  28852. e.isArray() ? e.getColumnCount() : 1,
  28853. t.isArray() ? t.getColumnCount() : 1,
  28854. r.isArray() ? r.getColumnCount() : 1
  28855. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  28856. const _ = u.get(h, d), C = c.get(h, d);
  28857. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSingleObject(f, _, C);
  28858. });
  28859. return n === 1 && s === 1 ? l.get(0, 0) : l;
  28860. }
  28861. _handleSingleObject(e, t, r) {
  28862. const n = De(e), { isError: s, errorObject: o, variants: u } = I(t, r);
  28863. if (s)
  28864. return o;
  28865. const [c, l] = u, f = Math.floor(+c.getValue()), h = Math.floor(+l.getValue());
  28866. if (f <= 0 || h < 0)
  28867. return g.create(m.VALUE);
  28868. if (e.isNull() || f > n.length || h === 0)
  28869. return j.create("");
  28870. const d = n.substring(f - 1, f - 1 + h);
  28871. return j.create(d);
  28872. }
  28873. }
  28874. class wE extends V {
  28875. constructor() {
  28876. super(...arguments);
  28877. A(this, "minParams", 3);
  28878. A(this, "maxParams", 3);
  28879. }
  28880. calculate(e, t, r) {
  28881. const n = Math.max(
  28882. e.isArray() ? e.getRowCount() : 1,
  28883. t.isArray() ? t.getRowCount() : 1,
  28884. r.isArray() ? r.getRowCount() : 1
  28885. ), s = Math.max(
  28886. e.isArray() ? e.getColumnCount() : 1,
  28887. t.isArray() ? t.getColumnCount() : 1,
  28888. r.isArray() ? r.getColumnCount() : 1
  28889. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, t, g.create(m.NA)), c = O(n, s, r, g.create(m.NA)), l = o.mapValue((f, h, d) => {
  28890. const _ = u.get(h, d), C = c.get(h, d);
  28891. return f.isError() ? f : _.isError() ? _ : C.isError() ? C : this._handleSingleObject(f, _, C);
  28892. });
  28893. return n === 1 && s === 1 ? l.get(0, 0) : l;
  28894. }
  28895. _handleSingleObject(e, t, r) {
  28896. let n = De(e);
  28897. const { isError: s, errorObject: o, variants: u } = I(t, r);
  28898. if (s)
  28899. return o;
  28900. const [c, l] = u, f = Math.floor(+c.getValue()), h = Math.floor(+l.getValue());
  28901. if (f <= 0 || h < 0)
  28902. return g.create(m.VALUE);
  28903. if (e.isNull() || f > n.length || h === 0)
  28904. return j.create("");
  28905. n = n.substring(f - 1);
  28906. let d = 0, _ = 0, C = "";
  28907. for (; _ < h && d < n.length; )
  28908. _ += Qr(n, d), C += n.charAt(d), d++;
  28909. return j.create(C);
  28910. }
  28911. }
  28912. class DE extends V {
  28913. constructor() {
  28914. super(...arguments);
  28915. A(this, "minParams", 1);
  28916. A(this, "maxParams", 3);
  28917. }
  28918. calculate(e, t, r) {
  28919. const n = t != null ? t : j.create("."), s = Math.max(
  28920. e.isArray() ? e.getRowCount() : 1,
  28921. n.isArray() ? n.getRowCount() : 1,
  28922. r != null && r.isArray() ? r.getRowCount() : 1
  28923. ), o = Math.max(
  28924. e.isArray() ? e.getColumnCount() : 1,
  28925. n.isArray() ? n.getColumnCount() : 1,
  28926. r != null && r.isArray() ? r.getColumnCount() : 1
  28927. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, n, g.create(m.NA)), l = r ? O(s, o, r, g.create(m.NA)) : void 0, f = u.mapValue((h, d, _) => {
  28928. const C = c.get(d, _), E = r ? l.get(d, _) : void 0;
  28929. return h.isError() ? h : C.isError() ? C : E != null && E.isError() ? E : C.isNull() || E != null && E.isNull() ? g.create(m.VALUE) : h.isNull() ? y.create(0) : this._handleSingleObject(h, C, E);
  28930. });
  28931. return s === 1 && o === 1 ? f.get(0, 0) : f;
  28932. }
  28933. // eslint-disable-next-line
  28934. _handleSingleObject(e, t, r) {
  28935. let n = `${e.getValue()}`;
  28936. n = n.replace(/\s+/g, "");
  28937. let s = `${t.getValue()}`;
  28938. t.isBoolean() && (s = s.toLocaleUpperCase()), s = s.charAt(0);
  28939. let o;
  28940. if (r && (o = `${r.getValue()}`, r.isBoolean() && (o = o.toLocaleUpperCase()), o = o.charAt(0), s === o))
  28941. return g.create(m.VALUE);
  28942. if (n.trim() === "")
  28943. return y.create(0);
  28944. if (!n.match(/^\s*[+-]?\s*(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?[ \t]*/))
  28945. return g.create(m.VALUE);
  28946. const u = n.split(s);
  28947. if (u.length > 2)
  28948. return g.create(m.VALUE);
  28949. let c = u[0].replace(/,/g, "");
  28950. r && (c = c.split(o).join(""));
  28951. let l = 0;
  28952. if (u.length === 1) {
  28953. s === "," && (c = c.replace(/\./g, ""));
  28954. let f = 0;
  28955. for (; c.endsWith("%"); )
  28956. c = c.slice(0, -1), f++;
  28957. f > 0 ? l = +c / 100 ** f : l = +c;
  28958. } else {
  28959. if (!Q(c))
  28960. return g.create(m.VALUE);
  28961. let f = u[1], h = 0;
  28962. for (; f.endsWith("%"); )
  28963. f = f.slice(0, -1), h++;
  28964. const d = `${c}.${f}`;
  28965. if (!Q(d))
  28966. return g.create(m.VALUE);
  28967. h > 0 ? l = +d / 100 ** h : l = +d;
  28968. }
  28969. return Number.isNaN(l) ? g.create(m.VALUE) : y.create(l);
  28970. }
  28971. }
  28972. class SE extends V {
  28973. constructor() {
  28974. super(...arguments);
  28975. A(this, "minParams", 1);
  28976. A(this, "maxParams", 1);
  28977. }
  28978. calculate(e) {
  28979. if (e.isArray()) {
  28980. const t = e.mapValue((r) => this._handleSingleObject(r));
  28981. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  28982. }
  28983. return this._handleSingleObject(e);
  28984. }
  28985. _handleSingleObject(e) {
  28986. if (e.isError() || e.isNull() || e.isBoolean() || e.isNumber())
  28987. return e;
  28988. const r = e.getValue().toLocaleString().toLocaleLowerCase().replace(/(^|\b|\W|\d|_)[a-z]/g, (n) => n.toLocaleUpperCase());
  28989. return j.create(r);
  28990. }
  28991. }
  28992. const Nu = () => [
  28993. {
  28994. type: 4,
  28995. from: 48,
  28996. to: 57
  28997. }
  28998. ], Ou = () => [
  28999. {
  29000. type: 7,
  29001. value: 95
  29002. },
  29003. {
  29004. type: 4,
  29005. from: 97,
  29006. to: 122
  29007. },
  29008. {
  29009. type: 4,
  29010. from: 65,
  29011. to: 90
  29012. },
  29013. {
  29014. type: 4,
  29015. from: 48,
  29016. to: 57
  29017. }
  29018. ], Mu = () => [
  29019. {
  29020. type: 7,
  29021. value: 9
  29022. },
  29023. {
  29024. type: 7,
  29025. value: 10
  29026. },
  29027. {
  29028. type: 7,
  29029. value: 11
  29030. },
  29031. {
  29032. type: 7,
  29033. value: 12
  29034. },
  29035. {
  29036. type: 7,
  29037. value: 13
  29038. },
  29039. {
  29040. type: 7,
  29041. value: 32
  29042. },
  29043. {
  29044. type: 7,
  29045. value: 160
  29046. },
  29047. {
  29048. type: 7,
  29049. value: 5760
  29050. },
  29051. {
  29052. type: 4,
  29053. from: 8192,
  29054. to: 8202
  29055. },
  29056. {
  29057. type: 7,
  29058. value: 8232
  29059. },
  29060. {
  29061. type: 7,
  29062. value: 8233
  29063. },
  29064. {
  29065. type: 7,
  29066. value: 8239
  29067. },
  29068. {
  29069. type: 7,
  29070. value: 8287
  29071. },
  29072. {
  29073. type: 7,
  29074. value: 12288
  29075. },
  29076. {
  29077. type: 7,
  29078. value: 65279
  29079. }
  29080. ], wu = () => ({
  29081. type: 3,
  29082. set: Ou(),
  29083. not: !1
  29084. }), Du = () => ({
  29085. type: 3,
  29086. set: Ou(),
  29087. not: !0
  29088. }), Su = () => ({
  29089. type: 3,
  29090. set: Nu(),
  29091. not: !1
  29092. }), Pu = () => ({
  29093. type: 3,
  29094. set: Nu(),
  29095. not: !0
  29096. }), Lu = () => ({
  29097. type: 3,
  29098. set: Mu(),
  29099. not: !1
  29100. }), xu = () => ({
  29101. type: 3,
  29102. set: Mu(),
  29103. not: !0
  29104. }), PE = () => ({
  29105. type: 3,
  29106. set: [
  29107. {
  29108. type: 7,
  29109. value: 10
  29110. },
  29111. {
  29112. type: 7,
  29113. value: 13
  29114. },
  29115. {
  29116. type: 7,
  29117. value: 8232
  29118. },
  29119. {
  29120. type: 7,
  29121. value: 8233
  29122. }
  29123. ],
  29124. not: !0
  29125. });
  29126. function LE(i) {
  29127. const a = {
  29128. type: 0,
  29129. stack: []
  29130. };
  29131. let e = a, t = a.stack;
  29132. const r = [], n = [];
  29133. let s = 0;
  29134. const o = (f) => {
  29135. throw new SyntaxError(`Invalid regular expression: /${i}/: Nothing to repeat at column ${f - 1}`);
  29136. }, u = jE(i);
  29137. let c = 0, l;
  29138. for (; c < u.length; )
  29139. switch (l = u[c++], l) {
  29140. case "\\":
  29141. if (c === u.length)
  29142. throw new SyntaxError(`Invalid regular expression: /${i}/: \\ at end of pattern`);
  29143. switch (l = u[c++], l) {
  29144. case "b":
  29145. t.push({
  29146. type: 2,
  29147. value: "b"
  29148. });
  29149. break;
  29150. case "B":
  29151. t.push({
  29152. type: 2,
  29153. value: "B"
  29154. });
  29155. break;
  29156. case "w":
  29157. t.push(wu());
  29158. break;
  29159. case "W":
  29160. t.push(Du());
  29161. break;
  29162. case "d":
  29163. t.push(Su());
  29164. break;
  29165. case "D":
  29166. t.push(Pu());
  29167. break;
  29168. case "s":
  29169. t.push(Lu());
  29170. break;
  29171. case "S":
  29172. t.push(xu());
  29173. break;
  29174. default:
  29175. if (/\d/.test(l)) {
  29176. for (; /\d/.test(u[c]) && c < u.length; )
  29177. l += u[c++];
  29178. const f = Number.parseInt(l, 10);
  29179. t.push({
  29180. type: 6,
  29181. value: f
  29182. }), n.push({
  29183. reference: {
  29184. type: 6,
  29185. value: f
  29186. },
  29187. stack: t,
  29188. index: t.length - 1
  29189. });
  29190. } else
  29191. t.push({
  29192. type: 7,
  29193. value: l.charCodeAt(0)
  29194. });
  29195. }
  29196. break;
  29197. case "^":
  29198. t.push({
  29199. type: 2,
  29200. value: "^"
  29201. });
  29202. break;
  29203. case "$":
  29204. t.push({
  29205. type: 2,
  29206. value: "$"
  29207. });
  29208. break;
  29209. case "[": {
  29210. const f = u[c] === "^";
  29211. f && c++;
  29212. const h = xE(u.slice(c), i);
  29213. c += h[1], t.push({
  29214. type: 3,
  29215. set: h[0],
  29216. not: f
  29217. });
  29218. break;
  29219. }
  29220. case ".":
  29221. t.push(PE());
  29222. break;
  29223. case "(": {
  29224. const f = {
  29225. type: 1,
  29226. stack: [],
  29227. remember: !0
  29228. // 默认情况下,捕获组是需要记住(捕获)的
  29229. };
  29230. if (u[c] === "?") {
  29231. const h = u[c + 1];
  29232. if (c += 2, h === "=")
  29233. f.followedBy = !0;
  29234. else if (h === "!")
  29235. f.notFollowedBy = !0;
  29236. else if (h !== ":")
  29237. throw new SyntaxError(`Invalid regular expression: /${i}/: Invalid group, character '${h}' after '?' at column ${c - 1}`);
  29238. f.remember = !1;
  29239. } else
  29240. s += 1;
  29241. t.push(f), r.push(e), e = f, t = f.stack;
  29242. break;
  29243. }
  29244. case ")":
  29245. if (r.length === 0)
  29246. throw new SyntaxError(`Invalid regular expression: /${i}/: Unmatched ) at column ${c - 1}`);
  29247. e = r.pop(), t = e.options ? e.options[e.options.length - 1] : e.stack;
  29248. break;
  29249. case "|": {
  29250. e.options || (e.options = [e.stack], delete e.stack);
  29251. const f = [];
  29252. e.options.push(f), t = f;
  29253. break;
  29254. }
  29255. case "{": {
  29256. const f = /^(\d+)(,(\d+)?)?\}/.exec(u.slice(c));
  29257. if (f) {
  29258. t.length === 0 && o(c);
  29259. const h = Number.parseInt(f[1], 10), d = f[2] ? f[3] ? Number.parseInt(f[3], 10) : 1 / 0 : h;
  29260. c += f[0].length, t.push({
  29261. type: 5,
  29262. min: h,
  29263. max: d,
  29264. value: t.pop()
  29265. });
  29266. } else
  29267. t.push({
  29268. // Assuming 123 is the character code for '{'
  29269. type: 7,
  29270. value: 123
  29271. });
  29272. break;
  29273. }
  29274. case "?":
  29275. t.length === 0 && o(c), t.push({
  29276. type: 5,
  29277. min: 0,
  29278. max: 1,
  29279. value: t.pop()
  29280. });
  29281. break;
  29282. case "+":
  29283. t.length === 0 && o(c), t.push({
  29284. type: 5,
  29285. min: 1,
  29286. max: 1 / 0,
  29287. value: t.pop()
  29288. });
  29289. break;
  29290. case "*":
  29291. t.length === 0 && o(c), t.push({
  29292. type: 5,
  29293. min: 0,
  29294. max: 1 / 0,
  29295. value: t.pop()
  29296. });
  29297. break;
  29298. default:
  29299. t.push({
  29300. type: 7,
  29301. value: l.charCodeAt(0)
  29302. });
  29303. }
  29304. if (r.length > 0)
  29305. throw new SyntaxError(`Invalid regular expression: /${i}/: Unterminated group`);
  29306. return UE(n, s), a;
  29307. }
  29308. function xE(i, a) {
  29309. let e;
  29310. const t = [], r = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
  29311. for (; (e = r.exec(i)) !== null; ) {
  29312. let n = null;
  29313. const [, s, o, u, c, l, f, h, d, _, C] = e;
  29314. if (s || o || u || c || l || f ? n = (() => {
  29315. let E = {
  29316. type: 3,
  29317. set: [],
  29318. not: !1
  29319. };
  29320. return s ? E = wu() : o ? E = Su() : u ? E = Lu() : c ? E = Du() : l ? E = Pu() : f && (E = xu()), E;
  29321. })() : h && C ? n = {
  29322. type: 4,
  29323. from: (d || _).charCodeAt(0),
  29324. to: C.charCodeAt(C.length - 1)
  29325. } : e[16] && (n = {
  29326. type: 7,
  29327. value: e[16].charCodeAt(0)
  29328. }), !n)
  29329. return [t, r.lastIndex];
  29330. t.push(n);
  29331. }
  29332. throw new SyntaxError(`Invalid regular expression: /${a}/: Unterminated character class`);
  29333. }
  29334. function jE(i) {
  29335. return i.replace(
  29336. /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g,
  29337. (a, e, t, r, n, s, o) => {
  29338. if (t)
  29339. return a;
  29340. let u;
  29341. e ? u = 8 : r ? u = Number.parseInt(r, 16) : n ? u = Number.parseInt(n, 16) : s ? u = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?".indexOf(s) : u = {
  29342. 0: 0,
  29343. t: 9,
  29344. n: 10,
  29345. v: 11,
  29346. f: 12,
  29347. r: 13
  29348. }[o];
  29349. const c = String.fromCharCode(u);
  29350. return /[[\]{}^$.|?*+()]/.test(c) ? `\\${c}` : c;
  29351. }
  29352. );
  29353. }
  29354. function UE(i, a) {
  29355. for (const e of i.reverse()) {
  29356. const t = e.reference.value;
  29357. if (a < t) {
  29358. e.reference.type = 7;
  29359. const r = t.toString();
  29360. if (e.reference.value = Number.parseInt(r, 8), !/^[0-7]+$/.test(r)) {
  29361. let n = 0;
  29362. for (; r[n] !== "8" && r[n] !== "9" && n < r.length; )
  29363. n += 1;
  29364. if (n === 0 ? (e.reference.value = r.charCodeAt(0), n += 1) : e.reference.value = Number.parseInt(r.slice(0, n), 8), r.length > n) {
  29365. const s = e.stack.splice(e.index + 1);
  29366. for (const o of r.slice(n))
  29367. e.stack.push({
  29368. type: 7,
  29369. value: o.charCodeAt(0)
  29370. });
  29371. e.stack.push(...s);
  29372. }
  29373. }
  29374. }
  29375. }
  29376. }
  29377. function Ya(i, a) {
  29378. if (!vE(i))
  29379. return {
  29380. isError: !0,
  29381. regExp: null
  29382. };
  29383. try {
  29384. const e = new RegExp(i, a ? "ug" : "u");
  29385. return TE(e) ? {
  29386. isError: !1,
  29387. regExp: e
  29388. } : {
  29389. isError: !0,
  29390. regExp: null
  29391. };
  29392. } catch {
  29393. return {
  29394. isError: !0,
  29395. regExp: null
  29396. };
  29397. }
  29398. }
  29399. function vE(i) {
  29400. return !(/\(\?<=.*?\)/g.test(i) && !/\[.*?(\?<=.*?)\]/g.test(i) || /\(\?<!.*?\)/g.test(i) && !/\[.*?(\?<!.*?)\]/g.test(i));
  29401. }
  29402. function TE(i, a) {
  29403. let t;
  29404. Object.prototype.toString.call(i) === "[object RegExp]" ? t = i.source : i && typeof i != "string" && (t = `${i}`);
  29405. let r;
  29406. try {
  29407. r = LE(t);
  29408. } catch {
  29409. return !1;
  29410. }
  29411. let n = 0;
  29412. const s = (o, u) => {
  29413. let c = u;
  29414. if (o.type === 5 && (c++, n++, c > 1 || n > 25))
  29415. return !1;
  29416. if (o.options) {
  29417. for (const f of o.options)
  29418. if (!s({ stack: f }, c))
  29419. return !1;
  29420. }
  29421. const l = o.stack || o.value && o.value.stack;
  29422. if (!l)
  29423. return !0;
  29424. for (const f of l)
  29425. if (!s(f, c))
  29426. return !1;
  29427. return !0;
  29428. };
  29429. return s(r, 0);
  29430. }
  29431. class BE extends V {
  29432. constructor() {
  29433. super(...arguments);
  29434. A(this, "minParams", 2);
  29435. A(this, "maxParams", 2);
  29436. }
  29437. calculate(e, t) {
  29438. const { isError: r, errorObject: n, variants: s } = Fr(e, t);
  29439. if (r)
  29440. return n;
  29441. const [o, u] = s;
  29442. let c = o.getValue();
  29443. o.isNull() && (c = ""), o.isBoolean() && (c = c ? "TRUE" : "FALSE"), c = `${c}`;
  29444. let l = u.getValue();
  29445. u.isNull() && (l = ""), u.isBoolean() && (l = l ? "TRUE" : "FALSE"), l = `${l}`;
  29446. const { isError: f, regExp: h } = Ya(l, !1);
  29447. if (f)
  29448. return g.create(m.REF);
  29449. const d = c.match(h);
  29450. if (d === null)
  29451. return g.create(m.NA);
  29452. if (d.length > 1) {
  29453. const _ = d.slice(1).map((C) => j.create(C));
  29454. return _.length > 1 ? q.create({
  29455. calculateValueList: [_],
  29456. rowCount: 1,
  29457. columnCount: _.length,
  29458. unitId: this.unitId,
  29459. sheetId: this.subUnitId,
  29460. row: this.row,
  29461. column: this.column
  29462. }) : _[0];
  29463. }
  29464. return j.create(d[0]);
  29465. }
  29466. }
  29467. class IE extends V {
  29468. constructor() {
  29469. super(...arguments);
  29470. A(this, "minParams", 2);
  29471. A(this, "maxParams", 2);
  29472. }
  29473. calculate(e, t) {
  29474. const { isError: r, errorObject: n, variants: s } = Fr(e, t);
  29475. if (r)
  29476. return n;
  29477. const [o, u] = s;
  29478. let c = o.getValue();
  29479. o.isNull() && (c = ""), o.isBoolean() && (c = c ? "TRUE" : "FALSE"), c = `${c}`;
  29480. let l = u.getValue();
  29481. u.isNull() && (l = ""), u.isBoolean() && (l = l ? "TRUE" : "FALSE"), l = `${l}`;
  29482. const { isError: f, regExp: h } = Ya(l, !1);
  29483. return f ? g.create(m.REF) : c.match(h) === null ? T.create(!1) : T.create(!0);
  29484. }
  29485. }
  29486. class FE extends V {
  29487. constructor() {
  29488. super(...arguments);
  29489. A(this, "minParams", 3);
  29490. A(this, "maxParams", 3);
  29491. }
  29492. calculate(e, t, r) {
  29493. const { isError: n, errorObject: s, variants: o } = Fr(e, t, r);
  29494. if (n)
  29495. return s;
  29496. const [u, c, l] = o;
  29497. let f = u.getValue();
  29498. u.isNull() && (f = ""), u.isBoolean() && (f = f ? "TRUE" : "FALSE"), f = `${f}`;
  29499. let h = c.getValue();
  29500. c.isNull() && (h = ""), c.isBoolean() && (h = h ? "TRUE" : "FALSE"), h = `${h}`;
  29501. let d = l.getValue();
  29502. l.isNull() && (d = ""), l.isBoolean() && (d = d ? "TRUE" : "FALSE"), d = `${d}`;
  29503. const { isError: _, regExp: C } = Ya(h, !0);
  29504. if (_)
  29505. return g.create(m.REF);
  29506. const E = f.replace(C, d);
  29507. return j.create(E);
  29508. }
  29509. }
  29510. class kE extends V {
  29511. constructor() {
  29512. super(...arguments);
  29513. A(this, "minParams", 4);
  29514. A(this, "maxParams", 4);
  29515. }
  29516. calculate(e, t, r, n) {
  29517. const s = Math.max(
  29518. e.isArray() ? e.getRowCount() : 1,
  29519. t.isArray() ? t.getRowCount() : 1,
  29520. r.isArray() ? r.getRowCount() : 1,
  29521. n.isArray() ? n.getRowCount() : 1
  29522. ), o = Math.max(
  29523. e.isArray() ? e.getColumnCount() : 1,
  29524. t.isArray() ? t.getColumnCount() : 1,
  29525. r.isArray() ? r.getColumnCount() : 1,
  29526. n.isArray() ? n.getColumnCount() : 1
  29527. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  29528. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  29529. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSingleObject(d, E, b, R);
  29530. });
  29531. return s === 1 && o === 1 ? h.get(0, 0) : h;
  29532. }
  29533. _handleSingleObject(e, t, r, n) {
  29534. const { isError: s, errorObject: o, variants: u } = I(t, r);
  29535. if (s)
  29536. return o;
  29537. const [c, l] = u, f = Math.floor(+c.getValue()), h = Math.floor(+l.getValue());
  29538. if (f <= 0 || h < 0)
  29539. return g.create(m.VALUE);
  29540. const d = De(e), _ = De(n), C = d.substring(0, f - 1) + _ + d.substring(f - 1 + h);
  29541. return j.create(C);
  29542. }
  29543. }
  29544. class $E extends V {
  29545. constructor() {
  29546. super(...arguments);
  29547. A(this, "minParams", 4);
  29548. A(this, "maxParams", 4);
  29549. }
  29550. calculate(e, t, r, n) {
  29551. const s = Math.max(
  29552. e.isArray() ? e.getRowCount() : 1,
  29553. t.isArray() ? t.getRowCount() : 1,
  29554. r.isArray() ? r.getRowCount() : 1,
  29555. n.isArray() ? n.getRowCount() : 1
  29556. ), o = Math.max(
  29557. e.isArray() ? e.getColumnCount() : 1,
  29558. t.isArray() ? t.getColumnCount() : 1,
  29559. r.isArray() ? r.getColumnCount() : 1,
  29560. n.isArray() ? n.getColumnCount() : 1
  29561. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = O(s, o, n, g.create(m.NA)), h = u.mapValue((d, _, C) => {
  29562. const E = c.get(_, C), b = l.get(_, C), R = f.get(_, C);
  29563. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R.isError() ? R : this._handleSingleObject(d, E, b, R);
  29564. });
  29565. return s === 1 && o === 1 ? h.get(0, 0) : h;
  29566. }
  29567. _handleSingleObject(e, t, r, n) {
  29568. const { isError: s, errorObject: o, variants: u } = I(t, r);
  29569. if (s)
  29570. return o;
  29571. const [c, l] = u, f = Math.floor(+c.getValue()), h = Math.floor(+l.getValue());
  29572. if (f <= 0 || h < 0)
  29573. return g.create(m.VALUE);
  29574. let d = De(e);
  29575. const _ = De(n);
  29576. let C = d.substring(0, f - 1);
  29577. d = d.substring(f - 1);
  29578. let E = 0, b = 0;
  29579. for (; b < h && E < d.length; )
  29580. b += Qr(d, E), E++;
  29581. return C += _ + d.substring(E), j.create(C);
  29582. }
  29583. }
  29584. class YE extends V {
  29585. constructor() {
  29586. super(...arguments);
  29587. A(this, "minParams", 2);
  29588. A(this, "maxParams", 2);
  29589. }
  29590. calculate(e, t) {
  29591. if (e.isError())
  29592. return e;
  29593. if (t.isError())
  29594. return t;
  29595. const r = Math.max(
  29596. e.isArray() ? e.getRowCount() : 1,
  29597. t.isArray() ? t.getRowCount() : 1
  29598. ), n = Math.max(
  29599. e.isArray() ? e.getColumnCount() : 1,
  29600. t.isArray() ? t.getColumnCount() : 1
  29601. ), s = O(r, n, e, g.create(m.NA)), o = O(r, n, t, g.create(m.NA)), u = s.map((c, l, f) => {
  29602. let h = o.get(l, f);
  29603. if (c.isError())
  29604. return c;
  29605. let d = c.getValue();
  29606. if (c.isNull() && (d = ""), c.isBoolean() && (d = d ? "TRUE" : "FALSE"), d += "", h.isString() && (h = h.convertToNumberObjectValue()), h.isError())
  29607. return h;
  29608. const _ = 32767, C = Math.floor(+h.getValue());
  29609. if (C < 0 || C > _ / d.length)
  29610. return g.create(m.VALUE);
  29611. const E = d.repeat(C);
  29612. return j.create(E);
  29613. });
  29614. return r === 1 && n === 1 ? u.get(0, 0) : u;
  29615. }
  29616. }
  29617. class HE extends V {
  29618. constructor() {
  29619. super(...arguments);
  29620. A(this, "minParams", 1);
  29621. A(this, "maxParams", 2);
  29622. }
  29623. calculate(e, t) {
  29624. const r = t != null ? t : y.create(1), n = Math.max(
  29625. e.isArray() ? e.getRowCount() : 1,
  29626. r.isArray() ? r.getRowCount() : 1
  29627. ), s = Math.max(
  29628. e.isArray() ? e.getColumnCount() : 1,
  29629. r.isArray() ? r.getColumnCount() : 1
  29630. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  29631. const d = u.get(f, h);
  29632. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  29633. });
  29634. return n === 1 && s === 1 ? c.get(0, 0) : c;
  29635. }
  29636. _handleSingleObject(e, t) {
  29637. const r = De(e), { isError: n, errorObject: s, variants: o } = I(t);
  29638. if (n)
  29639. return s;
  29640. const [u] = o, c = Math.floor(+u.getValue());
  29641. if (c < 0)
  29642. return g.create(m.VALUE);
  29643. if (e.isNull() || c === 0)
  29644. return j.create("");
  29645. if (c >= r.length)
  29646. return j.create(r);
  29647. const l = r.substring(r.length - c);
  29648. return j.create(l);
  29649. }
  29650. }
  29651. class GE extends V {
  29652. constructor() {
  29653. super(...arguments);
  29654. A(this, "minParams", 1);
  29655. A(this, "maxParams", 2);
  29656. }
  29657. calculate(e, t) {
  29658. const r = t != null ? t : y.create(1), n = Math.max(
  29659. e.isArray() ? e.getRowCount() : 1,
  29660. r.isArray() ? r.getRowCount() : 1
  29661. ), s = Math.max(
  29662. e.isArray() ? e.getColumnCount() : 1,
  29663. r.isArray() ? r.getColumnCount() : 1
  29664. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  29665. const d = u.get(f, h);
  29666. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  29667. });
  29668. return n === 1 && s === 1 ? c.get(0, 0) : c;
  29669. }
  29670. _handleSingleObject(e, t) {
  29671. const r = De(e), { isError: n, errorObject: s, variants: o } = I(t);
  29672. if (n)
  29673. return s;
  29674. const [u] = o, c = Math.floor(+u.getValue());
  29675. if (c < 0)
  29676. return g.create(m.VALUE);
  29677. if (e.isNull() || c === 0)
  29678. return j.create("");
  29679. let l = r.length - 1, f = 0, h = "";
  29680. for (; f < c && l >= 0; )
  29681. f += Qr(r, l, "rtl"), h = r.charAt(l) + h, l--;
  29682. return j.create(h);
  29683. }
  29684. }
  29685. class QE extends V {
  29686. constructor() {
  29687. super(...arguments);
  29688. A(this, "minParams", 2);
  29689. A(this, "maxParams", 3);
  29690. }
  29691. calculate(e, t, r) {
  29692. const n = r != null ? r : y.create(1), s = Math.max(
  29693. e.isArray() ? e.getRowCount() : 1,
  29694. t.isArray() ? t.getRowCount() : 1,
  29695. n.isArray() ? n.getRowCount() : 1
  29696. ), o = Math.max(
  29697. e.isArray() ? e.getColumnCount() : 1,
  29698. t.isArray() ? t.getColumnCount() : 1,
  29699. n.isArray() ? n.getColumnCount() : 1
  29700. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.mapValue((h, d, _) => {
  29701. const C = c.get(d, _), E = l.get(d, _);
  29702. return h.isError() ? h : C.isError() ? C : E.isError() ? E : this._handleSingleObject(h, C, E);
  29703. });
  29704. return s === 1 && o === 1 ? f.get(0, 0) : f;
  29705. }
  29706. _handleSingleObject(e, t, r) {
  29707. const n = De(e).toLocaleUpperCase(), s = De(t).toLocaleUpperCase(), { isError: o, errorObject: u, variants: c } = I(r);
  29708. if (o)
  29709. return u;
  29710. const [l] = c, f = Math.floor(+l.getValue());
  29711. if (t.isNull() || f <= 0 || f > s.length)
  29712. return g.create(m.VALUE);
  29713. if (e.isNull() || n.length === 0)
  29714. return y.create(f);
  29715. const h = s.indexOf(n, f - 1);
  29716. return h === -1 ? g.create(m.VALUE) : y.create(h + 1);
  29717. }
  29718. }
  29719. class WE extends V {
  29720. constructor() {
  29721. super(...arguments);
  29722. A(this, "minParams", 2);
  29723. A(this, "maxParams", 3);
  29724. }
  29725. calculate(e, t, r) {
  29726. const n = r != null ? r : y.create(1), s = Math.max(
  29727. e.isArray() ? e.getRowCount() : 1,
  29728. t.isArray() ? t.getRowCount() : 1,
  29729. n.isArray() ? n.getRowCount() : 1
  29730. ), o = Math.max(
  29731. e.isArray() ? e.getColumnCount() : 1,
  29732. t.isArray() ? t.getColumnCount() : 1,
  29733. n.isArray() ? n.getColumnCount() : 1
  29734. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, n, g.create(m.NA)), f = u.mapValue((h, d, _) => {
  29735. const C = c.get(d, _), E = l.get(d, _);
  29736. return h.isError() ? h : C.isError() ? C : E.isError() ? E : this._handleSingleObject(h, C, E);
  29737. });
  29738. return s === 1 && o === 1 ? f.get(0, 0) : f;
  29739. }
  29740. _handleSingleObject(e, t, r) {
  29741. const n = De(e).toLocaleUpperCase(), s = De(t).toLocaleUpperCase(), { isError: o, errorObject: u, variants: c } = I(r);
  29742. if (o)
  29743. return u;
  29744. const [l] = c, f = Math.floor(+l.getValue());
  29745. if (t.isNull() || f <= 0 || f > s.length)
  29746. return g.create(m.VALUE);
  29747. if (e.isNull() || n.length === 0)
  29748. return y.create(f);
  29749. const h = s.indexOf(n, f - 1);
  29750. if (h === -1)
  29751. return g.create(m.VALUE);
  29752. const d = $a(s.substring(0, h)) + 1;
  29753. return y.create(d);
  29754. }
  29755. }
  29756. class qE extends V {
  29757. constructor() {
  29758. super(...arguments);
  29759. A(this, "minParams", 3);
  29760. A(this, "maxParams", 4);
  29761. }
  29762. calculate(e, t, r, n) {
  29763. const s = Math.max(
  29764. e.isArray() ? e.getRowCount() : 1,
  29765. t.isArray() ? t.getRowCount() : 1,
  29766. r.isArray() ? r.getRowCount() : 1,
  29767. n != null && n.isArray() ? n.getRowCount() : 1
  29768. ), o = Math.max(
  29769. e.isArray() ? e.getColumnCount() : 1,
  29770. t.isArray() ? t.getColumnCount() : 1,
  29771. r.isArray() ? r.getColumnCount() : 1,
  29772. n != null && n.isArray() ? n.getColumnCount() : 1
  29773. ), u = O(s, o, e, g.create(m.NA)), c = O(s, o, t, g.create(m.NA)), l = O(s, o, r, g.create(m.NA)), f = n ? O(s, o, n, g.create(m.NA)) : void 0, h = u.mapValue((d, _, C) => {
  29774. const E = c.get(_, C), b = l.get(_, C);
  29775. let R = n ? f.get(_, C) : void 0;
  29776. return d.isError() ? d : E.isError() ? E : b.isError() ? b : R != null && R.isError() ? R : R != null && R.isNull() || R != null && R.isBoolean() ? g.create(m.VALUE) : (R != null && R.isString() && (R = R.convertToNumberObjectValue()), R != null && R.isError() ? R : this._handleSingleObject(d, E, b, R));
  29777. });
  29778. return s === 1 && o === 1 ? h.get(0, 0) : h;
  29779. }
  29780. _handleSingleObject(e, t, r, n) {
  29781. const s = this._getObjectString(e), o = this._getObjectString(t), u = this._getObjectString(r), c = n ? Math.floor(+n.getValue()) : void 0;
  29782. if (n && c <= 0)
  29783. return g.create(m.VALUE);
  29784. if (o === "")
  29785. return j.create(s);
  29786. let l = "", f = 0;
  29787. for (let h = 0; h < s.length; h++) {
  29788. const d = s.substr(h, o.length);
  29789. if (d === o || d.length === o.length && d.trim() === o.trim()) {
  29790. if (f++, f === c) {
  29791. l = s.substr(0, h) + u + s.substr(h + o.length);
  29792. break;
  29793. }
  29794. c === void 0 && (l += u), h += o.length - 1;
  29795. } else
  29796. c === void 0 && (l += s[h]);
  29797. }
  29798. return c && f < c && (l = s), j.create(l);
  29799. }
  29800. _getObjectString(e) {
  29801. let t = `${e.getValue()}`;
  29802. return e.isNull() && (t = ""), e.isBoolean() && (t = t.toLocaleUpperCase()), t;
  29803. }
  29804. }
  29805. class KE extends V {
  29806. constructor() {
  29807. super(...arguments);
  29808. A(this, "minParams", 1);
  29809. A(this, "maxParams", 1);
  29810. }
  29811. calculate(e) {
  29812. let t = e;
  29813. return e.isArray() && (t = e.get(0, 0)), t.isError() ? t : t.isNull() || t.isBoolean() || t.isNumber() ? j.create("") : t;
  29814. }
  29815. }
  29816. class XE extends V {
  29817. constructor() {
  29818. super(...arguments);
  29819. A(this, "minParams", 2);
  29820. A(this, "maxParams", 2);
  29821. }
  29822. calculate(e, t) {
  29823. if (e.isError())
  29824. return e;
  29825. if (t.isError())
  29826. return t;
  29827. const r = Math.max(
  29828. e.isArray() ? e.getRowCount() : 1,
  29829. t.isArray() ? t.getRowCount() : 1
  29830. ), n = Math.max(
  29831. e.isArray() ? e.getColumnCount() : 1,
  29832. t.isArray() ? t.getColumnCount() : 1
  29833. ), s = O(r, n, e), o = O(r, n, t);
  29834. return s.map((u, c, l) => {
  29835. if (u.isError())
  29836. return u;
  29837. let f = o.get(c, l) || j.create(" ");
  29838. if (f.isError())
  29839. return f;
  29840. if (f.isBoolean())
  29841. return g.create(m.VALUE);
  29842. if (u.isBoolean())
  29843. return u;
  29844. let h = u.getValue();
  29845. if (u.isNull() && (h = 0), u.isString()) {
  29846. if (!Q(h))
  29847. return u;
  29848. h = Number(h);
  29849. }
  29850. f.isNull() && (f = j.create(" "));
  29851. const d = `${f.getValue()}`, _ = ka(d, h);
  29852. return j.create(d === " " ? _.trimEnd() : _);
  29853. });
  29854. }
  29855. }
  29856. class ZE extends V {
  29857. constructor() {
  29858. super(...arguments);
  29859. A(this, "minParams", 2);
  29860. A(this, "maxParams", 6);
  29861. }
  29862. calculate(e, t, r, n, s, o) {
  29863. let u = !1, c = r != null ? r : y.create(1);
  29864. c.isNull() && (u = !0, c = y.create(1));
  29865. const l = !n, f = n != null ? n : y.create(0), h = s != null ? s : y.create(0), d = o != null ? o : g.create(m.NA), _ = Math.max(
  29866. e.isArray() ? e.getRowCount() : 1,
  29867. c.isArray() ? c.getRowCount() : 1,
  29868. f.isArray() ? f.getRowCount() : 1,
  29869. h.isArray() ? h.getRowCount() : 1,
  29870. d.isArray() ? d.getRowCount() : 1
  29871. ), C = Math.max(
  29872. e.isArray() ? e.getColumnCount() : 1,
  29873. c.isArray() ? c.getColumnCount() : 1,
  29874. f.isArray() ? f.getColumnCount() : 1,
  29875. h.isArray() ? h.getColumnCount() : 1,
  29876. d.isArray() ? d.getColumnCount() : 1
  29877. ), E = O(_, C, e, g.create(m.NA)), b = O(_, C, c, g.create(m.NA)), R = O(_, C, f, g.create(m.NA)), p = O(_, C, h, g.create(m.NA)), N = O(_, C, d, g.create(m.NA)), M = this._getResultArray(E, t, b, R, p, N, u, l);
  29878. return _ === 1 && C === 1 ? M.get(0, 0) : M;
  29879. }
  29880. _getResultArray(e, t, r, n, s, o, u, c) {
  29881. return e.map((f, h, d) => {
  29882. const _ = r.get(h, d), C = n.get(h, d), E = s.get(h, d), b = o.get(h, d), R = this._checkVariantsError(f, _, C, E);
  29883. if (R.isError())
  29884. return R;
  29885. const p = this._getStringValue(f), N = this._getDelimiterValue(t);
  29886. if (N instanceof g)
  29887. return N;
  29888. const M = this._getVariantsNumberFloorValue(_, C, E);
  29889. if (M instanceof g)
  29890. return M;
  29891. const [w, D, S] = M;
  29892. return w === 0 || D < 0 || D > 1 || S < 0 || S > 1 ? g.create(m.VALUE) : N.includes("") ? w > 0 ? j.create(p) : j.create("") : !u && Math.abs(w) > p.length ? g.create(m.VALUE) : N.every((P) => P.length > p.length) ? g.create(m.NA) : this._getResult(p, N, w, D, S, b, c);
  29893. });
  29894. }
  29895. _checkVariantsError(...e) {
  29896. for (let t = 0; t < e.length; t++) {
  29897. const r = e[t];
  29898. if (r.isError())
  29899. return r;
  29900. }
  29901. return T.create(!0);
  29902. }
  29903. _getStringValue(e) {
  29904. let t = `${e.getValue()}`;
  29905. return e.isNull() && (t = ""), e.isBoolean() && (t = t.toLocaleUpperCase()), t;
  29906. }
  29907. _getDelimiterValue(e) {
  29908. const t = [];
  29909. if (e.isArray()) {
  29910. let r = !1, n = g.create(m.VALUE);
  29911. if (e.iterator((s) => {
  29912. const o = s;
  29913. if (o.isError())
  29914. return r = !0, n = o, !1;
  29915. t.push(this._getStringValue(o));
  29916. }), r)
  29917. return n;
  29918. } else {
  29919. if (e.isError())
  29920. return e;
  29921. t.push(this._getStringValue(e));
  29922. }
  29923. return t;
  29924. }
  29925. _getVariantsNumberFloorValue(...e) {
  29926. const t = [];
  29927. for (let r = 0; r < e.length; r++) {
  29928. let n = e[r];
  29929. if (n.isString() && (n = n.convertToNumberObjectValue()), n.isError())
  29930. return n;
  29931. const s = Math.floor(+n.getValue());
  29932. t.push(s);
  29933. }
  29934. return t;
  29935. }
  29936. _getResult(e, t, r, n, s, o, u) {
  29937. let c = n ? e.toLocaleLowerCase() : e;
  29938. const l = n ? t.map((C) => C.toLocaleLowerCase()) : t;
  29939. let f = 0, h = 0, d = 0;
  29940. for (let C = 0; C < Math.abs(r); C++)
  29941. if (r < 0) {
  29942. const E = l.map((b) => ({
  29943. index: c.lastIndexOf(b),
  29944. length: b.length
  29945. })).filter((b) => b.index !== -1).sort((b, R) => R.index - b.index)[0];
  29946. if (!E)
  29947. break;
  29948. f = E.index, c = c.substr(0, E.index), d = E.length, h++;
  29949. } else {
  29950. const E = l.map((b) => ({
  29951. index: c.indexOf(b),
  29952. length: b.length
  29953. })).filter((b) => b.index !== -1).sort((b, R) => b.index - R.index)[0];
  29954. if (!E)
  29955. break;
  29956. f += E.index + d, c = c.substr(E.index + E.length), d = E.length, h++;
  29957. }
  29958. if (h && h < Math.abs(r) && u)
  29959. return g.create(m.NA);
  29960. if (!h || h < Math.abs(r))
  29961. return s ? r > 0 ? j.create("") : j.create(e) : o;
  29962. const _ = e.substr(f + d);
  29963. return j.create(_);
  29964. }
  29965. }
  29966. class zE extends V {
  29967. constructor() {
  29968. super(...arguments);
  29969. A(this, "minParams", 2);
  29970. A(this, "maxParams", 6);
  29971. }
  29972. calculate(e, t, r, n, s, o) {
  29973. let u = !1, c = r != null ? r : y.create(1);
  29974. c.isNull() && (u = !0, c = y.create(1));
  29975. const l = !n, f = n != null ? n : y.create(0), h = s != null ? s : y.create(0), d = o != null ? o : g.create(m.NA), _ = Math.max(
  29976. e.isArray() ? e.getRowCount() : 1,
  29977. c.isArray() ? c.getRowCount() : 1,
  29978. f.isArray() ? f.getRowCount() : 1,
  29979. h.isArray() ? h.getRowCount() : 1,
  29980. d.isArray() ? d.getRowCount() : 1
  29981. ), C = Math.max(
  29982. e.isArray() ? e.getColumnCount() : 1,
  29983. c.isArray() ? c.getColumnCount() : 1,
  29984. f.isArray() ? f.getColumnCount() : 1,
  29985. h.isArray() ? h.getColumnCount() : 1,
  29986. d.isArray() ? d.getColumnCount() : 1
  29987. ), E = O(_, C, e, g.create(m.NA)), b = O(_, C, c, g.create(m.NA)), R = O(_, C, f, g.create(m.NA)), p = O(_, C, h, g.create(m.NA)), N = O(_, C, d, g.create(m.NA)), M = this._getResultArray(E, t, b, R, p, N, u, l);
  29988. return _ === 1 && C === 1 ? M.get(0, 0) : M;
  29989. }
  29990. _getResultArray(e, t, r, n, s, o, u, c) {
  29991. return e.map((f, h, d) => {
  29992. const _ = r.get(h, d), C = n.get(h, d), E = s.get(h, d), b = o.get(h, d), R = this._checkVariantsError(f, _, C, E);
  29993. if (R.isError())
  29994. return R;
  29995. const p = this._getStringValue(f), N = this._getDelimiterValue(t);
  29996. if (N instanceof g)
  29997. return N;
  29998. const M = this._getVariantsNumberFloorValue(_, C, E);
  29999. if (M instanceof g)
  30000. return M;
  30001. const [w, D, S] = M;
  30002. return w === 0 || D < 0 || D > 1 || S < 0 || S > 1 ? g.create(m.VALUE) : N.includes("") ? w > 0 ? j.create("") : j.create(p) : !u && Math.abs(w) > p.length ? g.create(m.VALUE) : N.every((P) => P.length > p.length) ? g.create(m.NA) : this._getResult(p, N, w, D, S, b, c);
  30003. });
  30004. }
  30005. _checkVariantsError(...e) {
  30006. for (let t = 0; t < e.length; t++) {
  30007. const r = e[t];
  30008. if (r.isError())
  30009. return r;
  30010. }
  30011. return T.create(!0);
  30012. }
  30013. _getStringValue(e) {
  30014. let t = `${e.getValue()}`;
  30015. return e.isNull() && (t = ""), e.isBoolean() && (t = t.toLocaleUpperCase()), t;
  30016. }
  30017. _getDelimiterValue(e) {
  30018. const t = [];
  30019. if (e.isArray()) {
  30020. let r = !1, n = g.create(m.VALUE);
  30021. if (e.iterator((s) => {
  30022. const o = s;
  30023. if (o.isError())
  30024. return r = !0, n = o, !1;
  30025. t.push(this._getStringValue(o));
  30026. }), r)
  30027. return n;
  30028. } else {
  30029. if (e.isError())
  30030. return e;
  30031. t.push(this._getStringValue(e));
  30032. }
  30033. return t;
  30034. }
  30035. _getVariantsNumberFloorValue(...e) {
  30036. const t = [];
  30037. for (let r = 0; r < e.length; r++) {
  30038. let n = e[r];
  30039. if (n.isString() && (n = n.convertToNumberObjectValue()), n.isError())
  30040. return n;
  30041. const s = Math.floor(+n.getValue());
  30042. t.push(s);
  30043. }
  30044. return t;
  30045. }
  30046. _getResult(e, t, r, n, s, o, u) {
  30047. let c = n ? e.toLocaleLowerCase() : e;
  30048. const l = n ? t.map((C) => C.toLocaleLowerCase()) : t;
  30049. let f = 0, h = 0, d = 0;
  30050. for (let C = 0; C < Math.abs(r); C++)
  30051. if (r < 0) {
  30052. const E = l.map((b) => ({
  30053. index: c.lastIndexOf(b),
  30054. length: b.length
  30055. })).filter((b) => b.index !== -1).sort((b, R) => R.index - b.index)[0];
  30056. if (!E)
  30057. break;
  30058. f = E.index, c = c.substr(0, E.index), h++;
  30059. } else {
  30060. const E = l.map((b) => ({
  30061. index: c.indexOf(b),
  30062. length: b.length
  30063. })).filter((b) => b.index !== -1).sort((b, R) => b.index - R.index)[0];
  30064. if (!E)
  30065. break;
  30066. f += E.index + d, c = c.substr(E.index + E.length), d = E.length, h++;
  30067. }
  30068. if (h && h < Math.abs(r) && u)
  30069. return g.create(m.NA);
  30070. if (!h || h < Math.abs(r))
  30071. return s ? r > 0 ? j.create(e) : j.create("") : o;
  30072. const _ = e.substr(0, f);
  30073. return j.create(_);
  30074. }
  30075. }
  30076. class JE extends V {
  30077. constructor() {
  30078. super(...arguments);
  30079. A(this, "minParams", 3);
  30080. A(this, "maxParams", 255);
  30081. }
  30082. calculate(e, t, ...r) {
  30083. const n = this._getDelimiterValues(e), s = this._getTextValues(r);
  30084. if (t.isArray()) {
  30085. const u = t.mapValue((c) => this._handleSingleObject(n, c, s));
  30086. return u.getRowCount() === 1 && u.getColumnCount() === 1 ? u.get(0, 0) : u;
  30087. }
  30088. const o = t;
  30089. if (o.isString()) {
  30090. const u = `${o.getValue()}`.toLocaleUpperCase();
  30091. if (u === "TRUE")
  30092. return this._handleSingleObject(n, T.create(!0), s);
  30093. if (u === "FALSE")
  30094. return this._handleSingleObject(n, T.create(!1), s);
  30095. }
  30096. return this._handleSingleObject(n, t, s);
  30097. }
  30098. _handleSingleObject(e, t, r) {
  30099. if (e instanceof g)
  30100. return e;
  30101. const { isError: n, errorObject: s, variants: o } = I(t);
  30102. if (n)
  30103. return s;
  30104. if (r instanceof g)
  30105. return r;
  30106. const [u] = o, c = +u.getValue();
  30107. let l = r;
  30108. c && (l = r.filter((h) => h !== null));
  30109. let f = "";
  30110. for (let h = 0; h < l.length; h++)
  30111. l[h] !== null && (f += l[h]), h < l.length - 1 && (f += e[h % e.length]);
  30112. return j.create(f);
  30113. }
  30114. _getDelimiterValues(e) {
  30115. const t = [], r = e.isArray() ? e.getRowCount() : 1, n = e.isArray() ? e.getColumnCount() : 1;
  30116. for (let s = 0; s < r; s++)
  30117. for (let o = 0; o < n; o++) {
  30118. const u = e.isArray() ? e.get(s, o) : e;
  30119. if (u.isError())
  30120. return u;
  30121. let c = `${u.getValue()}`;
  30122. u.isNull() && (c = ""), u.isBoolean() && (c = c.toLocaleUpperCase()), t.push(c);
  30123. }
  30124. return t;
  30125. }
  30126. _getTextValues(e) {
  30127. const t = [];
  30128. for (const r of e) {
  30129. const n = r.isArray() ? r.getRowCount() : 1, s = r.isArray() ? r.getColumnCount() : 1;
  30130. for (let o = 0; o < n; o++)
  30131. for (let u = 0; u < s; u++) {
  30132. const c = r.isArray() ? r.get(o, u) : r;
  30133. if (c.isError())
  30134. return c;
  30135. if (c.isNull()) {
  30136. t.push(null);
  30137. continue;
  30138. }
  30139. let l = `${c.getValue()}`;
  30140. c.isBoolean() && (l = l.toLocaleUpperCase()), t.push(l);
  30141. }
  30142. }
  30143. return t;
  30144. }
  30145. }
  30146. class eb extends V {
  30147. constructor() {
  30148. super(...arguments);
  30149. A(this, "minParams", 2);
  30150. A(this, "maxParams", 6);
  30151. }
  30152. calculate(e, t, r, n, s, o) {
  30153. let u = r != null ? r : j.create("\\s");
  30154. const c = n != null ? n : y.create(0), l = s != null ? s : y.create(0), f = o != null ? o : j.create(m.NA), { _variant: h, values: d } = this._getStringValues(t), { _variant: _, values: C } = this._getStringValues(u, !1);
  30155. u = _;
  30156. const E = Math.max(
  30157. e.isArray() ? e.getRowCount() : 1,
  30158. c.isArray() ? c.getRowCount() : 1,
  30159. l.isArray() ? l.getRowCount() : 1
  30160. ), b = Math.max(
  30161. e.isArray() ? e.getColumnCount() : 1,
  30162. c.isArray() ? c.getColumnCount() : 1,
  30163. l.isArray() ? l.getColumnCount() : 1
  30164. ), R = O(E, b, e, g.create(m.NA)), p = O(E, b, c, g.create(m.NA)), N = O(E, b, l, g.create(m.NA)), M = this._getResultArray(
  30165. R,
  30166. h,
  30167. u,
  30168. p,
  30169. N,
  30170. f,
  30171. d,
  30172. C
  30173. );
  30174. return E === 1 && b === 1 ? M.get(0, 0) : M.map((w) => w.get(0, 0));
  30175. }
  30176. _getStringValues(e, t = !0) {
  30177. let r = e;
  30178. const n = [];
  30179. if (r.isArray())
  30180. r.iterator((s) => {
  30181. if (s != null && s.isError())
  30182. return r = s, !1;
  30183. if (s != null && s.isNull() && t)
  30184. return r = g.create(m.VALUE), !1;
  30185. const o = this._getRegExpStringValue(s);
  30186. if (o === "")
  30187. return r = g.create(m.VALUE), !1;
  30188. n.push(o);
  30189. });
  30190. else {
  30191. r.isNull() && t && (r = g.create(m.VALUE));
  30192. const s = this._getRegExpStringValue(r);
  30193. s === "" && (r = g.create(m.VALUE)), n.push(s);
  30194. }
  30195. return {
  30196. _variant: r,
  30197. values: n
  30198. };
  30199. }
  30200. _getResultArray(e, t, r, n, s, o, u, c) {
  30201. return e.map((f, h, d) => {
  30202. let _ = n.get(h, d), C = s.get(h, d);
  30203. const E = this._checkVariantsError(f, t, r, _, C);
  30204. if (E.isError())
  30205. return E;
  30206. if (f.isNull())
  30207. return g.create(m.VALUE);
  30208. let b = o;
  30209. if (b.isArray()) {
  30210. const w = b.getRowCount(), D = b.getColumnCount();
  30211. if (w > 1 || D > 1)
  30212. return g.create(m.VALUE);
  30213. b = b.get(0, 0);
  30214. }
  30215. let R = `${f.getValue()}`;
  30216. if (f.isBoolean() && (R = R.toLocaleUpperCase()), _.isString() && (_ = _.convertToNumberObjectValue(), _.isError()))
  30217. return _;
  30218. const p = Math.floor(+_.getValue());
  30219. if (C.isString() && (C = C.convertToNumberObjectValue(), C.isError()))
  30220. return C;
  30221. const N = Math.floor(+C.getValue());
  30222. if (N < 0 || N > 1)
  30223. return g.create(m.VALUE);
  30224. let M = `${b.getValue()}`;
  30225. return b.isBoolean() && (M = M.toLocaleUpperCase()), this._getResult(R, u, c, p, N, M);
  30226. });
  30227. }
  30228. _getResult(e, t, r, n, s, o) {
  30229. const u = new RegExp(r.join("|"), `g${s ? "i" : ""}`), c = new RegExp(t.join("|"), `g${s ? "i" : ""}`), l = e.split(u);
  30230. let f = 1, h = l.map((d) => {
  30231. let _ = d.split(c);
  30232. return n && (_ = _.filter((C) => C !== "")), f = Math.max(f, _.length), _;
  30233. });
  30234. return h = h.map((d) => {
  30235. let _ = d;
  30236. return _.length < f && (_ = _.concat(new Array(f - _.length).fill(o))), _;
  30237. }), q.createByArray(h);
  30238. }
  30239. _checkVariantsError(...e) {
  30240. for (let t = 0; t < e.length; t++) {
  30241. const r = e[t];
  30242. if (r.isError())
  30243. return r;
  30244. }
  30245. return T.create(!0);
  30246. }
  30247. _getRegExpStringValue(e) {
  30248. let t = e.getValue();
  30249. return e.isNull() && (t = "\\s"), e.isBoolean() && (t = t ? "TRUE" : "FALSE"), t += "", this._escapeRegExp(t);
  30250. }
  30251. _escapeRegExp(e) {
  30252. return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  30253. }
  30254. }
  30255. class tb extends V {
  30256. constructor() {
  30257. super(...arguments);
  30258. A(this, "minParams", 1);
  30259. A(this, "maxParams", 1);
  30260. }
  30261. calculate(e) {
  30262. if (e.isArray()) {
  30263. const t = e.mapValue((r) => this._handleSingleObject(r));
  30264. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30265. }
  30266. return this._handleSingleObject(e);
  30267. }
  30268. _handleSingleObject(e) {
  30269. if (e.isError())
  30270. return e;
  30271. if (e.isNull())
  30272. return j.create("");
  30273. let t = `${e.getValue()}`;
  30274. return e.isBoolean() && (t = t.toLocaleUpperCase()), t = t.trim().replace(/\s+/g, " "), j.create(t);
  30275. }
  30276. }
  30277. const rb = Object.values(ve).filter((i) => [
  30278. ve.TABLE_START,
  30279. ve.TABLE_ROW_START,
  30280. ve.TABLE_CELL_START,
  30281. ve.TABLE_CELL_END,
  30282. ve.TABLE_ROW_END,
  30283. ve.TABLE_END,
  30284. ve.CUSTOM_BLOCK
  30285. ].includes(i));
  30286. class nb extends V {
  30287. constructor() {
  30288. super(...arguments);
  30289. A(this, "minParams", 1);
  30290. A(this, "maxParams", 1);
  30291. }
  30292. calculate(e) {
  30293. if (e.isArray()) {
  30294. const t = e.mapValue((r) => this._handleSingleObject(r));
  30295. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30296. }
  30297. return this._handleSingleObject(e);
  30298. }
  30299. _handleSingleObject(e) {
  30300. const { isError: t, errorObject: r, variants: n } = I(e);
  30301. if (t)
  30302. return r;
  30303. const [s] = n, o = Math.floor(+s.getValue());
  30304. if (o < 1 || o > 1114111)
  30305. return g.create(m.VALUE);
  30306. if (o === 1114111 || o === 1114110)
  30307. return g.create(m.NA);
  30308. let u = String.fromCharCode(o);
  30309. return rb.some((c) => c === u) && (u = ""), j.create(u);
  30310. }
  30311. }
  30312. class sb extends V {
  30313. constructor() {
  30314. super(...arguments);
  30315. A(this, "minParams", 1);
  30316. A(this, "maxParams", 1);
  30317. }
  30318. calculate(e) {
  30319. if (e.isArray()) {
  30320. const t = e.mapValue((r) => this._handleSingleObject(r));
  30321. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30322. }
  30323. return this._handleSingleObject(e);
  30324. }
  30325. _handleSingleObject(e) {
  30326. if (e.isError())
  30327. return e;
  30328. if (e.isNull())
  30329. return g.create(m.VALUE);
  30330. let t = e.getValue().toLocaleString();
  30331. e.isBoolean() && (t = t.toLocaleUpperCase());
  30332. const r = t.charCodeAt(0);
  30333. return y.create(r);
  30334. }
  30335. }
  30336. class ab extends V {
  30337. constructor() {
  30338. super(...arguments);
  30339. A(this, "minParams", 1);
  30340. A(this, "maxParams", 1);
  30341. }
  30342. calculate(e) {
  30343. if (e.isArray()) {
  30344. const t = e.mapValue((r) => this._handleSingleObject(r));
  30345. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30346. }
  30347. return this._handleSingleObject(e);
  30348. }
  30349. _handleSingleObject(e) {
  30350. if (e.isError())
  30351. return e;
  30352. if (e.isNull())
  30353. return j.create("");
  30354. const t = `${e.getValue()}`.toLocaleUpperCase();
  30355. return j.create(t);
  30356. }
  30357. }
  30358. class ib extends V {
  30359. constructor() {
  30360. super(...arguments);
  30361. A(this, "minParams", 1);
  30362. A(this, "maxParams", 1);
  30363. }
  30364. calculate(e) {
  30365. if (e.isArray()) {
  30366. const t = e.mapValue((r) => this._handleSingleObject(r));
  30367. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30368. }
  30369. return this._handleSingleObject(e);
  30370. }
  30371. _handleSingleObject(e) {
  30372. if (e.isError())
  30373. return e;
  30374. if (e.isBoolean())
  30375. return g.create(m.VALUE);
  30376. let t = e;
  30377. if (e.isString() && (t = t.convertToNumberObjectValue(), t.isError()))
  30378. return t;
  30379. const r = +t.getValue();
  30380. return y.create(r);
  30381. }
  30382. }
  30383. class ob extends V {
  30384. constructor() {
  30385. super(...arguments);
  30386. A(this, "minParams", 1);
  30387. A(this, "maxParams", 2);
  30388. }
  30389. calculate(e, t) {
  30390. const r = t != null ? t : y.create(0), n = Math.max(
  30391. e.isArray() ? e.getRowCount() : 1,
  30392. r.isArray() ? r.getRowCount() : 1
  30393. ), s = Math.max(
  30394. e.isArray() ? e.getColumnCount() : 1,
  30395. r.isArray() ? r.getColumnCount() : 1
  30396. ), o = O(n, s, e, g.create(m.NA)), u = O(n, s, r, g.create(m.NA)), c = o.mapValue((l, f, h) => {
  30397. const d = u.get(f, h);
  30398. return l.isError() ? l : d.isError() ? d : this._handleSingleObject(l, d);
  30399. });
  30400. return n === 1 && s === 1 ? c.get(0, 0) : c;
  30401. }
  30402. _handleSingleObject(e, t) {
  30403. const { isError: r, errorObject: n, variants: s } = I(t);
  30404. if (r)
  30405. return n;
  30406. const [o] = s, u = Math.floor(+o.getValue());
  30407. if (u < 0 || u > 1)
  30408. return g.create(m.VALUE);
  30409. if (e.isNull())
  30410. return j.create("");
  30411. if (e.isBoolean())
  30412. return e;
  30413. if (e.isNumber())
  30414. return y.create(e.getValue());
  30415. const c = u ? `"${e.getValue()}"` : `${e.getValue()}`;
  30416. return j.create(c);
  30417. }
  30418. }
  30419. const ub = [
  30420. [oE, se.ASC],
  30421. [iE, se.ARRAYTOTEXT],
  30422. [uE, se.BAHTTEXT],
  30423. [lE, se.CHAR],
  30424. [fE, se.CLEAN],
  30425. [hE, se.CODE],
  30426. [mE, se.CONCAT],
  30427. [gE, se.CONCATENATE],
  30428. [dE, se.DBCS],
  30429. [CE, se.DOLLAR],
  30430. [_E, se.EXACT],
  30431. [AE, se.FIND],
  30432. [bE, se.FINDB],
  30433. [yE, se.FIXED],
  30434. [RE, se.LEFT],
  30435. [pE, se.LEFTB],
  30436. [VE, se.LEN],
  30437. [NE, se.LENB],
  30438. [OE, se.LOWER],
  30439. [ME, se.MID],
  30440. [wE, se.MIDB],
  30441. [DE, se.NUMBERVALUE],
  30442. [BE, se.REGEXEXTRACT],
  30443. [IE, se.REGEXMATCH],
  30444. [FE, se.REGEXREPLACE],
  30445. [SE, se.PROPER],
  30446. [kE, se.REPLACE],
  30447. [$E, se.REPLACEB],
  30448. [YE, se.REPT],
  30449. [HE, se.RIGHT],
  30450. [GE, se.RIGHTB],
  30451. [QE, se.SEARCH],
  30452. [WE, se.SEARCHB],
  30453. [qE, se.SUBSTITUTE],
  30454. [KE, se.T],
  30455. [XE, se.TEXT],
  30456. [ZE, se.TEXTAFTER],
  30457. [zE, se.TEXTBEFORE],
  30458. [JE, se.TEXTJOIN],
  30459. [eb, se.TEXTSPLIT],
  30460. [tb, se.TRIM],
  30461. [nb, se.UNICHAR],
  30462. [sb, se.UNICODE],
  30463. [ab, se.UPPER],
  30464. [ib, se.VALUE],
  30465. [ob, se.VALUETOTEXT]
  30466. ], cb = [];
  30467. var lb = /* @__PURE__ */ ((i) => i)(lb || {});
  30468. class fb extends V {
  30469. constructor() {
  30470. super(...arguments);
  30471. A(this, "minParams", 1);
  30472. A(this, "maxParams", 1);
  30473. }
  30474. calculate(e) {
  30475. if (e.isArray()) {
  30476. const t = e.mapValue((r) => this._handleSingleObject(r));
  30477. return t.getRowCount() === 1 && t.getColumnCount() === 1 ? t.get(0, 0) : t;
  30478. }
  30479. return this._handleSingleObject(e);
  30480. }
  30481. _handleSingleObject(e) {
  30482. if (e.isError())
  30483. return e;
  30484. const t = De(e), r = encodeURIComponent(t).replace(/[!~'()*]/g, (n) => `%${n.charCodeAt(0).toString(16).toLocaleUpperCase()}`);
  30485. return j.create(r);
  30486. }
  30487. }
  30488. var ju = /* @__PURE__ */ ((i) => (i.ENCODEURL = "ENCODEURL", i.FILTERXML = "FILTERXML", i.WEBSERVICE = "WEBSERVICE", i))(ju || {});
  30489. const hb = [
  30490. [fb, ju.ENCODEURL]
  30491. ];
  30492. var mb = Object.defineProperty, gb = Object.getOwnPropertyDescriptor, db = (i, a, e, t) => {
  30493. for (var r = t > 1 ? void 0 : t ? gb(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30494. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30495. return t && r && mb(a, e, r), r;
  30496. }, Zr = (i, a) => (e, t) => a(e, t, i);
  30497. let wn = class extends Me {
  30498. constructor(i, a, e, t) {
  30499. super(), this._commandService = i, this._functionService = a, this._configService = e, this._dataSyncPrimaryController = t, this._initialize();
  30500. }
  30501. _initialize() {
  30502. this._registerCommands(), this._registerFunctions();
  30503. }
  30504. _registerCommands() {
  30505. [
  30506. eo,
  30507. bs,
  30508. Zi,
  30509. zi,
  30510. Ns,
  30511. Ji,
  30512. sa,
  30513. Xi,
  30514. aa,
  30515. ia,
  30516. oa,
  30517. ua,
  30518. jc,
  30519. Uc,
  30520. to,
  30521. bc
  30522. ].forEach((i) => {
  30523. var a;
  30524. this._commandService.registerCommand(i), (a = this._dataSyncPrimaryController) == null || a.registerSyncingMutations(i);
  30525. });
  30526. }
  30527. _registerFunctions() {
  30528. var e;
  30529. const i = this._configService.getConfig(fa), a = [
  30530. ...Yh,
  30531. ...pm,
  30532. ...Vm,
  30533. ...Im,
  30534. ...Rg,
  30535. ...O1,
  30536. ...P0,
  30537. ...td,
  30538. ...yd,
  30539. ...rC,
  30540. ...D_,
  30541. ...v_,
  30542. ...aE,
  30543. ...ub,
  30544. ...cb,
  30545. ...hb
  30546. ].concat((e = i == null ? void 0 : i.function) != null ? e : []).map((t) => {
  30547. const r = t[0], n = t[1];
  30548. return new r(n);
  30549. });
  30550. this._functionService.registerExecutors(...a);
  30551. }
  30552. };
  30553. wn = db([
  30554. Zr(0, br),
  30555. Zr(1, Yt),
  30556. Zr(2, ta),
  30557. Zr(3, qu(Zu))
  30558. ], wn);
  30559. var Cb = Object.defineProperty, _b = Object.getOwnPropertyDescriptor, Ab = (i, a, e, t) => {
  30560. for (var r = t > 1 ? void 0 : t ? _b(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30561. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30562. return t && r && Cb(a, e, r), r;
  30563. }, zr = (i, a) => (e, t) => a(e, t, i);
  30564. let Dn = class extends Me {
  30565. constructor(i, a, e) {
  30566. super(), this._commandService = i, this._dependencyManagerService = a, this._featureCalculationManagerService = e, this._initialize();
  30567. }
  30568. _initialize() {
  30569. this._commandExecutedListener(), this._featureCalculationManagerServiceListener();
  30570. }
  30571. _featureCalculationManagerServiceListener() {
  30572. this.disposeWithMe(
  30573. this._featureCalculationManagerService.onChanged$.subscribe((i) => {
  30574. const { unitId: a, subUnitId: e, featureIds: t } = i;
  30575. this._dependencyManagerService.removeFeatureFormulaDependency(a, e, t);
  30576. })
  30577. );
  30578. }
  30579. _commandExecutedListener() {
  30580. this.disposeWithMe(
  30581. this._commandService.onCommandExecuted((i) => {
  30582. if (i.id === ia.id) {
  30583. const a = i.params;
  30584. if (a == null)
  30585. return;
  30586. const { featureIds: e, unitId: t, subUnitId: r } = a;
  30587. this._dependencyManagerService.removeFeatureFormulaDependency(t, r, e);
  30588. } else if (i.id === aa.id) {
  30589. const a = i.params;
  30590. if (a == null)
  30591. return;
  30592. const { featureId: e, calculationParam: t } = a, { unitId: r, subUnitId: n } = t;
  30593. this._dependencyManagerService.removeFeatureFormulaDependency(r, n, [e]);
  30594. } else if (i.id === ua.id) {
  30595. const a = i.params;
  30596. if (a == null)
  30597. return;
  30598. this._dependencyManagerService.removeOtherFormulaDependency(a.unitId, a.subUnitId, a.formulaIdList);
  30599. } else if (i.id === oa.id) {
  30600. const a = i.params;
  30601. if (a == null)
  30602. return;
  30603. const e = a.formulaMap, t = [];
  30604. Object.keys(e).forEach((r) => {
  30605. t.push(r);
  30606. }), this._dependencyManagerService.removeOtherFormulaDependency(a.unitId, a.subUnitId, t);
  30607. } else if (i.id === eo.id) {
  30608. const a = i.params.formulaData;
  30609. Object.keys(a).forEach((e) => {
  30610. const t = a[e];
  30611. if (t !== void 0) {
  30612. if (t === null) {
  30613. this._dependencyManagerService.clearFormulaDependency(e);
  30614. return;
  30615. }
  30616. Object.keys(t).forEach((r) => {
  30617. const n = t[r];
  30618. if (n !== void 0) {
  30619. if (n === null)
  30620. return this._dependencyManagerService.clearFormulaDependency(e, r), !0;
  30621. new Ce(n).forValue((s, o) => {
  30622. this._dependencyManagerService.removeFormulaDependency(e, r, s, o);
  30623. });
  30624. }
  30625. });
  30626. }
  30627. });
  30628. } else i.id === sa.id && this._handleSetDefinedName(i);
  30629. })
  30630. );
  30631. }
  30632. _handleSetDefinedName(i) {
  30633. const a = i.params;
  30634. if (a == null)
  30635. return;
  30636. const { unitId: e, name: t } = a;
  30637. this._dependencyManagerService.removeFormulaDependencyByDefinedName(e, t);
  30638. }
  30639. };
  30640. Dn = Ab([
  30641. zr(0, br),
  30642. zr(1, jr),
  30643. zr(1, Hn),
  30644. zr(2, jr)
  30645. ], Dn);
  30646. var Eb = Object.defineProperty, bb = Object.getOwnPropertyDescriptor, yb = (i, a, e, t) => {
  30647. for (var r = t > 1 ? void 0 : t ? bb(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30648. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30649. return t && r && Eb(a, e, r), r;
  30650. }, Ti = (i, a) => (e, t) => a(e, t, i);
  30651. let Sn = class extends Me {
  30652. constructor(i, a) {
  30653. super(), this._commandService = i, this._featureCalculationManagerService = a, this._initialize();
  30654. }
  30655. _initialize() {
  30656. this._commandExecutedListener();
  30657. }
  30658. _commandExecutedListener() {
  30659. this.disposeWithMe(
  30660. this._commandService.onCommandExecuted((i) => {
  30661. if (i.id === aa.id) {
  30662. const a = i.params;
  30663. if (a == null)
  30664. return;
  30665. const { featureId: e, calculationParam: t } = a, { unitId: r, subUnitId: n } = t;
  30666. this._featureCalculationManagerService.register(r, n, e, t);
  30667. } else if (i.id === ia.id) {
  30668. const a = i.params;
  30669. if (a == null)
  30670. return;
  30671. const { featureIds: e, unitId: t, subUnitId: r } = a;
  30672. this._featureCalculationManagerService.remove(t, r, e);
  30673. }
  30674. })
  30675. );
  30676. }
  30677. };
  30678. Sn = yb([
  30679. Ti(0, br),
  30680. Ti(1, jr)
  30681. ], Sn);
  30682. var Rb = Object.defineProperty, pb = Object.getOwnPropertyDescriptor, Vb = (i, a, e, t) => {
  30683. for (var r = t > 1 ? void 0 : t ? pb(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30684. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30685. return t && r && Rb(a, e, r), r;
  30686. }, Cs = (i, a) => (e, t) => a(e, t, i);
  30687. let Pn = class extends Me {
  30688. constructor(i, a, e) {
  30689. super(), this._commandService = i, this._otherFormulaManagerService = a, this._dependencyManagerService = e, this._initialize();
  30690. }
  30691. _initialize() {
  30692. this._commandExecutedListener();
  30693. }
  30694. _commandExecutedListener() {
  30695. this.disposeWithMe(
  30696. this._commandService.onCommandExecuted((i) => {
  30697. if (i.id === oa.id) {
  30698. const a = i.params;
  30699. if (a == null)
  30700. return;
  30701. const e = { [a.unitId]: { [a.subUnitId]: a.formulaMap } };
  30702. this._otherFormulaManagerService.batchRegister(e);
  30703. } else if (i.id === ua.id) {
  30704. const a = i.params;
  30705. if (a == null)
  30706. return;
  30707. const e = {};
  30708. a.formulaIdList.forEach((r) => e[r] = !0);
  30709. const t = { [a.unitId]: { [a.subUnitId]: e } };
  30710. this._otherFormulaManagerService.batchRemove(t);
  30711. }
  30712. })
  30713. );
  30714. }
  30715. };
  30716. Pn = Vb([
  30717. Cs(0, br),
  30718. Cs(1, ya),
  30719. Cs(2, Hn)
  30720. ], Pn);
  30721. class Nb extends Me {
  30722. constructor() {
  30723. super(...arguments);
  30724. // 18.5.1.2 table (Table)
  30725. A(this, "_tableMap", /* @__PURE__ */ new Map());
  30726. // 18.5.1.2 table (Table) for I18N
  30727. A(this, "_tableOptionMap", /* @__PURE__ */ new Map());
  30728. }
  30729. dispose() {
  30730. this._tableMap.clear(), this._tableOptionMap.clear();
  30731. }
  30732. remove(e, t) {
  30733. var r;
  30734. (r = this._tableMap.get(e)) == null || r.delete(t);
  30735. }
  30736. getTableMap(e) {
  30737. return this._tableMap.get(e);
  30738. }
  30739. getTableOptionMap() {
  30740. return this._tableOptionMap;
  30741. }
  30742. registerTable(e, t, r) {
  30743. var n;
  30744. this._tableMap.get(e) == null && this._tableMap.set(e, /* @__PURE__ */ new Map()), (n = this._tableMap.get(e)) == null || n.set(t, r);
  30745. }
  30746. registerTableOptionMap(e, t) {
  30747. this._tableOptionMap.set(e, t);
  30748. }
  30749. }
  30750. const Uu = lt("univer.formula.super-table.service");
  30751. var Ob = Object.defineProperty, Mb = Object.getOwnPropertyDescriptor, wb = (i, a, e, t) => {
  30752. for (var r = t > 1 ? void 0 : t ? Mb(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30753. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30754. return t && r && Ob(a, e, r), r;
  30755. }, Bi = (i, a) => (e, t) => a(e, t, i);
  30756. let Ln = class extends Me {
  30757. constructor(i, a) {
  30758. super(), this._commandService = i, this._superTableService = a, this._initialize();
  30759. }
  30760. _initialize() {
  30761. this._commandExecutedListener();
  30762. }
  30763. _commandExecutedListener() {
  30764. this.disposeWithMe(
  30765. this._commandService.onCommandExecuted((i) => {
  30766. if (i.id === sa.id) {
  30767. const a = i.params;
  30768. if (a == null)
  30769. return;
  30770. const { unitId: e, tableName: t, reference: r } = a;
  30771. this._superTableService.registerTable(e, t, r);
  30772. } else if (i.id === Xi.id) {
  30773. const a = i.params;
  30774. if (a == null)
  30775. return;
  30776. const { unitId: e, tableName: t } = a;
  30777. this._superTableService.remove(e, t);
  30778. } else if (i.id === to.id) {
  30779. const a = i.params;
  30780. if (a == null)
  30781. return;
  30782. const { tableOption: e, tableOptionType: t } = a;
  30783. this._superTableService.registerTableOptionMap(e, t);
  30784. }
  30785. })
  30786. );
  30787. }
  30788. };
  30789. Ln = wb([
  30790. Bi(0, br),
  30791. Bi(1, Uu)
  30792. ], Ln);
  30793. class Db extends Me {
  30794. constructor() {
  30795. super(...arguments);
  30796. A(this, "_dirtyConversionMap", /* @__PURE__ */ new Map());
  30797. }
  30798. dispose() {
  30799. this._dirtyConversionMap.clear();
  30800. }
  30801. remove(e) {
  30802. this._dirtyConversionMap.delete(e);
  30803. }
  30804. get(e) {
  30805. return this._dirtyConversionMap.get(e);
  30806. }
  30807. has(e) {
  30808. return this._dirtyConversionMap.has(e);
  30809. }
  30810. register(e, t) {
  30811. this._dirtyConversionMap.set(e, t);
  30812. }
  30813. getDirtyConversionMap() {
  30814. return this._dirtyConversionMap;
  30815. }
  30816. }
  30817. const Sb = lt(
  30818. "univer.formula.active-dirty-manager.service"
  30819. );
  30820. var Pb = Object.defineProperty, Lb = Object.getOwnPropertyDescriptor, xb = (i, a, e, t) => {
  30821. for (var r = t > 1 ? void 0 : t ? Lb(a, e) : a, n = i.length - 1, s; n >= 0; n--)
  30822. (s = i[n]) && (r = (t ? s(a, e, r) : s(r)) || r);
  30823. return t && r && Pb(a, e, r), r;
  30824. }, Ii = (i, a) => (e, t) => a(e, t, i);
  30825. const jb = "UNIVER_ENGINE_FORMULA_PLUGIN";
  30826. var _s;
  30827. let Fi = (_s = class extends Ku {
  30828. constructor(i = ai, a, e) {
  30829. super(), this._config = i, this._injector = a, this._configService = e;
  30830. const { ...t } = Xu(
  30831. {},
  30832. ai,
  30833. this._config
  30834. );
  30835. this._configService.setConfig(fa, t);
  30836. }
  30837. onStarting() {
  30838. this._initialize(), this._initializeWithOverride();
  30839. }
  30840. onReady() {
  30841. var i;
  30842. ts(this._injector, [
  30843. [wn],
  30844. [Ln]
  30845. ]), (i = this._config) != null && i.notExecuteFormula || ts(this._injector, [
  30846. [Pn],
  30847. [Sn],
  30848. [Dn],
  30849. [Nn]
  30850. ]);
  30851. }
  30852. onRendered() {
  30853. var i;
  30854. (i = this._config) != null && i.notExecuteFormula || ts(this._injector, [
  30855. [Gs],
  30856. [Ys]
  30857. ]);
  30858. }
  30859. _initialize() {
  30860. var a;
  30861. const i = [
  30862. // Services
  30863. [Yt, { useClass: vf }],
  30864. [pr, { useClass: Vs }],
  30865. [Sb, { useClass: Db }],
  30866. [Uu, { useClass: Nb }],
  30867. // Models
  30868. [Pr],
  30869. // Engine
  30870. [ca],
  30871. //Controllers
  30872. [wn],
  30873. [Ln]
  30874. ];
  30875. (a = this._config) != null && a.notExecuteFormula || i.push(
  30876. // Services
  30877. [ya, { useClass: Oh }],
  30878. [Nt, { useClass: Is }],
  30879. [Ft, { useClass: ws }],
  30880. [jr, { useClass: Nh }],
  30881. //Controller
  30882. [Nn],
  30883. [Pn],
  30884. [Dn],
  30885. [Sn],
  30886. // Calculation engine
  30887. [Cr],
  30888. [xr],
  30889. [gr],
  30890. // AstNode factory
  30891. [Eo],
  30892. [En],
  30893. [bn],
  30894. [Vo],
  30895. [yn],
  30896. [An],
  30897. [Rn],
  30898. [pn],
  30899. [Vn],
  30900. [No]
  30901. ), i.forEach((e) => this._injector.add(e));
  30902. }
  30903. _initializeWithOverride() {
  30904. var i;
  30905. (i = this._config) != null && i.notExecuteFormula || [
  30906. [Gs, { useClass: Qs }],
  30907. [Hn, { useClass: Vh }],
  30908. [Ys, { useClass: Hs }]
  30909. ].forEach((e) => this._injector.add(e));
  30910. }
  30911. }, A(_s, "pluginName", jb), _s);
  30912. Fi = xb([
  30913. Ii(1, Ve(ki)),
  30914. Ii(2, ta)
  30915. ], Fi);
  30916. export {
  30917. Db as ActiveDirtyManagerService,
  30918. q as ArrayValueObject,
  30919. Eo as AstRootNodeFactory,
  30920. xr as AstTreeBuilder,
  30921. Of as AsyncArrayObject,
  30922. Qb as AsyncCustomFunction,
  30923. Nf as AsyncObject,
  30924. V as BaseFunction,
  30925. kn as BaseReferenceObject,
  30926. kt as BaseValueObject,
  30927. er as BooleanValue,
  30928. T as BooleanValueObject,
  30929. Nn as CalculateController,
  30930. Qs as CalculateFormulaService,
  30931. Om as CustomFunction,
  30932. Uh as DEFAULT_INTERVAL_COUNT,
  30933. Vs as DefinedNamesService,
  30934. ph as DependencyManagerBaseService,
  30935. Vh as DependencyManagerService,
  30936. Hb as ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,
  30937. fa as ENGINE_FORMULA_PLUGIN_CONFIG_KEY,
  30938. yr as ERROR_TYPE_SET,
  30939. m as ErrorType,
  30940. g as ErrorValueObject,
  30941. Ws as FUNCTION_NAMES_ARRAY,
  30942. le as FUNCTION_NAMES_COMPATIBILITY,
  30943. Nm as FUNCTION_NAMES_CUBE,
  30944. Qe as FUNCTION_NAMES_DATABASE,
  30945. be as FUNCTION_NAMES_DATE,
  30946. Z as FUNCTION_NAMES_ENGINEERING,
  30947. ee as FUNCTION_NAMES_FINANCIAL,
  30948. Ne as FUNCTION_NAMES_INFORMATION,
  30949. Se as FUNCTION_NAMES_LOGICAL,
  30950. me as FUNCTION_NAMES_LOOKUP,
  30951. Y as FUNCTION_NAMES_MATH,
  30952. v as FUNCTION_NAMES_STATISTICAL,
  30953. se as FUNCTION_NAMES_TEXT,
  30954. lb as FUNCTION_NAMES_UNIVER,
  30955. ju as FUNCTION_NAMES_WEB,
  30956. Nh as FeatureCalculationManagerService,
  30957. ws as FormulaCurrentConfigService,
  30958. Pr as FormulaDataModel,
  30959. Hs as FormulaDependencyGenerator,
  30960. hs as FormulaDependencyTree,
  30961. $s as FormulaDependencyTreeType,
  30962. Vi as FormulaDependencyTreeVirtual,
  30963. ft as FormulaExecuteStageType,
  30964. wr as FormulaExecutedStateType,
  30965. Is as FormulaRuntimeService,
  30966. En as FunctionNodeFactory,
  30967. vf as FunctionService,
  30968. Ju as FunctionType,
  30969. Sb as IActiveDirtyManagerService,
  30970. Gs as ICalculateFormulaService,
  30971. pr as IDefinedNamesService,
  30972. Hn as IDependencyManagerService,
  30973. jr as IFeatureCalculationManagerService,
  30974. Ft as IFormulaCurrentConfigService,
  30975. Ys as IFormulaDependencyGenerator,
  30976. Nt as IFormulaRuntimeService,
  30977. Yt as IFunctionService,
  30978. ya as IOtherFormulaManagerService,
  30979. Uu as ISuperTableService,
  30980. Cr as Interpreter,
  30981. bn as LambdaNodeFactory,
  30982. Vo as LambdaParameterNodeFactory,
  30983. ba as LambdaValueObjectObject,
  30984. gr as Lexer,
  30985. ae as LexerNode,
  30986. ca as LexerTreeBuilder,
  30987. ie as NullValueObject,
  30988. y as NumberValueObject,
  30989. yn as OperatorNodeFactory,
  30990. Oh as OtherFormulaManagerService,
  30991. An as PrefixNodeFactory,
  30992. Cn as RangeReferenceObject,
  30993. Rn as ReferenceNodeFactory,
  30994. bc as RegisterFunctionMutation,
  30995. Xi as RemoveDefinedNameMutation,
  30996. ia as RemoveFeatureCalculationMutation,
  30997. ua as RemoveOtherFormulaMutation,
  30998. Uc as RemoveSuperTableMutation,
  30999. bs as SetArrayFormulaDataMutation,
  31000. sa as SetDefinedNameMutation,
  31001. Yb as SetDefinedNameMutationFactory,
  31002. aa as SetFeatureCalculationMutation,
  31003. Ns as SetFormulaCalculationNotificationMutation,
  31004. Ji as SetFormulaCalculationResultMutation,
  31005. Zi as SetFormulaCalculationStartMutation,
  31006. zi as SetFormulaCalculationStopMutation,
  31007. eo as SetFormulaDataMutation,
  31008. oa as SetOtherFormulaMutation,
  31009. jc as SetSuperTableMutation,
  31010. to as SetSuperTableOptionMutation,
  31011. j as StringValueObject,
  31012. pn as SuffixNodeFactory,
  31013. Nb as SuperTableService,
  31014. Vn as UnionNodeFactory,
  31015. Fi as UniverFormulaEnginePlugin,
  31016. No as ValueNodeFactory,
  31017. pt as ValueObjectFactory,
  31018. $ as compareToken,
  31019. oc as convertUnitDataToRuntime,
  31020. Ih as deserializeRangeForR1C1,
  31021. fn as deserializeRangeWithSheet,
  31022. mr as deserializeRangeWithSheetWithCache,
  31023. Yh as functionArray,
  31024. pm as functionCompatibility,
  31025. Vm as functionCube,
  31026. Im as functionDatabase,
  31027. Rg as functionDate,
  31028. O1 as functionEngineering,
  31029. P0 as functionFinancial,
  31030. td as functionInformation,
  31031. yd as functionLogical,
  31032. rC as functionLookup,
  31033. D_ as functionMath,
  31034. v_ as functionMeta,
  31035. aE as functionStatistical,
  31036. ub as functionText,
  31037. cb as functionUniver,
  31038. hb as functionWeb,
  31039. pi as generateAstNode,
  31040. or as generateRandomDependencyTreeId,
  31041. ri as generateStringWithSequence,
  31042. kb as getAbsoluteRefTypeWitString,
  31043. tn as getAbsoluteRefTypeWithSingleString,
  31044. $b as getRangeWithRefsString,
  31045. Gb as handleNumfmtInCell,
  31046. na as handleRefStringInfo,
  31047. rc as includeFormulaLexerToken,
  31048. si as initSheetFormulaData,
  31049. en as isFormulaLexerToken,
  31050. zu as isInDirtyRange,
  31051. Ec as isReferenceString,
  31052. rn as isReferenceStringWithEffectiveColumn,
  31053. Oc as isReferenceStrings,
  31054. Fb as matchRefDrawToken,
  31055. K as matchToken,
  31056. Ib as normalizeSheetName,
  31057. X as operatorToken,
  31058. $e as sequenceNodeType,
  31059. fr as serializeRange,
  31060. ys as serializeRangeToRefString,
  31061. pc as serializeRangeWithSheet,
  31062. Vc as serializeRangeWithSpreadsheet,
  31063. ns as singleReferenceToGrid,
  31064. Ci as strip,
  31065. _f as stripErrorMargin
  31066. };