vitepress___@vueuse_core.js 258 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753
  1. import {
  2. Fragment,
  3. TransitionGroup,
  4. computed,
  5. customRef,
  6. defineComponent,
  7. effectScope,
  8. getCurrentInstance,
  9. getCurrentScope,
  10. h,
  11. inject,
  12. isReactive,
  13. isReadonly,
  14. isRef,
  15. markRaw,
  16. nextTick,
  17. onBeforeMount,
  18. onBeforeUnmount,
  19. onBeforeUpdate,
  20. onMounted,
  21. onScopeDispose,
  22. onUnmounted,
  23. onUpdated,
  24. provide,
  25. reactive,
  26. readonly,
  27. ref,
  28. shallowReactive,
  29. shallowRef,
  30. toRef,
  31. toRefs,
  32. unref,
  33. version,
  34. watch,
  35. watchEffect,
  36. } from './chunk-Z6W6QRLO.js';
  37. // ../node_modules/.pnpm/vitepress@1.2.2_@algolia+client-search@4.23.3_@types+node@20.12.12_async-validator@4.2.5_axio_5jctzjtewfbzj62xdve5deaagi/node_modules/vitepress/lib/vue-demi.mjs
  38. var isVue2 = false;
  39. var isVue3 = true;
  40. function set(target, key, val) {
  41. if (Array.isArray(target)) {
  42. target.length = Math.max(target.length, key);
  43. target.splice(key, 1, val);
  44. return val;
  45. }
  46. target[key] = val;
  47. return val;
  48. }
  49. function del(target, key) {
  50. if (Array.isArray(target)) {
  51. target.splice(key, 1);
  52. return;
  53. }
  54. delete target[key];
  55. }
  56. // ../node_modules/.pnpm/@vueuse+shared@10.9.0_vue@3.4.27_typescript@5.4.5_/node_modules/@vueuse/shared/index.mjs
  57. function computedEager(fn, options) {
  58. var _a;
  59. const result = shallowRef();
  60. watchEffect(
  61. () => {
  62. result.value = fn();
  63. },
  64. {
  65. ...options,
  66. flush:
  67. (_a = options == null ? void 0 : options.flush) != null ? _a : 'sync',
  68. },
  69. );
  70. return readonly(result);
  71. }
  72. function computedWithControl(source, fn) {
  73. let v = void 0;
  74. let track;
  75. let trigger;
  76. const dirty = ref(true);
  77. const update = () => {
  78. dirty.value = true;
  79. trigger();
  80. };
  81. watch(source, update, { flush: 'sync' });
  82. const get2 = typeof fn === 'function' ? fn : fn.get;
  83. const set3 = typeof fn === 'function' ? void 0 : fn.set;
  84. const result = customRef((_track, _trigger) => {
  85. track = _track;
  86. trigger = _trigger;
  87. return {
  88. get() {
  89. if (dirty.value) {
  90. v = get2();
  91. dirty.value = false;
  92. }
  93. track();
  94. return v;
  95. },
  96. set(v2) {
  97. set3 == null ? void 0 : set3(v2);
  98. },
  99. };
  100. });
  101. if (Object.isExtensible(result)) result.trigger = update;
  102. return result;
  103. }
  104. function tryOnScopeDispose(fn) {
  105. if (getCurrentScope()) {
  106. onScopeDispose(fn);
  107. return true;
  108. }
  109. return false;
  110. }
  111. function createEventHook() {
  112. const fns = /* @__PURE__ */ new Set();
  113. const off = (fn) => {
  114. fns.delete(fn);
  115. };
  116. const on = (fn) => {
  117. fns.add(fn);
  118. const offFn = () => off(fn);
  119. tryOnScopeDispose(offFn);
  120. return {
  121. off: offFn,
  122. };
  123. };
  124. const trigger = (...args) => {
  125. return Promise.all(Array.from(fns).map((fn) => fn(...args)));
  126. };
  127. return {
  128. on,
  129. off,
  130. trigger,
  131. };
  132. }
  133. function createGlobalState(stateFactory) {
  134. let initialized = false;
  135. let state;
  136. const scope = effectScope(true);
  137. return (...args) => {
  138. if (!initialized) {
  139. state = scope.run(() => stateFactory(...args));
  140. initialized = true;
  141. }
  142. return state;
  143. };
  144. }
  145. var localProvidedStateMap = /* @__PURE__ */ new WeakMap();
  146. var provideLocal = (key, value) => {
  147. var _a;
  148. const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
  149. if (instance == null) throw new Error('provideLocal must be called in setup');
  150. if (!localProvidedStateMap.has(instance))
  151. localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
  152. const localProvidedState = localProvidedStateMap.get(instance);
  153. localProvidedState[key] = value;
  154. provide(key, value);
  155. };
  156. var injectLocal = (...args) => {
  157. var _a;
  158. const key = args[0];
  159. const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
  160. if (instance == null) throw new Error('injectLocal must be called in setup');
  161. if (
  162. localProvidedStateMap.has(instance) &&
  163. key in localProvidedStateMap.get(instance)
  164. )
  165. return localProvidedStateMap.get(instance)[key];
  166. return inject(...args);
  167. };
  168. function createInjectionState(composable, options) {
  169. const key =
  170. (options == null ? void 0 : options.injectionKey) ||
  171. Symbol(composable.name || 'InjectionState');
  172. const useProvidingState = (...args) => {
  173. const state = composable(...args);
  174. provideLocal(key, state);
  175. return state;
  176. };
  177. const useInjectedState = () => injectLocal(key);
  178. return [useProvidingState, useInjectedState];
  179. }
  180. function createSharedComposable(composable) {
  181. let subscribers = 0;
  182. let state;
  183. let scope;
  184. const dispose = () => {
  185. subscribers -= 1;
  186. if (scope && subscribers <= 0) {
  187. scope.stop();
  188. state = void 0;
  189. scope = void 0;
  190. }
  191. };
  192. return (...args) => {
  193. subscribers += 1;
  194. if (!state) {
  195. scope = effectScope(true);
  196. state = scope.run(() => composable(...args));
  197. }
  198. tryOnScopeDispose(dispose);
  199. return state;
  200. };
  201. }
  202. function extendRef(ref2, extend, { enumerable = false, unwrap = true } = {}) {
  203. if (!isVue3 && !version.startsWith('2.7.')) {
  204. if (true)
  205. throw new Error('[VueUse] extendRef only works in Vue 2.7 or above.');
  206. return;
  207. }
  208. for (const [key, value] of Object.entries(extend)) {
  209. if (key === 'value') continue;
  210. if (isRef(value) && unwrap) {
  211. Object.defineProperty(ref2, key, {
  212. get() {
  213. return value.value;
  214. },
  215. set(v) {
  216. value.value = v;
  217. },
  218. enumerable,
  219. });
  220. } else {
  221. Object.defineProperty(ref2, key, { value, enumerable });
  222. }
  223. }
  224. return ref2;
  225. }
  226. function get(obj, key) {
  227. if (key == null) return unref(obj);
  228. return unref(obj)[key];
  229. }
  230. function isDefined(v) {
  231. return unref(v) != null;
  232. }
  233. function makeDestructurable(obj, arr) {
  234. if (typeof Symbol !== 'undefined') {
  235. const clone = { ...obj };
  236. Object.defineProperty(clone, Symbol.iterator, {
  237. enumerable: false,
  238. value() {
  239. let index = 0;
  240. return {
  241. next: () => ({
  242. value: arr[index++],
  243. done: index > arr.length,
  244. }),
  245. };
  246. },
  247. });
  248. return clone;
  249. } else {
  250. return Object.assign([...arr], obj);
  251. }
  252. }
  253. function toValue(r) {
  254. return typeof r === 'function' ? r() : unref(r);
  255. }
  256. var resolveUnref = toValue;
  257. function reactify(fn, options) {
  258. const unrefFn =
  259. (options == null ? void 0 : options.computedGetter) === false
  260. ? unref
  261. : toValue;
  262. return function (...args) {
  263. return computed(() =>
  264. fn.apply(
  265. this,
  266. args.map((i) => unrefFn(i)),
  267. ),
  268. );
  269. };
  270. }
  271. function reactifyObject(obj, optionsOrKeys = {}) {
  272. let keys2 = [];
  273. let options;
  274. if (Array.isArray(optionsOrKeys)) {
  275. keys2 = optionsOrKeys;
  276. } else {
  277. options = optionsOrKeys;
  278. const { includeOwnProperties = true } = optionsOrKeys;
  279. keys2.push(...Object.keys(obj));
  280. if (includeOwnProperties) keys2.push(...Object.getOwnPropertyNames(obj));
  281. }
  282. return Object.fromEntries(
  283. keys2.map((key) => {
  284. const value = obj[key];
  285. return [
  286. key,
  287. typeof value === 'function'
  288. ? reactify(value.bind(obj), options)
  289. : value,
  290. ];
  291. }),
  292. );
  293. }
  294. function toReactive(objectRef) {
  295. if (!isRef(objectRef)) return reactive(objectRef);
  296. const proxy = new Proxy(
  297. {},
  298. {
  299. get(_, p, receiver) {
  300. return unref(Reflect.get(objectRef.value, p, receiver));
  301. },
  302. set(_, p, value) {
  303. if (isRef(objectRef.value[p]) && !isRef(value))
  304. objectRef.value[p].value = value;
  305. else objectRef.value[p] = value;
  306. return true;
  307. },
  308. deleteProperty(_, p) {
  309. return Reflect.deleteProperty(objectRef.value, p);
  310. },
  311. has(_, p) {
  312. return Reflect.has(objectRef.value, p);
  313. },
  314. ownKeys() {
  315. return Object.keys(objectRef.value);
  316. },
  317. getOwnPropertyDescriptor() {
  318. return {
  319. enumerable: true,
  320. configurable: true,
  321. };
  322. },
  323. },
  324. );
  325. return reactive(proxy);
  326. }
  327. function reactiveComputed(fn) {
  328. return toReactive(computed(fn));
  329. }
  330. function reactiveOmit(obj, ...keys2) {
  331. const flatKeys = keys2.flat();
  332. const predicate = flatKeys[0];
  333. return reactiveComputed(() =>
  334. typeof predicate === 'function'
  335. ? Object.fromEntries(
  336. Object.entries(toRefs(obj)).filter(
  337. ([k, v]) => !predicate(toValue(v), k),
  338. ),
  339. )
  340. : Object.fromEntries(
  341. Object.entries(toRefs(obj)).filter((e) => !flatKeys.includes(e[0])),
  342. ),
  343. );
  344. }
  345. var isClient = typeof window !== 'undefined' && typeof document !== 'undefined';
  346. var isWorker =
  347. typeof WorkerGlobalScope !== 'undefined' &&
  348. globalThis instanceof WorkerGlobalScope;
  349. var isDef = (val) => typeof val !== 'undefined';
  350. var notNullish = (val) => val != null;
  351. var assert = (condition, ...infos) => {
  352. if (!condition) console.warn(...infos);
  353. };
  354. var toString = Object.prototype.toString;
  355. var isObject = (val) => toString.call(val) === '[object Object]';
  356. var now = () => Date.now();
  357. var timestamp = () => +Date.now();
  358. var clamp = (n, min, max) => Math.min(max, Math.max(min, n));
  359. var noop = () => {};
  360. var rand = (min, max) => {
  361. min = Math.ceil(min);
  362. max = Math.floor(max);
  363. return Math.floor(Math.random() * (max - min + 1)) + min;
  364. };
  365. var hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
  366. var isIOS = getIsIOS();
  367. function getIsIOS() {
  368. var _a, _b;
  369. return (
  370. isClient &&
  371. ((_a = window == null ? void 0 : window.navigator) == null
  372. ? void 0
  373. : _a.userAgent) &&
  374. (/iP(ad|hone|od)/.test(window.navigator.userAgent) ||
  375. (((_b = window == null ? void 0 : window.navigator) == null
  376. ? void 0
  377. : _b.maxTouchPoints) > 2 &&
  378. /iPad|Macintosh/.test(
  379. window == null ? void 0 : window.navigator.userAgent,
  380. )))
  381. );
  382. }
  383. function createFilterWrapper(filter, fn) {
  384. function wrapper(...args) {
  385. return new Promise((resolve, reject) => {
  386. Promise.resolve(
  387. filter(() => fn.apply(this, args), { fn, thisArg: this, args }),
  388. )
  389. .then(resolve)
  390. .catch(reject);
  391. });
  392. }
  393. return wrapper;
  394. }
  395. var bypassFilter = (invoke2) => {
  396. return invoke2();
  397. };
  398. function debounceFilter(ms, options = {}) {
  399. let timer;
  400. let maxTimer;
  401. let lastRejector = noop;
  402. const _clearTimeout = (timer2) => {
  403. clearTimeout(timer2);
  404. lastRejector();
  405. lastRejector = noop;
  406. };
  407. const filter = (invoke2) => {
  408. const duration = toValue(ms);
  409. const maxDuration = toValue(options.maxWait);
  410. if (timer) _clearTimeout(timer);
  411. if (duration <= 0 || (maxDuration !== void 0 && maxDuration <= 0)) {
  412. if (maxTimer) {
  413. _clearTimeout(maxTimer);
  414. maxTimer = null;
  415. }
  416. return Promise.resolve(invoke2());
  417. }
  418. return new Promise((resolve, reject) => {
  419. lastRejector = options.rejectOnCancel ? reject : resolve;
  420. if (maxDuration && !maxTimer) {
  421. maxTimer = setTimeout(() => {
  422. if (timer) _clearTimeout(timer);
  423. maxTimer = null;
  424. resolve(invoke2());
  425. }, maxDuration);
  426. }
  427. timer = setTimeout(() => {
  428. if (maxTimer) _clearTimeout(maxTimer);
  429. maxTimer = null;
  430. resolve(invoke2());
  431. }, duration);
  432. });
  433. };
  434. return filter;
  435. }
  436. function throttleFilter(...args) {
  437. let lastExec = 0;
  438. let timer;
  439. let isLeading = true;
  440. let lastRejector = noop;
  441. let lastValue;
  442. let ms;
  443. let trailing;
  444. let leading;
  445. let rejectOnCancel;
  446. if (!isRef(args[0]) && typeof args[0] === 'object')
  447. ({
  448. delay: ms,
  449. trailing = true,
  450. leading = true,
  451. rejectOnCancel = false,
  452. } = args[0]);
  453. else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
  454. const clear = () => {
  455. if (timer) {
  456. clearTimeout(timer);
  457. timer = void 0;
  458. lastRejector();
  459. lastRejector = noop;
  460. }
  461. };
  462. const filter = (_invoke) => {
  463. const duration = toValue(ms);
  464. const elapsed = Date.now() - lastExec;
  465. const invoke2 = () => {
  466. return (lastValue = _invoke());
  467. };
  468. clear();
  469. if (duration <= 0) {
  470. lastExec = Date.now();
  471. return invoke2();
  472. }
  473. if (elapsed > duration && (leading || !isLeading)) {
  474. lastExec = Date.now();
  475. invoke2();
  476. } else if (trailing) {
  477. lastValue = new Promise((resolve, reject) => {
  478. lastRejector = rejectOnCancel ? reject : resolve;
  479. timer = setTimeout(
  480. () => {
  481. lastExec = Date.now();
  482. isLeading = true;
  483. resolve(invoke2());
  484. clear();
  485. },
  486. Math.max(0, duration - elapsed),
  487. );
  488. });
  489. }
  490. if (!leading && !timer)
  491. timer = setTimeout(() => (isLeading = true), duration);
  492. isLeading = false;
  493. return lastValue;
  494. };
  495. return filter;
  496. }
  497. function pausableFilter(extendFilter = bypassFilter) {
  498. const isActive = ref(true);
  499. function pause() {
  500. isActive.value = false;
  501. }
  502. function resume() {
  503. isActive.value = true;
  504. }
  505. const eventFilter = (...args) => {
  506. if (isActive.value) extendFilter(...args);
  507. };
  508. return { isActive: readonly(isActive), pause, resume, eventFilter };
  509. }
  510. var directiveHooks = {
  511. mounted: isVue3 ? 'mounted' : 'inserted',
  512. updated: isVue3 ? 'updated' : 'componentUpdated',
  513. unmounted: isVue3 ? 'unmounted' : 'unbind',
  514. };
  515. function cacheStringFunction(fn) {
  516. const cache = /* @__PURE__ */ Object.create(null);
  517. return (str) => {
  518. const hit = cache[str];
  519. return hit || (cache[str] = fn(str));
  520. };
  521. }
  522. var hyphenateRE = /\B([A-Z])/g;
  523. var hyphenate = cacheStringFunction((str) =>
  524. str.replace(hyphenateRE, '-$1').toLowerCase(),
  525. );
  526. var camelizeRE = /-(\w)/g;
  527. var camelize = cacheStringFunction((str) => {
  528. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  529. });
  530. function promiseTimeout(ms, throwOnTimeout = false, reason = 'Timeout') {
  531. return new Promise((resolve, reject) => {
  532. if (throwOnTimeout) setTimeout(() => reject(reason), ms);
  533. else setTimeout(resolve, ms);
  534. });
  535. }
  536. function identity(arg) {
  537. return arg;
  538. }
  539. function createSingletonPromise(fn) {
  540. let _promise;
  541. function wrapper() {
  542. if (!_promise) _promise = fn();
  543. return _promise;
  544. }
  545. wrapper.reset = async () => {
  546. const _prev = _promise;
  547. _promise = void 0;
  548. if (_prev) await _prev;
  549. };
  550. return wrapper;
  551. }
  552. function invoke(fn) {
  553. return fn();
  554. }
  555. function containsProp(obj, ...props) {
  556. return props.some((k) => k in obj);
  557. }
  558. function increaseWithUnit(target, delta) {
  559. var _a;
  560. if (typeof target === 'number') return target + delta;
  561. const value =
  562. ((_a = target.match(/^-?[0-9]+\.?[0-9]*/)) == null ? void 0 : _a[0]) || '';
  563. const unit = target.slice(value.length);
  564. const result = Number.parseFloat(value) + delta;
  565. if (Number.isNaN(result)) return target;
  566. return result + unit;
  567. }
  568. function objectPick(obj, keys2, omitUndefined = false) {
  569. return keys2.reduce((n, k) => {
  570. if (k in obj) {
  571. if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
  572. }
  573. return n;
  574. }, {});
  575. }
  576. function objectOmit(obj, keys2, omitUndefined = false) {
  577. return Object.fromEntries(
  578. Object.entries(obj).filter(([key, value]) => {
  579. return (!omitUndefined || value !== void 0) && !keys2.includes(key);
  580. }),
  581. );
  582. }
  583. function objectEntries(obj) {
  584. return Object.entries(obj);
  585. }
  586. function getLifeCycleTarget(target) {
  587. return target || getCurrentInstance();
  588. }
  589. function toRef2(...args) {
  590. if (args.length !== 1) return toRef(...args);
  591. const r = args[0];
  592. return typeof r === 'function'
  593. ? readonly(customRef(() => ({ get: r, set: noop })))
  594. : ref(r);
  595. }
  596. var resolveRef = toRef2;
  597. function reactivePick(obj, ...keys2) {
  598. const flatKeys = keys2.flat();
  599. const predicate = flatKeys[0];
  600. return reactiveComputed(() =>
  601. typeof predicate === 'function'
  602. ? Object.fromEntries(
  603. Object.entries(toRefs(obj)).filter(([k, v]) =>
  604. predicate(toValue(v), k),
  605. ),
  606. )
  607. : Object.fromEntries(flatKeys.map((k) => [k, toRef2(obj, k)])),
  608. );
  609. }
  610. function refAutoReset(defaultValue, afterMs = 1e4) {
  611. return customRef((track, trigger) => {
  612. let value = toValue(defaultValue);
  613. let timer;
  614. const resetAfter = () =>
  615. setTimeout(() => {
  616. value = toValue(defaultValue);
  617. trigger();
  618. }, toValue(afterMs));
  619. tryOnScopeDispose(() => {
  620. clearTimeout(timer);
  621. });
  622. return {
  623. get() {
  624. track();
  625. return value;
  626. },
  627. set(newValue) {
  628. value = newValue;
  629. trigger();
  630. clearTimeout(timer);
  631. timer = resetAfter();
  632. },
  633. };
  634. });
  635. }
  636. function useDebounceFn(fn, ms = 200, options = {}) {
  637. return createFilterWrapper(debounceFilter(ms, options), fn);
  638. }
  639. function refDebounced(value, ms = 200, options = {}) {
  640. const debounced = ref(value.value);
  641. const updater = useDebounceFn(
  642. () => {
  643. debounced.value = value.value;
  644. },
  645. ms,
  646. options,
  647. );
  648. watch(value, () => updater());
  649. return debounced;
  650. }
  651. function refDefault(source, defaultValue) {
  652. return computed({
  653. get() {
  654. var _a;
  655. return (_a = source.value) != null ? _a : defaultValue;
  656. },
  657. set(value) {
  658. source.value = value;
  659. },
  660. });
  661. }
  662. function useThrottleFn(
  663. fn,
  664. ms = 200,
  665. trailing = false,
  666. leading = true,
  667. rejectOnCancel = false,
  668. ) {
  669. return createFilterWrapper(
  670. throttleFilter(ms, trailing, leading, rejectOnCancel),
  671. fn,
  672. );
  673. }
  674. function refThrottled(value, delay = 200, trailing = true, leading = true) {
  675. if (delay <= 0) return value;
  676. const throttled = ref(value.value);
  677. const updater = useThrottleFn(
  678. () => {
  679. throttled.value = value.value;
  680. },
  681. delay,
  682. trailing,
  683. leading,
  684. );
  685. watch(value, () => updater());
  686. return throttled;
  687. }
  688. function refWithControl(initial, options = {}) {
  689. let source = initial;
  690. let track;
  691. let trigger;
  692. const ref2 = customRef((_track, _trigger) => {
  693. track = _track;
  694. trigger = _trigger;
  695. return {
  696. get() {
  697. return get2();
  698. },
  699. set(v) {
  700. set3(v);
  701. },
  702. };
  703. });
  704. function get2(tracking = true) {
  705. if (tracking) track();
  706. return source;
  707. }
  708. function set3(value, triggering = true) {
  709. var _a, _b;
  710. if (value === source) return;
  711. const old = source;
  712. if (
  713. ((_a = options.onBeforeChange) == null
  714. ? void 0
  715. : _a.call(options, value, old)) === false
  716. )
  717. return;
  718. source = value;
  719. (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
  720. if (triggering) trigger();
  721. }
  722. const untrackedGet = () => get2(false);
  723. const silentSet = (v) => set3(v, false);
  724. const peek = () => get2(false);
  725. const lay = (v) => set3(v, false);
  726. return extendRef(
  727. ref2,
  728. {
  729. get: get2,
  730. set: set3,
  731. untrackedGet,
  732. silentSet,
  733. peek,
  734. lay,
  735. },
  736. { enumerable: true },
  737. );
  738. }
  739. var controlledRef = refWithControl;
  740. function set2(...args) {
  741. if (args.length === 2) {
  742. const [ref2, value] = args;
  743. ref2.value = value;
  744. }
  745. if (args.length === 3) {
  746. if (isVue2) {
  747. set(...args);
  748. } else {
  749. const [target, key, value] = args;
  750. target[key] = value;
  751. }
  752. }
  753. }
  754. function watchWithFilter(source, cb, options = {}) {
  755. const { eventFilter = bypassFilter, ...watchOptions } = options;
  756. return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
  757. }
  758. function watchPausable(source, cb, options = {}) {
  759. const { eventFilter: filter, ...watchOptions } = options;
  760. const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
  761. const stop = watchWithFilter(source, cb, {
  762. ...watchOptions,
  763. eventFilter,
  764. });
  765. return { stop, pause, resume, isActive };
  766. }
  767. function syncRef(left, right, ...[options]) {
  768. const {
  769. flush = 'sync',
  770. deep = false,
  771. immediate = true,
  772. direction = 'both',
  773. transform = {},
  774. } = options || {};
  775. const watchers = [];
  776. const transformLTR = ('ltr' in transform && transform.ltr) || ((v) => v);
  777. const transformRTL = ('rtl' in transform && transform.rtl) || ((v) => v);
  778. if (direction === 'both' || direction === 'ltr') {
  779. watchers.push(
  780. watchPausable(
  781. left,
  782. (newValue) => {
  783. watchers.forEach((w) => w.pause());
  784. right.value = transformLTR(newValue);
  785. watchers.forEach((w) => w.resume());
  786. },
  787. { flush, deep, immediate },
  788. ),
  789. );
  790. }
  791. if (direction === 'both' || direction === 'rtl') {
  792. watchers.push(
  793. watchPausable(
  794. right,
  795. (newValue) => {
  796. watchers.forEach((w) => w.pause());
  797. left.value = transformRTL(newValue);
  798. watchers.forEach((w) => w.resume());
  799. },
  800. { flush, deep, immediate },
  801. ),
  802. );
  803. }
  804. const stop = () => {
  805. watchers.forEach((w) => w.stop());
  806. };
  807. return stop;
  808. }
  809. function syncRefs(source, targets, options = {}) {
  810. const { flush = 'sync', deep = false, immediate = true } = options;
  811. if (!Array.isArray(targets)) targets = [targets];
  812. return watch(
  813. source,
  814. (newValue) => targets.forEach((target) => (target.value = newValue)),
  815. { flush, deep, immediate },
  816. );
  817. }
  818. function toRefs2(objectRef, options = {}) {
  819. if (!isRef(objectRef)) return toRefs(objectRef);
  820. const result = Array.isArray(objectRef.value)
  821. ? Array.from({ length: objectRef.value.length })
  822. : {};
  823. for (const key in objectRef.value) {
  824. result[key] = customRef(() => ({
  825. get() {
  826. return objectRef.value[key];
  827. },
  828. set(v) {
  829. var _a;
  830. const replaceRef =
  831. (_a = toValue(options.replaceRef)) != null ? _a : true;
  832. if (replaceRef) {
  833. if (Array.isArray(objectRef.value)) {
  834. const copy = [...objectRef.value];
  835. copy[key] = v;
  836. objectRef.value = copy;
  837. } else {
  838. const newObject = { ...objectRef.value, [key]: v };
  839. Object.setPrototypeOf(
  840. newObject,
  841. Object.getPrototypeOf(objectRef.value),
  842. );
  843. objectRef.value = newObject;
  844. }
  845. } else {
  846. objectRef.value[key] = v;
  847. }
  848. },
  849. }));
  850. }
  851. return result;
  852. }
  853. function tryOnBeforeMount(fn, sync = true, target) {
  854. const instance = getLifeCycleTarget(target);
  855. if (instance) onBeforeMount(fn, target);
  856. else if (sync) fn();
  857. else nextTick(fn);
  858. }
  859. function tryOnBeforeUnmount(fn, target) {
  860. const instance = getLifeCycleTarget(target);
  861. if (instance) onBeforeUnmount(fn, target);
  862. }
  863. function tryOnMounted(fn, sync = true, target) {
  864. const instance = getLifeCycleTarget();
  865. if (instance) onMounted(fn, target);
  866. else if (sync) fn();
  867. else nextTick(fn);
  868. }
  869. function tryOnUnmounted(fn, target) {
  870. const instance = getLifeCycleTarget(target);
  871. if (instance) onUnmounted(fn, target);
  872. }
  873. function createUntil(r, isNot = false) {
  874. function toMatch(
  875. condition,
  876. { flush = 'sync', deep = false, timeout, throwOnTimeout } = {},
  877. ) {
  878. let stop = null;
  879. const watcher = new Promise((resolve) => {
  880. stop = watch(
  881. r,
  882. (v) => {
  883. if (condition(v) !== isNot) {
  884. stop == null ? void 0 : stop();
  885. resolve(v);
  886. }
  887. },
  888. {
  889. flush,
  890. deep,
  891. immediate: true,
  892. },
  893. );
  894. });
  895. const promises = [watcher];
  896. if (timeout != null) {
  897. promises.push(
  898. promiseTimeout(timeout, throwOnTimeout)
  899. .then(() => toValue(r))
  900. .finally(() => (stop == null ? void 0 : stop())),
  901. );
  902. }
  903. return Promise.race(promises);
  904. }
  905. function toBe(value, options) {
  906. if (!isRef(value)) return toMatch((v) => v === value, options);
  907. const {
  908. flush = 'sync',
  909. deep = false,
  910. timeout,
  911. throwOnTimeout,
  912. } = options != null ? options : {};
  913. let stop = null;
  914. const watcher = new Promise((resolve) => {
  915. stop = watch(
  916. [r, value],
  917. ([v1, v2]) => {
  918. if (isNot !== (v1 === v2)) {
  919. stop == null ? void 0 : stop();
  920. resolve(v1);
  921. }
  922. },
  923. {
  924. flush,
  925. deep,
  926. immediate: true,
  927. },
  928. );
  929. });
  930. const promises = [watcher];
  931. if (timeout != null) {
  932. promises.push(
  933. promiseTimeout(timeout, throwOnTimeout)
  934. .then(() => toValue(r))
  935. .finally(() => {
  936. stop == null ? void 0 : stop();
  937. return toValue(r);
  938. }),
  939. );
  940. }
  941. return Promise.race(promises);
  942. }
  943. function toBeTruthy(options) {
  944. return toMatch((v) => Boolean(v), options);
  945. }
  946. function toBeNull(options) {
  947. return toBe(null, options);
  948. }
  949. function toBeUndefined(options) {
  950. return toBe(void 0, options);
  951. }
  952. function toBeNaN(options) {
  953. return toMatch(Number.isNaN, options);
  954. }
  955. function toContains(value, options) {
  956. return toMatch((v) => {
  957. const array = Array.from(v);
  958. return array.includes(value) || array.includes(toValue(value));
  959. }, options);
  960. }
  961. function changed(options) {
  962. return changedTimes(1, options);
  963. }
  964. function changedTimes(n = 1, options) {
  965. let count = -1;
  966. return toMatch(() => {
  967. count += 1;
  968. return count >= n;
  969. }, options);
  970. }
  971. if (Array.isArray(toValue(r))) {
  972. const instance = {
  973. toMatch,
  974. toContains,
  975. changed,
  976. changedTimes,
  977. get not() {
  978. return createUntil(r, !isNot);
  979. },
  980. };
  981. return instance;
  982. } else {
  983. const instance = {
  984. toMatch,
  985. toBe,
  986. toBeTruthy,
  987. toBeNull,
  988. toBeNaN,
  989. toBeUndefined,
  990. changed,
  991. changedTimes,
  992. get not() {
  993. return createUntil(r, !isNot);
  994. },
  995. };
  996. return instance;
  997. }
  998. }
  999. function until(r) {
  1000. return createUntil(r);
  1001. }
  1002. function defaultComparator(value, othVal) {
  1003. return value === othVal;
  1004. }
  1005. function useArrayDifference(...args) {
  1006. var _a;
  1007. const list = args[0];
  1008. const values = args[1];
  1009. let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
  1010. if (typeof compareFn === 'string') {
  1011. const key = compareFn;
  1012. compareFn = (value, othVal) => value[key] === othVal[key];
  1013. }
  1014. return computed(() =>
  1015. toValue(list).filter(
  1016. (x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1,
  1017. ),
  1018. );
  1019. }
  1020. function useArrayEvery(list, fn) {
  1021. return computed(() =>
  1022. toValue(list).every((element, index, array) =>
  1023. fn(toValue(element), index, array),
  1024. ),
  1025. );
  1026. }
  1027. function useArrayFilter(list, fn) {
  1028. return computed(() =>
  1029. toValue(list)
  1030. .map((i) => toValue(i))
  1031. .filter(fn),
  1032. );
  1033. }
  1034. function useArrayFind(list, fn) {
  1035. return computed(() =>
  1036. toValue(
  1037. toValue(list).find((element, index, array) =>
  1038. fn(toValue(element), index, array),
  1039. ),
  1040. ),
  1041. );
  1042. }
  1043. function useArrayFindIndex(list, fn) {
  1044. return computed(() =>
  1045. toValue(list).findIndex((element, index, array) =>
  1046. fn(toValue(element), index, array),
  1047. ),
  1048. );
  1049. }
  1050. function findLast(arr, cb) {
  1051. let index = arr.length;
  1052. while (index-- > 0) {
  1053. if (cb(arr[index], index, arr)) return arr[index];
  1054. }
  1055. return void 0;
  1056. }
  1057. function useArrayFindLast(list, fn) {
  1058. return computed(() =>
  1059. toValue(
  1060. !Array.prototype.findLast
  1061. ? findLast(toValue(list), (element, index, array) =>
  1062. fn(toValue(element), index, array),
  1063. )
  1064. : toValue(list).findLast((element, index, array) =>
  1065. fn(toValue(element), index, array),
  1066. ),
  1067. ),
  1068. );
  1069. }
  1070. function isArrayIncludesOptions(obj) {
  1071. return isObject(obj) && containsProp(obj, 'formIndex', 'comparator');
  1072. }
  1073. function useArrayIncludes(...args) {
  1074. var _a;
  1075. const list = args[0];
  1076. const value = args[1];
  1077. let comparator = args[2];
  1078. let formIndex = 0;
  1079. if (isArrayIncludesOptions(comparator)) {
  1080. formIndex = (_a = comparator.fromIndex) != null ? _a : 0;
  1081. comparator = comparator.comparator;
  1082. }
  1083. if (typeof comparator === 'string') {
  1084. const key = comparator;
  1085. comparator = (element, value2) => element[key] === toValue(value2);
  1086. }
  1087. comparator =
  1088. comparator != null
  1089. ? comparator
  1090. : (element, value2) => element === toValue(value2);
  1091. return computed(() =>
  1092. toValue(list)
  1093. .slice(formIndex)
  1094. .some((element, index, array) =>
  1095. comparator(toValue(element), toValue(value), index, toValue(array)),
  1096. ),
  1097. );
  1098. }
  1099. function useArrayJoin(list, separator) {
  1100. return computed(() =>
  1101. toValue(list)
  1102. .map((i) => toValue(i))
  1103. .join(toValue(separator)),
  1104. );
  1105. }
  1106. function useArrayMap(list, fn) {
  1107. return computed(() =>
  1108. toValue(list)
  1109. .map((i) => toValue(i))
  1110. .map(fn),
  1111. );
  1112. }
  1113. function useArrayReduce(list, reducer, ...args) {
  1114. const reduceCallback = (sum, value, index) =>
  1115. reducer(toValue(sum), toValue(value), index);
  1116. return computed(() => {
  1117. const resolved = toValue(list);
  1118. return args.length
  1119. ? resolved.reduce(reduceCallback, toValue(args[0]))
  1120. : resolved.reduce(reduceCallback);
  1121. });
  1122. }
  1123. function useArraySome(list, fn) {
  1124. return computed(() =>
  1125. toValue(list).some((element, index, array) =>
  1126. fn(toValue(element), index, array),
  1127. ),
  1128. );
  1129. }
  1130. function uniq(array) {
  1131. return Array.from(new Set(array));
  1132. }
  1133. function uniqueElementsBy(array, fn) {
  1134. return array.reduce((acc, v) => {
  1135. if (!acc.some((x) => fn(v, x, array))) acc.push(v);
  1136. return acc;
  1137. }, []);
  1138. }
  1139. function useArrayUnique(list, compareFn) {
  1140. return computed(() => {
  1141. const resolvedList = toValue(list).map((element) => toValue(element));
  1142. return compareFn
  1143. ? uniqueElementsBy(resolvedList, compareFn)
  1144. : uniq(resolvedList);
  1145. });
  1146. }
  1147. function useCounter(initialValue = 0, options = {}) {
  1148. let _initialValue = unref(initialValue);
  1149. const count = ref(initialValue);
  1150. const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } =
  1151. options;
  1152. const inc = (delta = 1) =>
  1153. (count.value = Math.max(Math.min(max, count.value + delta), min));
  1154. const dec = (delta = 1) =>
  1155. (count.value = Math.min(Math.max(min, count.value - delta), max));
  1156. const get2 = () => count.value;
  1157. const set3 = (val) => (count.value = Math.max(min, Math.min(max, val)));
  1158. const reset = (val = _initialValue) => {
  1159. _initialValue = val;
  1160. return set3(val);
  1161. };
  1162. return { count, inc, dec, get: get2, set: set3, reset };
  1163. }
  1164. var REGEX_PARSE =
  1165. /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
  1166. var REGEX_FORMAT =
  1167. /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
  1168. function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
  1169. let m = hours < 12 ? 'AM' : 'PM';
  1170. if (hasPeriod) m = m.split('').reduce((acc, curr) => (acc += `${curr}.`), '');
  1171. return isLowercase ? m.toLowerCase() : m;
  1172. }
  1173. function formatOrdinal(num) {
  1174. const suffixes = ['th', 'st', 'nd', 'rd'];
  1175. const v = num % 100;
  1176. return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
  1177. }
  1178. function formatDate(date, formatStr, options = {}) {
  1179. var _a;
  1180. const years = date.getFullYear();
  1181. const month = date.getMonth();
  1182. const days = date.getDate();
  1183. const hours = date.getHours();
  1184. const minutes = date.getMinutes();
  1185. const seconds = date.getSeconds();
  1186. const milliseconds = date.getMilliseconds();
  1187. const day = date.getDay();
  1188. const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
  1189. const matches = {
  1190. Yo: () => formatOrdinal(years),
  1191. YY: () => String(years).slice(-2),
  1192. YYYY: () => years,
  1193. M: () => month + 1,
  1194. Mo: () => formatOrdinal(month + 1),
  1195. MM: () => `${month + 1}`.padStart(2, '0'),
  1196. MMM: () => date.toLocaleDateString(options.locales, { month: 'short' }),
  1197. MMMM: () => date.toLocaleDateString(options.locales, { month: 'long' }),
  1198. D: () => String(days),
  1199. Do: () => formatOrdinal(days),
  1200. DD: () => `${days}`.padStart(2, '0'),
  1201. H: () => String(hours),
  1202. Ho: () => formatOrdinal(hours),
  1203. HH: () => `${hours}`.padStart(2, '0'),
  1204. h: () => `${hours % 12 || 12}`.padStart(1, '0'),
  1205. ho: () => formatOrdinal(hours % 12 || 12),
  1206. hh: () => `${hours % 12 || 12}`.padStart(2, '0'),
  1207. m: () => String(minutes),
  1208. mo: () => formatOrdinal(minutes),
  1209. mm: () => `${minutes}`.padStart(2, '0'),
  1210. s: () => String(seconds),
  1211. so: () => formatOrdinal(seconds),
  1212. ss: () => `${seconds}`.padStart(2, '0'),
  1213. SSS: () => `${milliseconds}`.padStart(3, '0'),
  1214. d: () => day,
  1215. dd: () => date.toLocaleDateString(options.locales, { weekday: 'narrow' }),
  1216. ddd: () => date.toLocaleDateString(options.locales, { weekday: 'short' }),
  1217. dddd: () => date.toLocaleDateString(options.locales, { weekday: 'long' }),
  1218. A: () => meridiem(hours, minutes),
  1219. AA: () => meridiem(hours, minutes, false, true),
  1220. a: () => meridiem(hours, minutes, true),
  1221. aa: () => meridiem(hours, minutes, true, true),
  1222. };
  1223. return formatStr.replace(REGEX_FORMAT, (match, $1) => {
  1224. var _a2, _b;
  1225. return (_b =
  1226. $1 != null
  1227. ? $1
  1228. : (_a2 = matches[match]) == null
  1229. ? void 0
  1230. : _a2.call(matches)) != null
  1231. ? _b
  1232. : match;
  1233. });
  1234. }
  1235. function normalizeDate(date) {
  1236. if (date === null) return new Date(Number.NaN);
  1237. if (date === void 0) return /* @__PURE__ */ new Date();
  1238. if (date instanceof Date) return new Date(date);
  1239. if (typeof date === 'string' && !/Z$/i.test(date)) {
  1240. const d = date.match(REGEX_PARSE);
  1241. if (d) {
  1242. const m = d[2] - 1 || 0;
  1243. const ms = (d[7] || '0').substring(0, 3);
  1244. return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
  1245. }
  1246. }
  1247. return new Date(date);
  1248. }
  1249. function useDateFormat(date, formatStr = 'HH:mm:ss', options = {}) {
  1250. return computed(() =>
  1251. formatDate(normalizeDate(toValue(date)), toValue(formatStr), options),
  1252. );
  1253. }
  1254. function useIntervalFn(cb, interval = 1e3, options = {}) {
  1255. const { immediate = true, immediateCallback = false } = options;
  1256. let timer = null;
  1257. const isActive = ref(false);
  1258. function clean() {
  1259. if (timer) {
  1260. clearInterval(timer);
  1261. timer = null;
  1262. }
  1263. }
  1264. function pause() {
  1265. isActive.value = false;
  1266. clean();
  1267. }
  1268. function resume() {
  1269. const intervalValue = toValue(interval);
  1270. if (intervalValue <= 0) return;
  1271. isActive.value = true;
  1272. if (immediateCallback) cb();
  1273. clean();
  1274. timer = setInterval(cb, intervalValue);
  1275. }
  1276. if (immediate && isClient) resume();
  1277. if (isRef(interval) || typeof interval === 'function') {
  1278. const stopWatch = watch(interval, () => {
  1279. if (isActive.value && isClient) resume();
  1280. });
  1281. tryOnScopeDispose(stopWatch);
  1282. }
  1283. tryOnScopeDispose(pause);
  1284. return {
  1285. isActive,
  1286. pause,
  1287. resume,
  1288. };
  1289. }
  1290. function useInterval(interval = 1e3, options = {}) {
  1291. const {
  1292. controls: exposeControls = false,
  1293. immediate = true,
  1294. callback,
  1295. } = options;
  1296. const counter = ref(0);
  1297. const update = () => (counter.value += 1);
  1298. const reset = () => {
  1299. counter.value = 0;
  1300. };
  1301. const controls = useIntervalFn(
  1302. callback
  1303. ? () => {
  1304. update();
  1305. callback(counter.value);
  1306. }
  1307. : update,
  1308. interval,
  1309. { immediate },
  1310. );
  1311. if (exposeControls) {
  1312. return {
  1313. counter,
  1314. reset,
  1315. ...controls,
  1316. };
  1317. } else {
  1318. return counter;
  1319. }
  1320. }
  1321. function useLastChanged(source, options = {}) {
  1322. var _a;
  1323. const ms = ref((_a = options.initialValue) != null ? _a : null);
  1324. watch(source, () => (ms.value = timestamp()), options);
  1325. return ms;
  1326. }
  1327. function useTimeoutFn(cb, interval, options = {}) {
  1328. const { immediate = true } = options;
  1329. const isPending = ref(false);
  1330. let timer = null;
  1331. function clear() {
  1332. if (timer) {
  1333. clearTimeout(timer);
  1334. timer = null;
  1335. }
  1336. }
  1337. function stop() {
  1338. isPending.value = false;
  1339. clear();
  1340. }
  1341. function start(...args) {
  1342. clear();
  1343. isPending.value = true;
  1344. timer = setTimeout(() => {
  1345. isPending.value = false;
  1346. timer = null;
  1347. cb(...args);
  1348. }, toValue(interval));
  1349. }
  1350. if (immediate) {
  1351. isPending.value = true;
  1352. if (isClient) start();
  1353. }
  1354. tryOnScopeDispose(stop);
  1355. return {
  1356. isPending: readonly(isPending),
  1357. start,
  1358. stop,
  1359. };
  1360. }
  1361. function useTimeout(interval = 1e3, options = {}) {
  1362. const { controls: exposeControls = false, callback } = options;
  1363. const controls = useTimeoutFn(
  1364. callback != null ? callback : noop,
  1365. interval,
  1366. options,
  1367. );
  1368. const ready = computed(() => !controls.isPending.value);
  1369. if (exposeControls) {
  1370. return {
  1371. ready,
  1372. ...controls,
  1373. };
  1374. } else {
  1375. return ready;
  1376. }
  1377. }
  1378. function useToNumber(value, options = {}) {
  1379. const { method = 'parseFloat', radix, nanToZero } = options;
  1380. return computed(() => {
  1381. let resolved = toValue(value);
  1382. if (typeof resolved === 'string')
  1383. resolved = Number[method](resolved, radix);
  1384. if (nanToZero && Number.isNaN(resolved)) resolved = 0;
  1385. return resolved;
  1386. });
  1387. }
  1388. function useToString(value) {
  1389. return computed(() => `${toValue(value)}`);
  1390. }
  1391. function useToggle(initialValue = false, options = {}) {
  1392. const { truthyValue = true, falsyValue = false } = options;
  1393. const valueIsRef = isRef(initialValue);
  1394. const _value = ref(initialValue);
  1395. function toggle(value) {
  1396. if (arguments.length) {
  1397. _value.value = value;
  1398. return _value.value;
  1399. } else {
  1400. const truthy = toValue(truthyValue);
  1401. _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
  1402. return _value.value;
  1403. }
  1404. }
  1405. if (valueIsRef) return toggle;
  1406. else return [_value, toggle];
  1407. }
  1408. function watchArray(source, cb, options) {
  1409. let oldList = (options == null ? void 0 : options.immediate)
  1410. ? []
  1411. : [
  1412. ...(source instanceof Function
  1413. ? source()
  1414. : Array.isArray(source)
  1415. ? source
  1416. : toValue(source)),
  1417. ];
  1418. return watch(
  1419. source,
  1420. (newList, _, onCleanup) => {
  1421. const oldListRemains = Array.from({ length: oldList.length });
  1422. const added = [];
  1423. for (const obj of newList) {
  1424. let found = false;
  1425. for (let i = 0; i < oldList.length; i++) {
  1426. if (!oldListRemains[i] && obj === oldList[i]) {
  1427. oldListRemains[i] = true;
  1428. found = true;
  1429. break;
  1430. }
  1431. }
  1432. if (!found) added.push(obj);
  1433. }
  1434. const removed = oldList.filter((_2, i) => !oldListRemains[i]);
  1435. cb(newList, oldList, added, removed, onCleanup);
  1436. oldList = [...newList];
  1437. },
  1438. options,
  1439. );
  1440. }
  1441. function watchAtMost(source, cb, options) {
  1442. const { count, ...watchOptions } = options;
  1443. const current = ref(0);
  1444. const stop = watchWithFilter(
  1445. source,
  1446. (...args) => {
  1447. current.value += 1;
  1448. if (current.value >= toValue(count)) nextTick(() => stop());
  1449. cb(...args);
  1450. },
  1451. watchOptions,
  1452. );
  1453. return { count: current, stop };
  1454. }
  1455. function watchDebounced(source, cb, options = {}) {
  1456. const { debounce = 0, maxWait = void 0, ...watchOptions } = options;
  1457. return watchWithFilter(source, cb, {
  1458. ...watchOptions,
  1459. eventFilter: debounceFilter(debounce, { maxWait }),
  1460. });
  1461. }
  1462. function watchDeep(source, cb, options) {
  1463. return watch(source, cb, {
  1464. ...options,
  1465. deep: true,
  1466. });
  1467. }
  1468. function watchIgnorable(source, cb, options = {}) {
  1469. const { eventFilter = bypassFilter, ...watchOptions } = options;
  1470. const filteredCb = createFilterWrapper(eventFilter, cb);
  1471. let ignoreUpdates;
  1472. let ignorePrevAsyncUpdates;
  1473. let stop;
  1474. if (watchOptions.flush === 'sync') {
  1475. const ignore = ref(false);
  1476. ignorePrevAsyncUpdates = () => {};
  1477. ignoreUpdates = (updater) => {
  1478. ignore.value = true;
  1479. updater();
  1480. ignore.value = false;
  1481. };
  1482. stop = watch(
  1483. source,
  1484. (...args) => {
  1485. if (!ignore.value) filteredCb(...args);
  1486. },
  1487. watchOptions,
  1488. );
  1489. } else {
  1490. const disposables = [];
  1491. const ignoreCounter = ref(0);
  1492. const syncCounter = ref(0);
  1493. ignorePrevAsyncUpdates = () => {
  1494. ignoreCounter.value = syncCounter.value;
  1495. };
  1496. disposables.push(
  1497. watch(
  1498. source,
  1499. () => {
  1500. syncCounter.value++;
  1501. },
  1502. { ...watchOptions, flush: 'sync' },
  1503. ),
  1504. );
  1505. ignoreUpdates = (updater) => {
  1506. const syncCounterPrev = syncCounter.value;
  1507. updater();
  1508. ignoreCounter.value += syncCounter.value - syncCounterPrev;
  1509. };
  1510. disposables.push(
  1511. watch(
  1512. source,
  1513. (...args) => {
  1514. const ignore =
  1515. ignoreCounter.value > 0 &&
  1516. ignoreCounter.value === syncCounter.value;
  1517. ignoreCounter.value = 0;
  1518. syncCounter.value = 0;
  1519. if (ignore) return;
  1520. filteredCb(...args);
  1521. },
  1522. watchOptions,
  1523. ),
  1524. );
  1525. stop = () => {
  1526. disposables.forEach((fn) => fn());
  1527. };
  1528. }
  1529. return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
  1530. }
  1531. function watchImmediate(source, cb, options) {
  1532. return watch(source, cb, {
  1533. ...options,
  1534. immediate: true,
  1535. });
  1536. }
  1537. function watchOnce(source, cb, options) {
  1538. const stop = watch(
  1539. source,
  1540. (...args) => {
  1541. nextTick(() => stop());
  1542. return cb(...args);
  1543. },
  1544. options,
  1545. );
  1546. return stop;
  1547. }
  1548. function watchThrottled(source, cb, options = {}) {
  1549. const {
  1550. throttle = 0,
  1551. trailing = true,
  1552. leading = true,
  1553. ...watchOptions
  1554. } = options;
  1555. return watchWithFilter(source, cb, {
  1556. ...watchOptions,
  1557. eventFilter: throttleFilter(throttle, trailing, leading),
  1558. });
  1559. }
  1560. function watchTriggerable(source, cb, options = {}) {
  1561. let cleanupFn;
  1562. function onEffect() {
  1563. if (!cleanupFn) return;
  1564. const fn = cleanupFn;
  1565. cleanupFn = void 0;
  1566. fn();
  1567. }
  1568. function onCleanup(callback) {
  1569. cleanupFn = callback;
  1570. }
  1571. const _cb = (value, oldValue) => {
  1572. onEffect();
  1573. return cb(value, oldValue, onCleanup);
  1574. };
  1575. const res = watchIgnorable(source, _cb, options);
  1576. const { ignoreUpdates } = res;
  1577. const trigger = () => {
  1578. let res2;
  1579. ignoreUpdates(() => {
  1580. res2 = _cb(getWatchSources(source), getOldValue(source));
  1581. });
  1582. return res2;
  1583. };
  1584. return {
  1585. ...res,
  1586. trigger,
  1587. };
  1588. }
  1589. function getWatchSources(sources) {
  1590. if (isReactive(sources)) return sources;
  1591. if (Array.isArray(sources)) return sources.map((item) => toValue(item));
  1592. return toValue(sources);
  1593. }
  1594. function getOldValue(source) {
  1595. return Array.isArray(source) ? source.map(() => void 0) : void 0;
  1596. }
  1597. function whenever(source, cb, options) {
  1598. const stop = watch(
  1599. source,
  1600. (v, ov, onInvalidate) => {
  1601. if (v) {
  1602. if (options == null ? void 0 : options.once) nextTick(() => stop());
  1603. cb(v, ov, onInvalidate);
  1604. }
  1605. },
  1606. {
  1607. ...options,
  1608. once: false,
  1609. },
  1610. );
  1611. return stop;
  1612. }
  1613. // ../node_modules/.pnpm/@vueuse+core@10.9.0_vue@3.4.27_typescript@5.4.5_/node_modules/@vueuse/core/index.mjs
  1614. function computedAsync(evaluationCallback, initialState, optionsOrRef) {
  1615. let options;
  1616. if (isRef(optionsOrRef)) {
  1617. options = {
  1618. evaluating: optionsOrRef,
  1619. };
  1620. } else {
  1621. options = optionsOrRef || {};
  1622. }
  1623. const {
  1624. lazy = false,
  1625. evaluating = void 0,
  1626. shallow = true,
  1627. onError = noop,
  1628. } = options;
  1629. const started = ref(!lazy);
  1630. const current = shallow ? shallowRef(initialState) : ref(initialState);
  1631. let counter = 0;
  1632. watchEffect(async (onInvalidate) => {
  1633. if (!started.value) return;
  1634. counter++;
  1635. const counterAtBeginning = counter;
  1636. let hasFinished = false;
  1637. if (evaluating) {
  1638. Promise.resolve().then(() => {
  1639. evaluating.value = true;
  1640. });
  1641. }
  1642. try {
  1643. const result = await evaluationCallback((cancelCallback) => {
  1644. onInvalidate(() => {
  1645. if (evaluating) evaluating.value = false;
  1646. if (!hasFinished) cancelCallback();
  1647. });
  1648. });
  1649. if (counterAtBeginning === counter) current.value = result;
  1650. } catch (e) {
  1651. onError(e);
  1652. } finally {
  1653. if (evaluating && counterAtBeginning === counter)
  1654. evaluating.value = false;
  1655. hasFinished = true;
  1656. }
  1657. });
  1658. if (lazy) {
  1659. return computed(() => {
  1660. started.value = true;
  1661. return current.value;
  1662. });
  1663. } else {
  1664. return current;
  1665. }
  1666. }
  1667. function computedInject(key, options, defaultSource, treatDefaultAsFactory) {
  1668. let source = inject(key);
  1669. if (defaultSource) source = inject(key, defaultSource);
  1670. if (treatDefaultAsFactory)
  1671. source = inject(key, defaultSource, treatDefaultAsFactory);
  1672. if (typeof options === 'function') {
  1673. return computed((ctx) => options(source, ctx));
  1674. } else {
  1675. return computed({
  1676. get: (ctx) => options.get(source, ctx),
  1677. set: options.set,
  1678. });
  1679. }
  1680. }
  1681. function createReusableTemplate(options = {}) {
  1682. if (!isVue3 && !version.startsWith('2.7.')) {
  1683. if (true)
  1684. throw new Error(
  1685. '[VueUse] createReusableTemplate only works in Vue 2.7 or above.',
  1686. );
  1687. return;
  1688. }
  1689. const { inheritAttrs = true } = options;
  1690. const render = shallowRef();
  1691. const define = defineComponent({
  1692. setup(_, { slots }) {
  1693. return () => {
  1694. render.value = slots.default;
  1695. };
  1696. },
  1697. });
  1698. const reuse = defineComponent({
  1699. inheritAttrs,
  1700. setup(_, { attrs, slots }) {
  1701. return () => {
  1702. var _a;
  1703. if (!render.value && true)
  1704. throw new Error(
  1705. '[VueUse] Failed to find the definition of reusable template',
  1706. );
  1707. const vnode =
  1708. (_a = render.value) == null
  1709. ? void 0
  1710. : _a.call(render, {
  1711. ...keysToCamelKebabCase(attrs),
  1712. $slots: slots,
  1713. });
  1714. return inheritAttrs && (vnode == null ? void 0 : vnode.length) === 1
  1715. ? vnode[0]
  1716. : vnode;
  1717. };
  1718. },
  1719. });
  1720. return makeDestructurable({ define, reuse }, [define, reuse]);
  1721. }
  1722. function keysToCamelKebabCase(obj) {
  1723. const newObj = {};
  1724. for (const key in obj) newObj[camelize(key)] = obj[key];
  1725. return newObj;
  1726. }
  1727. function createTemplatePromise(options = {}) {
  1728. if (!isVue3) {
  1729. if (true)
  1730. throw new Error(
  1731. '[VueUse] createTemplatePromise only works in Vue 3 or above.',
  1732. );
  1733. return;
  1734. }
  1735. let index = 0;
  1736. const instances = ref([]);
  1737. function create(...args) {
  1738. const props = shallowReactive({
  1739. key: index++,
  1740. args,
  1741. promise: void 0,
  1742. resolve: () => {},
  1743. reject: () => {},
  1744. isResolving: false,
  1745. options,
  1746. });
  1747. instances.value.push(props);
  1748. props.promise = new Promise((_resolve, _reject) => {
  1749. props.resolve = (v) => {
  1750. props.isResolving = true;
  1751. return _resolve(v);
  1752. };
  1753. props.reject = _reject;
  1754. }).finally(() => {
  1755. props.promise = void 0;
  1756. const index2 = instances.value.indexOf(props);
  1757. if (index2 !== -1) instances.value.splice(index2, 1);
  1758. });
  1759. return props.promise;
  1760. }
  1761. function start(...args) {
  1762. if (options.singleton && instances.value.length > 0)
  1763. return instances.value[0].promise;
  1764. return create(...args);
  1765. }
  1766. const component = defineComponent((_, { slots }) => {
  1767. const renderList = () =>
  1768. instances.value.map((props) => {
  1769. var _a;
  1770. return h(
  1771. Fragment,
  1772. { key: props.key },
  1773. (_a = slots.default) == null ? void 0 : _a.call(slots, props),
  1774. );
  1775. });
  1776. if (options.transition)
  1777. return () => h(TransitionGroup, options.transition, renderList);
  1778. return renderList;
  1779. });
  1780. component.start = start;
  1781. return component;
  1782. }
  1783. function createUnrefFn(fn) {
  1784. return function (...args) {
  1785. return fn.apply(
  1786. this,
  1787. args.map((i) => toValue(i)),
  1788. );
  1789. };
  1790. }
  1791. function unrefElement(elRef) {
  1792. var _a;
  1793. const plain = toValue(elRef);
  1794. return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
  1795. }
  1796. var defaultWindow = isClient ? window : void 0;
  1797. var defaultDocument = isClient ? window.document : void 0;
  1798. var defaultNavigator = isClient ? window.navigator : void 0;
  1799. var defaultLocation = isClient ? window.location : void 0;
  1800. function useEventListener(...args) {
  1801. let target;
  1802. let events2;
  1803. let listeners;
  1804. let options;
  1805. if (typeof args[0] === 'string' || Array.isArray(args[0])) {
  1806. [events2, listeners, options] = args;
  1807. target = defaultWindow;
  1808. } else {
  1809. [target, events2, listeners, options] = args;
  1810. }
  1811. if (!target) return noop;
  1812. if (!Array.isArray(events2)) events2 = [events2];
  1813. if (!Array.isArray(listeners)) listeners = [listeners];
  1814. const cleanups = [];
  1815. const cleanup = () => {
  1816. cleanups.forEach((fn) => fn());
  1817. cleanups.length = 0;
  1818. };
  1819. const register = (el, event, listener, options2) => {
  1820. el.addEventListener(event, listener, options2);
  1821. return () => el.removeEventListener(event, listener, options2);
  1822. };
  1823. const stopWatch = watch(
  1824. () => [unrefElement(target), toValue(options)],
  1825. ([el, options2]) => {
  1826. cleanup();
  1827. if (!el) return;
  1828. const optionsClone = isObject(options2) ? { ...options2 } : options2;
  1829. cleanups.push(
  1830. ...events2.flatMap((event) => {
  1831. return listeners.map((listener) =>
  1832. register(el, event, listener, optionsClone),
  1833. );
  1834. }),
  1835. );
  1836. },
  1837. { immediate: true, flush: 'post' },
  1838. );
  1839. const stop = () => {
  1840. stopWatch();
  1841. cleanup();
  1842. };
  1843. tryOnScopeDispose(stop);
  1844. return stop;
  1845. }
  1846. var _iOSWorkaround = false;
  1847. function onClickOutside(target, handler, options = {}) {
  1848. const {
  1849. window: window2 = defaultWindow,
  1850. ignore = [],
  1851. capture = true,
  1852. detectIframe = false,
  1853. } = options;
  1854. if (!window2) return noop;
  1855. if (isIOS && !_iOSWorkaround) {
  1856. _iOSWorkaround = true;
  1857. Array.from(window2.document.body.children).forEach((el) =>
  1858. el.addEventListener('click', noop),
  1859. );
  1860. window2.document.documentElement.addEventListener('click', noop);
  1861. }
  1862. let shouldListen = true;
  1863. const shouldIgnore = (event) => {
  1864. return ignore.some((target2) => {
  1865. if (typeof target2 === 'string') {
  1866. return Array.from(window2.document.querySelectorAll(target2)).some(
  1867. (el) => el === event.target || event.composedPath().includes(el),
  1868. );
  1869. } else {
  1870. const el = unrefElement(target2);
  1871. return el && (event.target === el || event.composedPath().includes(el));
  1872. }
  1873. });
  1874. };
  1875. const listener = (event) => {
  1876. const el = unrefElement(target);
  1877. if (!el || el === event.target || event.composedPath().includes(el)) return;
  1878. if (event.detail === 0) shouldListen = !shouldIgnore(event);
  1879. if (!shouldListen) {
  1880. shouldListen = true;
  1881. return;
  1882. }
  1883. handler(event);
  1884. };
  1885. const cleanup = [
  1886. useEventListener(window2, 'click', listener, { passive: true, capture }),
  1887. useEventListener(
  1888. window2,
  1889. 'pointerdown',
  1890. (e) => {
  1891. const el = unrefElement(target);
  1892. shouldListen =
  1893. !shouldIgnore(e) && !!(el && !e.composedPath().includes(el));
  1894. },
  1895. { passive: true },
  1896. ),
  1897. detectIframe &&
  1898. useEventListener(window2, 'blur', (event) => {
  1899. setTimeout(() => {
  1900. var _a;
  1901. const el = unrefElement(target);
  1902. if (
  1903. ((_a = window2.document.activeElement) == null
  1904. ? void 0
  1905. : _a.tagName) === 'IFRAME' &&
  1906. !(el == null ? void 0 : el.contains(window2.document.activeElement))
  1907. )
  1908. handler(event);
  1909. }, 0);
  1910. }),
  1911. ].filter(Boolean);
  1912. const stop = () => cleanup.forEach((fn) => fn());
  1913. return stop;
  1914. }
  1915. function createKeyPredicate(keyFilter) {
  1916. if (typeof keyFilter === 'function') return keyFilter;
  1917. else if (typeof keyFilter === 'string')
  1918. return (event) => event.key === keyFilter;
  1919. else if (Array.isArray(keyFilter))
  1920. return (event) => keyFilter.includes(event.key);
  1921. return () => true;
  1922. }
  1923. function onKeyStroke(...args) {
  1924. let key;
  1925. let handler;
  1926. let options = {};
  1927. if (args.length === 3) {
  1928. key = args[0];
  1929. handler = args[1];
  1930. options = args[2];
  1931. } else if (args.length === 2) {
  1932. if (typeof args[1] === 'object') {
  1933. key = true;
  1934. handler = args[0];
  1935. options = args[1];
  1936. } else {
  1937. key = args[0];
  1938. handler = args[1];
  1939. }
  1940. } else {
  1941. key = true;
  1942. handler = args[0];
  1943. }
  1944. const {
  1945. target = defaultWindow,
  1946. eventName = 'keydown',
  1947. passive = false,
  1948. dedupe = false,
  1949. } = options;
  1950. const predicate = createKeyPredicate(key);
  1951. const listener = (e) => {
  1952. if (e.repeat && toValue(dedupe)) return;
  1953. if (predicate(e)) handler(e);
  1954. };
  1955. return useEventListener(target, eventName, listener, passive);
  1956. }
  1957. function onKeyDown(key, handler, options = {}) {
  1958. return onKeyStroke(key, handler, { ...options, eventName: 'keydown' });
  1959. }
  1960. function onKeyPressed(key, handler, options = {}) {
  1961. return onKeyStroke(key, handler, { ...options, eventName: 'keypress' });
  1962. }
  1963. function onKeyUp(key, handler, options = {}) {
  1964. return onKeyStroke(key, handler, { ...options, eventName: 'keyup' });
  1965. }
  1966. var DEFAULT_DELAY = 500;
  1967. var DEFAULT_THRESHOLD = 10;
  1968. function onLongPress(target, handler, options) {
  1969. var _a, _b;
  1970. const elementRef = computed(() => unrefElement(target));
  1971. let timeout;
  1972. let posStart;
  1973. function clear() {
  1974. if (timeout) {
  1975. clearTimeout(timeout);
  1976. timeout = void 0;
  1977. }
  1978. posStart = void 0;
  1979. }
  1980. function onDown(ev) {
  1981. var _a2, _b2, _c, _d;
  1982. if (
  1983. ((_a2 = options == null ? void 0 : options.modifiers) == null
  1984. ? void 0
  1985. : _a2.self) &&
  1986. ev.target !== elementRef.value
  1987. )
  1988. return;
  1989. clear();
  1990. if (
  1991. (_b2 = options == null ? void 0 : options.modifiers) == null
  1992. ? void 0
  1993. : _b2.prevent
  1994. )
  1995. ev.preventDefault();
  1996. if (
  1997. (_c = options == null ? void 0 : options.modifiers) == null
  1998. ? void 0
  1999. : _c.stop
  2000. )
  2001. ev.stopPropagation();
  2002. posStart = {
  2003. x: ev.x,
  2004. y: ev.y,
  2005. };
  2006. timeout = setTimeout(
  2007. () => handler(ev),
  2008. (_d = options == null ? void 0 : options.delay) != null
  2009. ? _d
  2010. : DEFAULT_DELAY,
  2011. );
  2012. }
  2013. function onMove(ev) {
  2014. var _a2, _b2, _c, _d;
  2015. if (
  2016. ((_a2 = options == null ? void 0 : options.modifiers) == null
  2017. ? void 0
  2018. : _a2.self) &&
  2019. ev.target !== elementRef.value
  2020. )
  2021. return;
  2022. if (
  2023. !posStart ||
  2024. (options == null ? void 0 : options.distanceThreshold) === false
  2025. )
  2026. return;
  2027. if (
  2028. (_b2 = options == null ? void 0 : options.modifiers) == null
  2029. ? void 0
  2030. : _b2.prevent
  2031. )
  2032. ev.preventDefault();
  2033. if (
  2034. (_c = options == null ? void 0 : options.modifiers) == null
  2035. ? void 0
  2036. : _c.stop
  2037. )
  2038. ev.stopPropagation();
  2039. const dx = ev.x - posStart.x;
  2040. const dy = ev.y - posStart.y;
  2041. const distance = Math.sqrt(dx * dx + dy * dy);
  2042. if (
  2043. distance >=
  2044. ((_d = options == null ? void 0 : options.distanceThreshold) != null
  2045. ? _d
  2046. : DEFAULT_THRESHOLD)
  2047. )
  2048. clear();
  2049. }
  2050. const listenerOptions = {
  2051. capture:
  2052. (_a = options == null ? void 0 : options.modifiers) == null
  2053. ? void 0
  2054. : _a.capture,
  2055. once:
  2056. (_b = options == null ? void 0 : options.modifiers) == null
  2057. ? void 0
  2058. : _b.once,
  2059. };
  2060. const cleanup = [
  2061. useEventListener(elementRef, 'pointerdown', onDown, listenerOptions),
  2062. useEventListener(elementRef, 'pointermove', onMove, listenerOptions),
  2063. useEventListener(
  2064. elementRef,
  2065. ['pointerup', 'pointerleave'],
  2066. clear,
  2067. listenerOptions,
  2068. ),
  2069. ];
  2070. const stop = () => cleanup.forEach((fn) => fn());
  2071. return stop;
  2072. }
  2073. function isFocusedElementEditable() {
  2074. const { activeElement, body } = document;
  2075. if (!activeElement) return false;
  2076. if (activeElement === body) return false;
  2077. switch (activeElement.tagName) {
  2078. case 'INPUT':
  2079. case 'TEXTAREA':
  2080. return true;
  2081. }
  2082. return activeElement.hasAttribute('contenteditable');
  2083. }
  2084. function isTypedCharValid({ keyCode, metaKey, ctrlKey, altKey }) {
  2085. if (metaKey || ctrlKey || altKey) return false;
  2086. if (keyCode >= 48 && keyCode <= 57) return true;
  2087. if (keyCode >= 65 && keyCode <= 90) return true;
  2088. if (keyCode >= 97 && keyCode <= 122) return true;
  2089. return false;
  2090. }
  2091. function onStartTyping(callback, options = {}) {
  2092. const { document: document2 = defaultDocument } = options;
  2093. const keydown = (event) => {
  2094. !isFocusedElementEditable() && isTypedCharValid(event) && callback(event);
  2095. };
  2096. if (document2)
  2097. useEventListener(document2, 'keydown', keydown, { passive: true });
  2098. }
  2099. function templateRef(key, initialValue = null) {
  2100. const instance = getCurrentInstance();
  2101. let _trigger = () => {};
  2102. const element = customRef((track, trigger) => {
  2103. _trigger = trigger;
  2104. return {
  2105. get() {
  2106. var _a, _b;
  2107. track();
  2108. return (_b =
  2109. (_a = instance == null ? void 0 : instance.proxy) == null
  2110. ? void 0
  2111. : _a.$refs[key]) != null
  2112. ? _b
  2113. : initialValue;
  2114. },
  2115. set() {},
  2116. };
  2117. });
  2118. tryOnMounted(_trigger);
  2119. onUpdated(_trigger);
  2120. return element;
  2121. }
  2122. function useActiveElement(options = {}) {
  2123. var _a;
  2124. const { window: window2 = defaultWindow, deep = true } = options;
  2125. const document2 =
  2126. (_a = options.document) != null
  2127. ? _a
  2128. : window2 == null
  2129. ? void 0
  2130. : window2.document;
  2131. const getDeepActiveElement = () => {
  2132. var _a2;
  2133. let element = document2 == null ? void 0 : document2.activeElement;
  2134. if (deep) {
  2135. while (element == null ? void 0 : element.shadowRoot)
  2136. element =
  2137. (_a2 = element == null ? void 0 : element.shadowRoot) == null
  2138. ? void 0
  2139. : _a2.activeElement;
  2140. }
  2141. return element;
  2142. };
  2143. const activeElement = ref();
  2144. const trigger = () => {
  2145. activeElement.value = getDeepActiveElement();
  2146. };
  2147. if (window2) {
  2148. useEventListener(
  2149. window2,
  2150. 'blur',
  2151. (event) => {
  2152. if (event.relatedTarget !== null) return;
  2153. trigger();
  2154. },
  2155. true,
  2156. );
  2157. useEventListener(window2, 'focus', trigger, true);
  2158. }
  2159. trigger();
  2160. return activeElement;
  2161. }
  2162. function useMounted() {
  2163. const isMounted = ref(false);
  2164. const instance = getCurrentInstance();
  2165. if (instance) {
  2166. onMounted(
  2167. () => {
  2168. isMounted.value = true;
  2169. },
  2170. isVue2 ? null : instance,
  2171. );
  2172. }
  2173. return isMounted;
  2174. }
  2175. function useSupported(callback) {
  2176. const isMounted = useMounted();
  2177. return computed(() => {
  2178. isMounted.value;
  2179. return Boolean(callback());
  2180. });
  2181. }
  2182. function useRafFn(fn, options = {}) {
  2183. const {
  2184. immediate = true,
  2185. fpsLimit = void 0,
  2186. window: window2 = defaultWindow,
  2187. } = options;
  2188. const isActive = ref(false);
  2189. const intervalLimit = fpsLimit ? 1e3 / fpsLimit : null;
  2190. let previousFrameTimestamp = 0;
  2191. let rafId = null;
  2192. function loop(timestamp2) {
  2193. if (!isActive.value || !window2) return;
  2194. if (!previousFrameTimestamp) previousFrameTimestamp = timestamp2;
  2195. const delta = timestamp2 - previousFrameTimestamp;
  2196. if (intervalLimit && delta < intervalLimit) {
  2197. rafId = window2.requestAnimationFrame(loop);
  2198. return;
  2199. }
  2200. previousFrameTimestamp = timestamp2;
  2201. fn({ delta, timestamp: timestamp2 });
  2202. rafId = window2.requestAnimationFrame(loop);
  2203. }
  2204. function resume() {
  2205. if (!isActive.value && window2) {
  2206. isActive.value = true;
  2207. previousFrameTimestamp = 0;
  2208. rafId = window2.requestAnimationFrame(loop);
  2209. }
  2210. }
  2211. function pause() {
  2212. isActive.value = false;
  2213. if (rafId != null && window2) {
  2214. window2.cancelAnimationFrame(rafId);
  2215. rafId = null;
  2216. }
  2217. }
  2218. if (immediate) resume();
  2219. tryOnScopeDispose(pause);
  2220. return {
  2221. isActive: readonly(isActive),
  2222. pause,
  2223. resume,
  2224. };
  2225. }
  2226. function useAnimate(target, keyframes, options) {
  2227. let config;
  2228. let animateOptions;
  2229. if (isObject(options)) {
  2230. config = options;
  2231. animateOptions = objectOmit(options, [
  2232. 'window',
  2233. 'immediate',
  2234. 'commitStyles',
  2235. 'persist',
  2236. 'onReady',
  2237. 'onError',
  2238. ]);
  2239. } else {
  2240. config = { duration: options };
  2241. animateOptions = options;
  2242. }
  2243. const {
  2244. window: window2 = defaultWindow,
  2245. immediate = true,
  2246. commitStyles,
  2247. persist,
  2248. playbackRate: _playbackRate = 1,
  2249. onReady,
  2250. onError = (e) => {
  2251. console.error(e);
  2252. },
  2253. } = config;
  2254. const isSupported = useSupported(
  2255. () => window2 && HTMLElement && 'animate' in HTMLElement.prototype,
  2256. );
  2257. const animate = shallowRef(void 0);
  2258. const store = shallowReactive({
  2259. startTime: null,
  2260. currentTime: null,
  2261. timeline: null,
  2262. playbackRate: _playbackRate,
  2263. pending: false,
  2264. playState: immediate ? 'idle' : 'paused',
  2265. replaceState: 'active',
  2266. });
  2267. const pending = computed(() => store.pending);
  2268. const playState = computed(() => store.playState);
  2269. const replaceState = computed(() => store.replaceState);
  2270. const startTime = computed({
  2271. get() {
  2272. return store.startTime;
  2273. },
  2274. set(value) {
  2275. store.startTime = value;
  2276. if (animate.value) animate.value.startTime = value;
  2277. },
  2278. });
  2279. const currentTime = computed({
  2280. get() {
  2281. return store.currentTime;
  2282. },
  2283. set(value) {
  2284. store.currentTime = value;
  2285. if (animate.value) {
  2286. animate.value.currentTime = value;
  2287. syncResume();
  2288. }
  2289. },
  2290. });
  2291. const timeline = computed({
  2292. get() {
  2293. return store.timeline;
  2294. },
  2295. set(value) {
  2296. store.timeline = value;
  2297. if (animate.value) animate.value.timeline = value;
  2298. },
  2299. });
  2300. const playbackRate = computed({
  2301. get() {
  2302. return store.playbackRate;
  2303. },
  2304. set(value) {
  2305. store.playbackRate = value;
  2306. if (animate.value) animate.value.playbackRate = value;
  2307. },
  2308. });
  2309. const play = () => {
  2310. if (animate.value) {
  2311. try {
  2312. animate.value.play();
  2313. syncResume();
  2314. } catch (e) {
  2315. syncPause();
  2316. onError(e);
  2317. }
  2318. } else {
  2319. update();
  2320. }
  2321. };
  2322. const pause = () => {
  2323. var _a;
  2324. try {
  2325. (_a = animate.value) == null ? void 0 : _a.pause();
  2326. syncPause();
  2327. } catch (e) {
  2328. onError(e);
  2329. }
  2330. };
  2331. const reverse = () => {
  2332. var _a;
  2333. !animate.value && update();
  2334. try {
  2335. (_a = animate.value) == null ? void 0 : _a.reverse();
  2336. syncResume();
  2337. } catch (e) {
  2338. syncPause();
  2339. onError(e);
  2340. }
  2341. };
  2342. const finish = () => {
  2343. var _a;
  2344. try {
  2345. (_a = animate.value) == null ? void 0 : _a.finish();
  2346. syncPause();
  2347. } catch (e) {
  2348. onError(e);
  2349. }
  2350. };
  2351. const cancel = () => {
  2352. var _a;
  2353. try {
  2354. (_a = animate.value) == null ? void 0 : _a.cancel();
  2355. syncPause();
  2356. } catch (e) {
  2357. onError(e);
  2358. }
  2359. };
  2360. watch(
  2361. () => unrefElement(target),
  2362. (el) => {
  2363. el && update();
  2364. },
  2365. );
  2366. watch(
  2367. () => keyframes,
  2368. (value) => {
  2369. !animate.value && update();
  2370. if (!unrefElement(target) && animate.value) {
  2371. animate.value.effect = new KeyframeEffect(
  2372. unrefElement(target),
  2373. toValue(value),
  2374. animateOptions,
  2375. );
  2376. }
  2377. },
  2378. { deep: true },
  2379. );
  2380. tryOnMounted(() => {
  2381. nextTick(() => update(true));
  2382. });
  2383. tryOnScopeDispose(cancel);
  2384. function update(init) {
  2385. const el = unrefElement(target);
  2386. if (!isSupported.value || !el) return;
  2387. if (!animate.value)
  2388. animate.value = el.animate(toValue(keyframes), animateOptions);
  2389. if (commitStyles) animate.value.commitStyles();
  2390. if (persist) animate.value.persist();
  2391. if (_playbackRate !== 1) animate.value.playbackRate = _playbackRate;
  2392. if (init && !immediate) animate.value.pause();
  2393. else syncResume();
  2394. onReady == null ? void 0 : onReady(animate.value);
  2395. }
  2396. useEventListener(animate, ['cancel', 'finish', 'remove'], syncPause);
  2397. const { resume: resumeRef, pause: pauseRef } = useRafFn(
  2398. () => {
  2399. if (!animate.value) return;
  2400. store.pending = animate.value.pending;
  2401. store.playState = animate.value.playState;
  2402. store.replaceState = animate.value.replaceState;
  2403. store.startTime = animate.value.startTime;
  2404. store.currentTime = animate.value.currentTime;
  2405. store.timeline = animate.value.timeline;
  2406. store.playbackRate = animate.value.playbackRate;
  2407. },
  2408. { immediate: false },
  2409. );
  2410. function syncResume() {
  2411. if (isSupported.value) resumeRef();
  2412. }
  2413. function syncPause() {
  2414. if (isSupported.value && window2) window2.requestAnimationFrame(pauseRef);
  2415. }
  2416. return {
  2417. isSupported,
  2418. animate,
  2419. // actions
  2420. play,
  2421. pause,
  2422. reverse,
  2423. finish,
  2424. cancel,
  2425. // state
  2426. pending,
  2427. playState,
  2428. replaceState,
  2429. startTime,
  2430. currentTime,
  2431. timeline,
  2432. playbackRate,
  2433. };
  2434. }
  2435. function useAsyncQueue(tasks, options) {
  2436. const {
  2437. interrupt = true,
  2438. onError = noop,
  2439. onFinished = noop,
  2440. signal,
  2441. } = options || {};
  2442. const promiseState = {
  2443. aborted: 'aborted',
  2444. fulfilled: 'fulfilled',
  2445. pending: 'pending',
  2446. rejected: 'rejected',
  2447. };
  2448. const initialResult = Array.from(
  2449. Array.from({ length: tasks.length }),
  2450. () => ({ state: promiseState.pending, data: null }),
  2451. );
  2452. const result = reactive(initialResult);
  2453. const activeIndex = ref(-1);
  2454. if (!tasks || tasks.length === 0) {
  2455. onFinished();
  2456. return {
  2457. activeIndex,
  2458. result,
  2459. };
  2460. }
  2461. function updateResult(state, res) {
  2462. activeIndex.value++;
  2463. result[activeIndex.value].data = res;
  2464. result[activeIndex.value].state = state;
  2465. }
  2466. tasks.reduce((prev, curr) => {
  2467. return prev
  2468. .then((prevRes) => {
  2469. var _a;
  2470. if (signal == null ? void 0 : signal.aborted) {
  2471. updateResult(promiseState.aborted, new Error('aborted'));
  2472. return;
  2473. }
  2474. if (
  2475. ((_a = result[activeIndex.value]) == null ? void 0 : _a.state) ===
  2476. promiseState.rejected &&
  2477. interrupt
  2478. ) {
  2479. onFinished();
  2480. return;
  2481. }
  2482. const done = curr(prevRes).then((currentRes) => {
  2483. updateResult(promiseState.fulfilled, currentRes);
  2484. activeIndex.value === tasks.length - 1 && onFinished();
  2485. return currentRes;
  2486. });
  2487. if (!signal) return done;
  2488. return Promise.race([done, whenAborted(signal)]);
  2489. })
  2490. .catch((e) => {
  2491. if (signal == null ? void 0 : signal.aborted) {
  2492. updateResult(promiseState.aborted, e);
  2493. return e;
  2494. }
  2495. updateResult(promiseState.rejected, e);
  2496. onError();
  2497. return e;
  2498. });
  2499. }, Promise.resolve());
  2500. return {
  2501. activeIndex,
  2502. result,
  2503. };
  2504. }
  2505. function whenAborted(signal) {
  2506. return new Promise((resolve, reject) => {
  2507. const error = new Error('aborted');
  2508. if (signal.aborted) reject(error);
  2509. else signal.addEventListener('abort', () => reject(error), { once: true });
  2510. });
  2511. }
  2512. function useAsyncState(promise, initialState, options) {
  2513. const {
  2514. immediate = true,
  2515. delay = 0,
  2516. onError = noop,
  2517. onSuccess = noop,
  2518. resetOnExecute = true,
  2519. shallow = true,
  2520. throwError,
  2521. } = options != null ? options : {};
  2522. const state = shallow ? shallowRef(initialState) : ref(initialState);
  2523. const isReady = ref(false);
  2524. const isLoading = ref(false);
  2525. const error = shallowRef(void 0);
  2526. async function execute(delay2 = 0, ...args) {
  2527. if (resetOnExecute) state.value = initialState;
  2528. error.value = void 0;
  2529. isReady.value = false;
  2530. isLoading.value = true;
  2531. if (delay2 > 0) await promiseTimeout(delay2);
  2532. const _promise = typeof promise === 'function' ? promise(...args) : promise;
  2533. try {
  2534. const data = await _promise;
  2535. state.value = data;
  2536. isReady.value = true;
  2537. onSuccess(data);
  2538. } catch (e) {
  2539. error.value = e;
  2540. onError(e);
  2541. if (throwError) throw e;
  2542. } finally {
  2543. isLoading.value = false;
  2544. }
  2545. return state.value;
  2546. }
  2547. if (immediate) execute(delay);
  2548. const shell = {
  2549. state,
  2550. isReady,
  2551. isLoading,
  2552. error,
  2553. execute,
  2554. };
  2555. function waitUntilIsLoaded() {
  2556. return new Promise((resolve, reject) => {
  2557. until(isLoading)
  2558. .toBe(false)
  2559. .then(() => resolve(shell))
  2560. .catch(reject);
  2561. });
  2562. }
  2563. return {
  2564. ...shell,
  2565. then(onFulfilled, onRejected) {
  2566. return waitUntilIsLoaded().then(onFulfilled, onRejected);
  2567. },
  2568. };
  2569. }
  2570. var defaults = {
  2571. array: (v) => JSON.stringify(v),
  2572. object: (v) => JSON.stringify(v),
  2573. set: (v) => JSON.stringify(Array.from(v)),
  2574. map: (v) => JSON.stringify(Object.fromEntries(v)),
  2575. null: () => '',
  2576. };
  2577. function getDefaultSerialization(target) {
  2578. if (!target) return defaults.null;
  2579. if (target instanceof Map) return defaults.map;
  2580. else if (target instanceof Set) return defaults.set;
  2581. else if (Array.isArray(target)) return defaults.array;
  2582. else return defaults.object;
  2583. }
  2584. function useBase64(target, options) {
  2585. const base64 = ref('');
  2586. const promise = ref();
  2587. function execute() {
  2588. if (!isClient) return;
  2589. promise.value = new Promise((resolve, reject) => {
  2590. try {
  2591. const _target = toValue(target);
  2592. if (_target == null) {
  2593. resolve('');
  2594. } else if (typeof _target === 'string') {
  2595. resolve(blobToBase64(new Blob([_target], { type: 'text/plain' })));
  2596. } else if (_target instanceof Blob) {
  2597. resolve(blobToBase64(_target));
  2598. } else if (_target instanceof ArrayBuffer) {
  2599. resolve(window.btoa(String.fromCharCode(...new Uint8Array(_target))));
  2600. } else if (_target instanceof HTMLCanvasElement) {
  2601. resolve(
  2602. _target.toDataURL(
  2603. options == null ? void 0 : options.type,
  2604. options == null ? void 0 : options.quality,
  2605. ),
  2606. );
  2607. } else if (_target instanceof HTMLImageElement) {
  2608. const img = _target.cloneNode(false);
  2609. img.crossOrigin = 'Anonymous';
  2610. imgLoaded(img)
  2611. .then(() => {
  2612. const canvas = document.createElement('canvas');
  2613. const ctx = canvas.getContext('2d');
  2614. canvas.width = img.width;
  2615. canvas.height = img.height;
  2616. ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
  2617. resolve(
  2618. canvas.toDataURL(
  2619. options == null ? void 0 : options.type,
  2620. options == null ? void 0 : options.quality,
  2621. ),
  2622. );
  2623. })
  2624. .catch(reject);
  2625. } else if (typeof _target === 'object') {
  2626. const _serializeFn =
  2627. (options == null ? void 0 : options.serializer) ||
  2628. getDefaultSerialization(_target);
  2629. const serialized = _serializeFn(_target);
  2630. return resolve(
  2631. blobToBase64(new Blob([serialized], { type: 'application/json' })),
  2632. );
  2633. } else {
  2634. reject(new Error('target is unsupported types'));
  2635. }
  2636. } catch (error) {
  2637. reject(error);
  2638. }
  2639. });
  2640. promise.value.then((res) => (base64.value = res));
  2641. return promise.value;
  2642. }
  2643. if (isRef(target) || typeof target === 'function')
  2644. watch(target, execute, { immediate: true });
  2645. else execute();
  2646. return {
  2647. base64,
  2648. promise,
  2649. execute,
  2650. };
  2651. }
  2652. function imgLoaded(img) {
  2653. return new Promise((resolve, reject) => {
  2654. if (!img.complete) {
  2655. img.onload = () => {
  2656. resolve();
  2657. };
  2658. img.onerror = reject;
  2659. } else {
  2660. resolve();
  2661. }
  2662. });
  2663. }
  2664. function blobToBase64(blob) {
  2665. return new Promise((resolve, reject) => {
  2666. const fr = new FileReader();
  2667. fr.onload = (e) => {
  2668. resolve(e.target.result);
  2669. };
  2670. fr.onerror = reject;
  2671. fr.readAsDataURL(blob);
  2672. });
  2673. }
  2674. function useBattery(options = {}) {
  2675. const { navigator = defaultNavigator } = options;
  2676. const events2 = [
  2677. 'chargingchange',
  2678. 'chargingtimechange',
  2679. 'dischargingtimechange',
  2680. 'levelchange',
  2681. ];
  2682. const isSupported = useSupported(
  2683. () =>
  2684. navigator &&
  2685. 'getBattery' in navigator &&
  2686. typeof navigator.getBattery === 'function',
  2687. );
  2688. const charging = ref(false);
  2689. const chargingTime = ref(0);
  2690. const dischargingTime = ref(0);
  2691. const level = ref(1);
  2692. let battery;
  2693. function updateBatteryInfo() {
  2694. charging.value = this.charging;
  2695. chargingTime.value = this.chargingTime || 0;
  2696. dischargingTime.value = this.dischargingTime || 0;
  2697. level.value = this.level;
  2698. }
  2699. if (isSupported.value) {
  2700. navigator.getBattery().then((_battery) => {
  2701. battery = _battery;
  2702. updateBatteryInfo.call(battery);
  2703. useEventListener(battery, events2, updateBatteryInfo, { passive: true });
  2704. });
  2705. }
  2706. return {
  2707. isSupported,
  2708. charging,
  2709. chargingTime,
  2710. dischargingTime,
  2711. level,
  2712. };
  2713. }
  2714. function useBluetooth(options) {
  2715. let { acceptAllDevices = false } = options || {};
  2716. const {
  2717. filters = void 0,
  2718. optionalServices = void 0,
  2719. navigator = defaultNavigator,
  2720. } = options || {};
  2721. const isSupported = useSupported(() => navigator && 'bluetooth' in navigator);
  2722. const device = shallowRef(void 0);
  2723. const error = shallowRef(null);
  2724. watch(device, () => {
  2725. connectToBluetoothGATTServer();
  2726. });
  2727. async function requestDevice() {
  2728. if (!isSupported.value) return;
  2729. error.value = null;
  2730. if (filters && filters.length > 0) acceptAllDevices = false;
  2731. try {
  2732. device.value = await (navigator == null
  2733. ? void 0
  2734. : navigator.bluetooth.requestDevice({
  2735. acceptAllDevices,
  2736. filters,
  2737. optionalServices,
  2738. }));
  2739. } catch (err) {
  2740. error.value = err;
  2741. }
  2742. }
  2743. const server = ref();
  2744. const isConnected = computed(() => {
  2745. var _a;
  2746. return ((_a = server.value) == null ? void 0 : _a.connected) || false;
  2747. });
  2748. async function connectToBluetoothGATTServer() {
  2749. error.value = null;
  2750. if (device.value && device.value.gatt) {
  2751. device.value.addEventListener('gattserverdisconnected', () => {});
  2752. try {
  2753. server.value = await device.value.gatt.connect();
  2754. } catch (err) {
  2755. error.value = err;
  2756. }
  2757. }
  2758. }
  2759. tryOnMounted(() => {
  2760. var _a;
  2761. if (device.value) (_a = device.value.gatt) == null ? void 0 : _a.connect();
  2762. });
  2763. tryOnScopeDispose(() => {
  2764. var _a;
  2765. if (device.value)
  2766. (_a = device.value.gatt) == null ? void 0 : _a.disconnect();
  2767. });
  2768. return {
  2769. isSupported,
  2770. isConnected,
  2771. // Device:
  2772. device,
  2773. requestDevice,
  2774. // Server:
  2775. server,
  2776. // Errors:
  2777. error,
  2778. };
  2779. }
  2780. function useMediaQuery(query, options = {}) {
  2781. const { window: window2 = defaultWindow } = options;
  2782. const isSupported = useSupported(
  2783. () =>
  2784. window2 &&
  2785. 'matchMedia' in window2 &&
  2786. typeof window2.matchMedia === 'function',
  2787. );
  2788. let mediaQuery;
  2789. const matches = ref(false);
  2790. const handler = (event) => {
  2791. matches.value = event.matches;
  2792. };
  2793. const cleanup = () => {
  2794. if (!mediaQuery) return;
  2795. if ('removeEventListener' in mediaQuery)
  2796. mediaQuery.removeEventListener('change', handler);
  2797. else mediaQuery.removeListener(handler);
  2798. };
  2799. const stopWatch = watchEffect(() => {
  2800. if (!isSupported.value) return;
  2801. cleanup();
  2802. mediaQuery = window2.matchMedia(toValue(query));
  2803. if ('addEventListener' in mediaQuery)
  2804. mediaQuery.addEventListener('change', handler);
  2805. else mediaQuery.addListener(handler);
  2806. matches.value = mediaQuery.matches;
  2807. });
  2808. tryOnScopeDispose(() => {
  2809. stopWatch();
  2810. cleanup();
  2811. mediaQuery = void 0;
  2812. });
  2813. return matches;
  2814. }
  2815. var breakpointsTailwind = {
  2816. sm: 640,
  2817. md: 768,
  2818. lg: 1024,
  2819. xl: 1280,
  2820. '2xl': 1536,
  2821. };
  2822. var breakpointsBootstrapV5 = {
  2823. xs: 0,
  2824. sm: 576,
  2825. md: 768,
  2826. lg: 992,
  2827. xl: 1200,
  2828. xxl: 1400,
  2829. };
  2830. var breakpointsVuetifyV2 = {
  2831. xs: 0,
  2832. sm: 600,
  2833. md: 960,
  2834. lg: 1264,
  2835. xl: 1904,
  2836. };
  2837. var breakpointsVuetifyV3 = {
  2838. xs: 0,
  2839. sm: 600,
  2840. md: 960,
  2841. lg: 1280,
  2842. xl: 1920,
  2843. xxl: 2560,
  2844. };
  2845. var breakpointsVuetify = breakpointsVuetifyV2;
  2846. var breakpointsAntDesign = {
  2847. xs: 480,
  2848. sm: 576,
  2849. md: 768,
  2850. lg: 992,
  2851. xl: 1200,
  2852. xxl: 1600,
  2853. };
  2854. var breakpointsQuasar = {
  2855. xs: 0,
  2856. sm: 600,
  2857. md: 1024,
  2858. lg: 1440,
  2859. xl: 1920,
  2860. };
  2861. var breakpointsSematic = {
  2862. mobileS: 320,
  2863. mobileM: 375,
  2864. mobileL: 425,
  2865. tablet: 768,
  2866. laptop: 1024,
  2867. laptopL: 1440,
  2868. desktop4K: 2560,
  2869. };
  2870. var breakpointsMasterCss = {
  2871. '3xs': 360,
  2872. '2xs': 480,
  2873. xs: 600,
  2874. sm: 768,
  2875. md: 1024,
  2876. lg: 1280,
  2877. xl: 1440,
  2878. '2xl': 1600,
  2879. '3xl': 1920,
  2880. '4xl': 2560,
  2881. };
  2882. var breakpointsPrimeFlex = {
  2883. sm: 576,
  2884. md: 768,
  2885. lg: 992,
  2886. xl: 1200,
  2887. };
  2888. function useBreakpoints(breakpoints, options = {}) {
  2889. function getValue2(k, delta) {
  2890. let v = toValue(breakpoints[toValue(k)]);
  2891. if (delta != null) v = increaseWithUnit(v, delta);
  2892. if (typeof v === 'number') v = `${v}px`;
  2893. return v;
  2894. }
  2895. const { window: window2 = defaultWindow, strategy = 'min-width' } = options;
  2896. function match(query) {
  2897. if (!window2) return false;
  2898. return window2.matchMedia(query).matches;
  2899. }
  2900. const greaterOrEqual = (k) => {
  2901. return useMediaQuery(() => `(min-width: ${getValue2(k)})`, options);
  2902. };
  2903. const smallerOrEqual = (k) => {
  2904. return useMediaQuery(() => `(max-width: ${getValue2(k)})`, options);
  2905. };
  2906. const shortcutMethods = Object.keys(breakpoints).reduce((shortcuts, k) => {
  2907. Object.defineProperty(shortcuts, k, {
  2908. get: () =>
  2909. strategy === 'min-width' ? greaterOrEqual(k) : smallerOrEqual(k),
  2910. enumerable: true,
  2911. configurable: true,
  2912. });
  2913. return shortcuts;
  2914. }, {});
  2915. function current() {
  2916. const points = Object.keys(breakpoints).map((i) => [i, greaterOrEqual(i)]);
  2917. return computed(() => points.filter(([, v]) => v.value).map(([k]) => k));
  2918. }
  2919. return Object.assign(shortcutMethods, {
  2920. greaterOrEqual,
  2921. smallerOrEqual,
  2922. greater(k) {
  2923. return useMediaQuery(() => `(min-width: ${getValue2(k, 0.1)})`, options);
  2924. },
  2925. smaller(k) {
  2926. return useMediaQuery(() => `(max-width: ${getValue2(k, -0.1)})`, options);
  2927. },
  2928. between(a, b) {
  2929. return useMediaQuery(
  2930. () =>
  2931. `(min-width: ${getValue2(a)}) and (max-width: ${getValue2(b, -0.1)})`,
  2932. options,
  2933. );
  2934. },
  2935. isGreater(k) {
  2936. return match(`(min-width: ${getValue2(k, 0.1)})`);
  2937. },
  2938. isGreaterOrEqual(k) {
  2939. return match(`(min-width: ${getValue2(k)})`);
  2940. },
  2941. isSmaller(k) {
  2942. return match(`(max-width: ${getValue2(k, -0.1)})`);
  2943. },
  2944. isSmallerOrEqual(k) {
  2945. return match(`(max-width: ${getValue2(k)})`);
  2946. },
  2947. isInBetween(a, b) {
  2948. return match(
  2949. `(min-width: ${getValue2(a)}) and (max-width: ${getValue2(b, -0.1)})`,
  2950. );
  2951. },
  2952. current,
  2953. active() {
  2954. const bps = current();
  2955. return computed(() => (bps.value.length === 0 ? '' : bps.value.at(-1)));
  2956. },
  2957. });
  2958. }
  2959. function useBroadcastChannel(options) {
  2960. const { name, window: window2 = defaultWindow } = options;
  2961. const isSupported = useSupported(
  2962. () => window2 && 'BroadcastChannel' in window2,
  2963. );
  2964. const isClosed = ref(false);
  2965. const channel = ref();
  2966. const data = ref();
  2967. const error = shallowRef(null);
  2968. const post = (data2) => {
  2969. if (channel.value) channel.value.postMessage(data2);
  2970. };
  2971. const close = () => {
  2972. if (channel.value) channel.value.close();
  2973. isClosed.value = true;
  2974. };
  2975. if (isSupported.value) {
  2976. tryOnMounted(() => {
  2977. error.value = null;
  2978. channel.value = new BroadcastChannel(name);
  2979. channel.value.addEventListener(
  2980. 'message',
  2981. (e) => {
  2982. data.value = e.data;
  2983. },
  2984. { passive: true },
  2985. );
  2986. channel.value.addEventListener(
  2987. 'messageerror',
  2988. (e) => {
  2989. error.value = e;
  2990. },
  2991. { passive: true },
  2992. );
  2993. channel.value.addEventListener('close', () => {
  2994. isClosed.value = true;
  2995. });
  2996. });
  2997. }
  2998. tryOnScopeDispose(() => {
  2999. close();
  3000. });
  3001. return {
  3002. isSupported,
  3003. channel,
  3004. data,
  3005. post,
  3006. close,
  3007. error,
  3008. isClosed,
  3009. };
  3010. }
  3011. var WRITABLE_PROPERTIES = [
  3012. 'hash',
  3013. 'host',
  3014. 'hostname',
  3015. 'href',
  3016. 'pathname',
  3017. 'port',
  3018. 'protocol',
  3019. 'search',
  3020. ];
  3021. function useBrowserLocation(options = {}) {
  3022. const { window: window2 = defaultWindow } = options;
  3023. const refs = Object.fromEntries(
  3024. WRITABLE_PROPERTIES.map((key) => [key, ref()]),
  3025. );
  3026. for (const [key, ref2] of objectEntries(refs)) {
  3027. watch(ref2, (value) => {
  3028. if (
  3029. !(window2 == null ? void 0 : window2.location) ||
  3030. window2.location[key] === value
  3031. )
  3032. return;
  3033. window2.location[key] = value;
  3034. });
  3035. }
  3036. const buildState = (trigger) => {
  3037. var _a;
  3038. const { state: state2, length } =
  3039. (window2 == null ? void 0 : window2.history) || {};
  3040. const { origin } = (window2 == null ? void 0 : window2.location) || {};
  3041. for (const key of WRITABLE_PROPERTIES)
  3042. refs[key].value =
  3043. (_a = window2 == null ? void 0 : window2.location) == null
  3044. ? void 0
  3045. : _a[key];
  3046. return reactive({
  3047. trigger,
  3048. state: state2,
  3049. length,
  3050. origin,
  3051. ...refs,
  3052. });
  3053. };
  3054. const state = ref(buildState('load'));
  3055. if (window2) {
  3056. useEventListener(
  3057. window2,
  3058. 'popstate',
  3059. () => (state.value = buildState('popstate')),
  3060. { passive: true },
  3061. );
  3062. useEventListener(
  3063. window2,
  3064. 'hashchange',
  3065. () => (state.value = buildState('hashchange')),
  3066. { passive: true },
  3067. );
  3068. }
  3069. return state;
  3070. }
  3071. function useCached(refValue, comparator = (a, b) => a === b, watchOptions) {
  3072. const cachedValue = ref(refValue.value);
  3073. watch(
  3074. () => refValue.value,
  3075. (value) => {
  3076. if (!comparator(value, cachedValue.value)) cachedValue.value = value;
  3077. },
  3078. watchOptions,
  3079. );
  3080. return cachedValue;
  3081. }
  3082. function usePermission(permissionDesc, options = {}) {
  3083. const { controls = false, navigator = defaultNavigator } = options;
  3084. const isSupported = useSupported(
  3085. () => navigator && 'permissions' in navigator,
  3086. );
  3087. let permissionStatus;
  3088. const desc =
  3089. typeof permissionDesc === 'string'
  3090. ? { name: permissionDesc }
  3091. : permissionDesc;
  3092. const state = ref();
  3093. const onChange = () => {
  3094. if (permissionStatus) state.value = permissionStatus.state;
  3095. };
  3096. const query = createSingletonPromise(async () => {
  3097. if (!isSupported.value) return;
  3098. if (!permissionStatus) {
  3099. try {
  3100. permissionStatus = await navigator.permissions.query(desc);
  3101. useEventListener(permissionStatus, 'change', onChange);
  3102. onChange();
  3103. } catch (e) {
  3104. state.value = 'prompt';
  3105. }
  3106. }
  3107. return permissionStatus;
  3108. });
  3109. query();
  3110. if (controls) {
  3111. return {
  3112. state,
  3113. isSupported,
  3114. query,
  3115. };
  3116. } else {
  3117. return state;
  3118. }
  3119. }
  3120. function useClipboard(options = {}) {
  3121. const {
  3122. navigator = defaultNavigator,
  3123. read = false,
  3124. source,
  3125. copiedDuring = 1500,
  3126. legacy = false,
  3127. } = options;
  3128. const isClipboardApiSupported = useSupported(
  3129. () => navigator && 'clipboard' in navigator,
  3130. );
  3131. const permissionRead = usePermission('clipboard-read');
  3132. const permissionWrite = usePermission('clipboard-write');
  3133. const isSupported = computed(() => isClipboardApiSupported.value || legacy);
  3134. const text = ref('');
  3135. const copied = ref(false);
  3136. const timeout = useTimeoutFn(() => (copied.value = false), copiedDuring);
  3137. function updateText() {
  3138. if (isClipboardApiSupported.value && isAllowed(permissionRead.value)) {
  3139. navigator.clipboard.readText().then((value) => {
  3140. text.value = value;
  3141. });
  3142. } else {
  3143. text.value = legacyRead();
  3144. }
  3145. }
  3146. if (isSupported.value && read) useEventListener(['copy', 'cut'], updateText);
  3147. async function copy(value = toValue(source)) {
  3148. if (isSupported.value && value != null) {
  3149. if (isClipboardApiSupported.value && isAllowed(permissionWrite.value))
  3150. await navigator.clipboard.writeText(value);
  3151. else legacyCopy(value);
  3152. text.value = value;
  3153. copied.value = true;
  3154. timeout.start();
  3155. }
  3156. }
  3157. function legacyCopy(value) {
  3158. const ta = document.createElement('textarea');
  3159. ta.value = value != null ? value : '';
  3160. ta.style.position = 'absolute';
  3161. ta.style.opacity = '0';
  3162. document.body.appendChild(ta);
  3163. ta.select();
  3164. document.execCommand('copy');
  3165. ta.remove();
  3166. }
  3167. function legacyRead() {
  3168. var _a, _b, _c;
  3169. return (_c =
  3170. (_b =
  3171. (_a = document == null ? void 0 : document.getSelection) == null
  3172. ? void 0
  3173. : _a.call(document)) == null
  3174. ? void 0
  3175. : _b.toString()) != null
  3176. ? _c
  3177. : '';
  3178. }
  3179. function isAllowed(status) {
  3180. return status === 'granted' || status === 'prompt';
  3181. }
  3182. return {
  3183. isSupported,
  3184. text,
  3185. copied,
  3186. copy,
  3187. };
  3188. }
  3189. function useClipboardItems(options = {}) {
  3190. const {
  3191. navigator = defaultNavigator,
  3192. read = false,
  3193. source,
  3194. copiedDuring = 1500,
  3195. } = options;
  3196. const isSupported = useSupported(() => navigator && 'clipboard' in navigator);
  3197. const content = ref([]);
  3198. const copied = ref(false);
  3199. const timeout = useTimeoutFn(() => (copied.value = false), copiedDuring);
  3200. function updateContent() {
  3201. if (isSupported.value) {
  3202. navigator.clipboard.read().then((items) => {
  3203. content.value = items;
  3204. });
  3205. }
  3206. }
  3207. if (isSupported.value && read)
  3208. useEventListener(['copy', 'cut'], updateContent);
  3209. async function copy(value = toValue(source)) {
  3210. if (isSupported.value && value != null) {
  3211. await navigator.clipboard.write(value);
  3212. content.value = value;
  3213. copied.value = true;
  3214. timeout.start();
  3215. }
  3216. }
  3217. return {
  3218. isSupported,
  3219. content,
  3220. copied,
  3221. copy,
  3222. };
  3223. }
  3224. function cloneFnJSON(source) {
  3225. return JSON.parse(JSON.stringify(source));
  3226. }
  3227. function useCloned(source, options = {}) {
  3228. const cloned = ref({});
  3229. const {
  3230. manual,
  3231. clone = cloneFnJSON,
  3232. // watch options
  3233. deep = true,
  3234. immediate = true,
  3235. } = options;
  3236. function sync() {
  3237. cloned.value = clone(toValue(source));
  3238. }
  3239. if (!manual && (isRef(source) || typeof source === 'function')) {
  3240. watch(source, sync, {
  3241. ...options,
  3242. deep,
  3243. immediate,
  3244. });
  3245. } else {
  3246. sync();
  3247. }
  3248. return { cloned, sync };
  3249. }
  3250. var _global =
  3251. typeof globalThis !== 'undefined'
  3252. ? globalThis
  3253. : typeof window !== 'undefined'
  3254. ? window
  3255. : typeof global !== 'undefined'
  3256. ? global
  3257. : typeof self !== 'undefined'
  3258. ? self
  3259. : {};
  3260. var globalKey = '__vueuse_ssr_handlers__';
  3261. var handlers = getHandlers();
  3262. function getHandlers() {
  3263. if (!(globalKey in _global)) _global[globalKey] = _global[globalKey] || {};
  3264. return _global[globalKey];
  3265. }
  3266. function getSSRHandler(key, fallback) {
  3267. return handlers[key] || fallback;
  3268. }
  3269. function setSSRHandler(key, fn) {
  3270. handlers[key] = fn;
  3271. }
  3272. function guessSerializerType(rawInit) {
  3273. return rawInit == null
  3274. ? 'any'
  3275. : rawInit instanceof Set
  3276. ? 'set'
  3277. : rawInit instanceof Map
  3278. ? 'map'
  3279. : rawInit instanceof Date
  3280. ? 'date'
  3281. : typeof rawInit === 'boolean'
  3282. ? 'boolean'
  3283. : typeof rawInit === 'string'
  3284. ? 'string'
  3285. : typeof rawInit === 'object'
  3286. ? 'object'
  3287. : !Number.isNaN(rawInit)
  3288. ? 'number'
  3289. : 'any';
  3290. }
  3291. var StorageSerializers = {
  3292. boolean: {
  3293. read: (v) => v === 'true',
  3294. write: (v) => String(v),
  3295. },
  3296. object: {
  3297. read: (v) => JSON.parse(v),
  3298. write: (v) => JSON.stringify(v),
  3299. },
  3300. number: {
  3301. read: (v) => Number.parseFloat(v),
  3302. write: (v) => String(v),
  3303. },
  3304. any: {
  3305. read: (v) => v,
  3306. write: (v) => String(v),
  3307. },
  3308. string: {
  3309. read: (v) => v,
  3310. write: (v) => String(v),
  3311. },
  3312. map: {
  3313. read: (v) => new Map(JSON.parse(v)),
  3314. write: (v) => JSON.stringify(Array.from(v.entries())),
  3315. },
  3316. set: {
  3317. read: (v) => new Set(JSON.parse(v)),
  3318. write: (v) => JSON.stringify(Array.from(v)),
  3319. },
  3320. date: {
  3321. read: (v) => new Date(v),
  3322. write: (v) => v.toISOString(),
  3323. },
  3324. };
  3325. var customStorageEventName = 'vueuse-storage';
  3326. function useStorage(key, defaults2, storage, options = {}) {
  3327. var _a;
  3328. const {
  3329. flush = 'pre',
  3330. deep = true,
  3331. listenToStorageChanges = true,
  3332. writeDefaults = true,
  3333. mergeDefaults = false,
  3334. shallow,
  3335. window: window2 = defaultWindow,
  3336. eventFilter,
  3337. onError = (e) => {
  3338. console.error(e);
  3339. },
  3340. initOnMounted,
  3341. } = options;
  3342. const data = (shallow ? shallowRef : ref)(
  3343. typeof defaults2 === 'function' ? defaults2() : defaults2,
  3344. );
  3345. if (!storage) {
  3346. try {
  3347. storage = getSSRHandler('getDefaultStorage', () => {
  3348. var _a2;
  3349. return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
  3350. })();
  3351. } catch (e) {
  3352. onError(e);
  3353. }
  3354. }
  3355. if (!storage) return data;
  3356. const rawInit = toValue(defaults2);
  3357. const type = guessSerializerType(rawInit);
  3358. const serializer =
  3359. (_a = options.serializer) != null ? _a : StorageSerializers[type];
  3360. const { pause: pauseWatch, resume: resumeWatch } = watchPausable(
  3361. data,
  3362. () => write(data.value),
  3363. { flush, deep, eventFilter },
  3364. );
  3365. if (window2 && listenToStorageChanges) {
  3366. tryOnMounted(() => {
  3367. useEventListener(window2, 'storage', update);
  3368. useEventListener(window2, customStorageEventName, updateFromCustomEvent);
  3369. if (initOnMounted) update();
  3370. });
  3371. }
  3372. if (!initOnMounted) update();
  3373. function dispatchWriteEvent(oldValue, newValue) {
  3374. if (window2) {
  3375. window2.dispatchEvent(
  3376. new CustomEvent(customStorageEventName, {
  3377. detail: {
  3378. key,
  3379. oldValue,
  3380. newValue,
  3381. storageArea: storage,
  3382. },
  3383. }),
  3384. );
  3385. }
  3386. }
  3387. function write(v) {
  3388. try {
  3389. const oldValue = storage.getItem(key);
  3390. if (v == null) {
  3391. dispatchWriteEvent(oldValue, null);
  3392. storage.removeItem(key);
  3393. } else {
  3394. const serialized = serializer.write(v);
  3395. if (oldValue !== serialized) {
  3396. storage.setItem(key, serialized);
  3397. dispatchWriteEvent(oldValue, serialized);
  3398. }
  3399. }
  3400. } catch (e) {
  3401. onError(e);
  3402. }
  3403. }
  3404. function read(event) {
  3405. const rawValue = event ? event.newValue : storage.getItem(key);
  3406. if (rawValue == null) {
  3407. if (writeDefaults && rawInit != null)
  3408. storage.setItem(key, serializer.write(rawInit));
  3409. return rawInit;
  3410. } else if (!event && mergeDefaults) {
  3411. const value = serializer.read(rawValue);
  3412. if (typeof mergeDefaults === 'function')
  3413. return mergeDefaults(value, rawInit);
  3414. else if (type === 'object' && !Array.isArray(value))
  3415. return { ...rawInit, ...value };
  3416. return value;
  3417. } else if (typeof rawValue !== 'string') {
  3418. return rawValue;
  3419. } else {
  3420. return serializer.read(rawValue);
  3421. }
  3422. }
  3423. function update(event) {
  3424. if (event && event.storageArea !== storage) return;
  3425. if (event && event.key == null) {
  3426. data.value = rawInit;
  3427. return;
  3428. }
  3429. if (event && event.key !== key) return;
  3430. pauseWatch();
  3431. try {
  3432. if (
  3433. (event == null ? void 0 : event.newValue) !==
  3434. serializer.write(data.value)
  3435. )
  3436. data.value = read(event);
  3437. } catch (e) {
  3438. onError(e);
  3439. } finally {
  3440. if (event) nextTick(resumeWatch);
  3441. else resumeWatch();
  3442. }
  3443. }
  3444. function updateFromCustomEvent(event) {
  3445. update(event.detail);
  3446. }
  3447. return data;
  3448. }
  3449. function usePreferredDark(options) {
  3450. return useMediaQuery('(prefers-color-scheme: dark)', options);
  3451. }
  3452. function useColorMode(options = {}) {
  3453. const {
  3454. selector = 'html',
  3455. attribute = 'class',
  3456. initialValue = 'auto',
  3457. window: window2 = defaultWindow,
  3458. storage,
  3459. storageKey = 'vueuse-color-scheme',
  3460. listenToStorageChanges = true,
  3461. storageRef,
  3462. emitAuto,
  3463. disableTransition = true,
  3464. } = options;
  3465. const modes = {
  3466. auto: '',
  3467. light: 'light',
  3468. dark: 'dark',
  3469. ...(options.modes || {}),
  3470. };
  3471. const preferredDark = usePreferredDark({ window: window2 });
  3472. const system = computed(() => (preferredDark.value ? 'dark' : 'light'));
  3473. const store =
  3474. storageRef ||
  3475. (storageKey == null
  3476. ? toRef2(initialValue)
  3477. : useStorage(storageKey, initialValue, storage, {
  3478. window: window2,
  3479. listenToStorageChanges,
  3480. }));
  3481. const state = computed(() =>
  3482. store.value === 'auto' ? system.value : store.value,
  3483. );
  3484. const updateHTMLAttrs = getSSRHandler(
  3485. 'updateHTMLAttrs',
  3486. (selector2, attribute2, value) => {
  3487. const el =
  3488. typeof selector2 === 'string'
  3489. ? window2 == null
  3490. ? void 0
  3491. : window2.document.querySelector(selector2)
  3492. : unrefElement(selector2);
  3493. if (!el) return;
  3494. let style;
  3495. if (disableTransition) {
  3496. style = window2.document.createElement('style');
  3497. const styleString =
  3498. '*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
  3499. style.appendChild(document.createTextNode(styleString));
  3500. window2.document.head.appendChild(style);
  3501. }
  3502. if (attribute2 === 'class') {
  3503. const current = value.split(/\s/g);
  3504. Object.values(modes)
  3505. .flatMap((i) => (i || '').split(/\s/g))
  3506. .filter(Boolean)
  3507. .forEach((v) => {
  3508. if (current.includes(v)) el.classList.add(v);
  3509. else el.classList.remove(v);
  3510. });
  3511. } else {
  3512. el.setAttribute(attribute2, value);
  3513. }
  3514. if (disableTransition) {
  3515. window2.getComputedStyle(style).opacity;
  3516. document.head.removeChild(style);
  3517. }
  3518. },
  3519. );
  3520. function defaultOnChanged(mode) {
  3521. var _a;
  3522. updateHTMLAttrs(
  3523. selector,
  3524. attribute,
  3525. (_a = modes[mode]) != null ? _a : mode,
  3526. );
  3527. }
  3528. function onChanged(mode) {
  3529. if (options.onChanged) options.onChanged(mode, defaultOnChanged);
  3530. else defaultOnChanged(mode);
  3531. }
  3532. watch(state, onChanged, { flush: 'post', immediate: true });
  3533. tryOnMounted(() => onChanged(state.value));
  3534. const auto = computed({
  3535. get() {
  3536. return emitAuto ? store.value : state.value;
  3537. },
  3538. set(v) {
  3539. store.value = v;
  3540. },
  3541. });
  3542. try {
  3543. return Object.assign(auto, { store, system, state });
  3544. } catch (e) {
  3545. return auto;
  3546. }
  3547. }
  3548. function useConfirmDialog(revealed = ref(false)) {
  3549. const confirmHook = createEventHook();
  3550. const cancelHook = createEventHook();
  3551. const revealHook = createEventHook();
  3552. let _resolve = noop;
  3553. const reveal = (data) => {
  3554. revealHook.trigger(data);
  3555. revealed.value = true;
  3556. return new Promise((resolve) => {
  3557. _resolve = resolve;
  3558. });
  3559. };
  3560. const confirm = (data) => {
  3561. revealed.value = false;
  3562. confirmHook.trigger(data);
  3563. _resolve({ data, isCanceled: false });
  3564. };
  3565. const cancel = (data) => {
  3566. revealed.value = false;
  3567. cancelHook.trigger(data);
  3568. _resolve({ data, isCanceled: true });
  3569. };
  3570. return {
  3571. isRevealed: computed(() => revealed.value),
  3572. reveal,
  3573. confirm,
  3574. cancel,
  3575. onReveal: revealHook.on,
  3576. onConfirm: confirmHook.on,
  3577. onCancel: cancelHook.on,
  3578. };
  3579. }
  3580. function useMutationObserver(target, callback, options = {}) {
  3581. const { window: window2 = defaultWindow, ...mutationOptions } = options;
  3582. let observer;
  3583. const isSupported = useSupported(
  3584. () => window2 && 'MutationObserver' in window2,
  3585. );
  3586. const cleanup = () => {
  3587. if (observer) {
  3588. observer.disconnect();
  3589. observer = void 0;
  3590. }
  3591. };
  3592. const targets = computed(() => {
  3593. const value = toValue(target);
  3594. const items = (Array.isArray(value) ? value : [value])
  3595. .map(unrefElement)
  3596. .filter(notNullish);
  3597. return new Set(items);
  3598. });
  3599. const stopWatch = watch(
  3600. () => targets.value,
  3601. (targets2) => {
  3602. cleanup();
  3603. if (isSupported.value && window2 && targets2.size) {
  3604. observer = new MutationObserver(callback);
  3605. targets2.forEach((el) => observer.observe(el, mutationOptions));
  3606. }
  3607. },
  3608. { immediate: true, flush: 'post' },
  3609. );
  3610. const takeRecords = () => {
  3611. return observer == null ? void 0 : observer.takeRecords();
  3612. };
  3613. const stop = () => {
  3614. cleanup();
  3615. stopWatch();
  3616. };
  3617. tryOnScopeDispose(stop);
  3618. return {
  3619. isSupported,
  3620. stop,
  3621. takeRecords,
  3622. };
  3623. }
  3624. function useCssVar(prop, target, options = {}) {
  3625. const {
  3626. window: window2 = defaultWindow,
  3627. initialValue = '',
  3628. observe = false,
  3629. } = options;
  3630. const variable = ref(initialValue);
  3631. const elRef = computed(() => {
  3632. var _a;
  3633. return (
  3634. unrefElement(target) ||
  3635. ((_a = window2 == null ? void 0 : window2.document) == null
  3636. ? void 0
  3637. : _a.documentElement)
  3638. );
  3639. });
  3640. function updateCssVar() {
  3641. var _a;
  3642. const key = toValue(prop);
  3643. const el = toValue(elRef);
  3644. if (el && window2) {
  3645. const value =
  3646. (_a = window2.getComputedStyle(el).getPropertyValue(key)) == null
  3647. ? void 0
  3648. : _a.trim();
  3649. variable.value = value || initialValue;
  3650. }
  3651. }
  3652. if (observe) {
  3653. useMutationObserver(elRef, updateCssVar, {
  3654. attributeFilter: ['style', 'class'],
  3655. window: window2,
  3656. });
  3657. }
  3658. watch([elRef, () => toValue(prop)], updateCssVar, { immediate: true });
  3659. watch(variable, (val) => {
  3660. var _a;
  3661. if ((_a = elRef.value) == null ? void 0 : _a.style)
  3662. elRef.value.style.setProperty(toValue(prop), val);
  3663. });
  3664. return variable;
  3665. }
  3666. function useCurrentElement(rootComponent) {
  3667. const vm = getCurrentInstance();
  3668. const currentElement = computedWithControl(
  3669. () => null,
  3670. () => (rootComponent ? unrefElement(rootComponent) : vm.proxy.$el),
  3671. );
  3672. onUpdated(currentElement.trigger);
  3673. onMounted(currentElement.trigger);
  3674. return currentElement;
  3675. }
  3676. function useCycleList(list, options) {
  3677. const state = shallowRef(getInitialValue());
  3678. const listRef = toRef2(list);
  3679. const index = computed({
  3680. get() {
  3681. var _a;
  3682. const targetList = listRef.value;
  3683. let index2 = (options == null ? void 0 : options.getIndexOf)
  3684. ? options.getIndexOf(state.value, targetList)
  3685. : targetList.indexOf(state.value);
  3686. if (index2 < 0)
  3687. index2 =
  3688. (_a = options == null ? void 0 : options.fallbackIndex) != null
  3689. ? _a
  3690. : 0;
  3691. return index2;
  3692. },
  3693. set(v) {
  3694. set3(v);
  3695. },
  3696. });
  3697. function set3(i) {
  3698. const targetList = listRef.value;
  3699. const length = targetList.length;
  3700. const index2 = ((i % length) + length) % length;
  3701. const value = targetList[index2];
  3702. state.value = value;
  3703. return value;
  3704. }
  3705. function shift(delta = 1) {
  3706. return set3(index.value + delta);
  3707. }
  3708. function next(n = 1) {
  3709. return shift(n);
  3710. }
  3711. function prev(n = 1) {
  3712. return shift(-n);
  3713. }
  3714. function getInitialValue() {
  3715. var _a, _b;
  3716. return (_b = toValue(
  3717. (_a = options == null ? void 0 : options.initialValue) != null
  3718. ? _a
  3719. : toValue(list)[0],
  3720. )) != null
  3721. ? _b
  3722. : void 0;
  3723. }
  3724. watch(listRef, () => set3(index.value));
  3725. return {
  3726. state,
  3727. index,
  3728. next,
  3729. prev,
  3730. go: set3,
  3731. };
  3732. }
  3733. function useDark(options = {}) {
  3734. const {
  3735. valueDark = 'dark',
  3736. valueLight = '',
  3737. window: window2 = defaultWindow,
  3738. } = options;
  3739. const mode = useColorMode({
  3740. ...options,
  3741. onChanged: (mode2, defaultHandler) => {
  3742. var _a;
  3743. if (options.onChanged)
  3744. (_a = options.onChanged) == null
  3745. ? void 0
  3746. : _a.call(options, mode2 === 'dark', defaultHandler, mode2);
  3747. else defaultHandler(mode2);
  3748. },
  3749. modes: {
  3750. dark: valueDark,
  3751. light: valueLight,
  3752. },
  3753. });
  3754. const system = computed(() => {
  3755. if (mode.system) {
  3756. return mode.system.value;
  3757. } else {
  3758. const preferredDark = usePreferredDark({ window: window2 });
  3759. return preferredDark.value ? 'dark' : 'light';
  3760. }
  3761. });
  3762. const isDark = computed({
  3763. get() {
  3764. return mode.value === 'dark';
  3765. },
  3766. set(v) {
  3767. const modeVal = v ? 'dark' : 'light';
  3768. if (system.value === modeVal) mode.value = 'auto';
  3769. else mode.value = modeVal;
  3770. },
  3771. });
  3772. return isDark;
  3773. }
  3774. function fnBypass(v) {
  3775. return v;
  3776. }
  3777. function fnSetSource(source, value) {
  3778. return (source.value = value);
  3779. }
  3780. function defaultDump(clone) {
  3781. return clone ? (typeof clone === 'function' ? clone : cloneFnJSON) : fnBypass;
  3782. }
  3783. function defaultParse(clone) {
  3784. return clone ? (typeof clone === 'function' ? clone : cloneFnJSON) : fnBypass;
  3785. }
  3786. function useManualRefHistory(source, options = {}) {
  3787. const {
  3788. clone = false,
  3789. dump = defaultDump(clone),
  3790. parse = defaultParse(clone),
  3791. setSource = fnSetSource,
  3792. } = options;
  3793. function _createHistoryRecord() {
  3794. return markRaw({
  3795. snapshot: dump(source.value),
  3796. timestamp: timestamp(),
  3797. });
  3798. }
  3799. const last = ref(_createHistoryRecord());
  3800. const undoStack = ref([]);
  3801. const redoStack = ref([]);
  3802. const _setSource = (record) => {
  3803. setSource(source, parse(record.snapshot));
  3804. last.value = record;
  3805. };
  3806. const commit = () => {
  3807. undoStack.value.unshift(last.value);
  3808. last.value = _createHistoryRecord();
  3809. if (options.capacity && undoStack.value.length > options.capacity)
  3810. undoStack.value.splice(options.capacity, Number.POSITIVE_INFINITY);
  3811. if (redoStack.value.length)
  3812. redoStack.value.splice(0, redoStack.value.length);
  3813. };
  3814. const clear = () => {
  3815. undoStack.value.splice(0, undoStack.value.length);
  3816. redoStack.value.splice(0, redoStack.value.length);
  3817. };
  3818. const undo = () => {
  3819. const state = undoStack.value.shift();
  3820. if (state) {
  3821. redoStack.value.unshift(last.value);
  3822. _setSource(state);
  3823. }
  3824. };
  3825. const redo = () => {
  3826. const state = redoStack.value.shift();
  3827. if (state) {
  3828. undoStack.value.unshift(last.value);
  3829. _setSource(state);
  3830. }
  3831. };
  3832. const reset = () => {
  3833. _setSource(last.value);
  3834. };
  3835. const history = computed(() => [last.value, ...undoStack.value]);
  3836. const canUndo = computed(() => undoStack.value.length > 0);
  3837. const canRedo = computed(() => redoStack.value.length > 0);
  3838. return {
  3839. source,
  3840. undoStack,
  3841. redoStack,
  3842. last,
  3843. history,
  3844. canUndo,
  3845. canRedo,
  3846. clear,
  3847. commit,
  3848. reset,
  3849. undo,
  3850. redo,
  3851. };
  3852. }
  3853. function useRefHistory(source, options = {}) {
  3854. const { deep = false, flush = 'pre', eventFilter } = options;
  3855. const {
  3856. eventFilter: composedFilter,
  3857. pause,
  3858. resume: resumeTracking,
  3859. isActive: isTracking,
  3860. } = pausableFilter(eventFilter);
  3861. const { ignoreUpdates, ignorePrevAsyncUpdates, stop } = watchIgnorable(
  3862. source,
  3863. commit,
  3864. { deep, flush, eventFilter: composedFilter },
  3865. );
  3866. function setSource(source2, value) {
  3867. ignorePrevAsyncUpdates();
  3868. ignoreUpdates(() => {
  3869. source2.value = value;
  3870. });
  3871. }
  3872. const manualHistory = useManualRefHistory(source, {
  3873. ...options,
  3874. clone: options.clone || deep,
  3875. setSource,
  3876. });
  3877. const { clear, commit: manualCommit } = manualHistory;
  3878. function commit() {
  3879. ignorePrevAsyncUpdates();
  3880. manualCommit();
  3881. }
  3882. function resume(commitNow) {
  3883. resumeTracking();
  3884. if (commitNow) commit();
  3885. }
  3886. function batch(fn) {
  3887. let canceled = false;
  3888. const cancel = () => (canceled = true);
  3889. ignoreUpdates(() => {
  3890. fn(cancel);
  3891. });
  3892. if (!canceled) commit();
  3893. }
  3894. function dispose() {
  3895. stop();
  3896. clear();
  3897. }
  3898. return {
  3899. ...manualHistory,
  3900. isTracking,
  3901. pause,
  3902. resume,
  3903. commit,
  3904. batch,
  3905. dispose,
  3906. };
  3907. }
  3908. function useDebouncedRefHistory(source, options = {}) {
  3909. const filter = options.debounce ? debounceFilter(options.debounce) : void 0;
  3910. const history = useRefHistory(source, { ...options, eventFilter: filter });
  3911. return {
  3912. ...history,
  3913. };
  3914. }
  3915. function useDeviceMotion(options = {}) {
  3916. const { window: window2 = defaultWindow, eventFilter = bypassFilter } =
  3917. options;
  3918. const acceleration = ref({ x: null, y: null, z: null });
  3919. const rotationRate = ref({ alpha: null, beta: null, gamma: null });
  3920. const interval = ref(0);
  3921. const accelerationIncludingGravity = ref({
  3922. x: null,
  3923. y: null,
  3924. z: null,
  3925. });
  3926. if (window2) {
  3927. const onDeviceMotion = createFilterWrapper(eventFilter, (event) => {
  3928. acceleration.value = event.acceleration;
  3929. accelerationIncludingGravity.value = event.accelerationIncludingGravity;
  3930. rotationRate.value = event.rotationRate;
  3931. interval.value = event.interval;
  3932. });
  3933. useEventListener(window2, 'devicemotion', onDeviceMotion);
  3934. }
  3935. return {
  3936. acceleration,
  3937. accelerationIncludingGravity,
  3938. rotationRate,
  3939. interval,
  3940. };
  3941. }
  3942. function useDeviceOrientation(options = {}) {
  3943. const { window: window2 = defaultWindow } = options;
  3944. const isSupported = useSupported(
  3945. () => window2 && 'DeviceOrientationEvent' in window2,
  3946. );
  3947. const isAbsolute = ref(false);
  3948. const alpha = ref(null);
  3949. const beta = ref(null);
  3950. const gamma = ref(null);
  3951. if (window2 && isSupported.value) {
  3952. useEventListener(window2, 'deviceorientation', (event) => {
  3953. isAbsolute.value = event.absolute;
  3954. alpha.value = event.alpha;
  3955. beta.value = event.beta;
  3956. gamma.value = event.gamma;
  3957. });
  3958. }
  3959. return {
  3960. isSupported,
  3961. isAbsolute,
  3962. alpha,
  3963. beta,
  3964. gamma,
  3965. };
  3966. }
  3967. function useDevicePixelRatio(options = {}) {
  3968. const { window: window2 = defaultWindow } = options;
  3969. const pixelRatio = ref(1);
  3970. if (window2) {
  3971. let observe2 = function () {
  3972. pixelRatio.value = window2.devicePixelRatio;
  3973. cleanup2();
  3974. media = window2.matchMedia(`(resolution: ${pixelRatio.value}dppx)`);
  3975. media.addEventListener('change', observe2, { once: true });
  3976. },
  3977. cleanup2 = function () {
  3978. media == null ? void 0 : media.removeEventListener('change', observe2);
  3979. };
  3980. let media;
  3981. observe2();
  3982. tryOnScopeDispose(cleanup2);
  3983. }
  3984. return { pixelRatio };
  3985. }
  3986. function useDevicesList(options = {}) {
  3987. const {
  3988. navigator = defaultNavigator,
  3989. requestPermissions = false,
  3990. constraints = { audio: true, video: true },
  3991. onUpdated: onUpdated2,
  3992. } = options;
  3993. const devices = ref([]);
  3994. const videoInputs = computed(() =>
  3995. devices.value.filter((i) => i.kind === 'videoinput'),
  3996. );
  3997. const audioInputs = computed(() =>
  3998. devices.value.filter((i) => i.kind === 'audioinput'),
  3999. );
  4000. const audioOutputs = computed(() =>
  4001. devices.value.filter((i) => i.kind === 'audiooutput'),
  4002. );
  4003. const isSupported = useSupported(
  4004. () =>
  4005. navigator &&
  4006. navigator.mediaDevices &&
  4007. navigator.mediaDevices.enumerateDevices,
  4008. );
  4009. const permissionGranted = ref(false);
  4010. let stream;
  4011. async function update() {
  4012. if (!isSupported.value) return;
  4013. devices.value = await navigator.mediaDevices.enumerateDevices();
  4014. onUpdated2 == null ? void 0 : onUpdated2(devices.value);
  4015. if (stream) {
  4016. stream.getTracks().forEach((t) => t.stop());
  4017. stream = null;
  4018. }
  4019. }
  4020. async function ensurePermissions() {
  4021. if (!isSupported.value) return false;
  4022. if (permissionGranted.value) return true;
  4023. const { state, query } = usePermission('camera', { controls: true });
  4024. await query();
  4025. if (state.value !== 'granted') {
  4026. stream = await navigator.mediaDevices.getUserMedia(constraints);
  4027. update();
  4028. permissionGranted.value = true;
  4029. } else {
  4030. permissionGranted.value = true;
  4031. }
  4032. return permissionGranted.value;
  4033. }
  4034. if (isSupported.value) {
  4035. if (requestPermissions) ensurePermissions();
  4036. useEventListener(navigator.mediaDevices, 'devicechange', update);
  4037. update();
  4038. }
  4039. return {
  4040. devices,
  4041. ensurePermissions,
  4042. permissionGranted,
  4043. videoInputs,
  4044. audioInputs,
  4045. audioOutputs,
  4046. isSupported,
  4047. };
  4048. }
  4049. function useDisplayMedia(options = {}) {
  4050. var _a;
  4051. const enabled = ref((_a = options.enabled) != null ? _a : false);
  4052. const video = options.video;
  4053. const audio = options.audio;
  4054. const { navigator = defaultNavigator } = options;
  4055. const isSupported = useSupported(() => {
  4056. var _a2;
  4057. return (_a2 = navigator == null ? void 0 : navigator.mediaDevices) == null
  4058. ? void 0
  4059. : _a2.getDisplayMedia;
  4060. });
  4061. const constraint = { audio, video };
  4062. const stream = shallowRef();
  4063. async function _start() {
  4064. if (!isSupported.value || stream.value) return;
  4065. stream.value = await navigator.mediaDevices.getDisplayMedia(constraint);
  4066. return stream.value;
  4067. }
  4068. async function _stop() {
  4069. var _a2;
  4070. (_a2 = stream.value) == null
  4071. ? void 0
  4072. : _a2.getTracks().forEach((t) => t.stop());
  4073. stream.value = void 0;
  4074. }
  4075. function stop() {
  4076. _stop();
  4077. enabled.value = false;
  4078. }
  4079. async function start() {
  4080. await _start();
  4081. if (stream.value) enabled.value = true;
  4082. return stream.value;
  4083. }
  4084. watch(
  4085. enabled,
  4086. (v) => {
  4087. if (v) _start();
  4088. else _stop();
  4089. },
  4090. { immediate: true },
  4091. );
  4092. return {
  4093. isSupported,
  4094. stream,
  4095. start,
  4096. stop,
  4097. enabled,
  4098. };
  4099. }
  4100. function useDocumentVisibility(options = {}) {
  4101. const { document: document2 = defaultDocument } = options;
  4102. if (!document2) return ref('visible');
  4103. const visibility = ref(document2.visibilityState);
  4104. useEventListener(document2, 'visibilitychange', () => {
  4105. visibility.value = document2.visibilityState;
  4106. });
  4107. return visibility;
  4108. }
  4109. function useDraggable(target, options = {}) {
  4110. var _a, _b;
  4111. const {
  4112. pointerTypes,
  4113. preventDefault: preventDefault2,
  4114. stopPropagation,
  4115. exact,
  4116. onMove,
  4117. onEnd,
  4118. onStart,
  4119. initialValue,
  4120. axis = 'both',
  4121. draggingElement = defaultWindow,
  4122. containerElement,
  4123. handle: draggingHandle = target,
  4124. } = options;
  4125. const position = ref(
  4126. (_a = toValue(initialValue)) != null ? _a : { x: 0, y: 0 },
  4127. );
  4128. const pressedDelta = ref();
  4129. const filterEvent = (e) => {
  4130. if (pointerTypes) return pointerTypes.includes(e.pointerType);
  4131. return true;
  4132. };
  4133. const handleEvent = (e) => {
  4134. if (toValue(preventDefault2)) e.preventDefault();
  4135. if (toValue(stopPropagation)) e.stopPropagation();
  4136. };
  4137. const start = (e) => {
  4138. var _a2;
  4139. if (toValue(options.disabled) || !filterEvent(e)) return;
  4140. if (toValue(exact) && e.target !== toValue(target)) return;
  4141. const container = toValue(containerElement);
  4142. const containerRect =
  4143. (_a2 = container == null ? void 0 : container.getBoundingClientRect) ==
  4144. null
  4145. ? void 0
  4146. : _a2.call(container);
  4147. const targetRect = toValue(target).getBoundingClientRect();
  4148. const pos = {
  4149. x:
  4150. e.clientX -
  4151. (container
  4152. ? targetRect.left - containerRect.left + container.scrollLeft
  4153. : targetRect.left),
  4154. y:
  4155. e.clientY -
  4156. (container
  4157. ? targetRect.top - containerRect.top + container.scrollTop
  4158. : targetRect.top),
  4159. };
  4160. if ((onStart == null ? void 0 : onStart(pos, e)) === false) return;
  4161. pressedDelta.value = pos;
  4162. handleEvent(e);
  4163. };
  4164. const move = (e) => {
  4165. if (toValue(options.disabled) || !filterEvent(e)) return;
  4166. if (!pressedDelta.value) return;
  4167. const container = toValue(containerElement);
  4168. const targetRect = toValue(target).getBoundingClientRect();
  4169. let { x, y } = position.value;
  4170. if (axis === 'x' || axis === 'both') {
  4171. x = e.clientX - pressedDelta.value.x;
  4172. if (container)
  4173. x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
  4174. }
  4175. if (axis === 'y' || axis === 'both') {
  4176. y = e.clientY - pressedDelta.value.y;
  4177. if (container)
  4178. y = Math.min(
  4179. Math.max(0, y),
  4180. container.scrollHeight - targetRect.height,
  4181. );
  4182. }
  4183. position.value = {
  4184. x,
  4185. y,
  4186. };
  4187. onMove == null ? void 0 : onMove(position.value, e);
  4188. handleEvent(e);
  4189. };
  4190. const end = (e) => {
  4191. if (toValue(options.disabled) || !filterEvent(e)) return;
  4192. if (!pressedDelta.value) return;
  4193. pressedDelta.value = void 0;
  4194. onEnd == null ? void 0 : onEnd(position.value, e);
  4195. handleEvent(e);
  4196. };
  4197. if (isClient) {
  4198. const config = { capture: (_b = options.capture) != null ? _b : true };
  4199. useEventListener(draggingHandle, 'pointerdown', start, config);
  4200. useEventListener(draggingElement, 'pointermove', move, config);
  4201. useEventListener(draggingElement, 'pointerup', end, config);
  4202. }
  4203. return {
  4204. ...toRefs2(position),
  4205. position,
  4206. isDragging: computed(() => !!pressedDelta.value),
  4207. style: computed(
  4208. () => `left:${position.value.x}px;top:${position.value.y}px;`,
  4209. ),
  4210. };
  4211. }
  4212. function useDropZone(target, options = {}) {
  4213. const isOverDropZone = ref(false);
  4214. const files = shallowRef(null);
  4215. let counter = 0;
  4216. let isDataTypeIncluded = true;
  4217. if (isClient) {
  4218. const _options =
  4219. typeof options === 'function' ? { onDrop: options } : options;
  4220. const getFiles = (event) => {
  4221. var _a, _b;
  4222. const list = Array.from(
  4223. (_b = (_a = event.dataTransfer) == null ? void 0 : _a.files) != null
  4224. ? _b
  4225. : [],
  4226. );
  4227. return (files.value = list.length === 0 ? null : list);
  4228. };
  4229. useEventListener(target, 'dragenter', (event) => {
  4230. var _a, _b;
  4231. const types = Array.from(
  4232. ((_a = event == null ? void 0 : event.dataTransfer) == null
  4233. ? void 0
  4234. : _a.items) || [],
  4235. )
  4236. .map((i) => (i.kind === 'file' ? i.type : null))
  4237. .filter(notNullish);
  4238. if (_options.dataTypes && event.dataTransfer) {
  4239. const dataTypes = unref(_options.dataTypes);
  4240. isDataTypeIncluded =
  4241. typeof dataTypes === 'function'
  4242. ? dataTypes(types)
  4243. : dataTypes
  4244. ? dataTypes.some((item) => types.includes(item))
  4245. : true;
  4246. if (!isDataTypeIncluded) return;
  4247. }
  4248. event.preventDefault();
  4249. counter += 1;
  4250. isOverDropZone.value = true;
  4251. (_b = _options.onEnter) == null
  4252. ? void 0
  4253. : _b.call(_options, getFiles(event), event);
  4254. });
  4255. useEventListener(target, 'dragover', (event) => {
  4256. var _a;
  4257. if (!isDataTypeIncluded) return;
  4258. event.preventDefault();
  4259. (_a = _options.onOver) == null
  4260. ? void 0
  4261. : _a.call(_options, getFiles(event), event);
  4262. });
  4263. useEventListener(target, 'dragleave', (event) => {
  4264. var _a;
  4265. if (!isDataTypeIncluded) return;
  4266. event.preventDefault();
  4267. counter -= 1;
  4268. if (counter === 0) isOverDropZone.value = false;
  4269. (_a = _options.onLeave) == null
  4270. ? void 0
  4271. : _a.call(_options, getFiles(event), event);
  4272. });
  4273. useEventListener(target, 'drop', (event) => {
  4274. var _a;
  4275. event.preventDefault();
  4276. counter = 0;
  4277. isOverDropZone.value = false;
  4278. (_a = _options.onDrop) == null
  4279. ? void 0
  4280. : _a.call(_options, getFiles(event), event);
  4281. });
  4282. }
  4283. return {
  4284. files,
  4285. isOverDropZone,
  4286. };
  4287. }
  4288. function useResizeObserver(target, callback, options = {}) {
  4289. const { window: window2 = defaultWindow, ...observerOptions } = options;
  4290. let observer;
  4291. const isSupported = useSupported(
  4292. () => window2 && 'ResizeObserver' in window2,
  4293. );
  4294. const cleanup = () => {
  4295. if (observer) {
  4296. observer.disconnect();
  4297. observer = void 0;
  4298. }
  4299. };
  4300. const targets = computed(() =>
  4301. Array.isArray(target)
  4302. ? target.map((el) => unrefElement(el))
  4303. : [unrefElement(target)],
  4304. );
  4305. const stopWatch = watch(
  4306. targets,
  4307. (els) => {
  4308. cleanup();
  4309. if (isSupported.value && window2) {
  4310. observer = new ResizeObserver(callback);
  4311. for (const _el of els) _el && observer.observe(_el, observerOptions);
  4312. }
  4313. },
  4314. { immediate: true, flush: 'post' },
  4315. );
  4316. const stop = () => {
  4317. cleanup();
  4318. stopWatch();
  4319. };
  4320. tryOnScopeDispose(stop);
  4321. return {
  4322. isSupported,
  4323. stop,
  4324. };
  4325. }
  4326. function useElementBounding(target, options = {}) {
  4327. const {
  4328. reset = true,
  4329. windowResize = true,
  4330. windowScroll = true,
  4331. immediate = true,
  4332. } = options;
  4333. const height = ref(0);
  4334. const bottom = ref(0);
  4335. const left = ref(0);
  4336. const right = ref(0);
  4337. const top = ref(0);
  4338. const width = ref(0);
  4339. const x = ref(0);
  4340. const y = ref(0);
  4341. function update() {
  4342. const el = unrefElement(target);
  4343. if (!el) {
  4344. if (reset) {
  4345. height.value = 0;
  4346. bottom.value = 0;
  4347. left.value = 0;
  4348. right.value = 0;
  4349. top.value = 0;
  4350. width.value = 0;
  4351. x.value = 0;
  4352. y.value = 0;
  4353. }
  4354. return;
  4355. }
  4356. const rect = el.getBoundingClientRect();
  4357. height.value = rect.height;
  4358. bottom.value = rect.bottom;
  4359. left.value = rect.left;
  4360. right.value = rect.right;
  4361. top.value = rect.top;
  4362. width.value = rect.width;
  4363. x.value = rect.x;
  4364. y.value = rect.y;
  4365. }
  4366. useResizeObserver(target, update);
  4367. watch(
  4368. () => unrefElement(target),
  4369. (ele) => !ele && update(),
  4370. );
  4371. useMutationObserver(target, update, {
  4372. attributeFilter: ['style', 'class'],
  4373. });
  4374. if (windowScroll)
  4375. useEventListener('scroll', update, { capture: true, passive: true });
  4376. if (windowResize) useEventListener('resize', update, { passive: true });
  4377. tryOnMounted(() => {
  4378. if (immediate) update();
  4379. });
  4380. return {
  4381. height,
  4382. bottom,
  4383. left,
  4384. right,
  4385. top,
  4386. width,
  4387. x,
  4388. y,
  4389. update,
  4390. };
  4391. }
  4392. function useElementByPoint(options) {
  4393. const {
  4394. x,
  4395. y,
  4396. document: document2 = defaultDocument,
  4397. multiple,
  4398. interval = 'requestAnimationFrame',
  4399. immediate = true,
  4400. } = options;
  4401. const isSupported = useSupported(() => {
  4402. if (toValue(multiple)) return document2 && 'elementsFromPoint' in document2;
  4403. return document2 && 'elementFromPoint' in document2;
  4404. });
  4405. const element = ref(null);
  4406. const cb = () => {
  4407. var _a, _b;
  4408. element.value = toValue(multiple)
  4409. ? (_a =
  4410. document2 == null
  4411. ? void 0
  4412. : document2.elementsFromPoint(toValue(x), toValue(y))) != null
  4413. ? _a
  4414. : []
  4415. : (_b =
  4416. document2 == null
  4417. ? void 0
  4418. : document2.elementFromPoint(toValue(x), toValue(y))) != null
  4419. ? _b
  4420. : null;
  4421. };
  4422. const controls =
  4423. interval === 'requestAnimationFrame'
  4424. ? useRafFn(cb, { immediate })
  4425. : useIntervalFn(cb, interval, { immediate });
  4426. return {
  4427. isSupported,
  4428. element,
  4429. ...controls,
  4430. };
  4431. }
  4432. function useElementHover(el, options = {}) {
  4433. const {
  4434. delayEnter = 0,
  4435. delayLeave = 0,
  4436. window: window2 = defaultWindow,
  4437. } = options;
  4438. const isHovered = ref(false);
  4439. let timer;
  4440. const toggle = (entering) => {
  4441. const delay = entering ? delayEnter : delayLeave;
  4442. if (timer) {
  4443. clearTimeout(timer);
  4444. timer = void 0;
  4445. }
  4446. if (delay) timer = setTimeout(() => (isHovered.value = entering), delay);
  4447. else isHovered.value = entering;
  4448. };
  4449. if (!window2) return isHovered;
  4450. useEventListener(el, 'mouseenter', () => toggle(true), { passive: true });
  4451. useEventListener(el, 'mouseleave', () => toggle(false), { passive: true });
  4452. return isHovered;
  4453. }
  4454. function useElementSize(
  4455. target,
  4456. initialSize = { width: 0, height: 0 },
  4457. options = {},
  4458. ) {
  4459. const { window: window2 = defaultWindow, box = 'content-box' } = options;
  4460. const isSVG = computed(() => {
  4461. var _a, _b;
  4462. return (_b =
  4463. (_a = unrefElement(target)) == null ? void 0 : _a.namespaceURI) == null
  4464. ? void 0
  4465. : _b.includes('svg');
  4466. });
  4467. const width = ref(initialSize.width);
  4468. const height = ref(initialSize.height);
  4469. const { stop: stop1 } = useResizeObserver(
  4470. target,
  4471. ([entry]) => {
  4472. const boxSize =
  4473. box === 'border-box'
  4474. ? entry.borderBoxSize
  4475. : box === 'content-box'
  4476. ? entry.contentBoxSize
  4477. : entry.devicePixelContentBoxSize;
  4478. if (window2 && isSVG.value) {
  4479. const $elem = unrefElement(target);
  4480. if ($elem) {
  4481. const styles = window2.getComputedStyle($elem);
  4482. width.value = Number.parseFloat(styles.width);
  4483. height.value = Number.parseFloat(styles.height);
  4484. }
  4485. } else {
  4486. if (boxSize) {
  4487. const formatBoxSize = Array.isArray(boxSize) ? boxSize : [boxSize];
  4488. width.value = formatBoxSize.reduce(
  4489. (acc, { inlineSize }) => acc + inlineSize,
  4490. 0,
  4491. );
  4492. height.value = formatBoxSize.reduce(
  4493. (acc, { blockSize }) => acc + blockSize,
  4494. 0,
  4495. );
  4496. } else {
  4497. width.value = entry.contentRect.width;
  4498. height.value = entry.contentRect.height;
  4499. }
  4500. }
  4501. },
  4502. options,
  4503. );
  4504. tryOnMounted(() => {
  4505. const ele = unrefElement(target);
  4506. if (ele) {
  4507. width.value = 'offsetWidth' in ele ? ele.offsetWidth : initialSize.width;
  4508. height.value =
  4509. 'offsetHeight' in ele ? ele.offsetHeight : initialSize.height;
  4510. }
  4511. });
  4512. const stop2 = watch(
  4513. () => unrefElement(target),
  4514. (ele) => {
  4515. width.value = ele ? initialSize.width : 0;
  4516. height.value = ele ? initialSize.height : 0;
  4517. },
  4518. );
  4519. function stop() {
  4520. stop1();
  4521. stop2();
  4522. }
  4523. return {
  4524. width,
  4525. height,
  4526. stop,
  4527. };
  4528. }
  4529. function useIntersectionObserver(target, callback, options = {}) {
  4530. const {
  4531. root,
  4532. rootMargin = '0px',
  4533. threshold = 0.1,
  4534. window: window2 = defaultWindow,
  4535. immediate = true,
  4536. } = options;
  4537. const isSupported = useSupported(
  4538. () => window2 && 'IntersectionObserver' in window2,
  4539. );
  4540. const targets = computed(() => {
  4541. const _target = toValue(target);
  4542. return (Array.isArray(_target) ? _target : [_target])
  4543. .map(unrefElement)
  4544. .filter(notNullish);
  4545. });
  4546. let cleanup = noop;
  4547. const isActive = ref(immediate);
  4548. const stopWatch = isSupported.value
  4549. ? watch(
  4550. () => [targets.value, unrefElement(root), isActive.value],
  4551. ([targets2, root2]) => {
  4552. cleanup();
  4553. if (!isActive.value) return;
  4554. if (!targets2.length) return;
  4555. const observer = new IntersectionObserver(callback, {
  4556. root: unrefElement(root2),
  4557. rootMargin,
  4558. threshold,
  4559. });
  4560. targets2.forEach((el) => el && observer.observe(el));
  4561. cleanup = () => {
  4562. observer.disconnect();
  4563. cleanup = noop;
  4564. };
  4565. },
  4566. { immediate, flush: 'post' },
  4567. )
  4568. : noop;
  4569. const stop = () => {
  4570. cleanup();
  4571. stopWatch();
  4572. isActive.value = false;
  4573. };
  4574. tryOnScopeDispose(stop);
  4575. return {
  4576. isSupported,
  4577. isActive,
  4578. pause() {
  4579. cleanup();
  4580. isActive.value = false;
  4581. },
  4582. resume() {
  4583. isActive.value = true;
  4584. },
  4585. stop,
  4586. };
  4587. }
  4588. function useElementVisibility(element, options = {}) {
  4589. const {
  4590. window: window2 = defaultWindow,
  4591. scrollTarget,
  4592. threshold = 0,
  4593. } = options;
  4594. const elementIsVisible = ref(false);
  4595. useIntersectionObserver(
  4596. element,
  4597. (intersectionObserverEntries) => {
  4598. let isIntersecting = elementIsVisible.value;
  4599. let latestTime = 0;
  4600. for (const entry of intersectionObserverEntries) {
  4601. if (entry.time >= latestTime) {
  4602. latestTime = entry.time;
  4603. isIntersecting = entry.isIntersecting;
  4604. }
  4605. }
  4606. elementIsVisible.value = isIntersecting;
  4607. },
  4608. {
  4609. root: scrollTarget,
  4610. window: window2,
  4611. threshold,
  4612. },
  4613. );
  4614. return elementIsVisible;
  4615. }
  4616. var events = /* @__PURE__ */ new Map();
  4617. function useEventBus(key) {
  4618. const scope = getCurrentScope();
  4619. function on(listener) {
  4620. var _a;
  4621. const listeners = events.get(key) || /* @__PURE__ */ new Set();
  4622. listeners.add(listener);
  4623. events.set(key, listeners);
  4624. const _off = () => off(listener);
  4625. (_a = scope == null ? void 0 : scope.cleanups) == null
  4626. ? void 0
  4627. : _a.push(_off);
  4628. return _off;
  4629. }
  4630. function once(listener) {
  4631. function _listener(...args) {
  4632. off(_listener);
  4633. listener(...args);
  4634. }
  4635. return on(_listener);
  4636. }
  4637. function off(listener) {
  4638. const listeners = events.get(key);
  4639. if (!listeners) return;
  4640. listeners.delete(listener);
  4641. if (!listeners.size) reset();
  4642. }
  4643. function reset() {
  4644. events.delete(key);
  4645. }
  4646. function emit(event, payload) {
  4647. var _a;
  4648. (_a = events.get(key)) == null
  4649. ? void 0
  4650. : _a.forEach((v) => v(event, payload));
  4651. }
  4652. return { on, once, off, emit, reset };
  4653. }
  4654. function resolveNestedOptions$1(options) {
  4655. if (options === true) return {};
  4656. return options;
  4657. }
  4658. function useEventSource(url, events2 = [], options = {}) {
  4659. const event = ref(null);
  4660. const data = ref(null);
  4661. const status = ref('CONNECTING');
  4662. const eventSource = ref(null);
  4663. const error = shallowRef(null);
  4664. const urlRef = toRef2(url);
  4665. let explicitlyClosed = false;
  4666. let retried = 0;
  4667. const { withCredentials = false, immediate = true } = options;
  4668. const close = () => {
  4669. if (isClient && eventSource.value) {
  4670. eventSource.value.close();
  4671. eventSource.value = null;
  4672. status.value = 'CLOSED';
  4673. explicitlyClosed = true;
  4674. }
  4675. };
  4676. const _init = () => {
  4677. if (explicitlyClosed || typeof urlRef.value === 'undefined') return;
  4678. const es = new EventSource(urlRef.value, { withCredentials });
  4679. status.value = 'CONNECTING';
  4680. eventSource.value = es;
  4681. es.onopen = () => {
  4682. status.value = 'OPEN';
  4683. error.value = null;
  4684. };
  4685. es.onerror = (e) => {
  4686. status.value = 'CLOSED';
  4687. error.value = e;
  4688. if (es.readyState === 2 && !explicitlyClosed && options.autoReconnect) {
  4689. es.close();
  4690. const {
  4691. retries = -1,
  4692. delay = 1e3,
  4693. onFailed,
  4694. } = resolveNestedOptions$1(options.autoReconnect);
  4695. retried += 1;
  4696. if (typeof retries === 'number' && (retries < 0 || retried < retries))
  4697. setTimeout(_init, delay);
  4698. else if (typeof retries === 'function' && retries())
  4699. setTimeout(_init, delay);
  4700. else onFailed == null ? void 0 : onFailed();
  4701. }
  4702. };
  4703. es.onmessage = (e) => {
  4704. event.value = null;
  4705. data.value = e.data;
  4706. };
  4707. for (const event_name of events2) {
  4708. useEventListener(es, event_name, (e) => {
  4709. event.value = event_name;
  4710. data.value = e.data || null;
  4711. });
  4712. }
  4713. };
  4714. const open = () => {
  4715. if (!isClient) return;
  4716. close();
  4717. explicitlyClosed = false;
  4718. retried = 0;
  4719. _init();
  4720. };
  4721. if (immediate) watch(urlRef, open, { immediate: true });
  4722. tryOnScopeDispose(close);
  4723. return {
  4724. eventSource,
  4725. event,
  4726. data,
  4727. status,
  4728. error,
  4729. open,
  4730. close,
  4731. };
  4732. }
  4733. function useEyeDropper(options = {}) {
  4734. const { initialValue = '' } = options;
  4735. const isSupported = useSupported(
  4736. () => typeof window !== 'undefined' && 'EyeDropper' in window,
  4737. );
  4738. const sRGBHex = ref(initialValue);
  4739. async function open(openOptions) {
  4740. if (!isSupported.value) return;
  4741. const eyeDropper = new window.EyeDropper();
  4742. const result = await eyeDropper.open(openOptions);
  4743. sRGBHex.value = result.sRGBHex;
  4744. return result;
  4745. }
  4746. return { isSupported, sRGBHex, open };
  4747. }
  4748. function useFavicon(newIcon = null, options = {}) {
  4749. const {
  4750. baseUrl = '',
  4751. rel = 'icon',
  4752. document: document2 = defaultDocument,
  4753. } = options;
  4754. const favicon = toRef2(newIcon);
  4755. const applyIcon = (icon) => {
  4756. const elements =
  4757. document2 == null
  4758. ? void 0
  4759. : document2.head.querySelectorAll(`link[rel*="${rel}"]`);
  4760. if (!elements || elements.length === 0) {
  4761. const link = document2 == null ? void 0 : document2.createElement('link');
  4762. if (link) {
  4763. link.rel = rel;
  4764. link.href = `${baseUrl}${icon}`;
  4765. link.type = `image/${icon.split('.').pop()}`;
  4766. document2 == null ? void 0 : document2.head.append(link);
  4767. }
  4768. return;
  4769. }
  4770. elements == null
  4771. ? void 0
  4772. : elements.forEach((el) => (el.href = `${baseUrl}${icon}`));
  4773. };
  4774. watch(
  4775. favicon,
  4776. (i, o) => {
  4777. if (typeof i === 'string' && i !== o) applyIcon(i);
  4778. },
  4779. { immediate: true },
  4780. );
  4781. return favicon;
  4782. }
  4783. var payloadMapping = {
  4784. json: 'application/json',
  4785. text: 'text/plain',
  4786. };
  4787. function isFetchOptions(obj) {
  4788. return (
  4789. obj &&
  4790. containsProp(
  4791. obj,
  4792. 'immediate',
  4793. 'refetch',
  4794. 'initialData',
  4795. 'timeout',
  4796. 'beforeFetch',
  4797. 'afterFetch',
  4798. 'onFetchError',
  4799. 'fetch',
  4800. 'updateDataOnError',
  4801. )
  4802. );
  4803. }
  4804. function isAbsoluteURL(url) {
  4805. return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
  4806. }
  4807. function headersToObject(headers) {
  4808. if (typeof Headers !== 'undefined' && headers instanceof Headers)
  4809. return Object.fromEntries(headers.entries());
  4810. return headers;
  4811. }
  4812. function combineCallbacks(combination, ...callbacks) {
  4813. if (combination === 'overwrite') {
  4814. return async (ctx) => {
  4815. const callback = callbacks[callbacks.length - 1];
  4816. if (callback) return { ...ctx, ...(await callback(ctx)) };
  4817. return ctx;
  4818. };
  4819. } else {
  4820. return async (ctx) => {
  4821. for (const callback of callbacks) {
  4822. if (callback) ctx = { ...ctx, ...(await callback(ctx)) };
  4823. }
  4824. return ctx;
  4825. };
  4826. }
  4827. }
  4828. function createFetch(config = {}) {
  4829. const _combination = config.combination || 'chain';
  4830. const _options = config.options || {};
  4831. const _fetchOptions = config.fetchOptions || {};
  4832. function useFactoryFetch(url, ...args) {
  4833. const computedUrl = computed(() => {
  4834. const baseUrl = toValue(config.baseUrl);
  4835. const targetUrl = toValue(url);
  4836. return baseUrl && !isAbsoluteURL(targetUrl)
  4837. ? joinPaths(baseUrl, targetUrl)
  4838. : targetUrl;
  4839. });
  4840. let options = _options;
  4841. let fetchOptions = _fetchOptions;
  4842. if (args.length > 0) {
  4843. if (isFetchOptions(args[0])) {
  4844. options = {
  4845. ...options,
  4846. ...args[0],
  4847. beforeFetch: combineCallbacks(
  4848. _combination,
  4849. _options.beforeFetch,
  4850. args[0].beforeFetch,
  4851. ),
  4852. afterFetch: combineCallbacks(
  4853. _combination,
  4854. _options.afterFetch,
  4855. args[0].afterFetch,
  4856. ),
  4857. onFetchError: combineCallbacks(
  4858. _combination,
  4859. _options.onFetchError,
  4860. args[0].onFetchError,
  4861. ),
  4862. };
  4863. } else {
  4864. fetchOptions = {
  4865. ...fetchOptions,
  4866. ...args[0],
  4867. headers: {
  4868. ...(headersToObject(fetchOptions.headers) || {}),
  4869. ...(headersToObject(args[0].headers) || {}),
  4870. },
  4871. };
  4872. }
  4873. }
  4874. if (args.length > 1 && isFetchOptions(args[1])) {
  4875. options = {
  4876. ...options,
  4877. ...args[1],
  4878. beforeFetch: combineCallbacks(
  4879. _combination,
  4880. _options.beforeFetch,
  4881. args[1].beforeFetch,
  4882. ),
  4883. afterFetch: combineCallbacks(
  4884. _combination,
  4885. _options.afterFetch,
  4886. args[1].afterFetch,
  4887. ),
  4888. onFetchError: combineCallbacks(
  4889. _combination,
  4890. _options.onFetchError,
  4891. args[1].onFetchError,
  4892. ),
  4893. };
  4894. }
  4895. return useFetch(computedUrl, fetchOptions, options);
  4896. }
  4897. return useFactoryFetch;
  4898. }
  4899. function useFetch(url, ...args) {
  4900. var _a;
  4901. const supportsAbort = typeof AbortController === 'function';
  4902. let fetchOptions = {};
  4903. let options = {
  4904. immediate: true,
  4905. refetch: false,
  4906. timeout: 0,
  4907. updateDataOnError: false,
  4908. };
  4909. const config = {
  4910. method: 'GET',
  4911. type: 'text',
  4912. payload: void 0,
  4913. };
  4914. if (args.length > 0) {
  4915. if (isFetchOptions(args[0])) options = { ...options, ...args[0] };
  4916. else fetchOptions = args[0];
  4917. }
  4918. if (args.length > 1) {
  4919. if (isFetchOptions(args[1])) options = { ...options, ...args[1] };
  4920. }
  4921. const {
  4922. fetch = (_a = defaultWindow) == null ? void 0 : _a.fetch,
  4923. initialData,
  4924. timeout,
  4925. } = options;
  4926. const responseEvent = createEventHook();
  4927. const errorEvent = createEventHook();
  4928. const finallyEvent = createEventHook();
  4929. const isFinished = ref(false);
  4930. const isFetching = ref(false);
  4931. const aborted = ref(false);
  4932. const statusCode = ref(null);
  4933. const response = shallowRef(null);
  4934. const error = shallowRef(null);
  4935. const data = shallowRef(initialData || null);
  4936. const canAbort = computed(() => supportsAbort && isFetching.value);
  4937. let controller;
  4938. let timer;
  4939. const abort = () => {
  4940. if (supportsAbort) {
  4941. controller == null ? void 0 : controller.abort();
  4942. controller = new AbortController();
  4943. controller.signal.onabort = () => (aborted.value = true);
  4944. fetchOptions = {
  4945. ...fetchOptions,
  4946. signal: controller.signal,
  4947. };
  4948. }
  4949. };
  4950. const loading = (isLoading) => {
  4951. isFetching.value = isLoading;
  4952. isFinished.value = !isLoading;
  4953. };
  4954. if (timeout) timer = useTimeoutFn(abort, timeout, { immediate: false });
  4955. let executeCounter = 0;
  4956. const execute = async (throwOnFailed = false) => {
  4957. var _a2, _b;
  4958. abort();
  4959. loading(true);
  4960. error.value = null;
  4961. statusCode.value = null;
  4962. aborted.value = false;
  4963. executeCounter += 1;
  4964. const currentExecuteCounter = executeCounter;
  4965. const defaultFetchOptions = {
  4966. method: config.method,
  4967. headers: {},
  4968. };
  4969. if (config.payload) {
  4970. const headers = headersToObject(defaultFetchOptions.headers);
  4971. const payload = toValue(config.payload);
  4972. if (
  4973. !config.payloadType &&
  4974. payload &&
  4975. Object.getPrototypeOf(payload) === Object.prototype &&
  4976. !(payload instanceof FormData)
  4977. )
  4978. config.payloadType = 'json';
  4979. if (config.payloadType)
  4980. headers['Content-Type'] =
  4981. (_a2 = payloadMapping[config.payloadType]) != null
  4982. ? _a2
  4983. : config.payloadType;
  4984. defaultFetchOptions.body =
  4985. config.payloadType === 'json' ? JSON.stringify(payload) : payload;
  4986. }
  4987. let isCanceled = false;
  4988. const context = {
  4989. url: toValue(url),
  4990. options: {
  4991. ...defaultFetchOptions,
  4992. ...fetchOptions,
  4993. },
  4994. cancel: () => {
  4995. isCanceled = true;
  4996. },
  4997. };
  4998. if (options.beforeFetch)
  4999. Object.assign(context, await options.beforeFetch(context));
  5000. if (isCanceled || !fetch) {
  5001. loading(false);
  5002. return Promise.resolve(null);
  5003. }
  5004. let responseData = null;
  5005. if (timer) timer.start();
  5006. return fetch(context.url, {
  5007. ...defaultFetchOptions,
  5008. ...context.options,
  5009. headers: {
  5010. ...headersToObject(defaultFetchOptions.headers),
  5011. ...headersToObject(
  5012. (_b = context.options) == null ? void 0 : _b.headers,
  5013. ),
  5014. },
  5015. })
  5016. .then(async (fetchResponse) => {
  5017. response.value = fetchResponse;
  5018. statusCode.value = fetchResponse.status;
  5019. responseData = await fetchResponse.clone()[config.type]();
  5020. if (!fetchResponse.ok) {
  5021. data.value = initialData || null;
  5022. throw new Error(fetchResponse.statusText);
  5023. }
  5024. if (options.afterFetch) {
  5025. ({ data: responseData } = await options.afterFetch({
  5026. data: responseData,
  5027. response: fetchResponse,
  5028. }));
  5029. }
  5030. data.value = responseData;
  5031. responseEvent.trigger(fetchResponse);
  5032. return fetchResponse;
  5033. })
  5034. .catch(async (fetchError) => {
  5035. let errorData = fetchError.message || fetchError.name;
  5036. if (options.onFetchError) {
  5037. ({ error: errorData, data: responseData } =
  5038. await options.onFetchError({
  5039. data: responseData,
  5040. error: fetchError,
  5041. response: response.value,
  5042. }));
  5043. }
  5044. error.value = errorData;
  5045. if (options.updateDataOnError) data.value = responseData;
  5046. errorEvent.trigger(fetchError);
  5047. if (throwOnFailed) throw fetchError;
  5048. return null;
  5049. })
  5050. .finally(() => {
  5051. if (currentExecuteCounter === executeCounter) loading(false);
  5052. if (timer) timer.stop();
  5053. finallyEvent.trigger(null);
  5054. });
  5055. };
  5056. const refetch = toRef2(options.refetch);
  5057. watch([refetch, toRef2(url)], ([refetch2]) => refetch2 && execute(), {
  5058. deep: true,
  5059. });
  5060. const shell = {
  5061. isFinished: readonly(isFinished),
  5062. isFetching: readonly(isFetching),
  5063. statusCode,
  5064. response,
  5065. error,
  5066. data,
  5067. canAbort,
  5068. aborted,
  5069. abort,
  5070. execute,
  5071. onFetchResponse: responseEvent.on,
  5072. onFetchError: errorEvent.on,
  5073. onFetchFinally: finallyEvent.on,
  5074. // method
  5075. get: setMethod('GET'),
  5076. put: setMethod('PUT'),
  5077. post: setMethod('POST'),
  5078. delete: setMethod('DELETE'),
  5079. patch: setMethod('PATCH'),
  5080. head: setMethod('HEAD'),
  5081. options: setMethod('OPTIONS'),
  5082. // type
  5083. json: setType('json'),
  5084. text: setType('text'),
  5085. blob: setType('blob'),
  5086. arrayBuffer: setType('arrayBuffer'),
  5087. formData: setType('formData'),
  5088. };
  5089. function setMethod(method) {
  5090. return (payload, payloadType) => {
  5091. if (!isFetching.value) {
  5092. config.method = method;
  5093. config.payload = payload;
  5094. config.payloadType = payloadType;
  5095. if (isRef(config.payload)) {
  5096. watch(
  5097. [refetch, toRef2(config.payload)],
  5098. ([refetch2]) => refetch2 && execute(),
  5099. { deep: true },
  5100. );
  5101. }
  5102. return {
  5103. ...shell,
  5104. then(onFulfilled, onRejected) {
  5105. return waitUntilFinished().then(onFulfilled, onRejected);
  5106. },
  5107. };
  5108. }
  5109. return void 0;
  5110. };
  5111. }
  5112. function waitUntilFinished() {
  5113. return new Promise((resolve, reject) => {
  5114. until(isFinished)
  5115. .toBe(true)
  5116. .then(() => resolve(shell))
  5117. .catch((error2) => reject(error2));
  5118. });
  5119. }
  5120. function setType(type) {
  5121. return () => {
  5122. if (!isFetching.value) {
  5123. config.type = type;
  5124. return {
  5125. ...shell,
  5126. then(onFulfilled, onRejected) {
  5127. return waitUntilFinished().then(onFulfilled, onRejected);
  5128. },
  5129. };
  5130. }
  5131. return void 0;
  5132. };
  5133. }
  5134. if (options.immediate) Promise.resolve().then(() => execute());
  5135. return {
  5136. ...shell,
  5137. then(onFulfilled, onRejected) {
  5138. return waitUntilFinished().then(onFulfilled, onRejected);
  5139. },
  5140. };
  5141. }
  5142. function joinPaths(start, end) {
  5143. if (!start.endsWith('/') && !end.startsWith('/')) return `${start}/${end}`;
  5144. return `${start}${end}`;
  5145. }
  5146. var DEFAULT_OPTIONS = {
  5147. multiple: true,
  5148. accept: '*',
  5149. reset: false,
  5150. directory: false,
  5151. };
  5152. function useFileDialog(options = {}) {
  5153. const { document: document2 = defaultDocument } = options;
  5154. const files = ref(null);
  5155. const { on: onChange, trigger } = createEventHook();
  5156. let input;
  5157. if (document2) {
  5158. input = document2.createElement('input');
  5159. input.type = 'file';
  5160. input.onchange = (event) => {
  5161. const result = event.target;
  5162. files.value = result.files;
  5163. trigger(files.value);
  5164. };
  5165. }
  5166. const reset = () => {
  5167. files.value = null;
  5168. if (input) {
  5169. input.value = '';
  5170. trigger(null);
  5171. }
  5172. };
  5173. const open = (localOptions) => {
  5174. if (!input) return;
  5175. const _options = {
  5176. ...DEFAULT_OPTIONS,
  5177. ...options,
  5178. ...localOptions,
  5179. };
  5180. input.multiple = _options.multiple;
  5181. input.accept = _options.accept;
  5182. input.webkitdirectory = _options.directory;
  5183. if (hasOwn(_options, 'capture')) input.capture = _options.capture;
  5184. if (_options.reset) reset();
  5185. input.click();
  5186. };
  5187. return {
  5188. files: readonly(files),
  5189. open,
  5190. reset,
  5191. onChange,
  5192. };
  5193. }
  5194. function useFileSystemAccess(options = {}) {
  5195. const { window: _window = defaultWindow, dataType = 'Text' } = options;
  5196. const window2 = _window;
  5197. const isSupported = useSupported(
  5198. () =>
  5199. window2 &&
  5200. 'showSaveFilePicker' in window2 &&
  5201. 'showOpenFilePicker' in window2,
  5202. );
  5203. const fileHandle = ref();
  5204. const data = ref();
  5205. const file = ref();
  5206. const fileName = computed(() => {
  5207. var _a, _b;
  5208. return (_b = (_a = file.value) == null ? void 0 : _a.name) != null
  5209. ? _b
  5210. : '';
  5211. });
  5212. const fileMIME = computed(() => {
  5213. var _a, _b;
  5214. return (_b = (_a = file.value) == null ? void 0 : _a.type) != null
  5215. ? _b
  5216. : '';
  5217. });
  5218. const fileSize = computed(() => {
  5219. var _a, _b;
  5220. return (_b = (_a = file.value) == null ? void 0 : _a.size) != null ? _b : 0;
  5221. });
  5222. const fileLastModified = computed(() => {
  5223. var _a, _b;
  5224. return (_b = (_a = file.value) == null ? void 0 : _a.lastModified) != null
  5225. ? _b
  5226. : 0;
  5227. });
  5228. async function open(_options = {}) {
  5229. if (!isSupported.value) return;
  5230. const [handle] = await window2.showOpenFilePicker({
  5231. ...toValue(options),
  5232. ..._options,
  5233. });
  5234. fileHandle.value = handle;
  5235. await updateData();
  5236. }
  5237. async function create(_options = {}) {
  5238. if (!isSupported.value) return;
  5239. fileHandle.value = await window2.showSaveFilePicker({
  5240. ...options,
  5241. ..._options,
  5242. });
  5243. data.value = void 0;
  5244. await updateData();
  5245. }
  5246. async function save(_options = {}) {
  5247. if (!isSupported.value) return;
  5248. if (!fileHandle.value) return saveAs(_options);
  5249. if (data.value) {
  5250. const writableStream = await fileHandle.value.createWritable();
  5251. await writableStream.write(data.value);
  5252. await writableStream.close();
  5253. }
  5254. await updateFile();
  5255. }
  5256. async function saveAs(_options = {}) {
  5257. if (!isSupported.value) return;
  5258. fileHandle.value = await window2.showSaveFilePicker({
  5259. ...options,
  5260. ..._options,
  5261. });
  5262. if (data.value) {
  5263. const writableStream = await fileHandle.value.createWritable();
  5264. await writableStream.write(data.value);
  5265. await writableStream.close();
  5266. }
  5267. await updateFile();
  5268. }
  5269. async function updateFile() {
  5270. var _a;
  5271. file.value = await ((_a = fileHandle.value) == null
  5272. ? void 0
  5273. : _a.getFile());
  5274. }
  5275. async function updateData() {
  5276. var _a, _b;
  5277. await updateFile();
  5278. const type = toValue(dataType);
  5279. if (type === 'Text')
  5280. data.value = await ((_a = file.value) == null ? void 0 : _a.text());
  5281. else if (type === 'ArrayBuffer')
  5282. data.value = await ((_b = file.value) == null
  5283. ? void 0
  5284. : _b.arrayBuffer());
  5285. else if (type === 'Blob') data.value = file.value;
  5286. }
  5287. watch(() => toValue(dataType), updateData);
  5288. return {
  5289. isSupported,
  5290. data,
  5291. file,
  5292. fileName,
  5293. fileMIME,
  5294. fileSize,
  5295. fileLastModified,
  5296. open,
  5297. create,
  5298. save,
  5299. saveAs,
  5300. updateData,
  5301. };
  5302. }
  5303. function useFocus(target, options = {}) {
  5304. const { initialValue = false, focusVisible = false } = options;
  5305. const innerFocused = ref(false);
  5306. const targetElement = computed(() => unrefElement(target));
  5307. useEventListener(targetElement, 'focus', (event) => {
  5308. var _a, _b;
  5309. if (
  5310. !focusVisible ||
  5311. ((_b = (_a = event.target).matches) == null
  5312. ? void 0
  5313. : _b.call(_a, ':focus-visible'))
  5314. )
  5315. innerFocused.value = true;
  5316. });
  5317. useEventListener(targetElement, 'blur', () => (innerFocused.value = false));
  5318. const focused = computed({
  5319. get: () => innerFocused.value,
  5320. set(value) {
  5321. var _a, _b;
  5322. if (!value && innerFocused.value)
  5323. (_a = targetElement.value) == null ? void 0 : _a.blur();
  5324. else if (value && !innerFocused.value)
  5325. (_b = targetElement.value) == null ? void 0 : _b.focus();
  5326. },
  5327. });
  5328. watch(
  5329. targetElement,
  5330. () => {
  5331. focused.value = initialValue;
  5332. },
  5333. { immediate: true, flush: 'post' },
  5334. );
  5335. return { focused };
  5336. }
  5337. function useFocusWithin(target, options = {}) {
  5338. const activeElement = useActiveElement(options);
  5339. const targetElement = computed(() => unrefElement(target));
  5340. const focused = computed(() =>
  5341. targetElement.value && activeElement.value
  5342. ? targetElement.value.contains(activeElement.value)
  5343. : false,
  5344. );
  5345. return { focused };
  5346. }
  5347. function useFps(options) {
  5348. var _a;
  5349. const fps = ref(0);
  5350. if (typeof performance === 'undefined') return fps;
  5351. const every =
  5352. (_a = options == null ? void 0 : options.every) != null ? _a : 10;
  5353. let last = performance.now();
  5354. let ticks = 0;
  5355. useRafFn(() => {
  5356. ticks += 1;
  5357. if (ticks >= every) {
  5358. const now2 = performance.now();
  5359. const diff = now2 - last;
  5360. fps.value = Math.round(1e3 / (diff / ticks));
  5361. last = now2;
  5362. ticks = 0;
  5363. }
  5364. });
  5365. return fps;
  5366. }
  5367. var eventHandlers = [
  5368. 'fullscreenchange',
  5369. 'webkitfullscreenchange',
  5370. 'webkitendfullscreen',
  5371. 'mozfullscreenchange',
  5372. 'MSFullscreenChange',
  5373. ];
  5374. function useFullscreen(target, options = {}) {
  5375. const { document: document2 = defaultDocument, autoExit = false } = options;
  5376. const targetRef = computed(() => {
  5377. var _a;
  5378. return (_a = unrefElement(target)) != null
  5379. ? _a
  5380. : document2 == null
  5381. ? void 0
  5382. : document2.querySelector('html');
  5383. });
  5384. const isFullscreen = ref(false);
  5385. const requestMethod = computed(() => {
  5386. return [
  5387. 'requestFullscreen',
  5388. 'webkitRequestFullscreen',
  5389. 'webkitEnterFullscreen',
  5390. 'webkitEnterFullScreen',
  5391. 'webkitRequestFullScreen',
  5392. 'mozRequestFullScreen',
  5393. 'msRequestFullscreen',
  5394. ].find(
  5395. (m) =>
  5396. (document2 && m in document2) ||
  5397. (targetRef.value && m in targetRef.value),
  5398. );
  5399. });
  5400. const exitMethod = computed(() => {
  5401. return [
  5402. 'exitFullscreen',
  5403. 'webkitExitFullscreen',
  5404. 'webkitExitFullScreen',
  5405. 'webkitCancelFullScreen',
  5406. 'mozCancelFullScreen',
  5407. 'msExitFullscreen',
  5408. ].find(
  5409. (m) =>
  5410. (document2 && m in document2) ||
  5411. (targetRef.value && m in targetRef.value),
  5412. );
  5413. });
  5414. const fullscreenEnabled = computed(() => {
  5415. return [
  5416. 'fullScreen',
  5417. 'webkitIsFullScreen',
  5418. 'webkitDisplayingFullscreen',
  5419. 'mozFullScreen',
  5420. 'msFullscreenElement',
  5421. ].find(
  5422. (m) =>
  5423. (document2 && m in document2) ||
  5424. (targetRef.value && m in targetRef.value),
  5425. );
  5426. });
  5427. const fullscreenElementMethod = [
  5428. 'fullscreenElement',
  5429. 'webkitFullscreenElement',
  5430. 'mozFullScreenElement',
  5431. 'msFullscreenElement',
  5432. ].find((m) => document2 && m in document2);
  5433. const isSupported = useSupported(
  5434. () =>
  5435. targetRef.value &&
  5436. document2 &&
  5437. requestMethod.value !== void 0 &&
  5438. exitMethod.value !== void 0 &&
  5439. fullscreenEnabled.value !== void 0,
  5440. );
  5441. const isCurrentElementFullScreen = () => {
  5442. if (fullscreenElementMethod)
  5443. return (
  5444. (document2 == null ? void 0 : document2[fullscreenElementMethod]) ===
  5445. targetRef.value
  5446. );
  5447. return false;
  5448. };
  5449. const isElementFullScreen = () => {
  5450. if (fullscreenEnabled.value) {
  5451. if (document2 && document2[fullscreenEnabled.value] != null) {
  5452. return document2[fullscreenEnabled.value];
  5453. } else {
  5454. const target2 = targetRef.value;
  5455. if (
  5456. (target2 == null ? void 0 : target2[fullscreenEnabled.value]) != null
  5457. ) {
  5458. return Boolean(target2[fullscreenEnabled.value]);
  5459. }
  5460. }
  5461. }
  5462. return false;
  5463. };
  5464. async function exit() {
  5465. if (!isSupported.value || !isFullscreen.value) return;
  5466. if (exitMethod.value) {
  5467. if ((document2 == null ? void 0 : document2[exitMethod.value]) != null) {
  5468. await document2[exitMethod.value]();
  5469. } else {
  5470. const target2 = targetRef.value;
  5471. if ((target2 == null ? void 0 : target2[exitMethod.value]) != null)
  5472. await target2[exitMethod.value]();
  5473. }
  5474. }
  5475. isFullscreen.value = false;
  5476. }
  5477. async function enter() {
  5478. if (!isSupported.value || isFullscreen.value) return;
  5479. if (isElementFullScreen()) await exit();
  5480. const target2 = targetRef.value;
  5481. if (
  5482. requestMethod.value &&
  5483. (target2 == null ? void 0 : target2[requestMethod.value]) != null
  5484. ) {
  5485. await target2[requestMethod.value]();
  5486. isFullscreen.value = true;
  5487. }
  5488. }
  5489. async function toggle() {
  5490. await (isFullscreen.value ? exit() : enter());
  5491. }
  5492. const handlerCallback = () => {
  5493. const isElementFullScreenValue = isElementFullScreen();
  5494. if (
  5495. !isElementFullScreenValue ||
  5496. (isElementFullScreenValue && isCurrentElementFullScreen())
  5497. )
  5498. isFullscreen.value = isElementFullScreenValue;
  5499. };
  5500. useEventListener(document2, eventHandlers, handlerCallback, false);
  5501. useEventListener(
  5502. () => unrefElement(targetRef),
  5503. eventHandlers,
  5504. handlerCallback,
  5505. false,
  5506. );
  5507. if (autoExit) tryOnScopeDispose(exit);
  5508. return {
  5509. isSupported,
  5510. isFullscreen,
  5511. enter,
  5512. exit,
  5513. toggle,
  5514. };
  5515. }
  5516. function mapGamepadToXbox360Controller(gamepad) {
  5517. return computed(() => {
  5518. if (gamepad.value) {
  5519. return {
  5520. buttons: {
  5521. a: gamepad.value.buttons[0],
  5522. b: gamepad.value.buttons[1],
  5523. x: gamepad.value.buttons[2],
  5524. y: gamepad.value.buttons[3],
  5525. },
  5526. bumper: {
  5527. left: gamepad.value.buttons[4],
  5528. right: gamepad.value.buttons[5],
  5529. },
  5530. triggers: {
  5531. left: gamepad.value.buttons[6],
  5532. right: gamepad.value.buttons[7],
  5533. },
  5534. stick: {
  5535. left: {
  5536. horizontal: gamepad.value.axes[0],
  5537. vertical: gamepad.value.axes[1],
  5538. button: gamepad.value.buttons[10],
  5539. },
  5540. right: {
  5541. horizontal: gamepad.value.axes[2],
  5542. vertical: gamepad.value.axes[3],
  5543. button: gamepad.value.buttons[11],
  5544. },
  5545. },
  5546. dpad: {
  5547. up: gamepad.value.buttons[12],
  5548. down: gamepad.value.buttons[13],
  5549. left: gamepad.value.buttons[14],
  5550. right: gamepad.value.buttons[15],
  5551. },
  5552. back: gamepad.value.buttons[8],
  5553. start: gamepad.value.buttons[9],
  5554. };
  5555. }
  5556. return null;
  5557. });
  5558. }
  5559. function useGamepad(options = {}) {
  5560. const { navigator = defaultNavigator } = options;
  5561. const isSupported = useSupported(
  5562. () => navigator && 'getGamepads' in navigator,
  5563. );
  5564. const gamepads = ref([]);
  5565. const onConnectedHook = createEventHook();
  5566. const onDisconnectedHook = createEventHook();
  5567. const stateFromGamepad = (gamepad) => {
  5568. const hapticActuators = [];
  5569. const vibrationActuator =
  5570. 'vibrationActuator' in gamepad ? gamepad.vibrationActuator : null;
  5571. if (vibrationActuator) hapticActuators.push(vibrationActuator);
  5572. if (gamepad.hapticActuators)
  5573. hapticActuators.push(...gamepad.hapticActuators);
  5574. return {
  5575. ...gamepad,
  5576. id: gamepad.id,
  5577. hapticActuators,
  5578. axes: gamepad.axes.map((axes) => axes),
  5579. buttons: gamepad.buttons.map((button) => ({
  5580. pressed: button.pressed,
  5581. touched: button.touched,
  5582. value: button.value,
  5583. })),
  5584. index: gamepad.index,
  5585. };
  5586. };
  5587. const updateGamepadState = () => {
  5588. const _gamepads =
  5589. (navigator == null ? void 0 : navigator.getGamepads()) || [];
  5590. for (const gamepad of _gamepads) {
  5591. if (gamepad && gamepads.value[gamepad.index])
  5592. gamepads.value[gamepad.index] = stateFromGamepad(gamepad);
  5593. }
  5594. };
  5595. const { isActive, pause, resume } = useRafFn(updateGamepadState);
  5596. const onGamepadConnected = (gamepad) => {
  5597. if (!gamepads.value.some(({ index }) => index === gamepad.index)) {
  5598. gamepads.value.push(stateFromGamepad(gamepad));
  5599. onConnectedHook.trigger(gamepad.index);
  5600. }
  5601. resume();
  5602. };
  5603. const onGamepadDisconnected = (gamepad) => {
  5604. gamepads.value = gamepads.value.filter((x) => x.index !== gamepad.index);
  5605. onDisconnectedHook.trigger(gamepad.index);
  5606. };
  5607. useEventListener('gamepadconnected', (e) => onGamepadConnected(e.gamepad));
  5608. useEventListener('gamepaddisconnected', (e) =>
  5609. onGamepadDisconnected(e.gamepad),
  5610. );
  5611. tryOnMounted(() => {
  5612. const _gamepads =
  5613. (navigator == null ? void 0 : navigator.getGamepads()) || [];
  5614. for (const gamepad of _gamepads) {
  5615. if (gamepad && gamepads.value[gamepad.index]) onGamepadConnected(gamepad);
  5616. }
  5617. });
  5618. pause();
  5619. return {
  5620. isSupported,
  5621. onConnected: onConnectedHook.on,
  5622. onDisconnected: onDisconnectedHook.on,
  5623. gamepads,
  5624. pause,
  5625. resume,
  5626. isActive,
  5627. };
  5628. }
  5629. function useGeolocation(options = {}) {
  5630. const {
  5631. enableHighAccuracy = true,
  5632. maximumAge = 3e4,
  5633. timeout = 27e3,
  5634. navigator = defaultNavigator,
  5635. immediate = true,
  5636. } = options;
  5637. const isSupported = useSupported(
  5638. () => navigator && 'geolocation' in navigator,
  5639. );
  5640. const locatedAt = ref(null);
  5641. const error = shallowRef(null);
  5642. const coords = ref({
  5643. accuracy: 0,
  5644. latitude: Number.POSITIVE_INFINITY,
  5645. longitude: Number.POSITIVE_INFINITY,
  5646. altitude: null,
  5647. altitudeAccuracy: null,
  5648. heading: null,
  5649. speed: null,
  5650. });
  5651. function updatePosition(position) {
  5652. locatedAt.value = position.timestamp;
  5653. coords.value = position.coords;
  5654. error.value = null;
  5655. }
  5656. let watcher;
  5657. function resume() {
  5658. if (isSupported.value) {
  5659. watcher = navigator.geolocation.watchPosition(
  5660. updatePosition,
  5661. (err) => (error.value = err),
  5662. {
  5663. enableHighAccuracy,
  5664. maximumAge,
  5665. timeout,
  5666. },
  5667. );
  5668. }
  5669. }
  5670. if (immediate) resume();
  5671. function pause() {
  5672. if (watcher && navigator) navigator.geolocation.clearWatch(watcher);
  5673. }
  5674. tryOnScopeDispose(() => {
  5675. pause();
  5676. });
  5677. return {
  5678. isSupported,
  5679. coords,
  5680. locatedAt,
  5681. error,
  5682. resume,
  5683. pause,
  5684. };
  5685. }
  5686. var defaultEvents$1 = [
  5687. 'mousemove',
  5688. 'mousedown',
  5689. 'resize',
  5690. 'keydown',
  5691. 'touchstart',
  5692. 'wheel',
  5693. ];
  5694. var oneMinute = 6e4;
  5695. function useIdle(timeout = oneMinute, options = {}) {
  5696. const {
  5697. initialState = false,
  5698. listenForVisibilityChange = true,
  5699. events: events2 = defaultEvents$1,
  5700. window: window2 = defaultWindow,
  5701. eventFilter = throttleFilter(50),
  5702. } = options;
  5703. const idle = ref(initialState);
  5704. const lastActive = ref(timestamp());
  5705. let timer;
  5706. const reset = () => {
  5707. idle.value = false;
  5708. clearTimeout(timer);
  5709. timer = setTimeout(() => (idle.value = true), timeout);
  5710. };
  5711. const onEvent = createFilterWrapper(eventFilter, () => {
  5712. lastActive.value = timestamp();
  5713. reset();
  5714. });
  5715. if (window2) {
  5716. const document2 = window2.document;
  5717. for (const event of events2)
  5718. useEventListener(window2, event, onEvent, { passive: true });
  5719. if (listenForVisibilityChange) {
  5720. useEventListener(document2, 'visibilitychange', () => {
  5721. if (!document2.hidden) onEvent();
  5722. });
  5723. }
  5724. reset();
  5725. }
  5726. return {
  5727. idle,
  5728. lastActive,
  5729. reset,
  5730. };
  5731. }
  5732. async function loadImage(options) {
  5733. return new Promise((resolve, reject) => {
  5734. const img = new Image();
  5735. const {
  5736. src,
  5737. srcset,
  5738. sizes,
  5739. class: clazz,
  5740. loading,
  5741. crossorigin,
  5742. referrerPolicy,
  5743. } = options;
  5744. img.src = src;
  5745. if (srcset) img.srcset = srcset;
  5746. if (sizes) img.sizes = sizes;
  5747. if (clazz) img.className = clazz;
  5748. if (loading) img.loading = loading;
  5749. if (crossorigin) img.crossOrigin = crossorigin;
  5750. if (referrerPolicy) img.referrerPolicy = referrerPolicy;
  5751. img.onload = () => resolve(img);
  5752. img.onerror = reject;
  5753. });
  5754. }
  5755. function useImage(options, asyncStateOptions = {}) {
  5756. const state = useAsyncState(() => loadImage(toValue(options)), void 0, {
  5757. resetOnExecute: true,
  5758. ...asyncStateOptions,
  5759. });
  5760. watch(
  5761. () => toValue(options),
  5762. () => state.execute(asyncStateOptions.delay),
  5763. { deep: true },
  5764. );
  5765. return state;
  5766. }
  5767. var ARRIVED_STATE_THRESHOLD_PIXELS = 1;
  5768. function useScroll(element, options = {}) {
  5769. const {
  5770. throttle = 0,
  5771. idle = 200,
  5772. onStop = noop,
  5773. onScroll = noop,
  5774. offset = {
  5775. left: 0,
  5776. right: 0,
  5777. top: 0,
  5778. bottom: 0,
  5779. },
  5780. eventListenerOptions = {
  5781. capture: false,
  5782. passive: true,
  5783. },
  5784. behavior = 'auto',
  5785. window: window2 = defaultWindow,
  5786. onError = (e) => {
  5787. console.error(e);
  5788. },
  5789. } = options;
  5790. const internalX = ref(0);
  5791. const internalY = ref(0);
  5792. const x = computed({
  5793. get() {
  5794. return internalX.value;
  5795. },
  5796. set(x2) {
  5797. scrollTo2(x2, void 0);
  5798. },
  5799. });
  5800. const y = computed({
  5801. get() {
  5802. return internalY.value;
  5803. },
  5804. set(y2) {
  5805. scrollTo2(void 0, y2);
  5806. },
  5807. });
  5808. function scrollTo2(_x, _y) {
  5809. var _a, _b, _c;
  5810. if (!window2) return;
  5811. const _element = toValue(element);
  5812. if (!_element) return;
  5813. (_c = _element instanceof Document ? window2.document.body : _element) ==
  5814. null
  5815. ? void 0
  5816. : _c.scrollTo({
  5817. top: (_a = toValue(_y)) != null ? _a : y.value,
  5818. left: (_b = toValue(_x)) != null ? _b : x.value,
  5819. behavior: toValue(behavior),
  5820. });
  5821. }
  5822. const isScrolling = ref(false);
  5823. const arrivedState = reactive({
  5824. left: true,
  5825. right: false,
  5826. top: true,
  5827. bottom: false,
  5828. });
  5829. const directions = reactive({
  5830. left: false,
  5831. right: false,
  5832. top: false,
  5833. bottom: false,
  5834. });
  5835. const onScrollEnd = (e) => {
  5836. if (!isScrolling.value) return;
  5837. isScrolling.value = false;
  5838. directions.left = false;
  5839. directions.right = false;
  5840. directions.top = false;
  5841. directions.bottom = false;
  5842. onStop(e);
  5843. };
  5844. const onScrollEndDebounced = useDebounceFn(onScrollEnd, throttle + idle);
  5845. const setArrivedState = (target) => {
  5846. var _a;
  5847. if (!window2) return;
  5848. const el =
  5849. ((_a = target == null ? void 0 : target.document) == null
  5850. ? void 0
  5851. : _a.documentElement) ||
  5852. (target == null ? void 0 : target.documentElement) ||
  5853. unrefElement(target);
  5854. const { display, flexDirection } = getComputedStyle(el);
  5855. const scrollLeft = el.scrollLeft;
  5856. directions.left = scrollLeft < internalX.value;
  5857. directions.right = scrollLeft > internalX.value;
  5858. const left = Math.abs(scrollLeft) <= (offset.left || 0);
  5859. const right =
  5860. Math.abs(scrollLeft) + el.clientWidth >=
  5861. el.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
  5862. if (display === 'flex' && flexDirection === 'row-reverse') {
  5863. arrivedState.left = right;
  5864. arrivedState.right = left;
  5865. } else {
  5866. arrivedState.left = left;
  5867. arrivedState.right = right;
  5868. }
  5869. internalX.value = scrollLeft;
  5870. let scrollTop = el.scrollTop;
  5871. if (target === window2.document && !scrollTop)
  5872. scrollTop = window2.document.body.scrollTop;
  5873. directions.top = scrollTop < internalY.value;
  5874. directions.bottom = scrollTop > internalY.value;
  5875. const top = Math.abs(scrollTop) <= (offset.top || 0);
  5876. const bottom =
  5877. Math.abs(scrollTop) + el.clientHeight >=
  5878. el.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
  5879. if (display === 'flex' && flexDirection === 'column-reverse') {
  5880. arrivedState.top = bottom;
  5881. arrivedState.bottom = top;
  5882. } else {
  5883. arrivedState.top = top;
  5884. arrivedState.bottom = bottom;
  5885. }
  5886. internalY.value = scrollTop;
  5887. };
  5888. const onScrollHandler = (e) => {
  5889. var _a;
  5890. if (!window2) return;
  5891. const eventTarget = (_a = e.target.documentElement) != null ? _a : e.target;
  5892. setArrivedState(eventTarget);
  5893. isScrolling.value = true;
  5894. onScrollEndDebounced(e);
  5895. onScroll(e);
  5896. };
  5897. useEventListener(
  5898. element,
  5899. 'scroll',
  5900. throttle
  5901. ? useThrottleFn(onScrollHandler, throttle, true, false)
  5902. : onScrollHandler,
  5903. eventListenerOptions,
  5904. );
  5905. tryOnMounted(() => {
  5906. try {
  5907. const _element = toValue(element);
  5908. if (!_element) return;
  5909. setArrivedState(_element);
  5910. } catch (e) {
  5911. onError(e);
  5912. }
  5913. });
  5914. useEventListener(element, 'scrollend', onScrollEnd, eventListenerOptions);
  5915. return {
  5916. x,
  5917. y,
  5918. isScrolling,
  5919. arrivedState,
  5920. directions,
  5921. measure() {
  5922. const _element = toValue(element);
  5923. if (window2 && _element) setArrivedState(_element);
  5924. },
  5925. };
  5926. }
  5927. function resolveElement(el) {
  5928. if (typeof Window !== 'undefined' && el instanceof Window)
  5929. return el.document.documentElement;
  5930. if (typeof Document !== 'undefined' && el instanceof Document)
  5931. return el.documentElement;
  5932. return el;
  5933. }
  5934. function useInfiniteScroll(element, onLoadMore, options = {}) {
  5935. var _a;
  5936. const {
  5937. direction = 'bottom',
  5938. interval = 100,
  5939. canLoadMore = () => true,
  5940. } = options;
  5941. const state = reactive(
  5942. useScroll(element, {
  5943. ...options,
  5944. offset: {
  5945. [direction]: (_a = options.distance) != null ? _a : 0,
  5946. ...options.offset,
  5947. },
  5948. }),
  5949. );
  5950. const promise = ref();
  5951. const isLoading = computed(() => !!promise.value);
  5952. const observedElement = computed(() => {
  5953. return resolveElement(toValue(element));
  5954. });
  5955. const isElementVisible = useElementVisibility(observedElement);
  5956. function checkAndLoad() {
  5957. state.measure();
  5958. if (
  5959. !observedElement.value ||
  5960. !isElementVisible.value ||
  5961. !canLoadMore(observedElement.value)
  5962. )
  5963. return;
  5964. const { scrollHeight, clientHeight, scrollWidth, clientWidth } =
  5965. observedElement.value;
  5966. const isNarrower =
  5967. direction === 'bottom' || direction === 'top'
  5968. ? scrollHeight <= clientHeight
  5969. : scrollWidth <= clientWidth;
  5970. if (state.arrivedState[direction] || isNarrower) {
  5971. if (!promise.value) {
  5972. promise.value = Promise.all([
  5973. onLoadMore(state),
  5974. new Promise((resolve) => setTimeout(resolve, interval)),
  5975. ]).finally(() => {
  5976. promise.value = null;
  5977. nextTick(() => checkAndLoad());
  5978. });
  5979. }
  5980. }
  5981. }
  5982. watch(
  5983. () => [state.arrivedState[direction], isElementVisible.value],
  5984. checkAndLoad,
  5985. { immediate: true },
  5986. );
  5987. return {
  5988. isLoading,
  5989. };
  5990. }
  5991. var defaultEvents = ['mousedown', 'mouseup', 'keydown', 'keyup'];
  5992. function useKeyModifier(modifier, options = {}) {
  5993. const {
  5994. events: events2 = defaultEvents,
  5995. document: document2 = defaultDocument,
  5996. initial = null,
  5997. } = options;
  5998. const state = ref(initial);
  5999. if (document2) {
  6000. events2.forEach((listenerEvent) => {
  6001. useEventListener(document2, listenerEvent, (evt) => {
  6002. if (typeof evt.getModifierState === 'function')
  6003. state.value = evt.getModifierState(modifier);
  6004. });
  6005. });
  6006. }
  6007. return state;
  6008. }
  6009. function useLocalStorage(key, initialValue, options = {}) {
  6010. const { window: window2 = defaultWindow } = options;
  6011. return useStorage(
  6012. key,
  6013. initialValue,
  6014. window2 == null ? void 0 : window2.localStorage,
  6015. options,
  6016. );
  6017. }
  6018. var DefaultMagicKeysAliasMap = {
  6019. ctrl: 'control',
  6020. command: 'meta',
  6021. cmd: 'meta',
  6022. option: 'alt',
  6023. up: 'arrowup',
  6024. down: 'arrowdown',
  6025. left: 'arrowleft',
  6026. right: 'arrowright',
  6027. };
  6028. function useMagicKeys(options = {}) {
  6029. const {
  6030. reactive: useReactive = false,
  6031. target = defaultWindow,
  6032. aliasMap = DefaultMagicKeysAliasMap,
  6033. passive = true,
  6034. onEventFired = noop,
  6035. } = options;
  6036. const current = reactive(/* @__PURE__ */ new Set());
  6037. const obj = {
  6038. toJSON() {
  6039. return {};
  6040. },
  6041. current,
  6042. };
  6043. const refs = useReactive ? reactive(obj) : obj;
  6044. const metaDeps = /* @__PURE__ */ new Set();
  6045. const usedKeys = /* @__PURE__ */ new Set();
  6046. function setRefs(key, value) {
  6047. if (key in refs) {
  6048. if (useReactive) refs[key] = value;
  6049. else refs[key].value = value;
  6050. }
  6051. }
  6052. function reset() {
  6053. current.clear();
  6054. for (const key of usedKeys) setRefs(key, false);
  6055. }
  6056. function updateRefs(e, value) {
  6057. var _a, _b;
  6058. const key = (_a = e.key) == null ? void 0 : _a.toLowerCase();
  6059. const code = (_b = e.code) == null ? void 0 : _b.toLowerCase();
  6060. const values = [code, key].filter(Boolean);
  6061. if (key) {
  6062. if (value) current.add(key);
  6063. else current.delete(key);
  6064. }
  6065. for (const key2 of values) {
  6066. usedKeys.add(key2);
  6067. setRefs(key2, value);
  6068. }
  6069. if (key === 'meta' && !value) {
  6070. metaDeps.forEach((key2) => {
  6071. current.delete(key2);
  6072. setRefs(key2, false);
  6073. });
  6074. metaDeps.clear();
  6075. } else if (
  6076. typeof e.getModifierState === 'function' &&
  6077. e.getModifierState('Meta') &&
  6078. value
  6079. ) {
  6080. [...current, ...values].forEach((key2) => metaDeps.add(key2));
  6081. }
  6082. }
  6083. useEventListener(
  6084. target,
  6085. 'keydown',
  6086. (e) => {
  6087. updateRefs(e, true);
  6088. return onEventFired(e);
  6089. },
  6090. { passive },
  6091. );
  6092. useEventListener(
  6093. target,
  6094. 'keyup',
  6095. (e) => {
  6096. updateRefs(e, false);
  6097. return onEventFired(e);
  6098. },
  6099. { passive },
  6100. );
  6101. useEventListener('blur', reset, { passive: true });
  6102. useEventListener('focus', reset, { passive: true });
  6103. const proxy = new Proxy(refs, {
  6104. get(target2, prop, rec) {
  6105. if (typeof prop !== 'string') return Reflect.get(target2, prop, rec);
  6106. prop = prop.toLowerCase();
  6107. if (prop in aliasMap) prop = aliasMap[prop];
  6108. if (!(prop in refs)) {
  6109. if (/[+_-]/.test(prop)) {
  6110. const keys2 = prop.split(/[+_-]/g).map((i) => i.trim());
  6111. refs[prop] = computed(() =>
  6112. keys2.every((key) => toValue(proxy[key])),
  6113. );
  6114. } else {
  6115. refs[prop] = ref(false);
  6116. }
  6117. }
  6118. const r = Reflect.get(target2, prop, rec);
  6119. return useReactive ? toValue(r) : r;
  6120. },
  6121. });
  6122. return proxy;
  6123. }
  6124. function usingElRef(source, cb) {
  6125. if (toValue(source)) cb(toValue(source));
  6126. }
  6127. function timeRangeToArray(timeRanges) {
  6128. let ranges = [];
  6129. for (let i = 0; i < timeRanges.length; ++i)
  6130. ranges = [...ranges, [timeRanges.start(i), timeRanges.end(i)]];
  6131. return ranges;
  6132. }
  6133. function tracksToArray(tracks) {
  6134. return Array.from(tracks).map(
  6135. (
  6136. {
  6137. label,
  6138. kind,
  6139. language,
  6140. mode,
  6141. activeCues,
  6142. cues,
  6143. inBandMetadataTrackDispatchType,
  6144. },
  6145. id,
  6146. ) => ({
  6147. id,
  6148. label,
  6149. kind,
  6150. language,
  6151. mode,
  6152. activeCues,
  6153. cues,
  6154. inBandMetadataTrackDispatchType,
  6155. }),
  6156. );
  6157. }
  6158. var defaultOptions = {
  6159. src: '',
  6160. tracks: [],
  6161. };
  6162. function useMediaControls(target, options = {}) {
  6163. options = {
  6164. ...defaultOptions,
  6165. ...options,
  6166. };
  6167. const { document: document2 = defaultDocument } = options;
  6168. const currentTime = ref(0);
  6169. const duration = ref(0);
  6170. const seeking = ref(false);
  6171. const volume = ref(1);
  6172. const waiting = ref(false);
  6173. const ended = ref(false);
  6174. const playing = ref(false);
  6175. const rate = ref(1);
  6176. const stalled = ref(false);
  6177. const buffered = ref([]);
  6178. const tracks = ref([]);
  6179. const selectedTrack = ref(-1);
  6180. const isPictureInPicture = ref(false);
  6181. const muted = ref(false);
  6182. const supportsPictureInPicture =
  6183. document2 && 'pictureInPictureEnabled' in document2;
  6184. const sourceErrorEvent = createEventHook();
  6185. const disableTrack = (track) => {
  6186. usingElRef(target, (el) => {
  6187. if (track) {
  6188. const id = typeof track === 'number' ? track : track.id;
  6189. el.textTracks[id].mode = 'disabled';
  6190. } else {
  6191. for (let i = 0; i < el.textTracks.length; ++i)
  6192. el.textTracks[i].mode = 'disabled';
  6193. }
  6194. selectedTrack.value = -1;
  6195. });
  6196. };
  6197. const enableTrack = (track, disableTracks = true) => {
  6198. usingElRef(target, (el) => {
  6199. const id = typeof track === 'number' ? track : track.id;
  6200. if (disableTracks) disableTrack();
  6201. el.textTracks[id].mode = 'showing';
  6202. selectedTrack.value = id;
  6203. });
  6204. };
  6205. const togglePictureInPicture = () => {
  6206. return new Promise((resolve, reject) => {
  6207. usingElRef(target, async (el) => {
  6208. if (supportsPictureInPicture) {
  6209. if (!isPictureInPicture.value) {
  6210. el.requestPictureInPicture().then(resolve).catch(reject);
  6211. } else {
  6212. document2.exitPictureInPicture().then(resolve).catch(reject);
  6213. }
  6214. }
  6215. });
  6216. });
  6217. };
  6218. watchEffect(() => {
  6219. if (!document2) return;
  6220. const el = toValue(target);
  6221. if (!el) return;
  6222. const src = toValue(options.src);
  6223. let sources = [];
  6224. if (!src) return;
  6225. if (typeof src === 'string') sources = [{ src }];
  6226. else if (Array.isArray(src)) sources = src;
  6227. else if (isObject(src)) sources = [src];
  6228. el.querySelectorAll('source').forEach((e) => {
  6229. e.removeEventListener('error', sourceErrorEvent.trigger);
  6230. e.remove();
  6231. });
  6232. sources.forEach(({ src: src2, type }) => {
  6233. const source = document2.createElement('source');
  6234. source.setAttribute('src', src2);
  6235. source.setAttribute('type', type || '');
  6236. source.addEventListener('error', sourceErrorEvent.trigger);
  6237. el.appendChild(source);
  6238. });
  6239. el.load();
  6240. });
  6241. tryOnScopeDispose(() => {
  6242. const el = toValue(target);
  6243. if (!el) return;
  6244. el.querySelectorAll('source').forEach((e) =>
  6245. e.removeEventListener('error', sourceErrorEvent.trigger),
  6246. );
  6247. });
  6248. watch([target, volume], () => {
  6249. const el = toValue(target);
  6250. if (!el) return;
  6251. el.volume = volume.value;
  6252. });
  6253. watch([target, muted], () => {
  6254. const el = toValue(target);
  6255. if (!el) return;
  6256. el.muted = muted.value;
  6257. });
  6258. watch([target, rate], () => {
  6259. const el = toValue(target);
  6260. if (!el) return;
  6261. el.playbackRate = rate.value;
  6262. });
  6263. watchEffect(() => {
  6264. if (!document2) return;
  6265. const textTracks = toValue(options.tracks);
  6266. const el = toValue(target);
  6267. if (!textTracks || !textTracks.length || !el) return;
  6268. el.querySelectorAll('track').forEach((e) => e.remove());
  6269. textTracks.forEach(
  6270. ({ default: isDefault, kind, label, src, srcLang }, i) => {
  6271. const track = document2.createElement('track');
  6272. track.default = isDefault || false;
  6273. track.kind = kind;
  6274. track.label = label;
  6275. track.src = src;
  6276. track.srclang = srcLang;
  6277. if (track.default) selectedTrack.value = i;
  6278. el.appendChild(track);
  6279. },
  6280. );
  6281. });
  6282. const { ignoreUpdates: ignoreCurrentTimeUpdates } = watchIgnorable(
  6283. currentTime,
  6284. (time) => {
  6285. const el = toValue(target);
  6286. if (!el) return;
  6287. el.currentTime = time;
  6288. },
  6289. );
  6290. const { ignoreUpdates: ignorePlayingUpdates } = watchIgnorable(
  6291. playing,
  6292. (isPlaying) => {
  6293. const el = toValue(target);
  6294. if (!el) return;
  6295. isPlaying ? el.play() : el.pause();
  6296. },
  6297. );
  6298. useEventListener(target, 'timeupdate', () =>
  6299. ignoreCurrentTimeUpdates(
  6300. () => (currentTime.value = toValue(target).currentTime),
  6301. ),
  6302. );
  6303. useEventListener(
  6304. target,
  6305. 'durationchange',
  6306. () => (duration.value = toValue(target).duration),
  6307. );
  6308. useEventListener(
  6309. target,
  6310. 'progress',
  6311. () => (buffered.value = timeRangeToArray(toValue(target).buffered)),
  6312. );
  6313. useEventListener(target, 'seeking', () => (seeking.value = true));
  6314. useEventListener(target, 'seeked', () => (seeking.value = false));
  6315. useEventListener(target, ['waiting', 'loadstart'], () => {
  6316. waiting.value = true;
  6317. ignorePlayingUpdates(() => (playing.value = false));
  6318. });
  6319. useEventListener(target, 'loadeddata', () => (waiting.value = false));
  6320. useEventListener(target, 'playing', () => {
  6321. waiting.value = false;
  6322. ended.value = false;
  6323. ignorePlayingUpdates(() => (playing.value = true));
  6324. });
  6325. useEventListener(
  6326. target,
  6327. 'ratechange',
  6328. () => (rate.value = toValue(target).playbackRate),
  6329. );
  6330. useEventListener(target, 'stalled', () => (stalled.value = true));
  6331. useEventListener(target, 'ended', () => (ended.value = true));
  6332. useEventListener(target, 'pause', () =>
  6333. ignorePlayingUpdates(() => (playing.value = false)),
  6334. );
  6335. useEventListener(target, 'play', () =>
  6336. ignorePlayingUpdates(() => (playing.value = true)),
  6337. );
  6338. useEventListener(
  6339. target,
  6340. 'enterpictureinpicture',
  6341. () => (isPictureInPicture.value = true),
  6342. );
  6343. useEventListener(
  6344. target,
  6345. 'leavepictureinpicture',
  6346. () => (isPictureInPicture.value = false),
  6347. );
  6348. useEventListener(target, 'volumechange', () => {
  6349. const el = toValue(target);
  6350. if (!el) return;
  6351. volume.value = el.volume;
  6352. muted.value = el.muted;
  6353. });
  6354. const listeners = [];
  6355. const stop = watch([target], () => {
  6356. const el = toValue(target);
  6357. if (!el) return;
  6358. stop();
  6359. listeners[0] = useEventListener(
  6360. el.textTracks,
  6361. 'addtrack',
  6362. () => (tracks.value = tracksToArray(el.textTracks)),
  6363. );
  6364. listeners[1] = useEventListener(
  6365. el.textTracks,
  6366. 'removetrack',
  6367. () => (tracks.value = tracksToArray(el.textTracks)),
  6368. );
  6369. listeners[2] = useEventListener(
  6370. el.textTracks,
  6371. 'change',
  6372. () => (tracks.value = tracksToArray(el.textTracks)),
  6373. );
  6374. });
  6375. tryOnScopeDispose(() => listeners.forEach((listener) => listener()));
  6376. return {
  6377. currentTime,
  6378. duration,
  6379. waiting,
  6380. seeking,
  6381. ended,
  6382. stalled,
  6383. buffered,
  6384. playing,
  6385. rate,
  6386. // Volume
  6387. volume,
  6388. muted,
  6389. // Tracks
  6390. tracks,
  6391. selectedTrack,
  6392. enableTrack,
  6393. disableTrack,
  6394. // Picture in Picture
  6395. supportsPictureInPicture,
  6396. togglePictureInPicture,
  6397. isPictureInPicture,
  6398. // Events
  6399. onSourceError: sourceErrorEvent.on,
  6400. };
  6401. }
  6402. function getMapVue2Compat() {
  6403. const data = shallowReactive({});
  6404. return {
  6405. get: (key) => data[key],
  6406. set: (key, value) => set(data, key, value),
  6407. has: (key) => hasOwn(data, key),
  6408. delete: (key) => del(data, key),
  6409. clear: () => {
  6410. Object.keys(data).forEach((key) => {
  6411. del(data, key);
  6412. });
  6413. },
  6414. };
  6415. }
  6416. function useMemoize(resolver, options) {
  6417. const initCache = () => {
  6418. if (options == null ? void 0 : options.cache)
  6419. return shallowReactive(options.cache);
  6420. if (isVue2) return getMapVue2Compat();
  6421. return shallowReactive(/* @__PURE__ */ new Map());
  6422. };
  6423. const cache = initCache();
  6424. const generateKey = (...args) =>
  6425. (options == null ? void 0 : options.getKey)
  6426. ? options.getKey(...args)
  6427. : JSON.stringify(args);
  6428. const _loadData = (key, ...args) => {
  6429. cache.set(key, resolver(...args));
  6430. return cache.get(key);
  6431. };
  6432. const loadData = (...args) => _loadData(generateKey(...args), ...args);
  6433. const deleteData = (...args) => {
  6434. cache.delete(generateKey(...args));
  6435. };
  6436. const clearData = () => {
  6437. cache.clear();
  6438. };
  6439. const memoized = (...args) => {
  6440. const key = generateKey(...args);
  6441. if (cache.has(key)) return cache.get(key);
  6442. return _loadData(key, ...args);
  6443. };
  6444. memoized.load = loadData;
  6445. memoized.delete = deleteData;
  6446. memoized.clear = clearData;
  6447. memoized.generateKey = generateKey;
  6448. memoized.cache = cache;
  6449. return memoized;
  6450. }
  6451. function useMemory(options = {}) {
  6452. const memory = ref();
  6453. const isSupported = useSupported(
  6454. () => typeof performance !== 'undefined' && 'memory' in performance,
  6455. );
  6456. if (isSupported.value) {
  6457. const { interval = 1e3 } = options;
  6458. useIntervalFn(
  6459. () => {
  6460. memory.value = performance.memory;
  6461. },
  6462. interval,
  6463. {
  6464. immediate: options.immediate,
  6465. immediateCallback: options.immediateCallback,
  6466. },
  6467. );
  6468. }
  6469. return { isSupported, memory };
  6470. }
  6471. var UseMouseBuiltinExtractors = {
  6472. page: (event) => [event.pageX, event.pageY],
  6473. client: (event) => [event.clientX, event.clientY],
  6474. screen: (event) => [event.screenX, event.screenY],
  6475. movement: (event) =>
  6476. event instanceof Touch ? null : [event.movementX, event.movementY],
  6477. };
  6478. function useMouse(options = {}) {
  6479. const {
  6480. type = 'page',
  6481. touch = true,
  6482. resetOnTouchEnds = false,
  6483. initialValue = { x: 0, y: 0 },
  6484. window: window2 = defaultWindow,
  6485. target = window2,
  6486. scroll = true,
  6487. eventFilter,
  6488. } = options;
  6489. let _prevMouseEvent = null;
  6490. const x = ref(initialValue.x);
  6491. const y = ref(initialValue.y);
  6492. const sourceType = ref(null);
  6493. const extractor =
  6494. typeof type === 'function' ? type : UseMouseBuiltinExtractors[type];
  6495. const mouseHandler = (event) => {
  6496. const result = extractor(event);
  6497. _prevMouseEvent = event;
  6498. if (result) {
  6499. [x.value, y.value] = result;
  6500. sourceType.value = 'mouse';
  6501. }
  6502. };
  6503. const touchHandler = (event) => {
  6504. if (event.touches.length > 0) {
  6505. const result = extractor(event.touches[0]);
  6506. if (result) {
  6507. [x.value, y.value] = result;
  6508. sourceType.value = 'touch';
  6509. }
  6510. }
  6511. };
  6512. const scrollHandler = () => {
  6513. if (!_prevMouseEvent || !window2) return;
  6514. const pos = extractor(_prevMouseEvent);
  6515. if (_prevMouseEvent instanceof MouseEvent && pos) {
  6516. x.value = pos[0] + window2.scrollX;
  6517. y.value = pos[1] + window2.scrollY;
  6518. }
  6519. };
  6520. const reset = () => {
  6521. x.value = initialValue.x;
  6522. y.value = initialValue.y;
  6523. };
  6524. const mouseHandlerWrapper = eventFilter
  6525. ? (event) => eventFilter(() => mouseHandler(event), {})
  6526. : (event) => mouseHandler(event);
  6527. const touchHandlerWrapper = eventFilter
  6528. ? (event) => eventFilter(() => touchHandler(event), {})
  6529. : (event) => touchHandler(event);
  6530. const scrollHandlerWrapper = eventFilter
  6531. ? () => eventFilter(() => scrollHandler(), {})
  6532. : () => scrollHandler();
  6533. if (target) {
  6534. const listenerOptions = { passive: true };
  6535. useEventListener(
  6536. target,
  6537. ['mousemove', 'dragover'],
  6538. mouseHandlerWrapper,
  6539. listenerOptions,
  6540. );
  6541. if (touch && type !== 'movement') {
  6542. useEventListener(
  6543. target,
  6544. ['touchstart', 'touchmove'],
  6545. touchHandlerWrapper,
  6546. listenerOptions,
  6547. );
  6548. if (resetOnTouchEnds)
  6549. useEventListener(target, 'touchend', reset, listenerOptions);
  6550. }
  6551. if (scroll && type === 'page')
  6552. useEventListener(window2, 'scroll', scrollHandlerWrapper, {
  6553. passive: true,
  6554. });
  6555. }
  6556. return {
  6557. x,
  6558. y,
  6559. sourceType,
  6560. };
  6561. }
  6562. function useMouseInElement(target, options = {}) {
  6563. const { handleOutside = true, window: window2 = defaultWindow } = options;
  6564. const type = options.type || 'page';
  6565. const { x, y, sourceType } = useMouse(options);
  6566. const targetRef = ref(
  6567. target != null ? target : window2 == null ? void 0 : window2.document.body,
  6568. );
  6569. const elementX = ref(0);
  6570. const elementY = ref(0);
  6571. const elementPositionX = ref(0);
  6572. const elementPositionY = ref(0);
  6573. const elementHeight = ref(0);
  6574. const elementWidth = ref(0);
  6575. const isOutside = ref(true);
  6576. let stop = () => {};
  6577. if (window2) {
  6578. stop = watch(
  6579. [targetRef, x, y],
  6580. () => {
  6581. const el = unrefElement(targetRef);
  6582. if (!el) return;
  6583. const { left, top, width, height } = el.getBoundingClientRect();
  6584. elementPositionX.value =
  6585. left + (type === 'page' ? window2.pageXOffset : 0);
  6586. elementPositionY.value =
  6587. top + (type === 'page' ? window2.pageYOffset : 0);
  6588. elementHeight.value = height;
  6589. elementWidth.value = width;
  6590. const elX = x.value - elementPositionX.value;
  6591. const elY = y.value - elementPositionY.value;
  6592. isOutside.value =
  6593. width === 0 ||
  6594. height === 0 ||
  6595. elX < 0 ||
  6596. elY < 0 ||
  6597. elX > width ||
  6598. elY > height;
  6599. if (handleOutside || !isOutside.value) {
  6600. elementX.value = elX;
  6601. elementY.value = elY;
  6602. }
  6603. },
  6604. { immediate: true },
  6605. );
  6606. useEventListener(document, 'mouseleave', () => {
  6607. isOutside.value = true;
  6608. });
  6609. }
  6610. return {
  6611. x,
  6612. y,
  6613. sourceType,
  6614. elementX,
  6615. elementY,
  6616. elementPositionX,
  6617. elementPositionY,
  6618. elementHeight,
  6619. elementWidth,
  6620. isOutside,
  6621. stop,
  6622. };
  6623. }
  6624. function useMousePressed(options = {}) {
  6625. const {
  6626. touch = true,
  6627. drag = true,
  6628. capture = false,
  6629. initialValue = false,
  6630. window: window2 = defaultWindow,
  6631. } = options;
  6632. const pressed = ref(initialValue);
  6633. const sourceType = ref(null);
  6634. if (!window2) {
  6635. return {
  6636. pressed,
  6637. sourceType,
  6638. };
  6639. }
  6640. const onPressed = (srcType) => () => {
  6641. pressed.value = true;
  6642. sourceType.value = srcType;
  6643. };
  6644. const onReleased = () => {
  6645. pressed.value = false;
  6646. sourceType.value = null;
  6647. };
  6648. const target = computed(() => unrefElement(options.target) || window2);
  6649. useEventListener(target, 'mousedown', onPressed('mouse'), {
  6650. passive: true,
  6651. capture,
  6652. });
  6653. useEventListener(window2, 'mouseleave', onReleased, {
  6654. passive: true,
  6655. capture,
  6656. });
  6657. useEventListener(window2, 'mouseup', onReleased, { passive: true, capture });
  6658. if (drag) {
  6659. useEventListener(target, 'dragstart', onPressed('mouse'), {
  6660. passive: true,
  6661. capture,
  6662. });
  6663. useEventListener(window2, 'drop', onReleased, { passive: true, capture });
  6664. useEventListener(window2, 'dragend', onReleased, {
  6665. passive: true,
  6666. capture,
  6667. });
  6668. }
  6669. if (touch) {
  6670. useEventListener(target, 'touchstart', onPressed('touch'), {
  6671. passive: true,
  6672. capture,
  6673. });
  6674. useEventListener(window2, 'touchend', onReleased, {
  6675. passive: true,
  6676. capture,
  6677. });
  6678. useEventListener(window2, 'touchcancel', onReleased, {
  6679. passive: true,
  6680. capture,
  6681. });
  6682. }
  6683. return {
  6684. pressed,
  6685. sourceType,
  6686. };
  6687. }
  6688. function useNavigatorLanguage(options = {}) {
  6689. const { window: window2 = defaultWindow } = options;
  6690. const navigator = window2 == null ? void 0 : window2.navigator;
  6691. const isSupported = useSupported(() => navigator && 'language' in navigator);
  6692. const language = ref(navigator == null ? void 0 : navigator.language);
  6693. useEventListener(window2, 'languagechange', () => {
  6694. if (navigator) language.value = navigator.language;
  6695. });
  6696. return {
  6697. isSupported,
  6698. language,
  6699. };
  6700. }
  6701. function useNetwork(options = {}) {
  6702. const { window: window2 = defaultWindow } = options;
  6703. const navigator = window2 == null ? void 0 : window2.navigator;
  6704. const isSupported = useSupported(
  6705. () => navigator && 'connection' in navigator,
  6706. );
  6707. const isOnline = ref(true);
  6708. const saveData = ref(false);
  6709. const offlineAt = ref(void 0);
  6710. const onlineAt = ref(void 0);
  6711. const downlink = ref(void 0);
  6712. const downlinkMax = ref(void 0);
  6713. const rtt = ref(void 0);
  6714. const effectiveType = ref(void 0);
  6715. const type = ref('unknown');
  6716. const connection = isSupported.value && navigator.connection;
  6717. function updateNetworkInformation() {
  6718. if (!navigator) return;
  6719. isOnline.value = navigator.onLine;
  6720. offlineAt.value = isOnline.value ? void 0 : Date.now();
  6721. onlineAt.value = isOnline.value ? Date.now() : void 0;
  6722. if (connection) {
  6723. downlink.value = connection.downlink;
  6724. downlinkMax.value = connection.downlinkMax;
  6725. effectiveType.value = connection.effectiveType;
  6726. rtt.value = connection.rtt;
  6727. saveData.value = connection.saveData;
  6728. type.value = connection.type;
  6729. }
  6730. }
  6731. if (window2) {
  6732. useEventListener(window2, 'offline', () => {
  6733. isOnline.value = false;
  6734. offlineAt.value = Date.now();
  6735. });
  6736. useEventListener(window2, 'online', () => {
  6737. isOnline.value = true;
  6738. onlineAt.value = Date.now();
  6739. });
  6740. }
  6741. if (connection)
  6742. useEventListener(connection, 'change', updateNetworkInformation, false);
  6743. updateNetworkInformation();
  6744. return {
  6745. isSupported,
  6746. isOnline,
  6747. saveData,
  6748. offlineAt,
  6749. onlineAt,
  6750. downlink,
  6751. downlinkMax,
  6752. effectiveType,
  6753. rtt,
  6754. type,
  6755. };
  6756. }
  6757. function useNow(options = {}) {
  6758. const {
  6759. controls: exposeControls = false,
  6760. interval = 'requestAnimationFrame',
  6761. } = options;
  6762. const now2 = ref(/* @__PURE__ */ new Date());
  6763. const update = () => (now2.value = /* @__PURE__ */ new Date());
  6764. const controls =
  6765. interval === 'requestAnimationFrame'
  6766. ? useRafFn(update, { immediate: true })
  6767. : useIntervalFn(update, interval, { immediate: true });
  6768. if (exposeControls) {
  6769. return {
  6770. now: now2,
  6771. ...controls,
  6772. };
  6773. } else {
  6774. return now2;
  6775. }
  6776. }
  6777. function useObjectUrl(object) {
  6778. const url = ref();
  6779. const release = () => {
  6780. if (url.value) URL.revokeObjectURL(url.value);
  6781. url.value = void 0;
  6782. };
  6783. watch(
  6784. () => toValue(object),
  6785. (newObject) => {
  6786. release();
  6787. if (newObject) url.value = URL.createObjectURL(newObject);
  6788. },
  6789. { immediate: true },
  6790. );
  6791. tryOnScopeDispose(release);
  6792. return readonly(url);
  6793. }
  6794. function useClamp(value, min, max) {
  6795. if (typeof value === 'function' || isReadonly(value))
  6796. return computed(() => clamp(toValue(value), toValue(min), toValue(max)));
  6797. const _value = ref(value);
  6798. return computed({
  6799. get() {
  6800. return (_value.value = clamp(_value.value, toValue(min), toValue(max)));
  6801. },
  6802. set(value2) {
  6803. _value.value = clamp(value2, toValue(min), toValue(max));
  6804. },
  6805. });
  6806. }
  6807. function useOffsetPagination(options) {
  6808. const {
  6809. total = Number.POSITIVE_INFINITY,
  6810. pageSize = 10,
  6811. page = 1,
  6812. onPageChange = noop,
  6813. onPageSizeChange = noop,
  6814. onPageCountChange = noop,
  6815. } = options;
  6816. const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
  6817. const pageCount = computed(() =>
  6818. Math.max(1, Math.ceil(toValue(total) / toValue(currentPageSize))),
  6819. );
  6820. const currentPage = useClamp(page, 1, pageCount);
  6821. const isFirstPage = computed(() => currentPage.value === 1);
  6822. const isLastPage = computed(() => currentPage.value === pageCount.value);
  6823. if (isRef(page)) {
  6824. syncRef(page, currentPage, {
  6825. direction: isReadonly(page) ? 'ltr' : 'both',
  6826. });
  6827. }
  6828. if (isRef(pageSize)) {
  6829. syncRef(pageSize, currentPageSize, {
  6830. direction: isReadonly(pageSize) ? 'ltr' : 'both',
  6831. });
  6832. }
  6833. function prev() {
  6834. currentPage.value--;
  6835. }
  6836. function next() {
  6837. currentPage.value++;
  6838. }
  6839. const returnValue = {
  6840. currentPage,
  6841. currentPageSize,
  6842. pageCount,
  6843. isFirstPage,
  6844. isLastPage,
  6845. prev,
  6846. next,
  6847. };
  6848. watch(currentPage, () => {
  6849. onPageChange(reactive(returnValue));
  6850. });
  6851. watch(currentPageSize, () => {
  6852. onPageSizeChange(reactive(returnValue));
  6853. });
  6854. watch(pageCount, () => {
  6855. onPageCountChange(reactive(returnValue));
  6856. });
  6857. return returnValue;
  6858. }
  6859. function useOnline(options = {}) {
  6860. const { isOnline } = useNetwork(options);
  6861. return isOnline;
  6862. }
  6863. function usePageLeave(options = {}) {
  6864. const { window: window2 = defaultWindow } = options;
  6865. const isLeft = ref(false);
  6866. const handler = (event) => {
  6867. if (!window2) return;
  6868. event = event || window2.event;
  6869. const from = event.relatedTarget || event.toElement;
  6870. isLeft.value = !from;
  6871. };
  6872. if (window2) {
  6873. useEventListener(window2, 'mouseout', handler, { passive: true });
  6874. useEventListener(window2.document, 'mouseleave', handler, {
  6875. passive: true,
  6876. });
  6877. useEventListener(window2.document, 'mouseenter', handler, {
  6878. passive: true,
  6879. });
  6880. }
  6881. return isLeft;
  6882. }
  6883. function useScreenOrientation(options = {}) {
  6884. const { window: window2 = defaultWindow } = options;
  6885. const isSupported = useSupported(
  6886. () => window2 && 'screen' in window2 && 'orientation' in window2.screen,
  6887. );
  6888. const screenOrientation = isSupported.value ? window2.screen.orientation : {};
  6889. const orientation = ref(screenOrientation.type);
  6890. const angle = ref(screenOrientation.angle || 0);
  6891. if (isSupported.value) {
  6892. useEventListener(window2, 'orientationchange', () => {
  6893. orientation.value = screenOrientation.type;
  6894. angle.value = screenOrientation.angle;
  6895. });
  6896. }
  6897. const lockOrientation = (type) => {
  6898. if (isSupported.value && typeof screenOrientation.lock === 'function')
  6899. return screenOrientation.lock(type);
  6900. return Promise.reject(new Error('Not supported'));
  6901. };
  6902. const unlockOrientation = () => {
  6903. if (isSupported.value && typeof screenOrientation.unlock === 'function')
  6904. screenOrientation.unlock();
  6905. };
  6906. return {
  6907. isSupported,
  6908. orientation,
  6909. angle,
  6910. lockOrientation,
  6911. unlockOrientation,
  6912. };
  6913. }
  6914. function useParallax(target, options = {}) {
  6915. const {
  6916. deviceOrientationTiltAdjust = (i) => i,
  6917. deviceOrientationRollAdjust = (i) => i,
  6918. mouseTiltAdjust = (i) => i,
  6919. mouseRollAdjust = (i) => i,
  6920. window: window2 = defaultWindow,
  6921. } = options;
  6922. const orientation = reactive(useDeviceOrientation({ window: window2 }));
  6923. const screenOrientation = reactive(useScreenOrientation({ window: window2 }));
  6924. const {
  6925. elementX: x,
  6926. elementY: y,
  6927. elementWidth: width,
  6928. elementHeight: height,
  6929. } = useMouseInElement(target, { handleOutside: false, window: window2 });
  6930. const source = computed(() => {
  6931. if (
  6932. orientation.isSupported &&
  6933. ((orientation.alpha != null && orientation.alpha !== 0) ||
  6934. (orientation.gamma != null && orientation.gamma !== 0))
  6935. )
  6936. return 'deviceOrientation';
  6937. return 'mouse';
  6938. });
  6939. const roll = computed(() => {
  6940. if (source.value === 'deviceOrientation') {
  6941. let value;
  6942. switch (screenOrientation.orientation) {
  6943. case 'landscape-primary':
  6944. value = orientation.gamma / 90;
  6945. break;
  6946. case 'landscape-secondary':
  6947. value = -orientation.gamma / 90;
  6948. break;
  6949. case 'portrait-primary':
  6950. value = -orientation.beta / 90;
  6951. break;
  6952. case 'portrait-secondary':
  6953. value = orientation.beta / 90;
  6954. break;
  6955. default:
  6956. value = -orientation.beta / 90;
  6957. }
  6958. return deviceOrientationRollAdjust(value);
  6959. } else {
  6960. const value = -(y.value - height.value / 2) / height.value;
  6961. return mouseRollAdjust(value);
  6962. }
  6963. });
  6964. const tilt = computed(() => {
  6965. if (source.value === 'deviceOrientation') {
  6966. let value;
  6967. switch (screenOrientation.orientation) {
  6968. case 'landscape-primary':
  6969. value = orientation.beta / 90;
  6970. break;
  6971. case 'landscape-secondary':
  6972. value = -orientation.beta / 90;
  6973. break;
  6974. case 'portrait-primary':
  6975. value = orientation.gamma / 90;
  6976. break;
  6977. case 'portrait-secondary':
  6978. value = -orientation.gamma / 90;
  6979. break;
  6980. default:
  6981. value = orientation.gamma / 90;
  6982. }
  6983. return deviceOrientationTiltAdjust(value);
  6984. } else {
  6985. const value = (x.value - width.value / 2) / width.value;
  6986. return mouseTiltAdjust(value);
  6987. }
  6988. });
  6989. return { roll, tilt, source };
  6990. }
  6991. function useParentElement(element = useCurrentElement()) {
  6992. const parentElement = shallowRef();
  6993. const update = () => {
  6994. const el = unrefElement(element);
  6995. if (el) parentElement.value = el.parentElement;
  6996. };
  6997. tryOnMounted(update);
  6998. watch(() => toValue(element), update);
  6999. return parentElement;
  7000. }
  7001. function usePerformanceObserver(options, callback) {
  7002. const {
  7003. window: window2 = defaultWindow,
  7004. immediate = true,
  7005. ...performanceOptions
  7006. } = options;
  7007. const isSupported = useSupported(
  7008. () => window2 && 'PerformanceObserver' in window2,
  7009. );
  7010. let observer;
  7011. const stop = () => {
  7012. observer == null ? void 0 : observer.disconnect();
  7013. };
  7014. const start = () => {
  7015. if (isSupported.value) {
  7016. stop();
  7017. observer = new PerformanceObserver(callback);
  7018. observer.observe(performanceOptions);
  7019. }
  7020. };
  7021. tryOnScopeDispose(stop);
  7022. if (immediate) start();
  7023. return {
  7024. isSupported,
  7025. start,
  7026. stop,
  7027. };
  7028. }
  7029. var defaultState = {
  7030. x: 0,
  7031. y: 0,
  7032. pointerId: 0,
  7033. pressure: 0,
  7034. tiltX: 0,
  7035. tiltY: 0,
  7036. width: 0,
  7037. height: 0,
  7038. twist: 0,
  7039. pointerType: null,
  7040. };
  7041. var keys = Object.keys(defaultState);
  7042. function usePointer(options = {}) {
  7043. const { target = defaultWindow } = options;
  7044. const isInside = ref(false);
  7045. const state = ref(options.initialValue || {});
  7046. Object.assign(state.value, defaultState, state.value);
  7047. const handler = (event) => {
  7048. isInside.value = true;
  7049. if (
  7050. options.pointerTypes &&
  7051. !options.pointerTypes.includes(event.pointerType)
  7052. )
  7053. return;
  7054. state.value = objectPick(event, keys, false);
  7055. };
  7056. if (target) {
  7057. const listenerOptions = { passive: true };
  7058. useEventListener(
  7059. target,
  7060. ['pointerdown', 'pointermove', 'pointerup'],
  7061. handler,
  7062. listenerOptions,
  7063. );
  7064. useEventListener(
  7065. target,
  7066. 'pointerleave',
  7067. () => (isInside.value = false),
  7068. listenerOptions,
  7069. );
  7070. }
  7071. return {
  7072. ...toRefs2(state),
  7073. isInside,
  7074. };
  7075. }
  7076. function usePointerLock(target, options = {}) {
  7077. const { document: document2 = defaultDocument } = options;
  7078. const isSupported = useSupported(
  7079. () => document2 && 'pointerLockElement' in document2,
  7080. );
  7081. const element = ref();
  7082. const triggerElement = ref();
  7083. let targetElement;
  7084. if (isSupported.value) {
  7085. useEventListener(document2, 'pointerlockchange', () => {
  7086. var _a;
  7087. const currentElement =
  7088. (_a = document2.pointerLockElement) != null ? _a : element.value;
  7089. if (targetElement && currentElement === targetElement) {
  7090. element.value = document2.pointerLockElement;
  7091. if (!element.value) targetElement = triggerElement.value = null;
  7092. }
  7093. });
  7094. useEventListener(document2, 'pointerlockerror', () => {
  7095. var _a;
  7096. const currentElement =
  7097. (_a = document2.pointerLockElement) != null ? _a : element.value;
  7098. if (targetElement && currentElement === targetElement) {
  7099. const action = document2.pointerLockElement ? 'release' : 'acquire';
  7100. throw new Error(`Failed to ${action} pointer lock.`);
  7101. }
  7102. });
  7103. }
  7104. async function lock(e) {
  7105. var _a;
  7106. if (!isSupported.value)
  7107. throw new Error('Pointer Lock API is not supported by your browser.');
  7108. triggerElement.value = e instanceof Event ? e.currentTarget : null;
  7109. targetElement =
  7110. e instanceof Event
  7111. ? (_a = unrefElement(target)) != null
  7112. ? _a
  7113. : triggerElement.value
  7114. : unrefElement(e);
  7115. if (!targetElement) throw new Error('Target element undefined.');
  7116. targetElement.requestPointerLock();
  7117. return await until(element).toBe(targetElement);
  7118. }
  7119. async function unlock() {
  7120. if (!element.value) return false;
  7121. document2.exitPointerLock();
  7122. await until(element).toBeNull();
  7123. return true;
  7124. }
  7125. return {
  7126. isSupported,
  7127. element,
  7128. triggerElement,
  7129. lock,
  7130. unlock,
  7131. };
  7132. }
  7133. function usePointerSwipe(target, options = {}) {
  7134. const targetRef = toRef2(target);
  7135. const {
  7136. threshold = 50,
  7137. onSwipe,
  7138. onSwipeEnd,
  7139. onSwipeStart,
  7140. disableTextSelect = false,
  7141. } = options;
  7142. const posStart = reactive({ x: 0, y: 0 });
  7143. const updatePosStart = (x, y) => {
  7144. posStart.x = x;
  7145. posStart.y = y;
  7146. };
  7147. const posEnd = reactive({ x: 0, y: 0 });
  7148. const updatePosEnd = (x, y) => {
  7149. posEnd.x = x;
  7150. posEnd.y = y;
  7151. };
  7152. const distanceX = computed(() => posStart.x - posEnd.x);
  7153. const distanceY = computed(() => posStart.y - posEnd.y);
  7154. const { max, abs } = Math;
  7155. const isThresholdExceeded = computed(
  7156. () => max(abs(distanceX.value), abs(distanceY.value)) >= threshold,
  7157. );
  7158. const isSwiping = ref(false);
  7159. const isPointerDown = ref(false);
  7160. const direction = computed(() => {
  7161. if (!isThresholdExceeded.value) return 'none';
  7162. if (abs(distanceX.value) > abs(distanceY.value)) {
  7163. return distanceX.value > 0 ? 'left' : 'right';
  7164. } else {
  7165. return distanceY.value > 0 ? 'up' : 'down';
  7166. }
  7167. });
  7168. const eventIsAllowed = (e) => {
  7169. var _a, _b, _c;
  7170. const isReleasingButton = e.buttons === 0;
  7171. const isPrimaryButton = e.buttons === 1;
  7172. return (_c =
  7173. (_b =
  7174. (_a = options.pointerTypes) == null
  7175. ? void 0
  7176. : _a.includes(e.pointerType)) != null
  7177. ? _b
  7178. : isReleasingButton || isPrimaryButton) != null
  7179. ? _c
  7180. : true;
  7181. };
  7182. const stops = [
  7183. useEventListener(target, 'pointerdown', (e) => {
  7184. if (!eventIsAllowed(e)) return;
  7185. isPointerDown.value = true;
  7186. const eventTarget = e.target;
  7187. eventTarget == null ? void 0 : eventTarget.setPointerCapture(e.pointerId);
  7188. const { clientX: x, clientY: y } = e;
  7189. updatePosStart(x, y);
  7190. updatePosEnd(x, y);
  7191. onSwipeStart == null ? void 0 : onSwipeStart(e);
  7192. }),
  7193. useEventListener(target, 'pointermove', (e) => {
  7194. if (!eventIsAllowed(e)) return;
  7195. if (!isPointerDown.value) return;
  7196. const { clientX: x, clientY: y } = e;
  7197. updatePosEnd(x, y);
  7198. if (!isSwiping.value && isThresholdExceeded.value) isSwiping.value = true;
  7199. if (isSwiping.value) onSwipe == null ? void 0 : onSwipe(e);
  7200. }),
  7201. useEventListener(target, 'pointerup', (e) => {
  7202. if (!eventIsAllowed(e)) return;
  7203. if (isSwiping.value)
  7204. onSwipeEnd == null ? void 0 : onSwipeEnd(e, direction.value);
  7205. isPointerDown.value = false;
  7206. isSwiping.value = false;
  7207. }),
  7208. ];
  7209. tryOnMounted(() => {
  7210. var _a, _b, _c, _d, _e, _f, _g, _h;
  7211. (_b = (_a = targetRef.value) == null ? void 0 : _a.style) == null
  7212. ? void 0
  7213. : _b.setProperty('touch-action', 'none');
  7214. if (disableTextSelect) {
  7215. (_d = (_c = targetRef.value) == null ? void 0 : _c.style) == null
  7216. ? void 0
  7217. : _d.setProperty('-webkit-user-select', 'none');
  7218. (_f = (_e = targetRef.value) == null ? void 0 : _e.style) == null
  7219. ? void 0
  7220. : _f.setProperty('-ms-user-select', 'none');
  7221. (_h = (_g = targetRef.value) == null ? void 0 : _g.style) == null
  7222. ? void 0
  7223. : _h.setProperty('user-select', 'none');
  7224. }
  7225. });
  7226. const stop = () => stops.forEach((s) => s());
  7227. return {
  7228. isSwiping: readonly(isSwiping),
  7229. direction: readonly(direction),
  7230. posStart: readonly(posStart),
  7231. posEnd: readonly(posEnd),
  7232. distanceX,
  7233. distanceY,
  7234. stop,
  7235. };
  7236. }
  7237. function usePreferredColorScheme(options) {
  7238. const isLight = useMediaQuery('(prefers-color-scheme: light)', options);
  7239. const isDark = useMediaQuery('(prefers-color-scheme: dark)', options);
  7240. return computed(() => {
  7241. if (isDark.value) return 'dark';
  7242. if (isLight.value) return 'light';
  7243. return 'no-preference';
  7244. });
  7245. }
  7246. function usePreferredContrast(options) {
  7247. const isMore = useMediaQuery('(prefers-contrast: more)', options);
  7248. const isLess = useMediaQuery('(prefers-contrast: less)', options);
  7249. const isCustom = useMediaQuery('(prefers-contrast: custom)', options);
  7250. return computed(() => {
  7251. if (isMore.value) return 'more';
  7252. if (isLess.value) return 'less';
  7253. if (isCustom.value) return 'custom';
  7254. return 'no-preference';
  7255. });
  7256. }
  7257. function usePreferredLanguages(options = {}) {
  7258. const { window: window2 = defaultWindow } = options;
  7259. if (!window2) return ref(['en']);
  7260. const navigator = window2.navigator;
  7261. const value = ref(navigator.languages);
  7262. useEventListener(window2, 'languagechange', () => {
  7263. value.value = navigator.languages;
  7264. });
  7265. return value;
  7266. }
  7267. function usePreferredReducedMotion(options) {
  7268. const isReduced = useMediaQuery('(prefers-reduced-motion: reduce)', options);
  7269. return computed(() => {
  7270. if (isReduced.value) return 'reduce';
  7271. return 'no-preference';
  7272. });
  7273. }
  7274. function usePrevious(value, initialValue) {
  7275. const previous = shallowRef(initialValue);
  7276. watch(
  7277. toRef2(value),
  7278. (_, oldValue) => {
  7279. previous.value = oldValue;
  7280. },
  7281. { flush: 'sync' },
  7282. );
  7283. return readonly(previous);
  7284. }
  7285. var topVarName = '--vueuse-safe-area-top';
  7286. var rightVarName = '--vueuse-safe-area-right';
  7287. var bottomVarName = '--vueuse-safe-area-bottom';
  7288. var leftVarName = '--vueuse-safe-area-left';
  7289. function useScreenSafeArea() {
  7290. const top = ref('');
  7291. const right = ref('');
  7292. const bottom = ref('');
  7293. const left = ref('');
  7294. if (isClient) {
  7295. const topCssVar = useCssVar(topVarName);
  7296. const rightCssVar = useCssVar(rightVarName);
  7297. const bottomCssVar = useCssVar(bottomVarName);
  7298. const leftCssVar = useCssVar(leftVarName);
  7299. topCssVar.value = 'env(safe-area-inset-top, 0px)';
  7300. rightCssVar.value = 'env(safe-area-inset-right, 0px)';
  7301. bottomCssVar.value = 'env(safe-area-inset-bottom, 0px)';
  7302. leftCssVar.value = 'env(safe-area-inset-left, 0px)';
  7303. update();
  7304. useEventListener('resize', useDebounceFn(update));
  7305. }
  7306. function update() {
  7307. top.value = getValue(topVarName);
  7308. right.value = getValue(rightVarName);
  7309. bottom.value = getValue(bottomVarName);
  7310. left.value = getValue(leftVarName);
  7311. }
  7312. return {
  7313. top,
  7314. right,
  7315. bottom,
  7316. left,
  7317. update,
  7318. };
  7319. }
  7320. function getValue(position) {
  7321. return getComputedStyle(document.documentElement).getPropertyValue(position);
  7322. }
  7323. function useScriptTag(src, onLoaded = noop, options = {}) {
  7324. const {
  7325. immediate = true,
  7326. manual = false,
  7327. type = 'text/javascript',
  7328. async = true,
  7329. crossOrigin,
  7330. referrerPolicy,
  7331. noModule,
  7332. defer,
  7333. document: document2 = defaultDocument,
  7334. attrs = {},
  7335. } = options;
  7336. const scriptTag = ref(null);
  7337. let _promise = null;
  7338. const loadScript = (waitForScriptLoad) =>
  7339. new Promise((resolve, reject) => {
  7340. const resolveWithElement = (el2) => {
  7341. scriptTag.value = el2;
  7342. resolve(el2);
  7343. return el2;
  7344. };
  7345. if (!document2) {
  7346. resolve(false);
  7347. return;
  7348. }
  7349. let shouldAppend = false;
  7350. let el = document2.querySelector(`script[src="${toValue(src)}"]`);
  7351. if (!el) {
  7352. el = document2.createElement('script');
  7353. el.type = type;
  7354. el.async = async;
  7355. el.src = toValue(src);
  7356. if (defer) el.defer = defer;
  7357. if (crossOrigin) el.crossOrigin = crossOrigin;
  7358. if (noModule) el.noModule = noModule;
  7359. if (referrerPolicy) el.referrerPolicy = referrerPolicy;
  7360. Object.entries(attrs).forEach(([name, value]) =>
  7361. el == null ? void 0 : el.setAttribute(name, value),
  7362. );
  7363. shouldAppend = true;
  7364. } else if (el.hasAttribute('data-loaded')) {
  7365. resolveWithElement(el);
  7366. }
  7367. el.addEventListener('error', (event) => reject(event));
  7368. el.addEventListener('abort', (event) => reject(event));
  7369. el.addEventListener('load', () => {
  7370. el.setAttribute('data-loaded', 'true');
  7371. onLoaded(el);
  7372. resolveWithElement(el);
  7373. });
  7374. if (shouldAppend) el = document2.head.appendChild(el);
  7375. if (!waitForScriptLoad) resolveWithElement(el);
  7376. });
  7377. const load = (waitForScriptLoad = true) => {
  7378. if (!_promise) _promise = loadScript(waitForScriptLoad);
  7379. return _promise;
  7380. };
  7381. const unload = () => {
  7382. if (!document2) return;
  7383. _promise = null;
  7384. if (scriptTag.value) scriptTag.value = null;
  7385. const el = document2.querySelector(`script[src="${toValue(src)}"]`);
  7386. if (el) document2.head.removeChild(el);
  7387. };
  7388. if (immediate && !manual) tryOnMounted(load);
  7389. if (!manual) tryOnUnmounted(unload);
  7390. return { scriptTag, load, unload };
  7391. }
  7392. function checkOverflowScroll(ele) {
  7393. const style = window.getComputedStyle(ele);
  7394. if (
  7395. style.overflowX === 'scroll' ||
  7396. style.overflowY === 'scroll' ||
  7397. (style.overflowX === 'auto' && ele.clientWidth < ele.scrollWidth) ||
  7398. (style.overflowY === 'auto' && ele.clientHeight < ele.scrollHeight)
  7399. ) {
  7400. return true;
  7401. } else {
  7402. const parent = ele.parentNode;
  7403. if (!parent || parent.tagName === 'BODY') return false;
  7404. return checkOverflowScroll(parent);
  7405. }
  7406. }
  7407. function preventDefault(rawEvent) {
  7408. const e = rawEvent || window.event;
  7409. const _target = e.target;
  7410. if (checkOverflowScroll(_target)) return false;
  7411. if (e.touches.length > 1) return true;
  7412. if (e.preventDefault) e.preventDefault();
  7413. return false;
  7414. }
  7415. var elInitialOverflow = /* @__PURE__ */ new WeakMap();
  7416. function useScrollLock(element, initialState = false) {
  7417. const isLocked = ref(initialState);
  7418. let stopTouchMoveListener = null;
  7419. watch(
  7420. toRef2(element),
  7421. (el) => {
  7422. const target = resolveElement(toValue(el));
  7423. if (target) {
  7424. const ele = target;
  7425. if (!elInitialOverflow.get(ele))
  7426. elInitialOverflow.set(ele, ele.style.overflow);
  7427. if (isLocked.value) ele.style.overflow = 'hidden';
  7428. }
  7429. },
  7430. {
  7431. immediate: true,
  7432. },
  7433. );
  7434. const lock = () => {
  7435. const el = resolveElement(toValue(element));
  7436. if (!el || isLocked.value) return;
  7437. if (isIOS) {
  7438. stopTouchMoveListener = useEventListener(
  7439. el,
  7440. 'touchmove',
  7441. (e) => {
  7442. preventDefault(e);
  7443. },
  7444. { passive: false },
  7445. );
  7446. }
  7447. el.style.overflow = 'hidden';
  7448. isLocked.value = true;
  7449. };
  7450. const unlock = () => {
  7451. var _a;
  7452. const el = resolveElement(toValue(element));
  7453. if (!el || !isLocked.value) return;
  7454. isIOS && (stopTouchMoveListener == null ? void 0 : stopTouchMoveListener());
  7455. el.style.overflow = (_a = elInitialOverflow.get(el)) != null ? _a : '';
  7456. elInitialOverflow.delete(el);
  7457. isLocked.value = false;
  7458. };
  7459. tryOnScopeDispose(unlock);
  7460. return computed({
  7461. get() {
  7462. return isLocked.value;
  7463. },
  7464. set(v) {
  7465. if (v) lock();
  7466. else unlock();
  7467. },
  7468. });
  7469. }
  7470. function useSessionStorage(key, initialValue, options = {}) {
  7471. const { window: window2 = defaultWindow } = options;
  7472. return useStorage(
  7473. key,
  7474. initialValue,
  7475. window2 == null ? void 0 : window2.sessionStorage,
  7476. options,
  7477. );
  7478. }
  7479. function useShare(shareOptions = {}, options = {}) {
  7480. const { navigator = defaultNavigator } = options;
  7481. const _navigator = navigator;
  7482. const isSupported = useSupported(
  7483. () => _navigator && 'canShare' in _navigator,
  7484. );
  7485. const share = async (overrideOptions = {}) => {
  7486. if (isSupported.value) {
  7487. const data = {
  7488. ...toValue(shareOptions),
  7489. ...toValue(overrideOptions),
  7490. };
  7491. let granted = true;
  7492. if (data.files && _navigator.canShare)
  7493. granted = _navigator.canShare({ files: data.files });
  7494. if (granted) return _navigator.share(data);
  7495. }
  7496. };
  7497. return {
  7498. isSupported,
  7499. share,
  7500. };
  7501. }
  7502. var defaultSortFn = (source, compareFn) => source.sort(compareFn);
  7503. var defaultCompare = (a, b) => a - b;
  7504. function useSorted(...args) {
  7505. var _a, _b, _c, _d;
  7506. const [source] = args;
  7507. let compareFn = defaultCompare;
  7508. let options = {};
  7509. if (args.length === 2) {
  7510. if (typeof args[1] === 'object') {
  7511. options = args[1];
  7512. compareFn = (_a = options.compareFn) != null ? _a : defaultCompare;
  7513. } else {
  7514. compareFn = (_b = args[1]) != null ? _b : defaultCompare;
  7515. }
  7516. } else if (args.length > 2) {
  7517. compareFn = (_c = args[1]) != null ? _c : defaultCompare;
  7518. options = (_d = args[2]) != null ? _d : {};
  7519. }
  7520. const { dirty = false, sortFn = defaultSortFn } = options;
  7521. if (!dirty) return computed(() => sortFn([...toValue(source)], compareFn));
  7522. watchEffect(() => {
  7523. const result = sortFn(toValue(source), compareFn);
  7524. if (isRef(source)) source.value = result;
  7525. else source.splice(0, source.length, ...result);
  7526. });
  7527. return source;
  7528. }
  7529. function useSpeechRecognition(options = {}) {
  7530. const {
  7531. interimResults = true,
  7532. continuous = true,
  7533. window: window2 = defaultWindow,
  7534. } = options;
  7535. const lang = toRef2(options.lang || 'en-US');
  7536. const isListening = ref(false);
  7537. const isFinal = ref(false);
  7538. const result = ref('');
  7539. const error = shallowRef(void 0);
  7540. const toggle = (value = !isListening.value) => {
  7541. isListening.value = value;
  7542. };
  7543. const start = () => {
  7544. isListening.value = true;
  7545. };
  7546. const stop = () => {
  7547. isListening.value = false;
  7548. };
  7549. const SpeechRecognition =
  7550. window2 && (window2.SpeechRecognition || window2.webkitSpeechRecognition);
  7551. const isSupported = useSupported(() => SpeechRecognition);
  7552. let recognition;
  7553. if (isSupported.value) {
  7554. recognition = new SpeechRecognition();
  7555. recognition.continuous = continuous;
  7556. recognition.interimResults = interimResults;
  7557. recognition.lang = toValue(lang);
  7558. recognition.onstart = () => {
  7559. isFinal.value = false;
  7560. };
  7561. watch(lang, (lang2) => {
  7562. if (recognition && !isListening.value) recognition.lang = lang2;
  7563. });
  7564. recognition.onresult = (event) => {
  7565. const transcript = Array.from(event.results)
  7566. .map((result2) => {
  7567. isFinal.value = result2.isFinal;
  7568. return result2[0];
  7569. })
  7570. .map((result2) => result2.transcript)
  7571. .join('');
  7572. result.value = transcript;
  7573. error.value = void 0;
  7574. };
  7575. recognition.onerror = (event) => {
  7576. error.value = event;
  7577. };
  7578. recognition.onend = () => {
  7579. isListening.value = false;
  7580. recognition.lang = toValue(lang);
  7581. };
  7582. watch(isListening, () => {
  7583. if (isListening.value) recognition.start();
  7584. else recognition.stop();
  7585. });
  7586. }
  7587. tryOnScopeDispose(() => {
  7588. isListening.value = false;
  7589. });
  7590. return {
  7591. isSupported,
  7592. isListening,
  7593. isFinal,
  7594. recognition,
  7595. result,
  7596. error,
  7597. toggle,
  7598. start,
  7599. stop,
  7600. };
  7601. }
  7602. function useSpeechSynthesis(text, options = {}) {
  7603. const {
  7604. pitch = 1,
  7605. rate = 1,
  7606. volume = 1,
  7607. window: window2 = defaultWindow,
  7608. } = options;
  7609. const synth = window2 && window2.speechSynthesis;
  7610. const isSupported = useSupported(() => synth);
  7611. const isPlaying = ref(false);
  7612. const status = ref('init');
  7613. const spokenText = toRef2(text || '');
  7614. const lang = toRef2(options.lang || 'en-US');
  7615. const error = shallowRef(void 0);
  7616. const toggle = (value = !isPlaying.value) => {
  7617. isPlaying.value = value;
  7618. };
  7619. const bindEventsForUtterance = (utterance2) => {
  7620. utterance2.lang = toValue(lang);
  7621. utterance2.voice = toValue(options.voice) || null;
  7622. utterance2.pitch = toValue(pitch);
  7623. utterance2.rate = toValue(rate);
  7624. utterance2.volume = volume;
  7625. utterance2.onstart = () => {
  7626. isPlaying.value = true;
  7627. status.value = 'play';
  7628. };
  7629. utterance2.onpause = () => {
  7630. isPlaying.value = false;
  7631. status.value = 'pause';
  7632. };
  7633. utterance2.onresume = () => {
  7634. isPlaying.value = true;
  7635. status.value = 'play';
  7636. };
  7637. utterance2.onend = () => {
  7638. isPlaying.value = false;
  7639. status.value = 'end';
  7640. };
  7641. utterance2.onerror = (event) => {
  7642. error.value = event;
  7643. };
  7644. };
  7645. const utterance = computed(() => {
  7646. isPlaying.value = false;
  7647. status.value = 'init';
  7648. const newUtterance = new SpeechSynthesisUtterance(spokenText.value);
  7649. bindEventsForUtterance(newUtterance);
  7650. return newUtterance;
  7651. });
  7652. const speak = () => {
  7653. synth.cancel();
  7654. utterance && synth.speak(utterance.value);
  7655. };
  7656. const stop = () => {
  7657. synth.cancel();
  7658. isPlaying.value = false;
  7659. };
  7660. if (isSupported.value) {
  7661. bindEventsForUtterance(utterance.value);
  7662. watch(lang, (lang2) => {
  7663. if (utterance.value && !isPlaying.value) utterance.value.lang = lang2;
  7664. });
  7665. if (options.voice) {
  7666. watch(options.voice, () => {
  7667. synth.cancel();
  7668. });
  7669. }
  7670. watch(isPlaying, () => {
  7671. if (isPlaying.value) synth.resume();
  7672. else synth.pause();
  7673. });
  7674. }
  7675. tryOnScopeDispose(() => {
  7676. isPlaying.value = false;
  7677. });
  7678. return {
  7679. isSupported,
  7680. isPlaying,
  7681. status,
  7682. utterance,
  7683. error,
  7684. stop,
  7685. toggle,
  7686. speak,
  7687. };
  7688. }
  7689. function useStepper(steps, initialStep) {
  7690. const stepsRef = ref(steps);
  7691. const stepNames = computed(() =>
  7692. Array.isArray(stepsRef.value)
  7693. ? stepsRef.value
  7694. : Object.keys(stepsRef.value),
  7695. );
  7696. const index = ref(
  7697. stepNames.value.indexOf(
  7698. initialStep != null ? initialStep : stepNames.value[0],
  7699. ),
  7700. );
  7701. const current = computed(() => at(index.value));
  7702. const isFirst = computed(() => index.value === 0);
  7703. const isLast = computed(() => index.value === stepNames.value.length - 1);
  7704. const next = computed(() => stepNames.value[index.value + 1]);
  7705. const previous = computed(() => stepNames.value[index.value - 1]);
  7706. function at(index2) {
  7707. if (Array.isArray(stepsRef.value)) return stepsRef.value[index2];
  7708. return stepsRef.value[stepNames.value[index2]];
  7709. }
  7710. function get2(step) {
  7711. if (!stepNames.value.includes(step)) return;
  7712. return at(stepNames.value.indexOf(step));
  7713. }
  7714. function goTo(step) {
  7715. if (stepNames.value.includes(step))
  7716. index.value = stepNames.value.indexOf(step);
  7717. }
  7718. function goToNext() {
  7719. if (isLast.value) return;
  7720. index.value++;
  7721. }
  7722. function goToPrevious() {
  7723. if (isFirst.value) return;
  7724. index.value--;
  7725. }
  7726. function goBackTo(step) {
  7727. if (isAfter(step)) goTo(step);
  7728. }
  7729. function isNext(step) {
  7730. return stepNames.value.indexOf(step) === index.value + 1;
  7731. }
  7732. function isPrevious(step) {
  7733. return stepNames.value.indexOf(step) === index.value - 1;
  7734. }
  7735. function isCurrent(step) {
  7736. return stepNames.value.indexOf(step) === index.value;
  7737. }
  7738. function isBefore(step) {
  7739. return index.value < stepNames.value.indexOf(step);
  7740. }
  7741. function isAfter(step) {
  7742. return index.value > stepNames.value.indexOf(step);
  7743. }
  7744. return {
  7745. steps: stepsRef,
  7746. stepNames,
  7747. index,
  7748. current,
  7749. next,
  7750. previous,
  7751. isFirst,
  7752. isLast,
  7753. at,
  7754. get: get2,
  7755. goTo,
  7756. goToNext,
  7757. goToPrevious,
  7758. goBackTo,
  7759. isNext,
  7760. isPrevious,
  7761. isCurrent,
  7762. isBefore,
  7763. isAfter,
  7764. };
  7765. }
  7766. function useStorageAsync(key, initialValue, storage, options = {}) {
  7767. var _a;
  7768. const {
  7769. flush = 'pre',
  7770. deep = true,
  7771. listenToStorageChanges = true,
  7772. writeDefaults = true,
  7773. mergeDefaults = false,
  7774. shallow,
  7775. window: window2 = defaultWindow,
  7776. eventFilter,
  7777. onError = (e) => {
  7778. console.error(e);
  7779. },
  7780. } = options;
  7781. const rawInit = toValue(initialValue);
  7782. const type = guessSerializerType(rawInit);
  7783. const data = (shallow ? shallowRef : ref)(initialValue);
  7784. const serializer =
  7785. (_a = options.serializer) != null ? _a : StorageSerializers[type];
  7786. if (!storage) {
  7787. try {
  7788. storage = getSSRHandler('getDefaultStorageAsync', () => {
  7789. var _a2;
  7790. return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
  7791. })();
  7792. } catch (e) {
  7793. onError(e);
  7794. }
  7795. }
  7796. async function read(event) {
  7797. if (!storage || (event && event.key !== key)) return;
  7798. try {
  7799. const rawValue = event ? event.newValue : await storage.getItem(key);
  7800. if (rawValue == null) {
  7801. data.value = rawInit;
  7802. if (writeDefaults && rawInit !== null)
  7803. await storage.setItem(key, await serializer.write(rawInit));
  7804. } else if (mergeDefaults) {
  7805. const value = await serializer.read(rawValue);
  7806. if (typeof mergeDefaults === 'function')
  7807. data.value = mergeDefaults(value, rawInit);
  7808. else if (type === 'object' && !Array.isArray(value))
  7809. data.value = { ...rawInit, ...value };
  7810. else data.value = value;
  7811. } else {
  7812. data.value = await serializer.read(rawValue);
  7813. }
  7814. } catch (e) {
  7815. onError(e);
  7816. }
  7817. }
  7818. read();
  7819. if (window2 && listenToStorageChanges)
  7820. useEventListener(window2, 'storage', (e) =>
  7821. Promise.resolve().then(() => read(e)),
  7822. );
  7823. if (storage) {
  7824. watchWithFilter(
  7825. data,
  7826. async () => {
  7827. try {
  7828. if (data.value == null) await storage.removeItem(key);
  7829. else await storage.setItem(key, await serializer.write(data.value));
  7830. } catch (e) {
  7831. onError(e);
  7832. }
  7833. },
  7834. {
  7835. flush,
  7836. deep,
  7837. eventFilter,
  7838. },
  7839. );
  7840. }
  7841. return data;
  7842. }
  7843. var _id = 0;
  7844. function useStyleTag(css, options = {}) {
  7845. const isLoaded = ref(false);
  7846. const {
  7847. document: document2 = defaultDocument,
  7848. immediate = true,
  7849. manual = false,
  7850. id = `vueuse_styletag_${++_id}`,
  7851. } = options;
  7852. const cssRef = ref(css);
  7853. let stop = () => {};
  7854. const load = () => {
  7855. if (!document2) return;
  7856. const el = document2.getElementById(id) || document2.createElement('style');
  7857. if (!el.isConnected) {
  7858. el.id = id;
  7859. if (options.media) el.media = options.media;
  7860. document2.head.appendChild(el);
  7861. }
  7862. if (isLoaded.value) return;
  7863. stop = watch(
  7864. cssRef,
  7865. (value) => {
  7866. el.textContent = value;
  7867. },
  7868. { immediate: true },
  7869. );
  7870. isLoaded.value = true;
  7871. };
  7872. const unload = () => {
  7873. if (!document2 || !isLoaded.value) return;
  7874. stop();
  7875. document2.head.removeChild(document2.getElementById(id));
  7876. isLoaded.value = false;
  7877. };
  7878. if (immediate && !manual) tryOnMounted(load);
  7879. if (!manual) tryOnScopeDispose(unload);
  7880. return {
  7881. id,
  7882. css: cssRef,
  7883. unload,
  7884. load,
  7885. isLoaded: readonly(isLoaded),
  7886. };
  7887. }
  7888. function useSwipe(target, options = {}) {
  7889. const {
  7890. threshold = 50,
  7891. onSwipe,
  7892. onSwipeEnd,
  7893. onSwipeStart,
  7894. passive = true,
  7895. window: window2 = defaultWindow,
  7896. } = options;
  7897. const coordsStart = reactive({ x: 0, y: 0 });
  7898. const coordsEnd = reactive({ x: 0, y: 0 });
  7899. const diffX = computed(() => coordsStart.x - coordsEnd.x);
  7900. const diffY = computed(() => coordsStart.y - coordsEnd.y);
  7901. const { max, abs } = Math;
  7902. const isThresholdExceeded = computed(
  7903. () => max(abs(diffX.value), abs(diffY.value)) >= threshold,
  7904. );
  7905. const isSwiping = ref(false);
  7906. const direction = computed(() => {
  7907. if (!isThresholdExceeded.value) return 'none';
  7908. if (abs(diffX.value) > abs(diffY.value)) {
  7909. return diffX.value > 0 ? 'left' : 'right';
  7910. } else {
  7911. return diffY.value > 0 ? 'up' : 'down';
  7912. }
  7913. });
  7914. const getTouchEventCoords = (e) => [
  7915. e.touches[0].clientX,
  7916. e.touches[0].clientY,
  7917. ];
  7918. const updateCoordsStart = (x, y) => {
  7919. coordsStart.x = x;
  7920. coordsStart.y = y;
  7921. };
  7922. const updateCoordsEnd = (x, y) => {
  7923. coordsEnd.x = x;
  7924. coordsEnd.y = y;
  7925. };
  7926. let listenerOptions;
  7927. const isPassiveEventSupported = checkPassiveEventSupport(
  7928. window2 == null ? void 0 : window2.document,
  7929. );
  7930. if (!passive)
  7931. listenerOptions = isPassiveEventSupported
  7932. ? { passive: false, capture: true }
  7933. : { capture: true };
  7934. else
  7935. listenerOptions = isPassiveEventSupported
  7936. ? { passive: true }
  7937. : { capture: false };
  7938. const onTouchEnd = (e) => {
  7939. if (isSwiping.value)
  7940. onSwipeEnd == null ? void 0 : onSwipeEnd(e, direction.value);
  7941. isSwiping.value = false;
  7942. };
  7943. const stops = [
  7944. useEventListener(
  7945. target,
  7946. 'touchstart',
  7947. (e) => {
  7948. if (e.touches.length !== 1) return;
  7949. if (listenerOptions.capture && !listenerOptions.passive)
  7950. e.preventDefault();
  7951. const [x, y] = getTouchEventCoords(e);
  7952. updateCoordsStart(x, y);
  7953. updateCoordsEnd(x, y);
  7954. onSwipeStart == null ? void 0 : onSwipeStart(e);
  7955. },
  7956. listenerOptions,
  7957. ),
  7958. useEventListener(
  7959. target,
  7960. 'touchmove',
  7961. (e) => {
  7962. if (e.touches.length !== 1) return;
  7963. const [x, y] = getTouchEventCoords(e);
  7964. updateCoordsEnd(x, y);
  7965. if (!isSwiping.value && isThresholdExceeded.value)
  7966. isSwiping.value = true;
  7967. if (isSwiping.value) onSwipe == null ? void 0 : onSwipe(e);
  7968. },
  7969. listenerOptions,
  7970. ),
  7971. useEventListener(
  7972. target,
  7973. ['touchend', 'touchcancel'],
  7974. onTouchEnd,
  7975. listenerOptions,
  7976. ),
  7977. ];
  7978. const stop = () => stops.forEach((s) => s());
  7979. return {
  7980. isPassiveEventSupported,
  7981. isSwiping,
  7982. direction,
  7983. coordsStart,
  7984. coordsEnd,
  7985. lengthX: diffX,
  7986. lengthY: diffY,
  7987. stop,
  7988. };
  7989. }
  7990. function checkPassiveEventSupport(document2) {
  7991. if (!document2) return false;
  7992. let supportsPassive = false;
  7993. const optionsBlock = {
  7994. get passive() {
  7995. supportsPassive = true;
  7996. return false;
  7997. },
  7998. };
  7999. document2.addEventListener('x', noop, optionsBlock);
  8000. document2.removeEventListener('x', noop);
  8001. return supportsPassive;
  8002. }
  8003. function useTemplateRefsList() {
  8004. const refs = ref([]);
  8005. refs.value.set = (el) => {
  8006. if (el) refs.value.push(el);
  8007. };
  8008. onBeforeUpdate(() => {
  8009. refs.value.length = 0;
  8010. });
  8011. return refs;
  8012. }
  8013. function useTextDirection(options = {}) {
  8014. const {
  8015. document: document2 = defaultDocument,
  8016. selector = 'html',
  8017. observe = false,
  8018. initialValue = 'ltr',
  8019. } = options;
  8020. function getValue2() {
  8021. var _a, _b;
  8022. return (_b =
  8023. (_a = document2 == null ? void 0 : document2.querySelector(selector)) ==
  8024. null
  8025. ? void 0
  8026. : _a.getAttribute('dir')) != null
  8027. ? _b
  8028. : initialValue;
  8029. }
  8030. const dir = ref(getValue2());
  8031. tryOnMounted(() => (dir.value = getValue2()));
  8032. if (observe && document2) {
  8033. useMutationObserver(
  8034. document2.querySelector(selector),
  8035. () => (dir.value = getValue2()),
  8036. { attributes: true },
  8037. );
  8038. }
  8039. return computed({
  8040. get() {
  8041. return dir.value;
  8042. },
  8043. set(v) {
  8044. var _a, _b;
  8045. dir.value = v;
  8046. if (!document2) return;
  8047. if (dir.value)
  8048. (_a = document2.querySelector(selector)) == null
  8049. ? void 0
  8050. : _a.setAttribute('dir', dir.value);
  8051. else
  8052. (_b = document2.querySelector(selector)) == null
  8053. ? void 0
  8054. : _b.removeAttribute('dir');
  8055. },
  8056. });
  8057. }
  8058. function getRangesFromSelection(selection) {
  8059. var _a;
  8060. const rangeCount = (_a = selection.rangeCount) != null ? _a : 0;
  8061. return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i));
  8062. }
  8063. function useTextSelection(options = {}) {
  8064. const { window: window2 = defaultWindow } = options;
  8065. const selection = ref(null);
  8066. const text = computed(() => {
  8067. var _a, _b;
  8068. return (_b = (_a = selection.value) == null ? void 0 : _a.toString()) !=
  8069. null
  8070. ? _b
  8071. : '';
  8072. });
  8073. const ranges = computed(() =>
  8074. selection.value ? getRangesFromSelection(selection.value) : [],
  8075. );
  8076. const rects = computed(() =>
  8077. ranges.value.map((range) => range.getBoundingClientRect()),
  8078. );
  8079. function onSelectionChange() {
  8080. selection.value = null;
  8081. if (window2) selection.value = window2.getSelection();
  8082. }
  8083. if (window2)
  8084. useEventListener(window2.document, 'selectionchange', onSelectionChange);
  8085. return {
  8086. text,
  8087. rects,
  8088. ranges,
  8089. selection,
  8090. };
  8091. }
  8092. function useTextareaAutosize(options) {
  8093. var _a;
  8094. const textarea = ref(options == null ? void 0 : options.element);
  8095. const input = ref(options == null ? void 0 : options.input);
  8096. const styleProp =
  8097. (_a = options == null ? void 0 : options.styleProp) != null ? _a : 'height';
  8098. const textareaScrollHeight = ref(1);
  8099. function triggerResize() {
  8100. var _a2, _b;
  8101. if (!textarea.value) return;
  8102. let height = '';
  8103. textarea.value.style[styleProp] = '1px';
  8104. textareaScrollHeight.value =
  8105. (_a2 = textarea.value) == null ? void 0 : _a2.scrollHeight;
  8106. if (options == null ? void 0 : options.styleTarget)
  8107. toValue(options.styleTarget).style[styleProp] =
  8108. `${textareaScrollHeight.value}px`;
  8109. else height = `${textareaScrollHeight.value}px`;
  8110. textarea.value.style[styleProp] = height;
  8111. (_b = options == null ? void 0 : options.onResize) == null
  8112. ? void 0
  8113. : _b.call(options);
  8114. }
  8115. watch([input, textarea], () => nextTick(triggerResize), { immediate: true });
  8116. useResizeObserver(textarea, () => triggerResize());
  8117. if (options == null ? void 0 : options.watch)
  8118. watch(options.watch, triggerResize, { immediate: true, deep: true });
  8119. return {
  8120. textarea,
  8121. input,
  8122. triggerResize,
  8123. };
  8124. }
  8125. function useThrottledRefHistory(source, options = {}) {
  8126. const { throttle = 200, trailing = true } = options;
  8127. const filter = throttleFilter(throttle, trailing);
  8128. const history = useRefHistory(source, { ...options, eventFilter: filter });
  8129. return {
  8130. ...history,
  8131. };
  8132. }
  8133. var DEFAULT_UNITS = [
  8134. { max: 6e4, value: 1e3, name: 'second' },
  8135. { max: 276e4, value: 6e4, name: 'minute' },
  8136. { max: 72e6, value: 36e5, name: 'hour' },
  8137. { max: 5184e5, value: 864e5, name: 'day' },
  8138. { max: 24192e5, value: 6048e5, name: 'week' },
  8139. { max: 28512e6, value: 2592e6, name: 'month' },
  8140. { max: Number.POSITIVE_INFINITY, value: 31536e6, name: 'year' },
  8141. ];
  8142. var DEFAULT_MESSAGES = {
  8143. justNow: 'just now',
  8144. past: (n) => (n.match(/\d/) ? `${n} ago` : n),
  8145. future: (n) => (n.match(/\d/) ? `in ${n}` : n),
  8146. month: (n, past) =>
  8147. n === 1
  8148. ? past
  8149. ? 'last month'
  8150. : 'next month'
  8151. : `${n} month${n > 1 ? 's' : ''}`,
  8152. year: (n, past) =>
  8153. n === 1
  8154. ? past
  8155. ? 'last year'
  8156. : 'next year'
  8157. : `${n} year${n > 1 ? 's' : ''}`,
  8158. day: (n, past) =>
  8159. n === 1 ? (past ? 'yesterday' : 'tomorrow') : `${n} day${n > 1 ? 's' : ''}`,
  8160. week: (n, past) =>
  8161. n === 1
  8162. ? past
  8163. ? 'last week'
  8164. : 'next week'
  8165. : `${n} week${n > 1 ? 's' : ''}`,
  8166. hour: (n) => `${n} hour${n > 1 ? 's' : ''}`,
  8167. minute: (n) => `${n} minute${n > 1 ? 's' : ''}`,
  8168. second: (n) => `${n} second${n > 1 ? 's' : ''}`,
  8169. invalid: '',
  8170. };
  8171. function DEFAULT_FORMATTER(date) {
  8172. return date.toISOString().slice(0, 10);
  8173. }
  8174. function useTimeAgo(time, options = {}) {
  8175. const { controls: exposeControls = false, updateInterval = 3e4 } = options;
  8176. const { now: now2, ...controls } = useNow({
  8177. interval: updateInterval,
  8178. controls: true,
  8179. });
  8180. const timeAgo = computed(() =>
  8181. formatTimeAgo(new Date(toValue(time)), options, toValue(now2)),
  8182. );
  8183. if (exposeControls) {
  8184. return {
  8185. timeAgo,
  8186. ...controls,
  8187. };
  8188. } else {
  8189. return timeAgo;
  8190. }
  8191. }
  8192. function formatTimeAgo(from, options = {}, now2 = Date.now()) {
  8193. var _a;
  8194. const {
  8195. max,
  8196. messages = DEFAULT_MESSAGES,
  8197. fullDateFormatter = DEFAULT_FORMATTER,
  8198. units = DEFAULT_UNITS,
  8199. showSecond = false,
  8200. rounding = 'round',
  8201. } = options;
  8202. const roundFn =
  8203. typeof rounding === 'number' ? (n) => +n.toFixed(rounding) : Math[rounding];
  8204. const diff = +now2 - +from;
  8205. const absDiff = Math.abs(diff);
  8206. function getValue2(diff2, unit) {
  8207. return roundFn(Math.abs(diff2) / unit.value);
  8208. }
  8209. function format(diff2, unit) {
  8210. const val = getValue2(diff2, unit);
  8211. const past = diff2 > 0;
  8212. const str = applyFormat(unit.name, val, past);
  8213. return applyFormat(past ? 'past' : 'future', str, past);
  8214. }
  8215. function applyFormat(name, val, isPast) {
  8216. const formatter = messages[name];
  8217. if (typeof formatter === 'function') return formatter(val, isPast);
  8218. return formatter.replace('{0}', val.toString());
  8219. }
  8220. if (absDiff < 6e4 && !showSecond) return messages.justNow;
  8221. if (typeof max === 'number' && absDiff > max)
  8222. return fullDateFormatter(new Date(from));
  8223. if (typeof max === 'string') {
  8224. const unitMax =
  8225. (_a = units.find((i) => i.name === max)) == null ? void 0 : _a.max;
  8226. if (unitMax && absDiff > unitMax) return fullDateFormatter(new Date(from));
  8227. }
  8228. for (const [idx, unit] of units.entries()) {
  8229. const val = getValue2(diff, unit);
  8230. if (val <= 0 && units[idx - 1]) return format(diff, units[idx - 1]);
  8231. if (absDiff < unit.max) return format(diff, unit);
  8232. }
  8233. return messages.invalid;
  8234. }
  8235. function useTimeoutPoll(fn, interval, timeoutPollOptions) {
  8236. const { start } = useTimeoutFn(loop, interval, { immediate: false });
  8237. const isActive = ref(false);
  8238. async function loop() {
  8239. if (!isActive.value) return;
  8240. await fn();
  8241. start();
  8242. }
  8243. function resume() {
  8244. if (!isActive.value) {
  8245. isActive.value = true;
  8246. loop();
  8247. }
  8248. }
  8249. function pause() {
  8250. isActive.value = false;
  8251. }
  8252. if (timeoutPollOptions == null ? void 0 : timeoutPollOptions.immediate)
  8253. resume();
  8254. tryOnScopeDispose(pause);
  8255. return {
  8256. isActive,
  8257. pause,
  8258. resume,
  8259. };
  8260. }
  8261. function useTimestamp(options = {}) {
  8262. const {
  8263. controls: exposeControls = false,
  8264. offset = 0,
  8265. immediate = true,
  8266. interval = 'requestAnimationFrame',
  8267. callback,
  8268. } = options;
  8269. const ts = ref(timestamp() + offset);
  8270. const update = () => (ts.value = timestamp() + offset);
  8271. const cb = callback
  8272. ? () => {
  8273. update();
  8274. callback(ts.value);
  8275. }
  8276. : update;
  8277. const controls =
  8278. interval === 'requestAnimationFrame'
  8279. ? useRafFn(cb, { immediate })
  8280. : useIntervalFn(cb, interval, { immediate });
  8281. if (exposeControls) {
  8282. return {
  8283. timestamp: ts,
  8284. ...controls,
  8285. };
  8286. } else {
  8287. return ts;
  8288. }
  8289. }
  8290. function useTitle(newTitle = null, options = {}) {
  8291. var _a, _b, _c;
  8292. const { document: document2 = defaultDocument, restoreOnUnmount = (t) => t } =
  8293. options;
  8294. const originalTitle =
  8295. (_a = document2 == null ? void 0 : document2.title) != null ? _a : '';
  8296. const title = toRef2(
  8297. (_b =
  8298. newTitle != null
  8299. ? newTitle
  8300. : document2 == null
  8301. ? void 0
  8302. : document2.title) != null
  8303. ? _b
  8304. : null,
  8305. );
  8306. const isReadonly2 = newTitle && typeof newTitle === 'function';
  8307. function format(t) {
  8308. if (!('titleTemplate' in options)) return t;
  8309. const template = options.titleTemplate || '%s';
  8310. return typeof template === 'function'
  8311. ? template(t)
  8312. : toValue(template).replace(/%s/g, t);
  8313. }
  8314. watch(
  8315. title,
  8316. (t, o) => {
  8317. if (t !== o && document2)
  8318. document2.title = format(typeof t === 'string' ? t : '');
  8319. },
  8320. { immediate: true },
  8321. );
  8322. if (options.observe && !options.titleTemplate && document2 && !isReadonly2) {
  8323. useMutationObserver(
  8324. (_c = document2.head) == null ? void 0 : _c.querySelector('title'),
  8325. () => {
  8326. if (document2 && document2.title !== title.value)
  8327. title.value = format(document2.title);
  8328. },
  8329. { childList: true },
  8330. );
  8331. }
  8332. tryOnBeforeUnmount(() => {
  8333. if (restoreOnUnmount) {
  8334. const restoredTitle = restoreOnUnmount(originalTitle, title.value || '');
  8335. if (restoredTitle != null && document2) document2.title = restoredTitle;
  8336. }
  8337. });
  8338. return title;
  8339. }
  8340. var _TransitionPresets = {
  8341. easeInSine: [0.12, 0, 0.39, 0],
  8342. easeOutSine: [0.61, 1, 0.88, 1],
  8343. easeInOutSine: [0.37, 0, 0.63, 1],
  8344. easeInQuad: [0.11, 0, 0.5, 0],
  8345. easeOutQuad: [0.5, 1, 0.89, 1],
  8346. easeInOutQuad: [0.45, 0, 0.55, 1],
  8347. easeInCubic: [0.32, 0, 0.67, 0],
  8348. easeOutCubic: [0.33, 1, 0.68, 1],
  8349. easeInOutCubic: [0.65, 0, 0.35, 1],
  8350. easeInQuart: [0.5, 0, 0.75, 0],
  8351. easeOutQuart: [0.25, 1, 0.5, 1],
  8352. easeInOutQuart: [0.76, 0, 0.24, 1],
  8353. easeInQuint: [0.64, 0, 0.78, 0],
  8354. easeOutQuint: [0.22, 1, 0.36, 1],
  8355. easeInOutQuint: [0.83, 0, 0.17, 1],
  8356. easeInExpo: [0.7, 0, 0.84, 0],
  8357. easeOutExpo: [0.16, 1, 0.3, 1],
  8358. easeInOutExpo: [0.87, 0, 0.13, 1],
  8359. easeInCirc: [0.55, 0, 1, 0.45],
  8360. easeOutCirc: [0, 0.55, 0.45, 1],
  8361. easeInOutCirc: [0.85, 0, 0.15, 1],
  8362. easeInBack: [0.36, 0, 0.66, -0.56],
  8363. easeOutBack: [0.34, 1.56, 0.64, 1],
  8364. easeInOutBack: [0.68, -0.6, 0.32, 1.6],
  8365. };
  8366. var TransitionPresets = Object.assign(
  8367. {},
  8368. { linear: identity },
  8369. _TransitionPresets,
  8370. );
  8371. function createEasingFunction([p0, p1, p2, p3]) {
  8372. const a = (a1, a2) => 1 - 3 * a2 + 3 * a1;
  8373. const b = (a1, a2) => 3 * a2 - 6 * a1;
  8374. const c = (a1) => 3 * a1;
  8375. const calcBezier = (t, a1, a2) =>
  8376. ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t;
  8377. const getSlope = (t, a1, a2) =>
  8378. 3 * a(a1, a2) * t * t + 2 * b(a1, a2) * t + c(a1);
  8379. const getTforX = (x) => {
  8380. let aGuessT = x;
  8381. for (let i = 0; i < 4; ++i) {
  8382. const currentSlope = getSlope(aGuessT, p0, p2);
  8383. if (currentSlope === 0) return aGuessT;
  8384. const currentX = calcBezier(aGuessT, p0, p2) - x;
  8385. aGuessT -= currentX / currentSlope;
  8386. }
  8387. return aGuessT;
  8388. };
  8389. return (x) => (p0 === p1 && p2 === p3 ? x : calcBezier(getTforX(x), p1, p3));
  8390. }
  8391. function lerp(a, b, alpha) {
  8392. return a + alpha * (b - a);
  8393. }
  8394. function toVec(t) {
  8395. return (typeof t === 'number' ? [t] : t) || [];
  8396. }
  8397. function executeTransition(source, from, to, options = {}) {
  8398. var _a, _b;
  8399. const fromVal = toValue(from);
  8400. const toVal = toValue(to);
  8401. const v1 = toVec(fromVal);
  8402. const v2 = toVec(toVal);
  8403. const duration = (_a = toValue(options.duration)) != null ? _a : 1e3;
  8404. const startedAt = Date.now();
  8405. const endAt = Date.now() + duration;
  8406. const trans =
  8407. typeof options.transition === 'function'
  8408. ? options.transition
  8409. : (_b = toValue(options.transition)) != null
  8410. ? _b
  8411. : identity;
  8412. const ease =
  8413. typeof trans === 'function' ? trans : createEasingFunction(trans);
  8414. return new Promise((resolve) => {
  8415. source.value = fromVal;
  8416. const tick = () => {
  8417. var _a2;
  8418. if ((_a2 = options.abort) == null ? void 0 : _a2.call(options)) {
  8419. resolve();
  8420. return;
  8421. }
  8422. const now2 = Date.now();
  8423. const alpha = ease((now2 - startedAt) / duration);
  8424. const arr = toVec(source.value).map((n, i) => lerp(v1[i], v2[i], alpha));
  8425. if (Array.isArray(source.value))
  8426. source.value = arr.map((n, i) => {
  8427. var _a3, _b2;
  8428. return lerp(
  8429. (_a3 = v1[i]) != null ? _a3 : 0,
  8430. (_b2 = v2[i]) != null ? _b2 : 0,
  8431. alpha,
  8432. );
  8433. });
  8434. else if (typeof source.value === 'number') source.value = arr[0];
  8435. if (now2 < endAt) {
  8436. requestAnimationFrame(tick);
  8437. } else {
  8438. source.value = toVal;
  8439. resolve();
  8440. }
  8441. };
  8442. tick();
  8443. });
  8444. }
  8445. function useTransition(source, options = {}) {
  8446. let currentId = 0;
  8447. const sourceVal = () => {
  8448. const v = toValue(source);
  8449. return typeof v === 'number' ? v : v.map(toValue);
  8450. };
  8451. const outputRef = ref(sourceVal());
  8452. watch(
  8453. sourceVal,
  8454. async (to) => {
  8455. var _a, _b;
  8456. if (toValue(options.disabled)) return;
  8457. const id = ++currentId;
  8458. if (options.delay) await promiseTimeout(toValue(options.delay));
  8459. if (id !== currentId) return;
  8460. const toVal = Array.isArray(to) ? to.map(toValue) : toValue(to);
  8461. (_a = options.onStarted) == null ? void 0 : _a.call(options);
  8462. await executeTransition(outputRef, outputRef.value, toVal, {
  8463. ...options,
  8464. abort: () => {
  8465. var _a2;
  8466. return (
  8467. id !== currentId ||
  8468. ((_a2 = options.abort) == null ? void 0 : _a2.call(options))
  8469. );
  8470. },
  8471. });
  8472. (_b = options.onFinished) == null ? void 0 : _b.call(options);
  8473. },
  8474. { deep: true },
  8475. );
  8476. watch(
  8477. () => toValue(options.disabled),
  8478. (disabled) => {
  8479. if (disabled) {
  8480. currentId++;
  8481. outputRef.value = sourceVal();
  8482. }
  8483. },
  8484. );
  8485. tryOnScopeDispose(() => {
  8486. currentId++;
  8487. });
  8488. return computed(() =>
  8489. toValue(options.disabled) ? sourceVal() : outputRef.value,
  8490. );
  8491. }
  8492. function useUrlSearchParams(mode = 'history', options = {}) {
  8493. const {
  8494. initialValue = {},
  8495. removeNullishValues = true,
  8496. removeFalsyValues = false,
  8497. write: enableWrite = true,
  8498. window: window2 = defaultWindow,
  8499. } = options;
  8500. if (!window2) return reactive(initialValue);
  8501. const state = reactive({});
  8502. function getRawParams() {
  8503. if (mode === 'history') {
  8504. return window2.location.search || '';
  8505. } else if (mode === 'hash') {
  8506. const hash = window2.location.hash || '';
  8507. const index = hash.indexOf('?');
  8508. return index > 0 ? hash.slice(index) : '';
  8509. } else {
  8510. return (window2.location.hash || '').replace(/^#/, '');
  8511. }
  8512. }
  8513. function constructQuery(params) {
  8514. const stringified = params.toString();
  8515. if (mode === 'history')
  8516. return `${stringified ? `?${stringified}` : ''}${window2.location.hash || ''}`;
  8517. if (mode === 'hash-params')
  8518. return `${window2.location.search || ''}${stringified ? `#${stringified}` : ''}`;
  8519. const hash = window2.location.hash || '#';
  8520. const index = hash.indexOf('?');
  8521. if (index > 0)
  8522. return `${hash.slice(0, index)}${stringified ? `?${stringified}` : ''}`;
  8523. return `${hash}${stringified ? `?${stringified}` : ''}`;
  8524. }
  8525. function read() {
  8526. return new URLSearchParams(getRawParams());
  8527. }
  8528. function updateState(params) {
  8529. const unusedKeys = new Set(Object.keys(state));
  8530. for (const key of params.keys()) {
  8531. const paramsForKey = params.getAll(key);
  8532. state[key] =
  8533. paramsForKey.length > 1 ? paramsForKey : params.get(key) || '';
  8534. unusedKeys.delete(key);
  8535. }
  8536. Array.from(unusedKeys).forEach((key) => delete state[key]);
  8537. }
  8538. const { pause, resume } = watchPausable(
  8539. state,
  8540. () => {
  8541. const params = new URLSearchParams('');
  8542. Object.keys(state).forEach((key) => {
  8543. const mapEntry = state[key];
  8544. if (Array.isArray(mapEntry))
  8545. mapEntry.forEach((value) => params.append(key, value));
  8546. else if (removeNullishValues && mapEntry == null) params.delete(key);
  8547. else if (removeFalsyValues && !mapEntry) params.delete(key);
  8548. else params.set(key, mapEntry);
  8549. });
  8550. write(params);
  8551. },
  8552. { deep: true },
  8553. );
  8554. function write(params, shouldUpdate) {
  8555. pause();
  8556. if (shouldUpdate) updateState(params);
  8557. window2.history.replaceState(
  8558. window2.history.state,
  8559. window2.document.title,
  8560. window2.location.pathname + constructQuery(params),
  8561. );
  8562. resume();
  8563. }
  8564. function onChanged() {
  8565. if (!enableWrite) return;
  8566. write(read(), true);
  8567. }
  8568. useEventListener(window2, 'popstate', onChanged, false);
  8569. if (mode !== 'history')
  8570. useEventListener(window2, 'hashchange', onChanged, false);
  8571. const initial = read();
  8572. if (initial.keys().next().value) updateState(initial);
  8573. else Object.assign(state, initialValue);
  8574. return state;
  8575. }
  8576. function useUserMedia(options = {}) {
  8577. var _a, _b;
  8578. const enabled = ref((_a = options.enabled) != null ? _a : false);
  8579. const autoSwitch = ref((_b = options.autoSwitch) != null ? _b : true);
  8580. const constraints = ref(options.constraints);
  8581. const { navigator = defaultNavigator } = options;
  8582. const isSupported = useSupported(() => {
  8583. var _a2;
  8584. return (_a2 = navigator == null ? void 0 : navigator.mediaDevices) == null
  8585. ? void 0
  8586. : _a2.getUserMedia;
  8587. });
  8588. const stream = shallowRef();
  8589. function getDeviceOptions(type) {
  8590. switch (type) {
  8591. case 'video': {
  8592. if (constraints.value) return constraints.value.video || false;
  8593. break;
  8594. }
  8595. case 'audio': {
  8596. if (constraints.value) return constraints.value.audio || false;
  8597. break;
  8598. }
  8599. }
  8600. }
  8601. async function _start() {
  8602. if (!isSupported.value || stream.value) return;
  8603. stream.value = await navigator.mediaDevices.getUserMedia({
  8604. video: getDeviceOptions('video'),
  8605. audio: getDeviceOptions('audio'),
  8606. });
  8607. return stream.value;
  8608. }
  8609. function _stop() {
  8610. var _a2;
  8611. (_a2 = stream.value) == null
  8612. ? void 0
  8613. : _a2.getTracks().forEach((t) => t.stop());
  8614. stream.value = void 0;
  8615. }
  8616. function stop() {
  8617. _stop();
  8618. enabled.value = false;
  8619. }
  8620. async function start() {
  8621. await _start();
  8622. if (stream.value) enabled.value = true;
  8623. return stream.value;
  8624. }
  8625. async function restart() {
  8626. _stop();
  8627. return await start();
  8628. }
  8629. watch(
  8630. enabled,
  8631. (v) => {
  8632. if (v) _start();
  8633. else _stop();
  8634. },
  8635. { immediate: true },
  8636. );
  8637. watch(
  8638. constraints,
  8639. () => {
  8640. if (autoSwitch.value && stream.value) restart();
  8641. },
  8642. { immediate: true },
  8643. );
  8644. tryOnScopeDispose(() => {
  8645. stop();
  8646. });
  8647. return {
  8648. isSupported,
  8649. stream,
  8650. start,
  8651. stop,
  8652. restart,
  8653. constraints,
  8654. enabled,
  8655. autoSwitch,
  8656. };
  8657. }
  8658. function useVModel(props, key, emit, options = {}) {
  8659. var _a, _b, _c, _d, _e;
  8660. const {
  8661. clone = false,
  8662. passive = false,
  8663. eventName,
  8664. deep = false,
  8665. defaultValue,
  8666. shouldEmit,
  8667. } = options;
  8668. const vm = getCurrentInstance();
  8669. const _emit =
  8670. emit ||
  8671. (vm == null ? void 0 : vm.emit) ||
  8672. ((_a = vm == null ? void 0 : vm.$emit) == null ? void 0 : _a.bind(vm)) ||
  8673. ((_c = (_b = vm == null ? void 0 : vm.proxy) == null ? void 0 : _b.$emit) ==
  8674. null
  8675. ? void 0
  8676. : _c.bind(vm == null ? void 0 : vm.proxy));
  8677. let event = eventName;
  8678. if (!key) {
  8679. if (isVue2) {
  8680. const modelOptions =
  8681. (_e =
  8682. (_d = vm == null ? void 0 : vm.proxy) == null
  8683. ? void 0
  8684. : _d.$options) == null
  8685. ? void 0
  8686. : _e.model;
  8687. key = (modelOptions == null ? void 0 : modelOptions.value) || 'value';
  8688. if (!eventName)
  8689. event = (modelOptions == null ? void 0 : modelOptions.event) || 'input';
  8690. } else {
  8691. key = 'modelValue';
  8692. }
  8693. }
  8694. event = event || `update:${key.toString()}`;
  8695. const cloneFn = (val) =>
  8696. !clone ? val : typeof clone === 'function' ? clone(val) : cloneFnJSON(val);
  8697. const getValue2 = () =>
  8698. isDef(props[key]) ? cloneFn(props[key]) : defaultValue;
  8699. const triggerEmit = (value) => {
  8700. if (shouldEmit) {
  8701. if (shouldEmit(value)) _emit(event, value);
  8702. } else {
  8703. _emit(event, value);
  8704. }
  8705. };
  8706. if (passive) {
  8707. const initialValue = getValue2();
  8708. const proxy = ref(initialValue);
  8709. let isUpdating = false;
  8710. watch(
  8711. () => props[key],
  8712. (v) => {
  8713. if (!isUpdating) {
  8714. isUpdating = true;
  8715. proxy.value = cloneFn(v);
  8716. nextTick(() => (isUpdating = false));
  8717. }
  8718. },
  8719. );
  8720. watch(
  8721. proxy,
  8722. (v) => {
  8723. if (!isUpdating && (v !== props[key] || deep)) triggerEmit(v);
  8724. },
  8725. { deep },
  8726. );
  8727. return proxy;
  8728. } else {
  8729. return computed({
  8730. get() {
  8731. return getValue2();
  8732. },
  8733. set(value) {
  8734. triggerEmit(value);
  8735. },
  8736. });
  8737. }
  8738. }
  8739. function useVModels(props, emit, options = {}) {
  8740. const ret = {};
  8741. for (const key in props) {
  8742. ret[key] = useVModel(props, key, emit, options);
  8743. }
  8744. return ret;
  8745. }
  8746. function useVibrate(options) {
  8747. const {
  8748. pattern = [],
  8749. interval = 0,
  8750. navigator = defaultNavigator,
  8751. } = options || {};
  8752. const isSupported = useSupported(
  8753. () => typeof navigator !== 'undefined' && 'vibrate' in navigator,
  8754. );
  8755. const patternRef = toRef2(pattern);
  8756. let intervalControls;
  8757. const vibrate = (pattern2 = patternRef.value) => {
  8758. if (isSupported.value) navigator.vibrate(pattern2);
  8759. };
  8760. const stop = () => {
  8761. if (isSupported.value) navigator.vibrate(0);
  8762. intervalControls == null ? void 0 : intervalControls.pause();
  8763. };
  8764. if (interval > 0) {
  8765. intervalControls = useIntervalFn(vibrate, interval, {
  8766. immediate: false,
  8767. immediateCallback: false,
  8768. });
  8769. }
  8770. return {
  8771. isSupported,
  8772. pattern,
  8773. intervalControls,
  8774. vibrate,
  8775. stop,
  8776. };
  8777. }
  8778. function useVirtualList(list, options) {
  8779. const {
  8780. containerStyle,
  8781. wrapperProps,
  8782. scrollTo: scrollTo2,
  8783. calculateRange,
  8784. currentList,
  8785. containerRef,
  8786. } = 'itemHeight' in options
  8787. ? useVerticalVirtualList(options, list)
  8788. : useHorizontalVirtualList(options, list);
  8789. return {
  8790. list: currentList,
  8791. scrollTo: scrollTo2,
  8792. containerProps: {
  8793. ref: containerRef,
  8794. onScroll: () => {
  8795. calculateRange();
  8796. },
  8797. style: containerStyle,
  8798. },
  8799. wrapperProps,
  8800. };
  8801. }
  8802. function useVirtualListResources(list) {
  8803. const containerRef = ref(null);
  8804. const size = useElementSize(containerRef);
  8805. const currentList = ref([]);
  8806. const source = shallowRef(list);
  8807. const state = ref({ start: 0, end: 10 });
  8808. return { state, source, currentList, size, containerRef };
  8809. }
  8810. function createGetViewCapacity(state, source, itemSize) {
  8811. return (containerSize) => {
  8812. if (typeof itemSize === 'number')
  8813. return Math.ceil(containerSize / itemSize);
  8814. const { start = 0 } = state.value;
  8815. let sum = 0;
  8816. let capacity = 0;
  8817. for (let i = start; i < source.value.length; i++) {
  8818. const size = itemSize(i);
  8819. sum += size;
  8820. capacity = i;
  8821. if (sum > containerSize) break;
  8822. }
  8823. return capacity - start;
  8824. };
  8825. }
  8826. function createGetOffset(source, itemSize) {
  8827. return (scrollDirection) => {
  8828. if (typeof itemSize === 'number')
  8829. return Math.floor(scrollDirection / itemSize) + 1;
  8830. let sum = 0;
  8831. let offset = 0;
  8832. for (let i = 0; i < source.value.length; i++) {
  8833. const size = itemSize(i);
  8834. sum += size;
  8835. if (sum >= scrollDirection) {
  8836. offset = i;
  8837. break;
  8838. }
  8839. }
  8840. return offset + 1;
  8841. };
  8842. }
  8843. function createCalculateRange(
  8844. type,
  8845. overscan,
  8846. getOffset,
  8847. getViewCapacity,
  8848. { containerRef, state, currentList, source },
  8849. ) {
  8850. return () => {
  8851. const element = containerRef.value;
  8852. if (element) {
  8853. const offset = getOffset(
  8854. type === 'vertical' ? element.scrollTop : element.scrollLeft,
  8855. );
  8856. const viewCapacity = getViewCapacity(
  8857. type === 'vertical' ? element.clientHeight : element.clientWidth,
  8858. );
  8859. const from = offset - overscan;
  8860. const to = offset + viewCapacity + overscan;
  8861. state.value = {
  8862. start: from < 0 ? 0 : from,
  8863. end: to > source.value.length ? source.value.length : to,
  8864. };
  8865. currentList.value = source.value
  8866. .slice(state.value.start, state.value.end)
  8867. .map((ele, index) => ({
  8868. data: ele,
  8869. index: index + state.value.start,
  8870. }));
  8871. }
  8872. };
  8873. }
  8874. function createGetDistance(itemSize, source) {
  8875. return (index) => {
  8876. if (typeof itemSize === 'number') {
  8877. const size2 = index * itemSize;
  8878. return size2;
  8879. }
  8880. const size = source.value
  8881. .slice(0, index)
  8882. .reduce((sum, _, i) => sum + itemSize(i), 0);
  8883. return size;
  8884. };
  8885. }
  8886. function useWatchForSizes(size, list, calculateRange) {
  8887. watch([size.width, size.height, list], () => {
  8888. calculateRange();
  8889. });
  8890. }
  8891. function createComputedTotalSize(itemSize, source) {
  8892. return computed(() => {
  8893. if (typeof itemSize === 'number') return source.value.length * itemSize;
  8894. return source.value.reduce((sum, _, index) => sum + itemSize(index), 0);
  8895. });
  8896. }
  8897. var scrollToDictionaryForElementScrollKey = {
  8898. horizontal: 'scrollLeft',
  8899. vertical: 'scrollTop',
  8900. };
  8901. function createScrollTo(type, calculateRange, getDistance, containerRef) {
  8902. return (index) => {
  8903. if (containerRef.value) {
  8904. containerRef.value[scrollToDictionaryForElementScrollKey[type]] =
  8905. getDistance(index);
  8906. calculateRange();
  8907. }
  8908. };
  8909. }
  8910. function useHorizontalVirtualList(options, list) {
  8911. const resources = useVirtualListResources(list);
  8912. const { state, source, currentList, size, containerRef } = resources;
  8913. const containerStyle = { overflowX: 'auto' };
  8914. const { itemWidth, overscan = 5 } = options;
  8915. const getViewCapacity = createGetViewCapacity(state, source, itemWidth);
  8916. const getOffset = createGetOffset(source, itemWidth);
  8917. const calculateRange = createCalculateRange(
  8918. 'horizontal',
  8919. overscan,
  8920. getOffset,
  8921. getViewCapacity,
  8922. resources,
  8923. );
  8924. const getDistanceLeft = createGetDistance(itemWidth, source);
  8925. const offsetLeft = computed(() => getDistanceLeft(state.value.start));
  8926. const totalWidth = createComputedTotalSize(itemWidth, source);
  8927. useWatchForSizes(size, list, calculateRange);
  8928. const scrollTo2 = createScrollTo(
  8929. 'horizontal',
  8930. calculateRange,
  8931. getDistanceLeft,
  8932. containerRef,
  8933. );
  8934. const wrapperProps = computed(() => {
  8935. return {
  8936. style: {
  8937. height: '100%',
  8938. width: `${totalWidth.value - offsetLeft.value}px`,
  8939. marginLeft: `${offsetLeft.value}px`,
  8940. display: 'flex',
  8941. },
  8942. };
  8943. });
  8944. return {
  8945. scrollTo: scrollTo2,
  8946. calculateRange,
  8947. wrapperProps,
  8948. containerStyle,
  8949. currentList,
  8950. containerRef,
  8951. };
  8952. }
  8953. function useVerticalVirtualList(options, list) {
  8954. const resources = useVirtualListResources(list);
  8955. const { state, source, currentList, size, containerRef } = resources;
  8956. const containerStyle = { overflowY: 'auto' };
  8957. const { itemHeight, overscan = 5 } = options;
  8958. const getViewCapacity = createGetViewCapacity(state, source, itemHeight);
  8959. const getOffset = createGetOffset(source, itemHeight);
  8960. const calculateRange = createCalculateRange(
  8961. 'vertical',
  8962. overscan,
  8963. getOffset,
  8964. getViewCapacity,
  8965. resources,
  8966. );
  8967. const getDistanceTop = createGetDistance(itemHeight, source);
  8968. const offsetTop = computed(() => getDistanceTop(state.value.start));
  8969. const totalHeight = createComputedTotalSize(itemHeight, source);
  8970. useWatchForSizes(size, list, calculateRange);
  8971. const scrollTo2 = createScrollTo(
  8972. 'vertical',
  8973. calculateRange,
  8974. getDistanceTop,
  8975. containerRef,
  8976. );
  8977. const wrapperProps = computed(() => {
  8978. return {
  8979. style: {
  8980. width: '100%',
  8981. height: `${totalHeight.value - offsetTop.value}px`,
  8982. marginTop: `${offsetTop.value}px`,
  8983. },
  8984. };
  8985. });
  8986. return {
  8987. calculateRange,
  8988. scrollTo: scrollTo2,
  8989. containerStyle,
  8990. wrapperProps,
  8991. currentList,
  8992. containerRef,
  8993. };
  8994. }
  8995. function useWakeLock(options = {}) {
  8996. const {
  8997. navigator = defaultNavigator,
  8998. document: document2 = defaultDocument,
  8999. } = options;
  9000. let wakeLock;
  9001. const isSupported = useSupported(() => navigator && 'wakeLock' in navigator);
  9002. const isActive = ref(false);
  9003. async function onVisibilityChange() {
  9004. if (!isSupported.value || !wakeLock) return;
  9005. if (document2 && document2.visibilityState === 'visible')
  9006. wakeLock = await navigator.wakeLock.request('screen');
  9007. isActive.value = !wakeLock.released;
  9008. }
  9009. if (document2)
  9010. useEventListener(document2, 'visibilitychange', onVisibilityChange, {
  9011. passive: true,
  9012. });
  9013. async function request(type) {
  9014. if (!isSupported.value) return;
  9015. wakeLock = await navigator.wakeLock.request(type);
  9016. isActive.value = !wakeLock.released;
  9017. }
  9018. async function release() {
  9019. if (!isSupported.value || !wakeLock) return;
  9020. await wakeLock.release();
  9021. isActive.value = !wakeLock.released;
  9022. wakeLock = null;
  9023. }
  9024. return {
  9025. isSupported,
  9026. isActive,
  9027. request,
  9028. release,
  9029. };
  9030. }
  9031. function useWebNotification(options = {}) {
  9032. const {
  9033. window: window2 = defaultWindow,
  9034. requestPermissions: _requestForPermissions = true,
  9035. } = options;
  9036. const defaultWebNotificationOptions = options;
  9037. const isSupported = useSupported(
  9038. () => !!window2 && 'Notification' in window2,
  9039. );
  9040. const permissionGranted = ref(
  9041. isSupported.value &&
  9042. 'permission' in Notification &&
  9043. Notification.permission === 'granted',
  9044. );
  9045. const notification = ref(null);
  9046. const ensurePermissions = async () => {
  9047. if (!isSupported.value) return;
  9048. if (!permissionGranted.value && Notification.permission !== 'denied') {
  9049. const result = await Notification.requestPermission();
  9050. if (result === 'granted') permissionGranted.value = true;
  9051. }
  9052. return permissionGranted.value;
  9053. };
  9054. const { on: onClick, trigger: clickTrigger } = createEventHook();
  9055. const { on: onShow, trigger: showTrigger } = createEventHook();
  9056. const { on: onError, trigger: errorTrigger } = createEventHook();
  9057. const { on: onClose, trigger: closeTrigger } = createEventHook();
  9058. const show = async (overrides) => {
  9059. if (!isSupported.value || !permissionGranted.value) return;
  9060. const options2 = Object.assign(
  9061. {},
  9062. defaultWebNotificationOptions,
  9063. overrides,
  9064. );
  9065. notification.value = new Notification(options2.title || '', options2);
  9066. notification.value.onclick = clickTrigger;
  9067. notification.value.onshow = showTrigger;
  9068. notification.value.onerror = errorTrigger;
  9069. notification.value.onclose = closeTrigger;
  9070. return notification.value;
  9071. };
  9072. const close = () => {
  9073. if (notification.value) notification.value.close();
  9074. notification.value = null;
  9075. };
  9076. if (_requestForPermissions) tryOnMounted(ensurePermissions);
  9077. tryOnScopeDispose(close);
  9078. if (isSupported.value && window2) {
  9079. const document2 = window2.document;
  9080. useEventListener(document2, 'visibilitychange', (e) => {
  9081. e.preventDefault();
  9082. if (document2.visibilityState === 'visible') {
  9083. close();
  9084. }
  9085. });
  9086. }
  9087. return {
  9088. isSupported,
  9089. notification,
  9090. ensurePermissions,
  9091. permissionGranted,
  9092. show,
  9093. close,
  9094. onClick,
  9095. onShow,
  9096. onError,
  9097. onClose,
  9098. };
  9099. }
  9100. var DEFAULT_PING_MESSAGE = 'ping';
  9101. function resolveNestedOptions(options) {
  9102. if (options === true) return {};
  9103. return options;
  9104. }
  9105. function useWebSocket(url, options = {}) {
  9106. const {
  9107. onConnected,
  9108. onDisconnected,
  9109. onError,
  9110. onMessage,
  9111. immediate = true,
  9112. autoClose = true,
  9113. protocols = [],
  9114. } = options;
  9115. const data = ref(null);
  9116. const status = ref('CLOSED');
  9117. const wsRef = ref();
  9118. const urlRef = toRef2(url);
  9119. let heartbeatPause;
  9120. let heartbeatResume;
  9121. let explicitlyClosed = false;
  9122. let retried = 0;
  9123. let bufferedData = [];
  9124. let pongTimeoutWait;
  9125. const _sendBuffer = () => {
  9126. if (bufferedData.length && wsRef.value && status.value === 'OPEN') {
  9127. for (const buffer of bufferedData) wsRef.value.send(buffer);
  9128. bufferedData = [];
  9129. }
  9130. };
  9131. const resetHeartbeat = () => {
  9132. clearTimeout(pongTimeoutWait);
  9133. pongTimeoutWait = void 0;
  9134. };
  9135. const close = (code = 1e3, reason) => {
  9136. if (!isClient || !wsRef.value) return;
  9137. explicitlyClosed = true;
  9138. resetHeartbeat();
  9139. heartbeatPause == null ? void 0 : heartbeatPause();
  9140. wsRef.value.close(code, reason);
  9141. wsRef.value = void 0;
  9142. };
  9143. const send = (data2, useBuffer = true) => {
  9144. if (!wsRef.value || status.value !== 'OPEN') {
  9145. if (useBuffer) bufferedData.push(data2);
  9146. return false;
  9147. }
  9148. _sendBuffer();
  9149. wsRef.value.send(data2);
  9150. return true;
  9151. };
  9152. const _init = () => {
  9153. if (explicitlyClosed || typeof urlRef.value === 'undefined') return;
  9154. const ws = new WebSocket(urlRef.value, protocols);
  9155. wsRef.value = ws;
  9156. status.value = 'CONNECTING';
  9157. ws.onopen = () => {
  9158. status.value = 'OPEN';
  9159. onConnected == null ? void 0 : onConnected(ws);
  9160. heartbeatResume == null ? void 0 : heartbeatResume();
  9161. _sendBuffer();
  9162. };
  9163. ws.onclose = (ev) => {
  9164. status.value = 'CLOSED';
  9165. onDisconnected == null ? void 0 : onDisconnected(ws, ev);
  9166. if (!explicitlyClosed && options.autoReconnect) {
  9167. const {
  9168. retries = -1,
  9169. delay = 1e3,
  9170. onFailed,
  9171. } = resolveNestedOptions(options.autoReconnect);
  9172. retried += 1;
  9173. if (typeof retries === 'number' && (retries < 0 || retried < retries))
  9174. setTimeout(_init, delay);
  9175. else if (typeof retries === 'function' && retries())
  9176. setTimeout(_init, delay);
  9177. else onFailed == null ? void 0 : onFailed();
  9178. }
  9179. };
  9180. ws.onerror = (e) => {
  9181. onError == null ? void 0 : onError(ws, e);
  9182. };
  9183. ws.onmessage = (e) => {
  9184. if (options.heartbeat) {
  9185. resetHeartbeat();
  9186. const { message = DEFAULT_PING_MESSAGE } = resolveNestedOptions(
  9187. options.heartbeat,
  9188. );
  9189. if (e.data === message) return;
  9190. }
  9191. data.value = e.data;
  9192. onMessage == null ? void 0 : onMessage(ws, e);
  9193. };
  9194. };
  9195. if (options.heartbeat) {
  9196. const {
  9197. message = DEFAULT_PING_MESSAGE,
  9198. interval = 1e3,
  9199. pongTimeout = 1e3,
  9200. } = resolveNestedOptions(options.heartbeat);
  9201. const { pause, resume } = useIntervalFn(
  9202. () => {
  9203. send(message, false);
  9204. if (pongTimeoutWait != null) return;
  9205. pongTimeoutWait = setTimeout(() => {
  9206. close();
  9207. explicitlyClosed = false;
  9208. }, pongTimeout);
  9209. },
  9210. interval,
  9211. { immediate: false },
  9212. );
  9213. heartbeatPause = pause;
  9214. heartbeatResume = resume;
  9215. }
  9216. if (autoClose) {
  9217. if (isClient) useEventListener('beforeunload', () => close());
  9218. tryOnScopeDispose(close);
  9219. }
  9220. const open = () => {
  9221. if (!isClient && !isWorker) return;
  9222. close();
  9223. explicitlyClosed = false;
  9224. retried = 0;
  9225. _init();
  9226. };
  9227. if (immediate) open();
  9228. return {
  9229. data,
  9230. status,
  9231. close,
  9232. send,
  9233. open,
  9234. ws: wsRef,
  9235. };
  9236. }
  9237. function useWebWorker(arg0, workerOptions, options) {
  9238. const { window: window2 = defaultWindow } = options != null ? options : {};
  9239. const data = ref(null);
  9240. const worker = shallowRef();
  9241. const post = (...args) => {
  9242. if (!worker.value) return;
  9243. worker.value.postMessage(...args);
  9244. };
  9245. const terminate = function terminate2() {
  9246. if (!worker.value) return;
  9247. worker.value.terminate();
  9248. };
  9249. if (window2) {
  9250. if (typeof arg0 === 'string')
  9251. worker.value = new Worker(arg0, workerOptions);
  9252. else if (typeof arg0 === 'function') worker.value = arg0();
  9253. else worker.value = arg0;
  9254. worker.value.onmessage = (e) => {
  9255. data.value = e.data;
  9256. };
  9257. tryOnScopeDispose(() => {
  9258. if (worker.value) worker.value.terminate();
  9259. });
  9260. }
  9261. return {
  9262. data,
  9263. post,
  9264. terminate,
  9265. worker,
  9266. };
  9267. }
  9268. function jobRunner(userFunc) {
  9269. return (e) => {
  9270. const userFuncArgs = e.data[0];
  9271. return Promise.resolve(userFunc.apply(void 0, userFuncArgs))
  9272. .then((result) => {
  9273. postMessage(['SUCCESS', result]);
  9274. })
  9275. .catch((error) => {
  9276. postMessage(['ERROR', error]);
  9277. });
  9278. };
  9279. }
  9280. function depsParser(deps) {
  9281. if (deps.length === 0) return '';
  9282. const depsString = deps.map((dep) => `'${dep}'`).toString();
  9283. return `importScripts(${depsString})`;
  9284. }
  9285. function createWorkerBlobUrl(fn, deps) {
  9286. const blobCode = `${depsParser(deps)}; onmessage=(${jobRunner})(${fn})`;
  9287. const blob = new Blob([blobCode], { type: 'text/javascript' });
  9288. const url = URL.createObjectURL(blob);
  9289. return url;
  9290. }
  9291. function useWebWorkerFn(fn, options = {}) {
  9292. const {
  9293. dependencies = [],
  9294. timeout,
  9295. window: window2 = defaultWindow,
  9296. } = options;
  9297. const worker = ref();
  9298. const workerStatus = ref('PENDING');
  9299. const promise = ref({});
  9300. const timeoutId = ref();
  9301. const workerTerminate = (status = 'PENDING') => {
  9302. if (worker.value && worker.value._url && window2) {
  9303. worker.value.terminate();
  9304. URL.revokeObjectURL(worker.value._url);
  9305. promise.value = {};
  9306. worker.value = void 0;
  9307. window2.clearTimeout(timeoutId.value);
  9308. workerStatus.value = status;
  9309. }
  9310. };
  9311. workerTerminate();
  9312. tryOnScopeDispose(workerTerminate);
  9313. const generateWorker = () => {
  9314. const blobUrl = createWorkerBlobUrl(fn, dependencies);
  9315. const newWorker = new Worker(blobUrl);
  9316. newWorker._url = blobUrl;
  9317. newWorker.onmessage = (e) => {
  9318. const { resolve = () => {}, reject = () => {} } = promise.value;
  9319. const [status, result] = e.data;
  9320. switch (status) {
  9321. case 'SUCCESS':
  9322. resolve(result);
  9323. workerTerminate(status);
  9324. break;
  9325. default:
  9326. reject(result);
  9327. workerTerminate('ERROR');
  9328. break;
  9329. }
  9330. };
  9331. newWorker.onerror = (e) => {
  9332. const { reject = () => {} } = promise.value;
  9333. e.preventDefault();
  9334. reject(e);
  9335. workerTerminate('ERROR');
  9336. };
  9337. if (timeout) {
  9338. timeoutId.value = setTimeout(
  9339. () => workerTerminate('TIMEOUT_EXPIRED'),
  9340. timeout,
  9341. );
  9342. }
  9343. return newWorker;
  9344. };
  9345. const callWorker = (...fnArgs) =>
  9346. new Promise((resolve, reject) => {
  9347. promise.value = {
  9348. resolve,
  9349. reject,
  9350. };
  9351. worker.value && worker.value.postMessage([[...fnArgs]]);
  9352. workerStatus.value = 'RUNNING';
  9353. });
  9354. const workerFn = (...fnArgs) => {
  9355. if (workerStatus.value === 'RUNNING') {
  9356. console.error(
  9357. '[useWebWorkerFn] You can only run one instance of the worker at a time.',
  9358. );
  9359. return Promise.reject();
  9360. }
  9361. worker.value = generateWorker();
  9362. return callWorker(...fnArgs);
  9363. };
  9364. return {
  9365. workerFn,
  9366. workerStatus,
  9367. workerTerminate,
  9368. };
  9369. }
  9370. function useWindowFocus(options = {}) {
  9371. const { window: window2 = defaultWindow } = options;
  9372. if (!window2) return ref(false);
  9373. const focused = ref(window2.document.hasFocus());
  9374. useEventListener(window2, 'blur', () => {
  9375. focused.value = false;
  9376. });
  9377. useEventListener(window2, 'focus', () => {
  9378. focused.value = true;
  9379. });
  9380. return focused;
  9381. }
  9382. function useWindowScroll(options = {}) {
  9383. const { window: window2 = defaultWindow, behavior = 'auto' } = options;
  9384. if (!window2) {
  9385. return {
  9386. x: ref(0),
  9387. y: ref(0),
  9388. };
  9389. }
  9390. const internalX = ref(window2.scrollX);
  9391. const internalY = ref(window2.scrollY);
  9392. const x = computed({
  9393. get() {
  9394. return internalX.value;
  9395. },
  9396. set(x2) {
  9397. scrollTo({ left: x2, behavior });
  9398. },
  9399. });
  9400. const y = computed({
  9401. get() {
  9402. return internalY.value;
  9403. },
  9404. set(y2) {
  9405. scrollTo({ top: y2, behavior });
  9406. },
  9407. });
  9408. useEventListener(
  9409. window2,
  9410. 'scroll',
  9411. () => {
  9412. internalX.value = window2.scrollX;
  9413. internalY.value = window2.scrollY;
  9414. },
  9415. {
  9416. capture: false,
  9417. passive: true,
  9418. },
  9419. );
  9420. return { x, y };
  9421. }
  9422. function useWindowSize(options = {}) {
  9423. const {
  9424. window: window2 = defaultWindow,
  9425. initialWidth = Number.POSITIVE_INFINITY,
  9426. initialHeight = Number.POSITIVE_INFINITY,
  9427. listenOrientation = true,
  9428. includeScrollbar = true,
  9429. } = options;
  9430. const width = ref(initialWidth);
  9431. const height = ref(initialHeight);
  9432. const update = () => {
  9433. if (window2) {
  9434. if (includeScrollbar) {
  9435. width.value = window2.innerWidth;
  9436. height.value = window2.innerHeight;
  9437. } else {
  9438. width.value = window2.document.documentElement.clientWidth;
  9439. height.value = window2.document.documentElement.clientHeight;
  9440. }
  9441. }
  9442. };
  9443. update();
  9444. tryOnMounted(update);
  9445. useEventListener('resize', update, { passive: true });
  9446. if (listenOrientation) {
  9447. const matches = useMediaQuery('(orientation: portrait)');
  9448. watch(matches, () => update());
  9449. }
  9450. return { width, height };
  9451. }
  9452. export {
  9453. DefaultMagicKeysAliasMap,
  9454. StorageSerializers,
  9455. TransitionPresets,
  9456. assert,
  9457. computedAsync as asyncComputed,
  9458. refAutoReset as autoResetRef,
  9459. breakpointsAntDesign,
  9460. breakpointsBootstrapV5,
  9461. breakpointsMasterCss,
  9462. breakpointsPrimeFlex,
  9463. breakpointsQuasar,
  9464. breakpointsSematic,
  9465. breakpointsTailwind,
  9466. breakpointsVuetify,
  9467. breakpointsVuetifyV2,
  9468. breakpointsVuetifyV3,
  9469. bypassFilter,
  9470. camelize,
  9471. clamp,
  9472. cloneFnJSON,
  9473. computedAsync,
  9474. computedEager,
  9475. computedInject,
  9476. computedWithControl,
  9477. containsProp,
  9478. computedWithControl as controlledComputed,
  9479. controlledRef,
  9480. createEventHook,
  9481. createFetch,
  9482. createFilterWrapper,
  9483. createGlobalState,
  9484. createInjectionState,
  9485. reactify as createReactiveFn,
  9486. createReusableTemplate,
  9487. createSharedComposable,
  9488. createSingletonPromise,
  9489. createTemplatePromise,
  9490. createUnrefFn,
  9491. customStorageEventName,
  9492. debounceFilter,
  9493. refDebounced as debouncedRef,
  9494. watchDebounced as debouncedWatch,
  9495. defaultDocument,
  9496. defaultLocation,
  9497. defaultNavigator,
  9498. defaultWindow,
  9499. directiveHooks,
  9500. computedEager as eagerComputed,
  9501. executeTransition,
  9502. extendRef,
  9503. formatDate,
  9504. formatTimeAgo,
  9505. get,
  9506. getLifeCycleTarget,
  9507. getSSRHandler,
  9508. hasOwn,
  9509. hyphenate,
  9510. identity,
  9511. watchIgnorable as ignorableWatch,
  9512. increaseWithUnit,
  9513. injectLocal,
  9514. invoke,
  9515. isClient,
  9516. isDef,
  9517. isDefined,
  9518. isIOS,
  9519. isObject,
  9520. isWorker,
  9521. makeDestructurable,
  9522. mapGamepadToXbox360Controller,
  9523. noop,
  9524. normalizeDate,
  9525. notNullish,
  9526. now,
  9527. objectEntries,
  9528. objectOmit,
  9529. objectPick,
  9530. onClickOutside,
  9531. onKeyDown,
  9532. onKeyPressed,
  9533. onKeyStroke,
  9534. onKeyUp,
  9535. onLongPress,
  9536. onStartTyping,
  9537. pausableFilter,
  9538. watchPausable as pausableWatch,
  9539. promiseTimeout,
  9540. provideLocal,
  9541. rand,
  9542. reactify,
  9543. reactifyObject,
  9544. reactiveComputed,
  9545. reactiveOmit,
  9546. reactivePick,
  9547. refAutoReset,
  9548. refDebounced,
  9549. refDefault,
  9550. refThrottled,
  9551. refWithControl,
  9552. resolveRef,
  9553. resolveUnref,
  9554. set2 as set,
  9555. setSSRHandler,
  9556. syncRef,
  9557. syncRefs,
  9558. templateRef,
  9559. throttleFilter,
  9560. refThrottled as throttledRef,
  9561. watchThrottled as throttledWatch,
  9562. timestamp,
  9563. toReactive,
  9564. toRef2 as toRef,
  9565. toRefs2 as toRefs,
  9566. toValue,
  9567. tryOnBeforeMount,
  9568. tryOnBeforeUnmount,
  9569. tryOnMounted,
  9570. tryOnScopeDispose,
  9571. tryOnUnmounted,
  9572. unrefElement,
  9573. until,
  9574. useActiveElement,
  9575. useAnimate,
  9576. useArrayDifference,
  9577. useArrayEvery,
  9578. useArrayFilter,
  9579. useArrayFind,
  9580. useArrayFindIndex,
  9581. useArrayFindLast,
  9582. useArrayIncludes,
  9583. useArrayJoin,
  9584. useArrayMap,
  9585. useArrayReduce,
  9586. useArraySome,
  9587. useArrayUnique,
  9588. useAsyncQueue,
  9589. useAsyncState,
  9590. useBase64,
  9591. useBattery,
  9592. useBluetooth,
  9593. useBreakpoints,
  9594. useBroadcastChannel,
  9595. useBrowserLocation,
  9596. useCached,
  9597. useClipboard,
  9598. useClipboardItems,
  9599. useCloned,
  9600. useColorMode,
  9601. useConfirmDialog,
  9602. useCounter,
  9603. useCssVar,
  9604. useCurrentElement,
  9605. useCycleList,
  9606. useDark,
  9607. useDateFormat,
  9608. refDebounced as useDebounce,
  9609. useDebounceFn,
  9610. useDebouncedRefHistory,
  9611. useDeviceMotion,
  9612. useDeviceOrientation,
  9613. useDevicePixelRatio,
  9614. useDevicesList,
  9615. useDisplayMedia,
  9616. useDocumentVisibility,
  9617. useDraggable,
  9618. useDropZone,
  9619. useElementBounding,
  9620. useElementByPoint,
  9621. useElementHover,
  9622. useElementSize,
  9623. useElementVisibility,
  9624. useEventBus,
  9625. useEventListener,
  9626. useEventSource,
  9627. useEyeDropper,
  9628. useFavicon,
  9629. useFetch,
  9630. useFileDialog,
  9631. useFileSystemAccess,
  9632. useFocus,
  9633. useFocusWithin,
  9634. useFps,
  9635. useFullscreen,
  9636. useGamepad,
  9637. useGeolocation,
  9638. useIdle,
  9639. useImage,
  9640. useInfiniteScroll,
  9641. useIntersectionObserver,
  9642. useInterval,
  9643. useIntervalFn,
  9644. useKeyModifier,
  9645. useLastChanged,
  9646. useLocalStorage,
  9647. useMagicKeys,
  9648. useManualRefHistory,
  9649. useMediaControls,
  9650. useMediaQuery,
  9651. useMemoize,
  9652. useMemory,
  9653. useMounted,
  9654. useMouse,
  9655. useMouseInElement,
  9656. useMousePressed,
  9657. useMutationObserver,
  9658. useNavigatorLanguage,
  9659. useNetwork,
  9660. useNow,
  9661. useObjectUrl,
  9662. useOffsetPagination,
  9663. useOnline,
  9664. usePageLeave,
  9665. useParallax,
  9666. useParentElement,
  9667. usePerformanceObserver,
  9668. usePermission,
  9669. usePointer,
  9670. usePointerLock,
  9671. usePointerSwipe,
  9672. usePreferredColorScheme,
  9673. usePreferredContrast,
  9674. usePreferredDark,
  9675. usePreferredLanguages,
  9676. usePreferredReducedMotion,
  9677. usePrevious,
  9678. useRafFn,
  9679. useRefHistory,
  9680. useResizeObserver,
  9681. useScreenOrientation,
  9682. useScreenSafeArea,
  9683. useScriptTag,
  9684. useScroll,
  9685. useScrollLock,
  9686. useSessionStorage,
  9687. useShare,
  9688. useSorted,
  9689. useSpeechRecognition,
  9690. useSpeechSynthesis,
  9691. useStepper,
  9692. useStorage,
  9693. useStorageAsync,
  9694. useStyleTag,
  9695. useSupported,
  9696. useSwipe,
  9697. useTemplateRefsList,
  9698. useTextDirection,
  9699. useTextSelection,
  9700. useTextareaAutosize,
  9701. refThrottled as useThrottle,
  9702. useThrottleFn,
  9703. useThrottledRefHistory,
  9704. useTimeAgo,
  9705. useTimeout,
  9706. useTimeoutFn,
  9707. useTimeoutPoll,
  9708. useTimestamp,
  9709. useTitle,
  9710. useToNumber,
  9711. useToString,
  9712. useToggle,
  9713. useTransition,
  9714. useUrlSearchParams,
  9715. useUserMedia,
  9716. useVModel,
  9717. useVModels,
  9718. useVibrate,
  9719. useVirtualList,
  9720. useWakeLock,
  9721. useWebNotification,
  9722. useWebSocket,
  9723. useWebWorker,
  9724. useWebWorkerFn,
  9725. useWindowFocus,
  9726. useWindowScroll,
  9727. useWindowSize,
  9728. watchArray,
  9729. watchAtMost,
  9730. watchDebounced,
  9731. watchDeep,
  9732. watchIgnorable,
  9733. watchImmediate,
  9734. watchOnce,
  9735. watchPausable,
  9736. watchThrottled,
  9737. watchTriggerable,
  9738. watchWithFilter,
  9739. whenever,
  9740. };
  9741. /*! Bundled license information:
  9742. vitepress/lib/vue-demi.mjs:
  9743. (**
  9744. * vue-demi v0.14.7
  9745. * Copyright (c) 2020-present, Anthony Fu
  9746. * @license MIT
  9747. *)
  9748. */
  9749. //# sourceMappingURL=vitepress___@vueuse_core.js.map