rxjs.umd.js 278 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843
  1. /**
  2. @license
  3. Apache License
  4. Version 2.0, January 2004
  5. http://www.apache.org/licenses/
  6. TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
  7. 1. Definitions.
  8. "License" shall mean the terms and conditions for use, reproduction,
  9. and distribution as defined by Sections 1 through 9 of this document.
  10. "Licensor" shall mean the copyright owner or entity authorized by
  11. the copyright owner that is granting the License.
  12. "Legal Entity" shall mean the union of the acting entity and all
  13. other entities that control, are controlled by, or are under common
  14. control with that entity. For the purposes of this definition,
  15. "control" means (i) the power, direct or indirect, to cause the
  16. direction or management of such entity, whether by contract or
  17. otherwise, or (ii) ownership of fifty percent (50%) or more of the
  18. outstanding shares, or (iii) beneficial ownership of such entity.
  19. "You" (or "Your") shall mean an individual or Legal Entity
  20. exercising permissions granted by this License.
  21. "Source" form shall mean the preferred form for making modifications,
  22. including but not limited to software source code, documentation
  23. source, and configuration files.
  24. "Object" form shall mean any form resulting from mechanical
  25. transformation or translation of a Source form, including but
  26. not limited to compiled object code, generated documentation,
  27. and conversions to other media types.
  28. "Work" shall mean the work of authorship, whether in Source or
  29. Object form, made available under the License, as indicated by a
  30. copyright notice that is included in or attached to the work
  31. (an example is provided in the Appendix below).
  32. "Derivative Works" shall mean any work, whether in Source or Object
  33. form, that is based on (or derived from) the Work and for which the
  34. editorial revisions, annotations, elaborations, or other modifications
  35. represent, as a whole, an original work of authorship. For the purposes
  36. of this License, Derivative Works shall not include works that remain
  37. separable from, or merely link (or bind by name) to the interfaces of,
  38. the Work and Derivative Works thereof.
  39. "Contribution" shall mean any work of authorship, including
  40. the original version of the Work and any modifications or additions
  41. to that Work or Derivative Works thereof, that is intentionally
  42. submitted to Licensor for inclusion in the Work by the copyright owner
  43. or by an individual or Legal Entity authorized to submit on behalf of
  44. the copyright owner. For the purposes of this definition, "submitted"
  45. means any form of electronic, verbal, or written communication sent
  46. to the Licensor or its representatives, including but not limited to
  47. communication on electronic mailing lists, source code control systems,
  48. and issue tracking systems that are managed by, or on behalf of, the
  49. Licensor for the purpose of discussing and improving the Work, but
  50. excluding communication that is conspicuously marked or otherwise
  51. designated in writing by the copyright owner as "Not a Contribution."
  52. "Contributor" shall mean Licensor and any individual or Legal Entity
  53. on behalf of whom a Contribution has been received by Licensor and
  54. subsequently incorporated within the Work.
  55. 2. Grant of Copyright License. Subject to the terms and conditions of
  56. this License, each Contributor hereby grants to You a perpetual,
  57. worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  58. copyright license to reproduce, prepare Derivative Works of,
  59. publicly display, publicly perform, sublicense, and distribute the
  60. Work and such Derivative Works in Source or Object form.
  61. 3. Grant of Patent License. Subject to the terms and conditions of
  62. this License, each Contributor hereby grants to You a perpetual,
  63. worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  64. (except as stated in this section) patent license to make, have made,
  65. use, offer to sell, sell, import, and otherwise transfer the Work,
  66. where such license applies only to those patent claims licensable
  67. by such Contributor that are necessarily infringed by their
  68. Contribution(s) alone or by combination of their Contribution(s)
  69. with the Work to which such Contribution(s) was submitted. If You
  70. institute patent litigation against any entity (including a
  71. cross-claim or counterclaim in a lawsuit) alleging that the Work
  72. or a Contribution incorporated within the Work constitutes direct
  73. or contributory patent infringement, then any patent licenses
  74. granted to You under this License for that Work shall terminate
  75. as of the date such litigation is filed.
  76. 4. Redistribution. You may reproduce and distribute copies of the
  77. Work or Derivative Works thereof in any medium, with or without
  78. modifications, and in Source or Object form, provided that You
  79. meet the following conditions:
  80. (a) You must give any other recipients of the Work or
  81. Derivative Works a copy of this License; and
  82. (b) You must cause any modified files to carry prominent notices
  83. stating that You changed the files; and
  84. (c) You must retain, in the Source form of any Derivative Works
  85. that You distribute, all copyright, patent, trademark, and
  86. attribution notices from the Source form of the Work,
  87. excluding those notices that do not pertain to any part of
  88. the Derivative Works; and
  89. (d) If the Work includes a "NOTICE" text file as part of its
  90. distribution, then any Derivative Works that You distribute must
  91. include a readable copy of the attribution notices contained
  92. within such NOTICE file, excluding those notices that do not
  93. pertain to any part of the Derivative Works, in at least one
  94. of the following places: within a NOTICE text file distributed
  95. as part of the Derivative Works; within the Source form or
  96. documentation, if provided along with the Derivative Works; or,
  97. within a display generated by the Derivative Works, if and
  98. wherever such third-party notices normally appear. The contents
  99. of the NOTICE file are for informational purposes only and
  100. do not modify the License. You may add Your own attribution
  101. notices within Derivative Works that You distribute, alongside
  102. or as an addendum to the NOTICE text from the Work, provided
  103. that such additional attribution notices cannot be construed
  104. as modifying the License.
  105. You may add Your own copyright statement to Your modifications and
  106. may provide additional or different license terms and conditions
  107. for use, reproduction, or distribution of Your modifications, or
  108. for any such Derivative Works as a whole, provided Your use,
  109. reproduction, and distribution of the Work otherwise complies with
  110. the conditions stated in this License.
  111. 5. Submission of Contributions. Unless You explicitly state otherwise,
  112. any Contribution intentionally submitted for inclusion in the Work
  113. by You to the Licensor shall be under the terms and conditions of
  114. this License, without any additional terms or conditions.
  115. Notwithstanding the above, nothing herein shall supersede or modify
  116. the terms of any separate license agreement you may have executed
  117. with Licensor regarding such Contributions.
  118. 6. Trademarks. This License does not grant permission to use the trade
  119. names, trademarks, service marks, or product names of the Licensor,
  120. except as required for reasonable and customary use in describing the
  121. origin of the Work and reproducing the content of the NOTICE file.
  122. 7. Disclaimer of Warranty. Unless required by applicable law or
  123. agreed to in writing, Licensor provides the Work (and each
  124. Contributor provides its Contributions) on an "AS IS" BASIS,
  125. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  126. implied, including, without limitation, any warranties or conditions
  127. of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
  128. PARTICULAR PURPOSE. You are solely responsible for determining the
  129. appropriateness of using or redistributing the Work and assume any
  130. risks associated with Your exercise of permissions under this License.
  131. 8. Limitation of Liability. In no event and under no legal theory,
  132. whether in tort (including negligence), contract, or otherwise,
  133. unless required by applicable law (such as deliberate and grossly
  134. negligent acts) or agreed to in writing, shall any Contributor be
  135. liable to You for damages, including any direct, indirect, special,
  136. incidental, or consequential damages of any character arising as a
  137. result of this License or out of the use or inability to use the
  138. Work (including but not limited to damages for loss of goodwill,
  139. work stoppage, computer failure or malfunction, or any and all
  140. other commercial damages or losses), even if such Contributor
  141. has been advised of the possibility of such damages.
  142. 9. Accepting Warranty or Additional Liability. While redistributing
  143. the Work or Derivative Works thereof, You may choose to offer,
  144. and charge a fee for, acceptance of support, warranty, indemnity,
  145. or other liability obligations and/or rights consistent with this
  146. License. However, in accepting such obligations, You may act only
  147. on Your own behalf and on Your sole responsibility, not on behalf
  148. of any other Contributor, and only if You agree to indemnify,
  149. defend, and hold each Contributor harmless for any liability
  150. incurred by, or claims asserted against, such Contributor by reason
  151. of your accepting any such warranty or additional liability.
  152. END OF TERMS AND CONDITIONS
  153. APPENDIX: How to apply the Apache License to your work.
  154. To apply the Apache License to your work, attach the following
  155. boilerplate notice, with the fields enclosed by brackets "[]"
  156. replaced with your own identifying information. (Don't include
  157. the brackets!) The text should be enclosed in the appropriate
  158. comment syntax for the file format. We also recommend that a
  159. file or class name and description of purpose be included on the
  160. same "printed page" as the copyright notice for easier
  161. identification within third-party archives.
  162. Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
  163. Licensed under the Apache License, Version 2.0 (the "License");
  164. you may not use this file except in compliance with the License.
  165. You may obtain a copy of the License at
  166. http://www.apache.org/licenses/LICENSE-2.0
  167. Unless required by applicable law or agreed to in writing, software
  168. distributed under the License is distributed on an "AS IS" BASIS,
  169. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  170. See the License for the specific language governing permissions and
  171. limitations under the License.
  172. **/
  173. /**
  174. @license
  175. Apache License
  176. Version 2.0, January 2004
  177. http://www.apache.org/licenses/
  178. TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
  179. 1. Definitions.
  180. "License" shall mean the terms and conditions for use, reproduction,
  181. and distribution as defined by Sections 1 through 9 of this document.
  182. "Licensor" shall mean the copyright owner or entity authorized by
  183. the copyright owner that is granting the License.
  184. "Legal Entity" shall mean the union of the acting entity and all
  185. other entities that control, are controlled by, or are under common
  186. control with that entity. For the purposes of this definition,
  187. "control" means (i) the power, direct or indirect, to cause the
  188. direction or management of such entity, whether by contract or
  189. otherwise, or (ii) ownership of fifty percent (50%) or more of the
  190. outstanding shares, or (iii) beneficial ownership of such entity.
  191. "You" (or "Your") shall mean an individual or Legal Entity
  192. exercising permissions granted by this License.
  193. "Source" form shall mean the preferred form for making modifications,
  194. including but not limited to software source code, documentation
  195. source, and configuration files.
  196. "Object" form shall mean any form resulting from mechanical
  197. transformation or translation of a Source form, including but
  198. not limited to compiled object code, generated documentation,
  199. and conversions to other media types.
  200. "Work" shall mean the work of authorship, whether in Source or
  201. Object form, made available under the License, as indicated by a
  202. copyright notice that is included in or attached to the work
  203. (an example is provided in the Appendix below).
  204. "Derivative Works" shall mean any work, whether in Source or Object
  205. form, that is based on (or derived from) the Work and for which the
  206. editorial revisions, annotations, elaborations, or other modifications
  207. represent, as a whole, an original work of authorship. For the purposes
  208. of this License, Derivative Works shall not include works that remain
  209. separable from, or merely link (or bind by name) to the interfaces of,
  210. the Work and Derivative Works thereof.
  211. "Contribution" shall mean any work of authorship, including
  212. the original version of the Work and any modifications or additions
  213. to that Work or Derivative Works thereof, that is intentionally
  214. submitted to Licensor for inclusion in the Work by the copyright owner
  215. or by an individual or Legal Entity authorized to submit on behalf of
  216. the copyright owner. For the purposes of this definition, "submitted"
  217. means any form of electronic, verbal, or written communication sent
  218. to the Licensor or its representatives, including but not limited to
  219. communication on electronic mailing lists, source code control systems,
  220. and issue tracking systems that are managed by, or on behalf of, the
  221. Licensor for the purpose of discussing and improving the Work, but
  222. excluding communication that is conspicuously marked or otherwise
  223. designated in writing by the copyright owner as "Not a Contribution."
  224. "Contributor" shall mean Licensor and any individual or Legal Entity
  225. on behalf of whom a Contribution has been received by Licensor and
  226. subsequently incorporated within the Work.
  227. 2. Grant of Copyright License. Subject to the terms and conditions of
  228. this License, each Contributor hereby grants to You a perpetual,
  229. worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  230. copyright license to reproduce, prepare Derivative Works of,
  231. publicly display, publicly perform, sublicense, and distribute the
  232. Work and such Derivative Works in Source or Object form.
  233. 3. Grant of Patent License. Subject to the terms and conditions of
  234. this License, each Contributor hereby grants to You a perpetual,
  235. worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  236. (except as stated in this section) patent license to make, have made,
  237. use, offer to sell, sell, import, and otherwise transfer the Work,
  238. where such license applies only to those patent claims licensable
  239. by such Contributor that are necessarily infringed by their
  240. Contribution(s) alone or by combination of their Contribution(s)
  241. with the Work to which such Contribution(s) was submitted. If You
  242. institute patent litigation against any entity (including a
  243. cross-claim or counterclaim in a lawsuit) alleging that the Work
  244. or a Contribution incorporated within the Work constitutes direct
  245. or contributory patent infringement, then any patent licenses
  246. granted to You under this License for that Work shall terminate
  247. as of the date such litigation is filed.
  248. 4. Redistribution. You may reproduce and distribute copies of the
  249. Work or Derivative Works thereof in any medium, with or without
  250. modifications, and in Source or Object form, provided that You
  251. meet the following conditions:
  252. (a) You must give any other recipients of the Work or
  253. Derivative Works a copy of this License; and
  254. (b) You must cause any modified files to carry prominent notices
  255. stating that You changed the files; and
  256. (c) You must retain, in the Source form of any Derivative Works
  257. that You distribute, all copyright, patent, trademark, and
  258. attribution notices from the Source form of the Work,
  259. excluding those notices that do not pertain to any part of
  260. the Derivative Works; and
  261. (d) If the Work includes a "NOTICE" text file as part of its
  262. distribution, then any Derivative Works that You distribute must
  263. include a readable copy of the attribution notices contained
  264. within such NOTICE file, excluding those notices that do not
  265. pertain to any part of the Derivative Works, in at least one
  266. of the following places: within a NOTICE text file distributed
  267. as part of the Derivative Works; within the Source form or
  268. documentation, if provided along with the Derivative Works; or,
  269. within a display generated by the Derivative Works, if and
  270. wherever such third-party notices normally appear. The contents
  271. of the NOTICE file are for informational purposes only and
  272. do not modify the License. You may add Your own attribution
  273. notices within Derivative Works that You distribute, alongside
  274. or as an addendum to the NOTICE text from the Work, provided
  275. that such additional attribution notices cannot be construed
  276. as modifying the License.
  277. You may add Your own copyright statement to Your modifications and
  278. may provide additional or different license terms and conditions
  279. for use, reproduction, or distribution of Your modifications, or
  280. for any such Derivative Works as a whole, provided Your use,
  281. reproduction, and distribution of the Work otherwise complies with
  282. the conditions stated in this License.
  283. 5. Submission of Contributions. Unless You explicitly state otherwise,
  284. any Contribution intentionally submitted for inclusion in the Work
  285. by You to the Licensor shall be under the terms and conditions of
  286. this License, without any additional terms or conditions.
  287. Notwithstanding the above, nothing herein shall supersede or modify
  288. the terms of any separate license agreement you may have executed
  289. with Licensor regarding such Contributions.
  290. 6. Trademarks. This License does not grant permission to use the trade
  291. names, trademarks, service marks, or product names of the Licensor,
  292. except as required for reasonable and customary use in describing the
  293. origin of the Work and reproducing the content of the NOTICE file.
  294. 7. Disclaimer of Warranty. Unless required by applicable law or
  295. agreed to in writing, Licensor provides the Work (and each
  296. Contributor provides its Contributions) on an "AS IS" BASIS,
  297. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  298. implied, including, without limitation, any warranties or conditions
  299. of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
  300. PARTICULAR PURPOSE. You are solely responsible for determining the
  301. appropriateness of using or redistributing the Work and assume any
  302. risks associated with Your exercise of permissions under this License.
  303. 8. Limitation of Liability. In no event and under no legal theory,
  304. whether in tort (including negligence), contract, or otherwise,
  305. unless required by applicable law (such as deliberate and grossly
  306. negligent acts) or agreed to in writing, shall any Contributor be
  307. liable to You for damages, including any direct, indirect, special,
  308. incidental, or consequential damages of any character arising as a
  309. result of this License or out of the use or inability to use the
  310. Work (including but not limited to damages for loss of goodwill,
  311. work stoppage, computer failure or malfunction, or any and all
  312. other commercial damages or losses), even if such Contributor
  313. has been advised of the possibility of such damages.
  314. 9. Accepting Warranty or Additional Liability. While redistributing
  315. the Work or Derivative Works thereof, You may choose to offer,
  316. and charge a fee for, acceptance of support, warranty, indemnity,
  317. or other liability obligations and/or rights consistent with this
  318. License. However, in accepting such obligations, You may act only
  319. on Your own behalf and on Your sole responsibility, not on behalf
  320. of any other Contributor, and only if You agree to indemnify,
  321. defend, and hold each Contributor harmless for any liability
  322. incurred by, or claims asserted against, such Contributor by reason
  323. of your accepting any such warranty or additional liability.
  324. END OF TERMS AND CONDITIONS
  325. APPENDIX: How to apply the Apache License to your work.
  326. To apply the Apache License to your work, attach the following
  327. boilerplate notice, with the fields enclosed by brackets "[]"
  328. replaced with your own identifying information. (Don't include
  329. the brackets!) The text should be enclosed in the appropriate
  330. comment syntax for the file format. We also recommend that a
  331. file or class name and description of purpose be included on the
  332. same "printed page" as the copyright notice for easier
  333. identification within third-party archives.
  334. Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
  335. Licensed under the Apache License, Version 2.0 (the "License");
  336. you may not use this file except in compliance with the License.
  337. You may obtain a copy of the License at
  338. http://www.apache.org/licenses/LICENSE-2.0
  339. Unless required by applicable law or agreed to in writing, software
  340. distributed under the License is distributed on an "AS IS" BASIS,
  341. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  342. See the License for the specific language governing permissions and
  343. limitations under the License.
  344. **/
  345. (function (global, factory) {
  346. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  347. typeof define === 'function' && define.amd ? define('rxjs', ['exports'], factory) :
  348. (factory((global.rxjs = {})));
  349. }(this, (function (exports) { 'use strict';
  350. /*! *****************************************************************************
  351. Copyright (c) Microsoft Corporation.
  352. Permission to use, copy, modify, and/or distribute this software for any
  353. purpose with or without fee is hereby granted.
  354. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  355. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  356. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  357. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  358. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  359. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  360. PERFORMANCE OF THIS SOFTWARE.
  361. ***************************************************************************** */
  362. /* global Reflect, Promise */
  363. var extendStatics = function(d, b) {
  364. extendStatics = Object.setPrototypeOf ||
  365. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  366. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  367. return extendStatics(d, b);
  368. };
  369. function __extends(d, b) {
  370. if (typeof b !== "function" && b !== null)
  371. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  372. extendStatics(d, b);
  373. function __() { this.constructor = d; }
  374. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  375. }
  376. var __assign = function() {
  377. __assign = Object.assign || function __assign(t) {
  378. for (var s, i = 1, n = arguments.length; i < n; i++) {
  379. s = arguments[i];
  380. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  381. }
  382. return t;
  383. };
  384. return __assign.apply(this, arguments);
  385. };
  386. function __rest(s, e) {
  387. var t = {};
  388. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  389. t[p] = s[p];
  390. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  391. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  392. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  393. t[p[i]] = s[p[i]];
  394. }
  395. return t;
  396. }
  397. function __awaiter(thisArg, _arguments, P, generator) {
  398. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  399. return new (P || (P = Promise))(function (resolve, reject) {
  400. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  401. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  402. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  403. step((generator = generator.apply(thisArg, _arguments || [])).next());
  404. });
  405. }
  406. function __generator(thisArg, body) {
  407. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  408. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  409. function verb(n) { return function (v) { return step([n, v]); }; }
  410. function step(op) {
  411. if (f) throw new TypeError("Generator is already executing.");
  412. while (_) try {
  413. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  414. if (y = 0, t) op = [op[0] & 2, t.value];
  415. switch (op[0]) {
  416. case 0: case 1: t = op; break;
  417. case 4: _.label++; return { value: op[1], done: false };
  418. case 5: _.label++; y = op[1]; op = [0]; continue;
  419. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  420. default:
  421. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  422. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  423. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  424. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  425. if (t[2]) _.ops.pop();
  426. _.trys.pop(); continue;
  427. }
  428. op = body.call(thisArg, _);
  429. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  430. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  431. }
  432. }
  433. function __values(o) {
  434. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  435. if (m) return m.call(o);
  436. if (o && typeof o.length === "number") return {
  437. next: function () {
  438. if (o && i >= o.length) o = void 0;
  439. return { value: o && o[i++], done: !o };
  440. }
  441. };
  442. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  443. }
  444. function __read(o, n) {
  445. var m = typeof Symbol === "function" && o[Symbol.iterator];
  446. if (!m) return o;
  447. var i = m.call(o), r, ar = [], e;
  448. try {
  449. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  450. }
  451. catch (error) { e = { error: error }; }
  452. finally {
  453. try {
  454. if (r && !r.done && (m = i["return"])) m.call(i);
  455. }
  456. finally { if (e) throw e.error; }
  457. }
  458. return ar;
  459. }
  460. function __spreadArray(to, from, pack) {
  461. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  462. if (ar || !(i in from)) {
  463. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  464. ar[i] = from[i];
  465. }
  466. }
  467. return to.concat(ar || Array.prototype.slice.call(from));
  468. }
  469. function __await(v) {
  470. return this instanceof __await ? (this.v = v, this) : new __await(v);
  471. }
  472. function __asyncGenerator(thisArg, _arguments, generator) {
  473. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  474. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  475. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  476. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  477. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  478. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  479. function fulfill(value) { resume("next", value); }
  480. function reject(value) { resume("throw", value); }
  481. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  482. }
  483. function __asyncValues(o) {
  484. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  485. var m = o[Symbol.asyncIterator], i;
  486. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  487. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  488. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  489. }
  490. function isFunction(value) {
  491. return typeof value === 'function';
  492. }
  493. function createErrorClass(createImpl) {
  494. var _super = function (instance) {
  495. Error.call(instance);
  496. instance.stack = new Error().stack;
  497. };
  498. var ctorFunc = createImpl(_super);
  499. ctorFunc.prototype = Object.create(Error.prototype);
  500. ctorFunc.prototype.constructor = ctorFunc;
  501. return ctorFunc;
  502. }
  503. var UnsubscriptionError = createErrorClass(function (_super) {
  504. return function UnsubscriptionErrorImpl(errors) {
  505. _super(this);
  506. this.message = errors
  507. ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
  508. : '';
  509. this.name = 'UnsubscriptionError';
  510. this.errors = errors;
  511. };
  512. });
  513. function arrRemove(arr, item) {
  514. if (arr) {
  515. var index = arr.indexOf(item);
  516. 0 <= index && arr.splice(index, 1);
  517. }
  518. }
  519. var Subscription = (function () {
  520. function Subscription(initialTeardown) {
  521. this.initialTeardown = initialTeardown;
  522. this.closed = false;
  523. this._parentage = null;
  524. this._finalizers = null;
  525. }
  526. Subscription.prototype.unsubscribe = function () {
  527. var e_1, _a, e_2, _b;
  528. var errors;
  529. if (!this.closed) {
  530. this.closed = true;
  531. var _parentage = this._parentage;
  532. if (_parentage) {
  533. this._parentage = null;
  534. if (Array.isArray(_parentage)) {
  535. try {
  536. for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
  537. var parent_1 = _parentage_1_1.value;
  538. parent_1.remove(this);
  539. }
  540. }
  541. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  542. finally {
  543. try {
  544. if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
  545. }
  546. finally { if (e_1) throw e_1.error; }
  547. }
  548. }
  549. else {
  550. _parentage.remove(this);
  551. }
  552. }
  553. var initialFinalizer = this.initialTeardown;
  554. if (isFunction(initialFinalizer)) {
  555. try {
  556. initialFinalizer();
  557. }
  558. catch (e) {
  559. errors = e instanceof UnsubscriptionError ? e.errors : [e];
  560. }
  561. }
  562. var _finalizers = this._finalizers;
  563. if (_finalizers) {
  564. this._finalizers = null;
  565. try {
  566. for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
  567. var finalizer = _finalizers_1_1.value;
  568. try {
  569. execFinalizer(finalizer);
  570. }
  571. catch (err) {
  572. errors = errors !== null && errors !== void 0 ? errors : [];
  573. if (err instanceof UnsubscriptionError) {
  574. errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
  575. }
  576. else {
  577. errors.push(err);
  578. }
  579. }
  580. }
  581. }
  582. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  583. finally {
  584. try {
  585. if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
  586. }
  587. finally { if (e_2) throw e_2.error; }
  588. }
  589. }
  590. if (errors) {
  591. throw new UnsubscriptionError(errors);
  592. }
  593. }
  594. };
  595. Subscription.prototype.add = function (teardown) {
  596. var _a;
  597. if (teardown && teardown !== this) {
  598. if (this.closed) {
  599. execFinalizer(teardown);
  600. }
  601. else {
  602. if (teardown instanceof Subscription) {
  603. if (teardown.closed || teardown._hasParent(this)) {
  604. return;
  605. }
  606. teardown._addParent(this);
  607. }
  608. (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
  609. }
  610. }
  611. };
  612. Subscription.prototype._hasParent = function (parent) {
  613. var _parentage = this._parentage;
  614. return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
  615. };
  616. Subscription.prototype._addParent = function (parent) {
  617. var _parentage = this._parentage;
  618. this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
  619. };
  620. Subscription.prototype._removeParent = function (parent) {
  621. var _parentage = this._parentage;
  622. if (_parentage === parent) {
  623. this._parentage = null;
  624. }
  625. else if (Array.isArray(_parentage)) {
  626. arrRemove(_parentage, parent);
  627. }
  628. };
  629. Subscription.prototype.remove = function (teardown) {
  630. var _finalizers = this._finalizers;
  631. _finalizers && arrRemove(_finalizers, teardown);
  632. if (teardown instanceof Subscription) {
  633. teardown._removeParent(this);
  634. }
  635. };
  636. Subscription.EMPTY = (function () {
  637. var empty = new Subscription();
  638. empty.closed = true;
  639. return empty;
  640. })();
  641. return Subscription;
  642. }());
  643. var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
  644. function isSubscription(value) {
  645. return (value instanceof Subscription ||
  646. (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
  647. }
  648. function execFinalizer(finalizer) {
  649. if (isFunction(finalizer)) {
  650. finalizer();
  651. }
  652. else {
  653. finalizer.unsubscribe();
  654. }
  655. }
  656. var config = {
  657. onUnhandledError: null,
  658. onStoppedNotification: null,
  659. Promise: undefined,
  660. useDeprecatedSynchronousErrorHandling: false,
  661. useDeprecatedNextContext: false,
  662. };
  663. var timeoutProvider = {
  664. setTimeout: function (handler, timeout) {
  665. var args = [];
  666. for (var _i = 2; _i < arguments.length; _i++) {
  667. args[_i - 2] = arguments[_i];
  668. }
  669. var delegate = timeoutProvider.delegate;
  670. if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
  671. return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
  672. }
  673. return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
  674. },
  675. clearTimeout: function (handle) {
  676. var delegate = timeoutProvider.delegate;
  677. return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
  678. },
  679. delegate: undefined,
  680. };
  681. function reportUnhandledError(err) {
  682. timeoutProvider.setTimeout(function () {
  683. var onUnhandledError = config.onUnhandledError;
  684. if (onUnhandledError) {
  685. onUnhandledError(err);
  686. }
  687. else {
  688. throw err;
  689. }
  690. });
  691. }
  692. function noop() { }
  693. var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
  694. function errorNotification(error) {
  695. return createNotification('E', undefined, error);
  696. }
  697. function nextNotification(value) {
  698. return createNotification('N', value, undefined);
  699. }
  700. function createNotification(kind, value, error) {
  701. return {
  702. kind: kind,
  703. value: value,
  704. error: error,
  705. };
  706. }
  707. var context = null;
  708. function errorContext(cb) {
  709. if (config.useDeprecatedSynchronousErrorHandling) {
  710. var isRoot = !context;
  711. if (isRoot) {
  712. context = { errorThrown: false, error: null };
  713. }
  714. cb();
  715. if (isRoot) {
  716. var _a = context, errorThrown = _a.errorThrown, error = _a.error;
  717. context = null;
  718. if (errorThrown) {
  719. throw error;
  720. }
  721. }
  722. }
  723. else {
  724. cb();
  725. }
  726. }
  727. function captureError(err) {
  728. if (config.useDeprecatedSynchronousErrorHandling && context) {
  729. context.errorThrown = true;
  730. context.error = err;
  731. }
  732. }
  733. var Subscriber = (function (_super) {
  734. __extends(Subscriber, _super);
  735. function Subscriber(destination) {
  736. var _this = _super.call(this) || this;
  737. _this.isStopped = false;
  738. if (destination) {
  739. _this.destination = destination;
  740. if (isSubscription(destination)) {
  741. destination.add(_this);
  742. }
  743. }
  744. else {
  745. _this.destination = EMPTY_OBSERVER;
  746. }
  747. return _this;
  748. }
  749. Subscriber.create = function (next, error, complete) {
  750. return new SafeSubscriber(next, error, complete);
  751. };
  752. Subscriber.prototype.next = function (value) {
  753. if (this.isStopped) {
  754. handleStoppedNotification(nextNotification(value), this);
  755. }
  756. else {
  757. this._next(value);
  758. }
  759. };
  760. Subscriber.prototype.error = function (err) {
  761. if (this.isStopped) {
  762. handleStoppedNotification(errorNotification(err), this);
  763. }
  764. else {
  765. this.isStopped = true;
  766. this._error(err);
  767. }
  768. };
  769. Subscriber.prototype.complete = function () {
  770. if (this.isStopped) {
  771. handleStoppedNotification(COMPLETE_NOTIFICATION, this);
  772. }
  773. else {
  774. this.isStopped = true;
  775. this._complete();
  776. }
  777. };
  778. Subscriber.prototype.unsubscribe = function () {
  779. if (!this.closed) {
  780. this.isStopped = true;
  781. _super.prototype.unsubscribe.call(this);
  782. this.destination = null;
  783. }
  784. };
  785. Subscriber.prototype._next = function (value) {
  786. this.destination.next(value);
  787. };
  788. Subscriber.prototype._error = function (err) {
  789. try {
  790. this.destination.error(err);
  791. }
  792. finally {
  793. this.unsubscribe();
  794. }
  795. };
  796. Subscriber.prototype._complete = function () {
  797. try {
  798. this.destination.complete();
  799. }
  800. finally {
  801. this.unsubscribe();
  802. }
  803. };
  804. return Subscriber;
  805. }(Subscription));
  806. var _bind = Function.prototype.bind;
  807. function bind(fn, thisArg) {
  808. return _bind.call(fn, thisArg);
  809. }
  810. var ConsumerObserver = (function () {
  811. function ConsumerObserver(partialObserver) {
  812. this.partialObserver = partialObserver;
  813. }
  814. ConsumerObserver.prototype.next = function (value) {
  815. var partialObserver = this.partialObserver;
  816. if (partialObserver.next) {
  817. try {
  818. partialObserver.next(value);
  819. }
  820. catch (error) {
  821. handleUnhandledError(error);
  822. }
  823. }
  824. };
  825. ConsumerObserver.prototype.error = function (err) {
  826. var partialObserver = this.partialObserver;
  827. if (partialObserver.error) {
  828. try {
  829. partialObserver.error(err);
  830. }
  831. catch (error) {
  832. handleUnhandledError(error);
  833. }
  834. }
  835. else {
  836. handleUnhandledError(err);
  837. }
  838. };
  839. ConsumerObserver.prototype.complete = function () {
  840. var partialObserver = this.partialObserver;
  841. if (partialObserver.complete) {
  842. try {
  843. partialObserver.complete();
  844. }
  845. catch (error) {
  846. handleUnhandledError(error);
  847. }
  848. }
  849. };
  850. return ConsumerObserver;
  851. }());
  852. var SafeSubscriber = (function (_super) {
  853. __extends(SafeSubscriber, _super);
  854. function SafeSubscriber(observerOrNext, error, complete) {
  855. var _this = _super.call(this) || this;
  856. var partialObserver;
  857. if (isFunction(observerOrNext) || !observerOrNext) {
  858. partialObserver = {
  859. next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
  860. error: error !== null && error !== void 0 ? error : undefined,
  861. complete: complete !== null && complete !== void 0 ? complete : undefined,
  862. };
  863. }
  864. else {
  865. var context_1;
  866. if (_this && config.useDeprecatedNextContext) {
  867. context_1 = Object.create(observerOrNext);
  868. context_1.unsubscribe = function () { return _this.unsubscribe(); };
  869. partialObserver = {
  870. next: observerOrNext.next && bind(observerOrNext.next, context_1),
  871. error: observerOrNext.error && bind(observerOrNext.error, context_1),
  872. complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
  873. };
  874. }
  875. else {
  876. partialObserver = observerOrNext;
  877. }
  878. }
  879. _this.destination = new ConsumerObserver(partialObserver);
  880. return _this;
  881. }
  882. return SafeSubscriber;
  883. }(Subscriber));
  884. function handleUnhandledError(error) {
  885. if (config.useDeprecatedSynchronousErrorHandling) {
  886. captureError(error);
  887. }
  888. else {
  889. reportUnhandledError(error);
  890. }
  891. }
  892. function defaultErrorHandler(err) {
  893. throw err;
  894. }
  895. function handleStoppedNotification(notification, subscriber) {
  896. var onStoppedNotification = config.onStoppedNotification;
  897. onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
  898. }
  899. var EMPTY_OBSERVER = {
  900. closed: true,
  901. next: noop,
  902. error: defaultErrorHandler,
  903. complete: noop,
  904. };
  905. var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
  906. function identity(x) {
  907. return x;
  908. }
  909. function pipe() {
  910. var fns = [];
  911. for (var _i = 0; _i < arguments.length; _i++) {
  912. fns[_i] = arguments[_i];
  913. }
  914. return pipeFromArray(fns);
  915. }
  916. function pipeFromArray(fns) {
  917. if (fns.length === 0) {
  918. return identity;
  919. }
  920. if (fns.length === 1) {
  921. return fns[0];
  922. }
  923. return function piped(input) {
  924. return fns.reduce(function (prev, fn) { return fn(prev); }, input);
  925. };
  926. }
  927. var Observable = (function () {
  928. function Observable(subscribe) {
  929. if (subscribe) {
  930. this._subscribe = subscribe;
  931. }
  932. }
  933. Observable.prototype.lift = function (operator) {
  934. var observable$$1 = new Observable();
  935. observable$$1.source = this;
  936. observable$$1.operator = operator;
  937. return observable$$1;
  938. };
  939. Observable.prototype.subscribe = function (observerOrNext, error, complete) {
  940. var _this = this;
  941. var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
  942. errorContext(function () {
  943. var _a = _this, operator = _a.operator, source = _a.source;
  944. subscriber.add(operator
  945. ?
  946. operator.call(subscriber, source)
  947. : source
  948. ?
  949. _this._subscribe(subscriber)
  950. :
  951. _this._trySubscribe(subscriber));
  952. });
  953. return subscriber;
  954. };
  955. Observable.prototype._trySubscribe = function (sink) {
  956. try {
  957. return this._subscribe(sink);
  958. }
  959. catch (err) {
  960. sink.error(err);
  961. }
  962. };
  963. Observable.prototype.forEach = function (next, promiseCtor) {
  964. var _this = this;
  965. promiseCtor = getPromiseCtor(promiseCtor);
  966. return new promiseCtor(function (resolve, reject) {
  967. var subscriber = new SafeSubscriber({
  968. next: function (value) {
  969. try {
  970. next(value);
  971. }
  972. catch (err) {
  973. reject(err);
  974. subscriber.unsubscribe();
  975. }
  976. },
  977. error: reject,
  978. complete: resolve,
  979. });
  980. _this.subscribe(subscriber);
  981. });
  982. };
  983. Observable.prototype._subscribe = function (subscriber) {
  984. var _a;
  985. return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
  986. };
  987. Observable.prototype[observable] = function () {
  988. return this;
  989. };
  990. Observable.prototype.pipe = function () {
  991. var operations = [];
  992. for (var _i = 0; _i < arguments.length; _i++) {
  993. operations[_i] = arguments[_i];
  994. }
  995. return pipeFromArray(operations)(this);
  996. };
  997. Observable.prototype.toPromise = function (promiseCtor) {
  998. var _this = this;
  999. promiseCtor = getPromiseCtor(promiseCtor);
  1000. return new promiseCtor(function (resolve, reject) {
  1001. var value;
  1002. _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
  1003. });
  1004. };
  1005. Observable.create = function (subscribe) {
  1006. return new Observable(subscribe);
  1007. };
  1008. return Observable;
  1009. }());
  1010. function getPromiseCtor(promiseCtor) {
  1011. var _a;
  1012. return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
  1013. }
  1014. function isObserver(value) {
  1015. return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
  1016. }
  1017. function isSubscriber(value) {
  1018. return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
  1019. }
  1020. function hasLift(source) {
  1021. return isFunction(source === null || source === void 0 ? void 0 : source.lift);
  1022. }
  1023. function operate(init) {
  1024. return function (source) {
  1025. if (hasLift(source)) {
  1026. return source.lift(function (liftedSource) {
  1027. try {
  1028. return init(liftedSource, this);
  1029. }
  1030. catch (err) {
  1031. this.error(err);
  1032. }
  1033. });
  1034. }
  1035. throw new TypeError('Unable to lift unknown Observable type');
  1036. };
  1037. }
  1038. function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
  1039. return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
  1040. }
  1041. var OperatorSubscriber = (function (_super) {
  1042. __extends(OperatorSubscriber, _super);
  1043. function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
  1044. var _this = _super.call(this, destination) || this;
  1045. _this.onFinalize = onFinalize;
  1046. _this.shouldUnsubscribe = shouldUnsubscribe;
  1047. _this._next = onNext
  1048. ? function (value) {
  1049. try {
  1050. onNext(value);
  1051. }
  1052. catch (err) {
  1053. destination.error(err);
  1054. }
  1055. }
  1056. : _super.prototype._next;
  1057. _this._error = onError
  1058. ? function (err) {
  1059. try {
  1060. onError(err);
  1061. }
  1062. catch (err) {
  1063. destination.error(err);
  1064. }
  1065. finally {
  1066. this.unsubscribe();
  1067. }
  1068. }
  1069. : _super.prototype._error;
  1070. _this._complete = onComplete
  1071. ? function () {
  1072. try {
  1073. onComplete();
  1074. }
  1075. catch (err) {
  1076. destination.error(err);
  1077. }
  1078. finally {
  1079. this.unsubscribe();
  1080. }
  1081. }
  1082. : _super.prototype._complete;
  1083. return _this;
  1084. }
  1085. OperatorSubscriber.prototype.unsubscribe = function () {
  1086. var _a;
  1087. if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
  1088. var closed_1 = this.closed;
  1089. _super.prototype.unsubscribe.call(this);
  1090. !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
  1091. }
  1092. };
  1093. return OperatorSubscriber;
  1094. }(Subscriber));
  1095. function refCount() {
  1096. return operate(function (source, subscriber) {
  1097. var connection = null;
  1098. source._refCount++;
  1099. var refCounter = createOperatorSubscriber(subscriber, undefined, undefined, undefined, function () {
  1100. if (!source || source._refCount <= 0 || 0 < --source._refCount) {
  1101. connection = null;
  1102. return;
  1103. }
  1104. var sharedConnection = source._connection;
  1105. var conn = connection;
  1106. connection = null;
  1107. if (sharedConnection && (!conn || sharedConnection === conn)) {
  1108. sharedConnection.unsubscribe();
  1109. }
  1110. subscriber.unsubscribe();
  1111. });
  1112. source.subscribe(refCounter);
  1113. if (!refCounter.closed) {
  1114. connection = source.connect();
  1115. }
  1116. });
  1117. }
  1118. var ConnectableObservable = (function (_super) {
  1119. __extends(ConnectableObservable, _super);
  1120. function ConnectableObservable(source, subjectFactory) {
  1121. var _this = _super.call(this) || this;
  1122. _this.source = source;
  1123. _this.subjectFactory = subjectFactory;
  1124. _this._subject = null;
  1125. _this._refCount = 0;
  1126. _this._connection = null;
  1127. if (hasLift(source)) {
  1128. _this.lift = source.lift;
  1129. }
  1130. return _this;
  1131. }
  1132. ConnectableObservable.prototype._subscribe = function (subscriber) {
  1133. return this.getSubject().subscribe(subscriber);
  1134. };
  1135. ConnectableObservable.prototype.getSubject = function () {
  1136. var subject = this._subject;
  1137. if (!subject || subject.isStopped) {
  1138. this._subject = this.subjectFactory();
  1139. }
  1140. return this._subject;
  1141. };
  1142. ConnectableObservable.prototype._teardown = function () {
  1143. this._refCount = 0;
  1144. var _connection = this._connection;
  1145. this._subject = this._connection = null;
  1146. _connection === null || _connection === void 0 ? void 0 : _connection.unsubscribe();
  1147. };
  1148. ConnectableObservable.prototype.connect = function () {
  1149. var _this = this;
  1150. var connection = this._connection;
  1151. if (!connection) {
  1152. connection = this._connection = new Subscription();
  1153. var subject_1 = this.getSubject();
  1154. connection.add(this.source.subscribe(createOperatorSubscriber(subject_1, undefined, function () {
  1155. _this._teardown();
  1156. subject_1.complete();
  1157. }, function (err) {
  1158. _this._teardown();
  1159. subject_1.error(err);
  1160. }, function () { return _this._teardown(); })));
  1161. if (connection.closed) {
  1162. this._connection = null;
  1163. connection = Subscription.EMPTY;
  1164. }
  1165. }
  1166. return connection;
  1167. };
  1168. ConnectableObservable.prototype.refCount = function () {
  1169. return refCount()(this);
  1170. };
  1171. return ConnectableObservable;
  1172. }(Observable));
  1173. var performanceTimestampProvider = {
  1174. now: function () {
  1175. return (performanceTimestampProvider.delegate || performance).now();
  1176. },
  1177. delegate: undefined,
  1178. };
  1179. var animationFrameProvider = {
  1180. schedule: function (callback) {
  1181. var request = requestAnimationFrame;
  1182. var cancel = cancelAnimationFrame;
  1183. var delegate = animationFrameProvider.delegate;
  1184. if (delegate) {
  1185. request = delegate.requestAnimationFrame;
  1186. cancel = delegate.cancelAnimationFrame;
  1187. }
  1188. var handle = request(function (timestamp) {
  1189. cancel = undefined;
  1190. callback(timestamp);
  1191. });
  1192. return new Subscription(function () { return cancel === null || cancel === void 0 ? void 0 : cancel(handle); });
  1193. },
  1194. requestAnimationFrame: function () {
  1195. var args = [];
  1196. for (var _i = 0; _i < arguments.length; _i++) {
  1197. args[_i] = arguments[_i];
  1198. }
  1199. var delegate = animationFrameProvider.delegate;
  1200. return ((delegate === null || delegate === void 0 ? void 0 : delegate.requestAnimationFrame) || requestAnimationFrame).apply(void 0, __spreadArray([], __read(args)));
  1201. },
  1202. cancelAnimationFrame: function () {
  1203. var args = [];
  1204. for (var _i = 0; _i < arguments.length; _i++) {
  1205. args[_i] = arguments[_i];
  1206. }
  1207. var delegate = animationFrameProvider.delegate;
  1208. return ((delegate === null || delegate === void 0 ? void 0 : delegate.cancelAnimationFrame) || cancelAnimationFrame).apply(void 0, __spreadArray([], __read(args)));
  1209. },
  1210. delegate: undefined,
  1211. };
  1212. function animationFrames(timestampProvider) {
  1213. return timestampProvider ? animationFramesFactory(timestampProvider) : DEFAULT_ANIMATION_FRAMES;
  1214. }
  1215. function animationFramesFactory(timestampProvider) {
  1216. return new Observable(function (subscriber) {
  1217. var provider = timestampProvider || performanceTimestampProvider;
  1218. var start = provider.now();
  1219. var id = 0;
  1220. var run = function () {
  1221. if (!subscriber.closed) {
  1222. id = animationFrameProvider.requestAnimationFrame(function (timestamp) {
  1223. id = 0;
  1224. var now = provider.now();
  1225. subscriber.next({
  1226. timestamp: timestampProvider ? now : timestamp,
  1227. elapsed: now - start,
  1228. });
  1229. run();
  1230. });
  1231. }
  1232. };
  1233. run();
  1234. return function () {
  1235. if (id) {
  1236. animationFrameProvider.cancelAnimationFrame(id);
  1237. }
  1238. };
  1239. });
  1240. }
  1241. var DEFAULT_ANIMATION_FRAMES = animationFramesFactory();
  1242. var ObjectUnsubscribedError = createErrorClass(function (_super) {
  1243. return function ObjectUnsubscribedErrorImpl() {
  1244. _super(this);
  1245. this.name = 'ObjectUnsubscribedError';
  1246. this.message = 'object unsubscribed';
  1247. };
  1248. });
  1249. var Subject = (function (_super) {
  1250. __extends(Subject, _super);
  1251. function Subject() {
  1252. var _this = _super.call(this) || this;
  1253. _this.closed = false;
  1254. _this.currentObservers = null;
  1255. _this.observers = [];
  1256. _this.isStopped = false;
  1257. _this.hasError = false;
  1258. _this.thrownError = null;
  1259. return _this;
  1260. }
  1261. Subject.prototype.lift = function (operator) {
  1262. var subject = new AnonymousSubject(this, this);
  1263. subject.operator = operator;
  1264. return subject;
  1265. };
  1266. Subject.prototype._throwIfClosed = function () {
  1267. if (this.closed) {
  1268. throw new ObjectUnsubscribedError();
  1269. }
  1270. };
  1271. Subject.prototype.next = function (value) {
  1272. var _this = this;
  1273. errorContext(function () {
  1274. var e_1, _a;
  1275. _this._throwIfClosed();
  1276. if (!_this.isStopped) {
  1277. if (!_this.currentObservers) {
  1278. _this.currentObservers = Array.from(_this.observers);
  1279. }
  1280. try {
  1281. for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
  1282. var observer = _c.value;
  1283. observer.next(value);
  1284. }
  1285. }
  1286. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1287. finally {
  1288. try {
  1289. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1290. }
  1291. finally { if (e_1) throw e_1.error; }
  1292. }
  1293. }
  1294. });
  1295. };
  1296. Subject.prototype.error = function (err) {
  1297. var _this = this;
  1298. errorContext(function () {
  1299. _this._throwIfClosed();
  1300. if (!_this.isStopped) {
  1301. _this.hasError = _this.isStopped = true;
  1302. _this.thrownError = err;
  1303. var observers = _this.observers;
  1304. while (observers.length) {
  1305. observers.shift().error(err);
  1306. }
  1307. }
  1308. });
  1309. };
  1310. Subject.prototype.complete = function () {
  1311. var _this = this;
  1312. errorContext(function () {
  1313. _this._throwIfClosed();
  1314. if (!_this.isStopped) {
  1315. _this.isStopped = true;
  1316. var observers = _this.observers;
  1317. while (observers.length) {
  1318. observers.shift().complete();
  1319. }
  1320. }
  1321. });
  1322. };
  1323. Subject.prototype.unsubscribe = function () {
  1324. this.isStopped = this.closed = true;
  1325. this.observers = this.currentObservers = null;
  1326. };
  1327. Object.defineProperty(Subject.prototype, "observed", {
  1328. get: function () {
  1329. var _a;
  1330. return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
  1331. },
  1332. enumerable: false,
  1333. configurable: true
  1334. });
  1335. Subject.prototype._trySubscribe = function (subscriber) {
  1336. this._throwIfClosed();
  1337. return _super.prototype._trySubscribe.call(this, subscriber);
  1338. };
  1339. Subject.prototype._subscribe = function (subscriber) {
  1340. this._throwIfClosed();
  1341. this._checkFinalizedStatuses(subscriber);
  1342. return this._innerSubscribe(subscriber);
  1343. };
  1344. Subject.prototype._innerSubscribe = function (subscriber) {
  1345. var _this = this;
  1346. var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
  1347. if (hasError || isStopped) {
  1348. return EMPTY_SUBSCRIPTION;
  1349. }
  1350. this.currentObservers = null;
  1351. observers.push(subscriber);
  1352. return new Subscription(function () {
  1353. _this.currentObservers = null;
  1354. arrRemove(observers, subscriber);
  1355. });
  1356. };
  1357. Subject.prototype._checkFinalizedStatuses = function (subscriber) {
  1358. var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
  1359. if (hasError) {
  1360. subscriber.error(thrownError);
  1361. }
  1362. else if (isStopped) {
  1363. subscriber.complete();
  1364. }
  1365. };
  1366. Subject.prototype.asObservable = function () {
  1367. var observable = new Observable();
  1368. observable.source = this;
  1369. return observable;
  1370. };
  1371. Subject.create = function (destination, source) {
  1372. return new AnonymousSubject(destination, source);
  1373. };
  1374. return Subject;
  1375. }(Observable));
  1376. var AnonymousSubject = (function (_super) {
  1377. __extends(AnonymousSubject, _super);
  1378. function AnonymousSubject(destination, source) {
  1379. var _this = _super.call(this) || this;
  1380. _this.destination = destination;
  1381. _this.source = source;
  1382. return _this;
  1383. }
  1384. AnonymousSubject.prototype.next = function (value) {
  1385. var _a, _b;
  1386. (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
  1387. };
  1388. AnonymousSubject.prototype.error = function (err) {
  1389. var _a, _b;
  1390. (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
  1391. };
  1392. AnonymousSubject.prototype.complete = function () {
  1393. var _a, _b;
  1394. (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
  1395. };
  1396. AnonymousSubject.prototype._subscribe = function (subscriber) {
  1397. var _a, _b;
  1398. return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
  1399. };
  1400. return AnonymousSubject;
  1401. }(Subject));
  1402. var BehaviorSubject = (function (_super) {
  1403. __extends(BehaviorSubject, _super);
  1404. function BehaviorSubject(_value) {
  1405. var _this = _super.call(this) || this;
  1406. _this._value = _value;
  1407. return _this;
  1408. }
  1409. Object.defineProperty(BehaviorSubject.prototype, "value", {
  1410. get: function () {
  1411. return this.getValue();
  1412. },
  1413. enumerable: false,
  1414. configurable: true
  1415. });
  1416. BehaviorSubject.prototype._subscribe = function (subscriber) {
  1417. var subscription = _super.prototype._subscribe.call(this, subscriber);
  1418. !subscription.closed && subscriber.next(this._value);
  1419. return subscription;
  1420. };
  1421. BehaviorSubject.prototype.getValue = function () {
  1422. var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
  1423. if (hasError) {
  1424. throw thrownError;
  1425. }
  1426. this._throwIfClosed();
  1427. return _value;
  1428. };
  1429. BehaviorSubject.prototype.next = function (value) {
  1430. _super.prototype.next.call(this, (this._value = value));
  1431. };
  1432. return BehaviorSubject;
  1433. }(Subject));
  1434. var dateTimestampProvider = {
  1435. now: function () {
  1436. return (dateTimestampProvider.delegate || Date).now();
  1437. },
  1438. delegate: undefined,
  1439. };
  1440. var ReplaySubject = (function (_super) {
  1441. __extends(ReplaySubject, _super);
  1442. function ReplaySubject(_bufferSize, _windowTime, _timestampProvider) {
  1443. if (_bufferSize === void 0) { _bufferSize = Infinity; }
  1444. if (_windowTime === void 0) { _windowTime = Infinity; }
  1445. if (_timestampProvider === void 0) { _timestampProvider = dateTimestampProvider; }
  1446. var _this = _super.call(this) || this;
  1447. _this._bufferSize = _bufferSize;
  1448. _this._windowTime = _windowTime;
  1449. _this._timestampProvider = _timestampProvider;
  1450. _this._buffer = [];
  1451. _this._infiniteTimeWindow = true;
  1452. _this._infiniteTimeWindow = _windowTime === Infinity;
  1453. _this._bufferSize = Math.max(1, _bufferSize);
  1454. _this._windowTime = Math.max(1, _windowTime);
  1455. return _this;
  1456. }
  1457. ReplaySubject.prototype.next = function (value) {
  1458. var _a = this, isStopped = _a.isStopped, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow, _timestampProvider = _a._timestampProvider, _windowTime = _a._windowTime;
  1459. if (!isStopped) {
  1460. _buffer.push(value);
  1461. !_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime);
  1462. }
  1463. this._trimBuffer();
  1464. _super.prototype.next.call(this, value);
  1465. };
  1466. ReplaySubject.prototype._subscribe = function (subscriber) {
  1467. this._throwIfClosed();
  1468. this._trimBuffer();
  1469. var subscription = this._innerSubscribe(subscriber);
  1470. var _a = this, _infiniteTimeWindow = _a._infiniteTimeWindow, _buffer = _a._buffer;
  1471. var copy = _buffer.slice();
  1472. for (var i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) {
  1473. subscriber.next(copy[i]);
  1474. }
  1475. this._checkFinalizedStatuses(subscriber);
  1476. return subscription;
  1477. };
  1478. ReplaySubject.prototype._trimBuffer = function () {
  1479. var _a = this, _bufferSize = _a._bufferSize, _timestampProvider = _a._timestampProvider, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow;
  1480. var adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize;
  1481. _bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize);
  1482. if (!_infiniteTimeWindow) {
  1483. var now = _timestampProvider.now();
  1484. var last = 0;
  1485. for (var i = 1; i < _buffer.length && _buffer[i] <= now; i += 2) {
  1486. last = i;
  1487. }
  1488. last && _buffer.splice(0, last + 1);
  1489. }
  1490. };
  1491. return ReplaySubject;
  1492. }(Subject));
  1493. var AsyncSubject = (function (_super) {
  1494. __extends(AsyncSubject, _super);
  1495. function AsyncSubject() {
  1496. var _this = _super !== null && _super.apply(this, arguments) || this;
  1497. _this._value = null;
  1498. _this._hasValue = false;
  1499. _this._isComplete = false;
  1500. return _this;
  1501. }
  1502. AsyncSubject.prototype._checkFinalizedStatuses = function (subscriber) {
  1503. var _a = this, hasError = _a.hasError, _hasValue = _a._hasValue, _value = _a._value, thrownError = _a.thrownError, isStopped = _a.isStopped, _isComplete = _a._isComplete;
  1504. if (hasError) {
  1505. subscriber.error(thrownError);
  1506. }
  1507. else if (isStopped || _isComplete) {
  1508. _hasValue && subscriber.next(_value);
  1509. subscriber.complete();
  1510. }
  1511. };
  1512. AsyncSubject.prototype.next = function (value) {
  1513. if (!this.isStopped) {
  1514. this._value = value;
  1515. this._hasValue = true;
  1516. }
  1517. };
  1518. AsyncSubject.prototype.complete = function () {
  1519. var _a = this, _hasValue = _a._hasValue, _value = _a._value, _isComplete = _a._isComplete;
  1520. if (!_isComplete) {
  1521. this._isComplete = true;
  1522. _hasValue && _super.prototype.next.call(this, _value);
  1523. _super.prototype.complete.call(this);
  1524. }
  1525. };
  1526. return AsyncSubject;
  1527. }(Subject));
  1528. var Action = (function (_super) {
  1529. __extends(Action, _super);
  1530. function Action(scheduler, work) {
  1531. return _super.call(this) || this;
  1532. }
  1533. Action.prototype.schedule = function (state, delay) {
  1534. if (delay === void 0) { delay = 0; }
  1535. return this;
  1536. };
  1537. return Action;
  1538. }(Subscription));
  1539. var intervalProvider = {
  1540. setInterval: function (handler, timeout) {
  1541. var args = [];
  1542. for (var _i = 2; _i < arguments.length; _i++) {
  1543. args[_i - 2] = arguments[_i];
  1544. }
  1545. var delegate = intervalProvider.delegate;
  1546. if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
  1547. return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
  1548. }
  1549. return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
  1550. },
  1551. clearInterval: function (handle) {
  1552. var delegate = intervalProvider.delegate;
  1553. return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
  1554. },
  1555. delegate: undefined,
  1556. };
  1557. var AsyncAction = (function (_super) {
  1558. __extends(AsyncAction, _super);
  1559. function AsyncAction(scheduler, work) {
  1560. var _this = _super.call(this, scheduler, work) || this;
  1561. _this.scheduler = scheduler;
  1562. _this.work = work;
  1563. _this.pending = false;
  1564. return _this;
  1565. }
  1566. AsyncAction.prototype.schedule = function (state, delay) {
  1567. var _a;
  1568. if (delay === void 0) { delay = 0; }
  1569. if (this.closed) {
  1570. return this;
  1571. }
  1572. this.state = state;
  1573. var id = this.id;
  1574. var scheduler = this.scheduler;
  1575. if (id != null) {
  1576. this.id = this.recycleAsyncId(scheduler, id, delay);
  1577. }
  1578. this.pending = true;
  1579. this.delay = delay;
  1580. this.id = (_a = this.id) !== null && _a !== void 0 ? _a : this.requestAsyncId(scheduler, this.id, delay);
  1581. return this;
  1582. };
  1583. AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
  1584. if (delay === void 0) { delay = 0; }
  1585. return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
  1586. };
  1587. AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
  1588. if (delay === void 0) { delay = 0; }
  1589. if (delay != null && this.delay === delay && this.pending === false) {
  1590. return id;
  1591. }
  1592. if (id != null) {
  1593. intervalProvider.clearInterval(id);
  1594. }
  1595. return undefined;
  1596. };
  1597. AsyncAction.prototype.execute = function (state, delay) {
  1598. if (this.closed) {
  1599. return new Error('executing a cancelled action');
  1600. }
  1601. this.pending = false;
  1602. var error = this._execute(state, delay);
  1603. if (error) {
  1604. return error;
  1605. }
  1606. else if (this.pending === false && this.id != null) {
  1607. this.id = this.recycleAsyncId(this.scheduler, this.id, null);
  1608. }
  1609. };
  1610. AsyncAction.prototype._execute = function (state, _delay) {
  1611. var errored = false;
  1612. var errorValue;
  1613. try {
  1614. this.work(state);
  1615. }
  1616. catch (e) {
  1617. errored = true;
  1618. errorValue = e ? e : new Error('Scheduled action threw falsy error');
  1619. }
  1620. if (errored) {
  1621. this.unsubscribe();
  1622. return errorValue;
  1623. }
  1624. };
  1625. AsyncAction.prototype.unsubscribe = function () {
  1626. if (!this.closed) {
  1627. var _a = this, id = _a.id, scheduler = _a.scheduler;
  1628. var actions = scheduler.actions;
  1629. this.work = this.state = this.scheduler = null;
  1630. this.pending = false;
  1631. arrRemove(actions, this);
  1632. if (id != null) {
  1633. this.id = this.recycleAsyncId(scheduler, id, null);
  1634. }
  1635. this.delay = null;
  1636. _super.prototype.unsubscribe.call(this);
  1637. }
  1638. };
  1639. return AsyncAction;
  1640. }(Action));
  1641. var nextHandle = 1;
  1642. var resolved;
  1643. var activeHandles = {};
  1644. function findAndClearHandle(handle) {
  1645. if (handle in activeHandles) {
  1646. delete activeHandles[handle];
  1647. return true;
  1648. }
  1649. return false;
  1650. }
  1651. var Immediate = {
  1652. setImmediate: function (cb) {
  1653. var handle = nextHandle++;
  1654. activeHandles[handle] = true;
  1655. if (!resolved) {
  1656. resolved = Promise.resolve();
  1657. }
  1658. resolved.then(function () { return findAndClearHandle(handle) && cb(); });
  1659. return handle;
  1660. },
  1661. clearImmediate: function (handle) {
  1662. findAndClearHandle(handle);
  1663. },
  1664. };
  1665. var setImmediate = Immediate.setImmediate, clearImmediate = Immediate.clearImmediate;
  1666. var immediateProvider = {
  1667. setImmediate: function () {
  1668. var args = [];
  1669. for (var _i = 0; _i < arguments.length; _i++) {
  1670. args[_i] = arguments[_i];
  1671. }
  1672. var delegate = immediateProvider.delegate;
  1673. return ((delegate === null || delegate === void 0 ? void 0 : delegate.setImmediate) || setImmediate).apply(void 0, __spreadArray([], __read(args)));
  1674. },
  1675. clearImmediate: function (handle) {
  1676. var delegate = immediateProvider.delegate;
  1677. return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearImmediate) || clearImmediate)(handle);
  1678. },
  1679. delegate: undefined,
  1680. };
  1681. var AsapAction = (function (_super) {
  1682. __extends(AsapAction, _super);
  1683. function AsapAction(scheduler, work) {
  1684. var _this = _super.call(this, scheduler, work) || this;
  1685. _this.scheduler = scheduler;
  1686. _this.work = work;
  1687. return _this;
  1688. }
  1689. AsapAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1690. if (delay === void 0) { delay = 0; }
  1691. if (delay !== null && delay > 0) {
  1692. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1693. }
  1694. scheduler.actions.push(this);
  1695. return scheduler._scheduled || (scheduler._scheduled = immediateProvider.setImmediate(scheduler.flush.bind(scheduler, undefined)));
  1696. };
  1697. AsapAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1698. var _a;
  1699. if (delay === void 0) { delay = 0; }
  1700. if (delay != null ? delay > 0 : this.delay > 0) {
  1701. return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
  1702. }
  1703. var actions = scheduler.actions;
  1704. if (id != null && ((_a = actions[actions.length - 1]) === null || _a === void 0 ? void 0 : _a.id) !== id) {
  1705. immediateProvider.clearImmediate(id);
  1706. if (scheduler._scheduled === id) {
  1707. scheduler._scheduled = undefined;
  1708. }
  1709. }
  1710. return undefined;
  1711. };
  1712. return AsapAction;
  1713. }(AsyncAction));
  1714. var Scheduler = (function () {
  1715. function Scheduler(schedulerActionCtor, now) {
  1716. if (now === void 0) { now = Scheduler.now; }
  1717. this.schedulerActionCtor = schedulerActionCtor;
  1718. this.now = now;
  1719. }
  1720. Scheduler.prototype.schedule = function (work, delay, state) {
  1721. if (delay === void 0) { delay = 0; }
  1722. return new this.schedulerActionCtor(this, work).schedule(state, delay);
  1723. };
  1724. Scheduler.now = dateTimestampProvider.now;
  1725. return Scheduler;
  1726. }());
  1727. var AsyncScheduler = (function (_super) {
  1728. __extends(AsyncScheduler, _super);
  1729. function AsyncScheduler(SchedulerAction, now) {
  1730. if (now === void 0) { now = Scheduler.now; }
  1731. var _this = _super.call(this, SchedulerAction, now) || this;
  1732. _this.actions = [];
  1733. _this._active = false;
  1734. return _this;
  1735. }
  1736. AsyncScheduler.prototype.flush = function (action) {
  1737. var actions = this.actions;
  1738. if (this._active) {
  1739. actions.push(action);
  1740. return;
  1741. }
  1742. var error;
  1743. this._active = true;
  1744. do {
  1745. if ((error = action.execute(action.state, action.delay))) {
  1746. break;
  1747. }
  1748. } while ((action = actions.shift()));
  1749. this._active = false;
  1750. if (error) {
  1751. while ((action = actions.shift())) {
  1752. action.unsubscribe();
  1753. }
  1754. throw error;
  1755. }
  1756. };
  1757. return AsyncScheduler;
  1758. }(Scheduler));
  1759. var AsapScheduler = (function (_super) {
  1760. __extends(AsapScheduler, _super);
  1761. function AsapScheduler() {
  1762. return _super !== null && _super.apply(this, arguments) || this;
  1763. }
  1764. AsapScheduler.prototype.flush = function (action) {
  1765. this._active = true;
  1766. var flushId = this._scheduled;
  1767. this._scheduled = undefined;
  1768. var actions = this.actions;
  1769. var error;
  1770. action = action || actions.shift();
  1771. do {
  1772. if ((error = action.execute(action.state, action.delay))) {
  1773. break;
  1774. }
  1775. } while ((action = actions[0]) && action.id === flushId && actions.shift());
  1776. this._active = false;
  1777. if (error) {
  1778. while ((action = actions[0]) && action.id === flushId && actions.shift()) {
  1779. action.unsubscribe();
  1780. }
  1781. throw error;
  1782. }
  1783. };
  1784. return AsapScheduler;
  1785. }(AsyncScheduler));
  1786. var asapScheduler = new AsapScheduler(AsapAction);
  1787. var asap = asapScheduler;
  1788. var asyncScheduler = new AsyncScheduler(AsyncAction);
  1789. var async = asyncScheduler;
  1790. var QueueAction = (function (_super) {
  1791. __extends(QueueAction, _super);
  1792. function QueueAction(scheduler, work) {
  1793. var _this = _super.call(this, scheduler, work) || this;
  1794. _this.scheduler = scheduler;
  1795. _this.work = work;
  1796. return _this;
  1797. }
  1798. QueueAction.prototype.schedule = function (state, delay) {
  1799. if (delay === void 0) { delay = 0; }
  1800. if (delay > 0) {
  1801. return _super.prototype.schedule.call(this, state, delay);
  1802. }
  1803. this.delay = delay;
  1804. this.state = state;
  1805. this.scheduler.flush(this);
  1806. return this;
  1807. };
  1808. QueueAction.prototype.execute = function (state, delay) {
  1809. return delay > 0 || this.closed ? _super.prototype.execute.call(this, state, delay) : this._execute(state, delay);
  1810. };
  1811. QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1812. if (delay === void 0) { delay = 0; }
  1813. if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {
  1814. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1815. }
  1816. scheduler.flush(this);
  1817. return 0;
  1818. };
  1819. return QueueAction;
  1820. }(AsyncAction));
  1821. var QueueScheduler = (function (_super) {
  1822. __extends(QueueScheduler, _super);
  1823. function QueueScheduler() {
  1824. return _super !== null && _super.apply(this, arguments) || this;
  1825. }
  1826. return QueueScheduler;
  1827. }(AsyncScheduler));
  1828. var queueScheduler = new QueueScheduler(QueueAction);
  1829. var queue = queueScheduler;
  1830. var AnimationFrameAction = (function (_super) {
  1831. __extends(AnimationFrameAction, _super);
  1832. function AnimationFrameAction(scheduler, work) {
  1833. var _this = _super.call(this, scheduler, work) || this;
  1834. _this.scheduler = scheduler;
  1835. _this.work = work;
  1836. return _this;
  1837. }
  1838. AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1839. if (delay === void 0) { delay = 0; }
  1840. if (delay !== null && delay > 0) {
  1841. return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
  1842. }
  1843. scheduler.actions.push(this);
  1844. return scheduler._scheduled || (scheduler._scheduled = animationFrameProvider.requestAnimationFrame(function () { return scheduler.flush(undefined); }));
  1845. };
  1846. AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1847. var _a;
  1848. if (delay === void 0) { delay = 0; }
  1849. if (delay != null ? delay > 0 : this.delay > 0) {
  1850. return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
  1851. }
  1852. var actions = scheduler.actions;
  1853. if (id != null && ((_a = actions[actions.length - 1]) === null || _a === void 0 ? void 0 : _a.id) !== id) {
  1854. animationFrameProvider.cancelAnimationFrame(id);
  1855. scheduler._scheduled = undefined;
  1856. }
  1857. return undefined;
  1858. };
  1859. return AnimationFrameAction;
  1860. }(AsyncAction));
  1861. var AnimationFrameScheduler = (function (_super) {
  1862. __extends(AnimationFrameScheduler, _super);
  1863. function AnimationFrameScheduler() {
  1864. return _super !== null && _super.apply(this, arguments) || this;
  1865. }
  1866. AnimationFrameScheduler.prototype.flush = function (action) {
  1867. this._active = true;
  1868. var flushId = this._scheduled;
  1869. this._scheduled = undefined;
  1870. var actions = this.actions;
  1871. var error;
  1872. action = action || actions.shift();
  1873. do {
  1874. if ((error = action.execute(action.state, action.delay))) {
  1875. break;
  1876. }
  1877. } while ((action = actions[0]) && action.id === flushId && actions.shift());
  1878. this._active = false;
  1879. if (error) {
  1880. while ((action = actions[0]) && action.id === flushId && actions.shift()) {
  1881. action.unsubscribe();
  1882. }
  1883. throw error;
  1884. }
  1885. };
  1886. return AnimationFrameScheduler;
  1887. }(AsyncScheduler));
  1888. var animationFrameScheduler = new AnimationFrameScheduler(AnimationFrameAction);
  1889. var animationFrame = animationFrameScheduler;
  1890. var VirtualTimeScheduler = (function (_super) {
  1891. __extends(VirtualTimeScheduler, _super);
  1892. function VirtualTimeScheduler(schedulerActionCtor, maxFrames) {
  1893. if (schedulerActionCtor === void 0) { schedulerActionCtor = VirtualAction; }
  1894. if (maxFrames === void 0) { maxFrames = Infinity; }
  1895. var _this = _super.call(this, schedulerActionCtor, function () { return _this.frame; }) || this;
  1896. _this.maxFrames = maxFrames;
  1897. _this.frame = 0;
  1898. _this.index = -1;
  1899. return _this;
  1900. }
  1901. VirtualTimeScheduler.prototype.flush = function () {
  1902. var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
  1903. var error;
  1904. var action;
  1905. while ((action = actions[0]) && action.delay <= maxFrames) {
  1906. actions.shift();
  1907. this.frame = action.delay;
  1908. if ((error = action.execute(action.state, action.delay))) {
  1909. break;
  1910. }
  1911. }
  1912. if (error) {
  1913. while ((action = actions.shift())) {
  1914. action.unsubscribe();
  1915. }
  1916. throw error;
  1917. }
  1918. };
  1919. VirtualTimeScheduler.frameTimeFactor = 10;
  1920. return VirtualTimeScheduler;
  1921. }(AsyncScheduler));
  1922. var VirtualAction = (function (_super) {
  1923. __extends(VirtualAction, _super);
  1924. function VirtualAction(scheduler, work, index) {
  1925. if (index === void 0) { index = (scheduler.index += 1); }
  1926. var _this = _super.call(this, scheduler, work) || this;
  1927. _this.scheduler = scheduler;
  1928. _this.work = work;
  1929. _this.index = index;
  1930. _this.active = true;
  1931. _this.index = scheduler.index = index;
  1932. return _this;
  1933. }
  1934. VirtualAction.prototype.schedule = function (state, delay) {
  1935. if (delay === void 0) { delay = 0; }
  1936. if (Number.isFinite(delay)) {
  1937. if (!this.id) {
  1938. return _super.prototype.schedule.call(this, state, delay);
  1939. }
  1940. this.active = false;
  1941. var action = new VirtualAction(this.scheduler, this.work);
  1942. this.add(action);
  1943. return action.schedule(state, delay);
  1944. }
  1945. else {
  1946. return Subscription.EMPTY;
  1947. }
  1948. };
  1949. VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  1950. if (delay === void 0) { delay = 0; }
  1951. this.delay = scheduler.frame + delay;
  1952. var actions = scheduler.actions;
  1953. actions.push(this);
  1954. actions.sort(VirtualAction.sortActions);
  1955. return 1;
  1956. };
  1957. VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  1958. if (delay === void 0) { delay = 0; }
  1959. return undefined;
  1960. };
  1961. VirtualAction.prototype._execute = function (state, delay) {
  1962. if (this.active === true) {
  1963. return _super.prototype._execute.call(this, state, delay);
  1964. }
  1965. };
  1966. VirtualAction.sortActions = function (a, b) {
  1967. if (a.delay === b.delay) {
  1968. if (a.index === b.index) {
  1969. return 0;
  1970. }
  1971. else if (a.index > b.index) {
  1972. return 1;
  1973. }
  1974. else {
  1975. return -1;
  1976. }
  1977. }
  1978. else if (a.delay > b.delay) {
  1979. return 1;
  1980. }
  1981. else {
  1982. return -1;
  1983. }
  1984. };
  1985. return VirtualAction;
  1986. }(AsyncAction));
  1987. var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
  1988. function empty(scheduler) {
  1989. return scheduler ? emptyScheduled(scheduler) : EMPTY;
  1990. }
  1991. function emptyScheduled(scheduler) {
  1992. return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
  1993. }
  1994. function isScheduler(value) {
  1995. return value && isFunction(value.schedule);
  1996. }
  1997. function last(arr) {
  1998. return arr[arr.length - 1];
  1999. }
  2000. function popResultSelector(args) {
  2001. return isFunction(last(args)) ? args.pop() : undefined;
  2002. }
  2003. function popScheduler(args) {
  2004. return isScheduler(last(args)) ? args.pop() : undefined;
  2005. }
  2006. function popNumber(args, defaultValue) {
  2007. return typeof last(args) === 'number' ? args.pop() : defaultValue;
  2008. }
  2009. var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
  2010. function isPromise(value) {
  2011. return isFunction(value === null || value === void 0 ? void 0 : value.then);
  2012. }
  2013. function isInteropObservable(input) {
  2014. return isFunction(input[observable]);
  2015. }
  2016. function isAsyncIterable(obj) {
  2017. return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
  2018. }
  2019. function createInvalidObservableTypeError(input) {
  2020. return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
  2021. }
  2022. function getSymbolIterator() {
  2023. if (typeof Symbol !== 'function' || !Symbol.iterator) {
  2024. return '@@iterator';
  2025. }
  2026. return Symbol.iterator;
  2027. }
  2028. var iterator = getSymbolIterator();
  2029. function isIterable(input) {
  2030. return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
  2031. }
  2032. function readableStreamLikeToAsyncGenerator(readableStream) {
  2033. return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
  2034. var reader, _a, value, done;
  2035. return __generator(this, function (_b) {
  2036. switch (_b.label) {
  2037. case 0:
  2038. reader = readableStream.getReader();
  2039. _b.label = 1;
  2040. case 1:
  2041. _b.trys.push([1, , 9, 10]);
  2042. _b.label = 2;
  2043. case 2:
  2044. return [4, __await(reader.read())];
  2045. case 3:
  2046. _a = _b.sent(), value = _a.value, done = _a.done;
  2047. if (!done) return [3, 5];
  2048. return [4, __await(void 0)];
  2049. case 4: return [2, _b.sent()];
  2050. case 5: return [4, __await(value)];
  2051. case 6: return [4, _b.sent()];
  2052. case 7:
  2053. _b.sent();
  2054. return [3, 2];
  2055. case 8: return [3, 10];
  2056. case 9:
  2057. reader.releaseLock();
  2058. return [7];
  2059. case 10: return [2];
  2060. }
  2061. });
  2062. });
  2063. }
  2064. function isReadableStreamLike(obj) {
  2065. return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
  2066. }
  2067. function innerFrom(input) {
  2068. if (input instanceof Observable) {
  2069. return input;
  2070. }
  2071. if (input != null) {
  2072. if (isInteropObservable(input)) {
  2073. return fromInteropObservable(input);
  2074. }
  2075. if (isArrayLike(input)) {
  2076. return fromArrayLike(input);
  2077. }
  2078. if (isPromise(input)) {
  2079. return fromPromise(input);
  2080. }
  2081. if (isAsyncIterable(input)) {
  2082. return fromAsyncIterable(input);
  2083. }
  2084. if (isIterable(input)) {
  2085. return fromIterable(input);
  2086. }
  2087. if (isReadableStreamLike(input)) {
  2088. return fromReadableStreamLike(input);
  2089. }
  2090. }
  2091. throw createInvalidObservableTypeError(input);
  2092. }
  2093. function fromInteropObservable(obj) {
  2094. return new Observable(function (subscriber) {
  2095. var obs = obj[observable]();
  2096. if (isFunction(obs.subscribe)) {
  2097. return obs.subscribe(subscriber);
  2098. }
  2099. throw new TypeError('Provided object does not correctly implement Symbol.observable');
  2100. });
  2101. }
  2102. function fromArrayLike(array) {
  2103. return new Observable(function (subscriber) {
  2104. for (var i = 0; i < array.length && !subscriber.closed; i++) {
  2105. subscriber.next(array[i]);
  2106. }
  2107. subscriber.complete();
  2108. });
  2109. }
  2110. function fromPromise(promise) {
  2111. return new Observable(function (subscriber) {
  2112. promise
  2113. .then(function (value) {
  2114. if (!subscriber.closed) {
  2115. subscriber.next(value);
  2116. subscriber.complete();
  2117. }
  2118. }, function (err) { return subscriber.error(err); })
  2119. .then(null, reportUnhandledError);
  2120. });
  2121. }
  2122. function fromIterable(iterable) {
  2123. return new Observable(function (subscriber) {
  2124. var e_1, _a;
  2125. try {
  2126. for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
  2127. var value = iterable_1_1.value;
  2128. subscriber.next(value);
  2129. if (subscriber.closed) {
  2130. return;
  2131. }
  2132. }
  2133. }
  2134. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2135. finally {
  2136. try {
  2137. if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
  2138. }
  2139. finally { if (e_1) throw e_1.error; }
  2140. }
  2141. subscriber.complete();
  2142. });
  2143. }
  2144. function fromAsyncIterable(asyncIterable) {
  2145. return new Observable(function (subscriber) {
  2146. process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
  2147. });
  2148. }
  2149. function fromReadableStreamLike(readableStream) {
  2150. return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
  2151. }
  2152. function process(asyncIterable, subscriber) {
  2153. var asyncIterable_1, asyncIterable_1_1;
  2154. var e_2, _a;
  2155. return __awaiter(this, void 0, void 0, function () {
  2156. var value, e_2_1;
  2157. return __generator(this, function (_b) {
  2158. switch (_b.label) {
  2159. case 0:
  2160. _b.trys.push([0, 5, 6, 11]);
  2161. asyncIterable_1 = __asyncValues(asyncIterable);
  2162. _b.label = 1;
  2163. case 1: return [4, asyncIterable_1.next()];
  2164. case 2:
  2165. if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
  2166. value = asyncIterable_1_1.value;
  2167. subscriber.next(value);
  2168. if (subscriber.closed) {
  2169. return [2];
  2170. }
  2171. _b.label = 3;
  2172. case 3: return [3, 1];
  2173. case 4: return [3, 11];
  2174. case 5:
  2175. e_2_1 = _b.sent();
  2176. e_2 = { error: e_2_1 };
  2177. return [3, 11];
  2178. case 6:
  2179. _b.trys.push([6, , 9, 10]);
  2180. if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
  2181. return [4, _a.call(asyncIterable_1)];
  2182. case 7:
  2183. _b.sent();
  2184. _b.label = 8;
  2185. case 8: return [3, 10];
  2186. case 9:
  2187. if (e_2) throw e_2.error;
  2188. return [7];
  2189. case 10: return [7];
  2190. case 11:
  2191. subscriber.complete();
  2192. return [2];
  2193. }
  2194. });
  2195. });
  2196. }
  2197. function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
  2198. if (delay === void 0) { delay = 0; }
  2199. if (repeat === void 0) { repeat = false; }
  2200. var scheduleSubscription = scheduler.schedule(function () {
  2201. work();
  2202. if (repeat) {
  2203. parentSubscription.add(this.schedule(null, delay));
  2204. }
  2205. else {
  2206. this.unsubscribe();
  2207. }
  2208. }, delay);
  2209. parentSubscription.add(scheduleSubscription);
  2210. if (!repeat) {
  2211. return scheduleSubscription;
  2212. }
  2213. }
  2214. function observeOn(scheduler, delay) {
  2215. if (delay === void 0) { delay = 0; }
  2216. return operate(function (source, subscriber) {
  2217. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
  2218. });
  2219. }
  2220. function subscribeOn(scheduler, delay) {
  2221. if (delay === void 0) { delay = 0; }
  2222. return operate(function (source, subscriber) {
  2223. subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
  2224. });
  2225. }
  2226. function scheduleObservable(input, scheduler) {
  2227. return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
  2228. }
  2229. function schedulePromise(input, scheduler) {
  2230. return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
  2231. }
  2232. function scheduleArray(input, scheduler) {
  2233. return new Observable(function (subscriber) {
  2234. var i = 0;
  2235. return scheduler.schedule(function () {
  2236. if (i === input.length) {
  2237. subscriber.complete();
  2238. }
  2239. else {
  2240. subscriber.next(input[i++]);
  2241. if (!subscriber.closed) {
  2242. this.schedule();
  2243. }
  2244. }
  2245. });
  2246. });
  2247. }
  2248. function scheduleIterable(input, scheduler) {
  2249. return new Observable(function (subscriber) {
  2250. var iterator$$1;
  2251. executeSchedule(subscriber, scheduler, function () {
  2252. iterator$$1 = input[iterator]();
  2253. executeSchedule(subscriber, scheduler, function () {
  2254. var _a;
  2255. var value;
  2256. var done;
  2257. try {
  2258. (_a = iterator$$1.next(), value = _a.value, done = _a.done);
  2259. }
  2260. catch (err) {
  2261. subscriber.error(err);
  2262. return;
  2263. }
  2264. if (done) {
  2265. subscriber.complete();
  2266. }
  2267. else {
  2268. subscriber.next(value);
  2269. }
  2270. }, 0, true);
  2271. });
  2272. return function () { return isFunction(iterator$$1 === null || iterator$$1 === void 0 ? void 0 : iterator$$1.return) && iterator$$1.return(); };
  2273. });
  2274. }
  2275. function scheduleAsyncIterable(input, scheduler) {
  2276. if (!input) {
  2277. throw new Error('Iterable cannot be null');
  2278. }
  2279. return new Observable(function (subscriber) {
  2280. executeSchedule(subscriber, scheduler, function () {
  2281. var iterator = input[Symbol.asyncIterator]();
  2282. executeSchedule(subscriber, scheduler, function () {
  2283. iterator.next().then(function (result) {
  2284. if (result.done) {
  2285. subscriber.complete();
  2286. }
  2287. else {
  2288. subscriber.next(result.value);
  2289. }
  2290. });
  2291. }, 0, true);
  2292. });
  2293. });
  2294. }
  2295. function scheduleReadableStreamLike(input, scheduler) {
  2296. return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
  2297. }
  2298. function scheduled(input, scheduler) {
  2299. if (input != null) {
  2300. if (isInteropObservable(input)) {
  2301. return scheduleObservable(input, scheduler);
  2302. }
  2303. if (isArrayLike(input)) {
  2304. return scheduleArray(input, scheduler);
  2305. }
  2306. if (isPromise(input)) {
  2307. return schedulePromise(input, scheduler);
  2308. }
  2309. if (isAsyncIterable(input)) {
  2310. return scheduleAsyncIterable(input, scheduler);
  2311. }
  2312. if (isIterable(input)) {
  2313. return scheduleIterable(input, scheduler);
  2314. }
  2315. if (isReadableStreamLike(input)) {
  2316. return scheduleReadableStreamLike(input, scheduler);
  2317. }
  2318. }
  2319. throw createInvalidObservableTypeError(input);
  2320. }
  2321. function from(input, scheduler) {
  2322. return scheduler ? scheduled(input, scheduler) : innerFrom(input);
  2323. }
  2324. function of() {
  2325. var args = [];
  2326. for (var _i = 0; _i < arguments.length; _i++) {
  2327. args[_i] = arguments[_i];
  2328. }
  2329. var scheduler = popScheduler(args);
  2330. return from(args, scheduler);
  2331. }
  2332. function throwError(errorOrErrorFactory, scheduler) {
  2333. var errorFactory = isFunction(errorOrErrorFactory) ? errorOrErrorFactory : function () { return errorOrErrorFactory; };
  2334. var init = function (subscriber) { return subscriber.error(errorFactory()); };
  2335. return new Observable(scheduler ? function (subscriber) { return scheduler.schedule(init, 0, subscriber); } : init);
  2336. }
  2337. (function (NotificationKind) {
  2338. NotificationKind["NEXT"] = "N";
  2339. NotificationKind["ERROR"] = "E";
  2340. NotificationKind["COMPLETE"] = "C";
  2341. })(exports.NotificationKind || (exports.NotificationKind = {}));
  2342. var Notification = (function () {
  2343. function Notification(kind, value, error) {
  2344. this.kind = kind;
  2345. this.value = value;
  2346. this.error = error;
  2347. this.hasValue = kind === 'N';
  2348. }
  2349. Notification.prototype.observe = function (observer) {
  2350. return observeNotification(this, observer);
  2351. };
  2352. Notification.prototype.do = function (nextHandler, errorHandler, completeHandler) {
  2353. var _a = this, kind = _a.kind, value = _a.value, error = _a.error;
  2354. return kind === 'N' ? nextHandler === null || nextHandler === void 0 ? void 0 : nextHandler(value) : kind === 'E' ? errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(error) : completeHandler === null || completeHandler === void 0 ? void 0 : completeHandler();
  2355. };
  2356. Notification.prototype.accept = function (nextOrObserver, error, complete) {
  2357. var _a;
  2358. return isFunction((_a = nextOrObserver) === null || _a === void 0 ? void 0 : _a.next)
  2359. ? this.observe(nextOrObserver)
  2360. : this.do(nextOrObserver, error, complete);
  2361. };
  2362. Notification.prototype.toObservable = function () {
  2363. var _a = this, kind = _a.kind, value = _a.value, error = _a.error;
  2364. var result = kind === 'N'
  2365. ?
  2366. of(value)
  2367. :
  2368. kind === 'E'
  2369. ?
  2370. throwError(function () { return error; })
  2371. :
  2372. kind === 'C'
  2373. ?
  2374. EMPTY
  2375. :
  2376. 0;
  2377. if (!result) {
  2378. throw new TypeError("Unexpected notification kind " + kind);
  2379. }
  2380. return result;
  2381. };
  2382. Notification.createNext = function (value) {
  2383. return new Notification('N', value);
  2384. };
  2385. Notification.createError = function (err) {
  2386. return new Notification('E', undefined, err);
  2387. };
  2388. Notification.createComplete = function () {
  2389. return Notification.completeNotification;
  2390. };
  2391. Notification.completeNotification = new Notification('C');
  2392. return Notification;
  2393. }());
  2394. function observeNotification(notification, observer) {
  2395. var _a, _b, _c;
  2396. var _d = notification, kind = _d.kind, value = _d.value, error = _d.error;
  2397. if (typeof kind !== 'string') {
  2398. throw new TypeError('Invalid notification, missing "kind"');
  2399. }
  2400. kind === 'N' ? (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, value) : kind === 'E' ? (_b = observer.error) === null || _b === void 0 ? void 0 : _b.call(observer, error) : (_c = observer.complete) === null || _c === void 0 ? void 0 : _c.call(observer);
  2401. }
  2402. function isObservable(obj) {
  2403. return !!obj && (obj instanceof Observable || (isFunction(obj.lift) && isFunction(obj.subscribe)));
  2404. }
  2405. var EmptyError = createErrorClass(function (_super) { return function EmptyErrorImpl() {
  2406. _super(this);
  2407. this.name = 'EmptyError';
  2408. this.message = 'no elements in sequence';
  2409. }; });
  2410. function lastValueFrom(source, config) {
  2411. var hasConfig = typeof config === 'object';
  2412. return new Promise(function (resolve, reject) {
  2413. var _hasValue = false;
  2414. var _value;
  2415. source.subscribe({
  2416. next: function (value) {
  2417. _value = value;
  2418. _hasValue = true;
  2419. },
  2420. error: reject,
  2421. complete: function () {
  2422. if (_hasValue) {
  2423. resolve(_value);
  2424. }
  2425. else if (hasConfig) {
  2426. resolve(config.defaultValue);
  2427. }
  2428. else {
  2429. reject(new EmptyError());
  2430. }
  2431. },
  2432. });
  2433. });
  2434. }
  2435. function firstValueFrom(source, config) {
  2436. var hasConfig = typeof config === 'object';
  2437. return new Promise(function (resolve, reject) {
  2438. var subscriber = new SafeSubscriber({
  2439. next: function (value) {
  2440. resolve(value);
  2441. subscriber.unsubscribe();
  2442. },
  2443. error: reject,
  2444. complete: function () {
  2445. if (hasConfig) {
  2446. resolve(config.defaultValue);
  2447. }
  2448. else {
  2449. reject(new EmptyError());
  2450. }
  2451. },
  2452. });
  2453. source.subscribe(subscriber);
  2454. });
  2455. }
  2456. var ArgumentOutOfRangeError = createErrorClass(function (_super) {
  2457. return function ArgumentOutOfRangeErrorImpl() {
  2458. _super(this);
  2459. this.name = 'ArgumentOutOfRangeError';
  2460. this.message = 'argument out of range';
  2461. };
  2462. });
  2463. var NotFoundError = createErrorClass(function (_super) {
  2464. return function NotFoundErrorImpl(message) {
  2465. _super(this);
  2466. this.name = 'NotFoundError';
  2467. this.message = message;
  2468. };
  2469. });
  2470. var SequenceError = createErrorClass(function (_super) {
  2471. return function SequenceErrorImpl(message) {
  2472. _super(this);
  2473. this.name = 'SequenceError';
  2474. this.message = message;
  2475. };
  2476. });
  2477. function isValidDate(value) {
  2478. return value instanceof Date && !isNaN(value);
  2479. }
  2480. var TimeoutError = createErrorClass(function (_super) {
  2481. return function TimeoutErrorImpl(info) {
  2482. if (info === void 0) { info = null; }
  2483. _super(this);
  2484. this.message = 'Timeout has occurred';
  2485. this.name = 'TimeoutError';
  2486. this.info = info;
  2487. };
  2488. });
  2489. function timeout(config, schedulerArg) {
  2490. var _a = (isValidDate(config) ? { first: config } : typeof config === 'number' ? { each: config } : config), first = _a.first, each = _a.each, _b = _a.with, _with = _b === void 0 ? timeoutErrorFactory : _b, _c = _a.scheduler, scheduler = _c === void 0 ? schedulerArg !== null && schedulerArg !== void 0 ? schedulerArg : asyncScheduler : _c, _d = _a.meta, meta = _d === void 0 ? null : _d;
  2491. if (first == null && each == null) {
  2492. throw new TypeError('No timeout provided.');
  2493. }
  2494. return operate(function (source, subscriber) {
  2495. var originalSourceSubscription;
  2496. var timerSubscription;
  2497. var lastValue = null;
  2498. var seen = 0;
  2499. var startTimer = function (delay) {
  2500. timerSubscription = executeSchedule(subscriber, scheduler, function () {
  2501. try {
  2502. originalSourceSubscription.unsubscribe();
  2503. innerFrom(_with({
  2504. meta: meta,
  2505. lastValue: lastValue,
  2506. seen: seen,
  2507. })).subscribe(subscriber);
  2508. }
  2509. catch (err) {
  2510. subscriber.error(err);
  2511. }
  2512. }, delay);
  2513. };
  2514. originalSourceSubscription = source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  2515. timerSubscription === null || timerSubscription === void 0 ? void 0 : timerSubscription.unsubscribe();
  2516. seen++;
  2517. subscriber.next((lastValue = value));
  2518. each > 0 && startTimer(each);
  2519. }, undefined, undefined, function () {
  2520. if (!(timerSubscription === null || timerSubscription === void 0 ? void 0 : timerSubscription.closed)) {
  2521. timerSubscription === null || timerSubscription === void 0 ? void 0 : timerSubscription.unsubscribe();
  2522. }
  2523. lastValue = null;
  2524. }));
  2525. !seen && startTimer(first != null ? (typeof first === 'number' ? first : +first - scheduler.now()) : each);
  2526. });
  2527. }
  2528. function timeoutErrorFactory(info) {
  2529. throw new TimeoutError(info);
  2530. }
  2531. function map(project, thisArg) {
  2532. return operate(function (source, subscriber) {
  2533. var index = 0;
  2534. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  2535. subscriber.next(project.call(thisArg, value, index++));
  2536. }));
  2537. });
  2538. }
  2539. var isArray = Array.isArray;
  2540. function callOrApply(fn, args) {
  2541. return isArray(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
  2542. }
  2543. function mapOneOrManyArgs(fn) {
  2544. return map(function (args) { return callOrApply(fn, args); });
  2545. }
  2546. function bindCallbackInternals(isNodeStyle, callbackFunc, resultSelector, scheduler) {
  2547. if (resultSelector) {
  2548. if (isScheduler(resultSelector)) {
  2549. scheduler = resultSelector;
  2550. }
  2551. else {
  2552. return function () {
  2553. var args = [];
  2554. for (var _i = 0; _i < arguments.length; _i++) {
  2555. args[_i] = arguments[_i];
  2556. }
  2557. return bindCallbackInternals(isNodeStyle, callbackFunc, scheduler)
  2558. .apply(this, args)
  2559. .pipe(mapOneOrManyArgs(resultSelector));
  2560. };
  2561. }
  2562. }
  2563. if (scheduler) {
  2564. return function () {
  2565. var args = [];
  2566. for (var _i = 0; _i < arguments.length; _i++) {
  2567. args[_i] = arguments[_i];
  2568. }
  2569. return bindCallbackInternals(isNodeStyle, callbackFunc)
  2570. .apply(this, args)
  2571. .pipe(subscribeOn(scheduler), observeOn(scheduler));
  2572. };
  2573. }
  2574. return function () {
  2575. var _this = this;
  2576. var args = [];
  2577. for (var _i = 0; _i < arguments.length; _i++) {
  2578. args[_i] = arguments[_i];
  2579. }
  2580. var subject = new AsyncSubject();
  2581. var uninitialized = true;
  2582. return new Observable(function (subscriber) {
  2583. var subs = subject.subscribe(subscriber);
  2584. if (uninitialized) {
  2585. uninitialized = false;
  2586. var isAsync_1 = false;
  2587. var isComplete_1 = false;
  2588. callbackFunc.apply(_this, __spreadArray(__spreadArray([], __read(args)), [
  2589. function () {
  2590. var results = [];
  2591. for (var _i = 0; _i < arguments.length; _i++) {
  2592. results[_i] = arguments[_i];
  2593. }
  2594. if (isNodeStyle) {
  2595. var err = results.shift();
  2596. if (err != null) {
  2597. subject.error(err);
  2598. return;
  2599. }
  2600. }
  2601. subject.next(1 < results.length ? results : results[0]);
  2602. isComplete_1 = true;
  2603. if (isAsync_1) {
  2604. subject.complete();
  2605. }
  2606. },
  2607. ]));
  2608. if (isComplete_1) {
  2609. subject.complete();
  2610. }
  2611. isAsync_1 = true;
  2612. }
  2613. return subs;
  2614. });
  2615. };
  2616. }
  2617. function bindCallback(callbackFunc, resultSelector, scheduler) {
  2618. return bindCallbackInternals(false, callbackFunc, resultSelector, scheduler);
  2619. }
  2620. function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
  2621. return bindCallbackInternals(true, callbackFunc, resultSelector, scheduler);
  2622. }
  2623. var isArray$1 = Array.isArray;
  2624. var getPrototypeOf = Object.getPrototypeOf, objectProto = Object.prototype, getKeys = Object.keys;
  2625. function argsArgArrayOrObject(args) {
  2626. if (args.length === 1) {
  2627. var first_1 = args[0];
  2628. if (isArray$1(first_1)) {
  2629. return { args: first_1, keys: null };
  2630. }
  2631. if (isPOJO(first_1)) {
  2632. var keys = getKeys(first_1);
  2633. return {
  2634. args: keys.map(function (key) { return first_1[key]; }),
  2635. keys: keys,
  2636. };
  2637. }
  2638. }
  2639. return { args: args, keys: null };
  2640. }
  2641. function isPOJO(obj) {
  2642. return obj && typeof obj === 'object' && getPrototypeOf(obj) === objectProto;
  2643. }
  2644. function createObject(keys, values) {
  2645. return keys.reduce(function (result, key, i) { return ((result[key] = values[i]), result); }, {});
  2646. }
  2647. function combineLatest() {
  2648. var args = [];
  2649. for (var _i = 0; _i < arguments.length; _i++) {
  2650. args[_i] = arguments[_i];
  2651. }
  2652. var scheduler = popScheduler(args);
  2653. var resultSelector = popResultSelector(args);
  2654. var _a = argsArgArrayOrObject(args), observables = _a.args, keys = _a.keys;
  2655. if (observables.length === 0) {
  2656. return from([], scheduler);
  2657. }
  2658. var result = new Observable(combineLatestInit(observables, scheduler, keys
  2659. ?
  2660. function (values) { return createObject(keys, values); }
  2661. :
  2662. identity));
  2663. return resultSelector ? result.pipe(mapOneOrManyArgs(resultSelector)) : result;
  2664. }
  2665. function combineLatestInit(observables, scheduler, valueTransform) {
  2666. if (valueTransform === void 0) { valueTransform = identity; }
  2667. return function (subscriber) {
  2668. maybeSchedule(scheduler, function () {
  2669. var length = observables.length;
  2670. var values = new Array(length);
  2671. var active = length;
  2672. var remainingFirstValues = length;
  2673. var _loop_1 = function (i) {
  2674. maybeSchedule(scheduler, function () {
  2675. var source = from(observables[i], scheduler);
  2676. var hasFirstValue = false;
  2677. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  2678. values[i] = value;
  2679. if (!hasFirstValue) {
  2680. hasFirstValue = true;
  2681. remainingFirstValues--;
  2682. }
  2683. if (!remainingFirstValues) {
  2684. subscriber.next(valueTransform(values.slice()));
  2685. }
  2686. }, function () {
  2687. if (!--active) {
  2688. subscriber.complete();
  2689. }
  2690. }));
  2691. }, subscriber);
  2692. };
  2693. for (var i = 0; i < length; i++) {
  2694. _loop_1(i);
  2695. }
  2696. }, subscriber);
  2697. };
  2698. }
  2699. function maybeSchedule(scheduler, execute, subscription) {
  2700. if (scheduler) {
  2701. executeSchedule(subscription, scheduler, execute);
  2702. }
  2703. else {
  2704. execute();
  2705. }
  2706. }
  2707. function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
  2708. var buffer = [];
  2709. var active = 0;
  2710. var index = 0;
  2711. var isComplete = false;
  2712. var checkComplete = function () {
  2713. if (isComplete && !buffer.length && !active) {
  2714. subscriber.complete();
  2715. }
  2716. };
  2717. var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
  2718. var doInnerSub = function (value) {
  2719. expand && subscriber.next(value);
  2720. active++;
  2721. var innerComplete = false;
  2722. innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
  2723. onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
  2724. if (expand) {
  2725. outerNext(innerValue);
  2726. }
  2727. else {
  2728. subscriber.next(innerValue);
  2729. }
  2730. }, function () {
  2731. innerComplete = true;
  2732. }, undefined, function () {
  2733. if (innerComplete) {
  2734. try {
  2735. active--;
  2736. var _loop_1 = function () {
  2737. var bufferedValue = buffer.shift();
  2738. if (innerSubScheduler) {
  2739. executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
  2740. }
  2741. else {
  2742. doInnerSub(bufferedValue);
  2743. }
  2744. };
  2745. while (buffer.length && active < concurrent) {
  2746. _loop_1();
  2747. }
  2748. checkComplete();
  2749. }
  2750. catch (err) {
  2751. subscriber.error(err);
  2752. }
  2753. }
  2754. }));
  2755. };
  2756. source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
  2757. isComplete = true;
  2758. checkComplete();
  2759. }));
  2760. return function () {
  2761. additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
  2762. };
  2763. }
  2764. function mergeMap(project, resultSelector, concurrent) {
  2765. if (concurrent === void 0) { concurrent = Infinity; }
  2766. if (isFunction(resultSelector)) {
  2767. return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
  2768. }
  2769. else if (typeof resultSelector === 'number') {
  2770. concurrent = resultSelector;
  2771. }
  2772. return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
  2773. }
  2774. function mergeAll(concurrent) {
  2775. if (concurrent === void 0) { concurrent = Infinity; }
  2776. return mergeMap(identity, concurrent);
  2777. }
  2778. function concatAll() {
  2779. return mergeAll(1);
  2780. }
  2781. function concat() {
  2782. var args = [];
  2783. for (var _i = 0; _i < arguments.length; _i++) {
  2784. args[_i] = arguments[_i];
  2785. }
  2786. return concatAll()(from(args, popScheduler(args)));
  2787. }
  2788. function defer(observableFactory) {
  2789. return new Observable(function (subscriber) {
  2790. innerFrom(observableFactory()).subscribe(subscriber);
  2791. });
  2792. }
  2793. var DEFAULT_CONFIG = {
  2794. connector: function () { return new Subject(); },
  2795. resetOnDisconnect: true,
  2796. };
  2797. function connectable(source, config) {
  2798. if (config === void 0) { config = DEFAULT_CONFIG; }
  2799. var connection = null;
  2800. var connector = config.connector, _a = config.resetOnDisconnect, resetOnDisconnect = _a === void 0 ? true : _a;
  2801. var subject = connector();
  2802. var result = new Observable(function (subscriber) {
  2803. return subject.subscribe(subscriber);
  2804. });
  2805. result.connect = function () {
  2806. if (!connection || connection.closed) {
  2807. connection = defer(function () { return source; }).subscribe(subject);
  2808. if (resetOnDisconnect) {
  2809. connection.add(function () { return (subject = connector()); });
  2810. }
  2811. }
  2812. return connection;
  2813. };
  2814. return result;
  2815. }
  2816. function forkJoin() {
  2817. var args = [];
  2818. for (var _i = 0; _i < arguments.length; _i++) {
  2819. args[_i] = arguments[_i];
  2820. }
  2821. var resultSelector = popResultSelector(args);
  2822. var _a = argsArgArrayOrObject(args), sources = _a.args, keys = _a.keys;
  2823. var result = new Observable(function (subscriber) {
  2824. var length = sources.length;
  2825. if (!length) {
  2826. subscriber.complete();
  2827. return;
  2828. }
  2829. var values = new Array(length);
  2830. var remainingCompletions = length;
  2831. var remainingEmissions = length;
  2832. var _loop_1 = function (sourceIndex) {
  2833. var hasValue = false;
  2834. innerFrom(sources[sourceIndex]).subscribe(createOperatorSubscriber(subscriber, function (value) {
  2835. if (!hasValue) {
  2836. hasValue = true;
  2837. remainingEmissions--;
  2838. }
  2839. values[sourceIndex] = value;
  2840. }, function () { return remainingCompletions--; }, undefined, function () {
  2841. if (!remainingCompletions || !hasValue) {
  2842. if (!remainingEmissions) {
  2843. subscriber.next(keys ? createObject(keys, values) : values);
  2844. }
  2845. subscriber.complete();
  2846. }
  2847. }));
  2848. };
  2849. for (var sourceIndex = 0; sourceIndex < length; sourceIndex++) {
  2850. _loop_1(sourceIndex);
  2851. }
  2852. });
  2853. return resultSelector ? result.pipe(mapOneOrManyArgs(resultSelector)) : result;
  2854. }
  2855. var nodeEventEmitterMethods = ['addListener', 'removeListener'];
  2856. var eventTargetMethods = ['addEventListener', 'removeEventListener'];
  2857. var jqueryMethods = ['on', 'off'];
  2858. function fromEvent(target, eventName, options, resultSelector) {
  2859. if (isFunction(options)) {
  2860. resultSelector = options;
  2861. options = undefined;
  2862. }
  2863. if (resultSelector) {
  2864. return fromEvent(target, eventName, options).pipe(mapOneOrManyArgs(resultSelector));
  2865. }
  2866. var _a = __read(isEventTarget(target)
  2867. ? eventTargetMethods.map(function (methodName) { return function (handler) { return target[methodName](eventName, handler, options); }; })
  2868. :
  2869. isNodeStyleEventEmitter(target)
  2870. ? nodeEventEmitterMethods.map(toCommonHandlerRegistry(target, eventName))
  2871. : isJQueryStyleEventEmitter(target)
  2872. ? jqueryMethods.map(toCommonHandlerRegistry(target, eventName))
  2873. : [], 2), add = _a[0], remove = _a[1];
  2874. if (!add) {
  2875. if (isArrayLike(target)) {
  2876. return mergeMap(function (subTarget) { return fromEvent(subTarget, eventName, options); })(innerFrom(target));
  2877. }
  2878. }
  2879. if (!add) {
  2880. throw new TypeError('Invalid event target');
  2881. }
  2882. return new Observable(function (subscriber) {
  2883. var handler = function () {
  2884. var args = [];
  2885. for (var _i = 0; _i < arguments.length; _i++) {
  2886. args[_i] = arguments[_i];
  2887. }
  2888. return subscriber.next(1 < args.length ? args : args[0]);
  2889. };
  2890. add(handler);
  2891. return function () { return remove(handler); };
  2892. });
  2893. }
  2894. function toCommonHandlerRegistry(target, eventName) {
  2895. return function (methodName) { return function (handler) { return target[methodName](eventName, handler); }; };
  2896. }
  2897. function isNodeStyleEventEmitter(target) {
  2898. return isFunction(target.addListener) && isFunction(target.removeListener);
  2899. }
  2900. function isJQueryStyleEventEmitter(target) {
  2901. return isFunction(target.on) && isFunction(target.off);
  2902. }
  2903. function isEventTarget(target) {
  2904. return isFunction(target.addEventListener) && isFunction(target.removeEventListener);
  2905. }
  2906. function fromEventPattern(addHandler, removeHandler, resultSelector) {
  2907. if (resultSelector) {
  2908. return fromEventPattern(addHandler, removeHandler).pipe(mapOneOrManyArgs(resultSelector));
  2909. }
  2910. return new Observable(function (subscriber) {
  2911. var handler = function () {
  2912. var e = [];
  2913. for (var _i = 0; _i < arguments.length; _i++) {
  2914. e[_i] = arguments[_i];
  2915. }
  2916. return subscriber.next(e.length === 1 ? e[0] : e);
  2917. };
  2918. var retValue = addHandler(handler);
  2919. return isFunction(removeHandler) ? function () { return removeHandler(handler, retValue); } : undefined;
  2920. });
  2921. }
  2922. function generate(initialStateOrOptions, condition, iterate, resultSelectorOrScheduler, scheduler) {
  2923. var _a, _b;
  2924. var resultSelector;
  2925. var initialState;
  2926. if (arguments.length === 1) {
  2927. (_a = initialStateOrOptions, initialState = _a.initialState, condition = _a.condition, iterate = _a.iterate, _b = _a.resultSelector, resultSelector = _b === void 0 ? identity : _b, scheduler = _a.scheduler);
  2928. }
  2929. else {
  2930. initialState = initialStateOrOptions;
  2931. if (!resultSelectorOrScheduler || isScheduler(resultSelectorOrScheduler)) {
  2932. resultSelector = identity;
  2933. scheduler = resultSelectorOrScheduler;
  2934. }
  2935. else {
  2936. resultSelector = resultSelectorOrScheduler;
  2937. }
  2938. }
  2939. function gen() {
  2940. var state;
  2941. return __generator(this, function (_a) {
  2942. switch (_a.label) {
  2943. case 0:
  2944. state = initialState;
  2945. _a.label = 1;
  2946. case 1:
  2947. if (!(!condition || condition(state))) return [3, 4];
  2948. return [4, resultSelector(state)];
  2949. case 2:
  2950. _a.sent();
  2951. _a.label = 3;
  2952. case 3:
  2953. state = iterate(state);
  2954. return [3, 1];
  2955. case 4: return [2];
  2956. }
  2957. });
  2958. }
  2959. return defer((scheduler
  2960. ?
  2961. function () { return scheduleIterable(gen(), scheduler); }
  2962. :
  2963. gen));
  2964. }
  2965. function iif(condition, trueResult, falseResult) {
  2966. return defer(function () { return (condition() ? trueResult : falseResult); });
  2967. }
  2968. function timer(dueTime, intervalOrScheduler, scheduler) {
  2969. if (dueTime === void 0) { dueTime = 0; }
  2970. if (scheduler === void 0) { scheduler = async; }
  2971. var intervalDuration = -1;
  2972. if (intervalOrScheduler != null) {
  2973. if (isScheduler(intervalOrScheduler)) {
  2974. scheduler = intervalOrScheduler;
  2975. }
  2976. else {
  2977. intervalDuration = intervalOrScheduler;
  2978. }
  2979. }
  2980. return new Observable(function (subscriber) {
  2981. var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
  2982. if (due < 0) {
  2983. due = 0;
  2984. }
  2985. var n = 0;
  2986. return scheduler.schedule(function () {
  2987. if (!subscriber.closed) {
  2988. subscriber.next(n++);
  2989. if (0 <= intervalDuration) {
  2990. this.schedule(undefined, intervalDuration);
  2991. }
  2992. else {
  2993. subscriber.complete();
  2994. }
  2995. }
  2996. }, due);
  2997. });
  2998. }
  2999. function interval(period, scheduler) {
  3000. if (period === void 0) { period = 0; }
  3001. if (scheduler === void 0) { scheduler = asyncScheduler; }
  3002. if (period < 0) {
  3003. period = 0;
  3004. }
  3005. return timer(period, period, scheduler);
  3006. }
  3007. function merge() {
  3008. var args = [];
  3009. for (var _i = 0; _i < arguments.length; _i++) {
  3010. args[_i] = arguments[_i];
  3011. }
  3012. var scheduler = popScheduler(args);
  3013. var concurrent = popNumber(args, Infinity);
  3014. var sources = args;
  3015. return !sources.length
  3016. ?
  3017. EMPTY
  3018. : sources.length === 1
  3019. ?
  3020. innerFrom(sources[0])
  3021. :
  3022. mergeAll(concurrent)(from(sources, scheduler));
  3023. }
  3024. var NEVER = new Observable(noop);
  3025. function never() {
  3026. return NEVER;
  3027. }
  3028. var isArray$2 = Array.isArray;
  3029. function argsOrArgArray(args) {
  3030. return args.length === 1 && isArray$2(args[0]) ? args[0] : args;
  3031. }
  3032. function onErrorResumeNext() {
  3033. var sources = [];
  3034. for (var _i = 0; _i < arguments.length; _i++) {
  3035. sources[_i] = arguments[_i];
  3036. }
  3037. var nextSources = argsOrArgArray(sources);
  3038. return new Observable(function (subscriber) {
  3039. var sourceIndex = 0;
  3040. var subscribeNext = function () {
  3041. if (sourceIndex < nextSources.length) {
  3042. var nextSource = void 0;
  3043. try {
  3044. nextSource = innerFrom(nextSources[sourceIndex++]);
  3045. }
  3046. catch (err) {
  3047. subscribeNext();
  3048. return;
  3049. }
  3050. var innerSubscriber = new OperatorSubscriber(subscriber, undefined, noop, noop);
  3051. nextSource.subscribe(innerSubscriber);
  3052. innerSubscriber.add(subscribeNext);
  3053. }
  3054. else {
  3055. subscriber.complete();
  3056. }
  3057. };
  3058. subscribeNext();
  3059. });
  3060. }
  3061. function pairs(obj, scheduler) {
  3062. return from(Object.entries(obj), scheduler);
  3063. }
  3064. function not(pred, thisArg) {
  3065. return function (value, index) { return !pred.call(thisArg, value, index); };
  3066. }
  3067. function filter(predicate, thisArg) {
  3068. return operate(function (source, subscriber) {
  3069. var index = 0;
  3070. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
  3071. });
  3072. }
  3073. function partition(source, predicate, thisArg) {
  3074. return [filter(predicate, thisArg)(innerFrom(source)), filter(not(predicate, thisArg))(innerFrom(source))];
  3075. }
  3076. function race() {
  3077. var sources = [];
  3078. for (var _i = 0; _i < arguments.length; _i++) {
  3079. sources[_i] = arguments[_i];
  3080. }
  3081. sources = argsOrArgArray(sources);
  3082. return sources.length === 1 ? innerFrom(sources[0]) : new Observable(raceInit(sources));
  3083. }
  3084. function raceInit(sources) {
  3085. return function (subscriber) {
  3086. var subscriptions = [];
  3087. var _loop_1 = function (i) {
  3088. subscriptions.push(innerFrom(sources[i]).subscribe(createOperatorSubscriber(subscriber, function (value) {
  3089. if (subscriptions) {
  3090. for (var s = 0; s < subscriptions.length; s++) {
  3091. s !== i && subscriptions[s].unsubscribe();
  3092. }
  3093. subscriptions = null;
  3094. }
  3095. subscriber.next(value);
  3096. })));
  3097. };
  3098. for (var i = 0; subscriptions && !subscriber.closed && i < sources.length; i++) {
  3099. _loop_1(i);
  3100. }
  3101. };
  3102. }
  3103. function range(start, count, scheduler) {
  3104. if (count == null) {
  3105. count = start;
  3106. start = 0;
  3107. }
  3108. if (count <= 0) {
  3109. return EMPTY;
  3110. }
  3111. var end = count + start;
  3112. return new Observable(scheduler
  3113. ?
  3114. function (subscriber) {
  3115. var n = start;
  3116. return scheduler.schedule(function () {
  3117. if (n < end) {
  3118. subscriber.next(n++);
  3119. this.schedule();
  3120. }
  3121. else {
  3122. subscriber.complete();
  3123. }
  3124. });
  3125. }
  3126. :
  3127. function (subscriber) {
  3128. var n = start;
  3129. while (n < end && !subscriber.closed) {
  3130. subscriber.next(n++);
  3131. }
  3132. subscriber.complete();
  3133. });
  3134. }
  3135. function using(resourceFactory, observableFactory) {
  3136. return new Observable(function (subscriber) {
  3137. var resource = resourceFactory();
  3138. var result = observableFactory(resource);
  3139. var source = result ? innerFrom(result) : EMPTY;
  3140. source.subscribe(subscriber);
  3141. return function () {
  3142. if (resource) {
  3143. resource.unsubscribe();
  3144. }
  3145. };
  3146. });
  3147. }
  3148. function zip() {
  3149. var args = [];
  3150. for (var _i = 0; _i < arguments.length; _i++) {
  3151. args[_i] = arguments[_i];
  3152. }
  3153. var resultSelector = popResultSelector(args);
  3154. var sources = argsOrArgArray(args);
  3155. return sources.length
  3156. ? new Observable(function (subscriber) {
  3157. var buffers = sources.map(function () { return []; });
  3158. var completed = sources.map(function () { return false; });
  3159. subscriber.add(function () {
  3160. buffers = completed = null;
  3161. });
  3162. var _loop_1 = function (sourceIndex) {
  3163. innerFrom(sources[sourceIndex]).subscribe(createOperatorSubscriber(subscriber, function (value) {
  3164. buffers[sourceIndex].push(value);
  3165. if (buffers.every(function (buffer) { return buffer.length; })) {
  3166. var result = buffers.map(function (buffer) { return buffer.shift(); });
  3167. subscriber.next(resultSelector ? resultSelector.apply(void 0, __spreadArray([], __read(result))) : result);
  3168. if (buffers.some(function (buffer, i) { return !buffer.length && completed[i]; })) {
  3169. subscriber.complete();
  3170. }
  3171. }
  3172. }, function () {
  3173. completed[sourceIndex] = true;
  3174. !buffers[sourceIndex].length && subscriber.complete();
  3175. }));
  3176. };
  3177. for (var sourceIndex = 0; !subscriber.closed && sourceIndex < sources.length; sourceIndex++) {
  3178. _loop_1(sourceIndex);
  3179. }
  3180. return function () {
  3181. buffers = completed = null;
  3182. };
  3183. })
  3184. : EMPTY;
  3185. }
  3186. function audit(durationSelector) {
  3187. return operate(function (source, subscriber) {
  3188. var hasValue = false;
  3189. var lastValue = null;
  3190. var durationSubscriber = null;
  3191. var isComplete = false;
  3192. var endDuration = function () {
  3193. durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
  3194. durationSubscriber = null;
  3195. if (hasValue) {
  3196. hasValue = false;
  3197. var value = lastValue;
  3198. lastValue = null;
  3199. subscriber.next(value);
  3200. }
  3201. isComplete && subscriber.complete();
  3202. };
  3203. var cleanupDuration = function () {
  3204. durationSubscriber = null;
  3205. isComplete && subscriber.complete();
  3206. };
  3207. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3208. hasValue = true;
  3209. lastValue = value;
  3210. if (!durationSubscriber) {
  3211. innerFrom(durationSelector(value)).subscribe((durationSubscriber = createOperatorSubscriber(subscriber, endDuration, cleanupDuration)));
  3212. }
  3213. }, function () {
  3214. isComplete = true;
  3215. (!hasValue || !durationSubscriber || durationSubscriber.closed) && subscriber.complete();
  3216. }));
  3217. });
  3218. }
  3219. function auditTime(duration, scheduler) {
  3220. if (scheduler === void 0) { scheduler = asyncScheduler; }
  3221. return audit(function () { return timer(duration, scheduler); });
  3222. }
  3223. function buffer(closingNotifier) {
  3224. return operate(function (source, subscriber) {
  3225. var currentBuffer = [];
  3226. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return currentBuffer.push(value); }, function () {
  3227. subscriber.next(currentBuffer);
  3228. subscriber.complete();
  3229. }));
  3230. innerFrom(closingNotifier).subscribe(createOperatorSubscriber(subscriber, function () {
  3231. var b = currentBuffer;
  3232. currentBuffer = [];
  3233. subscriber.next(b);
  3234. }, noop));
  3235. return function () {
  3236. currentBuffer = null;
  3237. };
  3238. });
  3239. }
  3240. function bufferCount(bufferSize, startBufferEvery) {
  3241. if (startBufferEvery === void 0) { startBufferEvery = null; }
  3242. startBufferEvery = startBufferEvery !== null && startBufferEvery !== void 0 ? startBufferEvery : bufferSize;
  3243. return operate(function (source, subscriber) {
  3244. var buffers = [];
  3245. var count = 0;
  3246. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3247. var e_1, _a, e_2, _b;
  3248. var toEmit = null;
  3249. if (count++ % startBufferEvery === 0) {
  3250. buffers.push([]);
  3251. }
  3252. try {
  3253. for (var buffers_1 = __values(buffers), buffers_1_1 = buffers_1.next(); !buffers_1_1.done; buffers_1_1 = buffers_1.next()) {
  3254. var buffer = buffers_1_1.value;
  3255. buffer.push(value);
  3256. if (bufferSize <= buffer.length) {
  3257. toEmit = toEmit !== null && toEmit !== void 0 ? toEmit : [];
  3258. toEmit.push(buffer);
  3259. }
  3260. }
  3261. }
  3262. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3263. finally {
  3264. try {
  3265. if (buffers_1_1 && !buffers_1_1.done && (_a = buffers_1.return)) _a.call(buffers_1);
  3266. }
  3267. finally { if (e_1) throw e_1.error; }
  3268. }
  3269. if (toEmit) {
  3270. try {
  3271. for (var toEmit_1 = __values(toEmit), toEmit_1_1 = toEmit_1.next(); !toEmit_1_1.done; toEmit_1_1 = toEmit_1.next()) {
  3272. var buffer = toEmit_1_1.value;
  3273. arrRemove(buffers, buffer);
  3274. subscriber.next(buffer);
  3275. }
  3276. }
  3277. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  3278. finally {
  3279. try {
  3280. if (toEmit_1_1 && !toEmit_1_1.done && (_b = toEmit_1.return)) _b.call(toEmit_1);
  3281. }
  3282. finally { if (e_2) throw e_2.error; }
  3283. }
  3284. }
  3285. }, function () {
  3286. var e_3, _a;
  3287. try {
  3288. for (var buffers_2 = __values(buffers), buffers_2_1 = buffers_2.next(); !buffers_2_1.done; buffers_2_1 = buffers_2.next()) {
  3289. var buffer = buffers_2_1.value;
  3290. subscriber.next(buffer);
  3291. }
  3292. }
  3293. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  3294. finally {
  3295. try {
  3296. if (buffers_2_1 && !buffers_2_1.done && (_a = buffers_2.return)) _a.call(buffers_2);
  3297. }
  3298. finally { if (e_3) throw e_3.error; }
  3299. }
  3300. subscriber.complete();
  3301. }, undefined, function () {
  3302. buffers = null;
  3303. }));
  3304. });
  3305. }
  3306. function bufferTime(bufferTimeSpan) {
  3307. var _a, _b;
  3308. var otherArgs = [];
  3309. for (var _i = 1; _i < arguments.length; _i++) {
  3310. otherArgs[_i - 1] = arguments[_i];
  3311. }
  3312. var scheduler = (_a = popScheduler(otherArgs)) !== null && _a !== void 0 ? _a : asyncScheduler;
  3313. var bufferCreationInterval = (_b = otherArgs[0]) !== null && _b !== void 0 ? _b : null;
  3314. var maxBufferSize = otherArgs[1] || Infinity;
  3315. return operate(function (source, subscriber) {
  3316. var bufferRecords = [];
  3317. var restartOnEmit = false;
  3318. var emit = function (record) {
  3319. var buffer = record.buffer, subs = record.subs;
  3320. subs.unsubscribe();
  3321. arrRemove(bufferRecords, record);
  3322. subscriber.next(buffer);
  3323. restartOnEmit && startBuffer();
  3324. };
  3325. var startBuffer = function () {
  3326. if (bufferRecords) {
  3327. var subs = new Subscription();
  3328. subscriber.add(subs);
  3329. var buffer = [];
  3330. var record_1 = {
  3331. buffer: buffer,
  3332. subs: subs,
  3333. };
  3334. bufferRecords.push(record_1);
  3335. executeSchedule(subs, scheduler, function () { return emit(record_1); }, bufferTimeSpan);
  3336. }
  3337. };
  3338. if (bufferCreationInterval !== null && bufferCreationInterval >= 0) {
  3339. executeSchedule(subscriber, scheduler, startBuffer, bufferCreationInterval, true);
  3340. }
  3341. else {
  3342. restartOnEmit = true;
  3343. }
  3344. startBuffer();
  3345. var bufferTimeSubscriber = createOperatorSubscriber(subscriber, function (value) {
  3346. var e_1, _a;
  3347. var recordsCopy = bufferRecords.slice();
  3348. try {
  3349. for (var recordsCopy_1 = __values(recordsCopy), recordsCopy_1_1 = recordsCopy_1.next(); !recordsCopy_1_1.done; recordsCopy_1_1 = recordsCopy_1.next()) {
  3350. var record = recordsCopy_1_1.value;
  3351. var buffer = record.buffer;
  3352. buffer.push(value);
  3353. maxBufferSize <= buffer.length && emit(record);
  3354. }
  3355. }
  3356. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3357. finally {
  3358. try {
  3359. if (recordsCopy_1_1 && !recordsCopy_1_1.done && (_a = recordsCopy_1.return)) _a.call(recordsCopy_1);
  3360. }
  3361. finally { if (e_1) throw e_1.error; }
  3362. }
  3363. }, function () {
  3364. while (bufferRecords === null || bufferRecords === void 0 ? void 0 : bufferRecords.length) {
  3365. subscriber.next(bufferRecords.shift().buffer);
  3366. }
  3367. bufferTimeSubscriber === null || bufferTimeSubscriber === void 0 ? void 0 : bufferTimeSubscriber.unsubscribe();
  3368. subscriber.complete();
  3369. subscriber.unsubscribe();
  3370. }, undefined, function () { return (bufferRecords = null); });
  3371. source.subscribe(bufferTimeSubscriber);
  3372. });
  3373. }
  3374. function bufferToggle(openings, closingSelector) {
  3375. return operate(function (source, subscriber) {
  3376. var buffers = [];
  3377. innerFrom(openings).subscribe(createOperatorSubscriber(subscriber, function (openValue) {
  3378. var buffer = [];
  3379. buffers.push(buffer);
  3380. var closingSubscription = new Subscription();
  3381. var emitBuffer = function () {
  3382. arrRemove(buffers, buffer);
  3383. subscriber.next(buffer);
  3384. closingSubscription.unsubscribe();
  3385. };
  3386. closingSubscription.add(innerFrom(closingSelector(openValue)).subscribe(createOperatorSubscriber(subscriber, emitBuffer, noop)));
  3387. }, noop));
  3388. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3389. var e_1, _a;
  3390. try {
  3391. for (var buffers_1 = __values(buffers), buffers_1_1 = buffers_1.next(); !buffers_1_1.done; buffers_1_1 = buffers_1.next()) {
  3392. var buffer = buffers_1_1.value;
  3393. buffer.push(value);
  3394. }
  3395. }
  3396. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3397. finally {
  3398. try {
  3399. if (buffers_1_1 && !buffers_1_1.done && (_a = buffers_1.return)) _a.call(buffers_1);
  3400. }
  3401. finally { if (e_1) throw e_1.error; }
  3402. }
  3403. }, function () {
  3404. while (buffers.length > 0) {
  3405. subscriber.next(buffers.shift());
  3406. }
  3407. subscriber.complete();
  3408. }));
  3409. });
  3410. }
  3411. function bufferWhen(closingSelector) {
  3412. return operate(function (source, subscriber) {
  3413. var buffer = null;
  3414. var closingSubscriber = null;
  3415. var openBuffer = function () {
  3416. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  3417. var b = buffer;
  3418. buffer = [];
  3419. b && subscriber.next(b);
  3420. innerFrom(closingSelector()).subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openBuffer, noop)));
  3421. };
  3422. openBuffer();
  3423. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return buffer === null || buffer === void 0 ? void 0 : buffer.push(value); }, function () {
  3424. buffer && subscriber.next(buffer);
  3425. subscriber.complete();
  3426. }, undefined, function () { return (buffer = closingSubscriber = null); }));
  3427. });
  3428. }
  3429. function catchError(selector) {
  3430. return operate(function (source, subscriber) {
  3431. var innerSub = null;
  3432. var syncUnsub = false;
  3433. var handledResult;
  3434. innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
  3435. handledResult = innerFrom(selector(err, catchError(selector)(source)));
  3436. if (innerSub) {
  3437. innerSub.unsubscribe();
  3438. innerSub = null;
  3439. handledResult.subscribe(subscriber);
  3440. }
  3441. else {
  3442. syncUnsub = true;
  3443. }
  3444. }));
  3445. if (syncUnsub) {
  3446. innerSub.unsubscribe();
  3447. innerSub = null;
  3448. handledResult.subscribe(subscriber);
  3449. }
  3450. });
  3451. }
  3452. function scanInternals(accumulator, seed, hasSeed, emitOnNext, emitBeforeComplete) {
  3453. return function (source, subscriber) {
  3454. var hasState = hasSeed;
  3455. var state = seed;
  3456. var index = 0;
  3457. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3458. var i = index++;
  3459. state = hasState
  3460. ?
  3461. accumulator(state, value, i)
  3462. :
  3463. ((hasState = true), value);
  3464. emitOnNext && subscriber.next(state);
  3465. }, emitBeforeComplete &&
  3466. (function () {
  3467. hasState && subscriber.next(state);
  3468. subscriber.complete();
  3469. })));
  3470. };
  3471. }
  3472. function reduce(accumulator, seed) {
  3473. return operate(scanInternals(accumulator, seed, arguments.length >= 2, false, true));
  3474. }
  3475. var arrReducer = function (arr, value) { return (arr.push(value), arr); };
  3476. function toArray() {
  3477. return operate(function (source, subscriber) {
  3478. reduce(arrReducer, [])(source).subscribe(subscriber);
  3479. });
  3480. }
  3481. function joinAllInternals(joinFn, project) {
  3482. return pipe(toArray(), mergeMap(function (sources) { return joinFn(sources); }), project ? mapOneOrManyArgs(project) : identity);
  3483. }
  3484. function combineLatestAll(project) {
  3485. return joinAllInternals(combineLatest, project);
  3486. }
  3487. var combineAll = combineLatestAll;
  3488. function combineLatest$1() {
  3489. var args = [];
  3490. for (var _i = 0; _i < arguments.length; _i++) {
  3491. args[_i] = arguments[_i];
  3492. }
  3493. var resultSelector = popResultSelector(args);
  3494. return resultSelector
  3495. ? pipe(combineLatest$1.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector))
  3496. : operate(function (source, subscriber) {
  3497. combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
  3498. });
  3499. }
  3500. function combineLatestWith() {
  3501. var otherSources = [];
  3502. for (var _i = 0; _i < arguments.length; _i++) {
  3503. otherSources[_i] = arguments[_i];
  3504. }
  3505. return combineLatest$1.apply(void 0, __spreadArray([], __read(otherSources)));
  3506. }
  3507. function concatMap(project, resultSelector) {
  3508. return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
  3509. }
  3510. function concatMapTo(innerObservable, resultSelector) {
  3511. return isFunction(resultSelector) ? concatMap(function () { return innerObservable; }, resultSelector) : concatMap(function () { return innerObservable; });
  3512. }
  3513. function concat$1() {
  3514. var args = [];
  3515. for (var _i = 0; _i < arguments.length; _i++) {
  3516. args[_i] = arguments[_i];
  3517. }
  3518. var scheduler = popScheduler(args);
  3519. return operate(function (source, subscriber) {
  3520. concatAll()(from(__spreadArray([source], __read(args)), scheduler)).subscribe(subscriber);
  3521. });
  3522. }
  3523. function concatWith() {
  3524. var otherSources = [];
  3525. for (var _i = 0; _i < arguments.length; _i++) {
  3526. otherSources[_i] = arguments[_i];
  3527. }
  3528. return concat$1.apply(void 0, __spreadArray([], __read(otherSources)));
  3529. }
  3530. function fromSubscribable(subscribable) {
  3531. return new Observable(function (subscriber) { return subscribable.subscribe(subscriber); });
  3532. }
  3533. var DEFAULT_CONFIG$1 = {
  3534. connector: function () { return new Subject(); },
  3535. };
  3536. function connect(selector, config) {
  3537. if (config === void 0) { config = DEFAULT_CONFIG$1; }
  3538. var connector = config.connector;
  3539. return operate(function (source, subscriber) {
  3540. var subject = connector();
  3541. innerFrom(selector(fromSubscribable(subject))).subscribe(subscriber);
  3542. subscriber.add(source.subscribe(subject));
  3543. });
  3544. }
  3545. function count(predicate) {
  3546. return reduce(function (total, value, i) { return (!predicate || predicate(value, i) ? total + 1 : total); }, 0);
  3547. }
  3548. function debounce(durationSelector) {
  3549. return operate(function (source, subscriber) {
  3550. var hasValue = false;
  3551. var lastValue = null;
  3552. var durationSubscriber = null;
  3553. var emit = function () {
  3554. durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
  3555. durationSubscriber = null;
  3556. if (hasValue) {
  3557. hasValue = false;
  3558. var value = lastValue;
  3559. lastValue = null;
  3560. subscriber.next(value);
  3561. }
  3562. };
  3563. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3564. durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
  3565. hasValue = true;
  3566. lastValue = value;
  3567. durationSubscriber = createOperatorSubscriber(subscriber, emit, noop);
  3568. innerFrom(durationSelector(value)).subscribe(durationSubscriber);
  3569. }, function () {
  3570. emit();
  3571. subscriber.complete();
  3572. }, undefined, function () {
  3573. lastValue = durationSubscriber = null;
  3574. }));
  3575. });
  3576. }
  3577. function debounceTime(dueTime, scheduler) {
  3578. if (scheduler === void 0) { scheduler = asyncScheduler; }
  3579. return operate(function (source, subscriber) {
  3580. var activeTask = null;
  3581. var lastValue = null;
  3582. var lastTime = null;
  3583. var emit = function () {
  3584. if (activeTask) {
  3585. activeTask.unsubscribe();
  3586. activeTask = null;
  3587. var value = lastValue;
  3588. lastValue = null;
  3589. subscriber.next(value);
  3590. }
  3591. };
  3592. function emitWhenIdle() {
  3593. var targetTime = lastTime + dueTime;
  3594. var now = scheduler.now();
  3595. if (now < targetTime) {
  3596. activeTask = this.schedule(undefined, targetTime - now);
  3597. subscriber.add(activeTask);
  3598. return;
  3599. }
  3600. emit();
  3601. }
  3602. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3603. lastValue = value;
  3604. lastTime = scheduler.now();
  3605. if (!activeTask) {
  3606. activeTask = scheduler.schedule(emitWhenIdle, dueTime);
  3607. subscriber.add(activeTask);
  3608. }
  3609. }, function () {
  3610. emit();
  3611. subscriber.complete();
  3612. }, undefined, function () {
  3613. lastValue = activeTask = null;
  3614. }));
  3615. });
  3616. }
  3617. function defaultIfEmpty(defaultValue) {
  3618. return operate(function (source, subscriber) {
  3619. var hasValue = false;
  3620. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3621. hasValue = true;
  3622. subscriber.next(value);
  3623. }, function () {
  3624. if (!hasValue) {
  3625. subscriber.next(defaultValue);
  3626. }
  3627. subscriber.complete();
  3628. }));
  3629. });
  3630. }
  3631. function take(count) {
  3632. return count <= 0
  3633. ?
  3634. function () { return EMPTY; }
  3635. : operate(function (source, subscriber) {
  3636. var seen = 0;
  3637. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3638. if (++seen <= count) {
  3639. subscriber.next(value);
  3640. if (count <= seen) {
  3641. subscriber.complete();
  3642. }
  3643. }
  3644. }));
  3645. });
  3646. }
  3647. function ignoreElements() {
  3648. return operate(function (source, subscriber) {
  3649. source.subscribe(createOperatorSubscriber(subscriber, noop));
  3650. });
  3651. }
  3652. function mapTo(value) {
  3653. return map(function () { return value; });
  3654. }
  3655. function delayWhen(delayDurationSelector, subscriptionDelay) {
  3656. if (subscriptionDelay) {
  3657. return function (source) {
  3658. return concat(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
  3659. };
  3660. }
  3661. return mergeMap(function (value, index) { return innerFrom(delayDurationSelector(value, index)).pipe(take(1), mapTo(value)); });
  3662. }
  3663. function delay(due, scheduler) {
  3664. if (scheduler === void 0) { scheduler = asyncScheduler; }
  3665. var duration = timer(due, scheduler);
  3666. return delayWhen(function () { return duration; });
  3667. }
  3668. function dematerialize() {
  3669. return operate(function (source, subscriber) {
  3670. source.subscribe(createOperatorSubscriber(subscriber, function (notification) { return observeNotification(notification, subscriber); }));
  3671. });
  3672. }
  3673. function distinct(keySelector, flushes) {
  3674. return operate(function (source, subscriber) {
  3675. var distinctKeys = new Set();
  3676. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3677. var key = keySelector ? keySelector(value) : value;
  3678. if (!distinctKeys.has(key)) {
  3679. distinctKeys.add(key);
  3680. subscriber.next(value);
  3681. }
  3682. }));
  3683. flushes && innerFrom(flushes).subscribe(createOperatorSubscriber(subscriber, function () { return distinctKeys.clear(); }, noop));
  3684. });
  3685. }
  3686. function distinctUntilChanged(comparator, keySelector) {
  3687. if (keySelector === void 0) { keySelector = identity; }
  3688. comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
  3689. return operate(function (source, subscriber) {
  3690. var previousKey;
  3691. var first = true;
  3692. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3693. var currentKey = keySelector(value);
  3694. if (first || !comparator(previousKey, currentKey)) {
  3695. first = false;
  3696. previousKey = currentKey;
  3697. subscriber.next(value);
  3698. }
  3699. }));
  3700. });
  3701. }
  3702. function defaultCompare(a, b) {
  3703. return a === b;
  3704. }
  3705. function distinctUntilKeyChanged(key, compare) {
  3706. return distinctUntilChanged(function (x, y) { return compare ? compare(x[key], y[key]) : x[key] === y[key]; });
  3707. }
  3708. function throwIfEmpty(errorFactory) {
  3709. if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
  3710. return operate(function (source, subscriber) {
  3711. var hasValue = false;
  3712. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3713. hasValue = true;
  3714. subscriber.next(value);
  3715. }, function () { return (hasValue ? subscriber.complete() : subscriber.error(errorFactory())); }));
  3716. });
  3717. }
  3718. function defaultErrorFactory() {
  3719. return new EmptyError();
  3720. }
  3721. function elementAt(index, defaultValue) {
  3722. if (index < 0) {
  3723. throw new ArgumentOutOfRangeError();
  3724. }
  3725. var hasDefaultValue = arguments.length >= 2;
  3726. return function (source) {
  3727. return source.pipe(filter(function (v, i) { return i === index; }), take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new ArgumentOutOfRangeError(); }));
  3728. };
  3729. }
  3730. function endWith() {
  3731. var values = [];
  3732. for (var _i = 0; _i < arguments.length; _i++) {
  3733. values[_i] = arguments[_i];
  3734. }
  3735. return function (source) { return concat(source, of.apply(void 0, __spreadArray([], __read(values)))); };
  3736. }
  3737. function every(predicate, thisArg) {
  3738. return operate(function (source, subscriber) {
  3739. var index = 0;
  3740. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3741. if (!predicate.call(thisArg, value, index++, source)) {
  3742. subscriber.next(false);
  3743. subscriber.complete();
  3744. }
  3745. }, function () {
  3746. subscriber.next(true);
  3747. subscriber.complete();
  3748. }));
  3749. });
  3750. }
  3751. function exhaustMap(project, resultSelector) {
  3752. if (resultSelector) {
  3753. return function (source) {
  3754. return source.pipe(exhaustMap(function (a, i) { return innerFrom(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }));
  3755. };
  3756. }
  3757. return operate(function (source, subscriber) {
  3758. var index = 0;
  3759. var innerSub = null;
  3760. var isComplete = false;
  3761. source.subscribe(createOperatorSubscriber(subscriber, function (outerValue) {
  3762. if (!innerSub) {
  3763. innerSub = createOperatorSubscriber(subscriber, undefined, function () {
  3764. innerSub = null;
  3765. isComplete && subscriber.complete();
  3766. });
  3767. innerFrom(project(outerValue, index++)).subscribe(innerSub);
  3768. }
  3769. }, function () {
  3770. isComplete = true;
  3771. !innerSub && subscriber.complete();
  3772. }));
  3773. });
  3774. }
  3775. function exhaustAll() {
  3776. return exhaustMap(identity);
  3777. }
  3778. var exhaust = exhaustAll;
  3779. function expand(project, concurrent, scheduler) {
  3780. if (concurrent === void 0) { concurrent = Infinity; }
  3781. concurrent = (concurrent || 0) < 1 ? Infinity : concurrent;
  3782. return operate(function (source, subscriber) {
  3783. return mergeInternals(source, subscriber, project, concurrent, undefined, true, scheduler);
  3784. });
  3785. }
  3786. function finalize(callback) {
  3787. return operate(function (source, subscriber) {
  3788. try {
  3789. source.subscribe(subscriber);
  3790. }
  3791. finally {
  3792. subscriber.add(callback);
  3793. }
  3794. });
  3795. }
  3796. function find(predicate, thisArg) {
  3797. return operate(createFind(predicate, thisArg, 'value'));
  3798. }
  3799. function createFind(predicate, thisArg, emit) {
  3800. var findIndex = emit === 'index';
  3801. return function (source, subscriber) {
  3802. var index = 0;
  3803. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3804. var i = index++;
  3805. if (predicate.call(thisArg, value, i, source)) {
  3806. subscriber.next(findIndex ? i : value);
  3807. subscriber.complete();
  3808. }
  3809. }, function () {
  3810. subscriber.next(findIndex ? -1 : undefined);
  3811. subscriber.complete();
  3812. }));
  3813. };
  3814. }
  3815. function findIndex(predicate, thisArg) {
  3816. return operate(createFind(predicate, thisArg, 'index'));
  3817. }
  3818. function first(predicate, defaultValue) {
  3819. var hasDefaultValue = arguments.length >= 2;
  3820. return function (source) {
  3821. return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); }));
  3822. };
  3823. }
  3824. function groupBy(keySelector, elementOrOptions, duration, connector) {
  3825. return operate(function (source, subscriber) {
  3826. var element;
  3827. if (!elementOrOptions || typeof elementOrOptions === 'function') {
  3828. element = elementOrOptions;
  3829. }
  3830. else {
  3831. (duration = elementOrOptions.duration, element = elementOrOptions.element, connector = elementOrOptions.connector);
  3832. }
  3833. var groups = new Map();
  3834. var notify = function (cb) {
  3835. groups.forEach(cb);
  3836. cb(subscriber);
  3837. };
  3838. var handleError = function (err) { return notify(function (consumer) { return consumer.error(err); }); };
  3839. var activeGroups = 0;
  3840. var teardownAttempted = false;
  3841. var groupBySourceSubscriber = new OperatorSubscriber(subscriber, function (value) {
  3842. try {
  3843. var key_1 = keySelector(value);
  3844. var group_1 = groups.get(key_1);
  3845. if (!group_1) {
  3846. groups.set(key_1, (group_1 = connector ? connector() : new Subject()));
  3847. var grouped = createGroupedObservable(key_1, group_1);
  3848. subscriber.next(grouped);
  3849. if (duration) {
  3850. var durationSubscriber_1 = createOperatorSubscriber(group_1, function () {
  3851. group_1.complete();
  3852. durationSubscriber_1 === null || durationSubscriber_1 === void 0 ? void 0 : durationSubscriber_1.unsubscribe();
  3853. }, undefined, undefined, function () { return groups.delete(key_1); });
  3854. groupBySourceSubscriber.add(innerFrom(duration(grouped)).subscribe(durationSubscriber_1));
  3855. }
  3856. }
  3857. group_1.next(element ? element(value) : value);
  3858. }
  3859. catch (err) {
  3860. handleError(err);
  3861. }
  3862. }, function () { return notify(function (consumer) { return consumer.complete(); }); }, handleError, function () { return groups.clear(); }, function () {
  3863. teardownAttempted = true;
  3864. return activeGroups === 0;
  3865. });
  3866. source.subscribe(groupBySourceSubscriber);
  3867. function createGroupedObservable(key, groupSubject) {
  3868. var result = new Observable(function (groupSubscriber) {
  3869. activeGroups++;
  3870. var innerSub = groupSubject.subscribe(groupSubscriber);
  3871. return function () {
  3872. innerSub.unsubscribe();
  3873. --activeGroups === 0 && teardownAttempted && groupBySourceSubscriber.unsubscribe();
  3874. };
  3875. });
  3876. result.key = key;
  3877. return result;
  3878. }
  3879. });
  3880. }
  3881. function isEmpty() {
  3882. return operate(function (source, subscriber) {
  3883. source.subscribe(createOperatorSubscriber(subscriber, function () {
  3884. subscriber.next(false);
  3885. subscriber.complete();
  3886. }, function () {
  3887. subscriber.next(true);
  3888. subscriber.complete();
  3889. }));
  3890. });
  3891. }
  3892. function takeLast(count) {
  3893. return count <= 0
  3894. ? function () { return EMPTY; }
  3895. : operate(function (source, subscriber) {
  3896. var buffer = [];
  3897. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3898. buffer.push(value);
  3899. count < buffer.length && buffer.shift();
  3900. }, function () {
  3901. var e_1, _a;
  3902. try {
  3903. for (var buffer_1 = __values(buffer), buffer_1_1 = buffer_1.next(); !buffer_1_1.done; buffer_1_1 = buffer_1.next()) {
  3904. var value = buffer_1_1.value;
  3905. subscriber.next(value);
  3906. }
  3907. }
  3908. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3909. finally {
  3910. try {
  3911. if (buffer_1_1 && !buffer_1_1.done && (_a = buffer_1.return)) _a.call(buffer_1);
  3912. }
  3913. finally { if (e_1) throw e_1.error; }
  3914. }
  3915. subscriber.complete();
  3916. }, undefined, function () {
  3917. buffer = null;
  3918. }));
  3919. });
  3920. }
  3921. function last$1(predicate, defaultValue) {
  3922. var hasDefaultValue = arguments.length >= 2;
  3923. return function (source) {
  3924. return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, takeLast(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); }));
  3925. };
  3926. }
  3927. function materialize() {
  3928. return operate(function (source, subscriber) {
  3929. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  3930. subscriber.next(Notification.createNext(value));
  3931. }, function () {
  3932. subscriber.next(Notification.createComplete());
  3933. subscriber.complete();
  3934. }, function (err) {
  3935. subscriber.next(Notification.createError(err));
  3936. subscriber.complete();
  3937. }));
  3938. });
  3939. }
  3940. function max(comparer) {
  3941. return reduce(isFunction(comparer) ? function (x, y) { return (comparer(x, y) > 0 ? x : y); } : function (x, y) { return (x > y ? x : y); });
  3942. }
  3943. var flatMap = mergeMap;
  3944. function mergeMapTo(innerObservable, resultSelector, concurrent) {
  3945. if (concurrent === void 0) { concurrent = Infinity; }
  3946. if (isFunction(resultSelector)) {
  3947. return mergeMap(function () { return innerObservable; }, resultSelector, concurrent);
  3948. }
  3949. if (typeof resultSelector === 'number') {
  3950. concurrent = resultSelector;
  3951. }
  3952. return mergeMap(function () { return innerObservable; }, concurrent);
  3953. }
  3954. function mergeScan(accumulator, seed, concurrent) {
  3955. if (concurrent === void 0) { concurrent = Infinity; }
  3956. return operate(function (source, subscriber) {
  3957. var state = seed;
  3958. return mergeInternals(source, subscriber, function (value, index) { return accumulator(state, value, index); }, concurrent, function (value) {
  3959. state = value;
  3960. }, false, undefined, function () { return (state = null); });
  3961. });
  3962. }
  3963. function merge$1() {
  3964. var args = [];
  3965. for (var _i = 0; _i < arguments.length; _i++) {
  3966. args[_i] = arguments[_i];
  3967. }
  3968. var scheduler = popScheduler(args);
  3969. var concurrent = popNumber(args, Infinity);
  3970. args = argsOrArgArray(args);
  3971. return operate(function (source, subscriber) {
  3972. mergeAll(concurrent)(from(__spreadArray([source], __read(args)), scheduler)).subscribe(subscriber);
  3973. });
  3974. }
  3975. function mergeWith() {
  3976. var otherSources = [];
  3977. for (var _i = 0; _i < arguments.length; _i++) {
  3978. otherSources[_i] = arguments[_i];
  3979. }
  3980. return merge$1.apply(void 0, __spreadArray([], __read(otherSources)));
  3981. }
  3982. function min(comparer) {
  3983. return reduce(isFunction(comparer) ? function (x, y) { return (comparer(x, y) < 0 ? x : y); } : function (x, y) { return (x < y ? x : y); });
  3984. }
  3985. function multicast(subjectOrSubjectFactory, selector) {
  3986. var subjectFactory = isFunction(subjectOrSubjectFactory) ? subjectOrSubjectFactory : function () { return subjectOrSubjectFactory; };
  3987. if (isFunction(selector)) {
  3988. return connect(selector, {
  3989. connector: subjectFactory,
  3990. });
  3991. }
  3992. return function (source) { return new ConnectableObservable(source, subjectFactory); };
  3993. }
  3994. function onErrorResumeNextWith() {
  3995. var sources = [];
  3996. for (var _i = 0; _i < arguments.length; _i++) {
  3997. sources[_i] = arguments[_i];
  3998. }
  3999. var nextSources = argsOrArgArray(sources);
  4000. return function (source) { return onErrorResumeNext.apply(void 0, __spreadArray([source], __read(nextSources))); };
  4001. }
  4002. var onErrorResumeNext$1 = onErrorResumeNextWith;
  4003. function pairwise() {
  4004. return operate(function (source, subscriber) {
  4005. var prev;
  4006. var hasPrev = false;
  4007. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4008. var p = prev;
  4009. prev = value;
  4010. hasPrev && subscriber.next([p, value]);
  4011. hasPrev = true;
  4012. }));
  4013. });
  4014. }
  4015. function pluck() {
  4016. var properties = [];
  4017. for (var _i = 0; _i < arguments.length; _i++) {
  4018. properties[_i] = arguments[_i];
  4019. }
  4020. var length = properties.length;
  4021. if (length === 0) {
  4022. throw new Error('list of properties cannot be empty.');
  4023. }
  4024. return map(function (x) {
  4025. var currentProp = x;
  4026. for (var i = 0; i < length; i++) {
  4027. var p = currentProp === null || currentProp === void 0 ? void 0 : currentProp[properties[i]];
  4028. if (typeof p !== 'undefined') {
  4029. currentProp = p;
  4030. }
  4031. else {
  4032. return undefined;
  4033. }
  4034. }
  4035. return currentProp;
  4036. });
  4037. }
  4038. function publish(selector) {
  4039. return selector ? function (source) { return connect(selector)(source); } : function (source) { return multicast(new Subject())(source); };
  4040. }
  4041. function publishBehavior(initialValue) {
  4042. return function (source) {
  4043. var subject = new BehaviorSubject(initialValue);
  4044. return new ConnectableObservable(source, function () { return subject; });
  4045. };
  4046. }
  4047. function publishLast() {
  4048. return function (source) {
  4049. var subject = new AsyncSubject();
  4050. return new ConnectableObservable(source, function () { return subject; });
  4051. };
  4052. }
  4053. function publishReplay(bufferSize, windowTime, selectorOrScheduler, timestampProvider) {
  4054. if (selectorOrScheduler && !isFunction(selectorOrScheduler)) {
  4055. timestampProvider = selectorOrScheduler;
  4056. }
  4057. var selector = isFunction(selectorOrScheduler) ? selectorOrScheduler : undefined;
  4058. return function (source) { return multicast(new ReplaySubject(bufferSize, windowTime, timestampProvider), selector)(source); };
  4059. }
  4060. function raceWith() {
  4061. var otherSources = [];
  4062. for (var _i = 0; _i < arguments.length; _i++) {
  4063. otherSources[_i] = arguments[_i];
  4064. }
  4065. return !otherSources.length
  4066. ? identity
  4067. : operate(function (source, subscriber) {
  4068. raceInit(__spreadArray([source], __read(otherSources)))(subscriber);
  4069. });
  4070. }
  4071. function repeat(countOrConfig) {
  4072. var _a;
  4073. var count = Infinity;
  4074. var delay;
  4075. if (countOrConfig != null) {
  4076. if (typeof countOrConfig === 'object') {
  4077. (_a = countOrConfig.count, count = _a === void 0 ? Infinity : _a, delay = countOrConfig.delay);
  4078. }
  4079. else {
  4080. count = countOrConfig;
  4081. }
  4082. }
  4083. return count <= 0
  4084. ? function () { return EMPTY; }
  4085. : operate(function (source, subscriber) {
  4086. var soFar = 0;
  4087. var sourceSub;
  4088. var resubscribe = function () {
  4089. sourceSub === null || sourceSub === void 0 ? void 0 : sourceSub.unsubscribe();
  4090. sourceSub = null;
  4091. if (delay != null) {
  4092. var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(soFar));
  4093. var notifierSubscriber_1 = createOperatorSubscriber(subscriber, function () {
  4094. notifierSubscriber_1.unsubscribe();
  4095. subscribeToSource();
  4096. });
  4097. notifier.subscribe(notifierSubscriber_1);
  4098. }
  4099. else {
  4100. subscribeToSource();
  4101. }
  4102. };
  4103. var subscribeToSource = function () {
  4104. var syncUnsub = false;
  4105. sourceSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () {
  4106. if (++soFar < count) {
  4107. if (sourceSub) {
  4108. resubscribe();
  4109. }
  4110. else {
  4111. syncUnsub = true;
  4112. }
  4113. }
  4114. else {
  4115. subscriber.complete();
  4116. }
  4117. }));
  4118. if (syncUnsub) {
  4119. resubscribe();
  4120. }
  4121. };
  4122. subscribeToSource();
  4123. });
  4124. }
  4125. function repeatWhen(notifier) {
  4126. return operate(function (source, subscriber) {
  4127. var innerSub;
  4128. var syncResub = false;
  4129. var completions$;
  4130. var isNotifierComplete = false;
  4131. var isMainComplete = false;
  4132. var checkComplete = function () { return isMainComplete && isNotifierComplete && (subscriber.complete(), true); };
  4133. var getCompletionSubject = function () {
  4134. if (!completions$) {
  4135. completions$ = new Subject();
  4136. innerFrom(notifier(completions$)).subscribe(createOperatorSubscriber(subscriber, function () {
  4137. if (innerSub) {
  4138. subscribeForRepeatWhen();
  4139. }
  4140. else {
  4141. syncResub = true;
  4142. }
  4143. }, function () {
  4144. isNotifierComplete = true;
  4145. checkComplete();
  4146. }));
  4147. }
  4148. return completions$;
  4149. };
  4150. var subscribeForRepeatWhen = function () {
  4151. isMainComplete = false;
  4152. innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, function () {
  4153. isMainComplete = true;
  4154. !checkComplete() && getCompletionSubject().next();
  4155. }));
  4156. if (syncResub) {
  4157. innerSub.unsubscribe();
  4158. innerSub = null;
  4159. syncResub = false;
  4160. subscribeForRepeatWhen();
  4161. }
  4162. };
  4163. subscribeForRepeatWhen();
  4164. });
  4165. }
  4166. function retry(configOrCount) {
  4167. if (configOrCount === void 0) { configOrCount = Infinity; }
  4168. var config;
  4169. if (configOrCount && typeof configOrCount === 'object') {
  4170. config = configOrCount;
  4171. }
  4172. else {
  4173. config = {
  4174. count: configOrCount,
  4175. };
  4176. }
  4177. var _a = config.count, count = _a === void 0 ? Infinity : _a, delay = config.delay, _b = config.resetOnSuccess, resetOnSuccess = _b === void 0 ? false : _b;
  4178. return count <= 0
  4179. ? identity
  4180. : operate(function (source, subscriber) {
  4181. var soFar = 0;
  4182. var innerSub;
  4183. var subscribeForRetry = function () {
  4184. var syncUnsub = false;
  4185. innerSub = source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4186. if (resetOnSuccess) {
  4187. soFar = 0;
  4188. }
  4189. subscriber.next(value);
  4190. }, undefined, function (err) {
  4191. if (soFar++ < count) {
  4192. var resub_1 = function () {
  4193. if (innerSub) {
  4194. innerSub.unsubscribe();
  4195. innerSub = null;
  4196. subscribeForRetry();
  4197. }
  4198. else {
  4199. syncUnsub = true;
  4200. }
  4201. };
  4202. if (delay != null) {
  4203. var notifier = typeof delay === 'number' ? timer(delay) : innerFrom(delay(err, soFar));
  4204. var notifierSubscriber_1 = createOperatorSubscriber(subscriber, function () {
  4205. notifierSubscriber_1.unsubscribe();
  4206. resub_1();
  4207. }, function () {
  4208. subscriber.complete();
  4209. });
  4210. notifier.subscribe(notifierSubscriber_1);
  4211. }
  4212. else {
  4213. resub_1();
  4214. }
  4215. }
  4216. else {
  4217. subscriber.error(err);
  4218. }
  4219. }));
  4220. if (syncUnsub) {
  4221. innerSub.unsubscribe();
  4222. innerSub = null;
  4223. subscribeForRetry();
  4224. }
  4225. };
  4226. subscribeForRetry();
  4227. });
  4228. }
  4229. function retryWhen(notifier) {
  4230. return operate(function (source, subscriber) {
  4231. var innerSub;
  4232. var syncResub = false;
  4233. var errors$;
  4234. var subscribeForRetryWhen = function () {
  4235. innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
  4236. if (!errors$) {
  4237. errors$ = new Subject();
  4238. innerFrom(notifier(errors$)).subscribe(createOperatorSubscriber(subscriber, function () {
  4239. return innerSub ? subscribeForRetryWhen() : (syncResub = true);
  4240. }));
  4241. }
  4242. if (errors$) {
  4243. errors$.next(err);
  4244. }
  4245. }));
  4246. if (syncResub) {
  4247. innerSub.unsubscribe();
  4248. innerSub = null;
  4249. syncResub = false;
  4250. subscribeForRetryWhen();
  4251. }
  4252. };
  4253. subscribeForRetryWhen();
  4254. });
  4255. }
  4256. function sample(notifier) {
  4257. return operate(function (source, subscriber) {
  4258. var hasValue = false;
  4259. var lastValue = null;
  4260. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4261. hasValue = true;
  4262. lastValue = value;
  4263. }));
  4264. innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function () {
  4265. if (hasValue) {
  4266. hasValue = false;
  4267. var value = lastValue;
  4268. lastValue = null;
  4269. subscriber.next(value);
  4270. }
  4271. }, noop));
  4272. });
  4273. }
  4274. function sampleTime(period, scheduler) {
  4275. if (scheduler === void 0) { scheduler = asyncScheduler; }
  4276. return sample(interval(period, scheduler));
  4277. }
  4278. function scan(accumulator, seed) {
  4279. return operate(scanInternals(accumulator, seed, arguments.length >= 2, true));
  4280. }
  4281. function sequenceEqual(compareTo, comparator) {
  4282. if (comparator === void 0) { comparator = function (a, b) { return a === b; }; }
  4283. return operate(function (source, subscriber) {
  4284. var aState = createState();
  4285. var bState = createState();
  4286. var emit = function (isEqual) {
  4287. subscriber.next(isEqual);
  4288. subscriber.complete();
  4289. };
  4290. var createSubscriber = function (selfState, otherState) {
  4291. var sequenceEqualSubscriber = createOperatorSubscriber(subscriber, function (a) {
  4292. var buffer = otherState.buffer, complete = otherState.complete;
  4293. if (buffer.length === 0) {
  4294. complete ? emit(false) : selfState.buffer.push(a);
  4295. }
  4296. else {
  4297. !comparator(a, buffer.shift()) && emit(false);
  4298. }
  4299. }, function () {
  4300. selfState.complete = true;
  4301. var complete = otherState.complete, buffer = otherState.buffer;
  4302. complete && emit(buffer.length === 0);
  4303. sequenceEqualSubscriber === null || sequenceEqualSubscriber === void 0 ? void 0 : sequenceEqualSubscriber.unsubscribe();
  4304. });
  4305. return sequenceEqualSubscriber;
  4306. };
  4307. source.subscribe(createSubscriber(aState, bState));
  4308. innerFrom(compareTo).subscribe(createSubscriber(bState, aState));
  4309. });
  4310. }
  4311. function createState() {
  4312. return {
  4313. buffer: [],
  4314. complete: false,
  4315. };
  4316. }
  4317. function share(options) {
  4318. if (options === void 0) { options = {}; }
  4319. var _a = options.connector, connector = _a === void 0 ? function () { return new Subject(); } : _a, _b = options.resetOnError, resetOnError = _b === void 0 ? true : _b, _c = options.resetOnComplete, resetOnComplete = _c === void 0 ? true : _c, _d = options.resetOnRefCountZero, resetOnRefCountZero = _d === void 0 ? true : _d;
  4320. return function (wrapperSource) {
  4321. var connection;
  4322. var resetConnection;
  4323. var subject;
  4324. var refCount = 0;
  4325. var hasCompleted = false;
  4326. var hasErrored = false;
  4327. var cancelReset = function () {
  4328. resetConnection === null || resetConnection === void 0 ? void 0 : resetConnection.unsubscribe();
  4329. resetConnection = undefined;
  4330. };
  4331. var reset = function () {
  4332. cancelReset();
  4333. connection = subject = undefined;
  4334. hasCompleted = hasErrored = false;
  4335. };
  4336. var resetAndUnsubscribe = function () {
  4337. var conn = connection;
  4338. reset();
  4339. conn === null || conn === void 0 ? void 0 : conn.unsubscribe();
  4340. };
  4341. return operate(function (source, subscriber) {
  4342. refCount++;
  4343. if (!hasErrored && !hasCompleted) {
  4344. cancelReset();
  4345. }
  4346. var dest = (subject = subject !== null && subject !== void 0 ? subject : connector());
  4347. subscriber.add(function () {
  4348. refCount--;
  4349. if (refCount === 0 && !hasErrored && !hasCompleted) {
  4350. resetConnection = handleReset(resetAndUnsubscribe, resetOnRefCountZero);
  4351. }
  4352. });
  4353. dest.subscribe(subscriber);
  4354. if (!connection &&
  4355. refCount > 0) {
  4356. connection = new SafeSubscriber({
  4357. next: function (value) { return dest.next(value); },
  4358. error: function (err) {
  4359. hasErrored = true;
  4360. cancelReset();
  4361. resetConnection = handleReset(reset, resetOnError, err);
  4362. dest.error(err);
  4363. },
  4364. complete: function () {
  4365. hasCompleted = true;
  4366. cancelReset();
  4367. resetConnection = handleReset(reset, resetOnComplete);
  4368. dest.complete();
  4369. },
  4370. });
  4371. innerFrom(source).subscribe(connection);
  4372. }
  4373. })(wrapperSource);
  4374. };
  4375. }
  4376. function handleReset(reset, on) {
  4377. var args = [];
  4378. for (var _i = 2; _i < arguments.length; _i++) {
  4379. args[_i - 2] = arguments[_i];
  4380. }
  4381. if (on === true) {
  4382. reset();
  4383. return;
  4384. }
  4385. if (on === false) {
  4386. return;
  4387. }
  4388. var onSubscriber = new SafeSubscriber({
  4389. next: function () {
  4390. onSubscriber.unsubscribe();
  4391. reset();
  4392. },
  4393. });
  4394. return innerFrom(on.apply(void 0, __spreadArray([], __read(args)))).subscribe(onSubscriber);
  4395. }
  4396. function shareReplay(configOrBufferSize, windowTime, scheduler) {
  4397. var _a, _b, _c;
  4398. var bufferSize;
  4399. var refCount = false;
  4400. if (configOrBufferSize && typeof configOrBufferSize === 'object') {
  4401. (_a = configOrBufferSize.bufferSize, bufferSize = _a === void 0 ? Infinity : _a, _b = configOrBufferSize.windowTime, windowTime = _b === void 0 ? Infinity : _b, _c = configOrBufferSize.refCount, refCount = _c === void 0 ? false : _c, scheduler = configOrBufferSize.scheduler);
  4402. }
  4403. else {
  4404. bufferSize = (configOrBufferSize !== null && configOrBufferSize !== void 0 ? configOrBufferSize : Infinity);
  4405. }
  4406. return share({
  4407. connector: function () { return new ReplaySubject(bufferSize, windowTime, scheduler); },
  4408. resetOnError: true,
  4409. resetOnComplete: false,
  4410. resetOnRefCountZero: refCount,
  4411. });
  4412. }
  4413. function single(predicate) {
  4414. return operate(function (source, subscriber) {
  4415. var hasValue = false;
  4416. var singleValue;
  4417. var seenValue = false;
  4418. var index = 0;
  4419. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4420. seenValue = true;
  4421. if (!predicate || predicate(value, index++, source)) {
  4422. hasValue && subscriber.error(new SequenceError('Too many matching values'));
  4423. hasValue = true;
  4424. singleValue = value;
  4425. }
  4426. }, function () {
  4427. if (hasValue) {
  4428. subscriber.next(singleValue);
  4429. subscriber.complete();
  4430. }
  4431. else {
  4432. subscriber.error(seenValue ? new NotFoundError('No matching values') : new EmptyError());
  4433. }
  4434. }));
  4435. });
  4436. }
  4437. function skip(count) {
  4438. return filter(function (_, index) { return count <= index; });
  4439. }
  4440. function skipLast(skipCount) {
  4441. return skipCount <= 0
  4442. ?
  4443. identity
  4444. : operate(function (source, subscriber) {
  4445. var ring = new Array(skipCount);
  4446. var seen = 0;
  4447. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4448. var valueIndex = seen++;
  4449. if (valueIndex < skipCount) {
  4450. ring[valueIndex] = value;
  4451. }
  4452. else {
  4453. var index = valueIndex % skipCount;
  4454. var oldValue = ring[index];
  4455. ring[index] = value;
  4456. subscriber.next(oldValue);
  4457. }
  4458. }));
  4459. return function () {
  4460. ring = null;
  4461. };
  4462. });
  4463. }
  4464. function skipUntil(notifier) {
  4465. return operate(function (source, subscriber) {
  4466. var taking = false;
  4467. var skipSubscriber = createOperatorSubscriber(subscriber, function () {
  4468. skipSubscriber === null || skipSubscriber === void 0 ? void 0 : skipSubscriber.unsubscribe();
  4469. taking = true;
  4470. }, noop);
  4471. innerFrom(notifier).subscribe(skipSubscriber);
  4472. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return taking && subscriber.next(value); }));
  4473. });
  4474. }
  4475. function skipWhile(predicate) {
  4476. return operate(function (source, subscriber) {
  4477. var taking = false;
  4478. var index = 0;
  4479. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return (taking || (taking = !predicate(value, index++))) && subscriber.next(value); }));
  4480. });
  4481. }
  4482. function startWith() {
  4483. var values = [];
  4484. for (var _i = 0; _i < arguments.length; _i++) {
  4485. values[_i] = arguments[_i];
  4486. }
  4487. var scheduler = popScheduler(values);
  4488. return operate(function (source, subscriber) {
  4489. (scheduler ? concat(values, source, scheduler) : concat(values, source)).subscribe(subscriber);
  4490. });
  4491. }
  4492. function switchMap(project, resultSelector) {
  4493. return operate(function (source, subscriber) {
  4494. var innerSubscriber = null;
  4495. var index = 0;
  4496. var isComplete = false;
  4497. var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
  4498. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4499. innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
  4500. var innerIndex = 0;
  4501. var outerIndex = index++;
  4502. innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
  4503. innerSubscriber = null;
  4504. checkComplete();
  4505. })));
  4506. }, function () {
  4507. isComplete = true;
  4508. checkComplete();
  4509. }));
  4510. });
  4511. }
  4512. function switchAll() {
  4513. return switchMap(identity);
  4514. }
  4515. function switchMapTo(innerObservable, resultSelector) {
  4516. return isFunction(resultSelector) ? switchMap(function () { return innerObservable; }, resultSelector) : switchMap(function () { return innerObservable; });
  4517. }
  4518. function switchScan(accumulator, seed) {
  4519. return operate(function (source, subscriber) {
  4520. var state = seed;
  4521. switchMap(function (value, index) { return accumulator(state, value, index); }, function (_, innerValue) { return ((state = innerValue), innerValue); })(source).subscribe(subscriber);
  4522. return function () {
  4523. state = null;
  4524. };
  4525. });
  4526. }
  4527. function takeUntil(notifier) {
  4528. return operate(function (source, subscriber) {
  4529. innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function () { return subscriber.complete(); }, noop));
  4530. !subscriber.closed && source.subscribe(subscriber);
  4531. });
  4532. }
  4533. function takeWhile(predicate, inclusive) {
  4534. if (inclusive === void 0) { inclusive = false; }
  4535. return operate(function (source, subscriber) {
  4536. var index = 0;
  4537. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4538. var result = predicate(value, index++);
  4539. (result || inclusive) && subscriber.next(value);
  4540. !result && subscriber.complete();
  4541. }));
  4542. });
  4543. }
  4544. function tap(observerOrNext, error, complete) {
  4545. var tapObserver = isFunction(observerOrNext) || error || complete
  4546. ?
  4547. { next: observerOrNext, error: error, complete: complete }
  4548. : observerOrNext;
  4549. return tapObserver
  4550. ? operate(function (source, subscriber) {
  4551. var _a;
  4552. (_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
  4553. var isUnsub = true;
  4554. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4555. var _a;
  4556. (_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
  4557. subscriber.next(value);
  4558. }, function () {
  4559. var _a;
  4560. isUnsub = false;
  4561. (_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
  4562. subscriber.complete();
  4563. }, function (err) {
  4564. var _a;
  4565. isUnsub = false;
  4566. (_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
  4567. subscriber.error(err);
  4568. }, function () {
  4569. var _a, _b;
  4570. if (isUnsub) {
  4571. (_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
  4572. }
  4573. (_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
  4574. }));
  4575. })
  4576. :
  4577. identity;
  4578. }
  4579. function throttle(durationSelector, config) {
  4580. return operate(function (source, subscriber) {
  4581. var _a = config !== null && config !== void 0 ? config : {}, _b = _a.leading, leading = _b === void 0 ? true : _b, _c = _a.trailing, trailing = _c === void 0 ? false : _c;
  4582. var hasValue = false;
  4583. var sendValue = null;
  4584. var throttled = null;
  4585. var isComplete = false;
  4586. var endThrottling = function () {
  4587. throttled === null || throttled === void 0 ? void 0 : throttled.unsubscribe();
  4588. throttled = null;
  4589. if (trailing) {
  4590. send();
  4591. isComplete && subscriber.complete();
  4592. }
  4593. };
  4594. var cleanupThrottling = function () {
  4595. throttled = null;
  4596. isComplete && subscriber.complete();
  4597. };
  4598. var startThrottle = function (value) {
  4599. return (throttled = innerFrom(durationSelector(value)).subscribe(createOperatorSubscriber(subscriber, endThrottling, cleanupThrottling)));
  4600. };
  4601. var send = function () {
  4602. if (hasValue) {
  4603. hasValue = false;
  4604. var value = sendValue;
  4605. sendValue = null;
  4606. subscriber.next(value);
  4607. !isComplete && startThrottle(value);
  4608. }
  4609. };
  4610. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4611. hasValue = true;
  4612. sendValue = value;
  4613. !(throttled && !throttled.closed) && (leading ? send() : startThrottle(value));
  4614. }, function () {
  4615. isComplete = true;
  4616. !(trailing && hasValue && throttled && !throttled.closed) && subscriber.complete();
  4617. }));
  4618. });
  4619. }
  4620. function throttleTime(duration, scheduler, config) {
  4621. if (scheduler === void 0) { scheduler = asyncScheduler; }
  4622. var duration$ = timer(duration, scheduler);
  4623. return throttle(function () { return duration$; }, config);
  4624. }
  4625. function timeInterval(scheduler) {
  4626. if (scheduler === void 0) { scheduler = asyncScheduler; }
  4627. return operate(function (source, subscriber) {
  4628. var last = scheduler.now();
  4629. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4630. var now = scheduler.now();
  4631. var interval = now - last;
  4632. last = now;
  4633. subscriber.next(new TimeInterval(value, interval));
  4634. }));
  4635. });
  4636. }
  4637. var TimeInterval = (function () {
  4638. function TimeInterval(value, interval) {
  4639. this.value = value;
  4640. this.interval = interval;
  4641. }
  4642. return TimeInterval;
  4643. }());
  4644. function timeoutWith(due, withObservable, scheduler) {
  4645. var first;
  4646. var each;
  4647. var _with;
  4648. scheduler = scheduler !== null && scheduler !== void 0 ? scheduler : async;
  4649. if (isValidDate(due)) {
  4650. first = due;
  4651. }
  4652. else if (typeof due === 'number') {
  4653. each = due;
  4654. }
  4655. if (withObservable) {
  4656. _with = function () { return withObservable; };
  4657. }
  4658. else {
  4659. throw new TypeError('No observable provided to switch to');
  4660. }
  4661. if (first == null && each == null) {
  4662. throw new TypeError('No timeout provided.');
  4663. }
  4664. return timeout({
  4665. first: first,
  4666. each: each,
  4667. scheduler: scheduler,
  4668. with: _with,
  4669. });
  4670. }
  4671. function timestamp(timestampProvider) {
  4672. if (timestampProvider === void 0) { timestampProvider = dateTimestampProvider; }
  4673. return map(function (value) { return ({ value: value, timestamp: timestampProvider.now() }); });
  4674. }
  4675. function window(windowBoundaries) {
  4676. return operate(function (source, subscriber) {
  4677. var windowSubject = new Subject();
  4678. subscriber.next(windowSubject.asObservable());
  4679. var errorHandler = function (err) {
  4680. windowSubject.error(err);
  4681. subscriber.error(err);
  4682. };
  4683. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return windowSubject === null || windowSubject === void 0 ? void 0 : windowSubject.next(value); }, function () {
  4684. windowSubject.complete();
  4685. subscriber.complete();
  4686. }, errorHandler));
  4687. innerFrom(windowBoundaries).subscribe(createOperatorSubscriber(subscriber, function () {
  4688. windowSubject.complete();
  4689. subscriber.next((windowSubject = new Subject()));
  4690. }, noop, errorHandler));
  4691. return function () {
  4692. windowSubject === null || windowSubject === void 0 ? void 0 : windowSubject.unsubscribe();
  4693. windowSubject = null;
  4694. };
  4695. });
  4696. }
  4697. function windowCount(windowSize, startWindowEvery) {
  4698. if (startWindowEvery === void 0) { startWindowEvery = 0; }
  4699. var startEvery = startWindowEvery > 0 ? startWindowEvery : windowSize;
  4700. return operate(function (source, subscriber) {
  4701. var windows = [new Subject()];
  4702. var count = 0;
  4703. subscriber.next(windows[0].asObservable());
  4704. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4705. var e_1, _a;
  4706. try {
  4707. for (var windows_1 = __values(windows), windows_1_1 = windows_1.next(); !windows_1_1.done; windows_1_1 = windows_1.next()) {
  4708. var window_1 = windows_1_1.value;
  4709. window_1.next(value);
  4710. }
  4711. }
  4712. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  4713. finally {
  4714. try {
  4715. if (windows_1_1 && !windows_1_1.done && (_a = windows_1.return)) _a.call(windows_1);
  4716. }
  4717. finally { if (e_1) throw e_1.error; }
  4718. }
  4719. var c = count - windowSize + 1;
  4720. if (c >= 0 && c % startEvery === 0) {
  4721. windows.shift().complete();
  4722. }
  4723. if (++count % startEvery === 0) {
  4724. var window_2 = new Subject();
  4725. windows.push(window_2);
  4726. subscriber.next(window_2.asObservable());
  4727. }
  4728. }, function () {
  4729. while (windows.length > 0) {
  4730. windows.shift().complete();
  4731. }
  4732. subscriber.complete();
  4733. }, function (err) {
  4734. while (windows.length > 0) {
  4735. windows.shift().error(err);
  4736. }
  4737. subscriber.error(err);
  4738. }, function () {
  4739. windows = null;
  4740. }));
  4741. });
  4742. }
  4743. function windowTime(windowTimeSpan) {
  4744. var _a, _b;
  4745. var otherArgs = [];
  4746. for (var _i = 1; _i < arguments.length; _i++) {
  4747. otherArgs[_i - 1] = arguments[_i];
  4748. }
  4749. var scheduler = (_a = popScheduler(otherArgs)) !== null && _a !== void 0 ? _a : asyncScheduler;
  4750. var windowCreationInterval = (_b = otherArgs[0]) !== null && _b !== void 0 ? _b : null;
  4751. var maxWindowSize = otherArgs[1] || Infinity;
  4752. return operate(function (source, subscriber) {
  4753. var windowRecords = [];
  4754. var restartOnClose = false;
  4755. var closeWindow = function (record) {
  4756. var window = record.window, subs = record.subs;
  4757. window.complete();
  4758. subs.unsubscribe();
  4759. arrRemove(windowRecords, record);
  4760. restartOnClose && startWindow();
  4761. };
  4762. var startWindow = function () {
  4763. if (windowRecords) {
  4764. var subs = new Subscription();
  4765. subscriber.add(subs);
  4766. var window_1 = new Subject();
  4767. var record_1 = {
  4768. window: window_1,
  4769. subs: subs,
  4770. seen: 0,
  4771. };
  4772. windowRecords.push(record_1);
  4773. subscriber.next(window_1.asObservable());
  4774. executeSchedule(subs, scheduler, function () { return closeWindow(record_1); }, windowTimeSpan);
  4775. }
  4776. };
  4777. if (windowCreationInterval !== null && windowCreationInterval >= 0) {
  4778. executeSchedule(subscriber, scheduler, startWindow, windowCreationInterval, true);
  4779. }
  4780. else {
  4781. restartOnClose = true;
  4782. }
  4783. startWindow();
  4784. var loop = function (cb) { return windowRecords.slice().forEach(cb); };
  4785. var terminate = function (cb) {
  4786. loop(function (_a) {
  4787. var window = _a.window;
  4788. return cb(window);
  4789. });
  4790. cb(subscriber);
  4791. subscriber.unsubscribe();
  4792. };
  4793. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4794. loop(function (record) {
  4795. record.window.next(value);
  4796. maxWindowSize <= ++record.seen && closeWindow(record);
  4797. });
  4798. }, function () { return terminate(function (consumer) { return consumer.complete(); }); }, function (err) { return terminate(function (consumer) { return consumer.error(err); }); }));
  4799. return function () {
  4800. windowRecords = null;
  4801. };
  4802. });
  4803. }
  4804. function windowToggle(openings, closingSelector) {
  4805. return operate(function (source, subscriber) {
  4806. var windows = [];
  4807. var handleError = function (err) {
  4808. while (0 < windows.length) {
  4809. windows.shift().error(err);
  4810. }
  4811. subscriber.error(err);
  4812. };
  4813. innerFrom(openings).subscribe(createOperatorSubscriber(subscriber, function (openValue) {
  4814. var window = new Subject();
  4815. windows.push(window);
  4816. var closingSubscription = new Subscription();
  4817. var closeWindow = function () {
  4818. arrRemove(windows, window);
  4819. window.complete();
  4820. closingSubscription.unsubscribe();
  4821. };
  4822. var closingNotifier;
  4823. try {
  4824. closingNotifier = innerFrom(closingSelector(openValue));
  4825. }
  4826. catch (err) {
  4827. handleError(err);
  4828. return;
  4829. }
  4830. subscriber.next(window.asObservable());
  4831. closingSubscription.add(closingNotifier.subscribe(createOperatorSubscriber(subscriber, closeWindow, noop, handleError)));
  4832. }, noop));
  4833. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4834. var e_1, _a;
  4835. var windowsCopy = windows.slice();
  4836. try {
  4837. for (var windowsCopy_1 = __values(windowsCopy), windowsCopy_1_1 = windowsCopy_1.next(); !windowsCopy_1_1.done; windowsCopy_1_1 = windowsCopy_1.next()) {
  4838. var window_1 = windowsCopy_1_1.value;
  4839. window_1.next(value);
  4840. }
  4841. }
  4842. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  4843. finally {
  4844. try {
  4845. if (windowsCopy_1_1 && !windowsCopy_1_1.done && (_a = windowsCopy_1.return)) _a.call(windowsCopy_1);
  4846. }
  4847. finally { if (e_1) throw e_1.error; }
  4848. }
  4849. }, function () {
  4850. while (0 < windows.length) {
  4851. windows.shift().complete();
  4852. }
  4853. subscriber.complete();
  4854. }, handleError, function () {
  4855. while (0 < windows.length) {
  4856. windows.shift().unsubscribe();
  4857. }
  4858. }));
  4859. });
  4860. }
  4861. function windowWhen(closingSelector) {
  4862. return operate(function (source, subscriber) {
  4863. var window;
  4864. var closingSubscriber;
  4865. var handleError = function (err) {
  4866. window.error(err);
  4867. subscriber.error(err);
  4868. };
  4869. var openWindow = function () {
  4870. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  4871. window === null || window === void 0 ? void 0 : window.complete();
  4872. window = new Subject();
  4873. subscriber.next(window.asObservable());
  4874. var closingNotifier;
  4875. try {
  4876. closingNotifier = innerFrom(closingSelector());
  4877. }
  4878. catch (err) {
  4879. handleError(err);
  4880. return;
  4881. }
  4882. closingNotifier.subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openWindow, openWindow, handleError)));
  4883. };
  4884. openWindow();
  4885. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return window.next(value); }, function () {
  4886. window.complete();
  4887. subscriber.complete();
  4888. }, handleError, function () {
  4889. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  4890. window = null;
  4891. }));
  4892. });
  4893. }
  4894. function withLatestFrom() {
  4895. var inputs = [];
  4896. for (var _i = 0; _i < arguments.length; _i++) {
  4897. inputs[_i] = arguments[_i];
  4898. }
  4899. var project = popResultSelector(inputs);
  4900. return operate(function (source, subscriber) {
  4901. var len = inputs.length;
  4902. var otherValues = new Array(len);
  4903. var hasValue = inputs.map(function () { return false; });
  4904. var ready = false;
  4905. var _loop_1 = function (i) {
  4906. innerFrom(inputs[i]).subscribe(createOperatorSubscriber(subscriber, function (value) {
  4907. otherValues[i] = value;
  4908. if (!ready && !hasValue[i]) {
  4909. hasValue[i] = true;
  4910. (ready = hasValue.every(identity)) && (hasValue = null);
  4911. }
  4912. }, noop));
  4913. };
  4914. for (var i = 0; i < len; i++) {
  4915. _loop_1(i);
  4916. }
  4917. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  4918. if (ready) {
  4919. var values = __spreadArray([value], __read(otherValues));
  4920. subscriber.next(project ? project.apply(void 0, __spreadArray([], __read(values))) : values);
  4921. }
  4922. }));
  4923. });
  4924. }
  4925. function zipAll(project) {
  4926. return joinAllInternals(zip, project);
  4927. }
  4928. function zip$1() {
  4929. var sources = [];
  4930. for (var _i = 0; _i < arguments.length; _i++) {
  4931. sources[_i] = arguments[_i];
  4932. }
  4933. return operate(function (source, subscriber) {
  4934. zip.apply(void 0, __spreadArray([source], __read(sources))).subscribe(subscriber);
  4935. });
  4936. }
  4937. function zipWith() {
  4938. var otherInputs = [];
  4939. for (var _i = 0; _i < arguments.length; _i++) {
  4940. otherInputs[_i] = arguments[_i];
  4941. }
  4942. return zip$1.apply(void 0, __spreadArray([], __read(otherInputs)));
  4943. }
  4944. function partition$1(predicate, thisArg) {
  4945. return function (source) {
  4946. return [filter(predicate, thisArg)(source), filter(not(predicate, thisArg))(source)];
  4947. };
  4948. }
  4949. function race$1() {
  4950. var args = [];
  4951. for (var _i = 0; _i < arguments.length; _i++) {
  4952. args[_i] = arguments[_i];
  4953. }
  4954. return raceWith.apply(void 0, __spreadArray([], __read(argsOrArgArray(args))));
  4955. }
  4956. var _operators = /*#__PURE__*/Object.freeze({
  4957. audit: audit,
  4958. auditTime: auditTime,
  4959. buffer: buffer,
  4960. bufferCount: bufferCount,
  4961. bufferTime: bufferTime,
  4962. bufferToggle: bufferToggle,
  4963. bufferWhen: bufferWhen,
  4964. catchError: catchError,
  4965. combineAll: combineAll,
  4966. combineLatestAll: combineLatestAll,
  4967. combineLatest: combineLatest$1,
  4968. combineLatestWith: combineLatestWith,
  4969. concat: concat$1,
  4970. concatAll: concatAll,
  4971. concatMap: concatMap,
  4972. concatMapTo: concatMapTo,
  4973. concatWith: concatWith,
  4974. connect: connect,
  4975. count: count,
  4976. debounce: debounce,
  4977. debounceTime: debounceTime,
  4978. defaultIfEmpty: defaultIfEmpty,
  4979. delay: delay,
  4980. delayWhen: delayWhen,
  4981. dematerialize: dematerialize,
  4982. distinct: distinct,
  4983. distinctUntilChanged: distinctUntilChanged,
  4984. distinctUntilKeyChanged: distinctUntilKeyChanged,
  4985. elementAt: elementAt,
  4986. endWith: endWith,
  4987. every: every,
  4988. exhaust: exhaust,
  4989. exhaustAll: exhaustAll,
  4990. exhaustMap: exhaustMap,
  4991. expand: expand,
  4992. filter: filter,
  4993. finalize: finalize,
  4994. find: find,
  4995. findIndex: findIndex,
  4996. first: first,
  4997. groupBy: groupBy,
  4998. ignoreElements: ignoreElements,
  4999. isEmpty: isEmpty,
  5000. last: last$1,
  5001. map: map,
  5002. mapTo: mapTo,
  5003. materialize: materialize,
  5004. max: max,
  5005. merge: merge$1,
  5006. mergeAll: mergeAll,
  5007. flatMap: flatMap,
  5008. mergeMap: mergeMap,
  5009. mergeMapTo: mergeMapTo,
  5010. mergeScan: mergeScan,
  5011. mergeWith: mergeWith,
  5012. min: min,
  5013. multicast: multicast,
  5014. observeOn: observeOn,
  5015. onErrorResumeNext: onErrorResumeNext$1,
  5016. pairwise: pairwise,
  5017. partition: partition$1,
  5018. pluck: pluck,
  5019. publish: publish,
  5020. publishBehavior: publishBehavior,
  5021. publishLast: publishLast,
  5022. publishReplay: publishReplay,
  5023. race: race$1,
  5024. raceWith: raceWith,
  5025. reduce: reduce,
  5026. repeat: repeat,
  5027. repeatWhen: repeatWhen,
  5028. retry: retry,
  5029. retryWhen: retryWhen,
  5030. refCount: refCount,
  5031. sample: sample,
  5032. sampleTime: sampleTime,
  5033. scan: scan,
  5034. sequenceEqual: sequenceEqual,
  5035. share: share,
  5036. shareReplay: shareReplay,
  5037. single: single,
  5038. skip: skip,
  5039. skipLast: skipLast,
  5040. skipUntil: skipUntil,
  5041. skipWhile: skipWhile,
  5042. startWith: startWith,
  5043. subscribeOn: subscribeOn,
  5044. switchAll: switchAll,
  5045. switchMap: switchMap,
  5046. switchMapTo: switchMapTo,
  5047. switchScan: switchScan,
  5048. take: take,
  5049. takeLast: takeLast,
  5050. takeUntil: takeUntil,
  5051. takeWhile: takeWhile,
  5052. tap: tap,
  5053. throttle: throttle,
  5054. throttleTime: throttleTime,
  5055. throwIfEmpty: throwIfEmpty,
  5056. timeInterval: timeInterval,
  5057. timeout: timeout,
  5058. timeoutWith: timeoutWith,
  5059. timestamp: timestamp,
  5060. toArray: toArray,
  5061. window: window,
  5062. windowCount: windowCount,
  5063. windowTime: windowTime,
  5064. windowToggle: windowToggle,
  5065. windowWhen: windowWhen,
  5066. withLatestFrom: withLatestFrom,
  5067. zip: zip$1,
  5068. zipAll: zipAll,
  5069. zipWith: zipWith
  5070. });
  5071. var SubscriptionLog = (function () {
  5072. function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
  5073. if (unsubscribedFrame === void 0) { unsubscribedFrame = Infinity; }
  5074. this.subscribedFrame = subscribedFrame;
  5075. this.unsubscribedFrame = unsubscribedFrame;
  5076. }
  5077. return SubscriptionLog;
  5078. }());
  5079. var SubscriptionLoggable = (function () {
  5080. function SubscriptionLoggable() {
  5081. this.subscriptions = [];
  5082. }
  5083. SubscriptionLoggable.prototype.logSubscribedFrame = function () {
  5084. this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
  5085. return this.subscriptions.length - 1;
  5086. };
  5087. SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
  5088. var subscriptionLogs = this.subscriptions;
  5089. var oldSubscriptionLog = subscriptionLogs[index];
  5090. subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
  5091. };
  5092. return SubscriptionLoggable;
  5093. }());
  5094. function applyMixins(derivedCtor, baseCtors) {
  5095. for (var i = 0, len = baseCtors.length; i < len; i++) {
  5096. var baseCtor = baseCtors[i];
  5097. var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
  5098. for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
  5099. var name_1 = propertyKeys[j];
  5100. derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
  5101. }
  5102. }
  5103. }
  5104. var ColdObservable = (function (_super) {
  5105. __extends(ColdObservable, _super);
  5106. function ColdObservable(messages, scheduler) {
  5107. var _this = _super.call(this, function (subscriber) {
  5108. var observable = this;
  5109. var index = observable.logSubscribedFrame();
  5110. var subscription = new Subscription();
  5111. subscription.add(new Subscription(function () {
  5112. observable.logUnsubscribedFrame(index);
  5113. }));
  5114. observable.scheduleMessages(subscriber);
  5115. return subscription;
  5116. }) || this;
  5117. _this.messages = messages;
  5118. _this.subscriptions = [];
  5119. _this.scheduler = scheduler;
  5120. return _this;
  5121. }
  5122. ColdObservable.prototype.scheduleMessages = function (subscriber) {
  5123. var messagesLength = this.messages.length;
  5124. for (var i = 0; i < messagesLength; i++) {
  5125. var message = this.messages[i];
  5126. subscriber.add(this.scheduler.schedule(function (state) {
  5127. var _a = state, notification = _a.message.notification, destination = _a.subscriber;
  5128. observeNotification(notification, destination);
  5129. }, message.frame, { message: message, subscriber: subscriber }));
  5130. }
  5131. };
  5132. return ColdObservable;
  5133. }(Observable));
  5134. applyMixins(ColdObservable, [SubscriptionLoggable]);
  5135. var HotObservable = (function (_super) {
  5136. __extends(HotObservable, _super);
  5137. function HotObservable(messages, scheduler) {
  5138. var _this = _super.call(this) || this;
  5139. _this.messages = messages;
  5140. _this.subscriptions = [];
  5141. _this.scheduler = scheduler;
  5142. return _this;
  5143. }
  5144. HotObservable.prototype._subscribe = function (subscriber) {
  5145. var subject = this;
  5146. var index = subject.logSubscribedFrame();
  5147. var subscription = new Subscription();
  5148. subscription.add(new Subscription(function () {
  5149. subject.logUnsubscribedFrame(index);
  5150. }));
  5151. subscription.add(_super.prototype._subscribe.call(this, subscriber));
  5152. return subscription;
  5153. };
  5154. HotObservable.prototype.setup = function () {
  5155. var subject = this;
  5156. var messagesLength = subject.messages.length;
  5157. var _loop_1 = function (i) {
  5158. (function () {
  5159. var _a = subject.messages[i], notification = _a.notification, frame = _a.frame;
  5160. subject.scheduler.schedule(function () {
  5161. observeNotification(notification, subject);
  5162. }, frame);
  5163. })();
  5164. };
  5165. for (var i = 0; i < messagesLength; i++) {
  5166. _loop_1(i);
  5167. }
  5168. };
  5169. return HotObservable;
  5170. }(Subject));
  5171. applyMixins(HotObservable, [SubscriptionLoggable]);
  5172. var defaultMaxFrame = 750;
  5173. var TestScheduler = (function (_super) {
  5174. __extends(TestScheduler, _super);
  5175. function TestScheduler(assertDeepEqual) {
  5176. var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
  5177. _this.assertDeepEqual = assertDeepEqual;
  5178. _this.hotObservables = [];
  5179. _this.coldObservables = [];
  5180. _this.flushTests = [];
  5181. _this.runMode = false;
  5182. return _this;
  5183. }
  5184. TestScheduler.prototype.createTime = function (marbles) {
  5185. var indexOf = this.runMode ? marbles.trim().indexOf('|') : marbles.indexOf('|');
  5186. if (indexOf === -1) {
  5187. throw new Error('marble diagram for time should have a completion marker "|"');
  5188. }
  5189. return indexOf * TestScheduler.frameTimeFactor;
  5190. };
  5191. TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
  5192. if (marbles.indexOf('^') !== -1) {
  5193. throw new Error('cold observable cannot have subscription offset "^"');
  5194. }
  5195. if (marbles.indexOf('!') !== -1) {
  5196. throw new Error('cold observable cannot have unsubscription marker "!"');
  5197. }
  5198. var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
  5199. var cold = new ColdObservable(messages, this);
  5200. this.coldObservables.push(cold);
  5201. return cold;
  5202. };
  5203. TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
  5204. if (marbles.indexOf('!') !== -1) {
  5205. throw new Error('hot observable cannot have unsubscription marker "!"');
  5206. }
  5207. var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
  5208. var subject = new HotObservable(messages, this);
  5209. this.hotObservables.push(subject);
  5210. return subject;
  5211. };
  5212. TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
  5213. var _this = this;
  5214. var messages = [];
  5215. observable.subscribe({
  5216. next: function (value) {
  5217. messages.push({ frame: _this.frame - outerFrame, notification: nextNotification(value) });
  5218. },
  5219. error: function (error) {
  5220. messages.push({ frame: _this.frame - outerFrame, notification: errorNotification(error) });
  5221. },
  5222. complete: function () {
  5223. messages.push({ frame: _this.frame - outerFrame, notification: COMPLETE_NOTIFICATION });
  5224. },
  5225. });
  5226. return messages;
  5227. };
  5228. TestScheduler.prototype.expectObservable = function (observable, subscriptionMarbles) {
  5229. var _this = this;
  5230. if (subscriptionMarbles === void 0) { subscriptionMarbles = null; }
  5231. var actual = [];
  5232. var flushTest = { actual: actual, ready: false };
  5233. var subscriptionParsed = TestScheduler.parseMarblesAsSubscriptions(subscriptionMarbles, this.runMode);
  5234. var subscriptionFrame = subscriptionParsed.subscribedFrame === Infinity ? 0 : subscriptionParsed.subscribedFrame;
  5235. var unsubscriptionFrame = subscriptionParsed.unsubscribedFrame;
  5236. var subscription;
  5237. this.schedule(function () {
  5238. subscription = observable.subscribe({
  5239. next: function (x) {
  5240. var value = x instanceof Observable ? _this.materializeInnerObservable(x, _this.frame) : x;
  5241. actual.push({ frame: _this.frame, notification: nextNotification(value) });
  5242. },
  5243. error: function (error) {
  5244. actual.push({ frame: _this.frame, notification: errorNotification(error) });
  5245. },
  5246. complete: function () {
  5247. actual.push({ frame: _this.frame, notification: COMPLETE_NOTIFICATION });
  5248. },
  5249. });
  5250. }, subscriptionFrame);
  5251. if (unsubscriptionFrame !== Infinity) {
  5252. this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
  5253. }
  5254. this.flushTests.push(flushTest);
  5255. var runMode = this.runMode;
  5256. return {
  5257. toBe: function (marbles, values, errorValue) {
  5258. flushTest.ready = true;
  5259. flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
  5260. },
  5261. toEqual: function (other) {
  5262. flushTest.ready = true;
  5263. flushTest.expected = [];
  5264. _this.schedule(function () {
  5265. subscription = other.subscribe({
  5266. next: function (x) {
  5267. var value = x instanceof Observable ? _this.materializeInnerObservable(x, _this.frame) : x;
  5268. flushTest.expected.push({ frame: _this.frame, notification: nextNotification(value) });
  5269. },
  5270. error: function (error) {
  5271. flushTest.expected.push({ frame: _this.frame, notification: errorNotification(error) });
  5272. },
  5273. complete: function () {
  5274. flushTest.expected.push({ frame: _this.frame, notification: COMPLETE_NOTIFICATION });
  5275. },
  5276. });
  5277. }, subscriptionFrame);
  5278. },
  5279. };
  5280. };
  5281. TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
  5282. var flushTest = { actual: actualSubscriptionLogs, ready: false };
  5283. this.flushTests.push(flushTest);
  5284. var runMode = this.runMode;
  5285. return {
  5286. toBe: function (marblesOrMarblesArray) {
  5287. var marblesArray = typeof marblesOrMarblesArray === 'string' ? [marblesOrMarblesArray] : marblesOrMarblesArray;
  5288. flushTest.ready = true;
  5289. flushTest.expected = marblesArray
  5290. .map(function (marbles) { return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode); })
  5291. .filter(function (marbles) { return marbles.subscribedFrame !== Infinity; });
  5292. },
  5293. };
  5294. };
  5295. TestScheduler.prototype.flush = function () {
  5296. var _this = this;
  5297. var hotObservables = this.hotObservables;
  5298. while (hotObservables.length > 0) {
  5299. hotObservables.shift().setup();
  5300. }
  5301. _super.prototype.flush.call(this);
  5302. this.flushTests = this.flushTests.filter(function (test) {
  5303. if (test.ready) {
  5304. _this.assertDeepEqual(test.actual, test.expected);
  5305. return false;
  5306. }
  5307. return true;
  5308. });
  5309. };
  5310. TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
  5311. var _this = this;
  5312. if (runMode === void 0) { runMode = false; }
  5313. if (typeof marbles !== 'string') {
  5314. return new SubscriptionLog(Infinity);
  5315. }
  5316. var characters = __spreadArray([], __read(marbles));
  5317. var len = characters.length;
  5318. var groupStart = -1;
  5319. var subscriptionFrame = Infinity;
  5320. var unsubscriptionFrame = Infinity;
  5321. var frame = 0;
  5322. var _loop_1 = function (i) {
  5323. var nextFrame = frame;
  5324. var advanceFrameBy = function (count) {
  5325. nextFrame += count * _this.frameTimeFactor;
  5326. };
  5327. var c = characters[i];
  5328. switch (c) {
  5329. case ' ':
  5330. if (!runMode) {
  5331. advanceFrameBy(1);
  5332. }
  5333. break;
  5334. case '-':
  5335. advanceFrameBy(1);
  5336. break;
  5337. case '(':
  5338. groupStart = frame;
  5339. advanceFrameBy(1);
  5340. break;
  5341. case ')':
  5342. groupStart = -1;
  5343. advanceFrameBy(1);
  5344. break;
  5345. case '^':
  5346. if (subscriptionFrame !== Infinity) {
  5347. throw new Error("found a second subscription point '^' in a " + 'subscription marble diagram. There can only be one.');
  5348. }
  5349. subscriptionFrame = groupStart > -1 ? groupStart : frame;
  5350. advanceFrameBy(1);
  5351. break;
  5352. case '!':
  5353. if (unsubscriptionFrame !== Infinity) {
  5354. throw new Error("found a second unsubscription point '!' in a " + 'subscription marble diagram. There can only be one.');
  5355. }
  5356. unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
  5357. break;
  5358. default:
  5359. if (runMode && c.match(/^[0-9]$/)) {
  5360. if (i === 0 || characters[i - 1] === ' ') {
  5361. var buffer = characters.slice(i).join('');
  5362. var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
  5363. if (match) {
  5364. i += match[0].length - 1;
  5365. var duration = parseFloat(match[1]);
  5366. var unit = match[2];
  5367. var durationInMs = void 0;
  5368. switch (unit) {
  5369. case 'ms':
  5370. durationInMs = duration;
  5371. break;
  5372. case 's':
  5373. durationInMs = duration * 1000;
  5374. break;
  5375. case 'm':
  5376. durationInMs = duration * 1000 * 60;
  5377. break;
  5378. default:
  5379. break;
  5380. }
  5381. advanceFrameBy(durationInMs / this_1.frameTimeFactor);
  5382. break;
  5383. }
  5384. }
  5385. }
  5386. throw new Error("there can only be '^' and '!' markers in a " + "subscription marble diagram. Found instead '" + c + "'.");
  5387. }
  5388. frame = nextFrame;
  5389. out_i_1 = i;
  5390. };
  5391. var this_1 = this, out_i_1;
  5392. for (var i = 0; i < len; i++) {
  5393. _loop_1(i);
  5394. i = out_i_1;
  5395. }
  5396. if (unsubscriptionFrame < 0) {
  5397. return new SubscriptionLog(subscriptionFrame);
  5398. }
  5399. else {
  5400. return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
  5401. }
  5402. };
  5403. TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
  5404. var _this = this;
  5405. if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
  5406. if (runMode === void 0) { runMode = false; }
  5407. if (marbles.indexOf('!') !== -1) {
  5408. throw new Error('conventional marble diagrams cannot have the ' + 'unsubscription marker "!"');
  5409. }
  5410. var characters = __spreadArray([], __read(marbles));
  5411. var len = characters.length;
  5412. var testMessages = [];
  5413. var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
  5414. var frame = subIndex === -1 ? 0 : subIndex * -this.frameTimeFactor;
  5415. var getValue = typeof values !== 'object'
  5416. ? function (x) { return x; }
  5417. : function (x) {
  5418. if (materializeInnerObservables && values[x] instanceof ColdObservable) {
  5419. return values[x].messages;
  5420. }
  5421. return values[x];
  5422. };
  5423. var groupStart = -1;
  5424. var _loop_2 = function (i) {
  5425. var nextFrame = frame;
  5426. var advanceFrameBy = function (count) {
  5427. nextFrame += count * _this.frameTimeFactor;
  5428. };
  5429. var notification = void 0;
  5430. var c = characters[i];
  5431. switch (c) {
  5432. case ' ':
  5433. if (!runMode) {
  5434. advanceFrameBy(1);
  5435. }
  5436. break;
  5437. case '-':
  5438. advanceFrameBy(1);
  5439. break;
  5440. case '(':
  5441. groupStart = frame;
  5442. advanceFrameBy(1);
  5443. break;
  5444. case ')':
  5445. groupStart = -1;
  5446. advanceFrameBy(1);
  5447. break;
  5448. case '|':
  5449. notification = COMPLETE_NOTIFICATION;
  5450. advanceFrameBy(1);
  5451. break;
  5452. case '^':
  5453. advanceFrameBy(1);
  5454. break;
  5455. case '#':
  5456. notification = errorNotification(errorValue || 'error');
  5457. advanceFrameBy(1);
  5458. break;
  5459. default:
  5460. if (runMode && c.match(/^[0-9]$/)) {
  5461. if (i === 0 || characters[i - 1] === ' ') {
  5462. var buffer = characters.slice(i).join('');
  5463. var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
  5464. if (match) {
  5465. i += match[0].length - 1;
  5466. var duration = parseFloat(match[1]);
  5467. var unit = match[2];
  5468. var durationInMs = void 0;
  5469. switch (unit) {
  5470. case 'ms':
  5471. durationInMs = duration;
  5472. break;
  5473. case 's':
  5474. durationInMs = duration * 1000;
  5475. break;
  5476. case 'm':
  5477. durationInMs = duration * 1000 * 60;
  5478. break;
  5479. default:
  5480. break;
  5481. }
  5482. advanceFrameBy(durationInMs / this_2.frameTimeFactor);
  5483. break;
  5484. }
  5485. }
  5486. }
  5487. notification = nextNotification(getValue(c));
  5488. advanceFrameBy(1);
  5489. break;
  5490. }
  5491. if (notification) {
  5492. testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
  5493. }
  5494. frame = nextFrame;
  5495. out_i_2 = i;
  5496. };
  5497. var this_2 = this, out_i_2;
  5498. for (var i = 0; i < len; i++) {
  5499. _loop_2(i);
  5500. i = out_i_2;
  5501. }
  5502. return testMessages;
  5503. };
  5504. TestScheduler.prototype.createAnimator = function () {
  5505. var _this = this;
  5506. if (!this.runMode) {
  5507. throw new Error('animate() must only be used in run mode');
  5508. }
  5509. var lastHandle = 0;
  5510. var map;
  5511. var delegate = {
  5512. requestAnimationFrame: function (callback) {
  5513. if (!map) {
  5514. throw new Error('animate() was not called within run()');
  5515. }
  5516. var handle = ++lastHandle;
  5517. map.set(handle, callback);
  5518. return handle;
  5519. },
  5520. cancelAnimationFrame: function (handle) {
  5521. if (!map) {
  5522. throw new Error('animate() was not called within run()');
  5523. }
  5524. map.delete(handle);
  5525. },
  5526. };
  5527. var animate = function (marbles) {
  5528. var e_1, _a;
  5529. if (map) {
  5530. throw new Error('animate() must not be called more than once within run()');
  5531. }
  5532. if (/[|#]/.test(marbles)) {
  5533. throw new Error('animate() must not complete or error');
  5534. }
  5535. map = new Map();
  5536. var messages = TestScheduler.parseMarbles(marbles, undefined, undefined, undefined, true);
  5537. try {
  5538. for (var messages_1 = __values(messages), messages_1_1 = messages_1.next(); !messages_1_1.done; messages_1_1 = messages_1.next()) {
  5539. var message = messages_1_1.value;
  5540. _this.schedule(function () {
  5541. var e_2, _a;
  5542. var now = _this.now();
  5543. var callbacks = Array.from(map.values());
  5544. map.clear();
  5545. try {
  5546. for (var callbacks_1 = (e_2 = void 0, __values(callbacks)), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
  5547. var callback = callbacks_1_1.value;
  5548. callback(now);
  5549. }
  5550. }
  5551. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  5552. finally {
  5553. try {
  5554. if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
  5555. }
  5556. finally { if (e_2) throw e_2.error; }
  5557. }
  5558. }, message.frame);
  5559. }
  5560. }
  5561. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  5562. finally {
  5563. try {
  5564. if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) _a.call(messages_1);
  5565. }
  5566. finally { if (e_1) throw e_1.error; }
  5567. }
  5568. };
  5569. return { animate: animate, delegate: delegate };
  5570. };
  5571. TestScheduler.prototype.createDelegates = function () {
  5572. var _this = this;
  5573. var lastHandle = 0;
  5574. var scheduleLookup = new Map();
  5575. var run = function () {
  5576. var now = _this.now();
  5577. var scheduledRecords = Array.from(scheduleLookup.values());
  5578. var scheduledRecordsDue = scheduledRecords.filter(function (_a) {
  5579. var due = _a.due;
  5580. return due <= now;
  5581. });
  5582. var dueImmediates = scheduledRecordsDue.filter(function (_a) {
  5583. var type = _a.type;
  5584. return type === 'immediate';
  5585. });
  5586. if (dueImmediates.length > 0) {
  5587. var _a = dueImmediates[0], handle = _a.handle, handler = _a.handler;
  5588. scheduleLookup.delete(handle);
  5589. handler();
  5590. return;
  5591. }
  5592. var dueIntervals = scheduledRecordsDue.filter(function (_a) {
  5593. var type = _a.type;
  5594. return type === 'interval';
  5595. });
  5596. if (dueIntervals.length > 0) {
  5597. var firstDueInterval = dueIntervals[0];
  5598. var duration = firstDueInterval.duration, handler = firstDueInterval.handler;
  5599. firstDueInterval.due = now + duration;
  5600. firstDueInterval.subscription = _this.schedule(run, duration);
  5601. handler();
  5602. return;
  5603. }
  5604. var dueTimeouts = scheduledRecordsDue.filter(function (_a) {
  5605. var type = _a.type;
  5606. return type === 'timeout';
  5607. });
  5608. if (dueTimeouts.length > 0) {
  5609. var _b = dueTimeouts[0], handle = _b.handle, handler = _b.handler;
  5610. scheduleLookup.delete(handle);
  5611. handler();
  5612. return;
  5613. }
  5614. throw new Error('Expected a due immediate or interval');
  5615. };
  5616. var immediate = {
  5617. setImmediate: function (handler) {
  5618. var handle = ++lastHandle;
  5619. scheduleLookup.set(handle, {
  5620. due: _this.now(),
  5621. duration: 0,
  5622. handle: handle,
  5623. handler: handler,
  5624. subscription: _this.schedule(run, 0),
  5625. type: 'immediate',
  5626. });
  5627. return handle;
  5628. },
  5629. clearImmediate: function (handle) {
  5630. var value = scheduleLookup.get(handle);
  5631. if (value) {
  5632. value.subscription.unsubscribe();
  5633. scheduleLookup.delete(handle);
  5634. }
  5635. },
  5636. };
  5637. var interval = {
  5638. setInterval: function (handler, duration) {
  5639. if (duration === void 0) { duration = 0; }
  5640. var handle = ++lastHandle;
  5641. scheduleLookup.set(handle, {
  5642. due: _this.now() + duration,
  5643. duration: duration,
  5644. handle: handle,
  5645. handler: handler,
  5646. subscription: _this.schedule(run, duration),
  5647. type: 'interval',
  5648. });
  5649. return handle;
  5650. },
  5651. clearInterval: function (handle) {
  5652. var value = scheduleLookup.get(handle);
  5653. if (value) {
  5654. value.subscription.unsubscribe();
  5655. scheduleLookup.delete(handle);
  5656. }
  5657. },
  5658. };
  5659. var timeout = {
  5660. setTimeout: function (handler, duration) {
  5661. if (duration === void 0) { duration = 0; }
  5662. var handle = ++lastHandle;
  5663. scheduleLookup.set(handle, {
  5664. due: _this.now() + duration,
  5665. duration: duration,
  5666. handle: handle,
  5667. handler: handler,
  5668. subscription: _this.schedule(run, duration),
  5669. type: 'timeout',
  5670. });
  5671. return handle;
  5672. },
  5673. clearTimeout: function (handle) {
  5674. var value = scheduleLookup.get(handle);
  5675. if (value) {
  5676. value.subscription.unsubscribe();
  5677. scheduleLookup.delete(handle);
  5678. }
  5679. },
  5680. };
  5681. return { immediate: immediate, interval: interval, timeout: timeout };
  5682. };
  5683. TestScheduler.prototype.run = function (callback) {
  5684. var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
  5685. var prevMaxFrames = this.maxFrames;
  5686. TestScheduler.frameTimeFactor = 1;
  5687. this.maxFrames = Infinity;
  5688. this.runMode = true;
  5689. var animator = this.createAnimator();
  5690. var delegates = this.createDelegates();
  5691. animationFrameProvider.delegate = animator.delegate;
  5692. dateTimestampProvider.delegate = this;
  5693. immediateProvider.delegate = delegates.immediate;
  5694. intervalProvider.delegate = delegates.interval;
  5695. timeoutProvider.delegate = delegates.timeout;
  5696. performanceTimestampProvider.delegate = this;
  5697. var helpers = {
  5698. cold: this.createColdObservable.bind(this),
  5699. hot: this.createHotObservable.bind(this),
  5700. flush: this.flush.bind(this),
  5701. time: this.createTime.bind(this),
  5702. expectObservable: this.expectObservable.bind(this),
  5703. expectSubscriptions: this.expectSubscriptions.bind(this),
  5704. animate: animator.animate,
  5705. };
  5706. try {
  5707. var ret = callback(helpers);
  5708. this.flush();
  5709. return ret;
  5710. }
  5711. finally {
  5712. TestScheduler.frameTimeFactor = prevFrameTimeFactor;
  5713. this.maxFrames = prevMaxFrames;
  5714. this.runMode = false;
  5715. animationFrameProvider.delegate = undefined;
  5716. dateTimestampProvider.delegate = undefined;
  5717. immediateProvider.delegate = undefined;
  5718. intervalProvider.delegate = undefined;
  5719. timeoutProvider.delegate = undefined;
  5720. performanceTimestampProvider.delegate = undefined;
  5721. }
  5722. };
  5723. TestScheduler.frameTimeFactor = 10;
  5724. return TestScheduler;
  5725. }(VirtualTimeScheduler));
  5726. var _testing = /*#__PURE__*/Object.freeze({
  5727. TestScheduler: TestScheduler
  5728. });
  5729. function getXHRResponse(xhr) {
  5730. switch (xhr.responseType) {
  5731. case 'json': {
  5732. if ('response' in xhr) {
  5733. return xhr.response;
  5734. }
  5735. else {
  5736. var ieXHR = xhr;
  5737. return JSON.parse(ieXHR.responseText);
  5738. }
  5739. }
  5740. case 'document':
  5741. return xhr.responseXML;
  5742. case 'text':
  5743. default: {
  5744. if ('response' in xhr) {
  5745. return xhr.response;
  5746. }
  5747. else {
  5748. var ieXHR = xhr;
  5749. return ieXHR.responseText;
  5750. }
  5751. }
  5752. }
  5753. }
  5754. var AjaxResponse = (function () {
  5755. function AjaxResponse(originalEvent, xhr, request, type) {
  5756. if (type === void 0) { type = 'download_load'; }
  5757. this.originalEvent = originalEvent;
  5758. this.xhr = xhr;
  5759. this.request = request;
  5760. this.type = type;
  5761. var status = xhr.status, responseType = xhr.responseType;
  5762. this.status = status !== null && status !== void 0 ? status : 0;
  5763. this.responseType = responseType !== null && responseType !== void 0 ? responseType : '';
  5764. var allHeaders = xhr.getAllResponseHeaders();
  5765. this.responseHeaders = allHeaders
  5766. ?
  5767. allHeaders.split('\n').reduce(function (headers, line) {
  5768. var index = line.indexOf(': ');
  5769. headers[line.slice(0, index)] = line.slice(index + 2);
  5770. return headers;
  5771. }, {})
  5772. : {};
  5773. this.response = getXHRResponse(xhr);
  5774. var loaded = originalEvent.loaded, total = originalEvent.total;
  5775. this.loaded = loaded;
  5776. this.total = total;
  5777. }
  5778. return AjaxResponse;
  5779. }());
  5780. var AjaxError = createErrorClass(function (_super) {
  5781. return function AjaxErrorImpl(message, xhr, request) {
  5782. this.message = message;
  5783. this.name = 'AjaxError';
  5784. this.xhr = xhr;
  5785. this.request = request;
  5786. this.status = xhr.status;
  5787. this.responseType = xhr.responseType;
  5788. var response;
  5789. try {
  5790. response = getXHRResponse(xhr);
  5791. }
  5792. catch (err) {
  5793. response = xhr.responseText;
  5794. }
  5795. this.response = response;
  5796. };
  5797. });
  5798. var AjaxTimeoutError = (function () {
  5799. function AjaxTimeoutErrorImpl(xhr, request) {
  5800. AjaxError.call(this, 'ajax timeout', xhr, request);
  5801. this.name = 'AjaxTimeoutError';
  5802. return this;
  5803. }
  5804. AjaxTimeoutErrorImpl.prototype = Object.create(AjaxError.prototype);
  5805. return AjaxTimeoutErrorImpl;
  5806. })();
  5807. function ajaxGet(url, headers) {
  5808. return ajax({ method: 'GET', url: url, headers: headers });
  5809. }
  5810. function ajaxPost(url, body, headers) {
  5811. return ajax({ method: 'POST', url: url, body: body, headers: headers });
  5812. }
  5813. function ajaxDelete(url, headers) {
  5814. return ajax({ method: 'DELETE', url: url, headers: headers });
  5815. }
  5816. function ajaxPut(url, body, headers) {
  5817. return ajax({ method: 'PUT', url: url, body: body, headers: headers });
  5818. }
  5819. function ajaxPatch(url, body, headers) {
  5820. return ajax({ method: 'PATCH', url: url, body: body, headers: headers });
  5821. }
  5822. var mapResponse = map(function (x) { return x.response; });
  5823. function ajaxGetJSON(url, headers) {
  5824. return mapResponse(ajax({
  5825. method: 'GET',
  5826. url: url,
  5827. headers: headers,
  5828. }));
  5829. }
  5830. var ajax = (function () {
  5831. var create = function (urlOrConfig) {
  5832. var config = typeof urlOrConfig === 'string'
  5833. ? {
  5834. url: urlOrConfig,
  5835. }
  5836. : urlOrConfig;
  5837. return fromAjax(config);
  5838. };
  5839. create.get = ajaxGet;
  5840. create.post = ajaxPost;
  5841. create.delete = ajaxDelete;
  5842. create.put = ajaxPut;
  5843. create.patch = ajaxPatch;
  5844. create.getJSON = ajaxGetJSON;
  5845. return create;
  5846. })();
  5847. var UPLOAD = 'upload';
  5848. var DOWNLOAD = 'download';
  5849. var LOADSTART = 'loadstart';
  5850. var PROGRESS = 'progress';
  5851. var LOAD = 'load';
  5852. function fromAjax(init) {
  5853. return new Observable(function (destination) {
  5854. var _a, _b;
  5855. var config = __assign({ async: true, crossDomain: false, withCredentials: false, method: 'GET', timeout: 0, responseType: 'json' }, init);
  5856. var queryParams = config.queryParams, configuredBody = config.body, configuredHeaders = config.headers;
  5857. var url = config.url;
  5858. if (!url) {
  5859. throw new TypeError('url is required');
  5860. }
  5861. if (queryParams) {
  5862. var searchParams_1;
  5863. if (url.includes('?')) {
  5864. var parts = url.split('?');
  5865. if (2 < parts.length) {
  5866. throw new TypeError('invalid url');
  5867. }
  5868. searchParams_1 = new URLSearchParams(parts[1]);
  5869. new URLSearchParams(queryParams).forEach(function (value, key) { return searchParams_1.set(key, value); });
  5870. url = parts[0] + '?' + searchParams_1;
  5871. }
  5872. else {
  5873. searchParams_1 = new URLSearchParams(queryParams);
  5874. url = url + '?' + searchParams_1;
  5875. }
  5876. }
  5877. var headers = {};
  5878. if (configuredHeaders) {
  5879. for (var key in configuredHeaders) {
  5880. if (configuredHeaders.hasOwnProperty(key)) {
  5881. headers[key.toLowerCase()] = configuredHeaders[key];
  5882. }
  5883. }
  5884. }
  5885. var crossDomain = config.crossDomain;
  5886. if (!crossDomain && !('x-requested-with' in headers)) {
  5887. headers['x-requested-with'] = 'XMLHttpRequest';
  5888. }
  5889. var withCredentials = config.withCredentials, xsrfCookieName = config.xsrfCookieName, xsrfHeaderName = config.xsrfHeaderName;
  5890. if ((withCredentials || !crossDomain) && xsrfCookieName && xsrfHeaderName) {
  5891. var xsrfCookie = (_b = (_a = document === null || document === void 0 ? void 0 : document.cookie.match(new RegExp("(^|;\\s*)(" + xsrfCookieName + ")=([^;]*)"))) === null || _a === void 0 ? void 0 : _a.pop()) !== null && _b !== void 0 ? _b : '';
  5892. if (xsrfCookie) {
  5893. headers[xsrfHeaderName] = xsrfCookie;
  5894. }
  5895. }
  5896. var body = extractContentTypeAndMaybeSerializeBody(configuredBody, headers);
  5897. var _request = __assign(__assign({}, config), { url: url,
  5898. headers: headers,
  5899. body: body });
  5900. var xhr;
  5901. xhr = init.createXHR ? init.createXHR() : new XMLHttpRequest();
  5902. {
  5903. var progressSubscriber_1 = init.progressSubscriber, _c = init.includeDownloadProgress, includeDownloadProgress = _c === void 0 ? false : _c, _d = init.includeUploadProgress, includeUploadProgress = _d === void 0 ? false : _d;
  5904. var addErrorEvent = function (type, errorFactory) {
  5905. xhr.addEventListener(type, function () {
  5906. var _a;
  5907. var error = errorFactory();
  5908. (_a = progressSubscriber_1 === null || progressSubscriber_1 === void 0 ? void 0 : progressSubscriber_1.error) === null || _a === void 0 ? void 0 : _a.call(progressSubscriber_1, error);
  5909. destination.error(error);
  5910. });
  5911. };
  5912. addErrorEvent('timeout', function () { return new AjaxTimeoutError(xhr, _request); });
  5913. addErrorEvent('abort', function () { return new AjaxError('aborted', xhr, _request); });
  5914. var createResponse_1 = function (direction, event) {
  5915. return new AjaxResponse(event, xhr, _request, direction + "_" + event.type);
  5916. };
  5917. var addProgressEvent_1 = function (target, type, direction) {
  5918. target.addEventListener(type, function (event) {
  5919. destination.next(createResponse_1(direction, event));
  5920. });
  5921. };
  5922. if (includeUploadProgress) {
  5923. [LOADSTART, PROGRESS, LOAD].forEach(function (type) { return addProgressEvent_1(xhr.upload, type, UPLOAD); });
  5924. }
  5925. if (progressSubscriber_1) {
  5926. [LOADSTART, PROGRESS].forEach(function (type) { return xhr.upload.addEventListener(type, function (e) { var _a; return (_a = progressSubscriber_1 === null || progressSubscriber_1 === void 0 ? void 0 : progressSubscriber_1.next) === null || _a === void 0 ? void 0 : _a.call(progressSubscriber_1, e); }); });
  5927. }
  5928. if (includeDownloadProgress) {
  5929. [LOADSTART, PROGRESS].forEach(function (type) { return addProgressEvent_1(xhr, type, DOWNLOAD); });
  5930. }
  5931. var emitError_1 = function (status) {
  5932. var msg = 'ajax error' + (status ? ' ' + status : '');
  5933. destination.error(new AjaxError(msg, xhr, _request));
  5934. };
  5935. xhr.addEventListener('error', function (e) {
  5936. var _a;
  5937. (_a = progressSubscriber_1 === null || progressSubscriber_1 === void 0 ? void 0 : progressSubscriber_1.error) === null || _a === void 0 ? void 0 : _a.call(progressSubscriber_1, e);
  5938. emitError_1();
  5939. });
  5940. xhr.addEventListener(LOAD, function (event) {
  5941. var _a, _b;
  5942. var status = xhr.status;
  5943. if (status < 400) {
  5944. (_a = progressSubscriber_1 === null || progressSubscriber_1 === void 0 ? void 0 : progressSubscriber_1.complete) === null || _a === void 0 ? void 0 : _a.call(progressSubscriber_1);
  5945. var response = void 0;
  5946. try {
  5947. response = createResponse_1(DOWNLOAD, event);
  5948. }
  5949. catch (err) {
  5950. destination.error(err);
  5951. return;
  5952. }
  5953. destination.next(response);
  5954. destination.complete();
  5955. }
  5956. else {
  5957. (_b = progressSubscriber_1 === null || progressSubscriber_1 === void 0 ? void 0 : progressSubscriber_1.error) === null || _b === void 0 ? void 0 : _b.call(progressSubscriber_1, event);
  5958. emitError_1(status);
  5959. }
  5960. });
  5961. }
  5962. var user = _request.user, method = _request.method, async = _request.async;
  5963. if (user) {
  5964. xhr.open(method, url, async, user, _request.password);
  5965. }
  5966. else {
  5967. xhr.open(method, url, async);
  5968. }
  5969. if (async) {
  5970. xhr.timeout = _request.timeout;
  5971. xhr.responseType = _request.responseType;
  5972. }
  5973. if ('withCredentials' in xhr) {
  5974. xhr.withCredentials = _request.withCredentials;
  5975. }
  5976. for (var key in headers) {
  5977. if (headers.hasOwnProperty(key)) {
  5978. xhr.setRequestHeader(key, headers[key]);
  5979. }
  5980. }
  5981. if (body) {
  5982. xhr.send(body);
  5983. }
  5984. else {
  5985. xhr.send();
  5986. }
  5987. return function () {
  5988. if (xhr && xhr.readyState !== 4) {
  5989. xhr.abort();
  5990. }
  5991. };
  5992. });
  5993. }
  5994. function extractContentTypeAndMaybeSerializeBody(body, headers) {
  5995. var _a;
  5996. if (!body ||
  5997. typeof body === 'string' ||
  5998. isFormData(body) ||
  5999. isURLSearchParams(body) ||
  6000. isArrayBuffer(body) ||
  6001. isFile(body) ||
  6002. isBlob(body) ||
  6003. isReadableStream(body)) {
  6004. return body;
  6005. }
  6006. if (isArrayBufferView(body)) {
  6007. return body.buffer;
  6008. }
  6009. if (typeof body === 'object') {
  6010. headers['content-type'] = (_a = headers['content-type']) !== null && _a !== void 0 ? _a : 'application/json;charset=utf-8';
  6011. return JSON.stringify(body);
  6012. }
  6013. throw new TypeError('Unknown body type');
  6014. }
  6015. var _toString = Object.prototype.toString;
  6016. function toStringCheck(obj, name) {
  6017. return _toString.call(obj) === "[object " + name + "]";
  6018. }
  6019. function isArrayBuffer(body) {
  6020. return toStringCheck(body, 'ArrayBuffer');
  6021. }
  6022. function isFile(body) {
  6023. return toStringCheck(body, 'File');
  6024. }
  6025. function isBlob(body) {
  6026. return toStringCheck(body, 'Blob');
  6027. }
  6028. function isArrayBufferView(body) {
  6029. return typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(body);
  6030. }
  6031. function isFormData(body) {
  6032. return typeof FormData !== 'undefined' && body instanceof FormData;
  6033. }
  6034. function isURLSearchParams(body) {
  6035. return typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams;
  6036. }
  6037. function isReadableStream(body) {
  6038. return typeof ReadableStream !== 'undefined' && body instanceof ReadableStream;
  6039. }
  6040. var _ajax = /*#__PURE__*/Object.freeze({
  6041. ajax: ajax,
  6042. AjaxError: AjaxError,
  6043. AjaxTimeoutError: AjaxTimeoutError,
  6044. AjaxResponse: AjaxResponse
  6045. });
  6046. var DEFAULT_WEBSOCKET_CONFIG = {
  6047. url: '',
  6048. deserializer: function (e) { return JSON.parse(e.data); },
  6049. serializer: function (value) { return JSON.stringify(value); },
  6050. };
  6051. var WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT = 'WebSocketSubject.error must be called with an object with an error code, and an optional reason: { code: number, reason: string }';
  6052. var WebSocketSubject = (function (_super) {
  6053. __extends(WebSocketSubject, _super);
  6054. function WebSocketSubject(urlConfigOrSource, destination) {
  6055. var _this = _super.call(this) || this;
  6056. _this._socket = null;
  6057. if (urlConfigOrSource instanceof Observable) {
  6058. _this.destination = destination;
  6059. _this.source = urlConfigOrSource;
  6060. }
  6061. else {
  6062. var config = (_this._config = __assign({}, DEFAULT_WEBSOCKET_CONFIG));
  6063. _this._output = new Subject();
  6064. if (typeof urlConfigOrSource === 'string') {
  6065. config.url = urlConfigOrSource;
  6066. }
  6067. else {
  6068. for (var key in urlConfigOrSource) {
  6069. if (urlConfigOrSource.hasOwnProperty(key)) {
  6070. config[key] = urlConfigOrSource[key];
  6071. }
  6072. }
  6073. }
  6074. if (!config.WebSocketCtor && WebSocket) {
  6075. config.WebSocketCtor = WebSocket;
  6076. }
  6077. else if (!config.WebSocketCtor) {
  6078. throw new Error('no WebSocket constructor can be found');
  6079. }
  6080. _this.destination = new ReplaySubject();
  6081. }
  6082. return _this;
  6083. }
  6084. WebSocketSubject.prototype.lift = function (operator) {
  6085. var sock = new WebSocketSubject(this._config, this.destination);
  6086. sock.operator = operator;
  6087. sock.source = this;
  6088. return sock;
  6089. };
  6090. WebSocketSubject.prototype._resetState = function () {
  6091. this._socket = null;
  6092. if (!this.source) {
  6093. this.destination = new ReplaySubject();
  6094. }
  6095. this._output = new Subject();
  6096. };
  6097. WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) {
  6098. var self = this;
  6099. return new Observable(function (observer) {
  6100. try {
  6101. self.next(subMsg());
  6102. }
  6103. catch (err) {
  6104. observer.error(err);
  6105. }
  6106. var subscription = self.subscribe({
  6107. next: function (x) {
  6108. try {
  6109. if (messageFilter(x)) {
  6110. observer.next(x);
  6111. }
  6112. }
  6113. catch (err) {
  6114. observer.error(err);
  6115. }
  6116. },
  6117. error: function (err) { return observer.error(err); },
  6118. complete: function () { return observer.complete(); },
  6119. });
  6120. return function () {
  6121. try {
  6122. self.next(unsubMsg());
  6123. }
  6124. catch (err) {
  6125. observer.error(err);
  6126. }
  6127. subscription.unsubscribe();
  6128. };
  6129. });
  6130. };
  6131. WebSocketSubject.prototype._connectSocket = function () {
  6132. var _this = this;
  6133. var _a = this._config, WebSocketCtor = _a.WebSocketCtor, protocol = _a.protocol, url = _a.url, binaryType = _a.binaryType;
  6134. var observer = this._output;
  6135. var socket = null;
  6136. try {
  6137. socket = protocol ? new WebSocketCtor(url, protocol) : new WebSocketCtor(url);
  6138. this._socket = socket;
  6139. if (binaryType) {
  6140. this._socket.binaryType = binaryType;
  6141. }
  6142. }
  6143. catch (e) {
  6144. observer.error(e);
  6145. return;
  6146. }
  6147. var subscription = new Subscription(function () {
  6148. _this._socket = null;
  6149. if (socket && socket.readyState === 1) {
  6150. socket.close();
  6151. }
  6152. });
  6153. socket.onopen = function (evt) {
  6154. var _socket = _this._socket;
  6155. if (!_socket) {
  6156. socket.close();
  6157. _this._resetState();
  6158. return;
  6159. }
  6160. var openObserver = _this._config.openObserver;
  6161. if (openObserver) {
  6162. openObserver.next(evt);
  6163. }
  6164. var queue = _this.destination;
  6165. _this.destination = Subscriber.create(function (x) {
  6166. if (socket.readyState === 1) {
  6167. try {
  6168. var serializer = _this._config.serializer;
  6169. socket.send(serializer(x));
  6170. }
  6171. catch (e) {
  6172. _this.destination.error(e);
  6173. }
  6174. }
  6175. }, function (err) {
  6176. var closingObserver = _this._config.closingObserver;
  6177. if (closingObserver) {
  6178. closingObserver.next(undefined);
  6179. }
  6180. if (err && err.code) {
  6181. socket.close(err.code, err.reason);
  6182. }
  6183. else {
  6184. observer.error(new TypeError(WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT));
  6185. }
  6186. _this._resetState();
  6187. }, function () {
  6188. var closingObserver = _this._config.closingObserver;
  6189. if (closingObserver) {
  6190. closingObserver.next(undefined);
  6191. }
  6192. socket.close();
  6193. _this._resetState();
  6194. });
  6195. if (queue && queue instanceof ReplaySubject) {
  6196. subscription.add(queue.subscribe(_this.destination));
  6197. }
  6198. };
  6199. socket.onerror = function (e) {
  6200. _this._resetState();
  6201. observer.error(e);
  6202. };
  6203. socket.onclose = function (e) {
  6204. if (socket === _this._socket) {
  6205. _this._resetState();
  6206. }
  6207. var closeObserver = _this._config.closeObserver;
  6208. if (closeObserver) {
  6209. closeObserver.next(e);
  6210. }
  6211. if (e.wasClean) {
  6212. observer.complete();
  6213. }
  6214. else {
  6215. observer.error(e);
  6216. }
  6217. };
  6218. socket.onmessage = function (e) {
  6219. try {
  6220. var deserializer = _this._config.deserializer;
  6221. observer.next(deserializer(e));
  6222. }
  6223. catch (err) {
  6224. observer.error(err);
  6225. }
  6226. };
  6227. };
  6228. WebSocketSubject.prototype._subscribe = function (subscriber) {
  6229. var _this = this;
  6230. var source = this.source;
  6231. if (source) {
  6232. return source.subscribe(subscriber);
  6233. }
  6234. if (!this._socket) {
  6235. this._connectSocket();
  6236. }
  6237. this._output.subscribe(subscriber);
  6238. subscriber.add(function () {
  6239. var _socket = _this._socket;
  6240. if (_this._output.observers.length === 0) {
  6241. if (_socket && (_socket.readyState === 1 || _socket.readyState === 0)) {
  6242. _socket.close();
  6243. }
  6244. _this._resetState();
  6245. }
  6246. });
  6247. return subscriber;
  6248. };
  6249. WebSocketSubject.prototype.unsubscribe = function () {
  6250. var _socket = this._socket;
  6251. if (_socket && (_socket.readyState === 1 || _socket.readyState === 0)) {
  6252. _socket.close();
  6253. }
  6254. this._resetState();
  6255. _super.prototype.unsubscribe.call(this);
  6256. };
  6257. return WebSocketSubject;
  6258. }(AnonymousSubject));
  6259. function webSocket(urlConfigOrSource) {
  6260. return new WebSocketSubject(urlConfigOrSource);
  6261. }
  6262. var _webSocket = /*#__PURE__*/Object.freeze({
  6263. webSocket: webSocket,
  6264. WebSocketSubject: WebSocketSubject
  6265. });
  6266. function fromFetch(input, initWithSelector) {
  6267. if (initWithSelector === void 0) { initWithSelector = {}; }
  6268. var selector = initWithSelector.selector, init = __rest(initWithSelector, ["selector"]);
  6269. return new Observable(function (subscriber) {
  6270. var controller = new AbortController();
  6271. var signal = controller.signal;
  6272. var abortable = true;
  6273. var outerSignal = init.signal;
  6274. if (outerSignal) {
  6275. if (outerSignal.aborted) {
  6276. controller.abort();
  6277. }
  6278. else {
  6279. var outerSignalHandler_1 = function () {
  6280. if (!signal.aborted) {
  6281. controller.abort();
  6282. }
  6283. };
  6284. outerSignal.addEventListener('abort', outerSignalHandler_1);
  6285. subscriber.add(function () { return outerSignal.removeEventListener('abort', outerSignalHandler_1); });
  6286. }
  6287. }
  6288. var perSubscriberInit = __assign(__assign({}, init), { signal: signal });
  6289. var handleError = function (err) {
  6290. abortable = false;
  6291. subscriber.error(err);
  6292. };
  6293. fetch(input, perSubscriberInit)
  6294. .then(function (response) {
  6295. if (selector) {
  6296. innerFrom(selector(response)).subscribe(createOperatorSubscriber(subscriber, undefined, function () {
  6297. abortable = false;
  6298. subscriber.complete();
  6299. }, handleError));
  6300. }
  6301. else {
  6302. abortable = false;
  6303. subscriber.next(response);
  6304. subscriber.complete();
  6305. }
  6306. })
  6307. .catch(handleError);
  6308. return function () {
  6309. if (abortable) {
  6310. controller.abort();
  6311. }
  6312. };
  6313. });
  6314. }
  6315. var _fetch = /*#__PURE__*/Object.freeze({
  6316. fromFetch: fromFetch
  6317. });
  6318. var operators = _operators;
  6319. var testing = _testing;
  6320. var ajax$1 = _ajax;
  6321. var webSocket$1 = _webSocket;
  6322. var fetch$1 = _fetch;
  6323. exports.operators = operators;
  6324. exports.testing = testing;
  6325. exports.ajax = ajax$1;
  6326. exports.webSocket = webSocket$1;
  6327. exports.fetch = fetch$1;
  6328. exports.Observable = Observable;
  6329. exports.ConnectableObservable = ConnectableObservable;
  6330. exports.observable = observable;
  6331. exports.animationFrames = animationFrames;
  6332. exports.Subject = Subject;
  6333. exports.BehaviorSubject = BehaviorSubject;
  6334. exports.ReplaySubject = ReplaySubject;
  6335. exports.AsyncSubject = AsyncSubject;
  6336. exports.asap = asap;
  6337. exports.asapScheduler = asapScheduler;
  6338. exports.async = async;
  6339. exports.asyncScheduler = asyncScheduler;
  6340. exports.queue = queue;
  6341. exports.queueScheduler = queueScheduler;
  6342. exports.animationFrame = animationFrame;
  6343. exports.animationFrameScheduler = animationFrameScheduler;
  6344. exports.VirtualTimeScheduler = VirtualTimeScheduler;
  6345. exports.VirtualAction = VirtualAction;
  6346. exports.Scheduler = Scheduler;
  6347. exports.Subscription = Subscription;
  6348. exports.Subscriber = Subscriber;
  6349. exports.Notification = Notification;
  6350. exports.pipe = pipe;
  6351. exports.noop = noop;
  6352. exports.identity = identity;
  6353. exports.isObservable = isObservable;
  6354. exports.lastValueFrom = lastValueFrom;
  6355. exports.firstValueFrom = firstValueFrom;
  6356. exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
  6357. exports.EmptyError = EmptyError;
  6358. exports.NotFoundError = NotFoundError;
  6359. exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
  6360. exports.SequenceError = SequenceError;
  6361. exports.TimeoutError = TimeoutError;
  6362. exports.UnsubscriptionError = UnsubscriptionError;
  6363. exports.bindCallback = bindCallback;
  6364. exports.bindNodeCallback = bindNodeCallback;
  6365. exports.combineLatest = combineLatest;
  6366. exports.concat = concat;
  6367. exports.connectable = connectable;
  6368. exports.defer = defer;
  6369. exports.empty = empty;
  6370. exports.forkJoin = forkJoin;
  6371. exports.from = from;
  6372. exports.fromEvent = fromEvent;
  6373. exports.fromEventPattern = fromEventPattern;
  6374. exports.generate = generate;
  6375. exports.iif = iif;
  6376. exports.interval = interval;
  6377. exports.merge = merge;
  6378. exports.never = never;
  6379. exports.of = of;
  6380. exports.onErrorResumeNext = onErrorResumeNext;
  6381. exports.pairs = pairs;
  6382. exports.partition = partition;
  6383. exports.race = race;
  6384. exports.range = range;
  6385. exports.throwError = throwError;
  6386. exports.timer = timer;
  6387. exports.using = using;
  6388. exports.zip = zip;
  6389. exports.scheduled = scheduled;
  6390. exports.EMPTY = EMPTY;
  6391. exports.NEVER = NEVER;
  6392. exports.config = config;
  6393. exports.audit = audit;
  6394. exports.auditTime = auditTime;
  6395. exports.buffer = buffer;
  6396. exports.bufferCount = bufferCount;
  6397. exports.bufferTime = bufferTime;
  6398. exports.bufferToggle = bufferToggle;
  6399. exports.bufferWhen = bufferWhen;
  6400. exports.catchError = catchError;
  6401. exports.combineAll = combineAll;
  6402. exports.combineLatestAll = combineLatestAll;
  6403. exports.combineLatestWith = combineLatestWith;
  6404. exports.concatAll = concatAll;
  6405. exports.concatMap = concatMap;
  6406. exports.concatMapTo = concatMapTo;
  6407. exports.concatWith = concatWith;
  6408. exports.connect = connect;
  6409. exports.count = count;
  6410. exports.debounce = debounce;
  6411. exports.debounceTime = debounceTime;
  6412. exports.defaultIfEmpty = defaultIfEmpty;
  6413. exports.delay = delay;
  6414. exports.delayWhen = delayWhen;
  6415. exports.dematerialize = dematerialize;
  6416. exports.distinct = distinct;
  6417. exports.distinctUntilChanged = distinctUntilChanged;
  6418. exports.distinctUntilKeyChanged = distinctUntilKeyChanged;
  6419. exports.elementAt = elementAt;
  6420. exports.endWith = endWith;
  6421. exports.every = every;
  6422. exports.exhaust = exhaust;
  6423. exports.exhaustAll = exhaustAll;
  6424. exports.exhaustMap = exhaustMap;
  6425. exports.expand = expand;
  6426. exports.filter = filter;
  6427. exports.finalize = finalize;
  6428. exports.find = find;
  6429. exports.findIndex = findIndex;
  6430. exports.first = first;
  6431. exports.groupBy = groupBy;
  6432. exports.ignoreElements = ignoreElements;
  6433. exports.isEmpty = isEmpty;
  6434. exports.last = last$1;
  6435. exports.map = map;
  6436. exports.mapTo = mapTo;
  6437. exports.materialize = materialize;
  6438. exports.max = max;
  6439. exports.mergeAll = mergeAll;
  6440. exports.flatMap = flatMap;
  6441. exports.mergeMap = mergeMap;
  6442. exports.mergeMapTo = mergeMapTo;
  6443. exports.mergeScan = mergeScan;
  6444. exports.mergeWith = mergeWith;
  6445. exports.min = min;
  6446. exports.multicast = multicast;
  6447. exports.observeOn = observeOn;
  6448. exports.onErrorResumeNextWith = onErrorResumeNextWith;
  6449. exports.pairwise = pairwise;
  6450. exports.pluck = pluck;
  6451. exports.publish = publish;
  6452. exports.publishBehavior = publishBehavior;
  6453. exports.publishLast = publishLast;
  6454. exports.publishReplay = publishReplay;
  6455. exports.raceWith = raceWith;
  6456. exports.reduce = reduce;
  6457. exports.repeat = repeat;
  6458. exports.repeatWhen = repeatWhen;
  6459. exports.retry = retry;
  6460. exports.retryWhen = retryWhen;
  6461. exports.refCount = refCount;
  6462. exports.sample = sample;
  6463. exports.sampleTime = sampleTime;
  6464. exports.scan = scan;
  6465. exports.sequenceEqual = sequenceEqual;
  6466. exports.share = share;
  6467. exports.shareReplay = shareReplay;
  6468. exports.single = single;
  6469. exports.skip = skip;
  6470. exports.skipLast = skipLast;
  6471. exports.skipUntil = skipUntil;
  6472. exports.skipWhile = skipWhile;
  6473. exports.startWith = startWith;
  6474. exports.subscribeOn = subscribeOn;
  6475. exports.switchAll = switchAll;
  6476. exports.switchMap = switchMap;
  6477. exports.switchMapTo = switchMapTo;
  6478. exports.switchScan = switchScan;
  6479. exports.take = take;
  6480. exports.takeLast = takeLast;
  6481. exports.takeUntil = takeUntil;
  6482. exports.takeWhile = takeWhile;
  6483. exports.tap = tap;
  6484. exports.throttle = throttle;
  6485. exports.throttleTime = throttleTime;
  6486. exports.throwIfEmpty = throwIfEmpty;
  6487. exports.timeInterval = timeInterval;
  6488. exports.timeout = timeout;
  6489. exports.timeoutWith = timeoutWith;
  6490. exports.timestamp = timestamp;
  6491. exports.toArray = toArray;
  6492. exports.window = window;
  6493. exports.windowCount = windowCount;
  6494. exports.windowTime = windowTime;
  6495. exports.windowToggle = windowToggle;
  6496. exports.windowWhen = windowWhen;
  6497. exports.withLatestFrom = withLatestFrom;
  6498. exports.zipAll = zipAll;
  6499. exports.zipWith = zipWith;
  6500. Object.defineProperty(exports, '__esModule', { value: true });
  6501. })));
  6502. //# sourceMappingURL=rxjs.umd.js.map